﻿
var pagevalue = "_ctl0_ContentPlaceHolder1_";
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;
var ns4 = document.layers;
var ct = 0;

function getObjectByID(Objid) {
    if (ns4) {
        return eval('document.' + Objid)
    }
    if (ns6) {
        return document.getElementById(Objid);
    }
    if (ie4) {
        return document.all(Objid);
    }
    return null
}


function SetText(objid, msg, fg, bg) {
    if (!fg) fg = "#ff0000";
    if (!bg) bg = "#FFFFFF";
    var content = msg;
    if (ns4) {
        objItm = eval('document.' + objid)
        objItm.document.write(content);
        objItm.document.close();
        objItm.visibility = "visible";
    }
    if (ns6) {
        document.getElementById(objid).innerHTML = content;
    }
    if (ie4) {
        document.all(objid).innerHTML = content;
    }
}

//Global XMLHTTP Request object
var XmlHttp;
var currentCntrl = 0


//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttpNew_left() {
    firstgo = 0
    //Creating object of XMLHTTP in IE
    try {
        XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (oc) {
            XmlHttp = null;
        }
    }
    //Creating object of XMLHTTP in Mozilla and Safari 
    if (!XmlHttp && typeof XMLHttpRequest != "undefined") {
        XmlHttp = new XMLHttpRequest();
    }

}


//Called when response comes back from server
function HandleResponseNew_left() {
    ////////////////////////////////////////////

    document.getElementById("divloadingPRINTING").innerHTML = "<img src='images/loader.gif' alt='loading' />"
    var windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
    var h = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
    var windowWidth = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
    var IpopTop = ((windowHeight - document.getElementById("divloadingPRINTING").offsetHeight) / 2);
    document.getElementById("divloadingPRINTING").style.top = (IpopTop + h) + 'px';
    document.getElementById("divloadingPRINTING").style.left = ((document.body.clientWidth / 2)) + 'px';
    document.getElementById("divloadingPRINTING").style.display = "block";

    //////////////////////////////////////////////
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {

        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {

            //alert(XmlHttp.responseXML.documentElement);
            ClearAndSetDdlItems_left(XmlHttp.responseXML.documentElement);
            //newddlcityOnChange_left();	

        }
        else {

            alert("There was a problem retrieving data from the server.");
        }
    }
}


function GetInnerTextNew_left(node) {
    return (node.textContent || node.innerText || node.text);
}

function ClearAndSetDdlItems_left(RowNode) {


    var textValue;
    var optionItem;
    var val;
    var ddlList;
    //debugger 
    if (currentCntrl == 0) {
        //alert('in currentCntrl=' + currentCntrl);
        ddlList = document.getElementById("LeftControls1_ddlState");
        document.getElementById("LeftControls1_ddlState").options.length = 0;


    }
    else if (currentCntrl == 1) {
        //alert('in currentCntrl=' + currentCntrl);
        ddlList = document.getElementById("LeftControls1_ddlCity");
        document.getElementById("LeftControls1_ddlCity").options.length = 0;
    }
    else if (currentCntrl == 2) {
        //alert('in currentCntrl=' + currentCntrl);
        ddlList = document.getElementById("LeftControls1_ddlCity");
        document.getElementById("LeftControls1_ddlCity").options.length = 0;
    }


    if (ddlList != null) {
        if (ddlList.options.length) {
            ddlList.options.length = 0;
        }
    }



    var RowNodes = RowNode.getElementsByTagName('item');



    for (var count = 0; count < RowNodes.length; count++) {
        textValue = GetInnerTextNew_left(RowNodes[count]);
        //alert(textValue);
        var value1 = RowNodes[count].getAttribute('value');
        optionItem = new Option(textValue, value1, false, false);
        ddlList.options[ddlList.length] = optionItem;
        //alert(ddlList.length);
    }

    //debugger 
    if (currentCntrl == 0) {
        if (document.getElementById("LeftControls1_ddlState")) {
            // newddlstateOnChange_left();
            newMajorddlstateOnChange_left();
        }
    }
    else if (currentCntrl == 1) {
        if (document.getElementById("LeftControls1_ddlCity")) {
            newddlcityOnChange_left()
        }
    }
    //newMajorddlstateOnChange_left
    else if (currentCntrl == 2) {
        if (document.getElementById("LeftControls1_ddlCity")) {
            newddlcityOnChange_left()
        }
    }
}
function newddlcountryOnChange_left() {
    //debugger 
    currentCntrl = 0
    //alert(currentCntrl);
    if (document.getElementById("LeftControls1_ddlCountry")) {
        var ddlcountry = document.getElementById("LeftControls1_ddlCountry");
        var countryid = ddlcountry.options[ddlcountry.selectedIndex].value;
    }
    var requestUrl = "newAjaxServer.aspx?SelectedCountry=" + encodeURIComponent(countryid);
    //var requestUrl = AjaxServerPageName + "?SelectedCountry=" + encodeURIComponent(selectedCountry);
    CreateXmlHttpNew_left();
    if (XmlHttp) {
        //Setting the event handler for the response		
        XmlHttp.onreadystatechange = HandleResponseNew_left;

        //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);
    }
}
function newddlstateOnChange_left() {
    currentCntrl = 1
    // debugger 
    //Getting the selected country from country combo box.
    if (document.getElementById("LeftControls1_ddlState")) {
        var ddlstate = document.getElementById("LeftControls1_ddlState");
        var stateid = ddlstate.options[ddlstate.selectedIndex].value;
    }

    if (document.getElementById("LeftControls1_ddlCountry")) {
        var ddlcountry = document.getElementById("LeftControls1_ddlCountry");
        var countryid = ddlcountry.options[ddlcountry.selectedIndex].value;
    }


    //alert(document.getElementById(pagevalue + "langid").value);
    // URL to get states for a given country
    var requestUrl = "newAjaxServer.aspx?SelectedCountry=" + encodeURIComponent(countryid) + "&selectedState=" + encodeURIComponent(stateid);
    ////////////var requestUrl = "newAjaxServer.aspx?&selectedflag=City&SelectedCountry=" + encodeURIComponent(countryid);
    CreateXmlHttpNew_left();
    // If browser supports XMLHTTPRequest object
    if (XmlHttp) {
        //Setting the event handler for the response
        XmlHttp.onreadystatechange = HandleResponseNew_left;

        //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);
    }
}

function newMajorddlstateOnChange_left() {
    currentCntrl = 2
    // debugger 
    //Getting the selected country from country combo box.
    if (document.getElementById("LeftControls1_ddlState")) {
        var ddlstate = document.getElementById("LeftControls1_ddlState");
        var stateid = ddlstate.options[ddlstate.selectedIndex].value;
    }

    if (document.getElementById("LeftControls1_ddlCountry")) {
        var ddlcountry = document.getElementById("LeftControls1_ddlCountry");
        var countryid = ddlcountry.options[ddlcountry.selectedIndex].value;
    }


    //alert(document.getElementById(pagevalue + "langid").value);
    // URL to get states for a given country
    /////running///// var requestUrl = "newAjaxServer.aspx?SelectedCountry=" + encodeURIComponent(countryid) + "&selectedState=" + encodeURIComponent(stateid);
    var requestUrl = "newAjaxServer.aspx?&selectedflag=City&SelectedCountry=" + encodeURIComponent(countryid);
    CreateXmlHttpNew_left();
    // If browser supports XMLHTTPRequest object
    if (XmlHttp) {
        //Setting the event handler for the response
        XmlHttp.onreadystatechange = HandleResponseNew_left;

        //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);
    }
}



function newddlcityOnChange_left() {
    //SetText(pagevalue + "ContentRate", document.getElementById(pagevalue + "ddlcert").value);
    //").value + ' certificate : ' + document.getElementById(pagevalue + "ddlcert").value)
    //document.getElementById("txtcountry").value = document.getElementById("LeftControls1_ddlCountry").value;
    document.getElementById("LeftControls1_ddlState1").value = document.getElementById("LeftControls1_ddlState").value;
    document.getElementById("LeftControls1_ddlCity1").value = document.getElementById("LeftControls1_ddlCity").value;

    document.getElementById("divloadingPRINTING").innerHTML = "";
    document.getElementById("divloadingPRINTING").style.display = "none";

}






