﻿
/* 处理岗位下拉联动 */
function SetChildStation(o){
    var parentId = o.value;     
    var childObj =  document.getElementById('ddlStation');
    RemoveOption(childObj);
    SetStationValue(childObj, parentId);
    childObj.selectedIndex = 0;
}
function SetStationValue(childObj, parentId){
    if(parentId > 0){
        var cmd = new RemoteCommand('JobFare', 'GetStations');
        cmd.SetParameter('parentId', parentId);
        var strStations = cmd.Execute().ReturnValue;
        var stations = new Array();
        if(strStations == null){ 
            return;
        }
            
        var stationId;
        var stationName;
        strStations = strStations.replace(/&nbsp;/gi, " ");
        stations = strStations.split('|');
        for(var i = 0; i < stations.length; i++){
            stationId = stations[i].split(',')[0];
            stationName = stations[i].split(',')[1];
            childObj.options[i+1] = new Option(stationName, stationId);
        }
    }
}
//添加和删除专业分类选项
function SubmitSpecialty(act){
    var sourceObj = document.getElementById('sltSpecialty'); 
    var objSelect = document.getElementById('ddlSpecialty');
    if(act=='select'){
        if(sourceObj.selectedIndex < 0){
            return;
        }
        //判断是否超过专业分类最大可选数
        if(IsOverOptions(3)){
            alert(GetResources(260709));
            return; 
        }
        //从左选择框增加专业分类选项到右选择框
        if(objSelect){            
            var optValue = sourceObj[sourceObj.selectedIndex].value;
            var optText = sourceObj[sourceObj.selectedIndex].text; 
            if(!CheckOptionIsExist(optValue)){
                objSelect.options.add(new Option(optText, optValue));
            } 
        } 
    }
    //Select the box to remove the option 
    if(act=='delselect'){
         if(objSelect){
            if(objSelect.selectedIndex >= 0){
                objSelect.options[objSelect.selectedIndex] = null;
            }  
        } 
    }
    //判断选项是否已经存在
    function CheckOptionIsExist(val){
        var sltLength = objSelect.options.length;
        for(i = 0; i < sltLength; i++){
            if(objSelect.options[i].value == val){
                return true;
            } 
        }
        return false;
    }
    //判断是否超过专业分类最大可选数 
    function IsOverOptions(optNum){
        var maxNum = objSelect.options.length;
        if(maxNum >= optNum){
            return true;
        }
        return false;
    }  
}

/* 处理专业下拉联动 */
function SetChildSpecialty(o){
    var parentId = o.value; 
    var objSelect = document.getElementById('sltSpecialty');
    if(objSelect) {
        var len = objSelect.options.length; 
        for(i = 0; i < len; i++){
            objSelect.options[0] = null;
        }    
    } 
    var cmd = new RemoteCommand('JobFare', 'GetSpecialtys');
    cmd.SetParameter('parentId', parentId);
    var specialtys = cmd.Execute().ReturnValue;
    if(specialtys != null){        
        specialtys = specialtys.replace(/&nbsp;/gi, " ");
        var arrSpecialty = specialtys.split('|');
        for(i = 0; i < arrSpecialty.length; i++){
            objSelect.options.add(new Option(arrSpecialty[i].split(',')[1], arrSpecialty[i].split(',')[0]));
        }
    }
}

function SetSpecialtyValue(){
    var ddlSpecialty = document.getElementById('ddlSpecialty');
    if(ddlSpecialty){
        var val = '';
        var sltLength = ddlSpecialty.options.length;
        for(i = 0; i < sltLength; i++){
            val += ',' + ddlSpecialty.options[i].value;
        }
        document.getElementById('hdSpecialtyId').value = val.length > 0 ? val + ',' : val;
    }
}

/* 地区的联动下拉 */
function SetChildRegion(o,name){
    var parentId=o.value;
    if(name != null){
        var objSelect=document.getElementById(name);
    }
    else{
        var objSelect=document.getElementById("sltRegion");
    }
    
    if(objSelect){
        var len=objSelect.options.length;
        for(var i=0;i<len;i++){
            objSelect.options[0]=null;
        }
    }
    
    if(parentId == 0){
        objSelect.options[0]= new Option(GetResources(100177), 0);
        objSelect.value = 0;
        return;
    }
    
    var cmd = new RemoteCommand('Platform', 'GetRegions');
    cmd.SetParameter('parentId', parentId);
    var strRegions = cmd.Execute().ReturnValue;
    var regions = new Array();
    if(strRegions == null){ 
        return;
    }
    objSelect.options[0]= new Option(GetResources(100177), 0);
    objSelect.value = 0; 
    
    strRegions = strRegions.replace(/&nbsp;/gi, " ");
    regions = strRegions.split('|');
    for(var i = 1; i <= regions.length; i++){
        objSelect.options.add(new Option(regions[i - 1].split(',')[1], regions[i - 1].split(',')[0]));
    }    
}

/* 处理岗位下拉联动2 */
function SetChildStation2(o,name){
    var parentId=o.value;
    if(name != null){
        var objSelect=document.getElementById(name);
    }
    else{
        var objSelect=document.getElementById("sltStation");
    }
    
    if(objSelect){
        var len=objSelect.options.length;
        for( var i=0;i<len;i++){
            objSelect.options[0]=null;
        }
    }
    if(parentId == 0){
        objSelect.options[0]= new Option(GetResources(100161), 0);
        objSelect.value = 0;
        return;
    }
     
    var cmd = new RemoteCommand('JobFare', 'GetStations');
    cmd.SetParameter('parentId', parentId);
    var strStations = cmd.Execute().ReturnValue;
    var stations = new Array();
    if(strStations == null){ 
        return;
    } 
    strStations = strStations.replace(/&nbsp;/gi, " ");
    stations = strStations.split('|');
    for(var i = 0; i < stations.length; i++){
        objSelect.options.add(new Option(stations[i].split(',')[1], stations[i].split(',')[0]));
    }
}

function SetStationValue2(){
    var ddlStation = document.getElementById('ddlStation');
   
    if(ddlStation){
        var val = '';
        var strLength = ddlStation.options.length;
        for( var i = 0; i < strLength; i++){
            val += ','+ddlStation.options[i].value;
        }
        document.getElementById('hdStationId').value = val.length > 0 ? val += ',' : val;
    }
}

//Add and delete options stations
function SubmitStation(act){
    var sourceObj = document.getElementById('sltStation');
    var objSelect = document.getElementById('ddlStation');
    if(act == 'select'){
        if(sourceObj.selectedIndex < 0){
            return;
        }
        //To determine whether more than the maximum number of options
        if(IsOverOptions(3)){
            alert(GetResources(260719));
            return;
        }
        //Select the option to increase the box from left to right to choose the box
        if(objSelect){
            var optValue = sourceObj[sourceObj.selectedIndex].value;
            var optText = sourceObj[sourceObj.selectedIndex].text;
            if(!CheckOptionIsExist(optValue)){
            objSelect.options.add(new Option(optText,optValue));           
          
            }
        }
    }
    //Select the box to remove the option
    if(act == 'delselect'){
        if(objSelect){
            if(objSelect.selectedIndex >= 0){         
                objSelect.options[objSelect.selectedIndex] = null;              
            }
        }
    }
    
    //Options to determine whether there is
    function CheckOptionIsExist(val){
        var strLength = objSelect.options.length;
        for(var i = 0; i < strLength; i++){
            if(objSelect.options[i].value == val){
                return true;
            }
        }
        return false;
    }

    //To determine whether more than the maximum number of options 
    function IsOverOptions(optNum){
        var maxNum = objSelect.options.length;
        if(maxNum >= optNum){
            return true;
        }
        return false;
    }  
}

//添加和删除行业分类选项
function SubmitIndustry(act){
    var Member_Company_OverIndustry = GetResources(220772);
    var objSelect = document.getElementById('sltIndustry');
    var sourceObj = document.getElementById('ddlIndustyTitleId'); 
    if(act=='select'){
        if(sourceObj.selectedIndex < 0){
            return;
        } 

        //判断是否超过行业分类最大可选数
        if(IsOverOptions(3)){
            Member_Company_OverIndustry = Member_Company_OverIndustry.replace('{0}', 3);
            alert(Member_Company_OverIndustry);
            return; 
        }
        
        //从左选择框增加行业分类选项到右选择框
        if(objSelect){            
            var optValue = sourceObj[sourceObj.selectedIndex].value;
            var optText = ClearTreeTag(sourceObj[sourceObj.selectedIndex].text); 
            if(!CheckOptionIsExist(optValue)){
                objSelect.options.add(new Option(optText, optValue));
            } 
        } 
    }
    
    //删除选择框内的所选项 
    if(act=='delselect'){
         if(objSelect){
            if(objSelect.selectedIndex >= 0){
                objSelect.options[objSelect.selectedIndex] = null;
            }  
        } 
    }
    
    //判断选项是否已经存在
    function CheckOptionIsExist(val){
        var sltLength = objSelect.options.length;
        for(var i = 0; i < sltLength; i++){
            if(objSelect.options[i].value == val){
                return true;
            } 
        }
        return false;
    }
    
    //判断是否超过行业分类最大可选数 
    function IsOverOptions(optNum){
        var maxNum = objSelect.options.length;
        if(maxNum >= optNum){
            return true;
        }
        return false;
    }  
}

//清除树型标记：“┆”、“└ ”、“├ ”
function ClearTreeTag(text){
    if(text.length > 0){
        text = text.replace(/┆/g, "");
        text = text.replace(/└ /g, "");
        text = text.replace(/├ /g, "");
    } 
    return text; 
}

function SetIndustyValue(){
    var objSelect = document.getElementById('sltIndustry');
    var hdObj = document.getElementById('hdIndustryId');
    var industryId = ''; 
    if(objSelect) {  
        var len = objSelect.options.length; 
        for(var i = 0; i < len; i++){
            industryId += ',' + objSelect.options[i].value;
        }    
    } 
    
    if(industryId.length > 0){
        industryId += ','; 
    }
    
    if(hdObj){
        hdObj.value = industryId; 
    }
}
