 $(document).ready(function() {
   $("#errorMsg").hide();
 });


var continueTo = "";

function callIRM()
{	
   
   continueTo = "";
   url ="";
   var ResortID = document.getElementById('ResortID').value;
   var url = "http://irmestore.bigwhitesilverstar.com/irmnet/res/resmain.aspx?";
   var foundOne = false;
     
   if (ResortID!='*') { 
   		url = url + 'Resort=' + ResortID + '&';}

	
	//Add guest requets if selected
    //These must correspond to GuestRequest1-9 values

   var adult = document.getElementById("People1");
   var youth = document.getElementById("People2");
   var child = document.getElementById("People3");
   var tot = document.getElementById("People4");
   var roomType = document.getElementById("RoomTypes");
   
   if (roomType != "*")
   {
		url = url + "RoomType=" + roomType.value;
		foundOne = true;
   }
  
   //Add arrival and departure dates if selected 
   var arrival = document.getElementById("wdcArrival_input").value;
   var departure = document.getElementById("wdcDeparture_input").value;
   if (arrival != "") 
   {
      //verify that arrival choice is not in the past
      if (new Date(arrival) < new Date("12/04/2010"))
      {
         sendMsg("Arrival date must be between December 4th, 2010 and April 9, 2011.\nPlease change your calendar dates and try again.");
      }
      
	  if (departure != "") 
      {

         //verify departure > arrival
         var nights = calcNights(arrival, departure);
         if (nights <= 0 )
         {
            sendMsg("Departure date must be later than arrival date.\nPlease change your calendar dates and try again.");
         }
         //additional checking
         if (nights > 10)   // for example enforce a maximum stay
         {
            sendMsg("Online Reservations cannot be made for more than a 10 night stay.\nPlease change your calendar dates, or call us about your extended stay.\nThank You");
         }
      }
      
      if (foundOne) url = url + "&";
      url = url + "Arrival=" + arrival;
      foundOne = true;      
      if (departure != "") 
      { url = url + "&Departure=" + departure; }
      else   // use default number of nights
      { url = url + "&Nights=" + numberNights; }
      
      
   }
   
   //Nothing was selected, get all rooms
   if (!foundOne) url = url + "AllRooms=true";
   //alert(url);   

	url = url + "&People1=" + adult.value;
    if (youth != "0") url = url + "&People2=" + youth.value;
	if (child != "0") url = url + "&People3=" + child.value;
	if (tot != "0") url = url + "&People4=" + tot.value;

  //parent.ifrme.location.href = url;
   if (!continueTo) window.open(url);
   
}  //callIRM


function sendMsg (msg)
{
	document.getElementById("errorMsg").innerHTML = '<div style="background-color: #FFF">' + msg + '</div>';
	//document.getElementById('errorMsg').innerHTML = 'Fred Flinstone';

	$("#errorMsg").fadeIn(500);
		$(this).delay(4000,function(){
		$("#errorMsg").fadeOut(500);
	});
		
	continueTo = "false";
	
	return false;
}

function calcNights(arrival, departure)
{   
    var arrDate = arrival.split("/");
    var depDate = departure.split("/");
   	var newArrDate = new Date(arrDate[0]+"/"+arrDate[1]+"/"+arrDate[2]);
	var newDepDate = new Date(depDate[0]+"/"+depDate[1]+"/"+depDate[2]);
	var numNights = (Math.round((newDepDate-newArrDate)/86400000));
	return numNights;
}		

// Get today's current date. 
var now = new Date();


// Array list of months.
var months = new Array('01','02','03','04','05','06','07','08','09','10','11','12');

// Calculate four digit year.
function fourdigits(number)	{
	return (number < 1000) ? number + 1900 : number;
	}
	

//Get actual values for date and month from DOM, For security purposes of demo year is not set to current//
var nowdate = 01;   //now.getDate();
var nowmonth = 2;  //now.getMonth(); // 2 = March see months array above//
var nowyear = 1998;

//For use with demo -will set the default departure date to x number of days ahead of arrival - remove or comment out for current date functionality;
var arr = 0;
var dep = 2;

function checkDate (m, d, y, field){
	//var maxDays = DaysInMonth(m, y);
	var newDay = d + field;
	var newMonth = months[m];
	var newYear = fourdigits(y);

	var fieldDate = newMonth + "/" +
					newDay + "/" +
					newYear;
	return fieldDate;
	}

// default arrival and departure dates	
var arrivalDate = checkDate(nowmonth, nowdate, nowyear, arr);
var departureDate = checkDate(nowmonth, nowdate, nowyear, dep);
//sets default number of nights
var numberNights = calcNights(arrivalDate, departureDate); 


function propertyChoose (){
	ResortID = document.getElementById('ResortID').value;
		
	switch (ResortID)
	{
	case '01':
		frmHTML = 'Type: <select name="RoomTypes" id="RoomTypes" tabindex="18" class="DropDownFrame" style="font-size:8.5pt;height:20px;width:130px;">' +
			'<option selected="selected" value="ALL">All Room Types</option>' +
			'<option value="BUD">BUDGET</option>' +
			'<option value="KIT">KITCHENETTE</option>' +
			'<option value="STU">STUDIO</option>' +
			'<option value="STUP">STUDIO PREM</option>' +
			'<option value="1BS">ONE BDRM STANDARD</option>' +
			'<option value="1BR">ONE BDRM REGULAR</option>' +
			'<option value="1BP">ONE BDRM PREMIUM</option>' +
			'<option value="1BPH">ONE BDRM PREM - HOTTUB</option>' +
			'<option value="1BXH">ONE BDRM EXE - HOTTUB</option>' +
			'<option value="1BPP">ONE BDRM PREM PLUS</option>' +
			'<option value="2BS">TWO BDRM STANDARD</option>' +
			'<option value="2BR">TWO BDRM REGULAR</option>' +
			'<option value="2BP">TWO BDRM PREMIUM</option>' +
			'<option value="2BPH">TWO BDRM PREM - HOTTUB</option>' +
			'<option value="2BX">TWO BDRM EXECUTIVE</option>' +
			'<option value="2BXH">TWO BDRM EXE - HOTTUB</option>' +
			'<option value="2VHH">TWO BDRM VACATION HOTTUB</option>' +
			'<option value="2BPP">TWO BDRM PREM PLUS</option>' +
			'<option value="2BPPH">TWO BDRM PREM PL HOTTUB</option>' +
			'<option value="2BXPH">TWO BDRM EXEC PL HOTTUB</option>' +
			'<option value="3BR">THREE BEDROOM REGULAR</option>' +
			'<option value="3BPH">THREE BDRM PREM HOTTUB</option>' +
			'<option value="3VHH">THREE BDRM VAC HOTTUB</option>' +
			'<option value="3BPPH">THREE BDRM PREM PLUS HT</option>' +
			'<option value="3VHPH">THREE BDRM VAC PLU HT</option>' +
			'<option value="4BR">FOUR BEDROOM REGULAR</option>' +
			'<option value="4BPH">FOUR BDRM PREM - HOTTUB</option>' +
			'<option value="4VHPH">FOUR BDRM VAC PL HOTTUB</option>' +
		'</select>';
		document.getElementById('frmRoomType').innerHTML = frmHTML;
	break;

	case '02':
		frmHTML = 'Type: <select name="RoomTypes" id="RoomTypes" tabindex="18" class="DropDownFrame" style="font-size:8.5pt;height:20px;width:130px;">' +
			'<option selected="selected" value="ALL">All Room Types</option>' +
			'<option value="STANDR">STANDARD</option>' +
			'<option value="STANDH">STANDARD HIDE-A-BED</option>' +
			'<option value="SUPR-K">SUPERIOR KIT-2 QUEEN </option>' +
			'<option value="SUPRKQ">SUPERIOR KIT-QUEEN</option>' +
			'<option value="SUPRKH">SUPERIOR KIT-QUEEN & HB</option>' +
			'<option value="SUPRMH">SUPERIOR KIT- MURPHY/HB </option>' +
			'<option value="LFT">LOFT BASIC</option>' +
			'<option value="LFTP">LOFT PREMIUM</option>' +
			'<option value="1BR-P">ONE BEDROOM PLUS</option>' +
			'<option value="2BP">TWO BEDROOM PREMIUM</option>' +
		'</select>';
		document.getElementById('frmRoomType').innerHTML = frmHTML;
	break;

	case '03':
		frmHTML = 'Type: <select name="RoomTypes" id="RoomTypes" tabindex="18" class="DropDownFrame" style="font-size:8.5pt;height:20px;width:130px;">' +
			'<option selected="selected" value="ALL">All Room Types</option>' +
			'<option value="SUPER">SUPERIOR</option>' +
			'<option value="SUPR-K">SUPERIOR-KITCHENETTE</option>' +
			'<option value="LOFT">LOFT-KITCHENETTE</option>' +
			'<option value="1BR">ONE BEDROOM</option>' +
			'<option value="1BR-P">ONE BEDROOM PLUS</option>' +
			'<option value="2BR-P">TWO BEDROOM PLUS</option>' +
		'</select>';
		document.getElementById('frmRoomType').innerHTML = frmHTML;
	break;
	
	case '04':
		frmHTML = 'Type: <select name="RoomTypes" id="RoomTypes" tabindex="18" class="DropDownFrame" style="font-size:8.5pt;height:20px;width:130px;">' +
			'<option selected="selected" value="ALL">All Room Types</option>' +
			'<option value="SUPER">SUPERIOR ROOM</option>' +
			'<option value="SUPERH">SUPERIOR W/M+H</option>' +
			'<option value="SUPERM">SUPERIOR MURPHY</option>' +
			'<option value="SUPRQQ">SUPERIOR W Q/Q</option>' +
			'<option value="1BR">1 BEDROOM</option>' +
			'<option value="1BRH">1 BEDROOM W H</option>' +
			'<option value="CORNER">CORNER UNIT</option>' +
		'</select>';
		document.getElementById('frmRoomType').innerHTML = frmHTML;
	break;

	case '05':
		frmHTML = 'Type: <select name="RoomTypes" id="RoomTypes" tabindex="18" class="DropDownFrame" style="font-size:8.5pt;height:20px;width:130px;">' +
			'<option selected="selected" value="ALL">All Room Types</option>' +
			'<option value="STUL">STUDIO LOCKOFF</option>' +
			'<option value="1BC">1 BEDROOM CLUB SUITE</option>' +
			'<option value="1BCL">1 BRM CLUB SUITE LOCKOFF</option>' +
			'<option value="2BC">2 BRM CLUB SUITE</option>' +
			'<option value="2BCL">2 BRM CLUB SUITE LOCKOFF</option>' +
			'<option value="2ECH">2 BDRM EXP CAB HOT TUB</option>' +
			'<option value="3BCL">3 BRM CLUB SUITE LOCKOFF</option>' +
			'<option value="3TPH">3TPH 3 BDRM TOWN H PLUS W/HT</option>' +
			'<option value="3ECPH">3ECPH 	3 BDRM EXP CAB P HOT TUB</option>' +
			'<option value="4ECPH">4ECPH 	4 BDRM EXP CAB P HOT TUB</option>' +
		'</select>';
		document.getElementById('frmRoomType').innerHTML = frmHTML;
	break;

	case '*':
		document.getElementById('frmRoomType').innerHTML = "";
	break;
	
	default:
		document.getElementById('frmRoomType').innerHTML = "";
	}
}
