tJobtitle_id = new Array;
tJobtitle_nm = new Array;
var g_jobtitlebox = null;
var g_set_job_val = 0;

var g_jobtitlebox_wait = null;
var g_set_job_val_wait = 0;

var job_list = new Array();
var empty_job_list = "#请先选择职能..."

var ajaxGetJob = new sack();

/*
	<tr >
	<td colspan="4"> 
	<div id="replaceme"></div>|<div id="sackdata"></td>
	</tr>
*/
function whenLoading()
{
	//var e = document.getElementById('replaceme'); 
	//e.innerHTML = "Sending...";
    if (g_jobtitlebox) {
		g_jobtitlebox.options[0] = new Option("-正在加载职位数据-", "");
		g_jobtitlebox.length = 1;
    }
    document.getElementById('imgloading').style.display = "block";
}

function whenLoaded()
{
	//var E = document.getElementById('replaceme'); 
	//e.innerHTML = "Sent...";
    if (g_jobtitlebox) {
		g_jobtitlebox.options[0] = new Option("-请稍候-", "");
		g_jobtitlebox.length = 1;
    }
}

function whenInteractive()
{
	//var e = document.getElementById('replaceme'); 
	//e.innerHTML = "Getting data...";
    if (g_jobtitlebox) {
		g_jobtitlebox.options[0] = new Option("-正在分析数据-", "");
		g_jobtitlebox.length = 1;
    }
}

function BuildJobList(content) 
{
	var jobelements = content.split('|');
	if ((content != "") && (jobelements.length > 0)) {
	    tJobtitle_id.length = 0;
	    for(var no=0;no<jobelements.length;no++){
	        thisjob = jobelements[no].split('#')
	        tJobtitle_id[no] = thisjob[0];
	        tJobtitle_nm[no] = thisjob[1];
	        //alert(tJobtitle_id[no] + "#" + tJobtitle_nm[no] );
	    }
	} else 
	    tJobtitle_id.length = 0;
	
	if ((tJobtitle_id.length > 0) && (g_jobtitlebox)) {
		g_jobtitlebox.options[0] = new Option("-请选择-", "");
		for(var i = 0; i < tJobtitle_id.length; i++)
		{
			g_jobtitlebox.options[i+1] = new Option(tJobtitle_nm[i], tJobtitle_id[i]);
            if (tJobtitle_id[i]  == g_set_job_val){
                   g_jobtitlebox.options[i+1].selected = true;
            }
		}
		g_jobtitlebox.length = i+1;
    } else if (g_jobtitlebox) {
		g_jobtitlebox.options[0] = new Option("-该职能暂无职位信息-", "");
		g_jobtitlebox.length = 1;
    }
}

function whenCompleted()
{
	//var e = document.getElementById('sackdata'); 
	if (ajaxGetJob.responseStatus){
        //var string = "<p>Status Code: " + ajaxGetJob.responseStatus[0] + "</p><p>Status Message: " + ajaxGetJob.responseStatus[1] + "</p><p>URLString Sent: " + ajaxGetJob.URLString + "</p>";
    	var content = ajaxGetJob.response;
        BuildJobList(content);
	} else {
	    //var content = empty_job_list;
	    //BuildJobList(content);
		//var string = "<p>URLString Sent: " + ajaxGetJob.URLString + "</p>";
	}
	document.getElementById('imgloading').style.display = "none";
	g_jobtitlebox.disabled = false;	
    g_jobtitlebox = null;	
	//e.innerHTML = string;
}

function init_GetJob(jobcat)
{
	ajaxGetJob.setVar("cat", jobcat); // recomended method of setting data to be parsed.
	ajaxGetJob.requestFile = "/class/jobcatlist.php";
	ajaxGetJob.method = "GET";
	//ajaxGetJob.element = 'replaceme';
	ajaxGetJob.element = null;
	ajaxGetJob.onLoading = whenLoading;
	ajaxGetJob.onLoaded = whenLoaded; 
	ajaxGetJob.onInteractive = whenInteractive;
	ajaxGetJob.onCompletion = whenCompleted;
	ajaxGetJob.runAJAX();
}

function buildjobtitleselect(catbox, cat_val, jobtitlebox, job_val)
{  
    var i;
    if (cat_val != -1) {
        catalog = cat_val;
    } else if ((catbox !=null ) && (catbox.value!="")) {
		catalog = parseInt(catbox.value);//parseInt(catbox.selectedIndex);
	} else if (jobtitlebox != null)
    {
		jobtitlebox.options[0] = new Option("-请先选择职能-", "");
		jobtitlebox.length = 1;
		jobtitlebox.disabled = true;
		return;
	}
	if (cat_val !=0) {
	    if (g_jobtitlebox != null) {
	        g_jobtitlebox_wait = jobtitlebox;
	        g_set_job_val_wait = job_val;
	        catalog_wait = catalog;
	        setTimeout('do_buildjobtitleselect()', 2500);
	        return;
	    }
	    g_jobtitlebox = jobtitlebox;
	    g_set_job_val = job_val;
        init_GetJob(catalog);
    }
}

function do_buildjobtitleselect()
{
    if (g_jobtitlebox != null) {
        setTimeout('do_buildjobtitleselect()', 2500);
    } else {
        g_jobtitlebox = g_jobtitlebox_wait;
	    g_set_job_val = g_set_job_val_wait;
        init_GetJob(catalog_wait);
    }
}
