<!--
//======================================================================
function isEmpty(s)
//======================================================================
{   return ((s == null) || (s.length == 0))
}
//======================================================================
function isWhitespace (s)
//======================================================================
// Search through string's characters one by one
// until we find a non-whitespace character.
// When we do, return false; if we don't, return true.
//======================================================================
{   var i;
    var whitespace = " \t\n\r";
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    // All characters are whitespace.
    return true;
}
//======================================================================
function isEmail (s)
//======================================================================
// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
// If emptyOK is false (or any value other than true), 
//      the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//======================================================================
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return false;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(s))) 
       return false;
    else
       return true;
}
//======================================================================
function submit_checkout()
//======================================================================
{
 var form_errors='';

 if (document.form_checkout.checkout_stage.value==1){
	if (!isEmpty(document.form_checkout.new_email.value) && !isEmpty(document.form_checkout.exist_email.value)){
		form_errors='Enter EMAIL ADDRESS in either New Customer OR Existing Customer\n'+form_errors;
	}else{
		if (isEmpty(document.form_checkout.new_email.value) && isEmpty(document.form_checkout.exist_email.value)){
			form_errors='EMAIL ADDRESS not entered\n'+form_errors;
	 	}else{
			if (!isEmpty(document.form_checkout.exist_email.value)){
				if (isEmpty(document.form_checkout.exist_pwd.value)){
					form_errors='PASSWORD not entered\n'+form_errors;
					document.form_checkout.exist_pwd.focus();
				}
			}else{
				if (!isEmpty(document.form_checkout.exist_pwd.value)){
					form_errors='PASSWORD not required for new customers\n'+form_errors;
					document.form_checkout.exist_pwd.focus();
				}
			}
			if (!isEmail(document.form_checkout.new_email.value,true)){
				form_errors='EMAIL is invalid\n'+form_errors;
				document.form_checkout.new_email.focus();
			}
			if (!isEmail(document.form_checkout.exist_email.value,true)){
				form_errors='EMAIL is invalid\n'+form_errors;
				document.form_checkout.exist_email.focus();
			}
		}
	 }
 }
 if (document.form_checkout.checkout_stage.value==2){
	if (document.form_checkout.del_name.value.toLowerCase()!="collect"){
		if (isEmpty(document.form_checkout.del_postcode.value)){
			form_errors='POSTCODE not entered\n'+form_errors;
			document.form_checkout.del_postcode.focus();
		}
		if (isEmpty(document.form_checkout.del_addr_4.value)){
			form_errors='COUNTY not entered\n'+form_errors;
			document.form_checkout.del_addr_4.focus();
		}
		if (isEmpty(document.form_checkout.del_addr_3.value)){
			form_errors='TOWN/CITY not entered\n'+form_errors;
			document.form_checkout.del_addr_3.focus();
		}
		if (isEmpty(document.form_checkout.del_addr_1.value)){
			form_errors='ADDRESS LINE 1 not entered\n'+form_errors;
			document.form_checkout.del_addr_1.focus();
		}
		if (isEmpty(document.form_checkout.del_name.value)){
			form_errors='NAME not entered\n'+form_errors;
			document.form_checkout.del_name.focus();
		}
	}
 }
	
 if (form_errors > '') {
   alert (form_errors);
   return false;
 }else{
   return true;
 }
}

//======================================================================
// -->
