//Fix for Goggle Toolbar adjusting style
function correctGoogle(){
	inputList = document.getElementsByTagName("INPUT");
	for(i=0;i<inputList.length;i++){
	  inputList[i].style.backgroundColor = "";
	  if (inputList[i].id != "checkbox") {
	  	inputList[i].className = "textbox";
	  }
	}
	selectList = document.getElementsByTagName("SELECT");
	for(i=0;i<selectList.length;i++){
	  selectList[i].style.backgroundColor = "";
	  selectList[i].className = "textbox";
	}
}
//End Fix
function swapDiv() { 
	var i = document.getElementById("info");
	var f = document.getElementById("form");
	
	if (f.style.display == "none") {
		i.style.display = "none";
		f.style.display = "block";
	} else {
		i.style.display = "block";
		f.style.display = "none";
	}
}

function login() {
	var myWin = window.open("login.php","myWin","menubar=0,scrollbars=0,toolbar=0,resizable=0,location=0,status=0,directories=0,width=250,height=130");
	var vp = getViewPort();
	myWin.moveTo((vp[0]*.65),150);
}

function getViewPort() {
	var viewportwidth;
	var viewportheight;
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined')
	{
	  viewportwidth = window.innerWidth,
	  viewportheight = window.innerHeight
	}
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined'
	 && typeof document.documentElement.clientWidth !=
	 'undefined' && document.documentElement.clientWidth != 0)
	{
	   viewportwidth = document.documentElement.clientWidth,
	   viewportheight = document.documentElement.clientHeight
	}
	// older versions of IE
	else
	{
	   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	   viewportheight = document.getElementsByTagName('body')[0].clientHeight
	} 
	return [viewportwidth , viewportheight];
}

/*-------------------------------------------------------------------------------------------------------------------------------------
AJAX STUFF
-------------------------------------------------------------------------------------------------------------------------------------*/
var xmlHttp;
function GetXmlHttpObject() {
   xmlHttp=null;
   try{
       // Firefox, Opera 8.0+, Safari
       xmlHttp=new XMLHttpRequest();
   }
   catch(e){
       //IE
           try{
               xmlHttp=new ActiveXObject("Msxml2.xmlHttp");
           }
           catch(e){
               xmlHttp=new ActiveXObject("Microsoft.xmlHttp");
           }
       }
   if (xmlHttp == null){
       alert("Your Browser does not support AJAX!");
       return;
   }
   return xmlHttp;
}
function submitForm(){
   xmlHttp=GetXmlHttpObject();
   var d = document.theForm;
   
   var fname = d.Contact0FirstName.value;
   var lname = d.Contact0LastName.value;
   var email = d.Contact0Email.value;
   var fid = d.fid.value;
   
   var zip   = document.getElementById('zip').value;
   var phone = document.getElementById('phone').value;
   var src  = document.getElementById('src').value;
   
   var url  = "server/addclient.php";
       url += "?f="+fname;
	   url += "&l="+lname;
	   url += "&e="+email;
	   url += "&z="+zip;
	   url += "&p="+phone;
	   url += "&fid="+fid;
	   url += "&src="+src;

   xmlHttp.onreadystatechange=StateChanged;
   xmlHttp.open("Get",url,true);
   xmlHttp.send(null);
}

function addHit() {
	xmlHttp=GetXmlHttpObject();
	var d = document.theForm;
	
	var fid = d.fid.value;
	var url  = "server/addHit.php";
	url += "?fid="+fid;
	
	xmlHttp.onreadystatechange=StateChanged;
	xmlHttp.open("Get",url,true);
	xmlHttp.send(null);
	
}
function StateChanged(){
   if (xmlHttp.readyState==4){
	   switch (xmlHttp.responseText) {
			case "true": document.theForm.submit();
						 //alert("Submitted");
						 break;
		 	case "added": addHit();
			              break;
			
			default: alert(xmlHttp.responseText);
	   }
	}
}
