﻿/// <reference path="../extjs_intellisense.js" />
$(document).ready(function(){
$("#gameList").trigger("change");
    //  临时注释
    //InitializationSpaceGameForSelect("gameList","gameAreaList","gameServerList",{}, true);    
}); 

function searchUser(){
    var key = $("#searchKey").val();
    if(key == "请输入姓名或角色名")
        key=' ';
//    if(key == ""){
//        alert("用户昵称不能为空。");
//        $("#searchKey")[0].focus();
//        return;
//    }
    var url = "/gsearch?from=1&gnk=" + escape(key);
    window.open(url);
}
function ChangeSearchType(){
    var type = $("#searchType").html();
    if(type == "简易搜索"){
        $("#searchType").html("高级搜索");
        $("#trSex,#trAge,#trSpace,#trSpace2").css("display", "none");
    } else {
        $("#searchType").html("简易搜索");
        $("#trSex,#trAge,#trSpace,#trSpace2").css("display", "");
        var proLength = $("#provinceList")[0].options.length;
        if(parseInt(proLength) < 5){
            getAllProvince();
        }
    }
}
//function changeGame(){
//    var gameId = $("#gameList").val();
//    if(gameId != "-1"){
//        var url = "/m/ajax?action=GetAreaByGameId&uin=" + $("#homeUserId").val();
//        var param = {"gameId":gameId};
//        $.post(url, param, function(msg){
//            var result = msg.split("{$}");
//            $("#gameAreaList").html("");
//            $("#gameAreaList")[0].options.add(new Option("请选择大区", "-1", false, false));
//            for(var i=0; i< result.length; i++){
//                var res = result[i].split("{&}");
//                $("#gameAreaList")[0].options.add(new Option(res[1], res[0], false, false));
//            }
//            $("#gameAreaList").removeAttr("disabled");
//        });
//    } else {
//        $("#gameAreaList").html("");
//        $("#gameAreaList")[0].options.add(new Option("请选择大区", "0", false, false));
//        $("#gameAreaList").attr("disabled", "disabled");
//    }
//    $("#gameServerList").html("");
//    $("#gameServerList")[0].options.add(new Option("请选择服务器", "-1", false, false));
//    $("#gameServerList").attr("disabled", "disabled");
//}
//function changeArea(){
//    var gameId = $("#gameList").val();
//    var areaId = $("#gameAreaList").val();
//    if(areaId != "-1"){
//        var url = "/m/ajax?action=GetServerByGameIdAndAreaId&uin=" + $("#homeUserId").val();
//        var param = {"gameId":gameId, "areaId":areaId};
//        $.post(url, param, function(msg){
//            var result = msg.split("{$}");
//            $("#gameServerList").html("");
//            $("#gameServerList")[0].options.add(new Option("请选择服务器", "-1", false, false));
//            for(var i=0; i< result.length; i++){
//                var res = result[i].split("{&}");
//                $("#gameServerList")[0].options.add(new Option(res[1], res[0], false, false));
//            }
//            $("#gameServerList").removeAttr("disabled");
//        });
//    } else {
//        $("#gameServerList").html("");
//        $("#gameServerList")[0].options.add(new Option("请选择服务器", "-1", false, false));
//        $("#gameServerList").attr("disabled", "disabled");
//    }
//}
function searchFriendAdv(){
    var key = "", game = "", area = "", server = "", sex = "", age1 = "", age2 = "", province = "", city = "", xb='';
    if($("#keyWord").length > 0){
        key = $("#keyWord").val();
        key = key.replace("请输入姓名或角色名", "");
    }
    if($("#gameList").length > 0){
        game = $("#gameList").val();
    }
    if($("#gameAreaList").length > 0){
        area = $("#gameAreaList").val();
    }
    if($("#gameServerList").length > 0){
        server = $("#gameServerList").val();
    }
    if($("#sex").length > 0){
        sex = $("#sex").val();
    }
    if($("#ageSmall").length > 0){
        age1 = $("#ageSmall").val();
    }
    if($("#ageBig").length > 0){
        age2 = $("#ageBig").val();
    }
    if($("#provinceList").length > 0){
        province = $("#provinceList").val();
    }
    if($("#cityList").length > 0){
        city = $("#cityList").val();
    }
    
    var url = "/gsearch?from=1";
    var pp = "";
    if(key.length > 0){
        pp += "&gnk=" + escape(key);
    }
    if(game != "-1" && game != "请选择"){
        pp += "&gin=" + game;
    }
        //url += "&glv=";
    if(area != "-1" && area != "请选择"){
        pp += "&gar=" + area;
    }
    if(server != "-1" && server != "请选择"){
        pp += "&gsr=" + server;
    }
    if(age1 != "-1" && age2 != "0"){
        pp += "&a1=" + age1;
    }
    if(age2 != "-1" && age2 != "0"){
        pp += "&a2=" + age2;
    }
    if(sex != "-1" && sex != "0"){
        pp += "&xb=" + sex;
    }
    if(province != "-1" && province != "0" && province != ""){
        province = getSelectText($("#provinceList")[0],parseInt(province));
//        province = province.replace("省", "");
//        province = province.replace("市", "");
//        province = province.replace("自治区", "");
//        province = province.replace("壮族", "");
//        province = province.replace("回族", "");
//        province = province.replace("维吾尔", "");
//        province = province.replace("特别行政区", "");
        province = escape(province);
        pp += "&rs0=" + province;
    }
    if(city != "-1" && city != "0" && city != ""){
        city = getSelectText($("#cityList")[0], parseInt(city));
        city = escape(city);
        pp += "&rs1=" + city;
    }
    //alert(url);
    if($("#sex").val() != -1){
        pp += "&xb=" + $("#sex").val();
    }

    if(pp.length == 0){
        pp += "&gnk=" + escape(' ');
    }
    
    window.open(url + pp);
}
function getSelectText(obj, j){
    var text = "";
    for(var i=0; i<obj.options.length; i++){
        if(obj.options[i].value == j){
            text = obj.options[i].text;
            break;
        }
    }
    return text;
}
function getAllProvince(){
    var url = "/m/ajax?action=GetAllProvince&uin=" + $("#homeUserId").val();
    var param = {"uin":$("#homeUserId").val()};
    $.post(url, param, GetAllProvinceHandle);
    function GetAllProvinceHandle(msg){
        provinceListString = msg;
        setProvince();
    }   
}
function setProvince(){
    var result = provinceListString.split("{$}");
    $("#provinceList").html("");
    $("#provinceList")[0].options.add(new Option("请选择", "-1", false, false));
    for(var i=0; i< result.length; i++){
        var res = result[i].split("{&}");
        $("#provinceList")[0].options.add(new Option(res[1], res[0], false, false));
    }
    $("#provinceList").removeAttr("disabled");
}
function getCity(){
    var url = "/m/ajax?action=GetCity&uin=" + $("#homeUserId").val();
    var param = {"pro":$("#provinceList").val()};
    $.post(url, param, GetCityHandle);
    function GetCityHandle(msg){
        var result = msg.split("{$}");
        $("#cityList").html("");
        $("#cityList")[0].options.add(new Option("请选择", "-1", false, false));
        for(var i=0; i< result.length; i++){
            var res = result[i].split("{&}");
            $("#cityList")[0].options.add(new Option(res[1], res[0], false, false));
        }
        $("#cityList").removeAttr("disabled");
    }
}
function showAdvSearch(){
    $("#simpleSearch").hide();
    $("#advSearch").show();
}
function showSimSearch(){
    $("#simpleSearch").show();
    $("#advSearch").hide();
}