<!--

function availwindow()
{
  var myform = document.forms.resRequest;
  check_year = myform.a_year.value;
  check_month = myform.a_month.value;
  
  awindow = window.open ('./availability.php?check_year='+check_year+'&check_month='+check_month, 'Availability', 'toolbar=no, width=800, height=300, status=no, scrollbars=yes, resizable=yes, menubar=no, directories=no, top=40, left=40');
  awindow.focus();  
}

function policieswindow()
{
pwindow=window.open('./popups/policies.html','Policies','toolbar=no,width=500,height=550,status=no,scrollbars=yes,resizable=yes,menubar=no,directories=no,top=40,left=40');
pwindow.focus();
}

function occasionswindow()
{
owindow=window.open('./occasions/occasions.html','Barristers Special Occasions','toolbar=no,width=500,height=550,status=no,scrollbars=yes,resizable=yes,menubar=no,directories=no,top=40,left=40');
owindow.focus();
}


function roomwindow(roomtype)
{
    if (roomtype == "country")
  {  rwindow=window.open('./popups/country-room.html','CountryRoom','toolbar=no,width=250,height=275,status=no,scrollbars=no,resizable=yes,menubar=no,directories=no,top=300,left=300');
    rwindow.focus();
  }
   else if (roomtype == "laura")
  { 
rwindow=window.open('./popups/laura-room.html','LauraRoom','toolbar=no,width=250,height=275,status=no,scrollbars=no,resizable=yes,menubar=no,directories=no,top=300,left=300');
    rwindow.focus();  
  }  
   else if (roomtype == "oriental")
  {
 rwindow=window.open('./popups/oriental-room.html','OrientalRoom','toolbar=no,width=250,height=275,status=no,scrollbars=no,resizable=yes,menubar=no,directories=no,top=300,left=300');
    rwindow.focus(); 
  } 
    
}

function getDaysInMonth(month,year)  
{
var days=31;

  if ((month == 4) || (month == 6) || (month == 9) || (month == 11))
  {
    days=30;
  }
  else if (month == 2)
  {
    (((year % 4)==0) && ((year % 100)!=0) || ((year % 400)==0)) ? days = 29 : days = 28;
  }

  return days;
}

function checkDate(month, day, year)
{
  if (getDaysInMonth(month, year) < day)
  {
    return false;
  }
  return true;
}

function validate()
{
  var myform = document.forms.resRequest;

  var aMonth = parseInt(myform.a_month.value);
  var aDay  = parseInt(myform.a_day.value);
  var aYear = parseInt(myform.a_year.value);

  var dMonth = parseInt(myform.d_month.value);
  var dDay  = parseInt(myform.d_day.value);
  var dYear = parseInt(myform.d_year.value);

  var time   = new Date();
  var cMonth = time.getMonth() + 1;
  var cDay   = time.getDate();
  var cYear  = time.getYear();
    
  if (myform.firstName.value.length < 1) 
  {
    alertMsg = "Please enter your first name.";
    alert(alertMsg);
    myform.firstName.focus();
    return false;
  }
  if (myform.lastName.value.length < 1) 
  {
    alertMsg = "Please enter your last name.";
    alert(alertMsg);
    myform.lastName.focus();
    return false;
  }
  if (myform.email.value.length < 1)
  {
    alertMsg = "Please enter an email address so we can respond to your request.";
    alert(alertMsg);
    myform.email.focus();
    return false;
  }
  if (checkEmail(myform.email.value) != true) 
  {
    alertMsg = "Invalid email address - please re-enter.";
    alert(alertMsg);
    myform.email.focus();
    return false;
  }
//  if (myform.email_reentered.value.length < 1)
//  {
//   alertMsg = "Please confirm your email address to verify correct entry.";
//    alert(alertMsg);
//    myform.email_reentered.focus();
//    return false;
//  }
//  if (myform.email.value != myform.email_reentered.value)
//  {
//    alertMsg = "Entered email addresses differ - please correct.";
//    alert(alertMsg);
//    myform.email.focus();
//    return false;
//  }

  if ((cYear > aYear) ||
      ((cYear == aYear) &&
       (cMonth > aMonth)) ||
      ((cYear == aYear) &&
       (cMonth == aMonth) &&
       (cDay >= aDay)))
  {
    alertMsg = "Please enter an arrival date after today.";
    alert(alertMsg);
    myform.a_month.focus();
    return false;
  }

  if (checkDate(myform.a_month.value, myform.a_day.value, myform.a_year.value) == false)
  {
    alertMsg = "There are not that many days in the arrival month you chose - please correct.";
    alert(alertMsg);
    myform.a_day.focus();
    return false;
  }
  if (checkDate(myform.d_month.value, myform.d_day.value, myform.d_year.value) == false)
  {
    alertMsg = "There are not that many days in the departure month you chose - please correct.";
    alert(alertMsg);
    myform.d_day.focus();
    return false;
  }
  if ((aYear > dYear) ||
      ((aYear == dYear) &&
       (aMonth > dMonth)) ||
      ((aYear == dYear) &&
       (aMonth == dMonth) &&
       (aDay >= dDay)))
  {
    alertMsg = "Please enter a departure date that is after your selected arrival date.";
    alert(alertMsg);
    myform.d_month.focus();
    return false;
  }
  if (!(myform.rp_read.checked))
  {
    alertMsg = "Please check that you have read the policies.";
    alert(alertMsg);
    return false;
  }
  
  return true;

//End validate()
}

function checkEmail(str) 
{
  var at="@";
  var dot=".";
  var lat=str.indexOf(at);
  var lstr=str.length;
  var ldot=str.indexOf(dot);

  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr-1)
  {
     return false;
  }

  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr-1)
  {
      return false;
  }

  if (str.indexOf(at,(lat+1))!=-1)
  {
      return false;
  }

  if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
  {
      return false;
  }

  if (str.indexOf(dot,(lat+2))==-1)
  {
     return false;
  }
		
  if (str.indexOf(" ")!=-1)
  {
     return false;
  }

  return true;
}

function resetPage(pageTitle)
{
  var myform = document.forms.resRequest;
  
  if (pageTitle == "Reservations")
  {
    if ((myform.how_found.value != "Other") &&
        (myform.how_found.value != "Other web site"))
    {
      hideDiv('other_info');
      hideDiv('other_text');
    }
    myform.other_details.value = "";
    document.forms.resRequest.firstName.focus();
  }
}

function on(imageName)
{
  if (document.images)
  {
    document.images[imageName].src = eval(imageName+"on.src");
  }
}

function checkOther()
{
  var myform = document.forms.resRequest;

  if ((myform.how_found.value == "Other") ||
      (myform.how_found.value == "Other web site"))
  {
    showDiv('other_info');
    showDiv('other_text');
  }
  else
  {
    hideDiv('other_info');
    hideDiv('other_text');
  }
}

function showDiv(id)
{
  document.getElementById(id).style.display = "block";
}

function hideDiv(id)
{
  document.getElementById(id).style.display = "none";
}

function updateDepart()
{
  var myform = document.forms.resRequest;

  var tmpMonth = parseInt(myform.a_month.value);
  var tmpDay = parseInt(myform.a_day.value) + 1;
  var tmpYear = parseInt(myform.a_year.value);

  if (checkDate(tmpMonth, tmpDay, tmpYear) == false)
  {
    tmpMonth = parseInt(tmpMonth) + 1;
    tmpDay = 1;
    if (tmpMonth == 13)
    {
      tmpMonth = 1;
      tmpYear = parseInt(tmpYear) + 1;
    }
  }

  myform.d_month.value = tmpMonth;
  myform.d_day.value   = tmpDay;
  myform.d_year.value  = tmpYear;

}

function setDefaultArrivalDate()
{
  var myform = document.forms.resRequest;

  var time   = new Date();
  var tmpMonth = time.getMonth() + 1;
  var tmpDay = time.getDate() + 1;
  var tmpYear = time.getYear();

  if (checkDate(tmpMonth, tmpDay, tmpYear) == false)
  {
    tmpMonth = parseInt(tmpMonth) + 1;
    tmpDay = 1;
    if (tmpMonth == 13)
    {
      tmpMonth = 1;
      tmpYear = parseInt(tmpYear) + 1;
    }
  }
  
  myform.a_month.value = tmpMonth;
  myform.a_day.value   = tmpDay;
  myform.a_year.value  = tmpYear;
  
  updateDepart();
}


//-->
