function validateHotel(theForm) {
var reason = "";
var clients = document.forms['orderhotel'].elements['guestsn'].value;

  reason += validateName(theForm.clientfname);
  reason += validateCountry(theForm.country);
  reason += validatePhone(theForm.clientphone);
  reason += validateEmail(theForm.clientemail);

  reason += validateDay(theForm.daya);
  reason += validateMonth(theForm.montha);
  reason += validateYear(theForm.yeara);
  reason += validateHour(theForm.timea);

  reason += validateDay(theForm.dayd);
  reason += validateMonth(theForm.monthd);
  reason += validateYear(theForm.yeard);
  reason += validateHour(theForm.timed);

  
  reason += validatePriceType(theForm.roomprice); 
  reason += validateRooms(theForm.nrooms);
  reason += validateNights(theForm.nnights);
  reason += validatePayment(theForm.payment);
  reason += validateClients(theForm.guestsn);
   if (clients > 1)
 {
  reason += validateGuestNames(theForm.otherguests);
 }

  
  
  
  if (reason != "") {
    alert("Some required fields are not filled out:\n" + reason);
    return false;
  }

   
}

function validateHour(fld)
{
error = "";
if (fld.value == 'no')
{
 fld.style.background = '#fcbf03'; 
  error = "- No hour selected\n";

}
else 
{
 fld.style.background = 'White';

}
return error;

}

function validateGuestNames()
{
var error = "";

 if (fld.value.length == 0)
 {
  fld.style.background = '#fcbf03'; 
  error = "- Guests names and citizenship\n";
 }
 else 
 {
  fld.style.background = 'White';
 }

 return error;
}

function validateName(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#fcbf03'; 
        error = "- Full Name\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function validatePriceType(fld) {
    var error = "";
 
    if (fld.value == 0) {
        fld.style.background = '#fcbf03'; 
        error = "- No room type selected\n";
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validatePayment(fld) {
    var error = "";
 
    if (fld.value == "no") {
        fld.style.background = '#fcbf03'; 
        error = "- No payment selected\n";
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateDay(fld) {
    var error = "";
 
    if (fld.value == "no") {
        fld.style.background = '#fcbf03'; 
        error = "- No day selected\n";
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateMonth(fld) {
    var error = "";
 
    if (fld.value == "no") {
        fld.style.background = '#fcbf03'; 
        error = "- No month selected\n";
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateYear(fld) {
    var error = "";
    
    if (fld.value == "no") {
        fld.style.background = '#fcbf03'; 
        error = "- No year selected\n";
    } 
    else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateCountry(fld) {
    var error = "";
    var country = document.getElementById("c").value;
    var bg = document.getElementById("c");
    if (country == "no") {
        bg.style.background = '#fcbf03'; 
        error = "- No country selected\n";
    } 
    else 
    {
        bg.style.background = 'White';
    }
    return error;  
}
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#fcbf03';
        error = "- Email address\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#fcbf03';
        error = "- Please enter a valid email address\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#fcbf03';
        error = "- The email address contains illegal characters\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
    var illegalChars = /[\a-z]/;
    if (fld.value == "") {
        fld.style.background = '#fcbf03';
        error = "- Phone\n";
    }  else if (isNaN(parseInt(stripped))) 
    {
        error = "- Phone must contain digits and + only\n";
        fld.style.background = '#fcbf03';
    }
    else if  (illegalChars.test(fld.value))
    {
        error = "- Phone must contain digits and + only\n";
        fld.style.background = '#fcbf03';
    }
    else if (stripped.length < 9) {
        error = "- Make sure you included country and city code.\n";
        fld.style.background = '#fcbf03';
    }
    else {
        fld.style.background = 'White';
    }
   return error;
}
function validateNights(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    
    var illegalChars = /[\W_a-z]/;
   if (fld.value == "") {
        error = "- Number of Nights\n";
        fld.style.background = '#fcbf03';
    }  
    else if (illegalChars.test(fld.value))
    {
      error = "- #Nights should be a number\n";
      fld.style.background = '#fcbf03';
    }
    else if (isNaN(parseInt(stripped))) {
        error = "- #Nights should be a number\n";
        fld.style.background = '#fcbf03';
    }
    else {
        fld.style.background = 'White';
    }

    return error;

}
function validateRooms(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    
    var illegalChars = /[\W_a-z]/;
   if (fld.value == "") {
        error = "- Number of Rooms\n";
        fld.style.background = '#fcbf03';
    }  
    else if (illegalChars.test(fld.value))
    {
      error = "- #Rooms should be a number\n";
      fld.style.background = '#fcbf03';
    }
    else if (isNaN(parseInt(stripped))) {
        error = "- #Rooms should be a number\n";
        fld.style.background = '#fcbf03';
    }
    else {
        fld.style.background = 'White';
    }

    return error;

}
function validateClients(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    
    var illegalChars = /[\W_a-z]/;
   if (fld.value == "") {
        error = "- Number of Guests\n";
        fld.style.background = '#fcbf03';
    }  
    else if (illegalChars.test(fld.value))
    {
      error = "- #Guests should be a number\n";
      fld.style.background = '#fcbf03';
    }

    else if (isNaN(parseInt(stripped))) {
        error = "- #Guests should be a number\n";
        fld.style.background = '#fcbf03';
    }
    else {
        fld.style.background = 'White';
    }

    return error;

}

function showRoomList()
{
var browser=navigator.appName;
var clients = document.forms['ordertour'].elements['nclients'].value;
var roomlist = document.getElementById('rlist');
var fulln = document.getElementById('fulln');
var opts = document.getElementById('opts');
var link = document.getElementById('link');
var oguest = document.getElementById('oguest');
var notIE = document.getElementById('notIE');
if (browser != 'Microsoft Internet Explorer') 
    {

if (clients > 1)
{
document.forms["ordertour"].elements["roomlist"].value="Yes";
document.forms["ordertour"].elements["ni"].value=1;
roomlist.style.display = "block";
link.style.display = "block";
oguest.style.display = "block";
notIE.style.display = "block";
}
}
else //this is IE 
{
if (clients > 1)
{
document.forms["ordertour"].elements["roomlist"].value="Yes";
document.forms["ordertour"].elements["ni"].value=1;
document.getElementById("IE").value='Yes';
roomlist.style.display = "block";
fulln.style.display = "block";
opts.style.display = "block";
link.style.display = "block";
oguest.style.display = "block";
}
}
}



