
//returns the GET argument when passed the key, will return false if not found
function getARG(ARGkey) {
	var URLarray = location.href.split('?');
	var ARGarray = URLarray[1].split('&');
	
	for(i=0;i<ARGarray.length;i++) {
		KeyVal = ARGarray[i].split('=');
		if(KeyVal[0]==ARGkey) return KeyVal[1];
	}
	return false;
}

function setCookie(cookieName,cookieVal) {
	nextyear = new Date();
	nextyear.setFullYear(nextyear.getFullYear() + 1);
	document.cookie = cookieName+"="+cookieVal+"; expires="+nextyear.toGMTString()+"; path=/";
}

function getCookie(cookieName) {
	cookieArr = document.cookie.split(';');
	for(i=0;i<cookieArr.length;i++) {
		KeyVal = cookieArr[i].split('=');
		if((KeyVal[0]==cookieName)||(KeyVal[0]==" "+cookieName)) return KeyVal[1];
	}
	return false; //if not found
}


function arrayList() {
	this.vals = new Array();
	for(i=0;i<arguments.length;i++) this.vals[i] = arguments[i];
}

function getCurrentPage() {
	retOption = arguments[0];
	pageArr = location.href.split("/") ;
	thisPageWithExt = pageArr[pageArr.length - 1].split("?");
	thisPageNoExt = pageArr[pageArr.length - 1].split(".");
	if(retOption == 'withExt') return thisPageWithExt[0];
	else if (retOption == 'withArgs') return pageArr[pageArr.length - 1];
	else return thisPageNoExt[0];
	
}

function checkText(theField,theForm) {
	var theString = document.forms[theForm].elements[theField].value;
	var theLength = document.forms[theForm].elements[theField].value.length;
	for (i = 0; i < theLength; i++) {
		s = theString.charCodeAt(i);
		if (((s >= 65) && (s <= 90)) || (s == 32) || ((s >= 97) && (s <= 122))) var isValid = 'yes';
		else {
			var isValid = 'no';			
			break;
			}		
		}
	if (isValid == 'no') {
		alert('You have used numeric, special or accented characters.\nPlease re-enter value using alphabetic characters only.');
		document.forms[theForm].elements[theField].value = '';
		document.forms[theForm].elements[theField].focus();
		return false;
		}
	else return true;		
	}
	
// following function disallows accented or special entries into fields

function checkNumText(theField,theForm) {
	var theString = document.forms[theForm].elements[theField].value;
	var theLength = document.forms[theForm].elements[theField].value.length;
	for (i = 0; i < theLength; i++) {
		s = theString.charCodeAt(i);
		if (((s >= 65) && (s <= 90)) || ((s >= 48) && (s <= 57)) || (s == 32) || ((s >= 97) && (s <= 122))) var isValid = 'yes';
		else {
			var isValid = 'no';			
			break;
			}		
		}
	if (isValid == 'no') {
		alert('You have used special or accented characters.\nPlease re-enter value using alphanumeric characters only.');
		document.forms[theForm].elements[theField].value = '';
		document.forms[theForm].elements[theField].focus();
		}	
	}		
		
// following function only allow numeric entry into certain fields

function checkNum(theField,theForm) {
	var s = document.forms[theForm].elements[theField].value;
	if(s=='.') ;
	else if (isNaN(s)) {
		document.forms[theForm].elements[theField].focus();
		if (isNaN(parseInt(s))) 
			document.forms[theForm].elements[theField].value = '';
		else	
			document.forms[theForm].elements[theField].value = parseInt(s);
		}
	}

//following function creates new popup window

function goPopupExt(myUrl,myWidth,myHeight, scrollbars) {
	//now = new Date();
	popup = window.open(myUrl,'thenewWin','top=50,left=50,toolbar=no,location=no,directories=no,status=no,resizable=yes,copyhistory=no,width=' + myWidth + ',height=' + myHeight + ',scrollbars=' + scrollbars);
	popup.focus();
	}

function goPopupExt(myUrl,myWidth,myHeight, scrollbars,winName) {
	//now = new Date();
	popup = window.open(myUrl,winName,'top=50,left=50,toolbar=no,location=no,directories=no,status=no,resizable=yes,copyhistory=no,width=' + myWidth + ',height=' + myHeight + ',scrollbars=' + scrollbars);
	popup.focus();
	}
	
function boxedImage(imName,imWidth,imHeight,imAlign,styleArgs) {
	theInfo =  "<table border=0 cellpadding=5 cellspacing=0 align="+imAlign+" ><tr><td><table border=0 cellpadding=0 cellspacing=0 width=imWidth background=\"images/"+imName+"\" "+styleArgs+">";
	theInfo += "<tr><td width=9 height=9><img src=\"images/box_topleft.gif\" width=9 height=9></td>";
	theInfo += "<td width="+eval(imWidth-18)+" height=9><img src=\"images/box_top.gif\" width="+eval(imWidth-18)+" height=9></td>";
	theInfo += "<td width=9 height=9><img src=\"images/box_topright.gif\" width=9 height=9></td></tr>";	
	theInfo += "<tr><td height="+eval(imHeight-18)+" width=9><img src=\"images/box_left.gif\" height="+eval(imHeight-18)+" width=9></td>";
	theInfo += "<td>&nbsp;</td>";
	theInfo += "<td height="+eval(imHeight-18)+" width=9><img src=\"images/box_right.gif\" height="+eval(imHeight-18)+" width=9></td></tr>";
	theInfo += "<tr><td width=9 height=9><img src=\"images/box_bottomleft.gif\" width=9 height=9></td>";
	theInfo += "<td width="+eval(imWidth-18)+" height=9><img src=\"images/box_bottom.gif\" width="+eval(imWidth-18)+" height=9></td>";
	theInfo += "<td width=9 height=9><img src=\"images/box_bottomright.gif\" width=9 height=9></td></tr></table></td></tr></table>";
	document.write(theInfo);
}	

function swapImages(imName,imSrc) {
	document.images[imName].src = imSrc;
	return true;
}


var timer; 

function ShowFromBase() {

	if(timer) clearTimeout(timer);
	if(document.getElementById(arguments[0]).style.visibility=='visible') return;
	else {
		/*
		if(arguments[0]=='indoors_menu') {
			pageWidth = document.body.offsetWidth;
			if(pageWidth < 787) pageWidth = 787;
			newLeft = (pageWidth/100) * 18 + 5;
			document.getElementById(arguments[0]).style.left = newLeft;	
			
		}
		*/
		for(i=0;i<topPages.length;i++) {
			
			document.getElementById(topPages[i]).style.visibility='hidden';
		}
		for(i=0;i<arguments.length;i++) {
			
			if(navigator.appName=='Microsoft Internet Explorer') {
				document.getElementById(arguments[i]).filters.revealTrans.apply();
				document.getElementById(arguments[i]).filters.revealTrans.play();
			}
			
			document.getElementById(arguments[i]).style.visibility='visible';
			
		}
	}
	


}

function Show() {
	if(timer) clearTimeout(timer);
	for(i=0;i<topPages.length;i++) {
		document.getElementById(topPages[i]).style.visibility='hidden';
	}
	for(i=0;i<arguments.length;i++) {
		document.getElementById(arguments[i]).style.visibility='visible';
	}

}



function Hide() { timer = setTimeout("Show()", 100); }


//Ajax requesting
var http_request = false;

function makeRequest(url) {
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
     http_request = new XMLHttpRequest();
     if (http_request.overrideMimeType) {
     	// set type accordingly to anticipated content type
        //http_request.overrideMimeType('text/xml');
        http_request.overrideMimeType('text/html');
     }
  } else if (window.ActiveXObject) { // IE
     try {
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
        try {
           http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
     }
  }
  if (!http_request) {
     alert('Cannot create XMLHTTP instance');
     return false;
  }
  http_request.onreadystatechange = alertContents;
  http_request.open('GET', url, true);
  http_request.send(null);
}

function alertContents() {
  if (http_request.readyState == 4) {
     if (http_request.status == 200) {
        //alert(http_request.responseText);
        result = http_request.responseText;
        //processResults function is unique to page
        processResults(result);          
     } else {
        alert('There was a problem with the request.');
     }
  }
}


//encode/decode base64


var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

function decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}


	