﻿
var message="Sorry, right-click has been disabled";
 
function clickIE() {if (document.all) {(alert(message));return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(alert(message));return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function("return false")

var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;
var price=0;

var total1=0;
var total2=0;
var total3=0;
var total4=0;
var total5=0;

var items=0;
var item1=0;
var item2=0;
var item3=0;
var item4=0;
var item5=0;	
//jz copy the code below this and edit it.






// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 
// -->

function reso(value, distance)
{
   var X = screen.width;
   var Y = screen.height;
   var Z = distance;
   X=X-850;
   X=X/2;
   X=X+Z;
  
   X1 = X+'px';
  
   document.getElementById(value).style.marginLeft=X1;
   
   }
function ProductP(name1)
{
	var price=0;
		switch (name1){
		case 'Agri Vinegar -330ml': price=5; break;
		case 'Agri Vinegar -1L': price=12; break;
		case 'Agri Vinegar -5L': price=50; break;
		case 'Agri Vinegar -25L': price=200; break;
		case 'Swiftlet -1L': price=50; break;
		case 'Swiftlet -5L': price=200; break;
		case 'C+ -350ml': price=10; break;
		case 'C+ -1L': price=25; break;
		case 'C+ -5L': price=100; break;
		case 'S+ -350ml': price=10; break;
		case 'S+ -1L': price=25; break;
		case 'S+ -5L': price=100; break;

			}
	return price;

}
function USD(value1)
{
	value1 = '$'+value1;
	return value1;
}

function Multiply(value1)
{
	var value2;
	value2=document.formEnter.Quantity_text.value;
	
	return value1*value2;
}

function Submit()
{	

	
	var product_name = document.formEnter.SelectProduct.value;
	var product_price = document.formEnter.Price_label.value;
	var product_quantity = document.formEnter.Quantity_text.value;
	var product_total = document.formEnter.Total_label.value;
	var price2 = price;
	var items2 = items;
	 items  = parseInt(document.formEnter.Quantity_text.value);
	 
	
	items = items2+items;
	document.formSubmit.NumberOfItems.value=items;	
	price = Multiply(ProductP(document.formEnter.SelectProduct.value));
	price = price+price2;
	document.formSubmit.grandTotal.value = USD(price);
	if(document.formSubmit.product1.value == ""){
	document.formSubmit.product1.value = product_name;
	document.formSubmit.price1.value = product_price;
	document.formSubmit.quuantity1.value = product_quantity;
	document.formSubmit.total1.value = product_total;
	total1=Multiply(ProductP(document.formEnter.SelectProduct.value));
	item1  = parseInt(document.formEnter.Quantity_text.value);
	
	
	
	
		} else if(document.formSubmit.product2.value == ""){
	document.formSubmit.product2.value = product_name;
	document.formSubmit.price2.value = product_price;
	document.formSubmit.quuantity2.value = product_quantity;
	document.formSubmit.total2.value = product_total;
	total2=Multiply(ProductP(document.formEnter.SelectProduct.value));
	item2  = parseInt(document.formEnter.Quantity_text.value);
		
	} else if(document.formSubmit.product3.value == ""){
	document.formSubmit.product3.value = product_name;
	document.formSubmit.price3.value = product_price;
	document.formSubmit.quuantity3.value = product_quantity;
	document.formSubmit.total3.value = product_total;
	total3=Multiply(ProductP(document.formEnter.SelectProduct.value));
	item3  = parseInt(document.formEnter.Quantity_text.value);	
	
	} else if(document.formSubmit.product4.value == ""){
	document.formSubmit.product4.value = product_name;
	document.formSubmit.price4.value = product_price;
	document.formSubmit.quuantity4.value = product_quantity;
	document.formSubmit.total4.value = product_total;
	total4=Multiply(ProductP(document.formEnter.SelectProduct.value));
	item4  = parseInt(document.formEnter.Quantity_text.value);
	} else if(document.formSubmit.product5.value == ""){
	document.formSubmit.product5.value = product_name;
	document.formSubmit.price5.value = product_price;
	document.formSubmit.quuantity5.value = product_quantity;
	document.formSubmit.total5.value = product_total;
	total5=Multiply(ProductP(document.formEnter.SelectProduct.value));
	item5  = parseInt(document.formEnter.Quantity_text.value);
	}
	
		
	
	
	document.formEnter.SelectProduct.value ="";
	document.formEnter.Price_label.value ="";
	document.formEnter.Quantity_text.value ="";
	document.formEnter.Total_label.value ="";

	

}
function allow()
{
	if(document.formSubmit.product1.value != ""){
	document.formSubmit.product1.disabled="";
	document.formSubmit.price1.disabled="";
	document.formSubmit.quuantity1.disabled="";
	document.formSubmit.total1.disabled="";

	}
	if(document.formSubmit.product2.value != ""){
	document.formSubmit.product2.disabled="";
	document.formSubmit.price2.disabled="";
	document.formSubmit.quuantity2.disabled="";
	document.formSubmit.total2.disabled="";

	}
	if(document.formSubmit.product3.value != ""){
	document.formSubmit.product3.disabled="";
	document.formSubmit.price3.disabled="";
	document.formSubmit.quuantity3.disabled="";
	document.formSubmit.total3.disabled="";

	}
	if(document.formSubmit.product4.value != ""){
	document.formSubmit.product4.disabled="";
	document.formSubmit.price4.disabled="";
	document.formSubmit.quuantity4.disabled="";
	document.formSubmit.total4.disabled="";

	}
	if(document.formSubmit.product5.value != ""){
	document.formSubmit.product5.disabled="";
	document.formSubmit.price5.disabled="";
	document.formSubmit.quuantity5.disabled="";
	document.formSubmit.total5.disabled="";

	}
	document.formSubmit.grandTotal.disabled="";
	document.formSubmit.NumberOfItems.disabled="";
}
function disallow()
{
	
	document.formSubmit.product1.disabled="disabled";
	document.formSubmit.price1.disabled="disabled";
	document.formSubmit.quuantity1.disabled="disabled";
	document.formSubmit.total1.disabled="disabled";

	
	
	document.formSubmit.product2.disabled="disabled";
	document.formSubmit.price2.disabled="disabled";
	document.formSubmit.quuantity2.disabled="disabled";
	document.formSubmit.total2.disabled="disabled";

	
	
	document.formSubmit.product3.disabled="disabled";
	document.formSubmit.price3.disabled="disabled";
	document.formSubmit.quuantity3.disabled="disabled";
	document.formSubmit.total3.disabled="disabled";

	
	
	document.formSubmit.product4.disabled="disabled";
	document.formSubmit.price4.disabled="disabled";
	document.formSubmit.quuantity4.disabled="disabled";
	document.formSubmit.total4.disabled="disabled";

	
	
	document.formSubmit.product5.disabled="disabled";
	document.formSubmit.price5.disabled="disabled";
	document.formSubmit.quuantity5.disabled="disabled";
	document.formSubmit.total5.disabled="disabled";

	
	document.formSubmit.grandTotal.disabled="disabled";
	document.formSubmit.NumberOfItems.disabled="disabled";
}
function clear1()
{	
	price = price-total1;
	document.formSubmit.grandTotal.value= USD(price);
	total1=0;
	
	items = items-item1;
	
	document.formSubmit.NumberOfItems.value = items;
	item1 = 0;
	document.formSubmit.product1.value = "";
	document.formSubmit.price1.value = "";
	document.formSubmit.quuantity1.value = "";
	document.formSubmit.total1.value = "";
	
		

}
function clear2()
{	
	price = price-total2;
	document.formSubmit.grandTotal.value= USD(price);
	total2=0;
	items = items-item2;
	
	document.formSubmit.NumberOfItems.value = items;
	item2 = 0;

	document.formSubmit.product2.value = "";
	document.formSubmit.price2.value = "";
	document.formSubmit.quuantity2.value = "";
	document.formSubmit.total2.value = "";

			
}
function clear3()
{	
	price = price-total3;
	document.formSubmit.grandTotal.value= USD(price);
	total3=0;
	items = items-item3;
	document.formSubmit.NumberOfItems.value = items;
	item3 = 0;


	document.formSubmit.product3.value = "";
	document.formSubmit.price3.value = "";
	document.formSubmit.quuantity3.value = "";
	document.formSubmit.total3.value = "";
			
		

}
function clear4()
{
	price = price-total4;
	document.formSubmit.grandTotal.value= USD(price);
	total4=0;
	items = items-item4;
	document.formSubmit.NumberOfItems.value = items;
	item4 = 0;

	document.formSubmit.product4.value = "";
	document.formSubmit.price4.value = "";
	document.formSubmit.quuantity4.value = "";
	document.formSubmit.total4.value = "";

	
}
function clear5()
{
	price = price-total5;
	document.formSubmit.grandTotal.value= USD(price);
	total5=0;
	items = items-item5;
	document.formSubmit.NumberOfItems.value = items;
	item5 = 0;

	document.formSubmit.product5.value = "";
	document.formSubmit.price5.value = "";
	document.formSubmit.quuantity5.value = "";
	document.formSubmit.total5.value = "";
			
			

}

function preSubmit()
{
	if(document.formEnter.Quantity_text.value =='0'){
		alert("Please do not key in quantity as 0");
		} else if (document.formEnter.SelectProduct.value !="")
		if(document.formEnter.Quantity_text.value !="")
			{
			Submit();
		} else {
		alert("Please key in all the details before submission");
			}
}



function validateForm()
{
var x=document.forms["formSubmit"]["Email"].value
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
var	name1 = document.formSubmit.Name.value;
var name2 = name1.length;
var numericExpression = /^[0-9]+$/;
contact = document.getElementById('contact1');
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
  {
  alert("Not a valid e-mail address");
  document.formSubmit.Email.focus();
  return false;
  } else if(name2<3)
  {
  	alert("Your name must be at least 3 character");
  	document.formSubmit.Name.focus();
  	return false;
  } 
  if (contact.value.match(numericExpression))
  {
  return true;
  }else
  {
  	alert("Your contact number contain non-numeric, please key in only numbers or integers in it");
 	contact.focus(); 
 	return false;	
 }

}

// close layer when click-out
document.onclick = mclose; 

