function numeric(v){ 
  	v = Math.round(parseFloat(v) * 100) / 100
	v = v.toString() 
	var p = v.indexOf('.') 
	
	if(p == -1) 
		return v + '.00' 
	
	p = v.length - p 
	
	if(p == 2) 
		return v + '0' 

return v 
}


function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}

function isEmailAddr(s) {
	var rv = false;
	if ((s == null) || (s.length == 0)) rv = false;
	else {
		var reEmail = /([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		rv = reEmail.test(s);
	}
	if (rv) return rv;
	else {
		return false;
	}
}


function checkoutValidate(theForm)
{
	if (theForm.firstName.value == "") {
		alert("Please enter your first name");
		theForm.firstName.focus();
		returnObjById("starFName").style.color = "red"
		return false;
	}
	else
	{
		returnObjById("starFName").style.color = ""
	}
	
	if (theForm.lastName.value == "") {
		alert("Please enter your last name");
		theForm.lastName.focus();
		returnObjById("starLName").style.color = "red"
		return false;
	}
	else
	{	
		returnObjById("starLName").style.color = ""
	}
	
	if(theForm.emailAddress.value == "")
	{
		alert("Please enter your email address");
		theForm.emailAddress.focus();
		returnObjById("starEmail").style.color = "red"
		return false;
	}
	else
	{
		returnObjById("starEmail").style.color = ""
	}
	
	if (!isEmailAddr(theForm.emailAddress.value)) {
		alert("Please enter your email address correctly");
		theForm.emailAddress.focus();
		returnObjById("starEmail").style.color = "red"
		return false;
	}
	else
	{
		returnObjById("starEmail").style.color = ""
	}

	if (theForm.contactPhone.value == "") {
		alert("Please enter your contact phone number");
		theForm.contactPhone.focus();
		returnObjById("starPhone").style.color = "red"
		return false;
	}
	else
	{
		returnObjById("starPhone").style.color = ""
	}

	if (theForm.streetNo.value == "") {
		alert("Please enter your street number");
		theForm.streetNo.focus();
		returnObjById("starStreetNo").style.color = "red"
		return false;
	}
	else
	{
		returnObjById("starStreetNo").style.color = ""
	}

	if (theForm.city.value == "") {
		alert("Please enter your city");
		theForm.city.focus();
		returnObjById("starCity").style.color = "red"
		return false;
	}
	else
	{
		returnObjById("starCity").style.color = ""
	}

	if (theForm.zip.value == "") {
		alert("Please enter your postal code");
		theForm.zip.focus();
		returnObjById("starZip").style.color = "red"
		return false;
	}
	else
	{
		returnObjById("starZip").style.color = ""
	}

	
	if (theForm.pstreetNo.value != "" || theForm.pcity.value != "" || theForm.pzip.value !="" ) {
		if(String(theForm.pstreetNo.value).replace(/^\s*|\s*$/g,"") == "")
		{
			alert("Please enter your street number for delivery address");
			theForm.pstreetNo.focus();
			returnObjById("starPStreetNo").style.color = "red"
			return false;
		}
		else
		{
			returnObjById("starPStreetNo").style.color = ""
		}

		
		if(theForm.pcity.value == "")
		{
			alert("Please enter your city for delivery address");
			theForm.pcity.focus();
			returnObjById("starPCity").style.color = "red"
			return false;
		}
		else
		{
			returnObjById("starPCity").style.color = ""
		}		
		
		if(theForm.pzip.value == "")
		{
			alert("Please enter your postal code for delivery address");
			theForm.pzip.focus();
			returnObjById("starPZip").style.color = "red"
			return false;
		}
		else
		{
			returnObjById("starPZip").style.color = ""
		}

	}
if(!theForm.acceptTerms.checked)
	{
		alert("You need to accept the Safety instructions to process your order");
		theForm.acceptTerms.focus();
		return false;
	}

	
	return true;	

}

function bartercard(f){
	
	if(f.bname.value == ""){
		alert("Please enter the name on the Bartercard card.")
		f.bname.focus()
		return false
	}
	
	if(f.bnumber.value == "" || f.bnumber.value.length < 16){
		alert("Please enter your 16 digital Bartercard number.")
		f.bnumber.focus()
		return false
	}

	
	return true
}

function validation(theForm){
	if (theForm.first_name.value == ""){
    	alert("Please enter your first name.");
    	theForm.first_name.focus();
    	return (false);
  	}
	if (theForm.last_name.value == ""){
    	alert("Please enter your last name.");
    	theForm.last_name.focus();
    	return (false);
  	}
  	if (!isEmailAddr(theForm.email.value)){
    	alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    	theForm.email.focus();
    	return (false);
 	}
	if (!IsNumeric(theForm.address_street_number.value)){
    	alert("Please enter your street number.");
    	theForm.address_street_number.focus();
    	return (false);
  	}
	if (theForm.address_street_name.value == ""){
    	alert("Please enter your street name.");
    	theForm.address_street_name.focus();
    	return (false);
  	}
	if (theForm.address_suburb.value == ""){
    	alert("Please enter your suburb.");
    	theForm.address_suburb.focus();
    	return (false);
  	}
	if (theForm.address_region.value == ""){
    	alert("Please enter your region.");
    	theForm.address_region.focus();
    	return (false);
  	}
	if (!IsNumeric(theForm.address_postcode.value)){
    	alert("Please enter your postcode.");
    	theForm.address_postcode.focus();
    	return (false);
  	}
	return (true);
}