//--------------------------------------------------------------------------------------------------------------
//NOTES: This file includes functions that control:
//Image rollovers
//Layer Menu Rollover
//Toggling <DIV>(s) to show and hide elements
//Jump Menus
//New Browser windows
//--------------------------------------------------------------------------------------------------------------
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i>a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i>d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function jumpmenu(ID){
	window.location.href = ID;
}

function toggleSelect(ps_FormName,ps_Status)
{
	var li_Seed;
	var lo_Form = eval('document.' + ps_FormName);
	var li_ElementCount = lo_Form.length;
	for (li_Seed = 0; li_Seed < li_ElementCount; li_Seed++)
	{
		if(lo_Form.elements(li_Seed).type == 'select-one')	
		{
			lo_Form.elements(li_Seed).style.visibility = ps_Status;
		}
	}	
}

function randomImage(arrItems)
{
	var dDate = new Date();
	var iTime = dDate.getTime();
	var iRandom = parseInt(((iTime - (parseInt(iTime/1000,10) * 1000))/10) / 100 * arrItems.length,10) + 1;
	document.write('<img src="' + arrItems[iRandom - 1] + '" />');
	return;
}

function checkKeyCode(){
	//alert(event.keyCode);

	var strUrl = document.URL;
	var nQuestPos = strUrl.indexOf('?');
	// if there is no ? then there are no parameters
	if (nQuestPos==-1)
		strUrl += '?';
	else
		strUrl += '&';

	// If the user presses F12
	if(event.keyCode==123)
	{		
		// add the xml=rtn
		strUrl += 'XML=RTN';
		// redirect the window
		document.URL = strUrl;
	}
	// If the user presses F10
	else if(event.keyCode==121)
	{		
		// add the xml=rtn
		strUrl += 'XML=RTN&RAW=RTN';
		// redirect the window
		document.URL = strUrl;
	}
	// If the user presses F9
	else if(event.keyCode==120)
	{		
		// add the dbg=rtn
		strUrl += 'DBG=RTN';
		// redirect the window
		document.URL = strUrl;
	}
	// If the user presses F8
	else if(event.keyCode==119)
	{		
		// add the dbg=rtn
		strUrl += 'CHE=N';
		// redirect the window
		document.URL = strUrl;
	}
	// If the user presses F7
	else if(event.keyCode==118)
	{		
		// add the dbg=rtn
		strUrl += 'RCHE=Y';
		// redirect the window
		document.URL = strUrl;
	}
}

function toggle(element,imgname)
{
	if (!element)
	{
		return;
	}
	{
	if (element.style.display == 'none') {
		element.style.display = 'block';
		if (imgname)	{
			document.images[imgname].src = 'images/i_minus.gif'
		}
	}
	else
	{
		element.style.display = 'none';
		if (imgname)	{
			document.images[imgname].src = 'images/i_plus.gif'
		}
	}
	}
}

function changeSysObjId( sFieldName )
{
	var oDropDownField = document.getElementById(sFieldName);
	var oHiddenField = document.getElementById("_SYS_OBJECT_ID");
	
	if ( (oDropDownField) && (oHiddenField) )
	{
		oHiddenField.value = oDropDownField.value;
	}
}
/***********************************************************************************/
function fHideMenu( psDivId )
/***********************************************************************************/
{
	var oAddDiv = document.getElementById(psDivId);

	var iXmin = 3 + oAddDiv.offsetLeft
	var iXmax = -3 + oAddDiv.offsetLeft + ((oAddDiv.offsetWidth)?(oAddDiv.offsetWidth):(oAddDiv.clientWidth))
	var iYmin = 0// + oAddDiv.offsetTop
	var iYmax = -3 + oAddDiv.offsetTop + ((oAddDiv.offsetHeight)?(oAddDiv.offsetHeight):(oAddDiv.clientHeight))
/*
alert('X: ' + giMouseX + '<=' + iXmin);
alert('X: ' + giMouseX + '>=' + iXmax);

alert('Y: ' + giMouseY + '<=' + iYmin);
alert('Y: ' + giMouseY + '>=' + iYmax);
*/

	if (oAddDiv)
	{
		if	(	(giMouseX <= iXmin)
			||	(giMouseX >= iXmax) 
			||	(giMouseY <= iYmin) 
			||	(giMouseY >= iYmax) 
			)
		{
			oAddDiv.style.visibility='hidden';
		}
	}

}
//
// DIV DROP DOWN SELECT FUNCTIONS -->
//
/***********************************************************************************/
function fShowDD( psSCM )
/***********************************************************************************/
{
	// Get the div that was clicked
	var oDropDownDiv = document.getElementById('DD' + psSCM);

	// if the div exists
	if (oDropDownDiv)
	{
		// find the x & y position of the div
		var iDivX = findPosX(oDropDownDiv);
		var iDivY = findPosY(oDropDownDiv);

		// find the height and width of the div
		var iDivHeight	=	((oDropDownDiv.offsetHeight)?(oDropDownDiv.offsetHeight):(oDropDownDiv.clientHeight));
		var iDivWidth	= 	((oDropDownDiv.offsetWidth)?(oDropDownDiv.offsetWidth):(oDropDownDiv.clientWidth));

		// get the drop down selector div
		var oSelectDiv = document.getElementById("DropDownSelect");

		// if the drop down selector div exists
		if (oSelectDiv)
		{
			if (oSelectDiv.style.visibility == 'visible')
			{
				fHideSelDD();
			} else {
				fHideSelDD();
	
				// Populate the select div
				fPopulateDiv( oSelectDiv, psSCM );
	
				// move the selector div to be below the drop down div
				oSelectDiv.style.left = iDivX;
				oSelectDiv.style.top = (iDivY + iDivHeight);
				// make the selector div the same width as the drop down div
				oSelectDiv.style.width = iDivWidth;
				// show the selector div
				oSelectDiv.style.visibility = 'visible';
				
				// find the value of the hidden field
				var oDDHiddenField	= document.getElementById(psSCM);
				// if the hidden field exists then
				if (oDDHiddenField)
				{
					var  lsSelectItem = oDDHiddenField.value;
					
					// get selected div
					var oSelectedItem = document.getElementById('DDS' + psSCM + '_' + lsSelectItem);
					// if the selected div exists
					if (oSelectedItem)
					{
						// set focus on the selected div
						oSelectedItem.scrollIntoView();
						oSelectedItem.style.backgroundColor = "#cccccc";
					}
				}
			} 
		}
	}
}

/***********************************************************************************/
function fHideSelDD()
/***********************************************************************************/
{
	// get the drop down selector div
	var oSelectDiv = document.getElementById("DropDownSelect");

	// if the drop down selector div exists
	if (oSelectDiv)
	{
		// hide the selector div
		oSelectDiv.style.visibility = 'hidden';
	}
}

/***********************************************************************************/
function fPopulateDiv( poDiv, psSCM )
/***********************************************************************************/
{
	poDiv.innerHTML = eval('gsDDVal' + psSCM);
}

/***********************************************************************************/
function fDDSelItem( psSCM, piItem)
/***********************************************************************************/
{
	var oDDHiddenField	= document.getElementById(psSCM);
	var oDDVisableField = document.getElementById('DD' + psSCM);
	var oDDSelectedDiv	= document.getElementById('DDS' + psSCM + '_' + piItem);

	// if the field exists
	if (oDDHiddenField && oDDVisableField)
	{
		// set the hidden and visible fields
		oDDHiddenField.value = piItem;
		oDDVisableField.innerHTML = oDDSelectedDiv.innerHTML;
		
	}

	// hide the select dropdown
	fHideSelDD();
}

/***********************************************************************************/
function findPosX(poObject)
/***********************************************************************************/
{
	var liCurLeft = 0;
	if (poObject.offsetParent)
	{
		while (poObject.offsetParent)
		{
			liCurLeft += poObject.offsetLeft
			poObject = poObject.offsetParent;
		}
	}
	else if (poObject.x)
	{
		liCurLeft += poObject.x;
	}

	return liCurLeft;
}

/***********************************************************************************/
function findPosY(poObject)
/***********************************************************************************/
{
	var liCurTop = 0;
	if (poObject.offsetParent)
	{
		while (poObject.offsetParent)
		{
			liCurTop += poObject.offsetTop
			poObject = poObject.offsetParent;
		}
	}
	else if (poObject.y)
	{
		liCurTop += poObject.y;
	}
	return liCurTop;
}

//
// <-- DIV DROP DOWN SELECT FUNCTIONS
//

function imageSwapIn(imgID,newSrc){
   var image = document.getElementById(imgID);
   //var oldSrc = image.setAttribute('title',image.src);
   image.src = newSrc;
}
function imageSwapOut(imgID){
   var image = document.getElementById(imgID);
   //var oldSrc = image.getAttribute('title');
   image.src = oldSrc;
   image.removeAttribute('title');
}

/***********************************************************************************/
/* END OF FILE */
/***********************************************************************************/
