function isEmpty(s)
{ return ((s == null) || (s.length == 0)) }

function isWhitespace (s) {
  var i;
  var whitespace = " \t\n\r";

  if (isEmpty(s)) return true;

  for (i = 0; i < s.length; i++) {
    // Check that current character isn't whitespace.
    var c = s.charAt(i);
    if (whitespace.indexOf(c) == -1) return false;
  }
  return true;
}

function inValidCharSet(str,charset) {
  var result=true;
  
  for (var i=0;i<str.length;i++)
    if (charset.indexOf(str.substr(i,1))<0)
    {
      result=false;
      break;
    }
  
  return result;
}

function allDigits(str) {
  return inValidCharSet(str,"0123456789");
}

function checkEmail(s)
{
  var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
  if (filter.test(s)) return true;
  else return false;
}

function chkRadio(oRadio) {
  var j
  var choice=''

  for (j=0; j<oRadio.length; j++) {
    if (oRadio[j].checked) {
     choice=oRadio[j].value;
      break;
    }
  }
  return choice;
}

function booking_validate()
{
  var submit=true;
  var errorlist='';

  if (document.frmThisPage.name.value=="") {errorlist=errorlist + "Name\n"; submit=false};
  if (document.frmThisPage.emailaddress.value=="") {errorlist=errorlist + "Email Address\n"; submit=false};
  if (document.frmThisPage.emailaddress.value!="") {if (!checkEmail(document.frmThisPage.emailaddress.value)) {errorlist=errorlist + "A valid Email Address\n"; submit=false}; };
  if (document.frmThisPage.streetaddress.value=="") {errorlist=errorlist + "Street Address\n"; submit=false};
  if (document.frmThisPage.city.value=="") {errorlist=errorlist + "City\n"; submit=false};
  if (document.frmThisPage.country.value=="") {errorlist=errorlist + "Country\n"; submit=false};
  if (document.frmThisPage.phone.value=="") {errorlist=errorlist + "Telephone Number\n"; submit=false};
  if (document.frmThisPage.numberadults.value=="") {errorlist=errorlist + "Number of Adults\n"; submit=false};
  if (document.frmThisPage.numberchildren.value=="") {errorlist=errorlist + "Number of Children\n"; submit=false};

  if (!dateCheck(document.frmThisPage.arrivaldate.value,'%dd/%mm/%yyyy')) {errorlist=errorlist + "A valid Arrival Date\n"; submit=false};
  if (!dateCheck(document.frmThisPage.departuredate.value,'%dd/%mm/%yyyy')) {errorlist=errorlist + "A valid Departure Date\n"; submit=false};

  if (!submit) {alert('Please supply information in the following field/s before sending us your booking:\n\n' + errorlist)};

return submit
}

function contact_validate()
{
  var submit=true;
  var errorlist='';

  if (document.frmThisPage.name.value=="") {errorlist=errorlist + "Name\n"; submit=false};
  if (document.frmThisPage.emailaddress.value=="") {errorlist=errorlist + "Email Address\n"; submit=false};
  if (document.frmThisPage.emailaddress.value!="") {if (!checkEmail(document.frmThisPage.emailaddress.value)) {errorlist=errorlist + "A valid Email Address\n"; submit=false}; };
  if (document.frmThisPage.phone.value=="") {errorlist=errorlist + "Telephone Number\n"; submit=false};
  if (document.frmThisPage.streetaddress.value=="") {errorlist=errorlist + "Street Address\n"; submit=false};
  if (document.frmThisPage.city.value=="") {errorlist=errorlist + "City\n"; submit=false};
  if (document.frmThisPage.country.value=="") {errorlist=errorlist + "Country\n"; submit=false};

  if (!submit) {alert('Please supply information in the following field/s before sending us your questions or comments:\n\n' + errorlist)};

return submit
}
