window.onerror=displaySorry
function displaySorry(message,url,line)
{
 var msg="There has been a scripting error."
 msg+="Please contact dave@reflections-photographic.co.uk"
 msg+="Reference file: " + url
 alert(msg)
 return true
}

function validate()
{
 if ( isEmpty(document.modelinfo.aname.value) )
 {
  alert("Error : You haven't entered your name. You don't need to enter a full name, just a forename will do if you wish.")
  return false
 }
 if ( isEmpty(document.modelinfo.b1addr.value) &&
      isEmpty(document.modelinfo.b2addr.value) )
 {
  alert("If I don't know where you live, it makes it a bit harder for me to make arrangements. Please enter at very least the town or city you live in, and maybe also your county.")
  return false
 }
 if (!(isEmpty(document.modelinfo.b1addr.value)))
 {
  if ( document.modelinfo.b1addr.value == "LONDON" || document.modelinfo.b1addr.value == "London" || document.modelinfo.b1addr.value == "london" )
  {
   alert("London is a big place, can you be a bit more specific please. It's probably better if you put London as your county, and the area of London as the town.")
   return false
  }
  if ( document.modelinfo.b1addr.value == "BIRMINGHAM" || document.modelinfo.b1addr.value == "Birmingham" || document.modelinfo.b1addr.value == "birmingham" )
  {
   alert("Birmingham is a big place, can you be a bit more specific please. It's probably better if you put Birmingham as your county, and the area of Birmingham as the town.")
   return false
  }
  if ( document.modelinfo.b1addr.value == "MANCHESTER" || document.modelinfo.b1addr.value == "Manchester" || document.modelinfo.b1addr.value == "manchester" )
  {
   alert("Manchester is a big place, can you be a bit more specific please. It's probably better if you put Manchester as your county, and the area of Manchester as the town.")
   return false
  }
  if ( document.modelinfo.b1addr.value == "GLASGOW" || document.modelinfo.b1addr.value == "Glasgow" || document.modelinfo.b1addr.value == "glasgow" )
  {
   alert("Glasgow is a big place, can you be a bit more specific please. It's probably better if you put Glasgow as your county, and the area of Glasgow as the town.")
   return false
  }
 }

 if ( document.modelinfo.b3addr.value == "x" )
 {
  alert("You must select your country, either England, Scotland or Wales. If you do not live in any of these, sorry but we cannot help you.")
  return false
 }

 if ( isEmpty(document.modelinfo.hdob.value))
 {
  alert("Your date of birth is mandatory as I can only take people over the age of 16. Note that 16 and 17 year olds will need written parental permission.")
  return false
 }

 if ( isEmpty(document.modelinfo.cday.value) &&
      isEmpty(document.modelinfo.deve.value) &&
      isEmpty(document.modelinfo.emob.value) &&
      document.modelinfo.mailfrom.value == "" )
 {
  alert("ERROR : You haven't entered any way of being contacted. You must enter your email address and should also enter at least one phone number. If you don't want me to contact you, you will need to contact me either by email directly, or by phone. See the contacts page for further information.")
  return false
 }

 if ( isEmpty(document.modelinfo.cday.value) &&
      isEmpty(document.modelinfo.deve.value) &&
      isEmpty(document.modelinfo.emob.value) )
 {
  if (!confirm("Warning : You haven't entered any phone numbers, ideally you should enter at least one.\nContinue anyway?"))
  {
   return false
  }
 }

 if (!(isEmpty(document.modelinfo.cday.value)))
 {
  if (!(isPhoneNumber(document.modelinfo.cday.value)))
  {
   alert("Error : The number you have entered as a daytime phone number is not a valid phone number")
   return false
  }
 }

 if (!(isEmpty(document.modelinfo.deve.value)))
 {
  if (!(isPhoneNumber(document.modelinfo.deve.value)))
  {
   alert("Error : The number you have entered as an evening phone number is not a valid phone number")
   return false
  }
 }

 if (!(isEmpty(document.modelinfo.emob.value)))
 {
  if (!(isPhoneNumber(document.modelinfo.emob.value)))
  {
   alert("Error : The number you have entered as a mobile phone number is not a valid phone number")
   return false
  }
 }

 if ( isEmpty(document.modelinfo.mailfrom.value) )
 {
  alert("Error : You haven't entered an email address.")
  return false
 }
 if ( isEmpty(document.modelinfo.cemail.value) || (document.modelinfo.mailfrom.value != document.modelinfo.cemail.value) )
 {
  alert("Email values do not match.")
  return false
 }
 return true
}

function isEmpty(inputStr)
{
 if ( inputStr == null || inputStr == "" ) { return true }
 return false
}

function isPhoneNumber(inputNum)
{
 for ( var i=0; i < inputNum.length; i++ )
 {
  var oneChar=inputNum.charAt(i)
  if (!(oneChar == " ")) { if (oneChar < "0" || oneChar > "9") { return false } }
 }
 var re = /^0[127]/
 if (!re.exec(inputNum)) { return false }
 return true
}
