﻿function overtable(this_s) {
    this_s.style.background = '#e5f1ff';
};
function outtable(this_s) {
    this_s.style.background = '';
};
function GetCookieSubValue(sCookieName, sKeyName) {
    // get the single cookies
    var _aCookies = sCookieName.split('&');
    var _iLenght = _aCookies.length;
    // parse cookies
    while (_iLenght--) {
        var _aCurrrent = _aCookies[_iLenght].split("=");
        // find the requested one
        if (jQuery.trim(_aCurrrent[0]) === sKeyName) { return decodeURI(_aCurrrent[1]); }
    }
};
function SelectCity() {
    if ($("#selecCity").val() != "0" && $("#selecCity").val() != "") {
        var sUrl = "http://" + $("#selecCity").val() + ".dadou.com/";
        //location.replace(sUrl);
        window.location.href = sUrl;
    }
};
$(function() {
    var vCookie = $.jCookie("User");
    var vCityName = $.jCookie("CityName");
    var vCitySpell = $.jCookie("CitySpell");
    $("#h2Title").html(vCityName);
    if (vCityName != false) {
        var vCityShowSpell = "<a href='http://" + vCitySpell + ".dadou.com/'>进入" + vCityName + "站--&gt;&gt;</a>";
        $("#CityShowSpell").html(vCityShowSpell);
    }

    if (vCookie != false) {
        vUserName = GetCookieSubValue(vCookie, "UserName");
        $("#ulUserName").html("<li><a href='/User/DelCookie.aspx' id='aLoginOut'>退出</a></li>");
        $("#ulUserName").append("<li><a href='/User/index.aspx'>用户中心</a></li>");
        $("#ulUserName").append("<li><a href='/User/index.aspx'>" + vUserName + "</a></li>");
    };
    var sSearch = $("#inputSearch").val();
    $("#inputSearch").click(function() {
        if ($("#inputSearch").val() == sSearch) {
            $("#inputSearch").val("");
        }
    });

    //escape,encodeURI,encodeURIComponent，相应3个解码函数：unescape,decodeURI,decodeURIComponent
    $("#bntSearch").click(function() {
        if ($("#inputSearch").val() == sSearch) {
            return;
        }
        var sUrl = "/search.aspx?iCate2ID=" + $("#ddlstCate2").val() + "&sKey=" + encodeURIComponent($("#inputSearch").val());
        //location.replace(sUrl);
        window.location.href = sUrl;
    });

    //escape,encodeURI,encodeURIComponent，相应3个解码函数：unescape,decodeURI,decodeURIComponent
    $("#bntSearchCate").click(function() {
        if ($("#inputSearchCateKey").val() == "") {
            return;
        }
        var sUrl = "/search.aspx?iCate2ID=" + $("#inputSearchCateID").val() + "&sKey=" + encodeURIComponent($("#inputSearchCateKey").val());
        //location.replace(sUrl);
        window.location.href = sUrl;
    });

    $("#bntSelectCity").click(function() {
        SelectCity();
    })
});

function getCity() {
    //获得省份下拉框的对象
    //var sltProvince=document.form1.province;
    var sltProvince = $("#selectProvince")[0];
    //获得城市下拉框的对象
    //var sltCity = document.form1.city;
    var sltCity = $("#selecCity")[0];
    //

    //得到对应省份的城市数组
    var provinceCity = vCity[sltProvince.selectedIndex - 1];
    var provinceCityValue = vCityValue[sltProvince.selectedIndex - 1];
    //清空城市下拉框，仅留提示选项 
    sltCity.length = 1;
    //将城市数组中的值填充到城市下拉框中 
    for (var i = 0; i < provinceCity.length; i++) {
        sltCity[i + 1] = new Option(provinceCity[i], provinceCityValue[i]);
    }
};
function getCate2() {
    //获得省份下拉框的对象
    var sltCate1 = $("#ddlstCate1")[0];
    //获得城市下拉框的对象
    var sltCate2 = $("#ddlstCate2")[0];
    //
    //得到对应省份的城市数组
    var Cate1Cate2List = vCate2[sltCate1.selectedIndex - 1];
    var Cate2Cate1ListValue = vCate2Value[sltCate1.selectedIndex - 1];
    //清空城市下拉框，仅留提示选项 
    sltCate2.length = 1;
    //将城市数组中的值填充到城市下拉框中 
    for (var i = 0; i < Cate1Cate2List.length; i++) {
        sltCate2[i + 1] = new Option(Cate1Cate2List[i], Cate2Cate1ListValue[i]);
    }
};
function Check(parentChk,ChildId,ControlName)   
{   
    var oElements = document.getElementsByTagName("INPUT");   
    var bIsChecked = parentChk.checked;   
  
   for(i=0; i<oElements.length;i++)   
    {   
        if( IsCheckBox(oElements[i]) &&    
            IsMatch(oElements[i].id, ChildId,ControlName))   
        {   
            oElements[i].checked = bIsChecked;   
        }           
    }      
 };   
  
function IsMatch(id, ChildId,ControlName)   
{   
    var sPattern ='^'+ControlName+'.*'+ChildId+'$';   
    var oRegExp = new RegExp(sPattern);   
    if(oRegExp.exec(id))    
        return true;   
    else    
        return false;   
} ;

function IsCheckBox(chk) {
    if (chk.type == 'checkbox') return true;
    else return false;
};   
