var City;
var State;
var ZipCode;
var CityZipColumnModel;
var CityZipListingGrid;
var pag_ZipSearch;
var pag_ConSearch;
Ext.onReady(function() {
    var H; var K; var I; var O;
    var M = 1; Ext.QuickTips.init();
    var J = Ext.get("btnSearch");
    pag_ConSearch = new Ext.data.Store({
        id: "pag_ConSearch",
        proxy: new Ext.data.HttpProxy({
            url: "GSIDataFetch.aspx",
            method: "POST"
        }),
        baseParams: { methodName: "GSI" },
        reader: new Ext.data.JsonReader({
            root: "GSIDealer",
            totalProperty: "total",
            id: "id"
        },
        [
            { name: "DealerId" },
            { name: "DealerName" },
            { name: "Distance" },
            { name: "City" },
            { name: "State" },
            { name: "address1" },
            { name: "address2" }, { name: "phone" },
            { name: "fax" },
            { name: "email" },
            { name: "zip" },
            { name: "websiteaddress" },
            { name: "sitestatus" },
            { name: "PreferredDealer" }
         ]),
        remoteSort: false,
        autoExpandColumn: "DealerName"
    });

    function L(B) {
        B = B.replace(/</g, "*abc*");
        B = B.replace(/&#/g, "*bcd*");
        return B
    }

    function N(B) {
        return L(document.getElementById(B).value)
    }

    function G(B) {
        return document.getElementById(B).checked
    }

    J.on("click", function() {
        if (N("ddCountry") == 0) {
            Ext.MessageBox.show({
                title: "Information",
                msg: "Please select Country!",
                width: 325,
                buttons: Ext.MessageBox.OK, icon: Ext.MessageBox.INFO
            });
        }
        else {
            if (N("ddCountry") == "US" || N("ddCountry") == "CA") {
                if (N("ddTypeOfOperation") == 0) {
                    Ext.MessageBox.show({
                        title: "Information",
                        msg: "Please select Type of Operation!",
                        width: 325,
                        buttons: Ext.MessageBox.OK, icon: Ext.MessageBox.INFO
                    })
                }
                else {
                    if (N("ddProductCategory") == 0) {
                        Ext.MessageBox.show({
                            title: "Information",
                            msg: "Please select Product Category!",
                            width: 325,
                            buttons: Ext.MessageBox.OK, icon: Ext.MessageBox.INFO
                        })
                    }
                    else {
                        if (N("ddProductType") == 0 && N("ddProductCategory") != 1) {
                            Ext.MessageBox.show({
                                title: "Information",
                                msg: "Please select Product Type!",
                                width: 325, buttons: Ext.MessageBox.OK,
                                icon: Ext.MessageBox.INFO
                            })
                        }
                        else {
                            if (N("txt_City") == "" && N("txt_Zip") == "") {
                                Ext.MessageBox.show({
                                    title: "Information",
                                    msg: "Please enter either City or Zip/Postal Code!",
                                    width: 325,
                                    buttons: Ext.MessageBox.OK,
                                    icon: Ext.MessageBox.INFO
                                })
                            }
                            else {
                                Country = N("ddCountry");
                                City = N("txt_City");
                                State = (N("ddCountry") == "US" || N("ddCountry") == "CA") ? N("txt_State") : "";
                                ZipCode = (N("ddCountry") == "US" || N("ddCountry") == "CA") ? N("txt_Zip") : "";
                                Ext.MessageBox.show({
                                    title: "Validating",
                                    msg: "Validating City, State  & Zip/Postal Code, please wait...",
                                    progressText: "Validating...",
                                    width: 400,
                                    wait: true,
                                    waitConfig: { interval: 200 },
                                    icon: "ext-mb-download",
                                    animEl: "btn_Search"
                                });
                                pag_ZipSearch = new Ext.data.Store({
                                    id: "pag_ZipSearch",
                                    proxy: new Ext.data.HttpProxy({ url: "GSIDataFetch.aspx", method: "POST" }),
                                    baseParams: { methodName: "GSI_ZipSearch" },
                                    reader: new Ext.data.JsonReader(
                                        { root: "GSIDealer", totalProperty: "total", id: "id" },
                                        [
                                            { name: "zip" },
                                            { name: "city" },
                                            { name: "state" },
                                            { name: "country" }
                                        ]
                                    ),
                                    sortInfo: { field: "city", direction: "ASC" },
                                    remoteSort: false
                                });

                                var B = new Ext.grid.CheckboxSelectionModel({ header: "", width: 20 });
                                CityZipColumnModel = new Ext.grid.ColumnModel([B,
                                    { id: "zip", header: "Zip/Postal Code", dataIndex: "zip", sortable: true, width: 100 },
                                    { id: "city", header: "City", dataIndex: "city", sortable: true, width: 150 },
                                    { id: "state", header: "State", dataIndex: "state", sortable: true, width: 50 },
                                    { id: "country", header: "country", dataIndex: "country", sortable: true, width: 150 }
                                    ]);
                                CityZipColumnModel.defaultSortable = true;
                                CityZipListingGrid = new Ext.grid.GridPanel({
                                    id: "CityZipListingGrid",
                                    title: "",
                                    store: pag_ZipSearch,
                                    cm: CityZipColumnModel,
                                    enableColLock: false,
                                    width: 500,
                                    height: 380,
                                    loadMask: true,
                                    autoExpandColumn: "city",
                                    viewConfig: { forceFit: true },
                                    selModel: new Ext.grid.RowSelectionModel({ singleSelect: true })
                                });
                                pag_ZipSearch.load({
                                    params: {
                                        start: 0,
                                        limit: 15,
                                        p1_City: N("txt_City"),
                                        p2_State: (N("ddCountry") == "US" || N("ddCountry") == "CA") ? N("txt_State") : "",
                                        p3_Zip: (N("ddCountry") == "US" || N("ddCountry") == "CA") ? N("txt_Zip") : "",
                                        p4_Country: N("ddCountry")
                                    }
                                });

                                K = new Ext.Window({
                                    title: "Dealer Locator : City, State and Zip/Postal Code List",
                                    modal: true,
                                    height: 450,
                                    width: 515,
                                    items: [new Ext.Panel({ items: [CityZipListingGrid] })],
                                    buttons: [{ text: "OK", handler: function() { D() } }]
                                });
                                CityZipListingGrid.on("rowdblclick", D, CityZipListingGrid);
                                pag_ZipSearch.on("load", P, CityZipListingGrid)
                            }
                        }
                    }
                }
            }
            else {
                E();
            }
        }
    });

    function P() {
        Ext.MessageBox.hide();
        if (CityZipListingGrid.store.getTotalCount() == 1)
        //pag_ConSearch=new Ext.data.Store({id:"pag_ConSearch",proxy:new Ext.data.HttpProxy({url:"http://locator.gsiag.com/gsi/GSIDataFetch.aspx",method:"POST"}),baseParams:{methodName:"GSI"},reader:new Ext.data.JsonReader({root:"GSIDealer",totalProperty:"total",id:"id"},[{name:"DealerId"},{name:"DealerName"},{name:"Distance"},{name:"City"},{name:"State"},{name:"address1"},{name:"address2"},{name:"phone"},{name:"fax"},{name:"email"},{name:"zip"},{name:"websiteaddress"},{name:"sitestatus"}]),remoteSort:false,autoExpandColumn:"DealerName"});function L(B){B=B.replace(/</g,"*abc*");B=B.replace(/&#/g,"*bcd*");return B}function N(B){return L(document.getElementById(B).value)}function G(B){return document.getElementById(B).checked}J.on("click",function(){if(N("ddTypeOfOperation")==0){Ext.MessageBox.show({title:"Information",msg:"Please select Type of Operation!",width:325,buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.INFO})}else{if(N("ddProductCategory")==0){Ext.MessageBox.show({title:"Information",msg:"Please select Product Category!",width:325,buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.INFO})}else{if(N("ddProductType")==0&&N("ddProductCategory")!=1){Ext.MessageBox.show({title:"Information",msg:"Please select Product Type!",width:325,buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.INFO})}else{if(N("txt_City")==""&&N("txt_Zip")==""){Ext.MessageBox.show({title:"Information",msg:"Please enter either City or Zip/Postal Code!",width:325,buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.INFO})}else{City=N("txt_City");State=N("ddState");ZipCode=N("txt_Zip");Ext.MessageBox.show({msg:"Validating City, State  & Zip/Postal Code, please wait...",progressText:"Validating...",width:400,wait:true,waitConfig:{interval:200},icon:"ext-mb-download",animEl:"btn_Search"});pag_ZipSearch=new Ext.data.Store({id:"pag_ZipSearch",proxy:new Ext.data.HttpProxy({url:"GSIDataFetch.aspx",method:"POST"}),baseParams:{methodName:"GSI_ZipSearch"},reader:new Ext.data.JsonReader({root:"GSIDealer",totalProperty:"total",id:"id"},[{name:"zip"},{name:"city"},{name:"state"},{name:"country"}]),sortInfo:{field:"city",direction:"ASC"},remoteSort:false});var B=new Ext.grid.CheckboxSelectionModel({header:"",width:20});CityZipColumnModel=new Ext.grid.ColumnModel([B,{id:"zip",header:"Zip/Postal Code",dataIndex:"zip",sortable:true,width:100},{id:"city",header:"City",dataIndex:"city",sortable:true,width:150},{id:"state",header:"State",dataIndex:"state",sortable:true,width:50},{id:"country",header:"country",dataIndex:"country",sortable:true,width:150}]);CityZipColumnModel.defaultSortable=true;CityZipListingGrid=new Ext.grid.GridPanel({id:"CityZipListingGrid",title:"",store:pag_ZipSearch,cm:CityZipColumnModel,enableColLock:false,width:500,height:380,loadMask:true,autoExpandColumn:"city",viewConfig:{forceFit:true},selModel:new Ext.grid.RowSelectionModel({singleSelect:true})});pag_ZipSearch.load({params:{start:0,limit:15,p1_City:N("txt_City"),p2_State:N("ddState"),p3_Zip:N("txt_Zip")}});K=new Ext.Window({title:"Dealer Locator : City, State and Zip/Postal Code List",modal:true,height:450,width:515,items:[new Ext.Panel({items:[CityZipListingGrid]})],buttons:[{text:"OK",handler:function(){D()}}]});CityZipListingGrid.on("rowdblclick",D,CityZipListingGrid);pag_ZipSearch.on("load",P,CityZipListingGrid)}}}}});function P(){Ext.MessageBox.hide();if(CityZipListingGrid.store.getTotalCount()==1)
        //pag_ConSearch=new Ext.data.Store({id:"pag_ConSearch",proxy:new Ext.data.HttpProxy({url:"C:\DealerLocator\DealerLocator\GSI",method:"POST"}),baseParams:{methodName:"GSI"},reader:new Ext.data.JsonReader({root:"GSIDealer",totalProperty:"total",id:"id"},[{name:"DealerId"},{name:"DealerName"},{name:"Distance"},{name:"City"},{name:"State"},{name:"address1"},{name:"address2"},{name:"phone"},{name:"fax"},{name:"email"},{name:"zip"},{name:"websiteaddress"},{name:"sitestatus"}]),remoteSort:false,autoExpandColumn:"DealerName"});function L(B){B=B.replace(/</g,"*abc*");B=B.replace(/&#/g,"*bcd*");return B}function N(B){return L(document.getElementById(B).value)}function G(B){return document.getElementById(B).checked}J.on("click",function(){if(N("ddTypeOfOperation")==0){Ext.MessageBox.show({title:"Information",msg:"Please select Type of Operation!",width:325,buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.INFO})}else{if(N("ddProductCategory")==0){Ext.MessageBox.show({title:"Information",msg:"Please select Product Category!",width:325,buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.INFO})}else{if(N("ddProductType")==0&&N("ddProductCategory")!=1){Ext.MessageBox.show({title:"Information",msg:"Please select Product Type!",width:325,buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.INFO})}else{if(N("txt_City")==""&&N("txt_Zip")==""){Ext.MessageBox.show({title:"Information",msg:"Please enter either City or Zip/Postal Code!",width:325,buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.INFO})}else{City=N("txt_City");State=N("ddState");ZipCode=N("txt_Zip");Ext.MessageBox.show({msg:"Validating City, State  & Zip/Postal Code, please wait...",progressText:"Validating...",width:400,wait:true,waitConfig:{interval:200},icon:"ext-mb-download",animEl:"btn_Search"});pag_ZipSearch=new Ext.data.Store({id:"pag_ZipSearch",proxy:new Ext.data.HttpProxy({url:"GSIDataFetch.aspx",method:"POST"}),baseParams:{methodName:"GSI_ZipSearch"},reader:new Ext.data.JsonReader({root:"GSIDealer",totalProperty:"total",id:"id"},[{name:"zip"},{name:"city"},{name:"state"},{name:"country"}]),sortInfo:{field:"city",direction:"ASC"},remoteSort:false});var B=new Ext.grid.CheckboxSelectionModel({header:"",width:20});CityZipColumnModel=new Ext.grid.ColumnModel([B,{id:"zip",header:"Zip/Postal Code",dataIndex:"zip",sortable:true,width:100},{id:"city",header:"City",dataIndex:"city",sortable:true,width:150},{id:"state",header:"State",dataIndex:"state",sortable:true,width:50},{id:"country",header:"country",dataIndex:"country",sortable:true,width:150}]);CityZipColumnModel.defaultSortable=true;CityZipListingGrid=new Ext.grid.GridPanel({id:"CityZipListingGrid",title:"",store:pag_ZipSearch,cm:CityZipColumnModel,enableColLock:false,width:500,height:380,loadMask:true,autoExpandColumn:"city",viewConfig:{forceFit:true},selModel:new Ext.grid.RowSelectionModel({singleSelect:true})});pag_ZipSearch.load({params:{start:0,limit:15,p1_City:N("txt_City"),p2_State:N("ddState"),p3_Zip:N("txt_Zip")}});K=new Ext.Window({title:"Dealer Locator : City, State and Zip/Postal Code List",modal:true,height:450,width:515,items:[new Ext.Panel({items:[CityZipListingGrid]})],buttons:[{text:"OK",handler:function(){D()}}]});CityZipListingGrid.on("rowdblclick",D,CityZipListingGrid);pag_ZipSearch.on("load",P,CityZipListingGrid)}}}}});function P(){Ext.MessageBox.hide();if(CityZipListingGrid.store.getTotalCount()==1)
        {
            document.getElementById("txt_Zip").value = pag_ZipSearch.data.items[0].data.zip;
            document.getElementById("txt_City").value = pag_ZipSearch.data.items[0].data.city;
            document.getElementById("txt_State").value = pag_ZipSearch.data.items[0].data.state;
            //alert(pag_ZipSearch.data.items[0].data.state);
            E()
        }
        else {
            if (CityZipListingGrid.store.getTotalCount() == 0) {
                Ext.MessageBox.show({
                    title: "Please Contact:",
                    msg: "<div class='info'><h1>THE GSI GROUP</h1><p>1004 E. Illinois St. Assumption, IL 62510</p><p>Phone: 888-474-2467 Intl. Tel.: 1-217-226-2467</p><p>U.S. Fax: 800-800-5329 Intl.Fax: 1-217-226-3404</p><p>Email: <a href='mailto:sales@gsiag.com'>sales@gsiag.com</a></p></div>",
                    width: 450,
                    buttons: Ext.MessageBox.OK,
                    icon: "infoGSILogo"
                });
            }
            else {
                K.show()
            }
        }
    }

    function E() {
        Ext.MessageBox.show({
            title: "Searching",
            msg: "Searching Dealer, please wait...",
            progressText: "Searching...",
            width: 300,
            wait: true,
            waitConfig: { interval: 200 },
            icon: "ext-mb-download",
            animEl: "btn_Search"
        });

        pag_ConSearch.load({
            params: {
                start: 0,
                limit: 15,
                p1_City: (N("ddCountry") == "US" || N("ddCountry") == "CA") ? N("txt_City") : "",
                p2_State: (N("ddCountry") == "US" || N("ddCountry") == "CA") ? N("txt_State") : "",
                p3_Zip: (N("ddCountry") == "US" || N("ddCountry") == "CA") ? N("txt_Zip") : "",
                p4_Country: N("ddCountry"),
                p1_TypeOfOperation: (N("ddCountry") == "US" || N("ddCountry") == "CA") ? N("ddTypeOfOperation") : "0",
                p_ProductType: (N("ddCountry") == "US" || N("ddCountry") == "CA") ? N("ddProductType") : "0",
                p_ProductCategory: (N("ddCountry") == "US" || N("ddCountry") == "CA") ? N("ddProductCategory") : "0"
            },
            callback: function(records, options, success) {
                if (records.length > 0) {
                    Ext.MessageBox.hide();
                    I.show()
                }
                else {
                    Ext.MessageBox.show({
                        title: "Please Contact:",
                        msg: "<div class='info'><h1>THE GSI GROUP</h1><p>1004 E. Illinois St. Assumption, IL 62510</p><p>Phone: 888-474-2467 Intl. Tel.: 1-217-226-2467</p><p>U.S. Fax: 800-800-5329 Intl.Fax: 1-217-226-3404</p><p>Email: <a href='mailto:sales@gsiag.com'>sales@gsiag.com</a></p></div>",
                        width: 450,
                        buttons: Ext.MessageBox.OK,
                        icon: "infoGSILogo"
                    });
                }
            }
        });

        var F = new Ext.grid.CheckboxSelectionModel({ header: "", width: 20 });
        DealerListColumnModel = new Ext.grid.ColumnModel(
            [{
                id: "PreferredDealer",
                header: "Preferred Dealer",
                dataIndex: "PreferredDealer",
                renderer: PD,
                sortable: true,
                width: 100
            },
            {
                id: "DealerName",
                header: "Dealer Information",
                dataIndex: "DealerName",
                renderer: B,
                sortable: true,
                width: 500
            },
            {
                id: "Distance",
                header: "Distance(in miles)",
                dataIndex: "Distance",
                renderer: BB,
                hidden: (N("ddCountry") == "US" || N("ddCountry") == "CA") ? false : true,
                sortable: true,
                width: 150
}]
            );
        DealerListColumnModel.defaultSortable = false;
        DealerListingGrid = new Ext.grid.GridPanel({
            id: "DealerListingGrid",
            title: "",
            store: pag_ConSearch,
            cm: DealerListColumnModel,
            enableColLock: false,
            stripeRows: true,
            width: 700,
            height: 380,
            loadMask: true,
            autoExpandColumn: "DealerName",
            viewConfig: { forceFit: true },
            selModel: new Ext.grid.RowSelectionModel({
                singleSelect: true
            })
        });
        function B(S, T, Q) {
            var R = Q.data.websiteaddress.replace("http://", "");
            if (R != "") { R = "http://" + R }
            if (Q.data.sitestatus == "2") {
                S = '<a href="../dealers/' + Q.data.DealerId + "/" + S.replace(/ /g, "").replace(/\./g, "") + '.html" target="_blank">' + S + "</a>"
            } return String.format('<b>{0}</b></br>{1}</br>{2}, {3} - {4}</br><b>Phone:</b>{5}</br><b>Fax:</b>{6}</br><b>Email:</b>{7}</br><b>Website:</b><a href="{8}" target="_blank">{8}</a>', S, Q.data.address1, Q.data.City, Q.data.State, Q.data.zip, Q.data.phone, Q.data.fax, Q.data.email, R)
        }
        function BB(S, T, Q) {
            return String.format('<span style="font-size:40px; line-height:85px;">{0}</span><span> mile(s)</span>', S, Q.data.Distance);
        }
        function PD(S, T, Q) {
            if (Q.data.PreferredDealer == 1) {
                return '<img src="../images/preferred.png" alt="Preferred Dealer" title="GSI Preferred Dealer" />';
            }
            else {
                return '';
            }
        }
        I = new Ext.Window({
            title: "Dealer Locator : Search Results",
            modal: true,
            height: 450,
            width: 715,
            items: [new Ext.Panel({ items: DealerListingGrid })],
            buttons: [{ text: "Print", handler: function() { C() } }]
        });
    }
    function D() {
        var B = CityZipListingGrid.getSelections();
        if (B.length > 0) {
            document.getElementById("txt_Zip").value = B[0].get("zip");
            document.getElementById("txt_City").value = B[0].get("city");
            document.getElementById("txt_State").value = B[0].get("state");
            K.hide();
            E()
        }
        else {
            Ext.MessageBox.show({
                title: "Information",
                msg: 'Select a City, State or Zip from grid before you click on "Ok" button',
                width: 350,
                buttons: Ext.MessageBox.OK, icon: Ext.MessageBox.INFO
            })
        }
    }
    function C() {
        var F = pag_ConSearch.data.items.length;
        var B;
        B = '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Dealer Information List</title><style type="text/css">body{font-family:Calibri,Verdana,Tahoma,Arial;font-size:10px !important; margin:0px 0px 0px 0px;}table{border:solid 1px #000; font-size:12px;}th{background-color:#333;color:#fff}td{background-color:#f1f1f1;border-bottom:#000 solid 1px;}</style></head>';
        B += '<body onload="window.print();"><table cellpadding="3" cellspacing="0" border="0"><tr><th style="width:150px">Preferred Dealer</th><th style="width:300px">Dealer Information</th>';
        if (N("ddCountry") == "US" || N("ddCountry") == "CA") {
            B += '<th style="width:150px">Distance(in miles)</th>';
        }
        B += '</tr>';
        for (i = 0; i < F; i++) {
            B += "<tr>";
            if (pag_ConSearch.data.item(i).data.PreferredDealer == 1) {
                B += "<td style='text-align:center;'><img src='../images/preferred.png' alt='Preferred Dealer' title='GSI Preferred Dealer' /></td>";
            }
            else {
                B += "<td>&nbsp;</td>";
            }
            B += "<td><b>" + pag_ConSearch.data.item(i).data.DealerName + "</b>";
            B += "<br />" + pag_ConSearch.data.item(i).data.address1 + " " + pag_ConSearch.data.item(i).data.address2;
            B += "<br />" + pag_ConSearch.data.item(i).data.City + "," + pag_ConSearch.data.item(i).data.State + "-" + pag_ConSearch.data.item(i).data.zip;
            B += "<br /><b>Phone:</b>" + pag_ConSearch.data.item(i).data.phone;
            B += "<br /><b>Email:</b>" + pag_ConSearch.data.item(i).data.email;
            B += "<br /><b>Fax:</b>" + pag_ConSearch.data.item(i).data.fax;
            B += "<br /><b>Website:</b>" + pag_ConSearch.data.item(i).data.websiteaddress;
            B += "</td>";
            if (N("ddCountry") == "US" || N("ddCountry") == "CA") {
                B += "<td style='text-align:center;'><span style='font-size:40px;'>" + pag_ConSearch.data.item(i).data.Distance + "</span><span> mile(s)</span></td>";
            }
            B += "</tr>"
        }
        B += "</table></body></html>";
        pwin = window.open();
        newdocument = pwin.document;
        newdocument.write(B)
    }
    function A(B) {
        B.focus();
        B.print()
    }
});

function countryChange() {
    var country = document.getElementById("ddCountry").value;
    if (country == "US" || country == "CA") {
        if (navigator.appName != "Microsoft Internet Explorer") {
            document.getElementById("idStateTR").style.display = "table-row";
            document.getElementById("idZipTR").style.display = "table-row";
            document.getElementById("idOr").style.display = "table-row";
            document.getElementById("idCityTR").style.display = "table-row";
            document.getElementById("idTOTR").style.display = "table-row";
            document.getElementById("idPCTR").style.display = "table-row";
            document.getElementById("idPTTR").style.display = "table-row";
        }
        else {
            document.getElementById("idStateTR").style.display = "block";
            document.getElementById("idZipTR").style.display = "block";
            document.getElementById("idOr").style.display = "block";
            document.getElementById("idCityTR").style.display = "block";
            document.getElementById("idTOTR").style.display = "block";
            document.getElementById("idPCTR").style.display = "block";
            document.getElementById("idPTTR").style.display = "block";
        }
    }
    else {
        document.getElementById("txt_State").value = "";
        document.getElementById("txt_Zip").value = "";
        document.getElementById("txt_City").value = "";
        document.getElementById("idStateTR").style.display = "none";
        document.getElementById("idZipTR").style.display = "none";
        document.getElementById("idOr").style.display = "none";
        document.getElementById("idCityTR").style.display = "none";
        document.getElementById("idTOTR").style.display = "none";
        document.getElementById("idPCTR").style.display = "none";
        document.getElementById("idPTTR").style.display = "none";
    }
}

function prodChange(A, B) {
    cleardd("ddProductType");
    addItem("ddProductType", "Select Product Type", 0);
    document.getElementById("ddProductType").disabled = false;
    if (A == 0) {
        document.getElementById("ddProductType").disabled = true
    }
    else {
        if (A == 1) {
            if (B == 1) {
                document.getElementById("ddProductType").disabled = true
            }
            if (B == 2) {
                addItem("ddProductType", "Farm", 1);
                addItem("ddProductType", "Farm Commercial", 2);
                addItem("ddProductType", "Bulk Feed Tanks", 3);
                addItem("ddProductType", "Parts", 4)
            }
            else {
                if (B == 3) {
                    addItem("ddProductType", "Fans & Heaters", 1);
                    addItem("ddProductType", "Portable Dryers", 2);
                    addItem("ddProductType", "Top Dry", 3);
                    addItem("ddProductType", "Parts", 4)
                }
                else {
                    if (B == 4) {
                        addItem("ddProductType", "Air Systems", 1);
                        addItem("ddProductType", "Chain Loops", 2);
                        addItem("ddProductType", "Bucket Elevators (<10,000 bph)", 3);
                        addItem("ddProductType", "Conveyors (<10,000 bph)", 5);
                        addItem("ddProductType", "Parts", 7)
                    }
                }
            }
        }
        else {
            if (A == 2 || A == 3 || A == 4) {
                if (B == 1) {
                    document.getElementById("ddProductType").disabled = true
                }
                if (B == 2) {
                    addItem("ddProductType", "Farm", 1);
                    addItem("ddProductType", "Farm Commercial", 2);
                    addItem("ddProductType", "Bulk Feed Tanks", 3);
                    addItem("ddProductType", "Commercial", 4);
                    addItem("ddProductType", "Parts", 4)
                }
                else {
                    if (B == 3) {
                        addItem("ddProductType", "Fans & Heaters", 1);
                        addItem("ddProductType", "Portable Dryers", 2);
                        addItem("ddProductType", "Top Dry", 3);
                        addItem("ddProductType", "Tower Dryer", 4);
                        addItem("ddProductType", "Parts", 5)
                    }
                    else {
                        if (B == 4) {
                            addItem("ddProductType", "Air Systems", 1);
                            addItem("ddProductType", "Chain Loops", 2);
                            addItem("ddProductType", "Bucket Elevators (<10,000 bph)", 3);
                            addItem("ddProductType", "Bucket Elevators (>10,000 bph)", 4);
                            addItem("ddProductType", "Conveyors (<10,000 bph)", 5);
                            addItem("ddProductType", "Conveyors (>10,000 bph)", 6);
                            addItem("ddProductType", "Parts", 7)
                        }
                    }
                }
            }
        }
    }
}

function addItem(C, B, E) {
    var D;
    var A = document.getElementById(C);
    D = document.createElement("Option");
    D.text = B;
    D.value = E;
    A.options.add(D)
}
function cleardd(C) {
    var B = document.getElementById(C);
    var A = B.options.length;
    for (i = 0; i < A; i++) {
        B.remove(0)
    }
};

function timeoutcallback()
{
   alert("Please try Again, Server Not Responding.");
}
///   called when the page loads
//    Thao commented the country code (10/05/2011)
//function LoadCountry()
//{
//   try
//   {
//      AjaxPro.timeoutPeriod = 6000000;      
//      AjaxCountry.LoadCountry(LoadCountry_Callback, null, null, null, timeoutcallback);
//   }
//   catch(e)
//   {
//      alert('\n' + e.message);
//   }
//}
//function LoadCountry_Callback(res)
//{
//   try
//      {
//         if(res.value == null)
//      {
//         //alert('Server is not responding, Please try lager.');
//         alert(res.error.Message);
//         return;
//      }
//      else
//      {
//         var restbl = res.value;
//         var CountryTable = restbl.Tables[0];
//          ///   Add values to the Domain drop down
//         if(CountryTable.Rows.length >0)
//         {
//            var CountryList = "";
//            var CountryDropDown =document.getElementById('ddCountry');
//            CountryDropDown.add(new Option('Select Country', 99));
//            for(var i = 0; i < CountryTable.Rows.length; i++)
//            {
//               CountryDropDown.add(new Option(CountryTable.Rows[i].CountryName, CountryTable.Rows[i].CountryCode));
//            }
//         }
//      }
//    }
//     catch(e)
//   {
//      alert('\n' + e.message);
//   }
// }
 ///   called when the DropDown value Change that time Load Data
function LoadState()
{
   var Selectedcountry = document.getElementById('ddCountry').options[document.getElementById('ddCountry').selectedIndex].value; 
   try
      {   
        AjaxPro.timeoutPeriod = 150000;
        AjaxCountry.LoadState(Selectedcountry,LoadState_Callback, null,null,null, timeoutcallback);
   }
   catch(e)
   {
      alert('\n' + e.message);
   }   
}
function LoadState_Callback(res)
{
   try
      {
      if(res.value == null)
      {
         //alert('Server is not responding, Please try lager.');
         alert(res.error.Message);
         return;
      }
      else
      {
         var restbl = res.value;
         var stateTable = restbl.Tables[0];
          ClearDDL('ddState', " Select State ")
  
        document.getElementById('ddState').options.selectedIndex = 0;
          ///   Add values to the Domain drop down
         if(stateTable.Rows.length >0)
         {
            var StateList = "";
            var StateDropDown =document.getElementById('ddState');
            StateDropDown.add(new Option('Select State', 99));
            for(var i = 0; i < stateTable.Rows.length; i++)
            {
               StateDropDown.add(new Option(stateTable.Rows[i].StateCode, stateTable.Rows[i].StateCode));//RegionName
            }
         }
      }
    }
     catch(e)
   {
      alert('\n' + e.message);
   }
 }
 
  
  // DropDownBox Clear Function
function ClearDDL(objId, objDescription) 
{ 
   var ddList = document.getElementById(objId); 
   for (var count = ddList.options.length - 1; count > -1; count--) 
   { 
     ddList.options[count] = null; 
   }
   //optionItem = new Option('All ' + objDescription, "0", false, false); 
   //ddList.options[ddList.length] = optionItem; 
}


