//IRMnet Web Integration Package and callIRM_updated2.js were created by Gueststream Inc.// 
//Unauthorized use of the code is prohibited.//
//Gueststream Inc., Toll-free:  877-880-5946 ext. 101//

// JavaScript Document
//////////////////////////////////////////
// Supporting date variables and functions
//////////////////////////////////////////
// Get today's current date. not necessary for this demo or current//
var now = new Date();

// Array list of days.
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

// 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;
	}
	
//function for returning how many days there are in a month including leap years
function DaysInMonth(WhichMonth, WhichYear){
  var DaysInMonth = 31;
  if (WhichMonth == "04" || WhichMonth == "06" || WhichMonth == "09" || WhichMonth == "11") DaysInMonth = 30;
  if (WhichMonth == "02" && (WhichYear/4) != Math.floor(WhichYear/4))	DaysInMonth = 28;
  if (WhichMonth == "02" && (WhichYear/4) == Math.floor(WhichYear/4))	DaysInMonth = 29;
  return DaysInMonth;
}



function callIRM(){
		var newform1 = document.getElementById("form1");


	var url = "http://secure.wildernessresort.com/irmnet/res/resmain.aspx?";
	var earliest = new Date(now.getFullYear(), now.getMonth(), now.getDate());
	var path1 = "Path=\\\\wil-svr-rdp1\\rdpnt\\rdp\\&Resort="; 
	var path2 = "Path=\\\\wil-svr-rdp2\\rdpnt\\rdp\\&Resort=";
	var resort = newform1.resort.value
	var arrival = newform1.wdcArrival_input.value;
    
	//var departure = 
	
	//var departure = newform1.wdcDeparture_input.value;
	var nights = newform1.wcNights_input.value;
	var child = newform1.People2.value;
	var adults = newform1.People1.value;
	if (arrival != "Select Date"){
		if (nights <= 0 ){
       alert("Departure date must be later than arrival date.\nPlease change your calendar dates and try again.")
       return false;
       }
    //additional checking
		if (nights > 10){  // for example enforce a maximum stay
		   alert("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");
		   return false;
		   }
		if(resort != "00"){
			if(resort == "01" || resort == "02"){
				url = url + path1 + resort;	
			}
			else if(resort == "03" || resort == "04" || resort == "05"){
				url = url + path2 + resort;	
			}
		}
		else{
			alert("Please select the Wilderness Resort Property of your choice");
			newform1.resort.focus();
			return false;
		}
	url = url + "&Arrival=" + arrival + "&nights=" + nights;
	//url = url + "&Departure=" + departure;
	}
	else{
		if(resort != "00"){
			if(resort == "01" || resort == "02"){
				url = url + path1 + resort;	
			}
			else if(resort == "03" || resort == "04" || resort == "05"){
				url = url + path2 + resort;	
			}
		}
		else{
			alert("Please select the Wilderness Resort Property of your choice");
			newform1.resort.focus();
			return false;
		}
		arrival = new Date(earliest.getFullYear(), earliest.getMonth(), earliest.getDate());
		var arriveField = (months[arrival.getMonth()]) + "/" +
								   ((arrival.getDate()<10) ? "0" : "")+ arrival.getDate() + "/" +    
								   fourdigits(arrival.getFullYear());
		departure = new Date(earliest.getFullYear(), earliest.getMonth(), earliest.getDate() + 2);
		var departField = (months[departure.getMonth()]) + "/" +
								   ((departure.getDate()<10) ? "0" : "")+ departure.getDate() + "/" +    
								   fourdigits(departure.getFullYear());
		url = url + "&nights=" + nights + "&Arrival=" + arriveField;
		//url = url + "&Departure=" + departField;
	}
	url = url + "&People1=" + adults;
	url = url + "&People2=" + child;
	
	/*
	
	urchinTracker('/outgoing/w/test1');


  var a = document.getElementById('availabilityform');	

  var b = document.getElementById('hotelCode2');	

	

   var hc = document.getElementById('hotelCode');

		

  if(b.options[b.selectedIndex].value == 'WSSTN')

  {

  urchinTracker('/outgoing/w/test2');

  urchinTracker('/outgoing/w/WSSTN');

  
   a.action ="https://reservations.wildernessatthesmokies.com/wrss/availability.asp";

   hc.value='WSSTN';

  }  

  else 

  if(b.options[b.selectedIndex].value == 'WSRL')


  {
  
  urchinTracker('/outgoing/w/test3');


urchinTracker ('/outgoing/w/WSRL');
  

    a.action ="https://reservations.wildernessatthesmokies.com/wrlc/availability.asp";

   	hc.value='WSRL';

  }

	
	*/
	
	
	/*
	if (resort=='01') {
		urchinTracker('/outgoing/w/irmtrackwildernesshotel');
	} 
	else if (resort=='02') {
		urchinTracker('/outgoing/w/irmtrackwildernessvillas');
	}	
	else if (resort=='03') {
		urchinTracker('/outgoing/w/irmtrackwildernesscondoscabins');
	}	
	else if (resort=='04') {
		urchinTracker('/outgoing/w/irmtrackwildernesslake');
	}	
	else if (resort=='05') {
		urchinTracker('/outgoing/w/irmtrackglaciercanyon');
	}		
	*/
	
	
	window.location.assign(url);	
}//end callIRM()


//Default Days ahead of todays date for arrival and departure set to current dates//
var arr = 2;
var dep = 4;

//Get actual values for date and month from DOM//
var nowdate = now.getDate();   
var nowmonth = now.getMonth();  
var nowyear = now.getFullYear();

var arrivalDate = new Date(nowyear, nowmonth, nowdate);
arrivalDate.setDate(arrivalDate.getDate() + arr);
var departureDate = new Date(nowyear, nowmonth, nowdate);
departureDate.setDate(departureDate.getDate() + dep);

var arrivalInit = (months[arrivalDate.getMonth()]) + "/" +
								   ((arrivalDate.getDate()<10) ? "0" : "")+ arrivalDate.getDate() + "/" +    
								   fourdigits(arrivalDate.getFullYear());
								   
var departureInit = (months[departureDate.getMonth()]) + "/" +
								   ((departureDate.getDate()<10) ? "0" : "")+ departureDate.getDate() + "/" +    
								   fourdigits(departureDate.getFullYear());
								   
var numberNights = Math.round(departureDate - arrivalDate)/86400000;

function calcDates(){
		var newform1 = document.getElementById("form1");
		
		var nights = parseInt(newform1.wcNights_input.value);
		var arrivals = newform1.arriveDefault.value;
		arrivals = arrivals.split("/");
		var newArrival = new Date(arrivals[0]+"/"+arrivals[1]+"/"+arrivals[2]);
		var newDeparture = new Date(arrivals[0]+"/"+arrivals[1]+"/"+arrivals[2]);
		if (!nights){
			return;
			}
		if (nights == 0){
			return;
			}
		if (nights > 29){
			nights = 29;
		}
		
		newDeparture.setDate(newDeparture.getDate() + nights);
		var departField = (months[newDeparture.getMonth()]) + "/" +
							   ((newDeparture.getDate()<10) ? "0" : "")+ newDeparture.getDate() + "/" +    
							   fourdigits(newDeparture.getFullYear());
		newform1.departDefault.value = departField;
		//newform1.wdcDeparture_input.value = departField;
		newform1.wcNights_input.value = nights;
		newform1.nightsDefault.value = nights;
		} //end calcDates()
