 
   function validateRange()
   {
      var s = document.frmInput.txtInput.value;
      var A = document.frmInput.txtA.value;
      var B = document.frmInput.txtB.value;

      switch (isIntegerInRange(s, A, B))
      {
         case true:
            alert(s + " is in range from " + A + " to " + B)
            break;
         case false:
            alert(s + " is not in range from " + A + " to " + B)
      }
   }

// isIntegerInRange (STRING s, INTEGER a, INTEGER b)
   function isIntegerInRange (s, a, b)
   {   if (isEmpty(s))
         if (isIntegerInRange.arguments.length == 1) return false;
         else return (isIntegerInRange.arguments[1] == true);

      // Catch non-integer strings to avoid creating a NaN below,
      // which isn't available on JavaScript 1.0 for Windows.
      if (!isInteger(s, false)) return false;

      // Now, explicitly change the type to integer via parseInt
      // so that the comparison code below will work both on
      // JavaScript 1.2 (which typechecks in equality comparisons)
      // and JavaScript 1.1 and before (which doesn't).
      var num = parseInt (s);
      return ((num >= a) && (num <= b));
   }

   function isInteger (s)
   {
      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }

   function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
   }

   function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }

function Validate_PostCode(sPostCode) { 
 //check postcode format is valid
 test = sPostCode;
 size = test.length;
 test = test.toUpperCase(); //Change to uppercase
 while (test.slice(0,1) == " ") //Strip leading spaces
  {test = test.substr(1,size-1);size = test.length
  }
 while(test.slice(size-1,size)== " ") //Strip trailing spaces
  {test = test.substr(0,size-1);size = test.length
  }
 sPostCode = test; //write back to form field
 if (size < 6 || size > 8){ //Code length rule
  alert(test + " is not a valid postcode - wrong length");
  return false;
  }
 if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule
   alert(test + " is not a valid postcode - cannot start with a number");
   return false;
  }
 if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule
   alert(test + " is not a valid postcode - alpha character in wrong position");
   return false;
  }
 if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   return false;
  }
 if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   return false;
  }
 if (!(test.charAt(size-4) == " ")){//space in position length-3 rule
   alert(test + " is not a valid postcode - no space or space in wrong position");
   return false;
   }
 count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");
 if (count1 != count2){//only one space rule
   alert(test + " is not a valid postcode - only one space allowed");
   return false;
  }
return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////
function validate_email(field,alerttxt)
{
 with (field) {
  apos=value.indexOf("@")
  dotpos=value.lastIndexOf(".")
  if (apos<1||dotpos-apos<2) 
    {alert(alerttxt);return false}
  else {return true}
 }
}


/////////////////////////////////////////////////////////////////////////////////////////////////////
// GUEST FORM
/////////////////////////////////////////////////////////////////////////////////////////////////////

function guest_validate(thisform)
{
with (thisform)
{

// Check name
if (Del_Name.value=='') {
	alert("You must enter a name.");
	Del_Name.focus();
	return false;
}

// Check address
if (Del_Addr1.value=='') {
	alert("You must enter an address.");
	Del_Addr1.focus();
	return false;
}

// Check postcode
if (Validate_PostCode(Del_Postcode.value)==false) {
	Del_Postcode.focus();
	return false;
}

// Check that email address is valid
if (validate_email(Del_EMail,"You have entered an invalid email address.")==false)  {
	Del_EMail.focus();
	return false;
}

// Check that email addreses are the same
if (Del_EMail_Verify.value!=Del_EMail.value) {
	alert("The email addresses you have entered do not match.");
	Del_EMail_Verify.focus();
	return false;
}

// Check telephone
if (Del_TelHome.value=='') {
    alert("You must enter a home telephone number");
    Del_TelHome.focus();
    return false;
}

}
	return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////

function guest_submit(thisform)
{
  if (guest_validate(thisform)) {
  	 thisform.submit();
  }
}


/////////////////////////////////////////////////////////////////////////////////////////////////////
// GUEST FORM
/////////////////////////////////////////////////////////////////////////////////////////////////////

function reg_validate(thisform)
{
with (thisform)
{

// Check name
if (Del_Name.value=='') {
	alert("You must enter a name.");
	Del_Name.focus();
	return false;
}

// Check address
if (Del_Addr1.value=='') {
	alert("You must enter an address.");
	Del_Addr1.focus();
	return false;
}

// Check postcode
if (Validate_PostCode(Del_Postcode.value)==false) {
	Del_Postcode.focus();
	return false;
}

// Check that email address is valid
if (validate_email(Del_EMail,"You have entered an invalid email address.")==false)  {
	Del_EMail.focus();
	return false;
}

// Check telephone
if (Del_TelHome.value=='') {
    alert("You must enter a home telephone number");
    Del_TelHome.focus();
    return false;
}

}
	return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////

function reg_submit(thisform)
{
  if (reg_validate(thisform)) {
  	 thisform.submit();
  }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////

function reg_clear(thisform) {
with (thisform) {
	Del_Name.value='';
	Del_Addr1.value='';
	Del_Addr2.value='';
	Del_Addr3.value='';
	Del_Addr4.value='';
	Del_Postcode.value='';
	Del_TelHome.value='';
	Del_TelWork.value='';
	Del_TelMobile.value='';
	Del_EMail.value='';
}	
}

/////////////////////////////////////////////////////////////////////////////////////////////////////
// REGISTER FORM
/////////////////////////////////////////////////////////////////////////////////////////////////////

function register_validate(thisform)
{
	with (thisform) {

	// Check that email address is valid
	if (validate_email(Reg_EMail,"You have entered an invalid email address.")==false)  {
		Reg_EMail.focus();
		return false;
	}

	// Check for minimum length of 6 chars
	if (Reg_Password.value.length<6) {
		alert('Your password is not long enough, it needs to be between 6 and 10 characters long.');
		Reg_Password.focus();
		return false;
	}
	
	// Check passwords match
	if (Reg_Password.value!=Reg_Password_Verify.value) {
		alert('Passwords do not match');
		Reg_Password_Verify.focus();
		return false;
	}

	// Check name
	if (Reg_Name.value=='') {
		alert("You must enter a name.");
		Reg_Name.focus();
		return false;
	}
	

	// Check address
	if (Reg_Addr1.value=='') {
		alert("You must enter an address.");
		Reg_Addr1.focus();
		return false;
	}

	// Check postcode
	if (Validate_PostCode(Reg_Postcode.value)==false) {
		Reg_Postcode.focus();
		return false;
	}

// Check telephone
if (Reg_TelHome.value=='') {
    alert("You must enter a home telephone number");
    Reg_TelHome.focus();
    return false;
}
    


	}
	return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////

function register_submit(thisform)
{
  if (register_validate(thisform)) {
  	 thisform.submit();
  }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////
// CONFIRMATION FORM
/////////////////////////////////////////////////////////////////////////////////////////////////////

function confirm_validate(thisform)
{
 with (thisform) {

	if (accept.checked==false) {
		alert("You must accept the terms and conditions to continue.");
		return false;
	}

	if (confirm18.checked==false) {
		alert("You must confirm you are over 18 to continue.");
		return false;
	}
 	thisform.submit();
 }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////

function confirm_submit(thisform)
{
 if (confirm_validate(thisform)) {
 	thisform.submit();
 }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////

function validate_qty(thisform, maxqty)
{

   if (typeof thisform.ass_accept != 'undefined') {
        if (thisform.ass_accept.checked==false) {
            alert('You must accept the condition of purchase to add this product to your cart.');
            return false;
            }
   }


   if (isIntegerInRange (thisform.quantity.value, 1, maxqty)==true) {
    return true;
  } else {
    thisform.quantity.value = thisform.orgquantity.value;
    thisform.quantity.focus();
    alert('Error quantity entered is not valid');
    return false;
  }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////

function validate_search(thisform)
{
    if (thisform.str_search.value=='') {
        alert('You must enter something to search');
        thisform.str_search.focus();
        return false;
    } else {
        return true;
    }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////

function validate_login(thisform) {

    with (thisform) {
      
        // Check that email address is valid
        if (validate_email(str_email,"You have entered an invalid login name.")==false)  {
            str_email.focus();
            return false;
        }

        // check password    
        if (str_password.value=='') {
            alert('You must enter a password.');
            str_password.focus();
            return false;
        }
    }
    
    return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////

function ShowProductPhoto(URL) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=640,height=480,left = 320,top = 272');");
}

/////////////////////////////////////////////////////////////////////////////////////////////////////

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////

function GoBackAndDisplayMessage(sMsg) {
    alert('');
}

/////////////////////////////////////////////////////////////////////////////////////////////////////
// My account - Change Password
/////////////////////////////////////////////////////////////////////////////////////////////////////

function myaccount_change_validate(thisform)
{
    with (thisform) {

    // Check for minimum length of 6 chars
    if (Acc_Password.value.length<6) {
        alert('Your password is not long enough, it needs to be between 6 and 10 characters long.');
        Acc_Password.focus();
        return false;
    }
    
    // Check passwords match
    if (Acc_Password.value!=Acc_Password_Verify.value) {
        alert('Passwords do not match');
        Acc_Password_Verify.focus();
        return false;
    }

    }
    return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////

function myaccount_change_submit(thisform)
{
  if (myaccount_change_validate(thisform)) {
       thisform.submit();
  }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////
// MY ACCOUNT DETAILS FORM
/////////////////////////////////////////////////////////////////////////////////////////////////////

function myaccount_details_validate(thisform)
{
    with (thisform) {

    // Check name
    if (Acc_Name.value=='') {
        alert("You must enter a name.");
        Acc_Name.focus();
        return false;
    }
    

    // Check address
    if (Acc_Addr1.value=='') {
        alert("You must enter an address.");
        Acc_Addr1.focus();
        return false;
    }

    // Check postcode
    if (Validate_PostCode(Acc_Postcode.value)==false) {
        Acc_Postcode.focus();
        return false;
    }

// Check telephone
if (Acc_TelHome.value=='') {
    alert("You must enter a home telephone number");
    Acc_TelHome.focus();
    return false;
}
    


    }
    return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////

function myaccount_details_submit(thisform)
{
  if (myaccount_details_validate(thisform)) {
       thisform.submit();
  }
}
