// JavaScript Document
//Contains generic Web functions

function GetAbsoluteTop(oElement)
{
	var y = 0;
	
	//get the absolute top position relative to the parent object
	for (obj=oElement;obj.offsetParent!=null;obj=obj.offsetParent){
		y+=obj.offsetTop;
	}
	//return value of y
	return y;	
}
function GetAbsoluteLeft(oElement)
{
	var x = 0;
	
	//get the absolute left position relative to the parent object
	for (obj=oElement;obj.offsetParent!=null;obj=obj.offsetParent){
		x+=obj.offsetLeft;	
	}
	//return value of x
	return x;
}
function ScreenLeft(nWinWidth)
{
	//generates a left point for screen positioning
		var nX = (screen.width / 2) - (nWinWidth / 2);
	
	//return
		return nX;
}

function ScreenTop(nWinHeight)
{
	//generates a top point for screen positioning
		var nY = (screen.height / 2)  - (nWinHeight / 2);
		
	//return
		return nY;
}

function CenterWindow(oWindow, nWinWidth, nWinHeight)
{
	//centers the window object in the current screen
	//retrieve screen coordinates
		var nX = (screen.width / 2) - (nWinWidth / 2);
		var nY = (screen.height / 2)  - (nWinHeight / 2);
		
	//move window
		oWindow.moveTo(nX, nY);
	
}
function SetValue(cName,cValue, bAppend){
	// creates hidden input control named: cName with value: cValue
	// if input control already present, contents are replaced
	if (document.frm(cName) == null || bAppend == true) {		
		var cInputField = '<input name="' + cName + '" id="' + cName + '" type="hidden" value="' + cValue + '">' + "\n";
		
		if (document.all["DIVHiddenInputs"]) {
			document.all["DIVHiddenInputs"].innerHTML = document.all["DIVHiddenInputs"].innerHTML + cInputField;
		}
		else {
			oHV=document.createElement(cInputField);
			document.frm.appendChild(oHV);
		}
	} else {
		document.frm(cName).value = cValue;
	}
}
function GetValue(cName)
{
	// retrieves frm element value
		if (document.frm[cName].value == null){
			return '';
		}
		else {
			return document.frm(cName).value;
		}

}
function SubmitCommand(cCommand){
	// sets hidden form var: Command then submits form
	SetValue("Command",cCommand);
	SubmitForm();
}
function SubmitForm() {
	// submits form
	document.frm.submit();
}      
function ShowDialog(cPageName, nHeight, nWidth){
		
		//check for width
			if(nWidth == null || nWidth == ''){
				
				nWidth = '400';
			}
			
		//check for height
			if(nHeight == null || nHeight == ''){
				nHeight = '350';
			}		
		
		//display window
			var oWin = window.open('#',cPageName,"resizable=yes,scrollbars=yes,location=no,menubar=no,height=" + nHeight + ",width=" + nWidth + "");
	        var c = '<form name="frm" method="post" action="default.asp">';
	        c+='<input type="hidden" name="SystemInfo" value="">';
	        c+='<input type="hidden" name="PageName" value="' + cPageName + '">';
	        c+='</form>';
	        oWin.document.write(c);
	        oWin.document.frm.SystemInfo.value=window.document.frm.SystemInfo.value;
	        oWin.document.frm.submit();			
}
function OpenWindow(cURL,cName,cAttribs){
	window.open(cURL,cName,cAttribs);
}
function preloadImages() {
	//jd: preloads images in document, takes any number of arguments   
   //get document object
   var oDoc=document;

	//verify if there are images in the document
	   if(oDoc.images){
	   
		     //create array of images
			   	 if(!oDoc.oImages) oDoc.oImages = new Array();
			 
			 //create vars for loop, get arguments passed to this function as an array
			 	var i, j=oDoc.oImages.length, oArgs = preloadImages.arguments; 			 
			 
			 //loop through the images, create them and set their source
				 for(i = 0; i < oArgs.length; i++){
				     if (oArgs[i].indexOf("#") != 0){
					 	 oDoc.oImages[j] = new Image; 
						 oDoc.oImages[j++].src = oArgs[i];
					}
				}
	  }
}



function findObj(n, d) {
	//jd: looks in the entire document of the specified object
   var p, i, x;

  	//get document object
		if(!oDoc) var oDoc = document;

	
	//look for the object in the parent frame (if any)
		if((p = n.indexOf("?")) > 0 && parent.frames.length) {
		 	oDoc = parent.frames[n.substring(p+1)].document;
		    n = n.substring(0,p);
		}
	
	//look for the object in the forms elements
	  	if(!(x = oDoc[n]) && oDoc .all) x = oDoc.all[n];
		
		for (i = 0; !x && i < oDoc.forms.length; i++)
		{
			 x = oDoc.forms[i][n];
		}
	
	//look for the object in the layers
	  	for(i = 0; !x && oDoc.layers && i < oDoc.layers.length; i++)
		{
			x = findObj(n,oDoc.layers[i].document);
		}
	
	//if the object has not been found yet, get it by element id
	  	if(!x && document.getElementById) x = document.getElementById(n);
	
	//return object
	    return x;
}

function swapImage() {

	//jd: swaps the image or images source to the one passed 
 	//locals
	var i, j = 0, x, a = swapImage.arguments; 
	
	//create array of images sources
		document.oSources = new Array;
	
	//loop through the array images passed as arguments
		for(i = 0; i < (a.length - 2); i += 3){
		 
		 	//if there is an image object then cache its source and swap it with the one passed
				if ((x = findObj(a[i])) != null){
					document.oSources[j++] = x;
					if(!x.oSrc) x.oSrc = x.src;
					x.src = a[i+2];
				}
				
		}
}

function swapImgRestore() {
	//jd: restores the image back to its original source
	//locals
	var i, x, a = document.oSources;
  
  //find the image and restore its source
	   for(i = 0 ; a && i < a.length && (x = a[i] ) && x.oSrc; i++)
	   {
	   	 	x.src = x.oSrc;
	   }
}

function HideAllNamed(cName){
	var oObj = document.all(cName);
	if(oObj!=null){
		if(oObj.length!=null){
			for(var x=0;x<oObj.length;x++){
				oObj[x].style.visibility='hidden';
				oObj[x].style.display='none';
			}
		} else {
			oObj.style.visibility='hidden';
			oObj.style.display='none';			
		}
	}
}

//aref in 8/27/02 #4
function ShowAllNamed(cName){
	var oToShow = document.all(cName);
	
		if(oToShow!=null){
		if(oToShow.length!=null){
			for(var x=0;x<oToShow.length;x++){
				oToShow[x].style.visibility='visible';
				oToShow[x].style.display='';				
			}
		} else 
			{oToShow.style.visibility='visible';oToShow.style.display='';}
	}
}


function GetCheckedItems(oCheckbox) {
	// This function accepts an array of checkbox's and returns a list selected/checked ID's 
	var cCheckedItems='';			
	
	try {
		if(oCheckbox) {
			if(oCheckbox.length!=null) {
				for(var x=0;x<oCheckbox.length;x++) {
				  if(oCheckbox[x].checked) {
						cCheckedItems+=oCheckbox[x].value + ';';				  
					}
				}							
			} else {
				if(oCheckbox.checked) {
					cCheckedItems+=oCheckbox.value + ';';
				}
			}			
			
		}
		
	} catch(e){} // ignore errors	
	
	return cCheckedItems;		
}

function isCheckboxVisible(oCheckbox) {
	var bVisible=false;  // default value
	
	try {
		if (oCheckbox.style.visibility!="hidden")
			bVisible=true;
	} catch(e) {}  // ignore errors
	
	
	if (!bVisible) {
		try {
			if (oCheckbox.length > 0)
				if (oCheckbox[0].style.visibility!="hidden")
					bVisible=true;
		} catch(e) {} // ignore errors
	}
	
	if (!bVisible)
		return false;
	else
		return true;
	
}
		

function HideShowObj(oObj) {
	// This function accepts an object/array of objects and alternates their visible property
	
	try {
		if(oObj) {
			
			if(oObj.length!=null) {
								
				for(var x=0;x<oObj.length;x++) {				  		  				  				
				  			  			  
				  if(oObj[x].style.visibility!='hidden') 
						oObj[x].style.visibility='hidden';
					else
						oObj[x].style.visibility='visible' ;
				}							
			} else {
				if(oObj.style.visibility!='hidden') 
					oObj.style.visibility='hidden';
				else
					oObj.style.visibility='visible'; 
			}			
			
		}
		
	} catch(e){} // ignore errors
		
}

function HideElem(oElem){
	oElem.style.visibility='hidden';
	oElem.style.display='none';
}

function ShowElem(oElem){
	oElem.style.visibility='visible';
	oElem.style.display='';
}