addLoadEvent(function(){
    bindEvent(getid('sheng'),'change',shilist);
    bindEvent(getid('shi'),'change',qulist);
    bindEvent(getid('qu'),'change',cunlist);
    bindEvent(getid('chacode'),'click',searchcode);
    bindEvent(getid('customcha'),'click',advancesearch);
    bindEvent(getid('seeditu'),'click',openditu);
});
//$(document).ready(function(){
//    $("#sheng").change(function() {
//        shilist();
//    });
//    $("#shi").change(function() {
//        qulist();
//    });
//    $("#qu").change(function() {
//        cunlist();
//    });
//    $("#chacode").click(function() {
//        searchcode();
//    });
//    $("#customcha").click(function() {
//        advancesearch();
//    });
//    $("#seeditu").click(function() {
//        openditu();
//    });
//});

function shilist()
{
    var selv= getSelectedValue('sheng');
    if (trim(selv)!='')
    {
        //针对开启伪静态部署的网站，必须加上'index.php?'
        //url=thesiteurl+'/youbianchaxun/shilist/';
        url=thesiteurl+'index.php?'+'/youbianchaxun/shilist/';
        fdata='sheng='+selv;
        clearselect(getid('shi'));
        clearselect(getid('qu'));
        clearselect(getid('cun'));
        postlist(url,fdata,'shi');
        document.getElementById('code').focus();
    }
}

function qulist()
{
    var selv= getSelectedValue('shi');
    if (trim(selv)!='')
    {
        //url=thesiteurl+'/youbianchaxun/qulist/';
        url=thesiteurl+'index.php?'+'/youbianchaxun/qulist/';
        fdata='shi='+selv;
        clearselect(getid('qu'));
        clearselect(getid('cun'));
        postlist(url,fdata,'qu');
        document.getElementById('code').focus();
    }
}

function cunlist()
{
    var selv= getSelectedValue('qu');
    if (trim(selv)!='')
    {
        //url=thesiteurl+'/youbianchaxun/cunlist/';
        url=thesiteurl+'index.php?'+'/youbianchaxun/cunlist/';
        fdata='qu='+selv;
        clearselect(getid('cun'));
        postlist(url,fdata,'cun');
        document.getElementById('code').focus();
    }
}

function openditu()
{
    var sheng=getSelectedValue('sheng');
    var shi=getSelectedValue('shi');
    var qu=getSelectedValue('qu');
    var cun=getSelectedValue('cun');
    document.getElementById('re').innerHTML='<br><center><iframe src="./image/2.htm?'+sheng+shi+qu+cun+'" height="300" width="500" frameborder="0" scrolling="no"></iframe></center>';
}

function advancesearch()
{   
    var sheng=getSelectedValue('sheng');
    var shi=getSelectedValue('shi');
    var qu=getSelectedValue('qu');
    var cun=getSelectedValue('cun');
    var fdata='';
    //url=thesiteurl+'/youbianchaxun/quhaolistby/';
    url=thesiteurl+'index.php?'+'/youbianchaxun/quhaolistby/';
    if (sheng!='')
    {
        fdata= fdata+ 'sheng='+sheng;
    }
    if (shi!='')
    {
        fdata= fdata+ '&shi='+shi;
    }
    if (qu!='')
    {
        fdata= fdata+ '&qu='+qu;
    }
    if (sheng!='')
    {
        fdata= fdata+ '&cun='+cun;
    }
    if (fdata!='')
    {
        postdata(url,fdata,'re');
    }
    else
    {
        alert('请输入查询内容');
    }
}

function advancesearchpage(surl)
{
    var sheng=getSelectedValue('sheng');
    var shi=getSelectedValue('shi');
    var qu=getSelectedValue('qu');
    var cun=getSelectedValue('cun');
    var fdata='';
    var url=surl;
    if (sheng!='')
    {
        fdata= fdata+ 'sheng='+sheng;
    }
    if (shi!='')
    {
        fdata= fdata+ '&shi='+shi;
    }
    if (qu!='')
    {
        fdata= fdata+ '&qu='+qu;
    }
    if (sheng!='')
    {
        fdata= fdata+ '&cun='+cun;
    }
    if (fdata!='')
    {
        postdata(url,fdata,'re');
    }
    else
    {
        alert('请输入查询内容');
    }
}

function searchcode()
{
    var code=getid('code').value;
    if (code!='')
    {
      //url=thesiteurl+'/youbianchaxun/ajaxsearchquhao/';
       url=thesiteurl+'index.php?'+'/youbianchaxun/ajaxsearchquhao/';
        fdata='code='+code;
        getid('h_scode').value=code;
        postdata(url,fdata,'re');
    }
    else
    {
        alert('请输入查询内容');
    }
}
function ajaxpage(url)
{
    fdata='code='+getid('h_scode').value;
    postdata(url,fdata,'re');
}

function postlist(furl,fdata,selectid){                             
//    $.ajax({
//        type: "POST",
//        url: furl,
//        data: fdata,
//        success: function(msg){
//            //alert(msg);
//            var strArray = new Array();
//            strArray= msg.split('`');
//            for (i=0;i<strArray.length;i++)
//            {
//                obj=getid(selectid);
//                writeselect(obj,strArray[i],strArray[i]);
//            }
//            getid(selectid).selectedIndex=1;
//        }
//    });
   var ajaxobj=new AJAXRequest;
   ajaxobj.method='POST';
   ajaxobj.async=true;
   ajaxobj.url=furl;
   ajaxobj.content=fdata;
   ajaxobj.callback=function(xmlobj) {
    var strArray = new Array();
    strArray= xmlobj.responseText.split('`');
    for (i=0;i<strArray.length;i++)
    {
        var obj=getid(selectid);
        writeselect(obj,strArray[i],strArray[i]);
    }
    getid(selectid).selectedIndex=1;
}
   ajaxobj.send();
}

function writeselect(obj,value,text)
{
    var opt = document.createElement("option")
    opt.text = text;
    opt.value   = value;
    obj.add(opt);
}

function clearselect(obj)
{
    var len=obj.options.length;
    for (var i=len;i>=0;i--)
    {
        obj.remove(i);
    }
}