var xmlHttp;
function getObject(objName)
{
	var theObj;
	if(document.getElementById(objName))
	{
		theObj = document.getElementById(objName);	
	}
	if(document.all) 
	{
		theObj=document.getElementById? document.getElementById(objName):document.all.objName;
        }
	else if (eval("document." + objName) != null)
	{
        	theObj = eval("document." + objName);
        }	
      return theObj;
}

function installZipCode(dealerId,zip)
{
	this.dealerId = dealerId;
	this.zip = zip;
}

function checkZip()
{
	var installerId = "";
	installerId = findInstallerId(getObject("txtZip").value);
	if(installerId != "")
	{
		showInstallerFoundDiv();
       //moreInfo();
      // hideInstallBoxDiv();
     }
     else
     {
       showSorryDiv();
     }
    sendData("updateInstallAddTracker.aspx", "trackingType=adClicks&zipCode=" + getObject("txtZip").value);
    getObject("txtZip").value = "";
       
}

function showSearchDiv()
{
	getObject("divSorry").style.visibility = "hidden";
	getObject("divInstallerFound").style.visibility = "hidden";
	getObject("divInstallBox").style.visibility = "visible";
	getObject("divSearch").style.visibility = "visible";
	
}

function validateInstaller(installerId)
{
	//if installer id is default, 
	// show the installer found layer, else check the zip code
	if(installerId == '0')
	{
		showInstallerFoundDiv();
	}
	else
	{
		showSearchDiv()
	}
	
}

function showSorryDiv()
{
	getObject("divSearch").style.visibility = "hidden"
	getObject("divInstallerFound").style.visibility = "hidden";
	getObject("divSorry").style.visibility = "visible";
	getObject("divInstallBox").style.visibility = "visible";
	setCookie("install_program_info","no",365)

}

function hideInstallBoxDiv()
{
	getObject('divInstallBox').style.visibility = 'hidden';
	getObject("divSearch").style.visibility = "hidden";
	getObject("divInstallerFound").style.visibility = "hidden";
	getObject("divSorry").style.visibility = "hidden";
}


function showInstallerFoundDiv()
{
	
	getObject("divSearch").style.visibility = "hidden"
	getObject("divSorry").style.visibility = "hidden";
	getObject('divInstallBox').style.visibility = 'visible';
	getObject("divInstallerFound").style.visibility = "visible";
	sendData("updateInstallAddTracker.aspx", "trackingType=installImpression&zipCode=" + getObject("txtZip").value);
   
}

function moreInfo()
{
	var newWin = window.open('InstallationProgram.aspx','cusWin','width=680,height=625,scrollbars=no,menubars=no,alwaysRaised=yes');
	if (newWin==null || typeof(newWin)=="undefined")
	{
		alert("Our system has detected that your popupup blocker\nis preventing you from viewing the item you clicked on!");
	}
	
	if (window.focus) 
	{
		if(newWin)
		{
			newWin.focus();
		}
	}
	return false;
}

function findInstallerId(zip)
{
	for(var i=0; i < installZipCodesArray.length; i++)
	{
		if(installZipCodesArray[i].zip == zip)
		{
			return installZipCodesArray[i].dealerId;
			break;
		}
	}
	return "";
}

function setCookie(cookieName,cookieValue,expireDays)
{
	var expirationDate=new Date();
	expirationDate.setDate(expirationDate.getDate() + expireDays);
	//document.cookie = 'install_program_info=no; expires=Thu, 2 Aug 2001 20:47:11 UTC; path=/'
	document.cookie=cookieName + "=" + escape(cookieValue) + ((expireDays==null) ? "" : ";expires=" + expirationDate.toGMTString());
}

function sendData(page,nameValuePairs){ 
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
 {
  alert ("Browser does not support HTTP Request");
  return;
 } 
 var url=page;
 url=url+"?"+nameValuePairs;
 url=url+"&rnd="+Math.random();
 //xmlHttp.onreadystatechange=stateChanged;
 xmlHttp.open("POST",url,true);
 xmlHttp.send(null);
}
 /*
function stateChanged() { 
 showLayer("autoSaveProgLayer");
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
  //debug(xmlHttp.responseText);
  } 
} 
 */
function GetXmlHttpObject(){ 
 var objXMLHttp=null;
 if (window.XMLHttpRequest){
  objXMLHttp=new XMLHttpRequest();
 }else if (window.ActiveXObject){
  objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
 return objXMLHttp;
}

 

