﻿/******************************************************************/
function stopEvent(e){
    if (e == null){
        return
    }
    var mBrowser = detectBrowser()
    
    switch (mBrowser){
        case "IE":
            e.returnValue = false
            break;
        case "FF":
            e.preventDefault()
            break;
        case "SF":
            e.stopPropagation()
            break;            
    }
    
}
/******************************************************************/
function detectBrowser(){
    var mReturnValue = null
    var mAgent = new String(navigator.userAgent.toLowerCase())
    
    if (mAgent.indexOf("msie") !== -1){
        mReturnValue = "IE"
    }else if(mAgent.indexOf("firefox") !== -1){
        mReturnValue = "FF"
    }else if(mAgent.indexOf("safari") !== -1){
        mReturnValue = "SF"
    }
        
    return mReturnValue

}
/******************************************************************/
function getControlValue(controlName){    
    var mValue = new String()
    mValue = document.getElementById(controlName).value
    return mValue
}
/******************************************************************/
function getControlInnerText(controlName){    
    var mValue = new String()
    if (detectBrowser()=="FF"){
		mValue = document.getElementById(controlName).textContent
    }else{
		mValue = document.getElementById(controlName).innerText
    }
    return mValue
}
/******************************************************************/
function DoCallBack(functionName, functionArguments, endFunction, context){
    __theFormPostData = "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=&"    
    WebForm_DoCallback('__Page', functionName + '|' + functionArguments, endFunction, context, null, false)        
}
/******************************************************************/
function DoCallBack2(functionName, mData, endFunction, context){
    __theFormPostData = "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=&"    
    WebForm_DoCallback('__Page', functionName + mData, endFunction, context, null, false)        
}
/******************************************************************/
function setupHtmlGrid(elementName, html){
    var elementMainTable = document.getElementById(elementName + "_main_table")
    elementMainTable.parentNode.innerHTML = html        
}
/******************************************************************/
function setupHtmlCombo(elementName, html){
    document.getElementById(elementName).name = "__"
    document.getElementById(elementName).parentNode.innerHTML = html
}
/******************************************************************/
function setFullScreen(){
    try{
        window.moveTo(0,0)
        window.resizeTo(screen.width,screen.height-30)

    }catch(ex){}
}
/******************************************************************/
function setSelectedValue(elementName, data){
    var elementCollection = document.getElementsByName(elementName)
    var mArray = data.split(":")
    
    if (elementCollection.length){
        
        for (i=0;i<elementCollection.length;i++){
            var mElement = elementCollection[i]  
            
            for (a=0;a < mArray.length;a++){
                if (mElement.value == mArray[a]){
                    mElement.checked = true
                }                
            
            }
        }    
    }else{
        for (a=0;a < mArray.length;a++){

            for (a=0;a < mArray.length;a++){
                if (elementCollection.value == mArray[a]){
                    elementCollection.checked = true
                }                
            
            }
        }
    
    }

}
/******************************************************************/
function getSelectedValue(elementName){
    
    var elementCollection = document.getElementsByName(elementName)
    var mArray = new Array()
    
    if (elementCollection.length){
        
        for (i=0;i<elementCollection.length;i++){
            var mElement = elementCollection[i]            
            if (mElement.checked){
                mArray.push(mElement.value)
            }                
        }    
    }else{
        if (elementCollection.checked){
            mArray.push(elementCollection.value)
        }
    
    }
    
    var mReturnValue = mArray.join(":")
    
    return mReturnValue
}
var mFormData = null
/******************************************************************/
function DoFormCallBack(functionName, dummy, endFunction){
    
    mFormData = new String()
    InitFormCallback()
    
    __theFormPostData = "__FORMCALLBACK=1&__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=&" + mFormData
    
    WebForm_DoCallback('__Page', functionName, endFunction, null, null, false)        
}
/******************************************************************/
function InitFormCallback() {
    var count = theForm.elements.length;
    var element;
    for (var i = 0; i < count; i++) {
        element = theForm.elements[i];
        var tagName = element.tagName.toLowerCase();
        if (tagName == "input") {
            var type = element.type;
            
            if ((type == "text" || type == "hidden" || type == "password" || ((type == "checkbox" || type == "radio") && element.checked)) && (element.id != "__EVENTVALIDATION" && element.id != "__VIEWSTATE" && element.id != "__EVENTTARGET" && element.id != "__EVENTARGUMENT")) {
                
                InitCallbackAddField(element.name, element.value);
            }
        }
        else if (tagName == "select") {
            var selectCount = element.options.length;
            for (var j = 0; j < selectCount; j++) {
                var selectChild = element.options[j];
                if (selectChild.selected == true) {
                    InitCallbackAddField(element.name, element.value);
                }
            }
        }
        else if (tagName == "textarea") {
            InitCallbackAddField(element.name, element.value);
        }
    }
}
/******************************************************************/
function InitCallbackAddField(name, value) {
    mFormData += name + "=" + WebForm_EncodeCallback(value) + "&";
}
/******************************************************************/
function uc(msg){
	alert(msg);
}
/******************************************************************/
function getKeyCode(e){
	// handle i.e. (window.event) and firefox (e)
	var eventInstance = window.event ? event : e;
	// handle i.e. (charCode) and firefox (keyCode)
	var unicode = eventInstance.charCode ? eventInstance.charCode : eventInstance.keyCode;
	
	if (detectBrowser()=="SF" && unicode==3){unicode=13}
	//var key = String.fromCharCode(unicode);
	return unicode
}
/******************************************************************/
function openWindowHide(url, windowHeight, windowWidth, resize, Name, Mode, MySendArgs, endFunction){		
	windowLeft = screen.availWidth;
	windowTop  = screen.availHeight;	
	
	var mUrl = new String(window.location.pathname + url);
	var mResize = "";

	if (typeof(Mode) == "undefined" || Mode == 1){
		if (resize == null){
			mResize = "resizable=false";
		}else{
			mResize = "resizable=" + (resize ? "yes":"no");
		}
		if (Name == null) {
			var newWindow = window.open(url, "", mResize + ", height=" + windowHeight + ",width=" + windowWidth + ",status=yes, left=" + windowLeft + ", top=" + windowTop);
			return newWindow;
		}else{
			var newWindow = window.open(url, Name, mResize + ", height=" + windowHeight + ",width=" + windowWidth + ",status=yes, left=" + windowLeft + ", top=" + windowTop);
			return newWindow;
		}
	}
	else{
		_DialogArguments = MySendArgs
		_CurrentWindow = showPopWin(url, windowWidth, windowHeight + 60, endFunction)

	}
}
/******************************************************************/
function setSearchDirectory(alpha){
	document.getElementById(SystemControlVars.hSearchDirectory).value = alpha;
	try{
   	document.getElementById(SystemControlVars._param).value = "";
   	
	}catch(e){
	
	}
	try{
       	document.getElementById("_param").value = "";
	}catch(e){
	}	
	
	if (alpha == "ALL"){
	  Begin_Search(3)
	}else{
	  Begin_Search(1)
	}
	
	
}
/******************************************************************/
function openWindow(url, windowHeight, windowWidth, resize, Name, Mode, MySendArgs, endFunction){           
      windowLeft = (screen.availWidth / 2) - (windowWidth / 2);

      windowTop  = ((screen.availHeight / 2) - (windowHeight / 2)) - 20;      
      var mUrl = new String(window.location.pathname + url);

      var mResize = "";
      if (typeof(Mode) == "undefined" || Mode == 1){

            if (resize == null){

                  mResize = "resizable=false";

            }else{
					if (resize == "1"){
						mResize = "location=no,status=no,scrollbars=yes";
					}else{
						mResize = "resizable=" + (resize ? "yes":"no");
					}
            }

            if (Name == null) {

                  var newWindow = window.open(url, "", mResize + ", height=" + windowHeight + ",width=" + windowWidth + ",status=yes, left=" + windowLeft + ", top=" + windowTop);

                  return newWindow;

            }else{

                  var newWindow = window.open(url, Name, mResize + ", height=" + windowHeight + ",width=" + windowWidth + ",status=yes, left=" + windowLeft + ", top=" + windowTop);

                  return newWindow;

            }

      }

      else{

            _DialogArguments = MySendArgs

            _CurrentWindow = showPopWin(url, windowWidth, windowHeight + 60, endFunction)

 

      }

}
/******************************************************************/
function getURLRoot(){
	var currentUrl = new String(document.location.pathname);
	var mUrlSegments = currentUrl.split("/");
	var supportUrl = "http://" + document.location.host;
	return supportUrl;
}
/******************************************************************/
function trim(cadena){
	for(i=0; i<cadena.length;){
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}
	for(i=cadena.length-1; i>=0; i=cadena.length-1){
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}
  return cadena	
}
/******************************************************************/
function controlValidationText(controlName, display, sText){
    document.getElementById(controlName).innerHTML = sText
    document.getElementById(controlName).style.display = display;
}
/******************************************************************/
function nt(){}
/******************************************************************/
