// 弹出窗口通用函数
function Pop(url,left,top,width,height) {
	window.open(url,"_blank","directories=no,resizable=yes,status=yes,toolbar=no,scrollbars=yes,height="+height+",width="+width+",top="+top+",left="+left);
}

// 弹出最大化窗口，一般用于详细信息的录入与维护
function PopMax(url){
	var maxWidth=window.screen.availWidth-10;
	var maxHeight=window.screen.availHeight-50;
	Pop(url,0,0,maxWidth,maxHeight);
}
function PopMaxWithTool(url)
{
	var maxWidth=window.screen.availWidth-10;
	var maxHeight=window.screen.availHeight-50;
	window.open(url,"_blank","directories=no,resizable=yes,status=yes,toolbar=no,menubar=yes,scrollbars=yes,height="+maxHeight+",width="+maxWidth+",top=0,left=0");
}

// 弹出带名字的最大化窗口，一般用于详细信息的录入与维护
function PopMaxWithName(url,winname){
	var maxWidth=window.screen.availWidth-10;
	var maxHeight=window.screen.availHeight-50;
	window.open(url,winname,"directories=no,resizable=yes,status=yes,toolbar=no,scrollbars=yes,height="+maxHeight+",width="+maxWidth+",top="+0+",left="+0);
}

// 弹出小窗口，一般编码表选择或者信息提示
function PopCenter(url,width,height) {
	var maxWidth=window.screen.availWidth-10;
	var maxHeight=window.screen.availHeight-30
	var left=(maxWidth-width)/2;
	var top=(maxHeight-height)/2;
	Pop(url,left,top,width,height)
}
//弹出小窗口，不能缩放
function PopView(url,width,height) {
	PopViewWithName( url , width , height , "_blank" ) ;
}
//弹出带名字的小窗口，不能缩放
function PopViewWithName( url , width , height , winname ){
	var maxWidth=window.screen.availWidth-10;
	var maxHeight=window.screen.availHeight-30
	var left=(maxWidth-width)/2;
	var top=(maxHeight-height)/2;
	window.open(url,winname,"directories=no,toolbar=no,scrollbars=no,height="+height+",width="+width+",top="+top+",left="+left);
}

//从主框架中的子页面中返回主框架页面
function ReturnMainFrame( url )
{
	window.opener.location.href = url ;
	window.opener.reload() ;
}

//首页注销 
function SignOut()
{
	try
	{
		if(window.opener != null)
		{
			window.opener.document.focus();
		}
	}
	catch(e)
	{			
	}
	finally
	{
		window.close();
	}			
}

//显示消息中心
function ShowMessageCenter( objid )
{
	ChangeTextColor( objid );
	TrueHidenMenu() ;
	window.open( "left.aspx" , "left" ) ;
	window.open( "right.aspx" , "right" ) ;
}

function ShowLeftTree( objid )
{
	var obj = document.all[objid + "Text"];
	if(obj != null)
	{
		ShowTree(objid,obj.innerText);
	}
}

//显示左边的菜单树
function ShowTree( objid , objname )
{
	ChangeTextColor( objid );
	ShowMenu() ;
	window.open( "left.aspx?XMLFile=" + objid + "&NAME=" + objname , "left" ) ;
}
//改变topmenu的text color
function ChangeTextColor( objid )
{	
	var s = window.parent.document.getElementsByTagName("span");
	if( s != null )
	{
		for (var i=0; i<s.length; i++)
		{
			s[ i ].style.color="#ffffff";
		}
	}
	var o = document.getElementById( objid + "Text");
	if( o != null )
	{
		o.style.color="#ff0000";
	}
}
//根据消息中心的链接显示页面
function ShowRightPage( objid , objname , url )
{
	window.top.ChangeTextColor( objid);
	window.top.ShowMenu();
	window.open( "left.aspx?XMLFile=" + objid + "&NAME=" + objname , "left" ) ;
	window.open( url , "right" ) ;
}

function WOnload() 
{	
	//控制iframe的高度
	if(top.location != self.location)
	{
		if( window.parent != null )
		{
			var ifra = window.parent.document.getElementsByTagName('iframe');
			
			if( ifra!=null )
			{
				for (var i=0; i<ifra.length; i++)
				{
					if( ifra[i].name == self.name )
					{
						var h = window.screen.availHeight - 229 ;
						ifra[i].height = "0" ;	
						if(document.body.scrollHeight > h )
						{
							ifra[i].height = document.body.scrollHeight ; 
						}
						else
						{
							ifra[i].height = "100%" ;
						}
					}
				}
			}
		}
	} 

	//控制首页logo图片
	var imgUrl = "/gzpiimages/images/m_top2.gif" ;
	var loca = self.location + "" ;
	
	if( loca.indexOf( "PersonIntroduce" ) != -1 ){ imgUrl = "/gzpiimages/images/m_top2_2.gif" ; }
	else if( loca.indexOf( "Relation" ) != -1 ) { imgUrl = "/gzpiimages/images/m_top2_3.gif" ; }
	else imgUrl = "/gzpiimages/images/m_top2.gif" ;
	
	if( window.parent.document.all( "SystemImg" ) != null )
	{
		window.parent.document.all( "SystemImg" ).src= imgUrl ;
	}
	return ;
}	

// 孔祥鑫
// 列表框选择
function AddItems(sel1,sel2,txtName,txtCode)
{	
	var i = 0;
	var isValid = true;
	for(i = 0; i < sel1.options.length;i ++)
	{		
		var obj = sel1.options[i];		
		if(obj.selected) 
		{			
			if(!Contains(sel2,obj))
			{
				if(sel2.options.length >= 5)
				{					
					isValid = false;
				}
				else
				{
					var oOption = document.createElement("OPTION");
					sel2.options.add(oOption);
					oOption.innerText = obj.text;
					oOption.value = obj.value;
				}
			}
		}		
	}
	if(!isValid)
	{			
		alert("您最多只能选择5条记录!");
	}
	SetNameCode(sel2,txtName,txtCode);
	
}
function Contains(sel,oOption)
{
	var i = 0;
	for(i = 0; i < sel.options.length; i ++)
	{
		var obj = sel.options[i];
		if(obj.text == oOption.text && obj.value == oOption.value) return true;		
	}
	return false;
}

function SetNameCode(sel,txtName,txtCode)
{
	var i = 0;
	if(txtName != null)	txtName.value = "";
	if(txtCode != null)	txtCode.value = "";
	for(i = 0; i < sel.options.length; i ++)
	{
		var obj = sel.options[i];
		if(txtName != null) txtName.value += obj.text + ",";
		if(txtCode != null) txtCode.value += obj.value + ",";
	}
	if(txtName != null && txtName.value != "")
	{
		txtName.value = txtName.value.substring(0,txtName.value.length - 1);		
	}
	if(txtCode != null && txtCode.value != "")
	{
		txtCode.value = txtCode.value.substring(0,txtCode.value.length - 1);
	}
}

function DelItems(sel,txtName,txtCode)
{
	var i = 0;
	for(i = sel.options.length - 1; i >= 0; i --)
	{
		if(sel.options[i].selected) sel.options.remove(i);
	}
	SetNameCode(sel,txtName,txtCode);
}
function bindSelect(s1,s2,txtBoxText,txtBoxValue,tableName)
	{		
	var drp2 = s2;
	var code = s1.value;
	for(var i = drp2.options.length -1;i>=0;i--)
	{
		drp2.remove(i);
	}
	var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
	var oDoc = new ActiveXObject("MSXML2.DOMDocument");
	oHttpReq.open("POST", "/GZPI/Class/BindSelect.aspx?Code="+code + "&Table=" + tableName, false);
	oHttpReq.send("");
	result = oHttpReq.responseText;
	
	oDoc.loadXML(result);
	
	items = oDoc.selectNodes("City/Table");
	for (var item = items.nextNode(); item; item = items.nextNode())
	{
		var name = item.selectSingleNode("name").nodeTypedValue;
		var value = item.selectSingleNode("code").nodeTypedValue;
		var newOption = document.createElement("OPTION");
		newOption.text = name;
		newOption.value = value;
		drp2.options.add(newOption);
	}	
	if(txtBoxValue != null)
	{
		txtBoxValue.value = drp2.value;
	}
	
	if(txtBoxText != null)
	{
		if(drp2.selectedIndex != null && drp2.options.length != 0)	
		{
			txtBoxText.value = drp2.options[drp2.selectedIndex].innerText;	
		}
	}		

}
function bindTextValue(s,txtBoxText,txtBoxValue)
{		
	if(txtBoxText != null)
	{
		if(s.selectedIndex != null && s.options.length != 0)
			txtBoxText.value = s.options[s.selectedIndex].innerText;
	}
	if(txtBoxValue != null)
	{
		txtBoxValue.value = s.value;
	}
}
function PopCalendar(obj) 
{
	showx = event.screenX - event.offsetX - 4 - 10 ; // + deltaX;
	showy = event.screenY - event.offsetY -168; // + deltaY;
	newWINwidth = 210 + 4 + 18;

 	window.showModalDialog("/GZPI/Styles/calendar.htm",obj,"dialogWidth:206px; dialogHeight:230px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; ");    
}
// 列表框选择结束

//刷新opener,并关闭本页
function RefreshOpener()
{
	if(window.opener != null&&!window.opener.closed)
	{
		window.opener.document.forms[0].submit();
	}
	window.close();
}

//全选
function SelectAllCheckBox(cbOne,cbAll)
{			
	var checklist = document.all[cbOne];
	if(checklist != null)
	{
		checklist.checked = document.all[cbAll].checked;
		for(var i = 0;i < checklist.length;i ++)
		{ 
		    checklist[i].checked = document.all[cbAll].checked;
		}
	}	
}

function oMover(obj)
{
	obj.name = obj.className;
	obj.className = "listItemHover";
	
}
function oMout(obj)
{		
	obj.className = obj.name;	
}
//检查浏览器状态
function CheckBrowser()
{
	//检查是不是IE
	if(navigator.appName !="Microsoft Internet Explorer")
	{
		alert("您好，建议使用Microsoft Internet Explorer浏览器来使用系统!");
	}
	else
	{
		//检查是不是IE6的版本
		if(navigator.appVersion.indexOf("MSIE 6.")<0 )
		{
			//alert("当前浏览器版本太低，影响系统正常使用，请将浏览器升级到6.0及以上版本!");
		}
	}

	//检查是否支持cookie
	if(navigator.cookieEnabled!=true )
	{
		alert("浏览器不支持cookie,无法正常使用系统，请先设置好浏览器!");
	}
}
