// JavaScript Document
//=============================================================================================
//  Constants
//=============================================================================================

//browser diferentiation-----------------------------------------------------------------------
if(document.layers){
	thisbrowser="NN4";
	allString = "document.";
	styleString = ""
}
if(document.all){
	thisbrowser="IE"
	allString = "document.all.";
	styleString = ".style";
}
if(!document.all && document.getElementById){
	thisbrowser="NN6";
	allString = "document.";
	styleString = ".style"
}

//=============================================================================================
//  Functions
//=============================================================================================
function MultiDimensionalArray(iRows,iCols) { 
	var i; 
	var j; 
	var a = new Array(iRows); 
	for (i=0; i < iRows; i++) 
	{ 
	   a[i] = new Array(iCols); 
	   for (j=0; j < iCols; j++) 
	   { 
		   a[i][j] = ""; 
	   } 
	} 
	return(a); 
} 

//---AJAX--------------------------------------------------------------------------------------
function ajaxRequest(formID, url, divID, loadingText) {
		return ajaxRequest2(formID, url, divID, loadingText,"application/x-www-form-urlencoded; charset=UTF-8","")
	}
	function ajaxRequestXML(formID, url, divID, loadingText) {
		return ajaxRequest2(formID, url, divID, loadingText,"text/xml","")
	}
	function ajaxRequestFunction(formID, url, divID, loadingText, fnc)
		{
		return ajaxRequest2(formID, url, divID, loadingText,"application/x-www-form-urlencoded; charset=UTF-8", fnc)
		}
	function ajaxRequest2(formID, url, divID, loadingText, cType,fnc) {
		//alert(cType);
		//FormID - Form Data you want to submit to the target url
		//url - url post form data to and retrieve results
		//DivID - target Div for retrieved data, if blank, only do a return, don't change page
		//loadingText - what to display while waiting for returned value
		//cType - Content type for the httprequest object
		//fnc - function to run at completion
		var req = new Object();
		var leadChar, queryStr;
		queryStr="";
		if (formID!="") {
			for (var i=0;i<document.getElementById(formID).length;i++) {	//get name/value pairs of form data
				current = document.getElementById(formID).elements[i];
				if (current.name!="") { //if form element has a name
					leadChar="&";
					if (queryStr.length == 0) {leadChar=''} //is this the start of the query string?
					queryStr=queryStr + leadChar + current.name + '=' + escape(current.value);
				}
			}
		}
		req.targetDiv=divID;
		if (loadingText != "" && loadingText != undefined && divID!="") { document.getElementById(req.targetDiv).innerHTML=loadingText }
		req.xmlHttp=GetXmlHttpObject(stateChanged);
		//if (xmlHttp==null) 	{
			//alert ("Browser does not support HTTP Request")
			//return
		//} 
		req.xmlHttp.open("POST",url,true);
		req.xmlHttp.setRequestHeader("Content-Type", cType ); //properly encode post data
		req.xmlHttp.send(queryStr)	//send request with post data
		
		function stateChanged() { 
		if (req.xmlHttp.readyState==4 || req.xmlHttp.readyState=="complete")	{ 
			//document.getElementById(targetDiv).innerHTML=xmlHttp.responseText
			if (req.targetDiv!="")
				{
				req.t = document.createElement('span');
				req.t.innerHTML = req.xmlHttp.responseText;
				document.getElementById(req.targetDiv).innerHTML="";
				document.getElementById(req.targetDiv).appendChild(req.t);
				}
			if (fnc!="")
				{
				eval(fnc);
				}
			} 
		} 
	}
	
	
	 
	function GetXmlHttpObject(handler) { 
			var objXmlHttp=null
			
			if (navigator.userAgent.indexOf("MSIE")>=0)
			{ 
				var strName="Msxml2.XMLHTTP"
				if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
				{
					strName="Microsoft.XMLHTTP"
				} 
				try
				{ 
					objXmlHttp=new ActiveXObject(strName)
					objXmlHttp.onreadystatechange=handler 
					return objXmlHttp
				} 
				catch(e)
				{ 
				alert("Error. Scripting for ActiveX might be disabled") 
				return 
				} 
			} 
			if (navigator.userAgent.indexOf("Mozilla")>=0)
			{
				objXmlHttp=new XMLHttpRequest()
				objXmlHttp.onload=handler
				objXmlHttp.onerror=handler 
				return objXmlHttp
			}
		}

//--Get Rectangular Coordinates-------------------------------------------------------
//specific element
function getPos(pos,el) {
	var x,w,y,h; 
	if (document.getBoxObjectFor) { 
		var bo = document.getBoxObjectFor(el); 
		
		x = bo.x; 
		w = bo.width;	
		y = bo.y;	
		h = bo.height;	
			} 
	else if (el.getBoundingClientRect) { 
		var rect = el.getBoundingClientRect(); 
		x = rect.left; 
		w = rect.right - rect.left;	
		y = rect.top;	
		h = rect.bottom - rect.top;	
	} 
	if (pos=='L') {	return x;	}
	else if (pos=='T') { return y; }
	else if (pos=='W') { return w; }
	else if (pos=='H') { return h; }
}	

//full window
function getWindow(a){
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
	if (a == "H") {return myHeight }
	else {return myWidth }
}

//get the location of the top visible pixel (i.e. how far down has the user scrolled?)
function getscrolltop() {
if (document.body.scrollTop==0) {
	LastPos=document.documentElement.scrollTop}	
else
	{LastPos=document.body.scrollTop}
return LastPos
}
//--Toggle element display-------------------------------------------------------
function toggleDisplayElement(el) {
	d1=document.getElementById(el);
	if (
	 d1.style.display.toLowerCase()=="none") 
	{
		d1.style.display="block";
	}
	else 
	{
		d1.style.display="none";
	}
}




