﻿var $ =function(ID){return document.getElementById(ID);};
function getQueryString(key)
{
	var locString = location.search;
	var reg = new RegExp("(\\?|\\&)" + key + "=([^\\&]*)(\\&?)","i").exec(locString);
	return RegExp.$2;
}
function checkenter(evt,para,option)
{
	evt = evt ? evt : (window.event ? window.event : null);	
	if(evt.keyCode == 13)
	{
		switch(para)
		{
			case 0:
				$(option).focus();
				break;
			case 1:
				setTimeout(option,100)
				break;
		}
		return false;
	}
}
function CheckLogin()
{
	var IsRootDir="";
	if($("hidVisitPageDetail").value!="Index")
		IsRootDir="../";
	$("divLogin").style.display="none";
	var result=g4pgold.ajax.common.CheckLogin().value;
	if(result != null && result!="0")
	{
		$("divUserInfo").innerHTML="<div style=\"padding-top:28px;\"><a class=\"bai\" href=\""+IsRootDir+"customer/\">My Account</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class=\"bai\" href=\""+IsRootDir+"customer/shoppinglist.html\">Shopping List</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class=\"bai\" href=\"javascript:Logout();\">Logout</a></div>";
		$("divIsLogin").style.display="";
		$("divNotLogin").style.display="none";
	}
	else
		$("divNotLogin").style.display="";
}
function Login()
{
	if($("txtCustomerID").value==""||$("txtPassword").value=="")
	{
		alert("Email or Password can't be empty.");
		return;
	}
	g4pgold.ajax.common.Login($("txtCustomerID").value,$("txtPassword").value,Login1);
}
function Login1(response)
{
	var result=response.value;
	if(result != null && result!="0")
	{
		$("divUserInfo").innerHTML="<div style=\"padding-top:28px;\"><a class=\"bai\" href=\""+IsRootDir+"customer/\">My Account</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class=\"bai\" href=\""+IsRootDir+"customer/shoppinglist.html\">Shopping List</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class=\"bai\" href=\"javascript:Logout();\">Logout</a></div>";
		$("divIsLogin").style.display="";
		$("divNotLogin").style.display="none";	
		$("txtCustomerID").value="";
		$("txtPassword").value="";
		if(IsRefresh)
			RefreshLogin();
	}
	else
		alert("Email or Password Error.");
}
function Logout()
{
	var result=g4pgold.ajax.common.Logout();
	$("divUserInfo").innerHTML="";
	$("divIsLogin").style.display="none";
	$("divNotLogin").style.display="";
	if(IsRefresh)
		RefreshLogout();
}
function CheckAff()
{
	var aff=getQueryString("aff")
	if(aff!="")
		var result=g4pgold.ajax.common.SaveAff(aff).value;
}
function TrackOrder()
{
	if($("txtTrackOrder").value=="")
		alert("Order Number can't be empty.");
	else
		window.location=IsRootDir+"customer/shoppinglist.html?CNO="+$("txtTrackOrder").value;
}
function DivAutoHeight()
{
	if($("divLeft")&&$("divRight"))
	{
		var divLeftHeight=$("divLeft").clientHeight;
		var divRightHeight=$("divRight").clientHeight;
		if(divLeftHeight>divRightHeight)
			$("divRight").style.height=$("divLeft").clientHeight+"px";
		else
			if(divLeftHeight>1700)
				$("divRight").style.height=$("divLeft").clientHeight+"px";
			else
				$("divRight").style.height="1700px";
	}
}
function CheckFileName(FileName)
{
	var re=new RegExp(" ","g");
	FileName=FileName.replace(re,"-");
	
	re=new RegExp("/","g");
	FileName=FileName.replace(re,"-");

	re=new RegExp("\\\\","g");
	FileName=FileName.replace(re,"-");		
	
	re=new RegExp(":","g");
	FileName=FileName.replace(re,"-");		

	re=new RegExp("\\*","g");
	FileName=FileName.replace(re,"-");		
			
	re=new RegExp("\\?","g");
	FileName=FileName.replace(re,"-");		

	re=new RegExp("<","g");
	FileName=FileName.replace(re,"-");		
	
	re=new RegExp(">","g");
	FileName=FileName.replace(re,"-");		
	
	re=new RegExp("\\|","g");
	FileName=FileName.replace(re,"-");		
		
	re=new RegExp('"',"g");
	FileName=FileName.replace(re,"-");
	
	return FileName;
}
CheckLogin();
CheckAff();

	