/***************************************************************************************
 * @Title        : JavaScript Document
 * @Description  : Tzzp.Com JavaScript Document
 * @Company      : Tzzp.Com Computer
 * @Program      : JavaScript
 * @Author       : Fanlei.Wang
 * @Email        : alei.shuaige@163.com
 * @version      : 9.0
 * @Copyright    : (c)2005-2010 Tzzp.Com All Rights Reserved
 ***************************************************************************************/

/**公共变量*/
var jobLen=3;  
/**
*下拉列表的值的改变
*mainitem:主类表单元素
*subitem:子类表单元素
*catalog:分类(城市、职位类别等主要是方便函数的重用)
*/
function selectOnchange(mainitem,subitem,catalog)
{
    var flag = 0; //显示中文
	setSubSelectItem(catalog,mainitem,subitem,flag);
}
/**
*设置子类表单元素的值
*catalog：类别
*mainitem：主对象
*subitem：子对象
*flag：标志位
*/
function setSubSelectItem(catalog,mainitem,subitem,flag)
{
	var itemCount;
	var items = new Array();
	var subvalue=mainitem.options[mainitem.selectedIndex].value;  
	var subtext=mainitem.options[mainitem.selectedIndex].text;  
	var szHref = document.location.href.toUpperCase();
	if(catalog=='jobcatelog')
	{
		subitem.length = 0;
		itemCount = catelogCount;
		items = catelogs;
		var opt=document.createElement("OPTION");
		if((subvalue == '') || (subvalue=='0'))
		{            
			opt.text="不限";
			opt.value="";            
				subitem.options.add(opt);
            return;
		}
		var bWork = ((szHref.indexOf('PER_')>-1||szHref.indexOf('GR_')>-1) && (szHref.indexOf('RESUME_SEARCH')<0) );
		var bJob = ((szHref.indexOf('_CAREERWILL')>-1)||(szHref.indexOf('_REGISTRYSTEPTWO')>-1)||(szHref.indexOf('_AUDIT')>-1));
		for (i=0;i<itemCount; i++)
		{
		
			if ((items[i][2]).substring(0,2) == subvalue.substring(0,2))
			{
				if ( (bJob&&i<itemCount-1) || (bWork&&i<itemCount-1))
				{
					var opt=document.createElement("OPTION");
					if (flag==1)  opt.text=items[i+1][1];
					else  opt.text=items[i+1][0];
					opt.value=items[i+1][2];					
					if (opt.value.substring(0,2) == subvalue.substring(0,2) && i<itemCount-2){
					    subitem.options.add(opt);
					}
				}
				else
				{
					var opt=document.createElement("OPTION");
					if (flag==1)  opt.text=items[i][1];
					else  opt.text=items[i][0];
					opt.value=items[i][2];
						subitem.options.add(opt);
				}
			}
		}
	}
}
/**
*向多选择列表中添加元素
*mObject:主选项
*sObject:源对象
*tObject:目标对象
*catalog:操作标志
*/
function multiSelect_additem(mObject,sObject,tObject,catalog)
{
	var itemtext,itemvalue;   
	/**城市下拉项新增处理*/
	if(catalog=='citys')
	{
		if(sObject.options [sObject.selectedIndex].text.indexOf("不限")>-1)
		{
			itemtext=sObject.options [sObject.selectedIndex].text;
		}
		else
		{
			var text1=mObject.options [mObject.selectedIndex].text;
			var text2=sObject.options [sObject.selectedIndex].text.replace("├-","").replace("∟","");
			if(text1!=text2)
			{
				itemtext=text1 + text2;
			}
			else
			{
				itemtext=text1;
			}
		}
		if(document.location.href.indexOf('company')=="-1")
		{
			itemvalue=sObject.options[sObject.selectedIndex].value; //Edit by Lzj.Liu
		}
		else
		{
			if(itemvalue=mObject.options[mObject.selectedIndex].value!=sObject.options[sObject.selectedIndex].value.replace("",""))
			{
				itemvalue=itemvalue=mObject.options[mObject.selectedIndex].value+sObject.options[sObject.selectedIndex].value;
			}
			else
			{
				itemvalue=itemvalue=mObject.options[mObject.selectedIndex].value;
			}
		}
		var option=document.createElement("OPTION");
		option.text=itemtext;
		option.value=itemvalue;
		if (tObject.length<3)
		{
		    for (i = 0; i < tObject.length; i++) {
		        v = tObject.options[i].value;
		        t = tObject.options[i].text;
		        if (v == itemvalue) { alert('您已经选择该项.'); return; }  //从上面移出

		        if ((itemvalue == '-1' || itemvalue == '' || itemtext == '不限')) {
		            alert('您已经选择了该项所在的类别中的子项.');
		            return;
		        }
		    }  
			setJobLocaPara(mObject,sObject,tObject);
				tObject.options.add(option);
			setJobLocation(tObject);
		}
		else {
		    alert('您已经选择三项.');
		    return;
		}
	}
	/**工作岗位类别的下拉项新增处理*/
	else if(catalog=='jobcatelog')
	{
	     if(sObject.selectedIndex < 0){
            alert("系统提示:请在左则选择具体的意向岗位!");
            sObject.focus();
	    return ;
        }
		if(sObject.options [sObject.selectedIndex].text.indexOf("不限")>-1)
		{
			itemtext=sObject.options [sObject.selectedIndex].text;
		}
		else
		{
			itemtext=mObject.options [mObject.selectedIndex].text +"-"+ sObject.options [sObject.selectedIndex].text;
		}
		itemvalue=sObject.options[sObject.selectedIndex].value;
		var option=document.createElement("OPTION");
		option.text=itemtext;
		option.value=itemvalue;
		if (tObject.length<3)/**最多只能选择三项*/
		{
			for(i=0;i<tObject.length;i++)
			{
				v=tObject.options[i].value;
				t=tObject.options[i].text;               
                if ((itemvalue=='-1' || itemvalue=='' || itemtext=='不限')) 
                { 
                    alert('您已经选择了该项所在的类别中的子项.'); 
                    return;
                }

				if(t=='不限') return ;

				if(v==itemvalue)    
				{             
					alert('您已经选择了该项!');  	
					return;
				}
				else
				{
					var iLoc = t.indexOf("-不限");
					if (iLoc>-1)		/**目标的文本带有“不限”*/
					{
					    if(itemtext.length > iLoc && t.length > iLoc)
					    {
    						if(itemtext.substring(0,iLoc)==t.substring(0,iLoc))
    						{
    							alert('您已经选择不限。');
    							return;
    						}
    					}
					}
					iLoc = itemtext.indexOf("-不限");
					if (iLoc>-1)	/**源文本带有不限**/
					{
					    if(itemtext.length > iLoc && t.length > iLoc)
					    {
    						if(itemtext.substring(0,iLoc)==t.substring(0,iLoc))
    						{
    							alert('您已经选择了该项所在的类别中的子项。');
    							return;
    						}
    					}
					}
				}
			}
			try{	
				tObject.add(option);
			}catch(e){
				tObject.add(option,null);
			}
			//发布职位时增加岗位类别
			var m=document.thisForm;
			var jobFunction=m.jobFunction;
			var jobSel=m.jobcatelog;
			if(typeof(m)=="object" && typeof(jobSel)=="object")
			{
				for(var j=0;j<jobSel.length;j++)
				{
					var intK=parseInt(j+1);
					var jobFunction=eval("m.jobFunction"+intK);
					if(typeof(jobFunction)=="object" && typeof(jobSel.options[j])=="object")
					{
						jobFunction.value=jobSel.options[j].value;
					}
				}
				if(jobSel.length<jobLen)
				{
					m.jobFunction3.value="";
				}
			}
		}
		else
		{
			alert("您已经选择三项.");
			return;	
		}
	}

}
function multiSelect_removeitem(Object){
    
    var m=document.thisForm;
    var jobFunction=m.jobFunction;
    var jobSel=m.jobcatelog;

    if(Object.selectedIndex < 0){
        alert("系统提示:请选择您想要移除的资料项!");
        Object.focus();
	return ;
    }

    if(Object.name=="jobcatelog" && document.location.href.indexOf("company")=="-1"){
        delJobFunc(Object) ; 
    }
    if(Object.name=="workplace"){
        delJobLocaPara(Object) ;
    }

    if(typeof(m)=="object" && Object.name=="jobcatelog"){
        for(var j=1;j<=jobSel.length;j++){
            var jobFunction=eval("m.jobFunction"+j);
            if(typeof(jobFunction)=="object"){
                if((Object.selectedIndex > -1 ) && jobFunction.value==Object.options[Object.selectedIndex].value){
                   jobFunction.value="";
                   break;
                }
            }
        }
    }

    if(Object.selectedIndex>-1){
        Object.remove(Object.selectedIndex);
    }
    if(Object.name=="workplace"){
        setJobLocation(Object);
    }

    if(Object.length==0 && Object.name=="jobcatelog"){
        for(var x=1;x<=jobLen;x++){
            var jobFunctions=eval("m.jobFunction"+x);
            jobFunctions.value="";
        }
    }
}
//设定工作地区jobLocation
function setJobLocation(tObject){
            var strLocation="";
            for(var x=0;x<tObject.length;x++){
                strLocation=tObject.options[x].value +";" + strLocation;
            }
            var m=document.thisForm;
            if(typeof(m)=="object"){
                var jobLocation=m.JobLocation;
                if(typeof(jobLocation)=="object"){
                    jobLocation.value=strLocation;
                }
            }
}
//设定工作地区jobLocaPara参数
function setJobLocaPara(mObject,sObject,tObject)
{
    var iLen = tObject.length;
    var m=document.thisForm;
    if (iLen == 0)
    {
        if(typeof(m)=="object"){
            var p1 = m.jobLocation1_p;
            if(typeof(p1)=="object"){
                p1.value = mObject.options[mObject.selectedIndex].value;
            }
            var c1 = m.jobLocation1_c;
            if(typeof(c1)=="object"){
                c1.value = sObject.options[sObject.selectedIndex].value;
            }
        }
    }
    else if (iLen == 1)
    {
        if(typeof(m)=="object"){
            var p2 = m.jobLocation2_p;
            if(typeof(p2)=="object"){
                p2.value = mObject.options[mObject.selectedIndex].value;
            }
            var c2 = m.jobLocation2_c;
            if(typeof(c2)=="object"){
                c2.value = sObject.options[sObject.selectedIndex].value;
            }
        }
    }
    else if (iLen == 2)
    {
        if(typeof(m)=="object"){
            var p3 = m.jobLocation3_p;
            if(typeof(p3)=="object"){
                p3.value = mObject.options[mObject.selectedIndex].value;
            }
            var c3 = m.jobLocation3_c;
            if(typeof(c3)=="object"){
                c3.value = sObject.options[sObject.selectedIndex].value;
            }
        }
    }
}
//清除工作地区jobLocaPara参数
function delJobLocaPara(obj)
{
    var m=document.thisForm;
    if(obj.selectedIndex < 0){
        return;
    }
    var idx = obj.selectedIndex;
    if (idx == 2)
    {
        if(typeof(m)=="object"){
            var p3 = m.jobLocation3_p;
            if(typeof(p3)=="object"){
                p3.value = '';
            }
            var c3 = m.jobLocation3_c;
            if(typeof(c3)=="object"){
                c3.value = ''
            }
        }
    }
    else if (idx == 1)
    {
        if(typeof(m)=="object"){
            var p3 = m.jobLocation3_p;
            var p2 = m.jobLocation2_p;
            if(typeof(p3)=="object"){
                if (typeof(p2)=="object") {
                   p2.value = p3.value;
                   p3.value = '';
                }
            }
            var c3 = m.jobLocation3_c;
            var c2 = m.jobLocation2_c;
            if(typeof(c3)=="object"){
                if (typeof(c2)=="object") {
                   c2.value = c3.value;
                   c3.value = '';
                }
            }
        }
    }
    else if (idx == 0)
    {
        if(typeof(m)=="object"){
            var p3 = m.jobLocation3_p;
            var p2 = m.jobLocation2_p;
            var p1 = m.jobLocation1_p;
            if(typeof(p3)=="object"){
                if (typeof(p1)=="object") {
                   p1.value = p2.value;
                }
                if (typeof(p2)=="object") {
                   p2.value = p3.value;
                   p3.value = '';
                }
            }
            var c3 = m.jobLocation3_c;
            var c2 = m.jobLocation2_c;
            var c1 = m.jobLocation1_c;
            if(typeof(c3)=="object"){
                if (typeof(c1)=="object") {
                   c1.value = c2.value;
                }
                if (typeof(c2)=="object") {
                   c2.value = c3.value;
                   c3.value = '';
                }
            }
        }
    } 

}
