function goFocus(e)
{
    if (e && e.which)
    {
        var e = e;
		var charCode=e.which;
    }
	else
	{
		var e=window.event;
		var charCode=e.keyCode;
	}

    if (charCode == 13)
    {
        var formLength = frmMain.length; // Get number of elements in the form
		if (e.target) var src=e.target; // Gets the field having focus
        else if (e.srcElement) var src = e.srcElement; //For IE

		if (src.nodeType == 3) src=src.parentNode; // For Safari
		
		try{
			var type = src.type.toLowerCase();
			if (type == "textarea") return;
		}catch(ex){}

		var currentTabIndex = src.getAttribute('tabindex'); // Gets its tabindex
		currentTabIndex=currentTabIndex*1; //make sure it is a number

		for (var i = 0; i < formLength; i++)
		{
			if (frmMain.elements[i].type == "hidden" && frmMain.elements[i].getAttribute('tabindex') == currentTabIndex + 1) currentTabIndex++;
			if (frmMain.elements[i].getAttribute('tabindex') == currentTabIndex + 1)
			{
				try{
					frmMain.elements[i].focus();
				}catch(ex){}

				return false;
			}
		}           
	}
}
function displayObjectsCollection2(CollectionName, display){ /////
	var objs = document.getElementsByName(CollectionName);
	if (isNaN(objs.length)){
		objs.style.display = display;
	}
	else{
		for (var i=0; i<objs.length; i++){
			objs[i].style.display = display;
		}
	}
}
function displayObjectsCollection(CollectionName, display){
	var objs = document.getElementById(CollectionName);
	if (isNaN(objs.length)){
		objs.style.display = display;
	}
	else{
		for (var i=0; i<objs.length; i++){
			objs[i].style.display = display;
		}
	}
}
function disableObjectsCollection(CollectionName, disable){
	var objs = document.all(CollectionName); 

	if (isNaN(objs.length)){
		objs.disabled = disable;
	}
	else{
		for (var i=0; i<objs.length; i++){
			objs[i].disabled = disable;
		}
	}
}
function hiddenMessage(ContainerObjectMessage, ObjectHidden){
	var objCOMsg = document.all(ContainerObjectMessage);
	var objOHddn = document.all(ObjectHidden);

	if (objCOMsg != null) objCOMsg.style.display = "none";
	if (objOHddn != null) objOHddn.style.display = "block";
}
function msgUC(){
	alert("Under Construction.")
}
function getElementsSelectedFromCustomControl(IFrameGrid, FormName, control, Collection){
	var form = IFrameGrid.document.all(FormName);
	var values = "";

	for (var i = 0; i < form.elements.length; i++){
		var obj = form.elements[i];
		var type = obj.type.toLowerCase();

		if (type == "checkbox"){
			if (obj.id != "chkAllItems"){
				if (obj.id == control){
					if (obj.checked && ! findControlIDInCollection(obj.id, Collection)){
						values += (values == "" ? "" : ";") + obj.text;
					}
				}
			}
		}
	}
	
	return values;
}
function getElementsSelectedFromCustomControlValue(IFrameGrid, FormName, control, Collection){
	var form = IFrameGrid.document.all(FormName);
	var values = "";

	for (var i = 0; i < form.elements.length; i++){
		var obj = form.elements[i];
		var type = obj.type.toLowerCase();

		if (type == "hidden"){
			if (obj.id == control){
				values += (values == "" ? "" : ";") + obj.value;
			}
		}
	}
	
	return values;
}
function getElementsSelected(IFrameGrid, FormName, Collection){
	var form = IFrameGrid.document.all(FormName);
	var values = "";

	for (var i = 0; i < form.elements.length; i++){
		var obj = form.elements[i];
		var type = obj.type.toLowerCase();

		if (type == "checkbox"){
			if (obj.id != "chkAllItems"){
				if (obj.checked && ! findControlIDInCollection(obj.id, Collection)){
					values += (values == "" ? "" : ";") + obj.text;
				}
			}
		}
	}
	
	return values;
}
function getElementsSelected2(IFrameGrid, FormName, Collection){
	var form = IFrameGrid.document.getElementById(FormName);
	var values = "";

	for (var i = 0; i < form.elements.length; i++){
		var obj = form.elements[i];
		var type = obj.type.toLowerCase();


		if (type == "checkbox"){
			if (obj.id != "chkAllItems"){
				if (obj.checked && ! findControlIDInCollection(obj.id, Collection)){
					values += (values == "" ? "" : ";") + obj.value;
				}
			}
		}
	}
	
	return values;
}
function getElementsTextBox(IFrameGrid, FormName, controID, Collection, deleteBlankItem){
	var form = IFrameGrid.document.all(FormName);
	var values = "";
	var vCheckBox = false;
	var xI = 0;

	for (var i = 0; i < form.elements.length; i++){
		var obj = form.elements[i];
		var type = obj.type.toLowerCase();

		if (type == "checkbox"){
			if (obj.id != "chkAllItems"){
				vCheckBox = (obj.checked && ! findControlIDInCollection(obj.id, Collection))
			}
		}

		if (type == "text"){
			if (obj.id == controID && vCheckBox){
				if (deleteBlankItem){
					if(obj.value != ""){
						values += (values == "" ? "" : ";") + obj.value;
					}
				}else{
					values += (xI > 0 ? ";" : "") + obj.value;
					xI = xI + 1
				}
			}
		}
	}
	
	return values;
}
function findControlIDInCollection(ControlID, Collection){
	var counter;

	if (typeof(Collection) == "undefined" || Collection == null) return false;

	for(counter in Collection){ 
		//alert(Collection[counter].toString())
		if (counter.toString() == ControlID) return true; 
	} 

	return false;
}
function openWindow(url, windowHeight, windowWidth, resize, Name, Mode, MySendArgs){		
	var windowLeft = (screen.availWidth / 2) - (windowWidth / 2);
	var windowTop = ((screen.availHeight / 2) - (windowHeight / 2)) - 10;
	var mUrl = new String(window.location.pathname + url);
	var windowName = mUrl.replace(/\W/g, "_")
	var mResize = "";

	if (typeof(Mode) == "undefined" || Mode == 1){
		if (resize == null) mResize = "resizable=false"; else mResize = "resizable=" + (resize ? "yes":"no");
		if (MySendArgs == null) MySendArgs = "scrollbars=false"; else MySendArgs = "scrollbars=" + (MySendArgs ? "yes":"no");
		
		var newWindow = window.open(url, windowName, mResize + ", " + MySendArgs + ", height=" + windowHeight + ",width=" + windowWidth + ",status=yes, left=" + windowLeft + ", top=" + windowTop);
		
		newWindow.focus();
	}
	else{
		var WinSettings = "dialogTop=" + windowTop
			+ "; dialogLeft=" + windowLeft
			+  "; dialogWidth=" + (windowWidth + 25) + "px;" + "dialogHeight=" + (windowHeight + 25) + "px;"
			+ "center=yes; status=no; help=no; scroll=no;";

		url += "&WinID=" + getWinID();

		return window.showModalDialog(url, MySendArgs, WinSettings);
	}
}

var ImageList=new Array(); 

function preLoadImages(Images){
	var counter;

	for(counter in Images){ 
		ImageList[counter]=new Image(); 
		ImageList[counter].src=Images[counter]; 
	} 
}
function RTrim(Value) {
	var nwvl = "";
	for (var i = Value.length-1;i >= 0;i--){
	  if (Value.charCodeAt(i) != 32){
	    nwvl = Value.substring(0,i+1);
	    break;
	  }
	}    
	return nwvl;
}
function LTrim(Value) {
	var nwvl = "";
	for (var i = 0;i < Value.length;i++){
		if (Value.charCodeAt(i) != 32){
			nwvl = Value.substring(i,Value.length);
			break;
		}
	}    
	return nwvl;
}
function Trim(Value){
	var nwvl = LTrim(RTrim(Value))
	return nwvl;
}
function CheckAllDataGridCheckBoxes(checkVal, Collection) {
	for(i = 0; i < document.forms[0].elements.length; i++) {
		elm = document.forms[0].elements[i];
		
		if (elm.type == 'checkbox' && elm.className!=='cCheckBoxHide') {
		
			if (! findControlIDInCollection(elm.id, Collection)){
				elm.checked = checkVal;
			}
		}
	}
}
function filterText(Object, FindTextVar, ExecOnChangeEvent){
	var strChr = String.fromCharCode(event.keyCode);
	var strFindText = new String(FindTextVar);

	if (event.keyCode == 13 || event.keyCode == 27){
		if (event.keyCode == 13 && ExecOnChangeEvent) Object.onchange();
		return "";
	}

	strFindText += strChr;

	for(var i=0; i<Object.length; i++){
		if (Object[i].text.substr(0,strFindText.length).toLowerCase()==strFindText.toLowerCase()){ 
			Object.selectedIndex=i;
			event.returnValue = false;
			return strFindText;
		}
	}

	return strChr;
}
function getRandom(Number)
{
    var ranNum= Math.round(Math.random()*Number);
    return ranNum;
}
function getWinID(){
	var chars = new Array("0","1","2","3","4","5","6","7","8","9",
	"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p",
	"q","r","s","t","u","v","w","x","y","z");

	var id = "";

	for (var n=1;n<=20;n++){
		id += chars[getRandom(35)];
	}

	return id
}
function getNumber(Value){
	return Value.toString().replace(/\,|\,/g,'');
}
function customConfirm(Message){
	var ParmA = Message;
	var MySendArgs = new Array(ParmA);

	var PageLocation = new String(location.pathname);
	var LocationSplit = PageLocation.split("/");
	var AppName = (LocationSplit[0] == "" ? LocationSplit[1] : LocationSplit[0]);
	var WinWidth = getWinWidth(Message);
	var WinHeight = getWinHeight(Message);

	var url = location.protocol + "http:///" + location.host + "/" + AppName + "/library/others/confirmUI.aspx?msg=" + ParmA;
	var MyArgs = openWindow(url, WinHeight, WinWidth, null, null, 2, MySendArgs);
	if (typeof(MyArgs) == "undefined") return;

	var sMsgYN = MyArgs[0].toString();

	if (sMsgYN=="1"){return true;}
	else{return false;}
}
function getWinWidth(Message){
	var w = 0;
	var lines = Message.split("<br>");

	for(var l=0; l<lines.length; l++){
		var TextWidth = getTextWidth(lines[l]);
		if(TextWidth>w){w=TextWidth};
	}

	w += 63;
	if (w<240) w=240;

	return w;
}
function getWinHeight(Message){
	var h = 2;
	if(Message.search(/<br>/g)!=-1){h = Message.match(/<br>/g).length+1;}
	h = 110 + (h*12.5);

	return h;
}
function getTextWidth(Text){
	var w = 0;
	for (var n=0; n<Text.length; n++){
		if (Text.substr(n,1) == Text.substr(n,1).toLocaleUpperCase()){w+=6.5} else{w+=5}
	}

	return w;
}
function goFocusNext(sender, focus, lenght){
	if (typeof(focus) != "undefined"){
		if (sender.value.length == lenght) focus.focus();
	}
}
function addOption(objNm, valueID, valueText) {
	var objTmp = document.createElement("OPTION");
	objTmp.value = valueID;
	objTmp.text = valueText;		
	window.parent.document.all(objNm).add(objTmp);  
	window.parent.document.all(objNm).value = valueID;
}
function remove_options(obj){
	var j = obj.length
	for (i=0; i<j; i++){
		obj.remove(0)
	}
}
function remove_options_blank(Obj){
	remove_options(document.all(Obj));
	addOption(Obj,0,"");
}
function HSLeftPanel(){
	document.all("tdPanel").style.display = document.all("tdPanel").style.display == "none" ? "block" : "none";
	document.all("imgLeftPanel_S").style.display = document.all("tdPanel").style.display == "none" ? "block" : "none";
}
function buttonEffectOver(){
	//event.srcElement.className="cButtonsOver"
}
function buttonEffectOut(){
	//event.srcElement.className="cButtons"
}
function getPersonAddressShipDoc(vPersonAddress1, vPersonAddress2, vPersonPostalCode, vPersonAddressCity, vStateCode, vStateName, vCountryName){
	var vGetPersonAddressShipDoc;
	
	vGetPersonAddressShipDoc = (vPersonAddress1 == "" ? "" : vPersonAddress1 + " ") + 
												(vPersonAddress2 == "" ? "" : vPersonAddress2 + ", ") + 
												(vPersonAddressCity == "" ? "" : vPersonAddressCity + ", ") +
												(vStateCode == "" || !isNaN(Number(vStateCode)) ? vStateName + ", " : vStateCode + ", ") +
												(vPersonPostalCode == "" ? "" : vPersonPostalCode + ", ") +
												vCountryName;
	
	return vGetPersonAddressShipDoc;
}
function moveFocus(obj){
	var v = obj.value;
	var t = obj.createTextRange();
	t.moveStart('character', v.length)
	t.select();
}
function LoadCombo(cboSet, cboGet, TOS, widthSet, ControlIndex){
	if (ControlIndex!==""){cboGet.tabIndex = ControlIndex}
	if (TOS == "IE"){
		cboSet.outerHTML = cboGet.outerHTML
	}else{
		cboSet.innerHTML = cboGet.innerHTML
		cboSet.style.width = widthSet
	}
	
}
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 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
}