function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// ***** Click Photo *****

function PrevPhoto() {
	var photo_id=parseInt(document.Photofrm.photo_id.value);
	if (photo_id>1) {
		photo_id--;
		document.Photofrm.photo_id.value=photo_id;
		Photofrm.zphoto_name.src=new Image();
		eval("Photofrm.zphoto_name.src = document.Photofrm.photo_name_" + photo_id + ".value;");
		eval("Photofrm.zphoto_name.alt = 'Order Number : '+ document.Photofrm.photo_order_" + photo_id + ".value;");
		document.Photofrm.photo_name.value=Photofrm.zphoto_name.src;
		Photofrm.number.src = new Image();
		Photofrm.number.src= "../../image/" + photo_id + ".gif";

	}
	if (photo_id<=1) {
		resetIcon("pre");
	}
	else {
		resetIcon("");
	}
}

function nextbhoto() {
	var photo_id=parseInt(document.Photofrm.photo_id.value);
	var lastorderid=parseInt(document.Photofrm.lastorderid.value);
	if (photo_id<lastorderid) {
		photo_id++;
		document.Photofrm.photo_id.value=photo_id;
		Photofrm.zphoto_name.src=new Image();
		eval("Photofrm.zphoto_name.src= document.Photofrm.photo_name_" + photo_id + ".value;");
		eval("Photofrm.zphoto_name.alt = 'Order Number : '+ document.Photofrm.photo_order_" + photo_id + ".value;");
		document.Photofrm.photo_name.value=Photofrm.zphoto_name.src;
		Photofrm.number.src = new Image();
		Photofrm.number.src= "../../image/" + photo_id + ".gif";
	}
	if (photo_id>=lastorderid) {
		resetIcon("next");
	}
	else {
		resetIcon("");
	}
}

function resetIcon(cIcon) {
	if (cIcon=="pre") {
		Photofrm.prevb.src=new Image(0,0);
		Photofrm.prevb.src="image/none.gif";
		Photofrm.nextb.src=new Image(15,14);
		Photofrm.nextb.src="image/right.gif";
		Photofrm.nextb.focus();
	}
	else if (cIcon=="next") {
		Photofrm.prevb.src=new Image(15,14);
		Photofrm.prevb.src="image/left.gif";
		Photofrm.nextb.src=new Image(0,0);
		Photofrm.nextb.src="../image/none.gif";
		Photofrm.nextb.focus();
	}
	else {
		Photofrm.prevb.src=new Image(15,14);
		Photofrm.prevb.src="image/left.gif";
		Photofrm.nextb.src=new Image(15,14);
		Photofrm.nextb.src="image/right.gif";
	}
}

function AddtoCart(objFormID)
{
	eval("var objForm = document.Productform_"+objFormID+";");

	if (objForm.opt.value == "Y" )
		objForm.action = "index.php?q=showroom/productdetail.php#selection";
	else
		objForm.action = "index.php?q=cart/cart.php&act=add";

   
	objForm.submit();
}


function UpdateItem(objForm)
{
	eval("var objForm = document."+objForm+";");

	objForm.action = "index.php?q=cart/cart.php&act=update&BasketID="+objForm;
 
	objForm.submit();
}


function RemoveItem(objForm)
{
	eval("var objForm = document."+objForm+";");

	objForm.action = "index.php?q=cart/cart.php&act=remove";
   
	objForm.submit();
}

function RemoveAll()
{
	if (confirm("Are you sure to remove all items?"))
	{
		document.CartLst.action = "index.php?q=cart/cart.php&act=removeall";

		document.CartLst.submit();
	}
   
}


function BuyNow(objFormID)
{
	eval("var objForm = document.Productform_"+objFormID+";");

	if (objForm.opt.value == "Y" )
		objForm.action = "index.php?q=showroom/productdetail.php#selection";
	else
		objForm.action = "index.php?q=cart/cart.php&act=buynow";

   
	objForm.submit();
}

function Productdetailfrm_Submit(url, action)
{
	document.Productdetailform.action = url; 
	document.Productdetailform.act.value = action; 
	document.Productdetailform.submit();

}



function CheckCheckoutform(objForm)
{	
		if(IsBlank(objForm.Firstname_b.value, "first name of the contact person"))
			return false;
		
		if(IsBlank(objForm.Familyname_b.value, "family name of the contact person"))
			return false;

		if(IsBlank(objForm.Email.value, "email address"))
			return false;

		if(!IsBlank(objForm.Email.value, "email address")){
				if(!IsValidEmail(objForm.Email))
					return false;
		}

		if(IsBlank(objForm.BillingAddress.value, "billing address"))
			return false;


		if(IsBlank(objForm.CountryCode_b.value, "country"))
			return false;

		if (objForm.AsBilling.checked != true){

			if(IsBlank(objForm.Firstname_s.value, "first name"))
				return false;

			if(IsBlank(objForm.Familyname_s.value, "family name"))
				return false;

			if(IsBlank(objForm.ShippingAddress.value, "shipping address"))
				return false;


			if(IsBlank(objForm.CountryCode_s.value, "country"))
				return false;

		}else{
			
			objForm.Firstname_s.value = objForm.Firstname_b.value;

			objForm.Familyname_s.value = objForm.Familyname_b.value;

			objForm.ShippingAddress.value = objForm.BillingAddress.value;

			objForm.City_s.value = objForm.City_b.value;

			objForm.Zipcode_s.value = objForm.Zipcode_b.value;

			objForm.State_s.value = objForm.State_b.value;

			objForm.Country_s.value = objForm.Country_b.value;

			objForm.CountryCode_s[objForm.CountryCode_s.selectedIndex].value = objForm.CountryCode_b[objForm.CountryCode_b.selectedIndex].value;

		}
	return true;
}

function ValidateCheckoutform(objForm) {
    if (CheckCheckoutform(objForm))
        objForm.submit();
}


function CheckForgetpassform(objForm)
{
	if(IsBlank(objForm.Username.value, "username"))
		return false;

	if(IsBlank(objForm.Email.value, "email address"))
		return false;

	return true;
}

function ValidateForgetpassform(objForm) {
    if (CheckForgetpassform(objForm))
        objForm.submit();
}

function CheckJoinform(objForm){
	if (IsBlank(objForm.Username.value, "username"))
		return false;
	if (IsBlank(objForm.Password1.value, "password"))
		return false;	
	if (IsBlank(objForm.Password2.value, "confirm password"))
		return false;	
	if (objForm.Password2.value != objForm.Password1.value){
		alert("Confirm password not matched. Please re-enter.");
		return false;
	}

	if (IsBlank(objForm.Firstname_b.value, "firstname"))
			return false;	
	if (IsBlank(objForm.Familyname_b.value, "family name"))		
		return false;	

	if (IsBlank(objForm.BillingAddress.value, "billing address"))		
		return false;	
	if (IsBlank(objForm.Email.value, "email address"))		
		return false;	
	if (!IsValidEmail(objForm.Email))		
		return false;	
	if (objForm.Country_b[objForm.Country_b.selectedIndex].value==0){					
		alert("Please select a country");		
		return false;	
	}	
	return true;
}


function ValidateJoinform(objForm) {
    if (CheckJoinform(objForm))
        objForm.submit();
}

function populate(objForm,selectIndex)
{
timeA = new Date(objForm.year.options[objForm.year.selectedIndex].text, objForm.month.options[objForm.month.selectedIndex].value,1);
timeDifference = timeA - 86400000;
timeB = new Date(timeDifference);
var daysInMonth = timeB.getDate();

for (var i = 0; i < objForm.day.length; i++) {
	objForm.day.options[0] = null;
}

for (var i = 0; i < daysInMonth; i++) {
	objForm.day.options[i] = new Option(i+1);
}
document.JoinMemberForm.day.options[0].selected = true;
}



function getYears()
{

	// You can easily customize what years can be used
	var years = new Array(1950, 1951, 1952, 1953, 1954, 1955, 1956, 1957, 1958, 1959, 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001)

	for (var i = 0; i < document.JoinMemberForm.year.length; i++) {
		document.JoinMemberForm.year.options[0] = null;
	}

	timeC = new Date();
	currYear = timeC.getFullYear();

	for (var i = 0; i < years.length; i++) {
		document.JoinMemberForm.year.options[i] = new Option(years[i]);
	}
	document.JoinMemberForm.year.options[2].selected=true;
}

function OnlinePaymentEPay() {
	document.Purchaseform.M_Payment.value = "Paid Online";
	document.Purchaseform.action = "index.php?q=cart/temporder_epay.php";
	document.Purchaseform.submit();	
}

function OnlinePaymentPayPal() {
	document.Purchaseform.M_Payment.value = "Paid Online";
	document.Purchaseform.action = "index.php?q=cart/temporder_paypal.php";
	document.Purchaseform.submit();	
}

function OnlinePaymentWP() {
	document.Purchaseform.M_Payment.value = "Paid Online";
	document.Purchaseform.action = "https://select.worldpay.com/wcc/purchase";
	document.Purchaseform.submit();	
}

function OnlinePaymentWH() {
	document.Purchaseform.M_Payment.value = "Paid Online";
	document.Purchaseform.action = "index.php?q=cart/temporder_winghang.php";
	document.Purchaseform.submit();	
}

function OnlinePayment()
{
//	document.Purchaseform.M_Payment.value = "Paid Online";
//	document.Purchaseform.action = "index.php?q=cart/temporder.php";
//	document.Purchaseform.submit();
	document.Purchaseform.M_Payment.value = "Paid Online";
//	document.Purchaseform.action = "https://select.worldpay.com/wcc/purchase";
//  document.Purchaseform.action = "https://test.paydollar.com/winghang/eng/payment/payForm.jsp";
	document.Purchaseform.action = "index.php?q=cart/temporder.php";
	document.Purchaseform.submit();
}

function OfflinePayment()
{
	document.Purchaseform.M_Payment.value = "Paid Offline";
	document.Purchaseform.action = "index.php?q=cart/done.php";

	document.Purchaseform.submit();
}

function CheckModifyprofilefrm(objForm)
{
	if(IsBlank(objForm.Firstname_b.value, "firstname"))
		return false;

	if(IsBlank(objForm.Familyname_b.value, "familyname"))
		return false;

	if(IsBlank(objForm.Email.value, "email address"))
		return false;

	if(IsBlank(objForm.BillingAddress.value, "address"))
		return false;

	if(IsBlank(objForm.Country_b[objForm.Country_b.selectedIndex].value, "country"))
		return false;


	if(!IsBlank(objForm.Email.value, "email address")){
			if(!IsValidEmail(objForm.Email))
				return false;
	}

	return true;
}


function ValidateModifyprofilefrm(objForm) {
    if (CheckModifyprofilefrm(objForm))
        objForm.submit();
}


function CheckChangepwdform(objForm)
{	
	if(IsBlank(objForm.Username.value, "username"))
		return false;

	if(IsBlank(objForm.Password1.value, "password"))
		return false;

	if(IsBlank(objForm.Password2.value, "re-entered password"))
		return false;

	if (objForm.Password2.value != objForm.Password1.value){
		alert("Re-entered password is wrong. Please entered again.");
		objForm.Password2.value = "";
		objForm.Password1.value = "";
		return false;
	}

	return true;
}



function ValidateChangepwdform(objForm) {
    if (CheckChangepwdform(objForm))
        objForm.submit();
}

function UpdateAllItem(){
	var form_size = document.forms.length;
	for (var i=0; i < form_size; i++)
	{
		if (document.forms[i].name.indexOf("Cartlstform2_")==0)
		{
			document.forms[i].submit();
		}
	}
}

function ZoomPhoto(width,height,image)
{
	if (image == "index"){
		image = Photofrm.zindexphoto_name.src;
	}else{
		image = Photofrm.zphoto_name.src;
	}
	window.open("../../zoomphoto.php?width=" + width + "&height=" + height + "&image=" + image, 'ZoomPic','width=1000, height=500, resizable=yes, scrollbars=yes');
}

function PopFitWin(imgpath,id) {
	if (imgpath == "editproduct") {
		var imgurl = document.frm.zphoto_name.src;
	} else if (imgpath == "productdetail") {
		var imgurl = Photofrm.zphoto_name.src;
	} else {
		var imgurl = imgpath;
	}

	var url = "popfitwin.php?id="+id+"&img="+imgurl;
	window.open(url, "", "resizable=no,status=no,HEIGHT=10,WIDTH=10,TOP=100,LEFT=100");

}