﻿function _openResults(countryCID, stateCID, cityCID, zipCID, distanceCID, GoogleAPIKey, pageURL, chosenSiteId, instanceId, stateCode) {    
    var countryID = $("#" + countryCID).val(); 
    var Country = $("#" + countryCID).val();   
    var stateID = $("#" + stateCID).val();
    var cityID = $("#" + cityCID).val();
    var Zip = $("#" + zipCID).val();
    var distance = $("#" + distanceCID).val();
    
                        
    if ( $("#" + countryCID).length == 0) {
        //country is hidden - asume United States
        Country = "United States";
        countryID = 0;   
        
    }
    
    if ( $("#" + stateCID).length == 0) 
        stateID = 0;
    
    if ( $("#" + cityCID).length == 0) 
        cityID = 0;
    
    if ( $("#" + zipCID).length ==0 ) {
        Zip = "";
    }
    
    if ( $("#" + distanceCID).length == 0) {
        distance = 0;
    }
    
    /*
    if (stateCode == "") {
    if (!validateForm(zipCID))
        return false;
    }
    */
        
    var lat = 0, lon = 0;
    if (Zip != "" && GoogleAPIKey != "") {
        var resCoord = AjaxMethods.GetCoordinatesForMap(Zip,
                        Country,
                        GoogleAPIKey)
        
        
        if (resCoord.error == null) {
            lat = resCoord.value[0];
            lon = resCoord.value[1];
        } else {
            window.alert("An error ocurred searching for the coordinates");
        }
    }
    var config = 'width=1000,height=1000,status=yes,toolbar=no';
    
    //read the info from the js
    
    var params = "{0}?sid={1}&cc={2}&s={3}&c={4}&d={5}&la={6}&lo={7}&zip={8}&countryText={9}&gak={10}";
    params += "&parentStateCID={11}&parentCityCID={12}&instanceId={13}&stateCode={14}";
    
    
    
    params = params.replace("{0}", pageURL);
    params = params.replace("{1}", chosenSiteId);   //sid
    params = params.replace("{2}", countryID);      //cc
    params = params.replace("{3}", stateID );       //s
    params = params.replace("{4}", cityID );        //c
    params = params.replace("{5}", distance );      //d
    params = params.replace("{6}", lat);            //la
    params = params.replace("{7}", lon);            //lo
    params = params.replace("{8}", Zip);            //zip
    params = params.replace("{9}", Country);        //countryText
    params = params.replace("{10}", GoogleAPIKey);  //gak
    params = params.replace("{11}", stateCID);  //parentStateCID
    params = params.replace("{12}", cityCID);  //parentCityCID
    params = params.replace("{13}", instanceId);  //instanceId
    params = params.replace("{14}", stateCode);  //instanceId
    


    //window.open(params, 'StoreLocatorMap', config);
    tb_show('StoreLocatorMap', params + '&KeepThis=true&TB_iframe=true&height=600&width=800&modal=true');      
    
    return false;
}

function ResetDropDown(ddlCID) {
    var ddl = parent.document.getElementById(ddlCID);
    ddl.selectedIndex = 0;
}

function ResetZipCode(zipCID) {
    $("#" + zipCID).val("");

}

function validateForm(zipCID) {
    var ZIP = $("#" + zipCID).val();
    
    if (ZIP == "") {
        window.alert("Please enter a ZIP code");
        return false;
    }
    
    return true;
}

function sndReqBKP(state)
{
    var ddl = $("#" + m_ddlState)[0];
    var hdd = $("#fromMap")[0];

    if (ddl == null || typeof statesArray == "undefined") {
        //we are not showing the state, need to use the querystring
        window.location.href = window.location.pathname + "?sn=" + state;
    } else {
        //set the hidden to indicate that we are using it from the map
        hdd.value = "1";

        var stateid = statesArray[state];
        if (stateid == null) {
            alert("We don't have any information for the state " + state);
            return;
        }
        ddl.value = stateid;
        ddl.onchange();
    }
}

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();