var PopupDiv={
 selectids:'',
 thistype:'',
 thismaxselect:0,
 selectFinishedMethod:'',
 selectnames:'',
 inptype:'',
 displayObjname:'',
 hiddenObjname:'',
 timer:null,
 showflag:true,
 rtrim : /^(\s|\u00A0)+|(\s|\u00A0)+$/g,
 popup :function(type,displayObj,hiddenObj,selectFinishedMethod ){
 if(selectFinishedMethod=="radio"){
   this.popupSingle(type,displayObj,hiddenObj,selectFinishedMethod);
   return ;
 }
 this.selectFinishedMethod=selectFinishedMethod;
 this.thistype=type;
 this.thismaxselect=5;
  this.displayObjname=displayObj;
  this.hiddenObjname=hiddenObj;
  this.selectids=document.getElementById(hiddenObj).value;
  
  this.selectnames=this.getSelectNameById( this.selectids );
  if(this.selectids.replace( this.rtrim, "" )==""){
   this.selectids="";
   this.selectnames="";
  }
  this.showAllSelectData( displayObj,hiddenObj );
   
  this.showSelected();
 },
popupSingle :function(type,displayObj,hiddenObj,selectFinishedMethod ){
 this.selectFinishedMethod=selectFinishedMethod;
 this.thistype=type;
 this.thismaxselect=1;
  this.displayObjname=displayObj;
  this.hiddenObjname=hiddenObj;
  this.selectids=document.getElementById(hiddenObj).value;
  
  this.selectnames=this.getSelectNameById( this.selectids );
  if(this.selectids.replace( this.rtrim, "" )==""){
   this.selectids="";
   this.selectnames="";
  }
  this.showAllSelectData( displayObj,hiddenObj );
   
  this.showSelected();
 },
showAllSelectData :function( displayObj,hiddenObj ){
 var catList=null;
 switch(this.thistype){
   case 'cat': catList=categoryList;break;
   case 'jrind': catList=industryList;break;
   case 'loc': catList=areaList;break;
   case 'major': catList=majorList;break;
  }
  var html=[];
  html=this.showStart(html );
 html=this.showSelectDate(html );
 
 switch(this.thistype){
   case 'cat':  ;
   case 'jrind': this.createSecondDiv(catList,html) ;break;
   case 'loc': this.createOneDiv(catList,html) ;break;
   case 'major': this.createOneDiv(catList,html) ;break;
  }
 
 
 
 html=this.showEnd(html);
 html.push('<div style="z-index: 1777; position: absolute; top: 20pt; left: 473px;" id="subItems_joinren" class="alert_lay_joinren sech_lay2_joinren lay_wsh_joinren" onmouseover="setIsShow(true)" onmouseout="setIsShow(false)">');
 html.push('</div>');
 document.getElementById('_newPOPDIV').innerHTML=(html.join(""));
 },
 createOneDiv :function(catList,html){
  
      html.push('<table width="740"  border="0" align="center" cellpadding="0" cellspacing="0"  ><tr>');
   var i=0;
   html.push('<td align="left"  >');
   switch(this.thistype){
   case 'loc': html.push('<div class="RedTitlebg_one"  id="needblack">');;break;
   case 'major': html.push('<div class="RedTitlebg"  id="needblack">');;break;
  }
   
   for(var j=0;j<catList.length;j++){
     html.push('<a href="#;" style="position:relative" onclick="selectData( \' '+catList[j].id+' \',\' '+catList[j].name+' \'  ),openSecondData(event, \'  '+i+'  \',\'  '+j+'  \', this.offsetTop ,this.offsetLeft,this.offsetWidth,this.offsetHeight )" onmouseout="hideSecondData()" onmouseover="openSecondData(event, \'  '+i+'  \',\'  '+j+'  \', this.offsetTop ,this.offsetLeft,this.offsetWidth,this.offsetHeight )">'+(catList[j].name.length>10?(catList[j].name.substring(0,9)+'...'):(catList[j].name))+'</a>');
     //html.push('<a href="#;" onclick="selectTest(    )">'+catList[i].subItems[j].name+'</a>');
   }
   html.push('</div></td></tr></table>');
 
 },
 createSecondDiv :function(catList,html){
  for(var i=0;i<catList.length;i++){
   if(i%2==0){
      html.push('<table width="740"  border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#E9E9E9"><tr>');
   }else{
      html.push('<table width="740"  border="0" align="center" cellpadding="0" cellspacing="0"  ><tr>');
   }
   html.push('<td width="189" class="RedTitle" onmouseover="setIsShow(false)">'+catList[i].name+'：</td><td align="left">');
   html.push('<div class="RedTitlebg"  id="needblack">');
   for(var j=0;j<catList[i].subItems.length;j++){
     html.push('<a href="#;" style="position:relative" onclick="selectData( \' '+catList[i].subItems[j].id+' \',\' '+catList[i].subItems[j].name+' \'  ),openSecondData(event, \'  '+i+'  \',\'  '+j+'  \', this.offsetTop ,this.offsetLeft,this.offsetWidth,this.offsetHeight )" onmouseout="hideSecondData()" onmouseover="openSecondData(event, \'  '+i+'  \',\'  '+j+'  \', this.offsetTop ,this.offsetLeft,this.offsetWidth,this.offsetHeight )">'+(catList[i].subItems[j].name.length>10?(catList[i].subItems[j].name.substring(0,9)+'...'):(catList[i].subItems[j].name))+'</a>');
     //html.push('<a href="#;" onclick="selectTest(    )">'+catList[i].subItems[j].name+'</a>');
   }
   html.push('</div></td></tr></table>');
 }
 },
 showSelectDate :function(htmlobj ){
  htmlobj.push('<table width="740"  border="0" align="center" cellpadding="0" cellspacing="0" onmouseover="setIsShow(false)"><tr>');
 switch(this.thistype){
   case 'cat': htmlobj.push('<td width="80" heigth="36">已选职位：</td>');break;
   case 'jrind': htmlobj.push('<td width="80" heigth="36">已选行业：</td>');break;
   case 'loc': htmlobj.push('<td width="80" heigth="36">已选地区：</td>');break;
   case 'major': htmlobj.push('<td width="80" heigth="36">已选专业：</td>');break;
  }
 htmlobj.push('<td align="left"><div class="RedTitlebg2" id="showselectdata">');
 htmlobj.push('</div></td></tr></table>');
 return htmlobj;
 },
 showEnd : function(htmlobj ){
  htmlobj.push('<table width="740" border="0" align="center" cellpadding="0" cellspacing="0" onmouseover="setIsShow(false)"><tr>');
  htmlobj.push('<td><div id="btn_black" style="padding-top:8px"><a class="btn-white btn_black" href="#;" onfocus="this.blur()" onclick="selectdivdata()">确认</a></div></td>');
  htmlobj.push('</tr></table></td></tr><tr><td bgcolor="#FFFFFF">&nbsp;</td></tr><tr>');
  htmlobj.push('<td height="7" class="Op"></td><td class="Op"></td>');
  htmlobj.push('<td height="7" class="Op"></td></tr></table></div>');
  return htmlobj;
 },
 showStart :function(htmlobj  ){
  htmlobj.push('<div id="ClickStyle" onmouseout="setIsShow(false)"><table width="810" border="0" cellspacing="0" cellpadding="0" style="background:#FFFFFF"><tr>');
  htmlobj.push('<td width="7" height="7" class="Op"></td><td class="Op"></td><td width="7" height="7" class="Op"></td>');
  htmlobj.push('</tr><tr><td rowspan="3" class="Op"></td><td bgcolor="#FFFFFF">');
  switch(this.thistype){
   case 'cat': htmlobj.push('<div class="xbox-title"><b>请选择职位类别 (您最多能选择'+this.thismaxselect+'项)</b></div>');break;
   case 'jrind': htmlobj.push('<div class="xbox-title"><b>请选择行业类别 (您最多能选择'+this.thismaxselect+'项)</b></div>');break;
   case 'loc': htmlobj.push('<div class="xbox-title"><b>请选择地区类别 (您最多能选择'+this.thismaxselect+'项)</b></div>');break;
   case 'major': htmlobj.push('<div class="xbox-title"><b>请选择专业类别 (您最多能选择'+this.thismaxselect+'项)</b></div>');break;
  }
  htmlobj.push('<a class="xbox-close-link-window icon_menu_click" href="#;" onclick="closeDiv()" onFocus="this.blur()">关闭</a></td>');
  htmlobj.push('<td rowspan="3" class="Op"></td></tr><tr ><td>');
  return htmlobj;
 },
 openSecondData :function(i,j,top,left,left2 ){
    var _y=document.getElementById('TB_window').offsetTop ;
     var _x=document.getElementById('TB_window').offsetLeft ;
     var catList=null;
     var parentid=0;
     var _x2=0;
     switch(this.thistype){
   case 'cat': if(categoryList[parseInt(i)].subItems[parseInt(j)]==undefined
         		||categoryList[parseInt(i)].subItems[parseInt(j)]==null
         		||categoryList[parseInt(i)].subItems[parseInt(j)].subItems[0].id==""){
       			document.getElementById('subItems_joinren').innerHTML="";
       				return;
      			};
      			catList=categoryList[parseInt(i)].subItems[parseInt(j)].subItems;
      			parentid=categoryList[parseInt(i)].subItems[parseInt(j)].id;
      			break;
   case 'jrind': if(industryList[parseInt(i)].subItems[parseInt(j)]==undefined
        			||industryList[parseInt(i)].subItems[parseInt(j)]==null
        			||industryList[parseInt(i)].subItems[parseInt(j)].subItems[0].id==""){
       				document.getElementById('subItems_joinren').innerHTML="";
       					return;
     				};
     				catList=industryList[parseInt(i)].subItems[parseInt(j)].subItems;
     				parentid=industryList[parseInt(i)].subItems[parseInt(j)].id;
     				break;
   case 'loc':  if(areaList[parseInt(j)].subItems ==undefined
        			||areaList[parseInt(j)].subItems ==null
        			||areaList[parseInt(j)].subItems[0].id==""){
       				document.getElementById('subItems_joinren').innerHTML="";
       					return;
     				};
     				catList=areaList[parseInt(j)].subItems;
     				parentid=areaList[parseInt(j)].id;
     				_x2=108;
     				break;
   case 'major':  if(majorList[parseInt(j)].subItems ==undefined
        			||majorList[parseInt(j)].subItems ==null
        			||majorList[parseInt(j)].subItems[0].id==""){
       				document.getElementById('subItems_joinren').innerHTML="";
       					return;
     				};
     				catList=majorList[parseInt(j)].subItems;
     				parentid=majorList[parseInt(j)].id;
     				break; 	  				 				
  }
     
    if(catList==undefined||catList==null){
      return;
    }
    var tempid=this.selectids.split(',');
    var hasValid=true;
     
    for(var k=0;k<tempid.length;k++){
     if(  tempid[k].replace( this.rtrim, "" )!="" && parentid==tempid[k] ){
        hasValid=false;
     }
   }
    var html2=[];
    html2.push('<div class="alert_t_joinren"></div><div id="_subBox" class="box_joinren"><ol>');
    for(var i=0;i<catList.length;i++){
       html2.push('<li id="^'+i+'" style="text-align: left;"><a href="javascript:void(0);" onclick="selectData( \' '+catList[i].id+' \',\' '+catList[i].name+' \',this   )"><label for="scbx209"><input ');
       if(this.thismaxselect>1){
         html2.push('type="checkbox" ');
       }else{
         html2.push('type="radio" ');
       }
       if(!hasValid){//选上大类，小类不可选
          html2.push('disabled="disabled"');
          html2.push('checked="checked"');
       }
       html2.push(' id="_checkbox'+catList[i].id+'" >'+catList[i].name+'</label></a></li>');
    }
    if(catList.length==1){
      html2.push('<li id="^2" style="text-align: left;"> </li>');
    }
    html2.push('</ol></div><div class="alert_b_joinren"><img src="http://222.73.167.52/joinren/theme/js/popupselect/image/laybj_br.gif" alt=""></div>');
     
     var counts=catList.length;
     var _width=420;
     var _height=(counts/2)*16;
       
     if((left+_width )>document.body.clientWidth ){
       left=left-left2-_width-12;
     }
     var _containHeight=document.getElementById('TB_window').clientHeight;
       //alert((top)+"*"+_height+"*"+_containHeight  );
     if((top+_height )>(_y+_containHeight +30) ){
       top=top-_height-30 ;
     }
     left=left-_x2;
     document.getElementById('subItems_joinren').style.top=(top-_y)+"px";
     document.getElementById('subItems_joinren').style.left=(left-_x)+"px";
     document.getElementById('subItems_joinren').innerHTML=html2.join("");
     
     //将选上的自动打勾
     for(var i=0;i<tempid.length;i++){
     if(  tempid[i].replace( this.rtrim, "" )!=""){
       if(document.getElementById('_checkbox'+tempid[i])!=undefined&&document.getElementById('_checkbox'+tempid[i])!=null){
         document.getElementById('_checkbox'+tempid[i]).checked="checked";
       }
     }
   }
   //选上大类，小类消失掉且小类全选上
   if(!hasValid){
      for(var i=0;i<tempid.length;i++){
     if(  tempid[i].replace( this.rtrim, "" )!=""){
        for(var j=0;j<catList.length;j++){
          if(  tempid[i]==catList[j].id){
              this.cancelData(catList[j].id,catList[j].name);
              if(document.getElementById('_checkbox'+tempid[i])!=undefined&&document.getElementById('_checkbox'+tempid[i])!=null){
                  document.getElementById('_checkbox'+tempid[i]).checked="checked";
              }
          }
       }   
     }
   }     
   }
   
 },
 selectData :function(id,name,obj){
   id=(id || "").replace( this.rtrim, "" );
   name=(name || "").replace( this.rtrim, "" );
   
   if(document.getElementById('_checkbox'+id)!=undefined
   &&document.getElementById('_checkbox'+id)!=null
   && document.getElementById('_checkbox'+id).disabled ){
                  return;
   }
   var tempid=this.selectids.split(',');
   var isExist=false; 
   for(var i=0;i<tempid.length;i++){
     if(id==tempid[i]){
        isExist=true; 
     }
   } 
   if(!isExist){
     if(tempid[0]!=""&&tempid.length>=this.thismaxselect){
     alert('您最多能选择'+this.thismaxselect+'项');
     return ;
    }
     if(this.selectids==""){
       this.selectids=id;
       this.selectnames=name;
     }else{
       this.selectids=this.selectids+','+id;
       this.selectnames=this.selectnames+','+name;
     }
     
     this.showSelected();
     if(document.getElementById('_checkbox'+id)!=undefined&&document.getElementById('_checkbox'+id)!=null){
         document.getElementById('_checkbox'+id).checked="checked";
       }
      
   }else{
     this.cancelData(id,name);
     if(document.getElementById('_checkbox'+id)!=undefined&&document.getElementById('_checkbox'+id)!=null){
         document.getElementById('_checkbox'+id).checked="";
       }
   }
 },
 cancelData :function(id,name){
   id=(id || "").replace( this.rtrim, "" );
   name=(name || "").replace( this.rtrim, "" );
   var tempid=this.selectids.split(',');
   var tempname=this.selectnames.split(',');
   var newselectids='';
   var newselectnames='';
    
   for(var i=0;i<tempid.length;i++){
     if(id!=tempid[i] && tempid[i].replace( this.rtrim, "" )!=""){
       if(newselectids==""){
         newselectids= tempid[i];
         newselectnames= tempname[i];
       }else{
         newselectids=newselectids+','+tempid[i];
         newselectnames=newselectnames+','+tempname[i];
       }
     }
   }
   this.selectids=newselectids;
   this.selectnames=newselectnames;
   this.showSelected();
 },
 showSelected :function( ){
  var tempid=this.selectids.split(',');
   
  var tempname=this.selectnames.split(',');
  var htmlobj=[];
  for(var i=0;i<tempid.length;i++){
      if( tempid[i].replace( this.rtrim, "" )!=""){
         htmlobj.push('<a href="#;" onclick="cancelData(\' '+tempid[i]+' \',\' '+tempname[i]+' \')"><input name="checkbox22" ');
         if(this.thismaxselect>1){
           htmlobj.push('type="checkbox" ');
         }else{
           htmlobj.push('type="radio" ');
         }
         htmlobj.push('id="checkbox2" value="checkbox" checked="checked"/><label for="checkbox">'+tempname[i]+'</label></a>');
      }
   }
    document.getElementById('showselectdata').innerHTML=htmlobj.join("");
 },
 hideSecondData :function( ){
  if( this.showflag ){
    document.getElementById('subItems_joinren').style.display="block";
  }else{
    document.getElementById('subItems_joinren').style.display="none";
  }
   
 },
 setIsShow :function(value ){
  this.showflag=value;
 },
 selectdivdata :function(  ){
   if(this.selectnames!=null&&this.selectnames.length>15){
     document.getElementById(this.displayObjname).value=this.selectnames.substring(0,15)+'...';
   }else{
     document.getElementById(this.displayObjname).value=this.selectnames;
   }
   
   document.getElementById(this.hiddenObjname).value=this.selectids;
   if(this.selectFinishedMethod=="radio"){
    return ;
   }
   if(this.selectFinishedMethod!=undefined){
     eval(this.selectFinishedMethod);
   }
   
 },
 getSelectNameById :function( ids ){
 var catList=null;
 switch(this.thistype){
   case 'cat': catList=categoryList;break;
   case 'jrind': catList=industryList;break;
   case 'loc': catList=areaList;break;
   case 'major': catList=majorList;break;
  }
  
 var idnames="";
 var _ids=ids.split(',');
 for(var i=0;i<catList.length;i++){
   for(var i2=0;i2<_ids.length;i2++){
      if(catList[i].id==_ids[i2]){
        idnames+=catList[i].name+',';
      }
   } 
   for(var j=0;j<catList[i].subItems.length;j++){
     for(var i2=0;i2<_ids.length;i2++){
      if(catList[i].subItems[j].id==_ids[i2]){
        idnames+=catList[i].subItems[j].name+',';
      }
   } 
   }
 }
 if(idnames.length>1){
   idnames=idnames.substring(0,idnames.length-1); 
 }
 
 return idnames;
 }  
 
 
 


}



function hideSecondData ( ){
     PopupDiv.hideSecondData ( );
 }
 
var hide_timer=null;
function openSecondData (event,i,j,top,left,width,height ){
   setIsShow(true);
    var oEvent= event||window.event;
		 var ox=oEvent.clientX;
		var oy=oEvent.clientY;
        var ox2=oEvent.offsetX ;
        var oy2=oEvent.offsetY ;
        if(ox2==undefined){ox2=oEvent.layerX ;}
        if(oy2==undefined){oy2=oEvent.layerY ;}
         
        ox=ox-width-ox2+265  ;
        oy=oy+height-oy2-25 ;
        //alert(" _y:"+_y+" _x:"+_x+" oEvent.clientX:"+oEvent.clientX+" oEvent.clientY:"+oEvent.clientY
        // +" oEvent.offsetX:"+oEvent.offsetX+" oEvent.offsetY:"+oEvent.offsetY
        // +" width:"+width+" height:"+height); 
		
    //PopupDiv.openSecondData(i,j,oEvent.clientY-230,oEvent.clientX-150,width );
    PopupDiv.openSecondData(i,j,oy ,ox ,width );
    document.getElementById('subItems_joinren').style.display="block";
    if( hide_timer!=null&& hide_timer!=0){
   clearInterval( hide_timer);
    hide_timer=0;
 }
  hide_timer=setInterval(hideSecondData,500);
 }

function selectData (id,name,obj){
    PopupDiv.selectData(id,name,obj);
 }
 
function cancelData (id,name){
    PopupDiv.cancelData(id,name);
 } 
function setIsShow (flag){
    PopupDiv.setIsShow(flag);
 } 
function selectdivdata ( ){
    PopupDiv.selectdivdata( );
    closeDiv ( );
 }
 function closeDiv ( ){
    document.getElementById('ClickStyle').style.display="none";
    tb_remove();
 }




