var msg = "Highfield Cat Hotel - Booking"; 
var spacer = "         "; 
var pos = 0; 
function ScrollMessage() 
{ 
window.defaultStatus = msg.substring(pos, msg.length) + spacer + 
msg.substring(0,pos); 
} 
ScrollMessage(); 

function checkData()
{
if (document.booking.name.value == "")
{
alert("Please enter a contact name so we know who the booking is from");
document.booking.name.focus();
return false;
}

{
    if(document.booking.email.value.length == 0) { 
      document.booking.email.focus(); 
      alert("Please enter your email address in case we have to contact you"); 
      return false; 
      }

    if(-1 == document.booking.email.value.indexOf("@")) { 
       document.booking.email.focus(); 
       alert("Your email address must have a '@' character"); 
       return false; 
       }
    if(-1 != document.booking.email.value.indexOf(",")) { 
       document.booking.email.focus(); 
       alert("Your email address must not have a ',' in it"); 
       return false; 
       }
    if(-1 != document.booking.email.value.indexOf("#")) { 
       document.booking.email.focus(); 
       alert("Your email address must not have an '#' in it" ); 
       return false; 
       }
    if(-1 != document.booking.email.value.indexOf("!")) { 
       document.booking.email.focus(); 
       alert("Your email address must not have a '!' in it" ); 
       return false; 
       }
    if(-1 != document.booking.email.value.indexOf(" ")) { 
       document.booking.email.focus(); 
       alert("Your email address must not have a space in it" ); 
       return false; 
       }
    if(document.booking.email.value.length ==
         (document.booking.email.value.indexOf("@")+1) ) {
       document.booking.email.focus();
       alert("Your email address must have a domain name\r\n(hotmail.co.uk for example) after the '@'");
       return false;
       }
  }

if (document.booking.telephone.value == "")
{
alert("Please enter your telephone number so\r\nwe can confirm the booking with you.");
document.booking.telephone.focus();
return false;
}


if (document.booking.InDate.value == "click to change")
{
alert("Please enter a booking Check In date.");
document.booking.InDate.focus();
return false;
}
if (document.booking.OutDate.value == "click to change")
{
alert("Please enter a booking Check Out date.");
document.booking.OutDate.focus();
return false;
}
if (document.booking.cats_names.value == "")
{
alert("Please enter you cat(s) name(s).");
document.booking.cats_names.focus();
return false;
}
var chk_in = new Date(document.booking.InDate.value);
var chk_out = new Date(document.booking.OutDate.value);
if (chk_out <= chk_in)
{
alert("The Check Out date is before or equal to the\r\nCheck In date, please check your booking dates");
return false;
}

if (document.booking.web_cam.value == "Yes Please" && document.booking.webcam_dates.value == "")
{
alert("Please indicate the dates you would like the web cam for");
document.booking.webcam_dates.focus();
return false;
}
if (document.booking.web_cam.value == "Yes Please" && document.booking.webcam_pass.value == "")
{
alert("Please enter a user name and\r\npassword for access to the web cam");
document.booking.webcam_pass.focus();
return false;
}

// CheckBoxValue();
}

function CheckBoxValue(){
if(document.booking.confirmation.checked == true){
  document.booking.chk1.value = "YES PLEASE";
  } else {
  document.booking.chk1.value = "NO THANKYOU";
}
if(document.booking.webcam.checked == true){
  document.booking.chk2.value = "YES PLEASE";
  } else {
  document.booking.chk2.value = "NO THANKYOU";
}
}

function FillUser(){
document.booking.webcam_pass.value = "username, password";
}

function CalcDays(){

// cost per cat

var_dd = Date.parse(document.booking.InDate.value);
// var_ds = Date.parse("01 July 2005");

// if (var_dd >= var_ds) {
	var c = new Array(6.50, 10.50, 14.00, 17.20, 19.50, 0, 0, 0, 0, 0)
//   } else {
//    var c = new Array(4.95, 8.50, 11.30, 14.15, 16.00, 0, 0, 0, 0, 0)
// }
 var chk_in = new Date(document.booking.InDate.value);
 var chk_out = new Date(document.booking.OutDate.value);
 var no_days = chk_out-chk_in;
 if (Math.round(no_days/1000/60/60/24+1) >= 0)
 {
 var no_days = ""+Math.round(no_days/1000/60/60/24+1);
 }
 if (no_days <= 1) {AddDate()}
 document.booking.datefrom.value = document.booking.InDate.value;
 document.booking.dateto.value = document.booking.OutDate.value;
 var chk_in = new Date(document.booking.InDate.value);
 var chk_out = new Date(document.booking.OutDate.value);
 var no_days = chk_out-chk_in;
 if (Math.round(no_days/1000/60/60/24+1) >= 0)
 {
 var no_days = ""+Math.round(no_days/1000/60/60/24+1);
 }
 var noc = " cats in one cabin";
 if (document.booking.cat_number.value == 1) {noc = " cat"}
 if (document.booking.cat_number.value < 6)
 {
 document.booking.bookquote.value = " " + document.booking.cat_number.value + noc + " for " + no_days + " days will cost £"+(no_days*c[document.booking.cat_number.value-1]).toFixed(2)
 var dow=["Sun","Mon","Tues","Wed","Thurs","Fri","Sat","Sun"]
 document.booking.Indow.value = dow[chk_in.getDay()]
 document.booking.Outdow.value = dow[chk_out.getDay()]
 }
 if (document.booking.cat_number.value > 5)
 {
 document.booking.bookquote.value = " Please phone for the cost of more than 5 cats."
 }
 if (document.booking.cabin_number.value != 1)
 {
 document.booking.bookquote.value = " Please contact Helen if you need a quote."
 }
}

function ShowHideCam(retval,id){
    if (retval == "Yes Please"){
        document.getElementById(id).style.visibility = 'visible';
        document.getElementById(id).style.height = '65px';
        document.getElementById(id).style.display = 'block';
        document.booking.webcam_dates.value = document.booking.InDate.value.substring(0,6)+ " to "+document.booking.OutDate.value.substring(0,6);
    }
    else if (retval == "No Thankyou"){
        document.getElementById(id).style.visibility = 'hidden';
        document.getElementById(id).style.height = '0px';
        document.getElementById(id).style.display = 'none';
        document.booking.webcam_dates.value = "";
        document.booking.webcam_pass.value = "";
    }
}

function ShowHide(retval){
	var MyElement = document.getElementById('Myinput');
	if (retval == "Other") {MyElement.value="click to tell us how you found us"; MyElement.style.display = 'inline'; MyElement.focus(); MyElement.select();}
	if (retval != "Other") {MyElement.style.display = 'none'; MyElement.value=""}
}

function Clear(){
	var MyElement = document.getElementById('Myinput');
	if (MyElement.value == "click to tell us how you found us") {MyElement.value = ""}
}

function AddDate() {

var AddDays = 1;  //  How many days ahead of the current date
TDate = new Date(document.booking.InDate.value);
TMonth = new Array('Jan','Feb','March','April','May','June','July','Aug','Sep','Oct','Nov','Dec');
MonthDays = new Array('31', '28', '31', '30', 
'31', '30', '31', '31', '30', '31', '30', '31');
function isLeapYear (Year) {
if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) {
return true;
} 
else {
return false;
   }
}
CurYear = TDate.getYear();
if (CurYear < 2000)       // Y2K Fix, Isaac Powell
CurYear = CurYear + 1900; // http://onyx.idbsu.edu/~ipowell
CurMonth = TDate.getMonth();
CurDayOw = TDate.getDay();
CurDay = TDate.getDate();
month = TMonth[CurMonth];
if (month == 'February')  {
if (((CurYear % 4)==0) && ((CurYear % 100)!=0) || ((CurYear %
400)==0)) {
MonthDays[1] = 29;
}
else {
MonthDays[1] = 28;
   }
}
days = MonthDays[CurMonth];
CurDay += AddDays;
if (CurDay > days) {
if (CurMonth == 11) {
CurMonth = 0;
month = TMonth[CurMonth];
CurYear = CurYear + 1
}
else {
month = TMonth[CurMonth+1];
}
CurDay = CurDay - days;
}
CurDayOw += AddDays;
function adjustDay (cday) {
if (cday > 6) {
cday -= 6;
adjustDay(cday-1);
}
else {
return true;

   }
}
if (CurDay < 10) {CurDay = "0" + CurDay}
TheDate = CurDay + ' ';
TheDate += month + ' ';
if (CurYear<100) CurYear="19" + CurYear;
TheDate += CurYear;
document.booking.OutDate.value=TheDate;
}

function InIt() {

function makeArray() {
for (i = 0; i<makeArray.arguments.length; i++)
this[i + 1] = makeArray.arguments[i];
}
var months = new makeArray('Jan','Feb','March','April','May','June','July','Aug','Sep','Oct','Nov','Dec');
var date = new Date();
var day = date.getDate();
var month = date.getMonth() + 1;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
if (day < 10) {day = "0" + day}

  document.booking.InDate.value = (day + " " + months[month] + " " + year);
  AddDate();
  CalcDays();
}
