var PageName = "http://searchjob.chinahr.com/SearchResult.aspx";
$(document).ready(function() {
    $("#btnSearch").bind("click", search);
    var urlKey = $ID("UrlKey").value;
    var CurUrl = document.location.href.toLowerCase();
    if (urlKey != "" && urlKey != "undefined")
        PopupSelector.loadSelected(urlKey);
    else if (document.location.href.toLowerCase().indexOf('www.chinahr.com') > -1)
    { }
    else if (document.location.href.toLowerCase().indexOf('quanguo.chinahr.com') > -1)
    { }
    else {
        var CurName = CurUrl.substring(CurUrl.indexOf("//") + 2, CurUrl.indexOf("."));
        var Url = Convertdomain(CurName);
        PopupSelector.loadSelected(Url);
    }

    $("#txtKeywords").keydown(function(ev) {
        if (ev.which == 13) {
            var val = $(this).val();
            if (val != "" && val != "结果中包含该关键词") search();
        }
    });
    document.getElementById("txtKeywords").onclick = function() {
        if (this.value == "结果中包含该关键词")
            this.value = "";
    }

});
function Convertdomain(id) {
    var Item;
    var myLocparentIDList = "-1";
    switch (id) {
        case "beijing":
            Item = "30000";
            break;
        case "shanghai":
            Item = "31000";
            break;
        case "guangzhou":
            Item = "40";
            myLocparentIDList = "16000";
            break;
        case "suzhou":
            Item = "220";
            myLocparentIDList = "7000";
            break;
        case "shenzhen":
            Item = "125";
            myLocparentIDList = "16000";
            break;
        case "zhusanjiao":
            Item = "225";
            myLocparentIDList = "16000";
            break;
        case "hangzhou":
            Item = "55";
            myLocparentIDList = "8000";
            break;
        case "ningbo":
            Item = "107";
            myLocparentIDList = "8000";
            break;
        case "wuxi":
            Item = "152";
            myLocparentIDList = "7000";
            break;
        case "tianjin":
            Item = "32000";
            break;
        case "xian":
            Item = "160";
            myLocparentIDList = "23000";
            break;
        case "wuhan":
            Item = "150";
            myLocparentIDList = "14000";
            break;
        case "nanjing":
            Item = "100";
            myLocparentIDList = "7000";
            break;
        case "chengdu":
            Item = "20";
            myLocparentIDList = "19000";
            break;
        case "changsha":
            Item = "15";
            myLocparentIDList = "15000";
            break;
        case "dalian":
            Item = "30";
            myLocparentIDList = "4000";
            break;
        case "hebei":
            Item = "1000";
            break;
        case "shandong":
            Item = "12000";
            break;
        case "fujian":
            Item = "10000";
            break;
        case "chongqing":
            Item = "33000";
            break;
        case "zhengzhou":
            Item = "175";
            myLocparentIDList = "13000";
            break;
        case "shenyang":
            Item = "120";
            myLocparentIDList = "4000";
            break;
        case "taiyuan":
            Item = "135";
            myLocparentIDList = "2000";
            break;
        case "hefei":
            Item = "65";
            myLocparentIDList = "9000";
            break;
        default:
            break;
    }
    Item = "myLocIDList=" + Item + "&myLocparentIDList=" + myLocparentIDList;
    return Item;
}
function search() {
  	if (($("#txtKeywords").val() == "" || $("#txtKeywords").val().replace(/[ ]/g, "") == "" || $("#txtKeywords").val() == "结果中包含该关键词") &&($("#txtCat").val()==""||$("#txtCat").val()=="请选择职位类别"))
	 {
		alert("请选择\"职位类别\"，或者填写有效的\"关键词\"进行搜索。");
		$("#txtKeywords")[0].focus();
		return;
	}
	var params = {};
    var arr1 = [], arr2 = [];
    jQuery.each(PopupSelector._selItems["cat"], function() {
    arr1.push(this.id);
    if (this.parObj != null)
	    arr2.push(this.parObj.id);
    else
	    arr2.push(this.id);
    });
    if (arr1.length > 0){
    
    params["occIDList"] =arr1.join(",");
    params["occParentIDList"] =arr2.join(",");
    }

    arr1.clear();
    arr2.clear();

	jQuery.each(PopupSelector._selItems["loc"], function() {
		arr1.push(this.id);
		if (this.parObj != null)
			arr2.push(this.parObj.id);
		else
			arr2.push(this.id);
	});
	if (arr1.length > 0){
	   
		params["myLocIDList"] = arr1.join(",");
		params["myLocParentIDList"] =arr2.join(",");
	}
	
	arr1.clear();
	arr2.clear();
	jQuery.each(PopupSelector._selItems["ind"], function() {
		arr1.push(this.id);
	});
	if (arr1.length > 0)
	{
	    
		params["indIDList"] = arr1.join(",");
    }
	arr1.clear();
	arr2.clear();
	var url = PageName + "?" + jQuery.param(params);
	if ($("#txtKeywords").val() != "结果中包含该关键词" && $("#txtKeywords").val().replace(/[ ]/g, "") != "") {
    		if ($("#radJob")[0].checked) url += "&positionName=" + UrlEncode($("#txtKeywords").val());
		if ($("#radComp")[0].checked) url += "&companyName=" + UrlEncode($("#txtKeywords").val());
	}
	var CurrentUrl=document.location.href;
	var Index=CurrentUrl.indexOf('.');
	var IndexHttp=CurrentUrl.indexOf('http://')
	var PrjTarGet=document.location.href.substring(IndexHttp+7,Index);
	url =url+"&prj="+PrjTarGet;
	$ID("UrlKey").value=url;
  if(typeof(appendRnd)!="undefined")
    url = appendRnd(url);
  document.location.href = url;
		}
		//转换工作地区
function ConverterLoc(obj)
{
    var Item;
   	switch (obj)
   	{
		case "5":
			Item="30000";
			break;
		case "115":
			Item="31000";
			break;
		case "140":
			Item="32000";
			break;
		case "25":
			Item="33000";
			break;
		case "185":
			Item="34000";
			break;
		case "190":
			Item="35000";
			break;
		case "195":
			Item="36000";
			break;
		case "200":
			Item="37000";
			break;
		case "205":
			Item="38000";
			break;
		case "210":
			Item="39000";
			break;
		case "215":
			Item="40000";
			break;
		case "230":
			Item="41000";
			break;
		case "235":
			Item="42000";
			break;
		default:
			Item=obj;
			break;
	}
	return Item;
}
//添加特殊行业类别转换函数
function ConverterInd(obj)
{

   var array=new Array();
   var strList=",";
   array=obj.split(',');
   var SubItem="";
   for(var i=0;i<array.length;i++)
   {
        SubItem=ConverterIndSubItem(array[i].toString());
        strList+=SubItem+",";
   }
   strList=TrimLR(strList,',');
   return strList;
   
}
///te
function ConverterIndSubItem(obj)
{
    var Item;
   	switch (obj)
   	{
		case "1107000":
			Item="100";
			break;
		case "1108000":
			Item="100";
			break;
		case "1109000":
			Item="100";
			break;
		case "1117000":
			Item="3700";
			break;
		case "1110000":
			Item="1000";
			break;
		case "1111000":
			Item="1000";
			break;
		case "1112000":
			Item="1000";
			break;
		case "1119000":
			Item="2200";
			break;
		case "1120000":
			Item="2200";
			break;
		default:
			Item=obj;
			break;
	}
	return Item;
}
		


		