function checkCouponCode()
{
   	if(document.getElementById('checkCoupon').checked == true)
	{
	    if(isEmpty(document.getElementById('couponCode').value))
		{
			alert('Please enter coupon code to validate');
			document.frmCoupon.couponCode.focus();
			return false ;
		}
		document.getElementById('frmCoupon').submit();
	}
}
function checkPaymentMethod()
{
	/*if(document.getElementById('issuer4').checked == true)
	{
		if(isEmpty(document.getElementById('issuer_directebanking').value))
		{
			alert('Please choose a bank');
			document.frmCheckout2.issuer_directebanking.focus();
			return false ;
		}	
	}*/
	if(document.getElementById('issuer6').checked == true)
	{
		if(isEmpty(document.getElementById('issuer_ideal').value))
		{
			alert('Please choose a bank');
			document.frmCheckout2.issuer_ideal.focus();
			return false ;
		}	
	}
}
function setCookie(name,value)
{
	var expdate=new Date();
	expdate.setTime(expdate.getTime()+(30*1000));
	document.cookie = name + "=" + value + ";expires="+expdate.toGMTString();
	window.location.reload();
} 
function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function setLanguage(lang)
	{
		var expdate=new Date();
		expdate.setDate(expdate.getDate()+365);
		document.cookie="language="+escape(lang)+";expires="+expdate.toGMTString();
	}
	function setLanguageHome(lang)
	{
		var expdate=new Date();
		expdate.setDate(expdate.getDate()+365);
		document.cookie="language="+escape(lang)+";expires="+expdate.toGMTString();
	}
///////////		VALIDATION OF DELETE	/////////////////
function validateDelete(alerts)
{
	var r=confirm(alerts);
	if (r==true)
	{
	 return true;
	}
    else
    {
	  return false;
    }
}

///////////		CHECKS IF EMPTY OR NOT	///////////////////
function isEmpty(elementValue)
{
	if( (elementValue=="") || (elementValue==null) )
	{
		return true;	//if empty
	}
	else
	{
		return false;	//if not empty
	}
}

/////////// 	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 ;
	 }
}


///////////		NUMERIC CHECK FOR RETAIL PRICE	AND DISCOUNTED PRICE	/////////////////
function numericCheck(elem)
{
	var numericExpression =/^[0-9]+$/;
	if(elem.match(numericExpression))
	{
	return true ;
	}
	else
	{
	return false;
	}
}
////////// VIEW CART QUANTITY CHECK	/////////////
function quantityCheck(quantityId)
{
	var quantityValue = document.getElementById(quantityId).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;
	}
	document.getElementById('frmOrderQuantity').action = 'orderHandler.php?msg=updtCart&orderQuantity='+quantityValue+'&productId='+quantityId+'';
	document.frmOrderQuantity.submit();
	//window.location='orderHandler.php?msg=updtCart&orderQuantity='+quantityValue+'&productId='+quantityId;
}

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);
}

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 makeEnable()
{
	var x=document.getElementById("issuer_directebanking");
    x.disabled=false;
}
function makeDisable()
{
    var x=document.getElementById("issuer_directebanking")
    x.disabled=true
}