﻿var curPage = 1; //当前页面编号
var totalPage = 0; //总页数
var startPage = 1; //开始页码

//加载头部广告
function topAdIni()
{
	var arrStr
	var piceArr = new Array();
	var textArr = new Array();
	var linksArr = new Array();

	piceArr[0] = "http://www.ntrc.gov.cn/Ad_Img/2010_9_14_9_1_0.jpg";
	textArr[0] = "";
	linksArr[0] = "http://www.ntrc.gov.cn/pc-html/html-news/News_View_796.html";

	piceArr[1] = "http://www.ntrc.gov.cn/Ad_Img/2010_8_2_13_39_17.jpg";
	textArr[1] = "";
	linksArr[1] = "http://www.ntrc.gov.cn/pc-html/html-news/News_View_715.html";

	piceArr[2] = "http://www.ntrc.gov.cn/Ad_Img/2010_6_24_8_26_47.jpg";
	textArr[2] = "gff";
	linksArr[2] = "http://58.221.239.228";
	
	arrStr = new Array(piceArr,textArr,linksArr);
	innerSWF(arrStr,980,100,0);
}

function innerSWF(arr,w,h,tH){
	
     var focus_width=w
     var focus_height=h
     var text_height=tH
     var swf_height = focus_height+text_height
	 
	 var pics=arr[0].join("|"); 
	 var texts=arr[1].join("|");
	 var links=arr[2].join("|"); 

     var flashCode = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/hotdeploy/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">';
     flashCode = flashCode + '<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="http://www.ntrc.gov.cn/purecolor/script/focus2.swf"><param name="quality" value="high"><param name="bgcolor" value="#F0F0F0">';
     flashCode = flashCode + '<param name="menu" value="false"><param name=wmode value="opaque">';
     flashCode = flashCode + '<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">';
     flashCode = flashCode + '<embed src="http://www.ntrc.gov.cn/purecolor/script/focus2.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + focus_width + '" height="' + swf_height + '" FlashVars="pics=' + pics + '&links=' + links + '&texts=' + texts + '&borderwidth=' + focus_width + '&borderheight=' + focus_height + '&textheight=' + text_height + '"></embed>';
     flashCode = flashCode + '</object>';
     $("topAdArea").innerHTML=flashCode;
}

//加载工作职能
function Position_b() {
    var url = "SearchHandler.ashx";
    var pars = "act=getJobType&parentId=0";
    Ajax(url, pars, "get", Position_b_Complete, Position_b_Wait, true);
    url = null;
    pars = null;
}

function Position_b_Complete(req) {
    if (req.responseText != "") {
        var num = 0;
        eval("s =" + req.responseText);
        num = s.num;
        var tempStr = "";
        if (num > 0) {
            for (var j = 0; j < num; j++) {
                AddItemToSelect($("Position_b"), s.lists[j].jobtype, s.lists[j].id);
            }

        }
        tempStr = null;
    }
}

function Position_b_Wait() {
}

//加载工作职位
function Position_s(pid) {
    var url = "SearchHandler.ashx";
    var pars = "act=getJobType&parentId="+pid;
    Ajax(url, pars, "get", Position_s_Complete, Position_s_Wait, true);
    url = null;
    pars = null;
}

function Position_s_Complete(req) {
    $("Position_s").length = 1;
    if (req.responseText != "") {
        var num = 0;
        eval("s =" + req.responseText);
        num = s.num;
        var tempStr = "";
        if (num > 0) {
            for (var j = 0; j < num; j++) {
                AddItemToSelect($("Position_s"), s.lists[j].jobtype, s.lists[j].id);
            }

        }
        tempStr = null;
    }
}

function Position_s_Wait() {
}

//加载省
function Province() {
    var url = "SearchHandler.ashx";
    var pars = "act=getArea&parentId=0";
    Ajax(url, pars, "get", Province_Complete, Province_Wait, true);
    url = null;
    pars = null;
}

function Province_Complete(req) {
    if (req.responseText != "") {
        var num = 0;
        eval("s =" + req.responseText);
        num = s.num;
        var tempStr = "";
        if (num > 0) {
            for (var j = 0; j < num; j++) {
                AddItemToSelect($("Province"), s.lists[j].area, s.lists[j].id);
            }

        }
        tempStr = null;
    }
}

function Province_Wait() {
}

//加载市
function City(pid) {
    var url = "SearchHandler.ashx";
    var pars = "act=getArea&parentId=" + pid;
    Ajax(url, pars, "get", City_Complete, City_Wait, true);
    url = null;
    pars = null;
}

function City_Complete(req) {
    $("City").length = 1;
    if (req.responseText != "") {
        var num = 0;
        eval("s =" + req.responseText);
        num = s.num;
        var tempStr = "";
        if (num > 0) {
            for (var j = 0; j < num; j++) {
                AddItemToSelect($("City"), s.lists[j].area, s.lists[j].id);
            }

        }
        tempStr = null;
    }
}

function City_Wait() {
}

//加载区
function County(pid) {
    var url = "SearchHandler.ashx";
    var pars = "act=getArea&parentId=" + pid;
    Ajax(url, pars, "get", County_Complete, County_Wait, true);
    url = null;
    pars = null;
}

function County_Complete(req) {
    $("County").length = 1;
    if (req.responseText != "") {
        var num = 0;
        eval("s =" + req.responseText);
        num = s.num;
        var tempStr = "";
        if (num > 0) {
            for (var j = 0; j < num; j++) {
                AddItemToSelect($("County"), s.lists[j].area, s.lists[j].id);
            }

        }
        tempStr = null;
    }
}

function County_Wait() {
}

function doSearch() {
    curPage = 1;
    startPage = 1;
    getSearchContent();
}

//加载职位列表
function getSearchContent() {
    var url = "SearchHandler.ashx";
    var pars = "act=getCompanySearch&curPage=" + curPage + "&Qualification=" + escape($("Qualification").value) + "&ValidityDate=" + $("ValidityDate").value + "&Position_b=" + escape(($("Position_b").value == "" ? "" : $("Position_b").options[$("Position_b").options.selectedIndex].text)) + "&Position_s=" + escape(($("Position_s").value == "" ? "" : $("Position_s").options[$("Position_s").options.selectedIndex].text)) + "&Province=" + escape(($("Province").value == "" ? "" : $("Province").options[$("Province").options.selectedIndex].text)) + "&City=" + escape(($("City").value == "" ? "" : $("City").options[$("City").options.selectedIndex].text)) + "&County=" + escape(($("County").value == "" ? "" : $("County").options[$("County").options.selectedIndex].text)) + "&keyword=" + escape(Trim($("keyword").value.replace('请输入要查询的职位或企业名称关键字', '')));
    Ajax(url, pars, "get", getSearchContent_Complete, getSearchContent_Wait, true);
    url = null;
    pars = null;
    $("result").innerHTML = "<img src='Images/wait.gif' style='margin-top:10px;' />";
}

function getSearchContent_Complete(req) {
    if (req.responseText != "" && req.responseText.indexOf("{num") > -1) {
        eval("s =" + req.responseText);
        showResult(s);
    }
    else {
        showResult("empty");
        document.write(req.responseText);
    }
}

function getSearchContent_Wait() {
}

//显示搜索结果
function showResult(obj) {
    if (obj != "empty") {
        var result = "";
        if (obj.num > 0) {
            $("result").innerHTML = "";
            var parentObj = $("result");
            var ele;
            for (var i = 0; i < obj.lists.length; i++) {
                ele = document.createElement("ul");
                ele.className = "resultList"; //RecruitId
                ele.innerHTML = "<li style='width:230px;'><a href='http://www.ntrc.gov.cn/pc-html/html-job/Company_Job_" + obj.lists[i]["RecruitId"] + ".html' target='_blank'>" + obj.lists[i]["jobname"] + "</a></li><li style='width:230px;'><a href='http://www.ntrc.gov.cn/pc-html/html-company/Company_View_" + obj.lists[i]["comid"] + ".html' target='_blank'>" + obj.lists[i]["companyname"] + "</a></li><li style='width:80px;'>" + obj.lists[i]["Qualification"] + "</li><li style='width:140px;'>" + (obj.lists[i]["salary"] == "" ? "面议" : obj.lists[i]["salary"]) + "</li><li style='width:160px;'>" + obj.lists[i]["City"] + "-" + obj.lists[i]["County"] + "</li><li style='width:120px;'>" + obj.lists[i]["editdate"] + "</li>";
                parentObj.appendChild(ele);
            }
        }
        else {
            $("result").innerHTML = "<p style='color:#f00; line-height:30px;'>&nbsp;&nbsp;抱歉，没有找到符合条件的求职信息。</p>";
        }
        sumPages(obj.num);
        createPages();
    }
    else {
        $("result").innerHTML = "<p style='color:#f00; line-height:30px;'>&nbsp;&nbsp;抱歉，查询过程中发生错误。</p>";
    }
}

//计算总页数
function sumPages(n) {
    if (n > 0) {
        //计算总页码
        if (n / 30 == parseInt(n / 30)) {
            totalPage = parseInt(n / 30);
        }
        else {
            totalPage = parseInt(n / 30) + 1;
        }
    }
    else {
        totalPage = 0;
    }
}

//创建分页 
function createPages() {
    if (totalPage > 0) {
        var str = ""; //分页HTML

        if (startPage > 1) {
            str += "<a class='pagenum' style='color:#068DF0;' title='上一段页码' href='#' onclick='prevPage();return false;'><<</a>";
        }

        if (totalPage >= startPage + 9) {
            for (var i = startPage; i <= startPage + 9; i++) {
                if (curPage == i) {
                    str += "<a class='curpage' style='color:#068DF0;' href='#' onclick='return false;'>" + i + "</a>";
                }
                else {
                    str += "<a class='pagenum' style='color:#068DF0;' href='#' onclick='jumpPage(" + i + ");return false;'>" + i + "</a>";
                }
            }
        }
        else {
            for (var i = startPage; i <= totalPage; i++) {
                if (curPage == i) {
                    str += "<a class='curpage' style='color:#068DF0;' href='#' onclick='return false;'>" + i + "</a>";
                }
                else {
                    str += "<a class='pagenum' style='color:#068DF0;' href='#' onclick='jumpPage(" + i + ");return false;'>" + i + "</a>";
                }
            }
        }
        if (totalPage > startPage + 9) {
            str += "<a class='pagenum' style='color:#068DF0;' title='下一段页码' href='#' onclick='nextPage();return false;'>>></a>";
        }
        $("pageList").innerHTML = str;
        str = null;
    }
    else {
        $("pageList").innerHTML = "";
    }
}

//上一段分页
function prevPage() {
    startPage = curPage = startPage - 10;
    getSearchContent();
}

//下一段分页
function nextPage() {
    startPage = curPage = startPage + 10;
    getSearchContent();
}

//页面跳转
function jumpPage(pn) {
    curPage = pn;
    getSearchContent();
}

window.onload = function () {
    getSearchContent();
    Position_b();
    Province();
    //topAdIni();
}
