//Global XMLHTTP Request object
var weatherserviceuri = "TodayWeather.ashx?cid=";

var WEATHER_DIV_ID;
WEATHER_DIV_ID = "weatherdiv";

var DIV_ERROR_ID;
DIV_ERROR_ID = "errordiv";


var ERROR_MESSAGE;
ERROR_MESSAGE = "Error Accessing the weather Service. Please try again Later."

var MENU_1;
var MENU_2;
var MENU_3;

//Gets called when country combo box selection changes
function DisplayWeather(cityname, divelementid) {


    if (cityname == null || cityname.length <= 0)
        return;

    var splitcityname = cityname.split(" ");

    if (splitcityname != null && splitcityname.length >= 1)
        cityname = splitcityname[0];

    if (divelementid != null)
        WEATHER_DIV_ID = divelementid

    
    ProgressStart();
    // URL to get states for a given country
    var requestUrl = weatherserviceuri + cityname;
    //alert(requestUrl);
    CreateXmlHttp();
    // If browser supports XMLHTTPRequest object
    if (XmlHttp) {
        //Setting the event handler for the response
        XmlHttp.onreadystatechange = HandleResponse;
        //Initializes the request object with GET (METHOD of posting), 
        //Request URL and sets the request as asynchronous.
        XmlHttp.open("GET", requestUrl, true);
        
        //Sends the request to server
        XmlHttp.send(null);
    }
}

//Called when response comes back from server
function HandleResponse() {
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        ProgressEnd();
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            var weatherdiv = document.getElementById(WEATHER_DIV_ID);
            
            if (weatherdiv != null)
                weatherdiv.innerHTML = XmlHttp.responseText;
            //select_innerHTML('ddlcreditor', XmlHttp.responseText);
            //SetDataEntryVisible(true);
                   
        }
        else {
            DisplayErrorMessage(ERROR_MESSAGE);
        }
        XmlHttp = null;
    }
}

function ProgressStart() {
    return;
}

function ProgressEnd() {
    return;
}

function DisplayErrorMessage(errormessage) {
    var div = document.getElementById(WEATHER_DIV_ID);
    if (div != null)
        div.innerHTML = "<span style='FONT-SIZE: 14px; COLOR: red; FONT-VARIANT: normal'>" + errormessage + "</span>";

    //SetDataEntryVisible(false);
}

