﻿
        var chandigarh = new Array ("Chandigarh");
        var haryana = new Array("Ambala", "Asand", "Panipat", "Yamuna Nagar");
        var himachalpradesh = new Array ("Hamirpur", "Nahan", "Parwanoo", "Sunder Nagar", "Una");
        var punjab = new Array ("Abohar", "Budhladha", "Dharamkot", "Dhuri", "Faridkot", "Ferozepur", "Jalandhar", "Kapurthala", "Kotkapura", "Ludhiana", "Malaut", "Malerkotla", "Mandi Gobindgarh", "Mohali", "Moga", "Mukatsar", "Nangal", "Patiala", "Phagwara", "Rampura Phool", "Ropar");
        var uttarpradesh = new Array ("Meerut");
        var uttaraKhand = new Array ("Rudrapur");
        
        function checkCurrentPage()// if currently not on Locate channel partners page than redirect to the same.
        {
            var loc = String(window.location);
            var selectedState = document.getElementById('states').value;
            setCookie('advantaWitty', selectedState, 365);
            
            if(loc.search("Advanta-Locate-Partner.aspx") == -1 )
            {
                window.location = "Advanta-Locate-Partner.aspx";
            }
           else
            { 
                selectedState = getCookie('advantaWitty');
                //if(selectedState == 
                //removeCities();
                //addSelectCity();
                setCities(selectedState);
                showAllCities(selectedState);
                setSelectedStateAndCity();
                setMasterChannelParterns(selectedState);
            }
        }
        
        function SetValues()
        {
            var loc = String(window.location);
            if(loc.search("Advanta-Locate-Partner.aspx") >= 0 )
            {
                selectedState = getCookie('advantaWitty');
                if(selectedState != "")
                {
                    document.getElementById('states').value = selectedState;
//alert('OK');                    
                    setCities(selectedState);
                    showAllCities(selectedState);
                    setMasterChannelParterns(selectedState);
                }
                else
                {
                    defaultStateSelect();
                }
                setSelectedStateAndCity();
            }

        }
        
        function setCities(state)
        {
            if(state != "selectLocation")
            {
                     if(state == "chandigarh")      addCities(chandigarh);
                else if(state == "haryana")         addCities(haryana);
                else if(state == "himachalPradesh") addCities(himachalpradesh);
                else if(state == "punjab")          addCities(punjab);
                else if(state == "uttarPradesh")    addCities(uttarpradesh);
                else if(state == "uttaraKhand")    addCities(uttaraKhand);
                
                clearResult();
            }
            else
            {
                removeCities();
                addSelectCity();
                clearResult();
            }
        }
        function addCities(state)
        {
            city = document.getElementById('cities');
            removeCities();
            addSelectCity();
            for(i = 0;i<state.length;i++)
            {
                addOption(state[i], state[i].replace(' ',''))
            }
        }
        function addOption(txt,val)
        {
            var newCity = document.createElement('option');
            newCity.text = txt;
            newCity.value = val;            
            try
            {
                city.add(newCity,null)
            }
            catch(ex)
            {
                city.add(newCity);
            }
        }
        function removeCities()
        {
            for(i=city.length;i>=0;i--)
            {
                city.remove(i);
            }
        }
        function addSelectCity()
        {
            addOption("-- Select City --","citySelect")
        }
        function clearResult()
        {
            document.getElementById('selectedContent').innerHTML = "";
        }
        function showResult() //Calling on change event of citySelect DropdownList
        {
            var citySelected = document.getElementById('cities').value;
            if(citySelected != "citySelect")
            {
                var contentText = document.getElementById(citySelected).innerHTML;
                document.getElementById('selectedContent').innerHTML = "&nbsp;";  
                document.getElementById('selectedContent').innerHTML = contentText; 
            }
            else
            {   
                var stateSeleted = document.getElementById('states').value;
                if(stateSeleted != "selectLocation")
                {  
                    showAllCities(stateSeleted); // to show all cities of a State
                }
                else
                {
                    document.getElementById('selectedContent').innerHTML = "&nbsp;";  
                }
            }
            setSelectedStateAndCity();

        }
        function showAllCities(state)
        {
            if(state != "selectLocation")
            {
                     if(state == "chandigarh")      showCities(chandigarh);
                else if(state == "haryana")         showCities(haryana);
                else if(state == "himachalPradesh") showCities(himachalpradesh);
                else if(state == "punjab")          showCities(punjab);
                else if(state == "uttarPradesh")    showCities(uttarpradesh);
                else if(state == "uttaraKhand")    showCities(uttaraKhand);
            }
            document.getElementById('cities').focus();
        }
        function showCities(state)
        {
            var allText = "";
            var newCityText= "";
            for(i=0;i<state.length;i++)
            {
              newCityText = "";
              newCityText = document.getElementById(state[i].replace(' ','')).innerHTML;
              allText += newCityText;
              document.getElementById('selectedContent').innerHTML = "&nbsp;";
            }
              document.getElementById('selectedContent').innerHTML  = allText;
            document.getElementById('selectedContent').offsetHeight;
        }
        
        function defaultStateSelect()
        {
            var state = document.getElementById('states').selectedIndex = 0;
        }


        function getCookie(c_name)
        {
        if (document.cookie.length>0)
          {
          c_start=document.cookie.indexOf(c_name + "=");
          if (c_start!=-1)
            { 
            c_start=c_start + c_name.length+1; 
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
            } 
          }
        return "";
        }

        function setCookie(c_name,value,expiredays)
        {
            var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);
            document.cookie=c_name+ "=" +escape(value)+
            ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
        }
        function setSelectedStateAndCity()
        {
            var stateIndex = document.getElementById('states').selectedIndex;
            var cityIndex = document.getElementById('cities').selectedIndex;
            var selectedState = document.getElementById('states').options[stateIndex].text;
            var selectedCity = document.getElementById('cities').options[cityIndex].text;
            
            if(stateIndex != 0)
            {
//                if(stateIndex == 0)
//                    document.getElementById('selectedStateSpan').innerHTML = "Please Select State";
//                else
                document.getElementById('selectedStateSpan').innerHTML = "Channel Partners for State: " + selectedState;
                if(cityIndex == 0)
                    document.getElementById('selectedCitySpan').innerHTML = ""; 
                else
                    document.getElementById('selectedCitySpan').innerHTML = " - City: " + selectedCity;
            }
            else
            {
                document.getElementById('selectedStateSpan').innerHTML = "Please Select Location (State/City)";
                document.getElementById('selectedCitySpan').innerHTML  = "";
            }
           
        }
        function setMasterChannelParterns(selectedSteteName)
        {
            var masters = "&nbsp;";
            try
            {
                var mastersDiv = document.getElementById(selectedSteteName+"Master");
                masters = mastersDiv.innerHTML;
            }
            catch(a)
            {
                document.getElementById('MasterPartner').innerHTML = masters;
            }
            finally
            {
                document.getElementById('MasterPartner').innerHTML = masters;
            }
        }