﻿    //生成行业列表
    function setIndustry(elemIndustry,sendername,parentDiv,showDiv)
    {
       var industry=document.getElementById(elemIndustry);
       if(!document.getElementById("tmp_pannel" + elemIndustry))
       {
            var j;
            var divIndustryItem;
            
            divIndustryItem=getElem("tmp_pannel_" + elemIndustry,"div",parentDiv); 
            divIndustryItem.innerHTML="";
            divIndustryItem.style.position="absolute";
            divIndustryItem.style.backgroundColor="#FFFCF3";
            divIndustryItem.style.height="360px";
            divIndustryItem.style.width="530px";
            divIndustryItem.style.overflow="auto";

            for(j=0;j<arrind.length;j++)
            {
                var isLengIndust = (arrind[j].classname.length > 12)? true : false; 
                divIndustryItem.innerHTML += "<div style=\"float:left;height:20px;width:" + (isLengIndust? "255px" : "170px") + ";\"><input onclick=\"return checkIndustryItem(this,'" + elemIndustry + "','" + showDiv + "')\" type=\"checkbox\" name=\"tmp_" + elemIndustry + "\" id='tmp_" + elemIndustry + arrind[j].classid + "' value=\"" + arrind[j].classid + "\"" + (IsIndustryItemChecked(arrind[j].classid,industry.value)?" checked=\"checked\"":"") + " /><label for='tmp_" + elemIndustry + arrind[j].classid + "' >" + arrind[j].classname + "</label></div>";
                if(IsIndustryItemChecked(arrind[j].classid,industry.value))
                {
                    AddIndustryCheckItem(showDiv,document.getElementById("tmp_" + elemIndustry + arrind[j].classid));
                }
            }
        }  
    }
    
   function getIndustrySelecter(sender,elemIndustry)
   {
        var defaultIndustryId = document.getElementById(elemIndustry).value;
        sender.value = getSelectedIndustryName(defaultIndustryId);
        
        var tmp_elemIndustry = "tmp_" + elemIndustry;
        var tmp_divMain = elemIndustry + "_divMain";
        var tmp_divTitle = elemIndustry + "_divTitle";
        var tmp_divClass= elemIndustry + "_divClass";
        var tmp_divItem= elemIndustry + "_divItem";
        var tmp_divShow = elemIndustry + "_divShow"; 
        var tmp_iframe= elemIndustry + "_iframe";
       
        if(document.getElementById(tmp_divMain))
        { 
            showIndustry(elemIndustry);
            return; 
        } 
        
        //创建主显示层
        var divMain=getElem(tmp_divMain,"div",document.body);
        divMain.style.textAlign="left";
        divMain.style.width="540px";
        divMain.style.height="450px";
        divMain.style.padding="3px";
        divMain.style.borderLeft="1px solid #999999";
        divMain.style.borderTop="1px solid #999999";
        divMain.style.borderRight="5px solid #999999";
        divMain.style.borderBottom="5px solid #999999";
        divMain.style.backgroundColor="#FFFCF3"; 
        divMain.style.position="absolute";
        divMain.style.zIndex="999999";
        divMain.style.left=(getObjLeft(sender)+sender.offsetWidth/4) + "px";
        divMain.style.top=(getObjTop(sender)+sender.offsetHeight/2) + "px";
        divMain.style.display="none";
        divMain.onselectstart=function(){ return false; }
       
        //创建框架，防止层被其它控件覆盖
        /*
        var iframe=getElem(tmp_iframe,"iFrame",document.body);
        iframe.style.position="absolute";
        iframe.style.padding=divMain.style.padding;
        iframe.style.border=divMain.style.border;
        iframe.style.width=divMain.style.width;
        iframe.style.height=divMain.style.height;
        iframe.style.left=divMain.style.left;
        iframe.style.top=divMain.style.top;
        iframe.style.zIndex=divMain.style.zIndex-1;
        iframe.style.display="none"; 
        */

        //创建标题层
        var divTitle=getElem(tmp_divTitle,"div",divMain);
        divTitle.style.width="540px";
        divTitle.style.backgroundColor="#FFE4A0";
        divTitle.style.overflow = "auto";
        divTitle.innerHTML="<div style=\"float:left;padding:5px;font-weight:bold;\"><img src=\"http://image.goodjob.cn/Image/search_dot02.gif\" style=\"border:0px;\" align=\"absmiddle\" />&nbsp;" + arrindlang[0] + "</div><div style=\"float:right;text-align:right;padding:5px;\"><a href=\"javascript:hiddenIndustry('" + elemIndustry + "');\">[" + arrindlang[1] + "]</a></div>"
        
        //处理拖动开始
        divTitle.onmousedown=function(evt){
            curMoveObj=divMain;
            //curMoveIframe=iframe;
            pX=evt.pageX-getInt(curMoveObj.style.left);
            pY=evt.pageY-getInt(curMoveObj.style.top);
        }
        
       //创建行业选择层 
       var divItem=getElem(tmp_divItem,"div",divMain);
       divItem.style.padding="5px";
       divItem.style.height="360px";
       divItem.style.clear="both";
       divItem.onclick=function(){ sender.focus(); }
       
       //创建已选行业层
       var divShow=getElem(tmp_divShow,"div",divMain);
       divShow.style.marginTop="8px";
       divShow.style.padding="5px";
       divShow.style.height="20px";
       divShow.style.clear="both";
       //divShow.style.borderBottom="5px solid #cccccc";
       divShow.onclick=function(){ sender.focus(); }
       
       setIndustry(elemIndustry,sender,divItem,tmp_divShow);
   }

   function getIndustryName(indid)
   {
        var i;
        for(i=0;i<arrind.length;i++)
        {
            if(arrind[i].classid==indid)
                return arrind[i].classname; 
        }
        return ""; 
   }
   
   function getSelectedIndustryName(idstr)
   {
        if(idstr=="")
            return "";
        if(idstr.indexOf(",")==-1)
            return getIndustryName(idstr);
        var arrid=idstr.split(",");
        var i;
        var rvalue="";
        for(i=0;i<arrid.length;i++)
        {
            var industryName = getIndustryName(arrid[i]);
            if(rvalue=="")
                rvalue = industryName;
            else
                if(industryName != "")
                { rvalue += "、" + industryName; }
        }
        return rvalue;
   }

   function AddIndustryCheckItem(elemstr,tmp_elemIndustry)
   {
        var divShow=document.getElementById(elemstr);
        var divItem=getElem(elemstr + "_" + tmp_elemIndustry.value,"span",divShow);
        var name=getIndustryName(tmp_elemIndustry.value)
        if(name.length>6)
            name=name.substr(0,6) + "...";
        divItem.style.textDecoration="underline";
        divItem.style.paddingRight="20px";
        divItem.style.cursor="hand";
        divItem.title=arrindlang[2];
        divItem.innerHTML="<label for='" + tmp_elemIndustry.id + "'><img src=\"http://image.goodjob.cn/image/ico_del.gif\" align=\"absmiddle\" /> " + name + "</label>";
        //divItem.innerHTML="<label for='" + tmp_elemIndustry.id + "'>" + name + "</label>";
   }
   
   function DelCheckItem(elemstr,tmp_elemIndustry,elemIndustry)
   {
        var divShow=document.getElementById(elemstr);
        var val=elemIndustry.value.split(",");
        var i;
        var indvalue="";  
        for(i=0;i<val.length;i++)
        {
            if(val[i]!=tmp_elemIndustry.value)
            { 
                if(indvalue=="")
                    indvalue = val[i];
                else
                    indvalue += ',' + val[i];
            }
        }
        elemIndustry.value = indvalue;
        divShow.removeChild(document.getElementById(elemstr + "_" + tmp_elemIndustry.value));
   }

   function checkIndustryItem(tmp_elemIndustry,elemstr,tmp_divShow)
   {
        var elemIndustry=document.getElementById(elemstr);
        var divShow=document.getElementById(tmp_divShow); 

        if(tmp_elemIndustry.checked)
        {
            if(elemIndustry.value=="")
            { 
                elemIndustry.value = tmp_elemIndustry.value;
                //divShow.innerHTML += getCityName(tmp_elemIndustry.value);
                AddIndustryCheckItem(tmp_divShow,tmp_elemIndustry);
            }
            else
            { 
                var val=elemIndustry.value.split(",");
                if(val.length>4)
                {
                    alert(arrindlang[3]);  
                    return false; 
                }
                elemIndustry.value += ',' + tmp_elemIndustry.value;
                //divShow.innerHTML += getCityName(tmp_elemCity.value);
                AddIndustryCheckItem(tmp_divShow,tmp_elemIndustry);
            } 
        }
        else
        {
            DelCheckItem(tmp_divShow,tmp_elemIndustry,elemIndustry);
        }
   }

   function IsIndustryItemChecked(itemid,defaultid)
   {
        var defaultidstr="," + defaultid + ",";
        var itemidstr="," + itemid + ",";
        if(defaultidstr.indexOf(itemidstr)!=-1)
            return true;
        else
            return false;    
   }

   function showIndustry(elemIndustry)
   {
        var divMain=document.getElementById(elemIndustry + "_divMain");
        var iframe=document.getElementById(elemIndustry + "_iframe"); 
        divMain.style.display="";
        iframe.style.display=""; 
   }
   
   function hiddenIndustry(elemIndustry)
   {
        var divMain=document.getElementById(elemIndustry + "_divMain");
        var iframe=document.getElementById(elemIndustry + "_iframe"); 
        
        divMain.style.display="none";
        iframe.style.display="none";
   }