﻿var xmlhttprequest=null;
var url;

var strReturn;

var flag=0;


//公司行业
function ChangeBuessiness(proid,cityid)
{
    var pro=document.getElementById(proid).options[document.getElementById(proid).selectedIndex].value;
    if(pro=="-1")
    {
        return;
    }
    else
    {
        flag=1;
        url="../web/Province.aspx?buesId="+pro+"&time"+new Date();
        getAllLayersName();
        var cityArray=strReturn.split('|');//这里strReturn 是接受的到得数据 格式是：1=上海|2=北京|3=重庆 这样是的格式
        var oOption=null;
         document.getElementById(cityid).options.length=1;
         for(var i=0;i<cityArray.length;i++)
         {
            var valuetext=cityArray[i].split('=');                
            oOption = new Option(valuetext[1],valuetext[0]);
            document.getElementById(cityid).options.add(oOption);
        }
    }
}
//公司库
//公司库绑定行业
function companyBuess(pro,SecondBuessId)
{
    if(pro=="-1")
    {
        return;
    }
    else
    {
        flag=1;
        url="../web/Province.aspx?buesId="+pro+"&time"+new Date();
        getAllLayersName();
        var cityArray=strReturn.split('|');//这里strReturn 是接受的到得数据 格式是：1=上海|2=北京|3=重庆 这样是的格式
        var oOption=null;
        // document.getElementById(cityid).options.length=1;
         for(var i=0;i<cityArray.length;i++)
         {
            var valuetext=cityArray[i].split('=');                
            oOption = new Option(valuetext[1],valuetext[0]);
            document.getElementById(SecondBuessId).options.add(oOption);
        }
    }
}
//公司库绑定省份

function companyProvince(pro,ProvinceId)
{
    if(pro=="-1")
    {
        return;
    }
    else
    {
        flag=1;
        url="../web/Province.aspx?ProID="+pro+"&time"+new Date();
        getAllLayersName();
        var cityArray=strReturn.split('|');//这里strReturn 是接受的到得数据 格式是：1=上海|2=北京|3=重庆 这样是的格式
        var oOption=null;
        // document.getElementById(cityid).options.length=1;
         for(var i=0;i<cityArray.length;i++)
         {
            var valuetext=cityArray[i].split('=');                
            oOption = new Option(valuetext[1],valuetext[0]);
            document.getElementById(ProvinceId).options.add(oOption);
        }
    }
}

//公司库



function ChangePro(proid,cityid)
{
    //alert(document.getElementById("SelectPro").selectedIndex);
    var pro=document.getElementById(proid).options[document.getElementById(proid).selectedIndex].value;

    if(pro=="-1")
    {
        return;
    }
    else
    {
        flag=1;
        url="../web/Province.aspx?ProID="+pro+"&time"+new Date();
        getAllLayersName();
        var cityArray=strReturn.split('|');//这里strReturn 是接受的到得数据 格式是：1=上海|2=北京|3=重庆 这样是的格式
        var oOption=null;
        document.getElementById(cityid).options.length=1;
       
         //document.getElementById(cityid).options.add(new Option('请选择城市',-1));
         for(var i=0;i<cityArray.length;i++)
         {
            var valuetext=cityArray[i].split('=');                
            oOption = new Option(valuetext[1],valuetext[0]);
            document.getElementById(cityid).options.add(oOption);
        }
    }
}
function ChangeRoadPro(proid,cityid,townid)
{
    //alert(document.getElementById("SelectPro").selectedIndex);
    var pro=document.getElementById(proid).options[document.getElementById(proid).selectedIndex].value;
    if(pro=="-1")
    {
        return;
    }
    else
    {
        flag=1;
        url="../web/Province.aspx?ProID="+pro+"&time"+new Date();
        getAllLayersName();
        var cityArray=strReturn.split('|');//这里strReturn 是接受的到得数据 格式是：1=上海|2=北京|3=重庆 这样是的格式
        var oOption=null;
        document.getElementById(cityid).options.length=0;
        document.getElementById(cityid).options.add(new Option('--请选择城市--',-1));
        document.getElementById(townid).options.length=0;
        document.getElementById(townid).options.add(new Option('--全境--',-1));
        
         for(var i=0;i<cityArray.length;i++)
         {
            var valuetext=cityArray[i].split('=');                
            oOption = new Option(valuetext[1],valuetext[0]);
            document.getElementById(cityid).options.add(oOption);
        }
    }
}
function ChangeRoadCity(cityid,countryid)
{
     var pro=document.getElementById(cityid).options[document.getElementById(cityid).selectedIndex].value;    
    if(pro=="-1")
    {
        return;
    }
    else
    {
        flag=1;
        
        url="../web/Province.aspx?CityId="+pro+"&time"+new Date();
           //alert(url);
         getAllLayersName();
        var cityArray=strReturn.split('|');//这里strReturn 是接受的到得数据 格式是：1=上海|2=北京|3=重庆 这样是的格式
        var oOption=null; 
        document.getElementById(countryid).options.length=0;
       
        document.getElementById(countryid).options.add(new Option('--请选择--',-1));
        for(var i=0;i<cityArray.length;i++)
        {
            var valuetext=cityArray[i].split('=');                
            oOption = new Option(valuetext[1],valuetext[0]);
            document.getElementById(countryid).options.add(oOption);
        }
    }
}

function ChangeCity(cityid,countryid)
{
     var pro=document.getElementById(cityid).options[document.getElementById(cityid).selectedIndex].value;    
    if(pro=="-1")
    {
        return;
    }
    else
    {
        flag=1;
        
        url="../web/Province.aspx?CityId="+pro+"&time"+new Date();
           //alert(url);
         getAllLayersName();
        var cityArray=strReturn.split('|');//这里strReturn 是接受的到得数据 格式是：1=上海|2=北京|3=重庆 这样是的格式
        var oOption=null; 
        document.getElementById(countryid).options.length=1;
       
       //  document.getElementById(countryid).options.add(new Option('请选择城市',-1));
        for(var i=0;i<cityArray.length;i++)
        {
            var valuetext=cityArray[i].split('=');                
            oOption = new Option(valuetext[1],valuetext[0]);
            document.getElementById(countryid).options.add(oOption);
        }
    }
}

function getOs()  
{  
   var OsObject = "";  
   if(navigator.userAgent.indexOf("MSIE")>0) {  
        return "MSIE";       //IE浏览器
   }
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){  
        return "Firefox";     //Firefox浏览器
   }
   if(isSafari=navigator.userAgent.indexOf("Safari")>0) {  
        return "Safari";      //Safan浏览器
   }
   if(isCamino=navigator.userAgent.indexOf("Camino")>0){  
        return "Camino";   //Camino浏览器
   }
   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){  
        return "Gecko";    //Gecko浏览器
   }  
} 
function getAllLayersName()
{
 if (null==xmlhttprequest)
    {
        if(window.ActiveXObject)   //IE浏览器   
        {                   
             xmlhttprequest  = new ActiveXObject("Microsoft.XMLHTTP");           
        }             
        else if(window.XMLHttpRequest)   //非IE浏览器   
        {                 
            xmlhttprequest =  new XMLHttpRequest();           
        }   
    }
    xmlhttprequest.open("GET",url,false);//向layer.ashx发送参数
    xmlhttprequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    var btype=getOs();
    xmlhttprequest.onreadystatechange = (btype!="Firefox")?(xmlHandle):(xmlHandle());
    xmlhttprequest.send(null);
    xmlhttprequest.onreadystatechange = (btype!="Firefox")?(xmlHandle):(xmlHandle());
}

function xmlHandle()
{ 
    var readyState=xmlhttprequest.readyState;
    if (readyState==4)//判断对象状态，4为完成
    {
         var status=xmlhttprequest.status;
        if(status==200)//信息已经返回开始处理信息
        {
            var strLayersName= xmlhttprequest.responseText;//得到返回的字符串
            if(strLayersName!= null)
            {
                var index=strLayersName.lastIndexOf('|');
                
                strLayersName=strLayersName.substring(0,index);
                //alert(strLayersName);
                strReturn=strLayersName;
            }
        }
        else
        {
        }
        // xmlhttprequest = null;
    }
}




