


/** 取指定字节长度的字符串 */
function getLimitLenStr(str,len)
{

    var val = "";
    var count = 0;
    for(i = 0; i < str.length; i++){
        var temp = escape(str.charAt(i));
        if (temp.length >= 6){
           count = count + 2;
        }
        else {
            count = count + 1;
        }
        if (count > len){break;}
        val = val + str.charAt(i);
    }
    return val;
}



/**取字串的字符个数(包括汉字)*/
function strByteLen( s )
{
    if( s.length <= 0 ) return 0 ;

    len = s.length;
    for( i =0 ; i < s.length  ; i++ ){
        temp = escape(s.charAt(i),'gbk');
        if(temp.length>=6){

            len ++;
        }
    }
    return len;
}


function isWrongStr(szOriginal)
{
    var szExp = "'\\/?\"<>|";
    if( szOriginal.length <=0 || szExp.length <=0 ) {
        return false;
    }
    for( var counter = 0 ; counter < szExp.length ; counter ++ ){
        curr_char = szExp.charAt(counter);
        if( szOriginal.indexOf( curr_char) >= 0 ){
            return true ;
        }
    }
    return false;
}

//表单是否为对象

function isObj(obj){
			if(typeof(obj)=="object"){
			   return true;	
			}	
			else{
		       return false;	
		}
}


//配置已选择的工作岗位类别

function formatJobCategory(bz){

    tmp = new Array();
    var m=document.thisForm;
    var job1=m.jobFunction1;
    var job2=m.jobFunction2;
    var job3=m.jobFunction3;
    var jobList=m.subCatelog;
    var jobSel=m.jobcatelog;
    var val  = '';
    var val1 = '';
    var val2 = '';
    var txt1 = '';
    var txt2 = '';
    //修改或克隆职位时配置已选择的工作岗位类别

    if(isObj(job1) && job1.value!=""){
        val = ''+job1.value;
        if (val.length>3)
        {
           val1 = val.substring(0, 2) ;
           val2 = val.substring(2) ;
           if (val2 == '00')
           {
              val1 = val ;
              val2 = '' ;
           }
           else 
           {
              val1 = val1 + '00' ;
              val2 = val ;
           }

           for (var i=0; i<catelogs.length; i++)
           {
               tmp = catelogs[i] ;
               if (val1!='' && tmp[2]==val1)
               {
                   if (bz==0) txt1 = tmp[0] ;
                   else  txt1 = tmp[1] ;
                   txt2 = val1 ;
               }
               if (val2!='' && tmp[2]==val2)
               {
                   if (bz==0) txt1 = txt1 + '-' + tmp[0] ;
                   else  txt1 = txt1 + '-' + tmp[1] ;
                   txt1 = txt1.replace('-不限', '');
                   txt2 = val1 ;
               }
           }

           if (txt1!='' && txt2!='')
           {
                var opt1=document.createElement("OPTION");
                opt1.value=val;
                opt1.text=txt1;
                jobSel.add(opt1);
           }
        }
    }

    if(isObj(job2) && job2.value!=""){
        val = ''+job2.value;
        if (val.length>3)
        {
           val1 = val.substring(0, 2) ;
           val2 = val.substring(2) ;

           if (val2 == '00')
           {
              val1 = val ;
              val2 = '' ;
           }
           else 
           {
              val1 = val1 + '00' ;
              val2 = val ;
           }

           for (var i=0; i<catelogs.length; i++)
           {
               tmp = catelogs[i] ;
               if (val1!='' && tmp[2]==val1)
               {
                   if (bz==0) txt1 = tmp[0] ;
                   else  txt1 = tmp[1] ;

                   txt2 = val1 ;
               }
               if (val2!='' && tmp[2]==val2)
               {
                   if (bz==0) txt1 = txt1 + '-' + tmp[0] ;
                   else  txt1 = txt1 + '-' + tmp[1] ;

                   txt1 = txt1.replace('-不限', '');
                   txt2 = val1 ;
               }
           }

           if (txt1!='' && txt2!='')
           {
                var opt1=document.createElement("OPTION");
                opt1.value=val;
                opt1.text=txt1;
                jobSel.add(opt1);
           }
        }
    }

    if(isObj(job3) && job3.value!=""){
        val = ''+job3.value;
        if (val.length>3)
        {
           val1 = val.substring(0, 2) ;
           val2 = val.substring(2) ;
           if (val2 == '00')
           {
              val1 = val ;
              val2 = '' ;
           }
           else 
           {
              val1 = val1 + '00' ;
              val2 = val ;
           }


           for (var i=0; i<catelogs.length; i++)
           {
               tmp = catelogs[i] ;
               if (val1!='' && tmp[2]==val1)
               {
                   if (bz==0) txt1 = tmp[0] ;
                   else  txt1 = tmp[1] ;

                   txt2 = val1 ;

               }
               if (val2!='' && tmp[2]==val2)
               {
                   if (bz==0) txt1 = txt1 + '-' + tmp[0] ;
                   else  txt1 = txt1 + '-' + tmp[1] ;

                   txt1 = txt1.replace('-不限', '');
                   txt2 = val1 ;
               }
           }

           if (txt1!='' && txt2!='')
           {
                var opt1=document.createElement("OPTION");
                opt1.value=val;
                opt1.text=txt1;
                jobSel.add(opt1);
           }

        }

    }
}


//删除工作岗位
function delJobCategory(obj)
{
	var m=document.thisForm;
	if(typeof(obj.options[obj.selectedIndex])=="unknown"){
		return;
	}
    var idx = obj.selectedIndex;
    if (idx == 2)
    {
        if(typeof(m)=="object"){
            var p3 = m.jobFunction3;
            if(typeof(p3)=="object"){
                p3.value = '';
            }
        }
    }
    else if (idx == 1)
    {
        if(typeof(m)=="object"){
            var p3 = m.jobFunction3;
            var p2 = m.jobFunction2;
            if(typeof(p3)=="object"){
                if (typeof(p2)=="object") {
                   p2.value = p3.value;
                   p3.value = '';
                }
            }
        }
    } 
    else if (idx == 0)
    {
        if(typeof(m)=="object"){
            var p3 = m.jobFunction3;
            var p2 = m.jobFunction2;
            var p1 = m.jobFunction1; 
            if(typeof(p3)=="object"){
                if (typeof(p1)=="object") {
                   p1.value = p2.value;
                }
                if (typeof(p2)=="object") {
                   p2.value = p3.value;
                   p3.value = '';
                }
            }
        }
    } 
}


//配置已选择的工作地区 
function formatLocation()
{
    tmp = new Array();
    var m=document.thisForm;
    var workplace=m.workplace;

    var workplace_c1 = m.jobLocation1;
    var workplace_c2 = m.jobLocation2;
    var workplace_c3 = m.jobLocation3;

    var place_c1 = workplace_c1.value;
    var place_c2 = workplace_c2.value;
    var place_c3 = workplace_c3.value;

	var place_c1_n;
    var place_c2_n;
    var place_c3_n;

    
    var exit_flag = 0;
    if (place_c1 == '') exit_flag++;
    if (place_c2 == '') exit_flag++;
    if (place_c3 == '') exit_flag++;

    for (var i=0; i<citys.length; i++)
    {
        if (exit_flag>=3) break;

        if (place_c1 == citys[i][2])
        {
			place_c1_n=citys[i][3];
			//alert(">>>>>>>>>>>1"+place_c1_n);
            if (place_c1 != citys[i][1]) place_c1 = citys[i][1] + place_c1;
            exit_flag++;
        }

        if (place_c2 == citys[i][2])
        {
			place_c2_n=citys[i][3];
			//alert(">>>>>>>>>>>2"+place_c2_n);
            if (place_c2 != citys[i][1]) place_c2 = citys[i][1] + place_c2;
            exit_flag++;
        }

        if (place_c3 == citys[i][2])
        {
			place_c3_n=citys[i][3];
			//alert(">>>>>>>>>>>3"+place_c3_n);
            if (place_c3 != citys[i][1]) place_c3 = citys[i][1] + place_c3;
             exit_flag++;
        }
    }

    if (!isObj(workplace)) return;
    if(isObj(workplace_c1))
    {
        if (workplace_c1.value!='')
        {
            var opt1=document.createElement("OPTION");
            opt1.value=workplace_c1.value;
            opt1.text=place_c1_n;
			//alert(opt1.value+opt1.text);
            workplace.add(opt1);
        }
    }

    if(isObj(workplace_c2))
    {
        if (workplace_c2.value!='')
        {
            var opt1=document.createElement("OPTION");
            opt1.value=workplace_c2.value;
            opt1.text=place_c2_n;
            workplace.add(opt1);
        }
    }

    if(isObj(workplace_c3))
    {
        if (workplace_c3.value!='')
        {
            var opt1=document.createElement("OPTION");
            opt1.value=workplace_c3.value;
            opt1.text=place_c3_n;
            workplace.add(opt1);
        }
    }
}

function setLimitInputLen(obj,len)
{
	if(obj.type=="text")
	obj.style.cssText="";
    if (strByteLen(obj.value) > len)
    {
        obj.value = getLimitLenStr(obj.value,len);
        obj.focus();
        alert('输入超长!');
    }
}
function add_jobCategory(main, sub, bz)
{
    count = jobCategoryCount;
    items = catelogs;
    var subvalue=main.options[main.selectedIndex].value;
    for (i=0;i<count-1; i++)
    {
        if ((items[i][2]).substring(0,2) == subvalue.substring(0,2))
        { 
            var opt=document.createElement("OPTION");
            if (bz==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))   sub.add(opt);
        }
    }
}

function add_city(sub, pv, v, bz)
{
    count = cityCount;
    items = citys;
    var mc = pv;
    if (mc == '') return;

    if (bz==1)
    {
        for (i=0; i<count; i++)
        {
            if (items[i][3] == v)
            {
               mc = items[i][1];
               break;
            }
        } 
    }

    for (i=0; i<count; i++)
    { 
        if (items[i][1] == mc) 
        {
            var opt=document.createElement("OPTION");
            if (bz==1){opt.text=items[i][4];}
			else opt.text=items[i][3];
			opt.value=items[i][2]; 
			sub.add(opt); 
			if (opt.value == v) opt.selected = true;
        }
    }
}




function add_city1(sub, v, bz)
{
    var b = (sub.name.indexOf('jobLocation')>-1) ;
    count = cityCount;
    items = citys;
    var mc = '';
    for (i=0;i < count; i++)
    {
        if (items[i][2] == v)
        { 
           mc = items[i][1];
           break;
        }
    } 
    for (i=0;i < count; i++)
    { 
        if (items[i][1] == mc) 
        {
            var opt=document.createElement("OPTION");
            if (bz==1) opt.text=items[i][3];
            else if (b) opt.text=items[i][0].replace('├-','');
            else opt.text=items[i][2];
            opt.value=items[i][2];
            subitem.add(opt);
            if (items[i][2] == val)  opt.selected = true;
        }
    }
}

function sleSetFocus(obj, val)
{
    for (i=0; i<obj.length; i++)
    {
        if (obj.options[i].value == val)
        {
            obj.options[i].selected = true;
            break;
        }
    }
}

//下拉菜单选中控制:最大、最小
function selSetMM(obj, flag)
{
    if (obj.length<2) return false;
    if (flag=='min') obj.options[0].selected = true;
    else  obj.options[obj.length-1].selected = true;
}

