//定義javascript全局變量
var x=0;

//全局方法

function SelectAll(id)
{
	var formname;
	if(id != null)
	{
		formname = id.name;
	}
	var t = event.srcElement.checked;
	var len = document.forms[0].elements.length;
	var i;
	for (i=0;i<len;i++)
	{
		if (document.forms[0].elements[i].type=="checkbox")
		{	
			var chk=document.forms[0].elements[i];
			//confirm(chk.disabled);
			if(id != null)
			{
				if (chk.id.indexOf("_chkItem")>0)
				{
					chk.checked=t;
					SelectRow(chk);
				}
				if (chk.id.indexOf("_ChkShipItem")>0)
				{
					chk.checked=t;
					SelectRow(chk);
				}
				if (chk.id.indexOf("_chkAffirm")>0 && !chk.disabled)
				{
					chk.checked=t;
					SelectRow(chk);
				}
			}
			else
			{
				if (chk.id.indexOf("_chkItem")>0)
				{
					chk.checked=t;
					SelectRow(chk);
				}
				if (chk.id.indexOf("_ChkShipItem")>0)
				{
					chk.checked=t;
					SelectRow(chk);
				}
				if (chk.id.indexOf("_chkAffirm")>0 && !chk.disabled)
				{
					chk.checked=t;
					SelectRow(chk);
				}
			}
		}
	}
	t=!t;
}
function SelectRow(chk)
{ 
	if (chk==null)
	{
		chk=event.srcElement;
	}
	if(chk.tagName == "INPUT")
	{
		SetBodyCheckboxRowColor(chk);
	}
}
function SetBodyCheckboxRowColor(chk)
{
	if (chk.id.indexOf("_chkItem")>0)
	{
		if (chk.checked==false)
		{
			GetGridRowOfCheckbox(chk).bgColor="#FFFFFF";
		}
		else
		{
			GetGridRowOfCheckbox(chk).bgColor="#ededed";
		}
	}
}

function GetGridRowOfCheckbox(chk)
{
	return chk.parentElement.parentElement;
}

function document.onkeydown()
{ 
	if(document.all('btnSearch') != null)
	{
		if(event.keyCode == 13) 
		{
			document.all('btnSearch').focus();
			document.all('btnSearch').click(); 
			return false;
		}
	}
}

function OpenEditWin(url)
		{
			//var url;
			//url = '../customer/ReceiveRecord.aspx';	
			var nwidth=screen.width;
			var nheight=screen.height;
			var posx;
			var posy;
			var wndWidth=1024;
			var wndHeight=600;	
			var sFeature;
			var str;

			posx=(parseInt(nwidth)-wndWidth)/2;
			posy=(parseInt(nheight)-wndHeight)/4;
			sFeature="height="+wndHeight+",width="+wndWidth+",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes";

			var openWnd;
			openWnd=window.open(url,null,sFeature);
			openWnd.moveTo(posx,posy);
			if(openWnd!=null)
			{
				openWnd.focus();
			}
			return ;
		}

function CloseWindow()
{
	window.opener=null;
	window.close();
}
function OpenWindow(Url,wndWidth,wndHeight)
{
	var nwidth=screen.width;
	var nheight=screen.height;
	var posx;
	var posy;
	var sFeature;

	posx=(parseInt(nwidth)-wndWidth)/2;	
	posy=(parseInt(nheight)-wndHeight)/2;
	sFeature="height="+wndHeight+",width="+wndWidth+",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,top=" + posy + ",left=" + posx;

	var openWnd;
	
	openWnd=window.open(Url,null,sFeature);

	if(openWnd!=null)
	{
		openWnd.focus();
	}
	return;
}

function OpenDialog(Url,wndWidth,wndHeight) {
	var sPath = Url;
	var nwidth=screen.width;
	var nheight=screen.height;
	var posx;
	var posy;
	posx=(parseInt(nwidth)-wndWidth)/2;	
	posy=(parseInt(nheight)-wndHeight)/2;
	
	strFeatures = "dialogWidth=wndWidth;dialogHeight=wndHeight;center=yes;help=no;status=no;toolbar=no;location=no;top=posy;left=posx";
	st = null;
	showModalDialog(sPath,st,strFeatures);
	
}
function OpenFullWindow(windowUrl,windowName)
{
	window.open(windowUrl,windowName,"top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no,status=no,width="+(screen.width-10)+",height="+(screen.availheight-30)+" ");
}

//登錄頁面
function checking()
{
	if(document.all.txtUsername.value=="")
	{
		alert("用戶名不能為空!請輸入");
		document.all.txtUsername.focus();
		return false;
	}
	if(document.all.txtPassword.value=="")
	{
		alert("密碼不能為空!請輸入");
		document.all.txtPassword.focus();
		return false;
	}
	return true;		       
}
function ClearInputs(){
	document.login.txtUsername.value="";
	document.login.txtPassword.value="";
}

//首頁
function RefreshMain()
{
	parent.MainFrame.location.reload();
}
		
function RefreshMain1(Action)
{
	if (Action == "REFRESH")
	{
		parent.MainFrame.location.reload();
	}
	//else if (Action == "BACK")
	//{
	//	parent.MainFrame.window.history.back(1);
	//	parent.MainFrame.window.location.reload();
	//}
	else
	{
		parent.MainFrame.document.all("txtHide").value=Action;
		parent.MainFrame.document.all("btnHideSubmit").click();
	}
  /*
	var URL = ""+window.parent.MainFrame.location;
	//alert(URL.indexOf("?"));
	
	if(URL.indexOf("?")<0)
	{    
		window.parent.MainFrame.location=URL+"?Action="+Action;
	}
	else
	{
		if (URL.indexOf("Action")<0)
		{
			window.parent.MainFrame.location=URL+"&Action="+Action;
		}
		else
		{
			var tempArr = URL.split("Action=");
			window.parent.MainFrame.location = tempArr[0]+"Action="+Action;
		}
	}
	*/
}

function RefreshToolBar()
{
}
function HideToolbar()
{	
}
function ShowToolbar()
{	
}

function SwitchLeftMenu()
{
	if (x==0)
	{ 
		x=1;
		switchPoint.innerHTML="<img src='../images/cmenu_b.jpg' width=7>";
		document.all("LeftMenu").style.display="none";
	}
	else
	{
		x=0;
		switchPoint.innerHTML="<img src='../images/cmenu_a.jpg' width=7>";
		document.all("LeftMenu").style.display="";
	}
}

function mhHoverover(idx)
{	
	idx.className="topselect";
}
function mhHoverout(idx)
{
	var t,d;
	idx.className="";
}
function mhHover(tbl,idx,cls)
{
	var t,d;
	if(document.getElementById)
		t=document.getElementById(tbl);
	else 
		t=document.all(tbl);
	if(t==null) return;
	if(t.getElementsByTagName)
		d=t.getElementsByTagName("TD");
	else 
		d=t.all.tags("TD");
	if(d==null)return;
	if(d.length <= idx)
		return;
	d[idx].className = cls;
	document.all["txtTitle"].value = cls;
}

function showHide(mid,mNum,menuid,menuname)
{
	for(i=0;i<mNum;i++)
	{
		Temp="r"+i; 	
		if(i == mid)
		{
			window.document.getElementById(Temp).className="TopselectMenu"; 
		}
		else
		{
			window.document.getElementById(Temp).className="TopMenu";  
		}
	}
	url='leftmenu.aspx?menuid='+menuid;
	window.parent.LeftFrame.location = url;
	window.parent.MainFrame.location = "main.aspx";
	//window.parent.MainFrame.location = "../Framework/Base/main.aspx";
	//alert("aa");
	/*document.getElementsById("TopMenu1_txtTitle").value =menuname;
	alert(document.getElementsById("TopMenu1_txtTitle").value);*/
	document.all["TopMenu1_txtTitle"].value = menuname;
	/*document.all["TopMenu1:txtTitle"].value = menuname;*/
	
}

function SaveUser(flag,pagetype)
{
	var nwidth=screen.width;
	var nheight=screen.height;
	var posx;
	var posy;
	var wndWidth=500;
	var wndHeight=330;	
	var sFeature;
	var str;

	posx=(parseInt(nwidth)-wndWidth)/2;	
	posy=(parseInt(nheight)-wndHeight)/2;
	sFeature="height="+wndHeight+",width="+wndWidth+",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,top=" + posy + ",left=" + posx;

	var openWnd;
	
	openWnd=window.open("../Manager/RoleUser.aspx?flag="+flag+"&pagetype="+pagetype,null,sFeature);
	//openWnd.moveTo(posx,posy);
	if(openWnd!=null)
	{
		openWnd.focus();
	}
	return false;
}