﻿var arrCon=new Array();
var arrPro=new Array();
var arrCity=new Array();

function getcity()
{
    ajax("/handler/city.ashx?com=get","getcityCallback");
}
function getcityCallback(res)
{
    var arrTmp=res.split("\n");
    arrCon=arrTmp[0].split("|");
    arrPro=arrTmp[1].split("|");
    arrCity=arrTmp[2].split("|");
    loadPageControl();
}

function loadPageControl()
{ 
    var objCountry=$("selLocalityCountry"); 
    var objCountry2=$("selNativeplaceCountry");
    objCountry.options.length = 0;
    objCountry2.options.length = 0;
    
    for (i=0;i<arrCon.length;i++)
    {
        if (arrCon[i]=="") continue;
        var tmpArray=new Array();
        tmpArray=arrCon[i].split(",");
        addSelectItem(objCountry,tmpArray[1],tmpArray[0]);
        addSelectItem(objCountry2,tmpArray[1],tmpArray[0]);
    }
    
    addSelectItem(objCountry,"不限","0");
    addSelectItem(objCountry2,"不限","0");
    
    objCountry.onchange=function (e){objCountry_OnChange(this);};
    objCountry2.onchange=function (e){objCountry_OnChange(this);};
    
    objCountry.selectedIndex=objCountry.options.length-2;
    objCountry2.selectedIndex=objCountry2.options.length-2;
    objCountry_OnChange(objCountry);
    objCountry_OnChange(objCountry2);
    
}

function objCountry_OnChange(obj)
{
    var objCity=$(obj.id+"selProvince"+"selCity");
    if (objCity) obj.parentNode.removeChild(objCity);
        
    var id=obj.options[obj.selectedIndex].value;
    
    var hasP=false;
    var objPro=$(obj.id+"selProvince");
    if (!objPro)
    {
        objPro = document.createElement("select");
        objPro.id=obj.id+"selProvince";
        objPro.className="select_2";
        obj.parentNode.appendChild(objPro);
        objPro.onchange=function (e){objPro_OnChange(this);};
    }
    objPro.options.length = 0;
    
    addSelectItem(objPro,"不限","0");
    for (i=0;i<arrPro.length;i++)
    {
        var tmpArray=new Array();
        tmpArray=arrPro[i].split(",");
        if (tmpArray[1]==id)
        {
            addSelectItem(objPro,tmpArray[2],tmpArray[0]);
            hasP=true;
        }
    }
    objPro.selectedIndex=objPro.options.length-10;//小包添加，默认选择上海
    if (!hasP) obj.parentNode.removeChild(objPro);
    else objPro_OnChange(objPro);
    
    
}

function objPro_OnChange(obj)
{
    var id=obj.options[obj.selectedIndex].value;
    
    var hasP=false;
    var objCity=$(obj.id+"selCity");
    if (!objCity)
    {
        objCity = document.createElement("select");
        objCity.id=obj.id+"selCity";
        objCity.className="select_3";
        obj.parentNode.appendChild(objCity);
        objCity.onchange=function (e){objCity_OnChange(this);};
    }
    objCity.options.length = 0;
    
    addSelectItem(objCity,"不限","0");
    for (i=0;i<arrCity.length;i++)
    {
        var tmpArray=new Array();
        tmpArray=arrCity[i].split(",");
        if (tmpArray[1]==id)
        {
            addSelectItem(objCity,tmpArray[2],tmpArray[0]);
            hasP=true;
        }
    }
    if (!hasP) obj.parentNode.removeChild(objCity);
    
}

function objCity_OnChange(obj)
{
    var id=obj.options[obj.selectedIndex].value;
}

function addSelectItem(objSelect,text,value) 
{
    var item = new Option(text, value);      
    objSelect.options.add(item);
}

function FormIni()
{
    getcity();
    $("btnSearch").onclick=function(e){search();}
    $("btnSimpleSearch").onclick=function(e){simpleSearch();}
    
    $("simSearch").onkeydown = function (e)
    {
        var theEvent = window.event || e;
        var code = theEvent.keyCode || theEvent.which;
        if (code==13) 
        {
            ObjClick( $("btnSimpleSearch"));
        }
    };
    $("higSearch").onkeydown = function (e)
    {
        var theEvent = window.event || e;
        var code = theEvent.keyCode || theEvent.which;
        if (code==13) 
        {
            ObjClick( $("btnSearch"));
        }
    };
}

function simpleSearch()
{
    var objFormat=document.createElement("textarea");
    function formatstr(str)
    {
        objFormat.value=str;
        return objFormat.innerHTML;
    }
    
    var nickName=$("txtNickName").value.Trim();
    var userID=$("txtUserID").value.Trim();
    var para="";
    var shunxu=0;
    if (nickName!="") para+="&nickname="+escape(formatstr(nickName));
    if (userID!="")
    {
        if (!IsUInt(userID))
        {
            alert("请输入正确的会员ID");
            $("txtUserID").focus();
            return;
        }
        para+="&userid="+escape(formatstr(userID));
    }
    if (shunxu == "0") {
        para += "&shunxu=" + shunxu;                             //默认排序
    }
    if (para=="")
        alert("请先填入搜索条件");
    else
        window.location.href=("searchinfo.aspx?page=1"+para);
}

function search()
{
    var sex=($("radioMan").checked?0:1); //性别
    
    var lcountry=0; //所在地国家
    var lprovince=0;//所在地省
    var lcity=0;//所在地市
    if ($("selLocalityCountry").value!="")
        lcountry=$("selLocalityCountry").options[$("selLocalityCountry").selectedIndex].value;
    if($("selLocalityCountry"+"selProvince"))
        if ($("selLocalityCountry"+"selProvince").value!="")
            lprovince=$("selLocalityCountry"+"selProvince").options[$("selLocalityCountry"+"selProvince").selectedIndex].value;
    if ($("selLocalityCountry"+"selProvince"+"selCity"))
        if ($("selLocalityCountry"+"selProvince"+"selCity").value!="")
            lcity=$("selLocalityCountry"+"selProvince"+"selCity").options[$("selLocalityCountry"+"selProvince"+"selCity").selectedIndex].value;
    var age1=$("selAge1").options[$("selAge1").selectedIndex].value//年龄1
    var age2=$("selAge2").options[$("selAge2").selectedIndex].value//年龄2
    var height1=$("selHeight1").options[$("selHeight1").selectedIndex].value//身高1
    var height2=$("selHeight2").options[$("selHeight2").selectedIndex].value//身高2
    var education=$("selEducation").options[$("selEducation").selectedIndex].value;//学历
    var salary=$("selSalary").options[$("selSalary").selectedIndex].value;//月薪
    var personalproperty=$("selPersonalproperty").options[$("selPersonalproperty").selectedIndex].value;//个人资产
    var civilstate=$("selCivilstate").options[$("selCivilstate").selectedIndex].value;//婚姻状况
    var childstate=$("selChildstate").options[$("selChildstate").selectedIndex].value;//子女状况
    var profession=$("selProfession").options[$("selProfession").selectedIndex].value;//职业
    var companytype=$("selCompanytype").options[$("selCompanytype").selectedIndex].value;//公司类型
    var house=$("selHouse").options[$("selHouse").selectedIndex].value;//住房
    var car=$("selCar").options[$("selCar").selectedIndex].value;//购车
    
    var ncountry=0;//籍贯国家
    var nprovince=0;//籍贯省
    var ncity=0;//籍贯市
    if ($("selNativeplaceCountry").value!="")
        ncountry=$("selNativeplaceCountry").options[$("selNativeplaceCountry").selectedIndex].value;
    if($("selNativeplaceCountry"+"selProvince"))
        if ($("selNativeplaceCountry"+"selProvince").value!="")
            nprovince=$("selNativeplaceCountry"+"selProvince").options[$("selNativeplaceCountry"+"selProvince").selectedIndex].value;
    if($("selNativeplaceCountry"+"selProvince"+"selCity"))
        if ($("selNativeplaceCountry"+"selProvince"+"selCity").value!="")
            ncity=$("selNativeplaceCountry"+"selProvince"+"selCity").options[$("selNativeplaceCountry"+"selProvince"+"selCity").selectedIndex].value;
    var nationality=$("selNationality").options[$("selNationality").selectedIndex].value;//民族
    var religion=$("selReligion").options[$("selReligion").selectedIndex].value;//宗教信仰
    var haspp=($("rdHavephoto").checked?1:0);//有无照片
    var renzheng = ($("renzheng").checked ? 1 : 0); //是否认证会员
    var shunxu = 0;
    
    var para="";
    var z="";
    if (!$("radioSexNo").checked) para+="&sex="+sex;                            //性别
    if (lcountry!="0") para+="&lcountry="+lcountry;                             //所在地国家
    if (lprovince!="0") para+="&lprovince="+lprovince;                          //所在地省
    if (lcity!="0") para+="&lcity="+lcity;                                      //所在地市
    if (age1!="0") para+="&age1="+age1;                                         //年龄1
    if (age2!="0") para+="&age2="+age2;                                         //年龄2
    if (height1!="0") para+="&height1="+height1;                                //身高1
    if (height2!="0") para+="&height2="+height2;                                //身高2
    if (education!="0") para+="&education="+education;                          //学历
    if (salary!="0") para+="&salary="+salary;                                   //月薪
    if (personalproperty!="0") para+="&personalproperty="+personalproperty;     //个人资产
    if (civilstate!="0") para+="&civilstate="+civilstate;                       //婚姻状况
    if (childstate!="0") para+="&childstate="+childstate;                       //子女状况
    if (profession!="0") para+="&profession="+profession;                       //职业
    if (companytype!="0") para+="&companytype="+companytype;                    //公司类型
    if (house!="0") para+="&house="+house;                                      //住房
    if (car!="0") para+="&car="+car;                                            //购车
    if (ncountry!="0") para+="&ncountry="+ncountry;                             //籍贯国家
    if (nprovince!="0") para+="&nprovince="+nprovince;                          //籍贯省
    if (ncity!="0") para+="&ncity="+ncity;                                      //籍贯市
    if (nationality!="0") para+="&nationality="+nationality;                    //民族
    if (religion!="0") para+="&religion="+religion;                             //宗教信仰
    if (!$("rdHavephotoNo").checked) para+="&haspp="+haspp;                                                      //有无照片
    if (!$("renzhengNo").checked) {
        para += "&renzheng=" + renzheng;                     //有无照片22222222222222
        z += "," + ((renzheng == "0") ? "不限" : "认证会员");
    }
    if (shunxu == "0") {
        para += "&shunxu=" + shunxu;                             //默认排序
    }
    //alert(para);
    if (para=="")
        alert("请先选择搜索条件");
    else
        window.location.href=("searchinfo.aspx?page=1"+para);
}

FormIni();
