var returnHtml="";
var imgpath = "/js/select/"

//ajax
  var XMLHttpReq=null; 
   var currentSort; 
   var flag = "";
   //创建xmlhttprequset对象 
   function createXMLHttpRequest()
   { 
       if(window.ActiveXObject){
         XMLHttpReq = new ActiveXObject("Microsoft.XMLHttp");
        }else if(window.ActiveXObject){
         XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP.4.0");
        }else if(window.ActiveXObject){
         XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
        }else if(window.XMLHttpRequest){
         XMLHttpReq = new XMLHttpRequest();
         }
   }


//发送请求函数 
function sendRequest(url){ 
 if(XMLHttpReq==null)
 {
    createXMLHttpRequest(); 
 }
 XMLHttpReq.open("POST",url,false);
 var contentType='application/x-www-form-urlencoded';
 XMLHttpReq.setRequestHeader('Content-Type', contentType);
 XMLHttpReq.onreadystatechange=processResponse; 
 XMLHttpReq.send(); 
} 
//处理返回信息函数 


function processResponse(){ 
   if(XMLHttpReq.readyState==4){ 
   if(XMLHttpReq.status==200)
   { 
        updateMenu(); 
}else{alert("您请求的页面有异常!")} 
} 
} 
//更新菜单函数 
function updateMenu(){ 
 var doc=XMLHttpReq.responseXML.documentElement;
 //alert(XMLHttpReq.responseXML.xml);
 var nodes_id = doc.getElementsByTagName("id"); 
 var nodes_ShowName = doc.getElementsByTagName("ShowName");
 
  var i=0;

     for(i=0;i<nodes_id.length;i++)
     {
	    if(flag=="1")
        {
  	    returnHtml += "<td height='24' width='25%' " + TdMouse + " onclick=\"SelectH('"+ nodes_ShowName[i].firstChild.data +"','"+ nodes_id[i].firstChild.data +"',2)\">" + nodes_ShowName[i].firstChild.data + "</td>";
	    }
        if(flag=="2")
       {
    	returnHtml += "<td height='24' width='25%' " + TdMouse + " onclick=\"SelectH('"+ nodes_ShowName[i].firstChild.data +"','"+ nodes_id[i].firstChild.data +"',0)\">" + nodes_ShowName[i].firstChild.data + "</td>";
       }
	   if(flag=="3")
	   {
		  returnHtml += "<td height='30' width='25%' " + TdMouse + " ><a href=\"RcResultList.aspx?type=yj&ApplyFunc="+nodes_id[i].firstChild.data+"\" target=\"_blank\">" + nodes_ShowName[i].firstChild.data + "</a></td>";   
	   }
		if((i+1)%4==0)
	   {
		  returnHtml +=   "</tr><tr>"; 
	   }
     }
     if(i>0)
     {
     for(var k= i % 4;k<3;k++){
       returnHtml += "<td height='24'>&nbsp;</td>";
     }
     }
  
} 
//创建级联菜单 
function showSubMenu(url,flagValue){ 
   flag = flagValue;

  returnHtml = "";
   sendRequest(url); 
} 
//ajax
var Field = "";
var Field_Hidden = "";
var Path = "";
var TdMouse = " align='center' style='cursor:hand' onMouseOver='this.style.backgroundColor=\"#D1E7FE\"' onMouseOut='this.style.backgroundColor=\"#FFFFFF\"' ";
//TiTle 标题，Field引申层对象divField，按钮btnField,值隐藏字段Field, DefaultVal 默认值,BigCode 大类代码长度，空，没有二级选项
function buildPopSel(Title,Field1,DefaultVal,BigCodeLen,w,h,bimg,Fieldhidden,path_loc,parentid){
//	function buildPopSel(Title){
	Field = Field1;
	Field_Hidden = Fieldhidden;
    Path = path_loc; 
ObjList += ",div" + Field1;
 
  var btnShowText = Title;
  
  var htmlDiv;
  htmlDiv  = "<div id='div"+ Field1 +"' width='720' style='position:absolute;left:0px;top:165px;visibility:hidden;z-index:9;'></div>";
  htmlDiv += "<INPUT type='button' name='btn"+Field1+"' id='btn"+Field1+"' value='"+btnShowText+"' title=' "+Title+"' style='text-align: left; BORDER-RIGHT: 0px; BORDER-TOP: 0px; BACKGROUND: url("+bimg+"); BORDER-LEFT: 0px; WIDTH: "+w+"px; HEIGHT: "+h+"px; CURSOR: hand; BORDER-BOTTOM: 0px' onclick=displayLayer(div"+ Field1+",'"+ Field1 +"','"+Path+"','"+ Title +"',"+parentid+",'"+ Fieldhidden +"');>";
  //htmlDiv += "<INPUT type='hidden' name='" + Field + "' id='" + Field + "' value='" + DefaultVal + "'>";
  htmlDiv = "<span id='div" + Field1 + "pop'>" + htmlDiv + "</span>";
 //alert(htmlDiv);
  document.writeln(htmlDiv);
 
  	if(document.getElementById(escape(Fieldhidden)).value !="0")
	{
	   	document.all("btn"+Field).value = document.getElementById(escape(Fieldhidden)).value
	}
}

function switchSelect(Field2) {
  var obj = document.all("switch" + Field2);
  if (obj == null)
    return;

  if (obj.value == "下拉") {
    obj.value = "弹出";
    document.all("div" + Field2 + "pop").style.display = "none";
  //  document.all("div" + Field + "drop").style.display = "";    
   document.getElementById(escape(Field2)).style.display = "";
  }
  else {
    obj.value = "下拉";
    document.all("div" + Field2 + "pop").style.display = "";
	 document.getElementById(escape(Field2)).style.display = "none";
  //  document.all("div" + Field + "drop").style.display = "none";    
  }      
}

var ObjList = "";

String.prototype.LeftStr  = function(maxlen){
  var len = 0;
  for(var i = 0; i < this.length; i++){
    len++;
    if(this.charCodeAt(i) > 128) len++;
    if(len>maxlen) break;
  }
  return this.substring(0,i);
}

function DelFlag(str,value)
{
 if(value!=0)
 {
  return str.replace("--","");	
 }
 else
 {
   return " 请选择职位类别";
 }
}

function SelectDrop(Field1,ShowText,Value,BigCodeLen)
{
   	Field =Field1;
	SelectH(ShowText,Value,BigCodeLen);
}

function SelectH(ShowText,Value,BigCodeLen){
  //var 	 
  var btnField = document.all("btn"+Field);
  //var _arr = document.getElementsByName("ctl00$ContentPlaceHolder1$RApplyFunc");
  //if (_arr != null)
  //  for (var i = 0; i < _arr.length; i++)
   //   _arr[i].value = Value;
  //document.all(Field).value = Value;
  document.getElementById(escape(Field)).value= Value;
  document.getElementById(escape(Field_Hidden)).value= ShowText;
  var btnWidth = btnField.style.width.replace("px","");
      btnWidth = btnWidth - 12;
      btnField.value = " " + ShowText.LeftStr(btnWidth/7);
      
//alert(ShowText);

if(ShowText!="其它职位名称")
{
    document.getElementById("ctl00_ContentPlaceHolder1_InputStationName").style.display="none";
}
else
{
    document.getElementById("ctl00_ContentPlaceHolder1_InputStationName").style.display="block";
}

 // if(BigCodeLen==0){
//    document.all("div"+Field).style.visibility="hidden";
 //  hiddenLayer();
 // }
 //// else{
  //  var big = Value.substring(0,BigCodeLen);
  ///  var jsq = 1;
  if(Value!=0)
	{
    var htmlDiv  = "<hr size=4 noshade color=#3186EF><table width=100% border=0 cellspacing=0 cellpadding=0 bgcolor=#FFFFFF style='border-color: #0000CC #0000CC #0000CC #0000CC; border-style: dashed; border-top-width: 0px; border-right-width: 1px; border-bottom-width: 0px; border-left-width: 1px'>";
        htmlDiv += "<tr>";
   //
    
     showSubMenu(Path + "getlist.aspx?parentid="+Value,"2");
	
	
  htmlDiv +=returnHtml;
  
    htmlDiv += "</tr></table>";
  
    if(returnHtml.length>0){
     subdiv = eval("subdiv" + Field);
      subdiv.innerHTML = htmlDiv;
    }
    else{
      hiddenLayer();
    }
 // }
  }
}



function displayLayer(layerID,Field1,Path,Title,ParentId,FieldH){
  //alert(Field1);
  Field = Field1;
  Field_Hidden = FieldH;
  var htmlDiv = "";
 
  htmlDiv += "<table width='720' border='0' cellspacing='0' cellpadding='0' bgcolor='#FFFFFF'>";
  htmlDiv += "<tr><td align='left' valign='middle' width=600 height='26' bgcolor='#0099FF'>&nbsp;&nbsp;";
  htmlDiv += "<span style='color:#FFFFFF'>"+Title+"</span><a href='#' onclick='ClearValue()' style='color:#FFFFFF;'>【清除选择】</a></td>";
  htmlDiv += "<td align='right' valign='middle'  bgcolor='#0099FF'  style='color:#FFFFFF;cursor:hand;' onclick='hiddenLayer()'>【关闭选单】</td></tr>";
  htmlDiv += "<tr><td colspan='2' width='720' valign='top'>";
  htmlDiv += "<table width='100%' border='0' cellspacing='0' cellpadding='0' bgcolor='#FFFFFF' style='border-color: #0000CC #0000CC #0000CC #0000CC; border-style: dashed; border-top-width: 0px; border-right-width: 1px; border-bottom-width: 0px; border-left-width: 1px'>";
  htmlDiv += "<tr>";
  var big = null;
  var jsq = 0;
  //alert(Path + "getlist.aspx?parentid="+ParentId);
  showSubMenu(Path + "getlist.aspx?parentid="+ParentId,"1");
  htmlDiv +=returnHtml;

  htmlDiv += "</tr></table>";
  //if(BigCodeLen>0)
  htmlDiv += "<div id='subdiv"+Field1+"'></div>";
  htmlDiv += "</td></tr><tr><td colspan='2' height='4' bgcolor='#3186EF'></td></tr></table>";
  
  layerID.innerHTML = htmlDiv;

  
  //hiddenLayer();
  //hideElementAll();
  parent_page.style.visibility = "hidden";
  GetCenterXY_ForLayer(layerID);
  DivSetVisible(layerID);
}

function hiddenLayer(){
  showElementAll();
  parent_page.style.visibility = "visible";
  var argArr = ObjList.split(",");
  for(var i=0;i<argArr.length;i++){
    if(argArr[i]!="")	
    eval(argArr[i]).style.visibility = "hidden";
  }
}

function ClearValue(){
     //alert("");
     document.getElementById(escape(Field)).value= "";
     document.getElementById(escape(Field_Hidden)).value= "";
     var btnField = document.all("btn"+Field);
     btnField.value = "";
	 hiddenLayer();
}

//将悬浮层的位置定位在屏幕中央
function GetCenterXY_ForLayer(objdiv){
 
  x = document.body.scrollLeft;
  y = window.event.clientY + document.documentElement.scrollTop;

  //获取屏幕宽度
  availWidth = parseInt(window.screen.availWidth);
  availHeight = parseInt(window.screen.availHeight);

  tblWidth = parseInt(objdiv.width);

  //y = y + availHeight/8;
  x = (availWidth - tblWidth)/2;

  objdiv.style.top  = y;
  objdiv.style.left = x;
}

function DivSetVisible(objDiv){
  hideElementAll();
  objDiv.style.visibility = "visible";
}

function HideElement(strElementTagName){
  try{
    for(i=0;i<window.document.all.tags(strElementTagName).length; i++){
      var objTemp = window.document.all.tags(strElementTagName)[i];
      objTemp.style.visibility = "hidden";
    }
  }
  catch(e){
    alert(e.message);
  }
}

function ShowElement(strElementTagName){
  try{
    for(i=0;i<window.document.all.tags(strElementTagName).length; i++){
      var objTemp = window.document.all.tags(strElementTagName)[i];
      objTemp.style.visibility = "visible";
    }
  }
  catch(e){
    alert(e.message);
  }
}

function hideElementAll(){
  HideElement("SELECT");
  HideElement("OBJECT");
  HideElement("IFRAME");
}

function showElementAll(){
  ShowElement("SELECT");
  ShowElement("OBJECT");
  ShowElement("IFRAME");
}

function buildApplyFunc()
{
  var htmlDiv = "";
  htmlDiv += "<table width='100%' border='0' cellspacing='0' cellpadding='0' bgcolor='#FFFFFF' style='border-color: #0000CC #0000CC #0000CC #0000CC; border-top-width: 0px; border-right-width: 1px; border-bottom-width: 0px; border-left-width: 1px'>";
  htmlDiv += "<tr>";
  var big = null;
  var jsq = 0;
  showSubMenu("http://localhost/JobJM/CompManage/getlist.aspx","3");
  htmlDiv +=returnHtml;

  htmlDiv += "</tr></table>";	
  document.write(htmlDiv);
}
