////////		FUNCTION TO SHOW DIV	/////////////
function showDiv()
{
	
	if (document.getElementById) 
	{ // DOM3 = IE5, NS6 
		document.getElementById('homeText').style.visibility = 'visible'; 
	} 
	else 
	{ 
		if (document.layers) 
		{ // Netscape 4 
			document.homeText.visibility = 'visible'; 
		} 
		else 
		{ // IE 4 
			document.all.homeText.style.visibility = 'visible'; 
		} 
	} 
} 

//////////		FUNCTION TO SET TIMER	//////////////
function textTimer(homeTime)
{
	setTimeout("showDiv()", homeTime);
}

//////////		SET COOKIE		///////////
function setLanguage(lang)
{
	var expdate=new Date();
	expdate.setDate(expdate.getDate()+365);
	document.cookie="language="+escape(lang)+";expires="+expdate.toGMTString();
}
	
///////////		CHECKS IF EMPTY OR NOT	///////////////////
function isEmpty(elementValue)
{
	if( (elementValue=="") || (elementValue==null) )
	{
		return true;	//if empty
	}
	else
	{
		return false;	//if not empty
	}
}
	
	
//////// VALIDATION FOR ORDER PAGE	////////////
function checkOrder()
{
	var telephoneValue = document.getElementById('order_tel').value;
	var proNumberValue = document.getElementById('pronumber').value;
	if(isEmpty(document.getElementById('pronumber').value))
	{
		alert('Please enter number of jar(s) you require');
		document.frmOrder.pronumber.focus();
		return false ;
	}
	else if(!numericCheck(proNumberValue))
	{
		alert('Please enter a valid number');
		document.frmOrder.pronumber.focus();
		return false;
	}
	if(isEmpty(document.getElementById('order_Initials').value))
	{
	alert('Please enter initials');
	document.frmOrder.order_Initials.focus();
	return false ;
	}
	if(isEmpty(document.getElementById('order_Surname').value))
	{
	alert('Please enter your last name');
	document.frmOrder.order_Surname.focus();
	return false ;
	}
	if(isEmpty(document.getElementById('order_adds').value))
	{
	alert('Please enter your address');
	document.frmOrder.order_adds.focus();
	return false;
	}
	if(isEmpty(document.getElementById('postal_code').value))
	{
	alert('Please enter postal code');
	document.frmOrder.postal_code.focus();
	return false;
	}
	if(isEmpty(document.getElementById('order_Country').value))
	{
	alert('Please enter country name');
	document.frmOrder.order_Country.focus();
	return false;
	}
	if(isEmpty(document.getElementById('order_mail').value))
	{
	alert('Please enter your email address');
	document.frmOrder.order_mail.focus();
	return false ;
	}
	if(!IsValidEMail(document.getElementById('order_mail').value))
	 {
		alert('Please enter a valid e-mail address');
		document.frmOrder.order_mail.focus();
		return false ;
	 }
	if(isEmpty(document.getElementById('order_tel').value))
	{
	alert('Please enter phone number');
	document.frmOrder.order_tel.focus();
	return false ;
	}
	else if(!numericCheck(telephoneValue))
	{
		alert('Please enter a valid phone number');
		document.frmOrder.order_tel.focus();
		return false;
	}
}

///////////		NUMERIC CHECK FOR RETAIL PRICE	AND DISCOUNTED PRICE	/////////////////
function numericCheck(elem)
{
	var numericExpression =/^[0-9]+$/;
	if(elem.match(numericExpression))
	{
	return true ;
	}
	else
	{
	return false;
	}
}

function IsValidEMail(strValue)
{
	nNoOfArguments = IsValidEMail.arguments.length;
	//if no parameter is supplied
	if(nNoOfArguments < 1)
	{
		return false;
	}	
	
	var strVal	= new String(strValue);
	var bReturn1 = false;
	var bReturn2 = false;
	var bReturn3 = false;
	var bReturn4 = false;
	var bReturn5 = false;
	var bReturn5 = false;
	
	//if '@' comes after first character then true
	bReturn1	=	(strValue.indexOf("@") > 0);							
	
	//if '.' comes after first character then true
	bReturn2	=	(strValue.indexOf(".") > 0);							
	
	//if single '@' exist in string then true
	bReturn3	=	(strValue.indexOf("@") == strValue.lastIndexOf("@"));	
	
	//if '.' exist after @ in string then true
	bReturn4	=	(strValue.indexOf(".",strValue.indexOf("@")) > (strValue.indexOf("@")));		
	
	//if '.' does not comes immediatly after @ then true
	bReturn5	=	(strValue.indexOf(".",strValue.indexOf("@")) != (strValue.indexOf("@")+1));		
	
	//if '.' does not comes immediatly before @ then true
	bReturn6	=	(strValue.lastIndexOf(".",strValue.indexOf("@")) != (strValue.indexOf("@")-1)); 
	
	//if all values are true return true else false.
	return(bReturn1 && bReturn2 && bReturn3 && bReturn4 && bReturn5 && bReturn6);
}
/////////// 	VALIDATE CHECK OUT 	///////////
function validateCheckOut()
{
	var shippingContactValue = document.getElementById('shippingContactNumber').value;
	var billingContactValue = document.getElementById('billingContactNumber').value;
	if(isEmpty(document.getElementById('shippingFirstName').value))
	{
	alert('You must fill in all fields correctly');
	document.frmCheckout.shippingFirstName.focus();
	return false ;
	}
	if(isEmpty(document.getElementById('shippingLastName').value))
	{
	alert('You must fill in all fields correctly');
	document.frmCheckout.shippingLastName.focus();
	return false ;
	}
	if(isEmpty(document.getElementById('shippingAddress').value))
	{
	alert('You must fill in all fields correctly');
	document.frmCheckout.shippingAddress.focus();
	return false ;
	}
	if(isEmpty(document.getElementById('shippingPostCode').value))
	{
	alert('You must fill in all fields correctly');
	document.frmCheckout.shippingPostCode.focus();
	return false;
	}
	if(isEmpty(document.getElementById('shippingCity').value))
	{
	alert('You must fill in all fields correctly');
	document.frmCheckout.shippingCity.focus();
	return false;
	}
	if(isEmpty(document.getElementById('shippingCountry').value))
	{
	alert('You must fill in all fields correctly');
	document.frmCheckout.shippingCountry.focus();
	return false;
	}
	if(isEmpty(document.getElementById('shippingContactNumber').value))
	{
	alert('You must fill in all fields correctly');
	document.frmCheckout.shippingContactNumber.focus();
	return false;
	}
	else if(!numericCheck(shippingContactValue))
	{
		alert('Please enter a valid shipping phone number');
		document.frmCheckout.shippingContactNumber.focus();
		return false;
	}
	if(isEmpty(document.getElementById('shippingEmail').value))
	{
	alert('You must fill in all fields correctly');
	document.frmCheckout.shippingEmail.focus();
	return false;
	}
	if(!IsValidEMail(document.getElementById('shippingEmail').value))
	 {
		alert('Please enter a valid e-mail address');
		document.frmCheckout.shippingEmail.focus();
		return false ;
	 }
	
	if(isEmpty(document.getElementById('billingFirstName').value))
	{
	alert('You must fill in all fields correctly');
	document.frmCheckout.billingFirstName.focus();
	return false ;
	}
	if(isEmpty(document.getElementById('billingLastName').value))
	{
	alert('You must fill in all fields correctly');
	document.frmCheckout.billingLastName.focus();
	return false ;
	}
	if(isEmpty(document.getElementById('billingAddress').value))
	{
	alert('You must fill in all fields correctly');
	document.frmCheckout.billingAddress.focus();
	return false ;
	}
	if(isEmpty(document.getElementById('billingPostCode').value))
	{
	alert('You must fill in all fields correctly');
	document.frmCheckout.billingPostCode.focus();
	return false ;
	}
	if(isEmpty(document.getElementById('billingCity').value))
	{
	alert('You must fill in all fields correctly');
	document.frmCheckout.billingCity.focus();
	return false ;
	}
	if(isEmpty(document.getElementById('billingCountry').value))
	{
	alert('You must fill in all fields correctly');
	document.frmCheckout.billingCountry.focus();
	return false ;
	}
	if(isEmpty(document.getElementById('billingContactNumber').value))
	{
	alert('You must fill in all fields correctly');
	document.frmCheckout.billingContactNumber.focus();
	return false ;
	}
	else if(!numericCheck(billingContactValue))
	{
		alert('Please enter a valid billing phone number');
		document.frmCheckout.billingContactNumber.focus();
		return false;
	}
	if(isEmpty(document.getElementById('billingEmail').value))
	{
	alert('You must fill in all fields correctly');
	document.frmCheckout.billingEmail.focus();
	return false;
	}
	if(!IsValidEMail(document.getElementById('billingEmail').value))
	 {
		alert('Please enter a valid e-mail address');
		document.frmCheckout.billingEmail.focus();
		return false ;
	 }
}

function copyShippingInfo()
{
	if(document.getElementById('check').checked == true)
	{
	document.getElementById('billingFirstName').value = document.getElementById('shippingFirstName').value;
	document.getElementById('billingLastName').value = document.getElementById('shippingLastName').value;
	document.getElementById('billingAddress').value = document.getElementById('shippingAddress').value;
	document.getElementById('billingPostCode').value = document.getElementById('shippingPostCode').value;
	document.getElementById('billingCity').value = document.getElementById('shippingCity').value;
	document.getElementById('billingCountry').value = document.getElementById('shippingCountry').value;
	document.getElementById('billingContactNumber').value = document.getElementById('shippingContactNumber').value;
	document.getElementById('billingEmail').value = document.getElementById('shippingEmail').value;
 }
 else
 {
	 document.getElementById('billingFirstName').value = "";
	document.getElementById('billingLastName').value = "";
	document.getElementById('billingAddress').value = "";
	document.getElementById('billingPostCode').value = "";
	document.getElementById('billingCity').value = "";
	document.getElementById('billingCountry').value = "";
	document.getElementById('billingContactNumber').value = "";
	document.getElementById('billingEmail').value = "";
 }
}
function quantityCheck()
{
	var quantityValue = document.getElementById('hiddenQuantity1').value;
	if(isEmpty(quantityValue))
	{
		alert('Please enter quantity');
		return false;
	}
	else if(!numericCheck(quantityValue))
	{
		alert('Please enter valid quantity');
		return false;
	}
	if(quantityValue<=0)
	{
		alert("Quantity should be more than zero");
		return false;
	}
}