function titleGender(TitleValue) {
 var y=TitleValue;
 if (y == "Mr") {
  document.shops.gender[0].checked = true;
 } else if (y == "Mrs") {
  document.shops.gender[1].checked = true;
 } else if (y == "Miss") {
  document.shops.gender[1].checked = true;
 } else if (y == "Ms") {
  document.shops.gender[1].checked = true;
 } else if (y == "Dr") {
  document.shops.gender[1].checked = false;
  document.shops.gender[0].checked = false;
 } else if (y == "Prof") {
  document.shops.gender[1].checked = false;
  document.shops.gender[0].checked = false;
 }
}



function isValidDate(dateStr) {
 // Original:  Sandeep V. Tamhankar
 // Checks for the following valid date formats:
 // MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
 // Also separates date into month, day, and year variables
 var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
 
 var matchArray = dateStr.match(datePat); // is the format ok?
 if (matchArray == null) {
  alert("Please select a full date.")
  return false;
 }
 month = matchArray[1]; // parse date into variables
 day = matchArray[3];
 year = matchArray[4];
 
 if ((month=="04" || month=="06" || month=="09" || month=="11") && day=="31") {
  switch(month)
  {
  case "04":
   var monthStr = "April";
   break;    
  case "06":
   var monthStr = "June";
   break;  
  case "09":
   var monthStr = "September";
   break;
  case "11":
   var monthStr = "November";
   break;
  default:
   var monthStr = month;
  }
  alert(monthStr + " doesn't have 31 days.");
  return false;
 }
 if (month == 02) { // check for february 29th
  var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
  if (day > 29 || (day == 29 && !isleap)) {
   alert("February " + year + " doesn't have " + day + " days.");
   return false;
    }
 }
 return true;  // date is valid
}
function dateCheck() {
 var theMonth = document.getElementById("Month").value;
 var theDay = document.getElementById("Day").value;
 var theYear = document.getElementById("Year").value;
 if (theMonth == "") {
  theMonth = "01";
 }
 if (theDay == "") {
  theDay = "01";
 }
 if (theYear == "") {
  theYear = "2008";
 }
 var myDateStr = theMonth + "/" + theDay + "/" + theYear;
 isValidDate(myDateStr);
}
function validRequired(formField,fieldLabel) {
 var result = true;
 if (formField.value == "") {
  result = false;
 }
 return result;
}
function validateForm(theForm) {
 
 var returnVal = true;
 var error_arr = new Array();
 var i = 0;
 
 if (!validRequired(theForm.answer,"answer")) {
  returnVal = false;
  error_arr[i] = "Answer\n";
  i++;
 }
 if (!validRequired(theForm.title,"title")) {
  returnVal = false;
  error_arr[i] = "Title\n";
  i++;
 }
 if (!validRequired(theForm.forename,"forename")) {
  returnVal = false;
  error_arr[i] = "Forename\n";
  i++;
 }
 if (!validRequired(theForm.surname,"surname")) {
  returnVal = false;
  error_arr[i] = "Surname\n";
  i++;
 }
 if (!validRequired(theForm.email,"email")) {
  returnVal = false;
  error_arr[i] = "Email\n";
  i++;
 }
 if (!validRequired(theForm.postcode,"postcode")) {
  returnVal = false;
  error_arr[i] = "Postcode\n";
  i++;
 }
 if (!validRequired(theForm.country,"country")) {
  returnVal = false;
  error_arr[i] = "Country\n";
  i++;
 }
 if (!theForm.newsletter.checked) {
  returnVal = false;
  error_arr[i] = "Please check the box to confirm you have read and accept the privacy statement.\n";
  i++;
 }
 
 if (error_arr.length > 0) {
  alertStr = "Please enter a value for the following fields:\n";
  for(var c=0; c<error_arr.length; c++) {
   alertStr += error_arr[c];
  }
  alert(alertStr);
 }
 
 // date checker
 if ((theForm.Day.value != "") || (theForm.Month.value != "") || (theForm.Year.value != "")) {
  var myDateStr = theForm.Month.value + "/" + theForm.Day.value + "/" + theForm.Year.value;
  if (myDateStr.length > 2) {
   //alert(isValidDate(myDateStr));
  }
 }
 
 return returnVal;
 
}
