function validate(form, F_PSMONTH, F_PSYEAR) {
  form.F_RPOW.value = RemoveBad(form.F_RPOW.value)
  form.F_RBC.value = RemoveBad(form.F_RBC.value)
  form.F_RDIA.value = RemoveBad(form.F_RDIA.value)
  form.F_RBIF.value = RemoveBad(form.F_RBIF.value)
  form.F_RCOL.value = RemoveBad(form.F_RCOL.value)
  form.F_LPOW.value = RemoveBad(form.F_LPOW.value)
  form.F_LBC.value = RemoveBad(form.F_LBC.value)
  form.F_LDIA.value = RemoveBad(form.F_LDIA.value)
  form.F_LBIF.value = RemoveBad(form.F_LBIF.value)
  form.F_LCOL.value = RemoveBad(form.F_LCOL.value)
  form.F_OPTNAME.value = RemoveBad(form.F_OPTNAME.value)
  form.F_OPTPHONE.value = RemoveBad(form.F_OPTPHONE.value)

  if (allSpaces(form.F_RPOW.value)) {
    alert('Please fill in Right Power.')
    form.F_RPOW.focus()
    return false;
  }

  if (allSpaces(form.F_RBC.value)) {
    alert('Please fill in your Right Base Curve.')
    form.F_RBC.focus()
    return false;
  }

  if (allSpaces(form.F_RDIA.value)) {
    alert('Please fill in your Right Diameter.')
    form.F_RDIA.focus()
    return false;
  }

  if (allSpaces(form.F_LPOW.value)) {
    alert('Please fill in Left Power.')
    form.F_LPOW.focus()
    return false;
  }

  if (allSpaces(form.F_LBC.value)) {
    alert('Please fill in your Left Base Curve.')
    form.F_LBC.focus()
    return false;
  }

  if (allSpaces(form.F_LDIA.value)) {
    alert('Please fill in your Left Diameter.')
    form.F_LDIA.focus()
    return false;
  }

  if (allSpaces(form.F_OPTNAME.value)) {
    alert('Please fill in Optometrists Name.')
    form.F_OPTNAME.focus()
    return false;
  }
  if (allSpaces(form.F_OPTPHONE.value)) {
    alert('Please fill in your Optometrists Phone Number.')
    form.F_OPTPHONE.focus()
    return false;
  }
  
  if ((form.F_PSYEAR.options[form.F_PSYEAR.selectedIndex].value + form.F_PSMONTH.options[form.F_PSMONTH.selectedIndex].value) < F_PSYEAR + F_PSMONTH)
  {
	alert('Prescriptions must not be more than 2 years old.')
	form.F_PSMONTH.focus()
	return false;
  }

  return true;
}

function allSpaces(szString) {
  spcCount = 0;
  for (var i = 0; i <= szString.length-1; i++) {
    if (szString.substring(i,i+1) != ' ') {
      spcCount = spcCount++
    }
  }
  if ((spcCount == szString.length) || (szString.length == 0))
    {return true} else {return false}
}

function RemoveBad(strTemp) {
  //strTemp = strTemp.replace(/\<|\>|\"|\'|\%|\;|\(|\)|\+/g, "");
  return strTemp;   
}

function qtyclick(product, rndlink)
{
	var URL = "detail.asp?x=" + rndlink + "&id=" + product + "&quantity=";
	URL = URL + document.orderform.qty.options[document.orderform.qty.selectedIndex].value;
	URL = URL + "&F_RPOW=" + document.orderform.F_RPOW.value;
	URL = URL + "&F_LPOW=" + document.orderform.F_LPOW.value;
	URL = URL + "&F_RBC=" + document.orderform.F_RBC.value;
	URL = URL + "&F_LBC=" + document.orderform.F_LBC.value;
	URL = URL + "&F_RDIA=" + document.orderform.F_RDIA.value;
	URL = URL + "&F_LDIA=" + document.orderform.F_LDIA.value;
	URL = URL + "&F_RBIF=" + document.orderform.F_RBIF.value;
	URL = URL + "&F_LBIF=" + document.orderform.F_LBIF.value;
	URL = URL + "&F_RCOL=" + document.orderform.F_RCOL.value;
	URL = URL + "&F_LCOL=" + document.orderform.F_LCOL.value;
	URL = URL + "&F_OPTNAME=" + document.orderform.F_OPTNAME.value;
	URL = URL + "&F_SCRIPTNAME=" + document.orderform.F_SCRIPTNAME.value;
	//URL = URL + "&scriptday=" + document.orderform.scriptday.options[document.orderform.scriptday.selectedIndex].value;
	URL = URL + "&F_PSMONTH=" + document.orderform.F_PSMONTH.options[document.orderform.F_PSMONTH.selectedIndex].value;
	URL = URL + "&F_PSYEAR=" + document.orderform.F_PSYEAR.options[document.orderform.F_PSYEAR.selectedIndex].value;
	URL = URL + "&F_OPTPHONE=" + document.orderform.F_OPTPHONE.value;
	//URL = URL + "&scriptvalid=" + document.orderform.scriptvalid.options[document.orderform.scriptvalid.selectedIndex].value;
	top.location.href = URL; target = '_self';
}

function orderqtyclick(product, fieldx, rndlink)
{
	var URL = "cart.asp?x=" + rndlink + "&pid=" + product + "&qty=";
	URL = URL + fieldx.options[fieldx.selectedIndex].value + "&loc=";
	URL = URL + document.orderform.shipping.options[document.orderform.shipping.selectedIndex].value;
	top.location.href = URL; target = '_self';
}

function shippingclick(rndlink)
{
	var URL = "cart.asp?x=" + rndlink + "&loc=";
	URL = URL + document.orderform.shipping.options[document.orderform.shipping.selectedIndex].value;
	top.location.href = URL; target = '_self';
}

function validatecheckout(form) {
  form.firstname.value = RemoveBad(form.firstname.value)
  form.lastname.value = RemoveBad(form.lastname.value)
  form.email.value = RemoveBad(form.email.value)
  form.dob.value = RemoveBad(form.dob.value)
  form.phone.value = RemoveBad(form.phone.value)
  form.username.value = RemoveBad(form.username.value)
  form.password.value = RemoveBad(form.password.value)
  form.address.value = RemoveBad(form.address.value)
  form.city.value = RemoveBad(form.city.value)
  form.postcode.value = RemoveBad(form.postcode.value)
  form.state.value = RemoveBad(form.state.value)
  form.country.value = RemoveBad(form.country.value)

  if (allSpaces(form.firstname.value)) {
    alert('Please fill in First Name.')
    form.firstname.focus()
    return false;
  }

  if (allSpaces(form.lastname.value)) {
    alert('Please fill in your Last Name.')
    form.lastname.focus()
    return false;
  }

  if (allSpaces(form.email.value)) {
    alert('Please fill in your Email Address.')
    form.email.focus()
    return false;
  }

  if (allSpaces(form.dob.value)) {
    alert('Please fill in Date of Birth.')
    form.dob.focus()
    return false;
  }

  if (allSpaces(form.phone.value)) {
    alert('Please fill in your Phone Number.')
    form.phone.focus()
    return false;
  }

  if (allSpaces(form.username.value)) {
    alert('Please fill in or chose your Username.')
    form.username.focus()
    return false;
  }

  if (allSpaces(form.password.value)) {
    alert('Please fill in or choose your Password.')
    form.password.focus()
    return false;
  }
  if (allSpaces(form.address.value)) {
    alert('Please fill in your Address.')
    form.address.focus()
    return false;
  }
  if (allSpaces(form.city.value)) {
    alert('Please fill in your City.')
    form.city.focus()
    return false;
  }
  if (allSpaces(form.postcode.value)) {
    alert('Please fill in your Post Code.')
    form.postcode.focus()
    return false;
  }
  if (allSpaces(form.state.value)) {
    alert('Please fill in your State.')
    form.state.focus()
    return false;
  }
  if (allSpaces(form.country.value)) {
    alert('Please fill in your Country.')
    form.country.focus()
    return false;
  }
  return true;
}