function Validator(theForm, checknewaccount)

{

///////////////////////////////////////////////////////////////////////////////////////////if user wants to create an account
if (checknewaccount == 1) {

//////////if they change there mind
if (theForm.createnewaccount.checked==true) {


/* if new account check passwords length and matchness */

if (theForm.accpassword.value.length >= 0) {

/////check length of passwords
	if (theForm.accpassword.value.length < 6) {
	
	alert('Passwords should be at least 6 characters long.');
	
	theForm.accpassword.focus();
	
	 return (false);
	
	}

	if (theForm.conaccpassword.value.length == 0) {
	
	alert('Please confirm your password.');
	
	theForm.conaccpassword.focus();
	
	 return (false);
	
	}
	
	if (theForm.accpassword.value != theForm.conaccpassword.value) {
	
	alert('Your password and confirmation does not match, please re-enter');
	
	/////clear fileds
	theForm.accpassword.value="";
	theForm.conaccpassword.value="";
	
	theForm.accpassword.focus();
	
	 return (false);
	
	}

}
}
}
   
   /* check for title */
    if (theForm.title.value.length < 1)

  {

    alert("Please add a title!");

    theForm.title.focus();

    return (false);

  }
   
   

   /* Check First Name */

  if (theForm.name.value.length < 1)

  {

    alert("You cannot leave your Name Blank!");

    theForm.name.focus();

    return (false);

  }

  

   /* Address 1 */

  if (theForm.address1.value.length < 1)

  {

    alert("You cannot leave the address blank");

    theForm.address1.focus();

    return (false);

  }  
  
  
    /* Address 2 */

  if (theForm.address2.value.length < 1)

  {

    alert("You cannot leave the address blank");

    theForm.address2.focus();

    return (false);

  }  
  
  
    /* PostCode */

  if (theForm.postcode.value.length < 1)

  {

    alert("You cannot leave the postcode blank");

    theForm.postcode.focus();

    return (false);

  }  
  
   /* Check Country */

  if (theForm.country.value == "** Select Country **")

  {

    alert("You must select a Country");

    theForm.country.focus();

    return (false);

  }



 /* Email check */

 

 {

	var emailID=document.checkout.userEmail

	

	if ((emailID.value==null)||(emailID.value=="")){

		alert("Please Enter your Email Address")

		emailID.focus()

		return false

	}

	if (echeck(emailID.value)==false){

		//emailID.value=""

		emailID.focus()

		return false

	}

 }


   /* Tel */

  if (theForm.telephone.value.length < 1)

  {

    alert("You cannot leave the Telephone blank");

    theForm.telephone.focus();

    return (false);

  }  
  
  

 /* Check Tel is a number */

	if ( (parseFloat(theForm.telephone.value) != theForm.telephone.value) ||

             theForm.telephone.value.length < 0 ||

             theForm.telephone.value.length > 255) {

		alert("The phone number must be a number");

		theForm.telephone.focus();

		theForm.telephone.select();

		return (false);

	}



//////////////////////////////////////////////////////////////////////////delivery check

 /* Check delivery Name */

  if (theForm.deliveryName.value.length < 1)

  {

    alert("You cannot leave your Delivery Name blank!");

    theForm.deliveryName.focus();

    return (false);

  }
  
  
  
   /* Delivery Address 1 */

  if (theForm.deliveryAddress1.value.length < 1)

  {

    alert("You cannot leave the delivery address blank");

    theForm.deliveryAddress1.focus();

    return (false);

  }
  
  
    /* Delivery Address 2 */

  if (theForm.deliveryAddress2.value.length < 1)

  {

    alert("You cannot leave the delivery address blank");

    theForm.deliveryAddress2.focus();

    return (false);

  }
  
  
  
  /* delivery PostCode */

  if (theForm.deliveryPostcode.value.length < 1)

  {

    alert("You cannot leave the delivery postcode blank");

    theForm.deliveryPostcode.focus();

    return (false);

  }
  
   /* Check Country */

  if (theForm.deliveryCountry.value == "** Select Country **")

  {

    alert("You must select a delivery Country");

    theForm.deliveryCountry.focus();

    return (false);

  }
  
    
  
  /* delivery Tel */

  if (theForm.deliveryPhone.value.length < 1)

  {

    alert("You cannot leave the delivery Telephone blank");

    theForm.deliveryPhone.focus();

    return (false);

  }
  
  
  
 /* Check delivery Tel is a number */

	if ( (parseFloat(theForm.deliveryPhone.value) != theForm.deliveryPhone.value) ||

             theForm.deliveryPhone.value.length < 0 ||

             theForm.deliveryPhone.value.length > 255) {

		alert("The delivery phone number must be a number");

		theForm.deliveryPhone.focus();

		theForm.deliveryPhone.select();

		return (false);

	}

 


/* TERMS */


if (theForm.terms.checked==false) 
{

	alert("Please confirm you have read the Terms & Conditions");
	
	return (false);

}


 }





function echeck(str) {



		var at="@"

		var dot="."

		var lat=str.indexOf(at)

		var lstr=str.length

		var ldot=str.indexOf(dot)

		if (str.indexOf(at)==-1){

		   alert("Invalid E-mail ID")

		   return false

		}



		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

		   alert("Invalid E-mail address")

		   return false

		}



		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

		    alert("Invalid E-mail  address")

		    return false

		}



		 if (str.indexOf(at,(lat+1))!=-1){

		    alert("Invalid E-mail address")

		    return false

		 }



		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

		    alert("Invalid E-mail address")

		    return false

		 }



		 if (str.indexOf(dot,(lat+2))==-1){

		    alert("Invalid E-mail address")

		    return false

		 }

		

		 if (str.indexOf(" ")!=-1){

		    alert("Invalid E-mail address")

		    return false

		 }



 		 return true					

	}

////////copy your details into delivery details

function copyDetails() {

/////do name
document.checkout.deliveryName.value=document.checkout.name.value;
/////do address1
document.checkout.deliveryAddress1.value=document.checkout.address1.value;
/////do address2
document.checkout.deliveryAddress2.value=document.checkout.address2.value;
//////do postcode
document.checkout.deliveryPostcode.value=document.checkout.postcode.value;
//////do phone
document.checkout.deliveryPhone.value=document.checkout.telephone.value;
////do country
var selector = document.checkout.country;
var selectorOptons = selector.options[selector.selectedIndex].value;
var id = "dc" + selectorOptons;
////alert(id);
document.getElementById(id).selected=true;

}

function copyDetails1(code) {

/////do name
document.checkout.deliveryName.value=document.checkout.name.value;
/////do address1
document.checkout.deliveryAddress1.value=document.checkout.address1.value;
/////do address2
document.checkout.deliveryAddress2.value=document.checkout.address2.value;
//////do postcode
document.checkout.deliveryPostcode.value=document.checkout.postcode.value;
//////do phone
document.checkout.deliveryPhone.value=document.checkout.telephone.value;
////do country
var id = "dc" + code;
////alert(id);
document.getElementById(id).selected=true;

}


//////////validate login
function validateLogin(thisForm) {

if (thisForm.accountHolderEmail.value.length < 1)

  {

    alert("Email address required!");

    thisForm.accountHolderEmail.focus();

    return (false);

  }
  


if (thisForm.accountHolderPassword.value.length < 1)

  {

    alert("Password required!");

    thisForm.accountHolderPassword.focus();

    return (false);

  }


}

function validateLoginSubmit() {

if (document.login.accountHolderEmail.value.length < 1)

  {

    alert("Email address required!");

    document.login.accountHolderEmail.focus();

    return (false);

  }
  


if (document.login.accountHolderPassword.value.length < 1)

  {

    alert("Password required!");

    document.login.accountHolderPassword.focus();

    return (false);

  }


}


function validateFpasswordSubmit() {

if (document.login.accountHolderEmail.value.length < 1)

  {

    alert("Email address required!");

    document.login.accountHolderEmail.focus();

    return (false);

  }
  

}

function ValidateAccount(theForm, checknewaccount)

{

///////////////////////////////////////////////////////////////////////////////////////////if user wants to create an account
if (checknewaccount == 1) {

//////////if they change there mind
if (theForm.createnewaccount.checked==true) {


/* if new account check passwords length and matchness */

if (theForm.accpassword.value.length >= 0) {

/////check length of passwords
	if (theForm.accpassword.value.length < 6) {
	
	alert('Passwords should be at least 6 characters long.');
	
	theForm.accpassword.focus();
	
	 return (false);
	
	}

	if (theForm.conaccpassword.value.length == 0) {
	
	alert('Please confirm your password.');
	
	theForm.conaccpassword.focus();
	
	 return (false);
	
	}
	
	if (theForm.accpassword.value != theForm.conaccpassword.value) {
	
	alert('Your password and confirmation does not match, please re-enter');
	
	/////clear fileds
	theForm.accpassword.value="";
	theForm.conaccpassword.value="";
	
	theForm.accpassword.focus();
	
	 return (false);
	
	}

}
}
}
   
   /* check for title */
    if (theForm.title.value.length < 1)

  {

    alert("Please add a title!");

    theForm.title.focus();

    return (false);

  }
   
   

   /* Check First Name */

  if (theForm.name.value.length < 1)

  {

    alert("You cannot leave your Name Blank!");

    theForm.name.focus();

    return (false);

  }

  

   /* Address 1 */

  if (theForm.address1.value.length < 1)

  {

    alert("You cannot leave the address blank");

    theForm.address1.focus();

    return (false);

  }  
  
  
    /* Address 2 */

  if (theForm.address2.value.length < 1)

  {

    alert("You cannot leave the address blank");

    theForm.address2.focus();

    return (false);

  }  
  
  
    /* PostCode */

  if (theForm.postcode.value.length < 1)

  {

    alert("You cannot leave the postcode blank");

    theForm.postcode.focus();

    return (false);

  }  
  
  
   /* Check Country */

  if (theForm.country.value == "** Select Country **")

  {

    alert("You must select a Country");

    theForm.country.focus();

    return (false);

  }



 /* Email check */

 

 {

	var emailID=document.checkout.userEmail

	

	if ((emailID.value==null)||(emailID.value=="")){

		alert("Please Enter your Email Address")

		emailID.focus()

		return false

	}

	if (echeck(emailID.value)==false){

		//emailID.value=""

		emailID.focus()

		return false

	}

 }


   /* Tel */

  if (theForm.telephone.value.length < 1)

  {

    alert("You cannot leave the Telephone blank");

    theForm.telephone.focus();

    return (false);

  }  
  
  

 /* Check Tel is a number */

	if ( (parseFloat(theForm.telephone.value) != theForm.telephone.value) ||

             theForm.telephone.value.length < 0 ||

             theForm.telephone.value.length > 255) {

		alert("The phone number must be a number");

		theForm.telephone.focus();

		theForm.telephone.select();

		return (false);

	}


/* TERMS */


if (theForm.terms.checked==false) 
{

	alert("Please confirm you have read the Terms & Conditions");
	
	return (false);

}



}





