﻿function GetRequest(obj,param,def,col,callback,add,chk){
    add=add||"";
    if(chk){
        if(param.pid == ""){
            $(obj)[0].options.length=0;
            if(def){
                $(obj)[0].options[0] = new Option(def[1],def[0]); 
            }
            return;
        }
    }
    $.get('CScript/selectajax.axd',param,function(data){
        $(obj)[0].options.length=0;
        if(def){
            $(obj)[0].options[0] = new Option(def[1],def[0]);
        }
        var column = col||[0,1];
        for(var i=0;i<data.length;i++){
            $(obj)[0].options[$(obj)[0].options.length] = new Option(add+data[i][column[1]],data[i][column[0]]);   
        }
        if(typeof(callback)=="function"){
            callback($(obj));
        }
    },"json");
}function GetOption(obj){    return [obj.value,obj.options[obj.selectedIndex].text];}
function AddWishTradeOptions(select1,select2){
    if(typeof(select1)=="string"){
        select1 = document.getElementById(select1);
    }
    if(typeof(select2)=="string"){
        select2 = document.getElementById(select2);
    }
    if(select2.options.length==5){  
        alert("只能选择5项!");
        return;
    }
    if(select1.selectedIndex< 0){
        alert("请选择添加项!");
        return;
    }
    for(var i=0;i<select1.options.length;i++){
        if(select1.options[i].selected){
            var op = select1.options[i];
            var isSelected = false;
            for(var j=0;j<select2.options.length;j++){
                if(select2.options[j].value==op.value){
                    alert(op.text+"已经添加过!");
                    isSelected = true;
                    break;
                }
            }
            if(!isSelected){
                if(select2.options.length==5){  
                    alert("只能选择5项!");
                    return;
                }
                select2.options[select2.length] = new Option(op.text,op.value);
            }
        }
    }
}
function AddWishJobOptions(select1,select2){
    if(typeof(select1)=="string"){
        select1 = document.getElementById(select1);
    }
    if(typeof(select2)=="string"){
        select2 = document.getElementById(select2);
    }
    if(select1.selectedIndex< 0){
        alert("请选择添加项!");
        return;
    }
    var val = select1.options[0].value;
    var txt = select1.options[0].text;
    if(select1.options[0].selected){
        for(var i=0 ; select2.options[i]!=null;){
             if(select2.options[i].upValue == val){
                select2.options[i] = null;
             }else{
                i++;
             }
        }
    }
    if(select2.options.length==5){  
        alert("只能选择5项!");
        return;
    }
    for(var i=0;i<select1.options.length;i++){
        if(select1.options[i].selected){
            var op = select1.options[i];
            var isSelected = false;
            for(var j=0;j<select2.options.length;j++){
                if(select2.options[j].value == val){
                    alert("已经添加过["+txt+"]无法添加"+op.text);
                    isSelected = true;
                    break;
                }else if(select2.options[j].value==op.value){
                    alert(op.text+"已经添加过!");
                    isSelected = true;
                    break;
                }
            }
            if(!isSelected){
                if(select2.options.length==5){  
                    alert("只能选择5项!");
                    return;
                }
                if(i==0){
                    select2.options[select2.length] = new Option(op.text,op.value);
                }else{
                    select2.options[select2.length] = new Option(txt+op.text,op.value);
                }
                select2.options[select2.length-1].upValue = val;
            }
        }
    }
}
function AddWorkPlaceOptions(select1,select2){
    if(typeof(select1)=="string"){
        select1 = document.getElementById(select1);
    }
    if(typeof(select2)=="string"){
        select2 = document.getElementById(select2);
    }
    if(select1.selectedIndex< 0){
        alert("请选择添加项!");
        return;
    }
    var val = select1.options[0].value;
    var txt = select1.options[0].text;
    if(select1.options[0].selected){
        for(var i=0 ; select2.options[i]!=null;){
             if(select2.options[i].value.split("-")[0] == val){
                select2.options[i] = null;
             }else{
                i++;
             }
        }
    }
    if(select2.options.length==5){  
        alert("只能选择5项!");
        return;
    }
    for(var i=0;i<select1.options.length;i++){
        if(select1.options[i].selected){
            var op = select1.options[i];
            var isSelected = false;
            for(var j=0;j<select2.options.length;j++){
                if(select2.options[j].value.split("-")[1] == val){
                    alert("已经添加过["+txt+"]无法添加"+op.text);
                    isSelected = true;
                    break;
                }else if(select2.options[j].value.split("-")[1]==op.value){
                    alert(op.text+"已经添加过!");
                    isSelected = true;
                    break;
                }
            }
            if(!isSelected){
                if(select2.options.length==5){  
                    alert("只能选择5项!");
                    return;
                }
                if(i==0){
                    select2.options[select2.length] = new Option(op.text,val+"-"+op.value);
                }else{
                    select2.options[select2.length] = new Option(txt+op.text,val+"-"+op.value);
                }
            }
        }
    }
}
function deleteOption(select){
    if(typeof(select)=="string"){
        select = document.getElementById(select);
    }
    for(var i=0;select.options[i] != null;){
        if(select.options[i].selected){
            select.options[i]=null;
        }else{
            i++;
        }
    }
}

//招聘发布的修改功能用，让子类选中
function GetRequest(obj,param,def,col,Subid){
var callback;
var add ;
var chk;
    add=add||"";
    if(chk){
        if(param.pid == ""){
            $(obj)[0].options.length=0;
            if(def){
                $(obj)[0].options[0] = new Option(def[1],def[0]); 
            }
            return;
        }
    }
    $.get('CScript/selectajax.axd',param,function(data){
        $(obj)[0].options.length=0;
        if(def){
            $(obj)[0].options[0] = new Option(def[1],def[0]);
        }
        var column = col||[0,1];
        for(var i=0;i<data.length;i++){
            $(obj)[0].options[$(obj)[0].options.length] = new Option(add+data[i][column[1]],data[i][column[0]]);
        }
        
        $(obj+" option").each(function() {
        if ($(this).val() == Subid){
                $(this).attr("selected", "selected");
            }
        });      

       
        if(typeof(callback)=="function"){
            callback($(obj));
        }
    },"json");
}
