﻿// JavaScript 文件
//一级类别
function JobTypeFirstSelector(objFirstType, PleaseChose)
{
    this.FirstJobType = GetObjectByIdJ(objFirstType);
    this.PleaseChose = PleaseChose;
    this.init = SetOnlyFirstJobList;
}
//只绑定一级类别
function SetOnlyFirstJobList() 
{
    //清除选项
    this.FirstJobType.options.length = 0;                           
    //添加'请选择'项

    if(this.PleaseChose)
    {
        AddOptions(this.FirstJobType,"-请选择职位类别-","");
    }

    //添加列表选项
    for(var i = 0; i < ArrFstClass.length; i++)
    {
        AddOptions(this.FirstJobType,ArrFstClass[i][1],ArrFstClass[i][0]);
    }
}


 function JobTypeSelector(objFirstType, objSecondType, PleaseChose)
 {
	  this.FirstJobType = GetObjectByIdJ(objFirstType);       
	  this.SecondType = GetObjectByIdJ(objSecondType);     
	  this.PleaseChose = PleaseChose;                           
	  this.FirstJobType.PleaseChose = this.PleaseChose;             
	  this.SecondType.PleaseChose = this.PleaseChose;                
	  this.FirstJobType.associateObject = this.SecondType;             
	  this.init = SetFirstJobList;                               
	  this.FirstJobType.onchange = SetSecondJobList; 
	  
      //设定各列表初始选项
	  this.SetDefaultItem = function(strValue1,strValue2)
	  {  
	   
	    //大类，小类变量
	    var strFirst = "",strSecond = "";
	   
	   //非数字字符串时直接返回不处理
	    if( isNaN(strValue1) && isNaN(strValue2))
	      {
    	      return ;
	      }
	    //数字字符串时设定值
	    else
	    {
	        strFirst  = strValue1;
    	    strSecond = strValue2;
	    }
        this.SetSeletedValue(strValue1,strValue2);
	  }
	//设置选择项
	this.SetSeletedValue = function(strValue1,strValue2)
	{ 
		for(var i = 0; i < this.FirstJobType.options.length; i++)
			{
			 if(this.FirstJobType.options[i].value == strValue1)
			   {
				 try
				 {
				  this.FirstJobType.options[i].selected = true;
				  this.FirstJobType.onchange();
				 }
				 catch(e)
				  {
					try
					 {
					  this.SecondType.selectedIndex = i;
					  this.SecondType.onchange();
					 }catch(ex){throw ex}
				  }
				}
			}
			
			  for(i = 0; i < this.SecondType.options.length; i++)
			 {
			  if(this.SecondType.options[i].value == strValue2)
			   {
				 try
				 {
				  this.SecondType.options[i].selected = true;
				 }
				 catch(e)
				  {
					try
					{ 
					  this.SecondType.selectedIndex = i;
					 }catch(ex){throw ex}
				  }
			   }
			 }
		 }
 }
 
  //绑定一级类别列表

	 function SetFirstJobList() 
	  {
		 //清除选项
		this.FirstJobType.options.length = 0;                           
		//添加'请选择'项

		if(this.PleaseChose) AddOptions(this.FirstJobType,"-请选择职位类别-","");
		
		//添加列表选项
		for(var i = 0; i < ArrFstClass.length; i++)
		 {
		   AddOptions(this.FirstJobType,ArrFstClass[i][1],ArrFstClass[i][0]);
		 }
		 this.FirstJobType.onchange();
	  }
	  
	 //绑定二级类别列表
	function SetSecondJobList()
	 {
		   //取得一级下拉框对象
		   TagObj = this.associateObject;                                   
		   //清除现有选项
		   TagObj.options.length = 0;                                       
		   //添加'请选择'项

		   if(TagObj.PleaseChose) AddOptions(TagObj,"-请选择职位-","");           
		   
		   //循环添加二级选项
		   for(var i = 0; i < ArrSndClass.length; i++)
		   {
			 if(ArrSndClass[i][0] == this.value)
			   AddOptions(TagObj,ArrSndClass[i][2],ArrSndClass[i][1]);
		   }
	 }
	 
 function ShowClassName(strValue)
  {
	 var strtmp = "";
	  if(strValue != "")
	   {
		 nvalue = parseInt(strValue);
		 if(nvalue >= 10000 && nvalue < 20000)
		  strtmp += GetFirtsNameByID(strValue);
		 else if(nvalue >= 20000)
		  strtmp += GetSecondNameByID(strValue);
		  }
		else
		 {
		  strtmp += "不限";
		 }
		 return strtmp;
	  }
	  
 function GetFirtsNameByID(fid)
  {
    
		   for(var i = 0; i < ArrFstClass.length; i++)
			{
				if(ArrFstClass[i][0] == fid)
				 {
				   return ArrFstClass[i][1];
				  }
				}
	  }
	  
 function GetSecondNameByID(sid)
  {
     if(sid==""||sid==null)
    {
      return "";
    }
		   for(var i = 0; i < ArrSndClass.length; i++)
			{
				if(ArrSndClass[i][1] == sid)
				 {
				   return GetFirtsNameByID(ArrSndClass[i][0]) + "-" + ArrSndClass[i][2];
				  }
				}
	  }
	  
 function GetParentIDBySecondID(sid)
  {
	  var strTemp = "";
		   for(var i = 0; i < ArrSndClass.length; i++)
			{
				if(ArrSndClass[i][1] == sid)
				 {
				   strTemp = ArrSndClass[i][0];
				  }
				}
		 return strTemp;
	  }
	  
  function ShowJobClassMult(str)
   {
	 var ar = str.split(",")
	  
	  for(var i = 0; i < ar.length; i++)
	  {
		document.write(ShowClassName(ar[i]));
		if(i < (ar.length - 1)) document.write("<br />");
	  }
   }
   
   function setJobClassMult(strobj,str)
	{
		var obj = GetObjectById(strobj);
		var ar = str.split(",");
		for(var i = 0; i < ar.length; i++)
		 {
		  AddOptions(obj,ShowClassName(ar[i]),ar[i]);
		  obj.options[i].selected = true;
		 }
	}
	  
  function GetObjectById(tagID)
   {
	if (typeof(tagID) != "string" || tagID == "") return null;
	if (document.getElementById) return document.getElementById(tagID);
	if (document.all) return document.all(tagID);
	try {return eval(tagID);} catch(e){ return null;}
   }
   
   function AddOptions(obj,strName,strValue)
	 {
		   obj.options.add(new Option(strName,strValue));
	}
  
  function AddJobToMultiple(obj1,obj2,objtarget,max)
   {
	var objFst = GetObjectById(obj1);
	var objSnd = GetObjectById(obj2);
	var objT = GetObjectById(objtarget);
	var strValue = objSnd.value == "" ? objFst.value : objSnd.value;
	   if(objT.options.length < max)
		{
		  if(NotExsitOption(objT,strValue))
		  {
		   AddOptions(objT,ShowClassName(strValue),strValue);
		   objT.options[objT.options.length - 1].selected = true;
		  }
		  else
		   alert("该项您已经选择过了!");
		}
	   else
		{
		  alert("对不起,您最多只能选择"+max+"项!");
		}
   }
   
     function GetObjectByIdJ(tagID)
   {
    if (typeof(tagID) != "string" || tagID == "") return null;
    if (document.getElementById) return document.getElementById(tagID);
    if (document.all) return document.all(tagID);
    try {return eval(tagID);} catch(e){ return null;}
   }
