/** Copyright (C) 2002 Dan Heuston. **/
/** All rights reserved.            **/

/* Global variables */
 var enquiry = new String



function validateForm(enqForm) {

 /* The name must always be mandatory. */
 if(enqForm.Name.value == "") {
  alert("Please enter your name.")
  enqForm.Name.focus()
  return false
 }

  enqForm.realname.value = enqForm.Name.value
  
 /* If the email address has been completed, validate it */
 if(enqForm.email.value =="") {
  alert("Please provide an email address where we can provide a response to your enquiry.")
  enqForm.email.focus()
  return false
 }
 else {
  invalidChars = " /:,;"
  for(i=0; i < invalidChars.length; i++) {
   badChar = invalidChars.charAt(i)
   if(enqForm.email.value.indexOf(badChar,0) > -1) {
    alert("You have entered some invalid characters in the email field. Please check you have entered a valid email address.")
    enqForm.email.focus()
	return false
   }
  }

  atPos = enqForm.email.value.indexOf("@", 1)
  if(atPos == -1) {
   alert("Please ensure you have entered a valid email address, as you do not appear to have an @ sign in your email address. e.g. automanor@btconnect.com.")
   enqForm.email.focus()
   return false
  }
  else {
   periodPos = enqForm.email.value.indexOf(".", atPos)
   if(periodPos == -1) {
    alert("Please ensure you have entered a valid email address, as you do not appear to have a correct domain in your email address. e.g. automanor@btconnect.com.")
    enqForm.email.focus()
    return false
   }
  }
 }


 enquiry = enqForm.Enquiry.value

 /* In all cases except the General Enquiry, check make and model has been completed */
 if(enquiry != "General Enquiry") {

  if(enqForm.VehicleMake.selectedIndex == 0) {
   alert("Please enter the vehicle make.")
   enqForm.VehicleMake.focus()
   return false
  }

  if(enqForm.VehicleModel.value =="") {
   alert("Please enter the vehicle model.")
   enqForm.VehicleModel.focus()
   return false
  }
 }
 else
 {
  if(enqForm.VehicleMake.selectedIndex != 0 && enqForm.VehicleModel.value =="") {
   alert("Please enter the vehicle model.")
   enqForm.VehicleModel.focus()
   return false
  }
 }



 if(enquiry == "General Enquiry") {
  if(enqForm.Comments.value =="") {
   alert("Please type in your enquiry.")
   enqForm.Comments.focus()
   return false
  }
 }
 else if(enquiry == "Service/Fitting") {
  if(enqForm.VehicleYear.value =="") {
   alert("Please type in the year of the vehicle.")
   enqForm.VehicleYear.focus()
   return false
  }  
  if(enqForm.Comments.value =="") {
   alert("Please type in the details of what you require servicing or installing.")
   enqForm.Comments.focus()
   return false
  }

 }
 else if(enquiry == "Trailer Hire") {
  if(enqForm.CollectionDate.value =="" || enqForm.ReturnDate.value =="") {
   alert("Please provide both your required Collection and Return Date.")
   enqForm.CollectionDate.focus()
   return false
  }
 }
 else if(enquiry == "Tow Bar Sales") {
  if(enqForm.VehicleYear.value =="") {
   alert("Please provide the car's year.")
   enqForm.VehicleYear.focus()
   return false
  }
 }
 

 if(!enqForm.MailingList.checked) {
  enqForm.MailingList.value = "No"
 }
 
 return true
}



function openPrivacy() {

 winWidth  = 600
 winHeight = 400
 winparams = "scrollbars=yes, menubar=no, width=" + winWidth + ", height=" + winHeight + ", resizable=yes, left=0, top=0, status=no"

 prWin = window.open("privacy.htm", "privacyWin", winparams)
 prWin.focus()
}



function getEnquiry(enqForm) {

 param = getParam(this.location.href)

 if(param != "") {

  if(param == "service") {
    enquiry = "Service/Fitting"
    document.enqForm.subject.value = "Service/Fitting Enquiry from towriteupminster.com"
    document.enqForm.Manufacturer.value = ""
    document.enqForm.Model.value = ""
    document.writeln("<p class='verylargetxt'>Service/Fitting Enquiry<\/p>")
  }
  else {
   productref = param.substring(param.indexOf('=')+1, param.length)
   product  = param.substring(0, param.indexOf('='))
   prod = new Array()

   if(product == trailers[0][0]) {
    prod = trailers
	enquiry = "Trailer Sales"
    document.enqForm.subject.value = "Trailer Sales Enquiry from towriteupminster.com"
	picref = trpic
   }
   else if(product == roofbox[0][0]) {
    prod = roofbox
	enquiry = "Roof Box Sales"
    document.enqForm.subject.value = "Roof Box Sales Enquiry from towriteupminster.com"
	picref = rbpic
   }

   /* Set our hidden fields containing the products */
   document.enqForm.Manufacturer.value = prod[productref][manu]
   document.enqForm.Model.value = prod[productref][model]

   document.write("<p class='verylargetxt'>Product Enquiry: <b>" + prod[productref][manu] + " " + prod[productref][model] + "<\/b><br>")
   document.write("<img class='yellowframe' src='" + picDir + "\/" + prod[productref][picref] + "' alt='[" + prod[productref][1] + " picture]' title=''><br><\/p>")
  }
 }
 else {
  enquiry = "General Enquiry"
  document.enqForm.subject.value = "Enquiry from towriteupminster.com"
  document.enqForm.Manufacturer.value = ""
  document.enqForm.Model.value = ""
  document.writeln("<p class='verylargetxt'>General Enquiry<\/p>")
 }

 document.enqForm.Enquiry.value = enquiry
}



function getHireTrailer(enqForm) {

 param = getParam(this.location.href)

 if(param != "") {

  productref = param.substring(param.indexOf('=')+1, param.length)
  product  = param.substring(0, param.indexOf('='))

  /* Set our hidden fields containing the products */
  document.enqForm.Manufacturer.value = trailers[productref][trmanu]
  document.enqForm.Model.value = trailers[productref][trmodel]

  document.write("<p class='verylargetxt'>Trailer hire enquiry for a <b>" + trailers[productref][trmanu] + " " + trailers[productref][trmodel] + "<\/b><br>")
  document.write("<img class='yellowframe' src='" + picDir + "\/" + trailers[productref][trpic] + "' alt='[" + trailers[productref][1] + " picture]' title=''><br><\/p>")
 }
 else {
  document.writeln("<p class='centered'>An error in the on-line database means we cannot identify the trailer you have selected. Please fill in the specific trailer model you wish to hire in the Additional Comments field below. Thank-you.<\/p>")
 }
}


function VehicleYear() {

 if(enquiry == "Service/Fitting") {
  document.write("<table cellspacing='5' cellpadding='5' width='100%' border='0'>")
  document.write("<tr><td width=\"50%\">&nbsp;</td>")
  document.write("<td width=\"15%\" align=\"right\">Year <sup>*</sup><\/td>")
  document.write("<td width=\"35%\"><input type=\"text\" name=\"VehicleYear\" size=\"4\" maxlength=\"4\">")
  document.write("<\/td><\/tr><\/table>")
 }
}



function perForm() {

 if(enquiry == "General Enquiry") {
   document.write("<tr valign=top><td align=right width='25%'>Your enquiry<sup>*<\/sup><\/td><td><textarea name='Comments' rows=5 cols=60><\/textarea><\/td><\/tr>")
 }
 else if(enquiry == "Service/Fitting") {
   document.write("<tr valign=\"top\"><td align=\"right\">Service/Fitting details<sup>*<\/sup><\/td><td><textarea name='Comments' rows=5 cols=50><\/textarea>")
 }
 else if(enquiry == "Roof Box Sales") {
   document.write("<tr valign=top><td colspan=2>")
   document.write("<table cellspacing='0' cellpadding='0' width='100%' border='0'>")
   document.write("<td width='25%' align=right>Do you require a roof bar as well?<\/td>")
   document.write("<td width='15%' align=center><input type='radio' name='Roofbar' value='Yes' checked> Yes <input type='radio' name='Roofbar' value='No'> No<\/td>")
   document.write("<td width='40%' align=right>Would you like us to give you a quote to fit this roof box?<\/td>")
   document.write("<td width='20%'><input type='radio' name='Roofboxinstall' value='Yes' checked> Yes <input type='radio' name='Roofboxinstall' value='No'> No<\/td><\/tr><\/table><\/tr>")
   document.write("<tr valign=top><td align=right width='25%'>Additional Requests or Comments<\/td><td><textarea name='Comments' rows=5 cols=60><\/textarea><\/td><\/tr>")
 }
 else {
   document.write("<tr valign=top><td align=right width='25%'>Additional Requests or Comments<\/td><td><textarea name='Comments' rows=5 cols=60><\/textarea><\/td><\/tr>")
 }
}