<!--
function getDesc(itemcode) {
  return descriptions[itemcode];
}

function getPrice(itemcode) {
  return prices[itemcode];
}

function getParams(firstparam) {
  var thisURL = document.location;
  var thisURLstring = thisURL.toString();
  var idx = thisURLstring.search(firstparam);
  var params = new Array();
  if (idx != -1) {
    var len = thisURLstring.length;
    var pairs = thisURLstring.substring(idx, len);
    nameVal = pairs.split('=');
    params[nameVal[0]] = nameVal[1];
  }
  return params;
}
params = getParams('itemdesc');
itemdesc = unescape(params["itemdesc"]);
if (itemdesc == "undefined")
{
  itemdesc="Error: no purchase item selected";
}

function checkName(field) {
   field.value = trim(field.value);
   if (! ((field.value.length > 1) && (field.value.length <= 70))) {
      alert("Please enter your name")
      return false
   }
   else return true
}

function checkEmail(field) {
   field.value = trim(field.value);
   var sLength = field.value.length;
   if ((sLength < 6) || (field.value.length > 100)) {
      alert("Please supply a valid email address of the form foo@bar.com")
      return false
   }
   var i = 0;
   if ( (i = field.value.indexOf('@')) <= -1) {
      alert("Please supply a valid email address of the form foo@bar.com")
      return false
   }
   // look for .
   i++;
   while ((i < sLength) && (field.value.charAt(i) != ".")) { i++ }

   // there must be at least one character after the .
   if ((i >= sLength - 1) || (field.value.charAt(i) != ".")) {
      alert("Please make sure your email address is valid and of the form foo@bar.com")
      return false
   }
   return true
}

function checkItem(itemname) {
   if (itemname == "Error: no description available") {
      alert("System error: no item description available. Please select an item for download before accessing this page")
      return false
   }
   else return true
}

function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

function validateAndSubmit(theform) {
		  
		  if (!checkItem(itemdesc)) {
		      return false
		  }
 
          if (!checkName(theform.name)) {  
              return false
          }

          if (!checkEmail(theform.email)) {       
              return false
          }
		  document.download_form.desc.value  = itemdesc;
          document.download_form.name.value  = document.purchaser_details.name.value;
		  document.download_form.email.value = document.purchaser_details.email.value;
		  if ((document.purchaser_details.company.value  != "") 
		  ||  (document.purchaser_details.address1.value != "") 
		  ||  (document.purchaser_details.address2.value != "") 
		  ||  (document.purchaser_details.address3.value != "") 
		  ||  (document.purchaser_details.address4.value != "")) 
		  {
		      var address = document.purchaser_details.company.value  + "\n"
			              + document.purchaser_details.address1.value + "\n"
						  + document.purchaser_details.address2.value + "\n"
						  + document.purchaser_details.address3.value + "\n"
						  + document.purchaser_details.address4.value + "\n";
              document.download_form.address.value = address;
          }
		  else 
		  {
		      document.download_form.address.value = " ";
		  }
		  
		  if  (document.purchaser_details.postcode.value != "") 
          {
		      var pcode = document.purchaser_details.postcode.value;
              document.download_form.postcode.value = pcode.toUpperCase();
		  }
		  else
		  {
              document.download_form.postcode.value = " ";
		  }		  
		  	 
		  cinx = document.purchaser_details.country.selectedIndex;
		   
		  if  (cinx > -1)
          {
              document.download_form.country.value = document.purchaser_details.country.options[cinx].value;
          }
		  else
		  {
              document.download_form.country.value = " ";
		  }		  
		  		  
          if (document.purchaser_details.telephone.value != "") {
              document.download_form.tel.value = document.purchaser_details.telephone.value;
	      }
		  else
		  {
              document.download_form.tel.value = " ";
	      }		  

          document.download_form.submit();
}

//-->
