// ----------------------------------------------------------------------
// Simple routines to quickly pick up obvious typos.
// All validation routines return true if executed by an older browser:
// in this case validation must be left to the server.
//
// ----------------------------------------------------------------------

var nbsp = 160;		// non-breaking space char
var node_text = 3;	// DOM text node-type
var emptyString = /^\s*$/ ;
var global_valfield;	// retain valfield for timer thread

// --------------------------------------------
//                  trim
// Trim leading/trailing whitespace off string
// --------------------------------------------

function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '');
}


// --------------------------------------------
//                  setfocus
// Delayed focus setting to get around IE bug
// --------------------------------------------

function setFocusDelayed()
{
  global_valfield.focus();
}

function setfocus(valfield)
{
  // save valfield in global variable so value retained when routine exits
  global_valfield = valfield;
  setTimeout( 'setFocusDelayed()', 100 );
}


// --------------------------------------------
//                  msg
// Display warn/error message in HTML element.
// commonCheck routine must have previously been called
// --------------------------------------------

function msg(fld,     // id of element to display message in
             msgtype, // class to give element ("warn" or "error")
             message) // string to display
{
  // setting an empty string can give problems if later set to a
  // non-empty string, so ensure a space present. (For Mozilla and Opera one could
  // simply use a space, but IE demands something more, like a non-breaking space.)
  var dispmessage;
  if (emptyString.test(message))
    dispmessage = String.fromCharCode(nbsp);
  else
    dispmessage = message;

  var elem = document.getElementById(fld);
  elem.firstChild.nodeValue = dispmessage;

  elem.className = msgtype;   // set the CSS class to adjust appearance of message
}

// --------------------------------------------
//            commonCheck
// Common code for all validation routines to:
// (a) check for older / less-equipped browsers
// (b) check if empty fields are required
// Returns true (validation passed),
//         false (validation failed) or
//         proceed (don't know yet)
// --------------------------------------------

var proceed = 2;

function commonCheck    (valfield,   // element to be validated
                         infofield,  // id of element to receive info/error msg
                         required)   // true if required
{
  if (!document.getElementById)
    return true;  // not available on this browser - leave validation to the server
  var elem = document.getElementById(infofield);
  if (!elem.firstChild) return true;  // not available on this browser
  if (elem.firstChild.nodeType != node_text) return true;  // infofield is wrong type of node

  if (emptyString.test(valfield.value)) {
    if (required) {
      msg (infofield, "error", "ERROR: required");
      setfocus(valfield);
      return false;
    }
    else {
      msg (infofield, "warn", "");   // OK
      return true;
    }
  }
  return proceed;
}

function commonCheckContext    (valfield,   // element to be validated
								 infofield,  // id of element to receive info/error msg
								 required,   // true if required
								 stype,		 // form type object
								 stypeval)   // form type text
{
  var index = stype.selectedIndex;
  var text = stype.options[index].text;
  var sDiv = text.substring(0,3);

  if (!(stypeval == trim(sDiv)))
  {
  	return true;
  }

  if (!document.getElementById)
    return true;  // not available on this browser - leave validation to the server
  var elem = document.getElementById(infofield);
  if (!elem.firstChild) return true;  // not available on this browser
  if (elem.firstChild.nodeType != node_text) return true;  // infofield is wrong type of node

  if (emptyString.test(valfield.value)) {
    if (required) {
      msg (infofield, "error", "ERROR: required");
      setfocus(valfield);
      return false;
    }
    else {
      msg (infofield, "warn", "");   // OK
      return true;
    }
  }
  return proceed;
}

// --------------------------------------------
//            validateMinLength
// Validate minimum length
// Returns true if so
// --------------------------------------------

function validateMinLength(valfield,   // element to be validated
                         infofield, // id of element to receive info/error msg
                         required,  // true if required
                         length) // minlength in integers 
{

  var stat = commonCheck (valfield, infofield, required);
  if (stat != proceed) return false;

  var num = valfield.value.length;

  if (num < length) {
    msg (infofield, "error", "ERROR: Please enter correct number of digits");
    setfocus(valfield);
    return false;
  }

  msg (infofield, "warn", "");

  return true;
}

// --------------------------------------------
//            validateMaxLength
// Validate maximum length
// Returns true if so
// --------------------------------------------

function validateMaxLength(valfield,   // element to be validated
                         infofield, // id of element to receive info/error msg
                         required,  // true if required
                         length) // minlength in integers 
{

  var stat = commonCheck (valfield, infofield, required);
  if (stat != proceed) return false;

  var num = valfield.value.length;

  if (num > length) {
    msg (infofield, "error", "ERROR: Please limit the length of this field to " + (length-1000) + " characters (including spaces)");
    setfocus(valfield);
    return false;
  }

  msg (infofield, "warn", "");

  return true;
}

// --------------------------------------------
//            validateCAPostCodeText
// Validate minimum length
// Returns true if so
// --------------------------------------------

function validateCAPostCodeText(valfield,   // element to be validated
                         infofield, // id of element to receive info/error msg
                         required,  // true if required
                         length) // minlength in integers 
{

  var stat = commonCheck (valfield, infofield, required);
  if (stat != proceed) return false;
  
  if (!validateCAPostCode(valfield.value)) {
  	msg (infofield, "error", "ERROR: Please enter a valid Canadian postal code");
  	setfocus(valfield);
  	return false;
  }

  msg (infofield, "warn", "");

  return true;
}

// --------------------------------------------
//            validateSelect
// Validate if a select form element
// Returns true if so
// --------------------------------------------

function validateSelect(valfield,   // element to be validated
                         infofield ) // id of element to receive info/error msg
{

  var index = valfield.selectedIndex;

  if (index == 0) {
    msg (infofield, "error", "ERROR: Please select a valid value from the list");
    setfocus(valfield);
    return false;
  }

  msg (infofield, "warn", "");

  return true;
}

// --------------------------------------------
//            validateRadio
// Validate if a radio group element
// Returns true if so
// --------------------------------------------

function validateRadio(valfield,   // element to be validated
                         infofield,  // id of element to receive info/error msg
                         newMsg) // custom Message
{

  var index = valfield.selectedIndex;

  if (!isChecked(valfield)) {
    msg (infofield, "error", "ERROR: " + newMsg);
    return false;
  }

  msg (infofield, "warn", "");

  return true;
}

function isChecked(obj)
{
	for (i=0;i<obj.length;i++){
		if (obj[i].checked){
			return true;
		}
	}
	return false;
}

// --------------------------------------------
//            validatePresent
// Validate if something has been entered
// Returns true if so
// --------------------------------------------

function validatePresent(valfield,   // element to be validated
                         infofield ) // id of element to receive info/error msg
{
  var stat = commonCheck (valfield, infofield, true);
  if (stat != proceed) return stat;

  msg (infofield, "warn", "");
  return true;
}

// --------------------------------------------
//            validatePresentContext
// Validate if something has been entered
// Returns true if so
// --------------------------------------------

function validatePresentContext(valfield,   // element to be validated
                         infofield,  // id of element to receive info/error msg
                         stype,      // form type object
                         stypeval)   // form type value
{
  var stat = commonCheckContext (valfield, infofield, true, stype, stypeval);
  if (stat != proceed) return stat;

  msg (infofield, "warn", "");
  return true;
}

// --------------------------------------------
//               validateEmail
// Validate if e-mail address
// Returns true if so (and also if could not be executed because of old browser)
// --------------------------------------------

function validateEmail  (valfield,   // element to be validated
                         infofield,  // id of element to receive info/error msg
                         required)   // true if required
{
  var stat = commonCheck (valfield, infofield, required);
  if (stat != proceed) return stat;

  var tfld = trim(valfield.value);  // value of field with whitespace trimmed off
  var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/  ;
  if (!email.test(tfld)) {
    msg (infofield, "error", "Error: Wrong eMail");
    setfocus(valfield);
    return false;
  }

  var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/  ;
  if (!email2.test(tfld))
    msg (infofield, "warn", "Unusual e-mail address - check if correct");
  else
    msg (infofield, "warn", "");
  return true;
}

// --------------------------------------------
//            validateTelnr
// Validate telephone number
// Returns true if so (and also if could not be executed because of old browser)
// Permits spaces, hyphens, brackets and leading +
// --------------------------------------------

function validateTelnr  (valfield,   // element to be validated
                         infofield,  // id of element to receive info/error msg
                         required, // true if required
                         errmesg)   
{
  var stat = commonCheck (valfield, infofield, required);
  if (stat != proceed) return stat;

  var tfld = trim(valfield.value);  // value of field with whitespace trimmed off
  var telnr = /^\+?[0-9 ()-]+[0-9]$/  ;
  if (!telnr.test(tfld)) {
    msg (infofield, "error", "ERROR: not a valid " + errmesg + " number. Characters permitted are digits, space ()- and leading +");
    setfocus(valfield);
    return false;
  }

  var numdigits = 0;
  for (var j=0; j<tfld.length; j++)
    if (tfld.charAt(j)>='0' && tfld.charAt(j)<='9') numdigits++;

  if (numdigits<4) {
    msg (infofield, "error", "ERROR: " + numdigits + " digits - too short");
    setfocus(valfield);
    return false;
  }

  if (numdigits>14)
    msg (infofield, "warn", numdigits + " digits - check if correct");
  else {
    if (numdigits<4)
      msg (infofield, "warn", "Only " + numdigits + " digits - check if correct");
    else
      msg (infofield, "warn", "");
  }
  return true;
}

// Form specific routines here.
// Form for orders
  function validateOrderSubmit(form) {
    // Special routine to set the multipay
    if (form.multiPay.checked)
    	form.orderMultiPay.value = "Y";
    else form.orderMultiPay.value = "N";
    
    return true;
  }
  
// Form for billing.
  function validateBillingSubmit(form) {
    var errs=0;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    
    if (!validateTelnr    (form.billFax,   'inf_billFax',  false, "fax")) errs += 1;
    if (!validateTelnr    (form.billPhone,   'inf_billPhone',  false, "phone")) errs += 1;
    if (!validateEmail    (form.billEmail,   'inf_billEmail',  true)) errs += 1;
    if (!validatePresent    (form.billPostalCode,   'inf_billPostalCode',  true)) errs += 1;
    //if (!validatePresent    (form.billState,   'inf_billState',  true)) errs += 1;
    //if (!validatePresent    (form.billCountry,   'inf_billCountry',  true)) errs += 1;
    if (!validatePresent    (form.billCity,   'inf_billCity',  true)) errs += 1;
    if (!validatePresent    (form.billAddress1,   'inf_billAddress1',  true)) errs += 1;
    if (!validatePresent    (form.billLName,   'inf_billLName',  true)) errs += 1;
    if (!validatePresent (form.billFName, 'inf_billFName', true)) errs += 1;
    
    // Special routine to set the billing address
    if (form.equalShip.checked)
    	form.billEqualShip.value = "Y";
    else form.billEqualShip.value = "N";
  
    return (errs==0);
  };

// Form for shipping.
  function validateShippingSubmit(form) {
    var errs=0;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    
    if (!validatePresent    (form.shipPostalCode,   'inf_shipPostalCode',  true)) errs += 1;
    //if (!validatePresent    (form.shipState,   'inf_shipState',  true)) errs += 1;
    //if (!validatePresent    (form.shipCountry,   'inf_shipCountry',  true)) errs += 1;
    if (!validatePresent    (form.shipCity,   'inf_shipCity',  true)) errs += 1;
    if (!validatePresent    (form.shipAddress1,   'inf_shipAddress1',  true)) errs += 1;
    if (!validatePresent    (form.shipLName,   'inf_shipLName',  true)) errs += 1;
    if (!validatePresent (form.shipFName, 'inf_shipFName', true)) errs += 1;
  
    return (errs==0);
  };
  
// Form for cc.
  function validateCCSubmit(form) {
    var errs=0;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    
    //if (!validateMinLength  (form.ewayCVN,   'inf_ccCVV2',  true, 3)) errs += 1;
    if (!validatePresent    (form.ewayCardHoldersName,   'inf_ccHoldersName',  true)) errs += 1;
    if (!validateMinLength  (form.ewayCardNumber ,   'inf_ccNumber',  true, 14)) errs += 1;
    if (!validatePresent    (form.ccType, 'inf_ccType', true)) errs += 1;
  
	if (errs==0)
	{
		var total = form.ewayTotalAmount.value;
		total = total.replace('.','')

		form.ewayTotalAmount.value = total;
	}
	
    return (errs==0);
  };
  
// Form for UK billing.
  function validateUKBillingSubmit(form) {
    var errs=0;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    
    if (!validateTelnr    (form.billFax,   'inf_billFax',  false, "fax")) errs += 1;
    if (!validateTelnr    (form.billPhone,   'inf_billPhone',  false, "phone")) errs += 1;
    if (!validateEmail    (form.billEmail,   'inf_billEmail',  true)) errs += 1;
    if (!validatePresent    (form.billPostalCode,   'inf_billPostalCode',  true)) errs += 1;
    if (!validatePresent    (form.billState,   'inf_billState',  true)) errs += 1;
    //if (!validatePresent    (form.billCountry,   'inf_billCountry',  true)) errs += 1;
    if (!validatePresent    (form.billCity,   'inf_billCity',  true)) errs += 1;
    if (!validatePresent    (form.billAddress1,   'inf_billAddress1',  true)) errs += 1;
    if (!validatePresent    (form.billLName,   'inf_billLName',  true)) errs += 1;
    if (!validatePresent (form.billFName, 'inf_billFName', true)) errs += 1;
    
    // Special routine to set the billing address
    if (form.equalShip.checked)
    	form.billEqualShip.value = "Y";
    else form.billEqualShip.value = "N";
  
    return (errs==0);
  };

// Form for UK shipping.
  function validateUKShippingSubmit(form) {
    var errs=0;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    
    if (!validatePresent    (form.shipPostalCode,   'inf_shipPostalCode',  true)) errs += 1;
    if (!validatePresent    (form.shipState,   'inf_shipState',  true)) errs += 1;
    //if (!validatePresent    (form.shipCountry,   'inf_shipCountry',  true)) errs += 1;
    if (!validatePresent    (form.shipCity,   'inf_shipCity',  true)) errs += 1;
    if (!validatePresent    (form.shipAddress1,   'inf_shipAddress1',  true)) errs += 1;
    if (!validatePresent    (form.shipLName,   'inf_shipLName',  true)) errs += 1;
    if (!validatePresent (form.shipFName, 'inf_shipFName', true)) errs += 1;
  
    return (errs==0);
  };
  
// Form for UK cc.
  function validateUKCCSubmit(form) {
    var errs=0;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    
    if (!validatePresent    (form.ewayCVN,   'inf_ccCVV2',  true)) errs += 1;
    if (!validatePresent    (form.ewayCardHoldersName,   'inf_ccHoldersName',  true)) errs += 1;
    if (!validateMinLength  (form.ewayCardNumber ,   'inf_ccNumber',  true, 14)) errs += 1;
    if (!validatePresent    (form.ccType, 'inf_ccType', true)) errs += 1;
    
    if (errs==0)
	{
		var total = form.ewayTotalAmount.value;
    	total = total.replace('.','')
    
    	form.ewayTotalAmount.value = total;
	}
  
    return (errs==0);
  };
  
// ****** New Zealand **************
// Form for NZ billing.
  function validateNZBillingSubmit(form) {
    var errs=0;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    
    if (!validateTelnr    (form.billFax,   'inf_billFax',  false, "fax")) errs += 1;
    if (!validateTelnr    (form.billPhone,   'inf_billPhone',  false, "phone")) errs += 1;
    if (!validateEmail    (form.billEmail,   'inf_billEmail',  true)) errs += 1;
    if (!validatePresent    (form.billPostalCode,   'inf_billPostalCode',  true)) errs += 1;
    //if (!validatePresent    (form.billState,   'inf_billState',  true)) errs += 1;
    //if (!validatePresent    (form.billCountry,   'inf_billCountry',  true)) errs += 1;
    if (!validatePresent    (form.billCity,   'inf_billCity',  true)) errs += 1;
    if (!validatePresent    (form.billAddress1,   'inf_billAddress1',  true)) errs += 1;
    if (!validatePresent    (form.billLName,   'inf_billLName',  true)) errs += 1;
    if (!validatePresent (form.billFName, 'inf_billFName', true)) errs += 1;
    
    // Special routine to set the billing address
    if (form.equalShip.checked)
    	form.billEqualShip.value = "Y";
    else form.billEqualShip.value = "N";
  
    return (errs==0);
  };

// Form for shipping.
  function validateNZShippingSubmit(form) {
    var errs=0;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    
    if (!validatePresent    (form.shipPostalCode,   'inf_shipPostalCode',  true)) errs += 1;
    //if (!validatePresent    (form.shipState,   'inf_shipState',  true)) errs += 1;
    //if (!validatePresent    (form.shipCountry,   'inf_shipCountry',  true)) errs += 1;
    if (!validatePresent    (form.shipCity,   'inf_shipCity',  true)) errs += 1;
    if (!validatePresent    (form.shipAddress1,   'inf_shipAddress1',  true)) errs += 1;
    if (!validatePresent    (form.shipLName,   'inf_shipLName',  true)) errs += 1;
    if (!validatePresent (form.shipFName, 'inf_shipFName', true)) errs += 1;
  
    return (errs==0);
  };
  
// Form for cc.
  function validateNZCCSubmit(form) {
    var errs=0;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    
    //if (!validateMinLength  (form.ewayCVN,   'inf_ccCVV2',  true, 3)) errs += 1;
    if (!validatePresent    (form.ewayCVN,   'inf_ccCVV2',  true)) errs += 1;
    if (!validatePresent    (form.ewayCardHoldersName,   'inf_ccHoldersName',  true)) errs += 1;
    if (!validateMinLength  (form.ewayCardNumber ,   'inf_ccNumber',  true, 14)) errs += 1;
    if (!validatePresent    (form.ccType, 'inf_ccType', true)) errs += 1;
  
	if (errs==0)
	{
		var total = form.ewayTotalAmount.value;
		total = total.replace('.','')

		form.ewayTotalAmount.value = total;
	}

    return (errs==0);
  };
  
  
  //********************* United States *******************************
  
// Form for USA billing.
  function validateBillingUSASubmit(form) {
    var errs=0;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    
    if (!validateTelnr    (form.billFax,   'inf_billFax',  false, "fax")) errs += 1;
    if (!validateTelnr    (form.billPhone,   'inf_billPhone',  false, "phone")) errs += 1;
    if (!validateEmail    (form.billEmail,   'inf_billEmail',  true)) errs += 1;
    if (form.billCountry.value == 'CA') {
    	if (!validateCAPostCodeText    (form.billPostalCode,   'inf_billPostalCode',  true)) errs += 1;
    } else {
    	if (!validatePresent    (form.billPostalCode,   'inf_billPostalCode',  true)) errs += 1;
    }
    //if (!validatePresent    (form.billState,   'inf_billState',  true)) errs += 1;
    //if (!validatePresent    (form.billCountry,   'inf_billCountry',  true)) errs += 1;
    if (form.billState.value != 'CA')
    	if (!validatePresent    (form.billCity,   'inf_billCity',  true)) errs += 1;
    if (!validatePresent    (form.billAddress1,   'inf_billAddress1',  true)) errs += 1;
    if (!validatePresent    (form.billLName,   'inf_billLName',  true)) errs += 1;
    if (!validatePresent (form.billFName, 'inf_billFName', true)) errs += 1;
    
    // Special routine to set the billing address
    if (form.equalShip.checked)
    	form.billEqualShip.value = "Y";
    else form.billEqualShip.value = "N";
  
    return (errs==0);
  };
  
// Form for shipping.
  function validateShippingUSASubmit(form) {
    var errs=0;
    var sDiv;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    
    //if (!validateEmail    (form.shipEmail,   'inf_shipEmail',  true)) errs += 1;    
    if (form.shipCountry.value == 'CA') {
    	if (!validateCAPostCodeText    (form.shipPostalCode,   'inf_shipPostalCode',  true)) errs += 1;
    } else {
    	if (!validatePresent    (form.shipPostalCode,   'inf_shipPostalCode',  true)) errs += 1;
    }

    if (!validateRadio (form.shippingMethodRadio, 'inf_shipMethod', 'You need to select a shipping method')) {
    	document.getElementById("shipMethodErrorPane").style.display="";
    	errs +=1;
    } else document.getElementById("shipMethodErrorPane").style.display="none";
    
    if (form.shipState.value != 'CA')
	if (!validatePresent    (form.shipCity,   'inf_shipCity',  true)) errs += 1;
    if (!validatePresent    (form.shipAddress1,   'inf_shipAddress1',  true)) errs += 1;
    if (!validatePresent    (form.shipLName,   'inf_shipLName',  true)) errs += 1;
    if (!validatePresent (form.shipFName, 'inf_shipFName', true)) errs += 1;
  
    return (errs==0);
  };
  
// Form for cc.
  function validateCCUSASubmit(form) {
    var errs=0;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    
    if (!validateMinLength  (form.ewayCVN,   'inf_ccCVV2',  true, 3)) errs += 1;
    if (!validatePresent    (form.ewayCVN,   'inf_ccCVV2',  true)) errs += 1;
    if (!validatePresent    (form.ewayCardHoldersName,   'inf_ccHoldersName',  true)) errs += 1;
    if (!validateMinLength  (form.ewayCardNumber ,   'inf_ccNumber',  true, 14)) errs += 1;
    if (!validatePresent    (form.ccType, 'inf_ccType', true)) errs += 1;
  
	if (errs==0)
	{
		var total = form.ewayTotalAmount.value;
		total = total.replace('.','')

		form.ewayTotalAmount.value = total;
	}

    return (errs==0);
  };
  
  //********************* Registration routines *************************
  // Form for registration.
    function validateRegisterSubmit(form) {
      var errs=0;
      
      // execute all element validations in reverse order, so focus gets
      // set to the first one in error.
    
      // fields
      
      if (!validateTelnr    (form.txtPhone,   'inf_txtPhone',  true, "phone")) errs += 1;
      if (!validateEmail    (form.txtEmail,   'inf_txtEmail',  true)) errs += 1;
      if (!validatePresent    (form.txtPostcode,   'inf_txtPostcode',  true)) errs += 1;
      if (!validatePresent    (form.txtCountry,   'inf_txtCountry',  true)) errs += 1;
      if (!validatePresent    (form.txtCity,   'inf_txtCity',  true)) errs += 1;
      if (!validatePresent    (form.txtAddress1,   'inf_txtAddress1',  true)) errs += 1;
      if (!validatePresent    (form.txtLName,   'inf_txtLName',  true)) errs += 1;
      if (!validatePresent (form.txtFName, 'inf_txtFName', true)) errs += 1;
      if (!validatePresent (form.txtPassword, 'inf_txtPassword', true)) errs += 1;
      if (!validatePresent (form.txtUsername, 'inf_txtUsername', true)) errs += 1;
    
      return (errs==0);
  };
  
  // Form for login.
    function validateLoginSubmit(form) {
      var errs=0;
      
      // execute all element validations in reverse order, so focus gets
      // set to the first one in error.
    
      // fields
      
      if (!validatePresent (form.txtPassword, 'inf_txtPassword', true)) errs += 1;
      if (!validatePresent (form.txtUsername, 'inf_txtUsername', true)) errs += 1;
    
      return (errs==0);
  };
  
// Form for reship.
  function validateReshipUSASubmit(form) {
    var errs=0;
    var sDiv;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    
    if (!validateEmail    (form.shipEmail,   'inf_shipEmail',  true)) errs += 1;

    if (form.shipCountry.value == 'CA') {
    	if (!validateCAPostCodeText    (form.shipPostalCode,   'inf_shipPostalCode',  true)) errs += 1;
    } else {
    	if (!validatePresent    (form.shipPostalCode,   'inf_shipPostalCode',  true)) errs += 1;
    }

    if (!validateRadio (form.shippingMethodRadio, 'inf_shipMethod', 'You need to select a shipping method')) {
    	document.getElementById("shipMethodErrorPane").style.display="";
    	errs +=1;
    } else document.getElementById("shipMethodErrorPane").style.display="none";

    if (form.shipState.value != 'CA')
	if (!validatePresent    (form.shipCity,   'inf_shipCity',  true)) errs += 1;
    if (!validatePresent    (form.shipAddress1,   'inf_shipAddress1',  true)) errs += 1;
    if (!validatePresent    (form.shipLName,   'inf_shipLName',  true)) errs += 1;
    if (!validatePresent (form.shipFName, 'inf_shipFName', true)) errs += 1;
  
    return (errs==0);
  };
  
//********************* Join Dunstan Team routines *************************

// Form for Join the Dunstan Team form.
  function validateJoinSubmit(form) {
    var errs=0;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    
    //if (!validatePresent    (form.joinExperience,   'inf_joinExperience',  true)) errs += 1;
    if (!validateMaxLength  (form.joinExperience ,   'inf_joinExperience',  true, 5000)) errs += 1;
    if (!validateTelnr    (form.joinPhone,   'inf_joinPhone',  true, "phone")) errs += 1;
    if (!validateEmail    (form.joinEmail,   'inf_joinEmail',  true)) errs += 1;
    if (!validatePresent    (form.joinAddress1,   'inf_joinAddress1',  true)) errs += 1;
    if (!validatePresent    (form.joinLName,   'inf_joinLName',  true)) errs += 1;
    if (!validatePresent (form.joinFName, 'inf_joinFName', true)) errs += 1;
  
    return (errs==0);
  };
  
// Form for Join the Dunstan Team form.
  function validateABAJoinSubmit(form) {
    var errs=0;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    
    if (!validateMaxLength  (form.joinCredentials ,   'inf_joinCredentials',  true, 3000)) errs += 1;
    if (!validateMaxLength  (form.joinAffiliation ,   'inf_joinAffiliation',  true, 3000)) errs += 1;
    if (!validateTelnr    (form.joinPhone,   'inf_joinPhone',  true, "phone")) errs += 1;
    if (!validateEmail    (form.joinEmail,   'inf_joinEmail',  true)) errs += 1;
    if (!validatePresent    (form.joinAddress1,   'inf_joinAddress1',  true)) errs += 1;
    if (!validatePresent    (form.joinLName,   'inf_joinLName',  true)) errs += 1;
    if (!validatePresent (form.joinFName, 'inf_joinFName', true)) errs += 1;
  
    return (errs==0);
  };
  
//********************* Opt Out routines *************************

// Form for Opt Out form.
  function validateOptOutSubmit(form) {
    var errs=0;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    
    if (!validateEmail    (form.optEmail,   'inf_optEmail',  true)) errs += 1;
  
    return (errs==0);
  };
  
//********************* Task System routines *************************

// Form for Tasking System form.
  function validateTaskSubmit(form) {
    var errs=0;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields

    if (!validateSelect    (form.taskAssignedTo,   'inf_taskAssignedTo',  true)) errs += 1;
    if (!validatePresent    (form.taskDescription,   'inf_taskDescription',  true)) errs += 1;
    if (!validatePresent    (form.taskRequestor,   'inf_taskRequestor',  true)) errs += 1;
    if (!validateSelect    (form.taskCountry,   'inf_taskCountry',  true)) errs += 1;  
        
    return (errs==0);
  };
  
//********************* Manual US Form routines *************************
  
  function validateShipManualUSASubmit(form) {
    var errs=0;
    var sDiv;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    
    //if (!validateEmail    (form.shipEmail,   'inf_shipEmail',  true)) errs += 1;    
    if (form.shipCountry.value == 'CA') {
    	if (!validateCAPostCodeText    (form.shipPostalCode,   'inf_shipPostalCode',  true)) errs += 1;
    } else {
    	if (!validatePresent    (form.shipPostalCode,   'inf_shipPostalCode',  true)) errs += 1;
    }

    if (!validateSelect    (form.shippedFlag,   'inf_shippedFlag',  true)) errs += 1;
    if (!validatePresent    (form.shipCost,   'inf_shipCost',  true)) errs += 1;
    if (!validateRadio (form.shippingMethodRadio, 'inf_shipMethod', 'You need to select a shipping method')) {
    	document.getElementById("shipMethodErrorPane").style.display="";
    	errs +=1;
    } else document.getElementById("shipMethodErrorPane").style.display="none";
    
    if (form.shipState.value != 'CA')
	if (!validatePresent    (form.shipCity,   'inf_shipCity',  true)) errs += 1;
    if (!validatePresent    (form.shipAddress1,   'inf_shipAddress1',  true)) errs += 1;
    if (!validatePresent    (form.shipLName,   'inf_shipLName',  true)) errs += 1;
    if (!validatePresent (form.shipFName, 'inf_shipFName', true)) errs += 1;
  
    return (errs==0);
  };
  
// Form for manual cc.
  function validateManualCCUSASubmit(form) {
    var errs=0;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields

	if (form.ccMethod.value == 'Credit Card') { 
		if (!validateMinLength  (form.ewayCVN,   'inf_ccCVV2',  true, 3)) errs += 1;
		if (!validatePresent    (form.ewayCardHoldersName,   'inf_ccHoldersName',  true)) errs += 1;
		if (!validateMinLength  (form.ewayCardNumber ,   'inf_ccNumber',  true, 14)) errs += 1;
		if (!validateSelect    (form.ccType,   'inf_ccType',  true)) errs += 1;
	} else if (form.ccMethod.value == 'Money Order') {
		if (!validatePresent    (form.ewayMoneyOrderRef, 'inf_ewayMoneyOrderRef', true)) errs += 1;
	} else if (form.ccMethod.value == 'Cheque') {
		if (!validatePresent    (form.ewayChequeRef, 'inf_ewayChequeRef', true)) errs += 1;
	}
    if (!validateSelect    (form.ccMethod,   'inf_ccMethod',  true)) errs += 1;
    if (!validateSelect    (form.ccOrderType,   'inf_ccOrderType',  true)) errs += 1;
  
	if (errs==0)
	{
		var total = form.ewayTotalAmount.value;
		total = total.replace('.','')

		form.ewayTotalAmount.value = total;
	}

    return (errs==0);
  };
 
function validateTellAFriend(form) {
    var errs=0;

    if (!validatePresent    (form.youName,   'inf_yourName',  true)) errs += 1;
    if (!validateEmail    (form.yourEmail,   'inf_yourEmail',  true)) errs += 1;
    if (!validatePresent    (form.yourFriend,   'inf_yourFriend',  true)) errs += 1;
    if (!validateEmail    (form.yourFriendEmail,   'inf_FriendEmail',  true)) errs += 1;
    if (!validatePresent (form.message, 'inf_message', true)) errs += 1;
  
    return (errs==0);
  };
  
function validateRegister(form) {
    var errs=0;


    if (!validatePresent    (form.regFName,   'inf_regFName',  true)) errs += 1;
    if (!validatePresent    (form.regLName,   'inf_regLName',  true)) errs += 1;
    if (!validateEmail    (form.regEmail,   'inf_regEmail',  true)) errs += 1;
    if (!validateEmail    (form.regConfirmEmail,   'inf_ConEmail',  true)) errs += 1;
    if (!validatePresent    (form.regSururb,   'inf_regSuburb',  true)) errs += 1;
    if (!validatePresent (form.regState, 'inf_regState', true)) errs += 1;
    if (!validatePresent (form.regLanguage, 'inf_regLanguage', true)) errs += 1;
    if (!validatePresent (form.regHowHeardAbout, 'inf_regAboutUS', true)) errs += 1;
    if (!validatePresent (form.regRelation, 'inf_regRelation', true)) errs += 1;

    if (!validatePresent (form.regBabyFName, 'inf_babyFName', true)) errs += 1;
    if (!validatePresent (form.regBabyLName, 'inf_babyLName', true)) errs += 1;
    if (!validatePresent (form.regBabyDOB, 'inf_BirthDate', true)) errs += 1;
  
    return (errs==0);
  };
//********************* US edit form routines *************************

function validateEditBillingUSASubmit(form) {
    var errs=0;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    if (!validateTelnr    (form.billFax,   'inf_billFax',  false, "fax")) errs += 1;
    if (!validateTelnr    (form.billPhone,   'inf_billPhone',  false, "phone")) errs += 1;
    if (!validateEmail    (form.billEmail,   'inf_billEmail',  true)) errs += 1;
    if (form.billCountry.value == 'CA') {
    	if (!validateCAPostCodeText    (form.billPostalCode,   'inf_billPostalCode',  true)) errs += 1;
    } else {
    	if (!validatePresent    (form.billPostalCode,   'inf_billPostalCode',  true)) errs += 1;
    }
    if (form.billState.value != 'CA')
    	if (!validatePresent    (form.billCity,   'inf_billCity',  true)) errs += 1;
    if (!validatePresent    (form.billAddress1,   'inf_billAddress1',  true)) errs += 1;
    if (!validatePresent    (form.billLName,   'inf_billLName',  true)) errs += 1;
    if (!validatePresent (form.billFName, 'inf_billFName', true)) errs += 1;
  
    return (errs==0);
  };
  
  function validateEditShippingUSASubmit(form) {
    var errs=0;
    var sDiv;
    
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
  
    // fields
    
    //if (!validateEmail    (form.shipEmail,   'inf_shipEmail',  true)) errs += 1;    
    if (form.shipCountry.value == 'CA') {
    	if (!validateCAPostCodeText    (form.shipPostalCode,   'inf_shipPostalCode',  true)) errs += 1;
    } else {
    	if (!validatePresent    (form.shipPostalCode,   'inf_shipPostalCode',  true)) errs += 1;
    }

    if (!validateRadio (form.shippingMethodRadio, 'inf_shipMethod', 'You need to select a shipping method')) {
    	document.getElementById("shipMethodErrorPane").style.display="";
    	errs +=1;
    } else document.getElementById("shipMethodErrorPane").style.display="none";
    
    if (form.shipState.value != 'CA')
	if (!validatePresent    (form.shipCity,   'inf_shipCity',  true)) errs += 1;
    if (!validatePresent    (form.shipAddress1,   'inf_shipAddress1',  true)) errs += 1;
    if (!validatePresent    (form.shipLName,   'inf_shipLName',  true)) errs += 1;
    if (!validatePresent (form.shipFName, 'inf_shipFName', true)) errs += 1;
  
    return (errs==0);
  };
  
//********************* shipping cost routines *************************
var post = new Array();
var courier = new Array();
var dto;

dto = new Object();
dto.note = "&pound;5.25 1-2 days";
dto.cost = 5.25;
courier["United Kingdom"] = dto;

dto = new Object();
dto.note = "&pound;8.80 3-4 days";
dto.cost = 8.80;
courier["Austria"] = dto;

dto = new Object();
dto.note = "&pound;7.52 2-3 days";
dto.cost = 7.52;
courier["Belgium"] = dto;

dto = new Object();
dto.note = "&pound;11.42 4-5 days";
dto.cost = 11.42;
courier["Czech Republic"] = dto;

dto = new Object();
dto.note = "&pound;9.70 3-4 days";
dto.cost = 9.70;
courier["Denmark"] = dto;

dto = new Object();
dto.note = "&pound;13.18 5-6 days";
dto.cost = 13.18;
courier["Finland"] = dto;

dto = new Object();
dto.note = "&pound;9.56 2-3 days";
dto.cost = 9.56;
courier["France"] = dto;

dto = new Object();
dto.note = "&pound;7.18 2-3 days";
dto.cost = 7.18;
courier["Germany"] = dto;

dto = new Object();
dto.note = "&pound;19.75 3-6 days";
dto.cost = 19.75;
courier["Greece"] = dto;

dto = new Object();
dto.note = "&pound;18.00 3-7 days";
dto.cost = 18.00;
courier["Iceland"] = dto;

dto = new Object();
dto.note = "&pound;9.59 2-3 days";
dto.cost = 9.59;
courier["Ireland"] = dto;

dto = new Object();
dto.note = "&pound;12.23 4-5 days";
dto.cost = 12.23;
courier["Italy"] = dto;

dto = new Object();
dto.note = "&pound;7.91 2-3 days";
dto.cost = 7.91;
courier["Luxembourg"] = dto;

dto = new Object();
dto.note = "&pound;7.50 3-5 days";
dto.cost = 7.50;
courier["Netherlands"] = dto;

dto = new Object();
dto.note = "&pound;34.80 5-8 days";
dto.cost = 34.80;
courier["Norway"] = dto;

dto = new Object();
dto.note = "&pound;19.75 3-4 days";
dto.cost = 19.75;
courier["Portugal"] = dto;

dto = new Object();
dto.note = "&pound;13.33 4-5 days";
dto.cost = 13.33;
courier["Spain"] = dto;

dto = new Object();
dto.note = "&pound;18.00 3-7 days";
dto.cost = 18.00;
courier["Slovakia"] = dto;

dto = new Object();
dto.note = "&pound;11.54 5-6 days";
dto.cost = 11.54;
courier["Sweden"] = dto;

dto = new Object();
dto.note = "&pound;25.20 2-5 days";
dto.cost = 25.20;
courier["Switzerland"] = dto;

dto = new Object();
dto.note = "&pound;21.38 5-8 days";
dto.cost = 21.38;
courier["Turkey"] = dto;

// Post

dto = new Object();
dto.note = "&pound;2.00 1-5 days";
dto.cost = 0.00
post["United Kingdom"] = dto;
dto = new Object();
dto.note = "&pound;2.50 5-7 days";
dto.cost = 2.50;
post["Austria"] = dto;
dto = new Object();
dto.note = "&pound;2.50 5-7 days";
dto.cost = 2.50;
post["Belgium"] = dto;
dto = new Object();
dto.note = "&pound;2.50 5-7 days";
dto.cost = 2.50;
post["Czech Republic"] = dto;
dto = new Object();
dto.note = "&pound;2.50 5-7 days";
dto.cost = 2.50;
post["Denmark"] = dto;
dto = new Object();
dto.note = "&pound;2.50 8-10 days";
dto.cost = 2.50;
post["Finland"] = dto;
dto = new Object();
dto.note = "&pound;2.50 5-7 days";
dto.cost = 2.50;
post["France"] = dto;
dto = new Object();
dto.note = "&pound;2.50 5-7 days";
dto.cost = 2.50;
post["Germany"] = dto;
dto = new Object();
dto.note = "&pound;2.50 5-7 days";
dto.cost = 2.50;
post["Greece"] = dto;
dto = new Object();
dto.note = "&pound;2.50 5-7 days";
dto.cost = 2.50;
post["Iceland"] = dto;
dto = new Object();
dto.note = "&pound;2.50 5-7 days";
dto.cost = 2.50;
post["Ireland"] = dto;
dto = new Object();
dto.note = "&pound;2.50 5-7 days";
dto.cost = 2.50;
post["Italy"] = dto;
dto = new Object();
dto.note = "&pound;2.50 5-7 days";
dto.cost = 2.50;
post["Luxembourg"] = dto;
dto = new Object();
dto.note = "&pound;2.50 5-7 days";
dto.cost = 2.50;
post["Netherlands"] = dto;
dto = new Object();
dto.note = "&pound;2.50 8-10 days";
dto.cost = 2.50;
post["Norway"] = dto;
dto = new Object();
dto.note = "&pound;2.50 5-7 days";
dto.cost = 2.50;
post["Portugal"] = dto;
dto = new Object();
dto.note = "&pound;2.50 5-7 days";
dto.cost = 2.50;
post["Spain"] = dto;
dto = new Object();
dto.note = "&pound;2.50 5-7 days";
dto.cost = 2.50;
post["Slovakia"] = dto;
dto = new Object();
dto.note = "&pound;2.50 8-10 days";
dto.cost = 2.50;
post["Sweden"] = dto;
dto = new Object();
dto.note = "&pound;2.50 5-7 days";
dto.cost = 2.50;
post["Switzerland"] = dto;
dto = new Object();
dto.note = "&pound;2.50 8-10 days";
dto.cost = 2.50;
post["Turkey"] = dto;

function doRadioShipping(obj, form) {
	var country = form.shipCountry[form.shipCountry.selectedIndex].value;
	var aDto = new Object();

	if (obj.value == 'post') {
		aDto = post[country];
	}
	else if (obj.value == 'courier') {
		aDto = courier[country];
	}

	form.shipCost.value = aDto.cost;
	document.getElementById('shipNote').innerHTML = aDto.note;
}

function doShipping(obj, form) {
	var shipMethodObj = form.shipMethod;
	var shipMethod = '';
	var country = obj.options[obj.selectedIndex].value;

	for (i=0;i<shipMethodObj.length;i++) {
		if (shipMethodObj[i].checked == true){
			shipMethod=shipMethodObj[i].value;
			break;
		}
	}

	if (shipMethod != '') {
		if (shipMethod == 'post') {
			dto = post[country];
		}
		else if (shipMethod == 'courier') {
			dto = courier[country];
		}
		form.shipCost.value = dto.cost;
		document.getElementById('shipNote').innerHTML = dto.note;
	}
}

//************************************ US Billing and Shipping **************************************

		var browser = new Object;
		browser.isNavigator = false;
		browser.isIE = false;

		if (navigator.appName.indexOf("Netscape") != -1)
			browser.isNavigator = true;
		else if (navigator.appName.indexOf("Microsoft") != -1)
			browser.isIE = true;

		function getStyleObject(objectId) {
			// cross-browser function to get an object's style object given its id
			if(document.getElementById && document.getElementById(objectId)) {
				// W3C DOM
				return document.getElementById(objectId).style;
			} else if (document.all && document.all(objectId)) {
				// MSIE 4 DOM
				return document.all(objectId).style;
			} else if (document.layers && document.layers[objectId]) {
				// NN 4 DOM.. note: this won't find nested layers
				return document.layers[objectId].style;
			} else {
				return false;
			}
		} // getStyleObject

		function changeObjectVisibility(objectId, newVisibility) {
			// get a reference to the cross-browser style object and make sure the object exists
			var styleObject = getStyleObject(objectId);

			if(styleObject) {
				styleObject.display = newVisibility;
				return true;
			} else {
				// we couldn't find the object, so we can't change its visibility
				return false;
			}
		} // changeObjectVisibility
		
		function toggleStates(obj){

			var country = obj.options[obj.selectedIndex].value;
			var sDiv = country+'State';
			
			toggle(sDiv);
			if (obj.form.shipState){
				obj.form.shipState.value = eval('obj.form.'+ country + 'StateList.options[0].value');
				eval('obj.form.'+ country + 'StateList.options[0].selected = true');
				toggleShippingMethods(obj.options[obj.selectedIndex].value);
				toggleTaxPane(obj.form.shipState.value);
			} else if (obj.form.billState){
				obj.form.billState.value = eval('obj.form.'+ country + 'StateList.options[0].value');
				eval('obj.form.'+ country + 'StateList.options[0].selected = true');
				toggleTaxPane(obj.form.billState.value);
			}
		}
		
		function toggleStatesByName(name, state){
			var stateObj;
			
			toggle(name+'State');
			
			if (name.length == 0){
				if (document.address.shipState){
					document.address.shipState.value=eval('document.address.USStateList.options[0].value');
					document.address.USStateList.options[0].selected = true;
				} else if (document.address.billState){
					document.address.billState.value=eval('document.address.USStateList.options[0].value');
					document.address.USStateList.options[0].selected = true;
				}
			} else {
				if (document.address.shipState){
					stateObj = eval('document.address.'+name+'StateList');
					for (i=0;i<stateObj.options.length;i++){
						if (stateObj.options[i].value == state){
							stateObj.selectedIndex = i;
							document.address.shipState.value = state;
							break;
						}
					}
				} else if (document.address.billState){
					document.address.billState.value=state;
				}
			}
		}
		
		function toggle(sDiv){
		
			if (sDiv == 'USState' || sDiv == '')
			{
				changeObjectVisibility(sDiv,'');
				changeObjectVisibility('MIState','none');
				changeObjectVisibility('CAState','none');
			}
			if (sDiv == 'MIState')
			{
				changeObjectVisibility(sDiv,'');
				changeObjectVisibility('CAState','none');
				changeObjectVisibility('USState','none');
			}
			if (sDiv == 'CAState')
			{
				changeObjectVisibility(sDiv,'');
				changeObjectVisibility('USState','none');
				changeObjectVisibility('MIState','none');
			}
		}
		
		function toggleShippingMethods(country){
			
			var sDiv = country+'ShippingOptions';
			
			var rg;
			
			if (document.address.shippingMethodRadio){
				rg = document.address.shippingMethodRadio;
				for (i=0;i<rg.length;i++){
					rg[i].checked = false;
				}
			}
			
			if (sDiv == 'USShippingOptions')
			{
				changeObjectVisibility(sDiv,'');
				changeObjectVisibility('MIShippingOptions','none');
				changeObjectVisibility('CAShippingOptions','none');
				changeObjectVisibility('PRShippingOptions','none');
				changeObjectVisibility('910ShippingOptions','none');
			}
			else if (sDiv == 'MIShippingOptions')
			{
				changeObjectVisibility(sDiv,'');
				changeObjectVisibility('CAShippingOptions','none');
				changeObjectVisibility('USShippingOptions','none');
				changeObjectVisibility('PRShippingOptions','none');
				changeObjectVisibility('910ShippingOptions','none');
			}
			else if (sDiv == 'CAShippingOptions')
			{
				changeObjectVisibility(sDiv,'');
				changeObjectVisibility('USShippingOptions','none');
				changeObjectVisibility('MIShippingOptions','none');
				changeObjectVisibility('PRShippingOptions','none');
				changeObjectVisibility('910ShippingOptions','none');
			}
			else if (sDiv == 'PRShippingOptions')
			{
				changeObjectVisibility(sDiv,'');
				changeObjectVisibility('USShippingOptions','none');
				changeObjectVisibility('MIShippingOptions','none');
				changeObjectVisibility('CAShippingOptions','none');
				changeObjectVisibility('910ShippingOptions','none');
			}
			else if (sDiv == 'AKShippingOptions' || sDiv == 'HIShippingOptions')
			{
				changeObjectVisibility('910ShippingOptions','');
				changeObjectVisibility('USShippingOptions','none');
				changeObjectVisibility('MIShippingOptions','none');
				changeObjectVisibility('CAShippingOptions','none');
				changeObjectVisibility('PRShippingOptions','none');
			}
			
			if (document.getElementById('shippingCostPane'))
			{
				g_shipCost = false;
				document.getElementById('shippingCostPane').innerHTML = '';
			}
			
		}
		
		function setStateValue(obj, ctryObj){
			var state = obj.options[obj.selectedIndex].value;
			var country = ctryObj.options[ctryObj.selectedIndex].value;
			
			if (document.address.billState){
				document.address.billState.value = state;
				toggleTaxPane(state);
			}
			else if (document.address.shipState){
				document.address.shipState.value = state;
				toggleTaxPane(state);
			}
			
			if (state == 'PR' || state == 'HI' || state == 'AK')
				toggleShippingMethods(state);
			else if (country == 'US' && (state != 'PR' || state == 'HI' || state == 'AK'))
				toggleShippingMethods(country);

		}
		
		function setStateValueByText(value){
			if (document.address.billState)
				document.address.billState.value = value;
			else if (document.address.shipState)
				document.address.shipState.value = value;

		}
		
		function initialise(country, state){
			var form = document.address;
			
			toggleStatesByName(country, state);
			if (state == 'PR' || state == 'AK' || state == 'HI')
				toggleShippingMethods(state);
			else toggleShippingMethods(country);
			setStateValueByText(state);
			toggleTaxPane(state);
		}
		
		function validateCAPostCode(postcode){
			var reg = /\D\d\D\W\d\D\d/;

			if (postcode.length > 7)
				return false;

			if (reg.exec(postcode))
				return true;
			else return false;
			
			return true;
		}
		
//************************************ US Billing and Shipping **************************************