function GetHTTPRequest(call, onreadystatechange) {
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		try {
			req.onreadystatechange = onreadystatechange;
     		req.open("GET", call , true);     	
			req.send(null);
   		} catch (e) {
   	  		alert(e);
   		}
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = onreadystatechange;
			req.open("GET", call, true);
			req.send();
		}
	}
}

function PostHTTPRequest(script, call, onreadystatechange) {
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		try {
			req.onreadystatechange = onreadystatechange;
			req.open("POST", script, true);
			req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			req.send(call);
		} catch (e) {
   	  		alert(e);
   		}
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = onreadystatechange;
			req.open("POST", script, true);
			req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			req.send(call);
		}
	}
}

function ValidateUser(){
	if(GEBI("username").value == "" || GEBI("password").value == ""){
		ShowBlock("LoginError");
	} else {
		Hide("LoginError");
		PostHTTPRequest("HTTPRequests/ValidateUser.php", "username="+GEBI("username").value+"&password="+GEBI("password").value+"&webpageid="+GEBI("webpageid").value, ValidateUser_ProcessStateChange);
	}
}

function ValidateUser_ProcessStateChange() {
	if (req.readyState == 4) {
    	if (req.status == 200) {
			if(req.responseText == "1"){
				window.location.href = GEBI("protectedpage").value;
			} else {
				ShowBlock("LoginError");
			}
		}
	}
}

function ShowProcessingRequest( Text ){
	GEBI("ProcessingRequest").innerHTML = Text;
	ShowBlock("ProcessingRequest");
}

function HideProcessingRequest(){
	Hide("ProcessingRequest");
}

function ShowBlock( Obj ){
	document.getElementById(Obj).style.display = "block";
}
function ShowInline( Obj ){
	document.getElementById(Obj).style.display = "inline";
}
function Hide( Obj ){
	document.getElementById(Obj).style.display = "none";
}
function Disable( Obj ) {
	document.getElementById(Obj).disabled = true;
}
function Enable( Obj ) {
	document.getElementById(Obj).disabled = false;
}
// Get element by ID
function GEBI( Obj ){
	return document.getElementById(Obj);
}

startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}



function FormatPhoneNbr(str) {
	re = /[\D]+/gi;
	return str.replace(re, '');
}


function stripSearch() {
	if(document.search.words.value == 'Search Site'){
		document.search.words.value = ''; 
	}
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

function popuplink(status,height,width,url) 
{
	var popup;
	var popup_window;
    if(status == 1 && popup == null) 
    { 
		    var popup = open(url, "", "width=" + width + ",height=" + height + ",screenX=0,screenY=0,top=0,left=10,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
    		popup_window = popup; 
		}
    
    if (status == 1 && popup != null)
    { 
			  popup.focus(); 
		}
    
    if (status == 0) 
    { 
		    popup_window.close(); 
		}
}

//form functions
function CheckBoxDivToggle(checkboxID, divID){
	if(GEBI(checkboxID).checked == true){
		ShowBlock(divID);
	} else {
		Hide(divID);
	}
}

//acceptedValues is comma seperated
function SelectBoxDivToggle(selectboxID, acceptedValues, divID){
	flag = false
	value = acceptedValues.split(',');
	for(i = 0; i < value.length; i++){
		if(GEBI(selectboxID).value == value[i]){
			flag = true;
		}
	}
	if(flag){
		ShowBlock(divID);
	} else {
		Hide(divID);
	}
}

//acceptedValues and divIDs are comma seperated and must match (i.e. value1 shows div1 and hides rest)
//use nodiv for the divID if a value should hide all divIDs
function SelectBoxMultiDivToggle(selectboxID, acceptedValues, divIDs){
	value = acceptedValues.split(',');
	div = divIDs.split(',');
	for(i = 0; i < value.length; i++){
		if(GEBI(selectboxID).value == value[i]){
			ShowBlock(div[i]);
		} else if(div[i] != "nodiv"){
			Hide(div[i]);
		}
	}
}	

function CheckPostContactForm()
{
	if (document.contact.name.value == "")
  {
    alert("Please enter your full name in the \"Name\" field.");
    document.contact.name.focus();
    return (false);
  }
  
	if (document.contact.email.value == "")
  {
    alert("Please enter your email in the \"Email\" field.");
    document.contact.email.focus();
    return (false);
  }
	
	call = "HTTPRequests/contact_us.php";
	querystring = "Action=Submit&name=" + GEBI("name").value +"&email=" + GEBI("email").value + "&phone=" + GEBI("phone").value + "&cell=" + GEBI("cell").value + "&comment=" + GEBI("comment").value;
	PostHTTPRequest(call, querystring, CheckPostContactForm_ProcessStateChange);

}

function CheckPostContactForm_ProcessStateChange(){
	if (req.readyState == 4) {
		if (req.status == 200) {		
				Hide("contactusform");
				ShowBlock("contactusformmessage");
				GEBI("contactusresult").innerHTML = req.responseText;
		}
	}
}

