<!--

// Handle Hotel Booking Date Ranges //

// you may use/modify this code, but please give credit as a courtesy
// script by Arash Ramin (http://www.digitalroom.net)

function setCheckInDate() {
  
  // changes the date selector menus to the current date
  var checkInDate = new Date();

  document.theform.CheckInYear.selectedIndex = 0;
  document.theform.CheckInMonth.selectedIndex = checkInDate.getMonth();

  setCIDays();  
  document.theform.CheckInDay.selectedIndex = checkInDate.getDate() - 1;

}

function setCheckOutDate() {
  
  // changes the date selector menus to 2 days AFTER current date
  var checkOutDate = new Date();
  
  checkOutDate.setDate(checkOutDate.getDate() + 2);

  document.theform.CheckOutYear.selectedIndex = 0;
  document.theform.CheckOutMonth.selectedIndex = checkOutDate.getMonth();

  setCODays();  
  document.theform.CheckOutDay.selectedIndex = checkOutDate.getDate() - 1;

}

function setCIDays() {

  var y = document.theform.CheckInYear.options[document.theform.CheckInYear.selectedIndex].value;
  var m = document.theform.CheckInMonth.selectedIndex;
  var d;

  // find number of days in current CheckInMonth
  if ( (m == 3) || (m == 5) || (m == 8) || (m == 10) ) {
    days = 30;
  }
  else if (m == 1) {
    // check for leapyear - Any CheckInYear divisible by 4, except those divisible by 100 (but NOT 400)
    if ( (Math.floor(y/4) == (y/4)) && ((Math.floor(y/100) != (y/100)) || (Math.floor(y/400) == (y/400))) )
      days = 29
    else
      days = 28
  }
  else {
    days = 31;
  }


  // if (days in new CheckInMonth > current days) then we must add the extra days
  if (days > document.theform.CheckInDay.length) {
    for (i = document.theform.CheckInDay.length; i < days; i++) {
      document.theform.CheckInDay.length = days;
      document.theform.CheckInDay.options[i].text = i + 1;
      document.theform.CheckInDay.options[i].value = i + 1;
    }
  }

  
  // if (days in new CheckInMonth < current days) then we must delete the extra days
  if (days < document.theform.CheckInDay.length) {
    document.theform.CheckInDay.length = days;
    if (document.theform.CheckInDay.selectedIndex == -1) 
      document.theform.CheckInDay.selectedIndex = days - 1;
  }

}

function setCODays() {

  var y = document.theform.CheckOutYear.options[document.theform.CheckOutYear.selectedIndex].value;
  var m = document.theform.CheckOutMonth.selectedIndex;
  var d;

  // find number of days in current CheckInMonth
  if ( (m == 3) || (m == 5) || (m == 8) || (m == 10) ) {
    days = 30;
  }
  else if (m == 1) {
    // check for leapyear - Any CheckInYear divisible by 4, except those divisible by 100 (but NOT 400)
    if ( (Math.floor(y/4) == (y/4)) && ((Math.floor(y/100) != (y/100)) || (Math.floor(y/400) == (y/400))) )
      days = 29
    else
      days = 28
  }
  else {
    days = 31;
  }


  // if (days in new CheckInMonth > current days) then we must add the extra days
  if (days > document.theform.CheckOutDay.length) {
    for (i = document.theform.CheckOutDay.length; i < days; i++) {
      document.theform.CheckOutDay.length = days;
      document.theform.CheckOutDay.options[i].text = i + 1;
      document.theform.CheckOutDay.options[i].value = i + 1;
    }
  }

  
  // if (days in new CheckInMonth < current days) then we must delete the extra days
  if (days < document.theform.CheckOutDay.length) {
    document.theform.CheckOutDay.length = days;
    if (document.theform.CheckOutDay.selectedIndex == -1) 
      document.theform.CheckOutDay.selectedIndex = days - 1;
  }

}

///////////////////////////////////

// auto fill Access Code w/ value from Discount Code Drop Down
function fillText() {
document.freestyle.P_ACCESSCODE.value=document.freestyle.P_DISCOUNTCODE.value;
}


function checkDateRange(userDate) {
  var firstPos
  var intMonth
  var intDay
  var intYear
  var timeDiff
  
  //Check for date string with 8 chars (m/d/yyyy)
  if (userDate.length == 8) {
	  intMonth = userDate.substring(0,1)
	  intDay = userDate.substring(2,3)
	  intYear = userDate.substring(4,8)
	  
	  now = new Date;
	  user = new Date(intYear,(intMonth-1),intDay,23,00,00);
	  
	  //check to see if date is less then current
	  if (user.getTime() < now.getTime()) {
         document.freestyle.P_ARRIVEDATE.style.backgroundColor = "#ffcccc"
         Message1.innerText = "Your arrival date cannot be less then today's date."
		 return false;
	  } else {
	     //check to see if date entered is past the 10 month cutoff.
		 //26006400000: this is the number of Milliseconds in 301 days
		 //formula to get Milliseconds in a day (((1000*60)*60)*24)
		 // timeDiff = (user.getTime() - now.getTime())    
// 		 if (timeDiff > 26006400000) {
//            document.freestyle.P_ARRIVEDATE.style.backgroundColor = "#ffcccc"
//            Message1.innerText = "You are not allowed to book rooms that far in advance."
// 		   return false;
// 		 } else {
		   return true; 
		 //}//if
	  }//if
  }//if
 
  //Check for date string with 10 chars (mm/dd/yyyy)
  if (userDate.length == 10) {
	  intMonth = userDate.substring(0,2)
	  intDay = userDate.substring(3,5)
	  intYear = userDate.substring(6,10)
	  
	  now = new Date;
	  user = new Date(intYear,(intMonth-1),intDay,23,00,00);
	  
	  //check to see if date is less then current
	  if (user.getTime() < now.getTime()) {
         document.freestyle.P_ARRIVEDATE.style.backgroundColor = "#ffcccc"
         Message1.innerText = "Your arrival date cannot be less then today's date."
		 return false;
	  } else {
	     //check to see if date entered is past the 10 month cutoff.
		 //26006400000: this is the number of Milliseconds in 301 days
		 //formula to get Milliseconds in a day (((1000*60)*60)*24)
		//  timeDiff = (user.getTime() - now.getTime())    
// 		 if (timeDiff > 26006400000) {
//            document.freestyle.P_ARRIVEDATE.style.backgroundColor = "#ffcccc"
//            Message1.innerText = "You are not allowed to book rooms that far in advance."
// 		   return false;
// 		 } else {
		   return true; 
		 //}//if
	  }//if
  }//if

  //Check for date string with 9 chars (mm/d/yyyy or m/dd/yyyy)
  if (userDate.length == 9) {
      firstPos = userDate.indexOf('/');
	  
	  //Check pos of 1st slash to determine exact positions of date values
	  //POS = 2 is format (mm/d/yyyy)
	  if (firstPos==2) {
	     intMonth = userDate.substring(0,2)
	     intDay = userDate.substring(3,4)
	     intYear = userDate.substring(5,9)
	  }//if

	  //Check pos of 1st slash to determine exact positions of date values
	  //POS = 1 is format (m/dd/yyyy)
	  if (firstPos==1) {
	     intMonth = userDate.substring(0,1)
	     intDay = userDate.substring(2,4)
	     intYear = userDate.substring(5,9)
	  }//if
	  
	  now = new Date;
	  user = new Date(intYear,(intMonth-1),intDay,23,00,00);
	  
	  //check to see if date is less then current
	  if (user.getTime() < now.getTime()) {
         document.freestyle.P_ARRIVEDATE.style.backgroundColor = "#ffcccc"
         Message1.innerText = "Your arrival date cannot be less then today's date."
		 return false;
	  } else {
	     //check to see if date entered is past the 10 month cutoff.
		 //26006400000: this is the number of Milliseconds in 301 days
		 //formula to get Milliseconds in a day (((1000*60)*60)*24)
		 // timeDiff = (user.getTime() - now.getTime())    
// 		 if (timeDiff > 26006400000) {
//            document.freestyle.P_ARRIVEDATE.style.backgroundColor = "#ffcccc"
//            Message1.innerText = "You are not allowed to book rooms that far in advance."
// 		   return false;
// 		 } else {
		   return true; 
		 //}//if
	  }//if
  }//if
}

function validateForm(form) {
  if ( (dateCheck(form.P_ARRIVEDATE.value,'%m/%d/%yyyy')) ) {
       form.P_ARRIVEDATE.style.backgroundColor = "#ffffff"
       Message1.innerText = " "
     
	   if (checkDateRange(form.P_ARRIVEDATE.value)==false) {
	      return false;
	   } else {
		  return true;
	   }//if
	
  } else {
       form.P_ARRIVEDATE.style.backgroundColor = "#ffcccc"
       Message1.innerText = "Invalid Date Format.  Please use (m/d/yyyy)."
       form.P_ARRIVEDATE.focus()
       form.P_ARRIVEDATE.select()
       return false;
  }//if   
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function openNewWindow(URLtoOpen, windowName, windowFeatures) { 
  newWindow=window.open(URLtoOpen, windowName, windowFeatures);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->