var bordercolor;
titleheight=25; //提示窗口标题高度
bordercolor="#4A721B";//提示窗口的边框颜色
titlecolor="#4A721B";//提示窗口的标题颜色
function ShowCityLayer(title,bgcodelen)
{
   ShowSelLayer(550,230,title,"city",bgcodelen);
}

var TdMouse = " align='center' style='cursor:hand' onMouseOver='this.style.backgroundColor=\"#F3F3F3\"' onMouseOut='this.style.backgroundColor=\"#FFFFFF\"' ";
var TdSelect = " align='center' bgcolor='#ebebef' style='cursor:hand' onMouseOver='this.style.backgroundColor=\"#F3F3F3\"' onMouseOut='this.style.backgroundColor=\"#ebebef\"' ";
//TiTle 标题，Field引申层对象divField，按钮btnField,值隐藏字段Field, DefaultVal 默认值,BigCode 大类代码长度，空，没有二级选项
function ShowSelLayer(width,height,Title,dt,BigCodeLen)
{
   CreateBackground();
   PopSelLayer(width,height,Title,dt,BigCodeLen);
}

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);
}

/*
Field -> 需要设置值的控件名称
ShowText -> 显示控件显示的文本
Value   -> 为控件设置的值
dt      -> 数据源,DataTable 类型
keyName -> 数据源表中的ID字段名
textName -> 数据源表中的名称字段名
pKeyName -> 表中父ID字段名
funName  -> 每项单击时触发的函数名
BigCodeLen -> 下拉级数
*/
function SelectIt(Value,selType,BigCodeLen)
{
	if(BigCodeLen==0)
	{
    	ClarePopSelLayer();
	}
	else
	{
		var Arr;
		if(selType == "city")
		{
			Arr = eval(cityItems);
		}
    var jsq = 0;
    var tableHtml  = "<table width=100% border=0 class='normalCss' cellspacing=0 cellpadding=0 bgcolor=#FFFfff>";
        tableHtml += "<tr><td colspan=4 align='left' valign='bottom' height=24 width=25%" + TdMouse + " onclick='ClarePopSelLayer()'>&nbsp;&nbsp;<font color=red>请选择下面的城市</font></td></tr>";
		tableHtml += "<tr><td colspan=4 align=center><hr size=1 width='98%' noshade color=#669933></td></tr>";
		tableHtml += "<tr>";
    for(var i=0;i<Arr.length;i++)
	{
      if(Value == Arr[i][0])
	  {		
	     if(BigCodeLen > 1)
		 {
             tableHtml += "<td height=24 width=25%" + TdMouse + " onclick=\"SelectIt('" + Arr[i][1] +"','"+selType+"','"+ eval(BigCodeLen-1) +"')\">" + Arr[i][3] + "</td>";
		 }
		 else
		 {
			 tableHtml += "<td height=24 width=25%" + TdMouse + " onclick=\"selectedItem('" + Arr[i][1] +"|" +Arr[i][2] +"|" +Arr[i][3] + "|" +Arr[i][4] + "','"+selType+"')\">" + Arr[i][3] + "</td>";
		 }
         jsq++;
		 
		 if(jsq%4 == 0)
		 {
			 tableHtml += "</tr><tr>";
		 }
	  }
    }
	
    for(var k= (jsq-1) % 4;k<3;k++)
	{
      tableHtml += "<td height=24>&nbsp;</td>";
    }
    tableHtml += "</tr></table>";
    if(jsq>0)
	{
      subdiv = eval("subdiv" + BigCodeLen + selType);
      subdiv.innerHTML = tableHtml;
    }
    else
	{
      ClarePopSelLayer();
    }
  }
}

function selectedItem(value,seltype)
{
	ClarePopSelLayer();
	
	// 调用窗体内部方法
	popWindowSelected(seltype,value);
}

function PopSelLayer(width,height,title,selType,BigCodeLen)
{
	var msgObj=document.createElement("div")
	msgObj.setAttribute("id","msgDiv");
	msgObj.setAttribute("align","center");
	msgObj.style.background="white"; 
	msgObj.style.border="2px solid " + bordercolor; 
	msgObj.style.position = "absolute"; 
//	msgObj.style.top = document.body.scrollTop + parseInt(window.screen.availHeight)/2; 
//	msgObj.style.left = (parseInt(window.screen.availWidth) - width)/2; 
	msgObj.style.font="12px/1.6em Verdana, Geneva,  Arial, Helvetica, sans-serif"; 
	msgObj.style.left = (window.screen.availWidth-window.screenLeft-width)/2+"px";
	msgObj.style.top = (window.screen.availHeight-158-window.screenTop-height)/2+"px"; 
	msgObj.style.width = width + "px"; 
	msgObj.style.height =height + "px"; 
	msgObj.style.textAlign = "center"; 
	msgObj.style.lineHeight ="24px"; 
	msgObj.style.zIndex = "10001"; 
    
	var Arr; 
	if(selType == "city")
	{
	   Arr = eval(cityItems);
	}
	
	var tableHtml="<table width='100%' border='0' cellspacing='0' cellpadding='0' class='normalCss'>";
	tableHtml +="	  <tr height='" +titleheight+ "'>";
	tableHtml +="		<td align='left' bgcolor='" +bordercolor+ "'>&nbsp;&nbsp;<font color='#FFFFFF' style='font-size:14px'><b>" +title+ "</b></font></td>";

	tableHtml +="		<td align='right' bgcolor='" +bordercolor+ "'><font color='#FFFFFF' style='font-size:14px'><samp onclick='ClarePopSelLayer();' style='cursor:pointer'>关 闭</samp></font>&nbsp;&nbsp;</td>";
	
	tableHtml +="	  </tr></table>";
	tableHtml += "<table width='100%' border='0' cellspacing='0' cellpadding='0' class='normalCss'><tr>";
  var jsq = 0;
 
 for(var i=0;i<Arr.length;i++)
  {
	if(BigCodeLen > 0)
	{
		if(Arr[i][0] == "0")
		{
	       tableHtml += "<td height=24 width=25%" + TdMouse + " onclick=\"SelectIt('" + Arr[i][1] +"','"+selType+"','"+ eval(BigCodeLen-1) +"')\">" + Arr[i][3] + "</td>";
		   jsq++;
		}
	}
	else
	{
	    tableHtml += "<td height=24 width=25%" + TdMouse + " onclick=\"selectedItem('" + Arr[i][1] +"|" +Arr[i][2] +"|" +Arr[i][3]+ "','"+selType+"')\">" + Arr[i][3] + "</td>";
		jsq++;
	}	
	
    if(jsq%4 == 0)
	{
       tableHtml += "</tr><tr>";
     }
  }
  for(var k= (jsq-1) % 4;k<3;k++)
  {
    tableHtml += "<td height='24'>&nbsp;</td>";
  }

  tableHtml += "</tr></table><table width='100%' border='0' cellspacing='0' cellpadding='0' class='normalCss'><tr><td>";
  if(BigCodeLen>0)
  {  
     for(var di=0;di<BigCodeLen;di++)
     {
        tableHtml += "<div id='subdiv" + eval(BigCodeLen - di) + selType + "'></div>";
     }
  }
  tableHtml += "</td></tr>"
  
  tableHtml +="</table>";
	
    document.body.appendChild(msgObj); 
    document.getElementById("msgDiv").innerHTML = tableHtml;
} 


function CreateBackground()
{		
	hideElementAll();
	
	// 创建背景
	var sWidth,sHeight;
	sWidth=document.body.clientWidth;
	sHeight=document.body.scrollHeight;

	var bgObj=document.createElement("div");
	bgObj.setAttribute('id','bgDiv');
	bgObj.style.position="absolute";
	bgObj.style.top="0";
	bgObj.style.background="#000000";
	bgObj.style.filter="Alpha(Opacity=30);";
	bgObj.style.left="0";
	bgObj.style.width=sWidth + "px";
	bgObj.style.height=sHeight + "px";
	bgObj.style.zIndex = "10000";
	document.body.appendChild(bgObj);	
}

function ClarePopSelLayer()
{
	document.body.removeChild(document.getElementById("bgDiv"));
	document.body.removeChild(document.getElementById("msgDiv"));
	showElementAll();
}
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("INPUT");
//  HideElement("OBJECT");
//  HideElement("IFRAME");
}

function showElementAll(){
  ShowElement("SELECT");
  ShowElement("INPUT");
//  ShowElement("OBJECT");
//  ShowElement("IFRAME");
}