﻿// JScript File

var xmlHttp=null;
var ZipCode = '';
function ExecuteCityCall(zip)
{
    ZipCode = zip;  
    var url = '/ZipCodeSearchAjax.aspx?Value=' + zip;
    try 
    { 
        xmlHttp = GetXmlHttpObject(CallBackMethod); 
        SendXmlHttpRequest(xmlHttp, url); 
    }
    catch(e){} 
} 

function CallBackMethod() 
{ 
    var result = null;
    try
    {
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	    { 
	        //get the results from the callback 
            result =  xmlHttp.responseText;
            SetValues(result);
	    }
    }   
    catch(e) {} 
} 
					
function GetXmlHttpObject(Handler)
{ 
    var oXmlHttp=null;
   
   if (navigator.userAgent.indexOf("Opera")>=0)
	{
	    alert("This doesn't work in Opera"); 
		return; 
	}
	
    if(window.XMLHttpRequest)
    {
        //For IE7, Mozilla, Safari & Netscape. 
        try
        {
            oXmlHttp=new XMLHttpRequest();
            if (navigator.userAgent.indexOf("MSIE")>=0 && navigator.appVersion.indexOf("MSIE 7.0")>=0)
            {
                oXmlHttp.onreadystatechange=Handler;
            }
            else
            {
		        oXmlHttp.onload=Handler;
		        oXmlHttp.onerror=Handler;
		    }
		    return oXmlHttp; 
		} 
		catch(e)
		{ 
		    alert("Unable to create XMLHttpRequest!"); 
		    return null; 
		} 
    }
    
    if(window.ActiveXObject)
    {
        //For < IE7 
        try
        {
            oXmlHttp = GetMSXmlHttp();
            oXmlHttp.onreadystatechange=Handler;
			return oXmlHttp;
        }
        catch(e)
        {
            alert("Unable to create ActiveX OR ActiveX might be disabled!");
            return null; 
        }
    }
}	

function GetMSXmlHttp()
{
    var xmlHttp = null;
    var clsIds = ["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP.2.6","Msxml2.XMLHTTP","Microsoft.XMLHTTP.1.0","Microsoft.XMLHTTP.1","Microsoft.XMLHTTP"];
                  
    for(var i=0; i<clsIds.length && xmlHttp == null; i++)
    {
        xmlHttp = CreateXmlHttp(clsIds[i]);
    }
    return xmlHttp;
}

function CreateXmlHttp(clsIds)
{
    var xmlHttp = null;
    
    try
    {
        xmlHttp = new ActiveXObject(clsIds);  
        return xmlHttp;      
    }
    catch(e)
    {
        return null;
    }
}               
					
function SendXmlHttpRequest(xmlhttp, url)
{ 
    xmlhttp.open('GET', url, true); 
    xmlhttp.send(null); 
}

function SetValues(Data)
{
    if(Data.replace(/^\s+|\s+$/g, '') != "badzip") {
    window.location= '/zipcodes/' + Data + '-' + ZipCode.replace(/^\s+|\s+$/g, '') + '.htm';    
    } else {
        window.location="/read-reviews.htm";
    }
}

