/**
 * This function parses the date in the format of MM/DD/YYYY and returns a date object.
 * Validation are done according to the values for MM and DD
 * @param {Object} dateStr
 * @param {String} the policy to round the out of bound days to down or up
 */
 
 
// var admin = $F('isAdmin').value;

function parseDate(dateStr , rndPolicy , element) {
                var list = dateStr.split("/");
                var date = Date.parse('today') ;
                if (list.length == 3) {
                                var mon = list[0] ;
                                var day = list[1] ;
                                var year = list[2] ;
                                try {
                                                mon = mon - 1 ;
                                                day = day - 0 ;
                                                year = year - 0 ;
                                                
                                                if (year > 0 && year <= Date.parse('today').getFullYear()+1) {
                                                                if (mon >= 0 && mon < 12) {
                                                                                date.setDate(1);
                                                                                date.setFullYear(year);
                                                                                date.setMonth(mon);
                                                                                // Negative date rounds to 1
                                                                                if (day <= 0) {
                                                                                                day = 1 ;
                                                                                }
                                                                                // bigger day is rounded in two ways
                                                                                else if (day > daysInMonth(mon, year)) {
                                                                                                // down rouding  round the day to the biggest of current month
                                                                                                if (rndPolicy == 'down' || rndPolicy == 'up') {
                                                                                                                //day = daysInMonth(mon, year);
                                                                                                                day = 1 ;
                                                                                                                date.setMonth(date.getMonth()+1);
                                                                                                }
                                                                                }
                                                                                date.setDate(day);
                                                                                //debugger;
                                                                                setDateString(element ,strToDisplayStr(dateToStr(date)));
                                                                                return date ; 
                                                                } else {
                                                                                return null;
                                                                }
                                                } else {
                                                                return null ;
                                                }
                                }catch (ex) {
                                                return null ;
                                }
                }
}


/**
 * This function sets back the adjusted Date in the UI
 * @param {Object} dateStr
 */
function setDateString(element,dateStr) {
                $(element).value = dateStr ;
}

//This function adds the numMon number of months to the provided date
function getMonthAfter(date , numMon) {
                currMon = date.getMonth();
                if ( (currMon + numMon ) > 11 ) {
                                date.setFullYear(date.getFullYear()+1);
                                date.setMonth((currMon + numMon ) - 12);
                } else {
                                date.setMonth = (currMon + numMon ) ;
                }
                return date ;
}  
/**
 * Determine the number of days in the given month
 * @param {Object} iMonth
 * @param {Object} iYear
 */
function daysInMonth(iMonth, iYear)
{
                return 32 - new Date(iYear, iMonth, 32).getDate();
}

/**
 * Validates the code and return true if any error detected
 */
function validateDepartDate() {
                
                //var departDate = Date.parse($F('departDate'));

                var departDate = parseDate($F('departDate'),'down' ,'departDate');
                var returnDate = parseDate($F('returnDate'),'up' ,'returnDate' );
                
                today = Date.parse('today');
                var isAnyError = false ;
                
                /* Invalid date format or characters */
                if((departDate == null)){
                                errorArray.depart_invalid_date = "You must choose a valid depart date";  isAnyError = true ;
                } else { 
                                errorArray.depart_invalid_date = "" ; 
                }
                                
                /* Date is not 3 days after today */
                if((departDate != null) && departDate.compareTo(Date.today().add(72).hours()) < 0){
                                errorArray.depart_in3days_date = "Packages must be booked at least 3 days in advance" ;          isAnyError = true ;
                }else {
                                errorArray.depart_in3days_date = "" ;
                }
                
                /* Date is beyond 11 month after today */
                if ((departDate != null) && departDate.compareTo(Date.today().add(11).months()) > 0 ) {
                                errorArray.depart_beyond_date = "Trips may only be booked up to 11 months in advance. For groups contact 1-866-875-4565";              isAnyError = true ;                                                                                                                                                                              
                } else {
                                errorArray.depart_beyond_date = "" ;
                }
                
                /* Both dates exist so update number of nights */
                if (returnDate!=null && departDate!=null ) {
                                nightNums = daysElapsed(departDate, returnDate) ;
                                if (nightNums < 2) {
                                                nightNums = 2 ;
                                }
                                $("numNights").value = nightNums;
                                validateNights() ;
                }
                
                /* return is updated based on depart date and number of nights */
                if (returnDate==null && departDate!=null && !isNaN(parseInt($("numNights").value) )) {
                                returnDate = new Date(departDate);
                                returnDate.setDate(returnDate.getDate() + parseInt($("numNights").value)) ;
                                $('returnDate').value = strToDisplayStr(dateToStr(returnDate));
                                validateElement('returnDate');
                }
                
                
                return isAnyError ;
}


function validateReturnDate() {
                var isAnyError = false ;
                var endDate = parseDate($F('returnDate'),'up' ,'returnDate' );
                var startDate = parseDate($F('departDate'),'down' ,'departDate');
                if (endDate == null) {
                                errorArray.return_invalid_date = "You must choose a valid return date"; isAnyError = true ;
                } else {
                                errorArray.return_invalid_date = "";
                }
                
                if ((endDate != null) && endDate.compareTo(Date.today().add(11).months()) > 0) {
                                errorArray.return_beyond_date = "Trips may only be booked up to 11 months in advance. For groups contact 1-866-875-4565";              
								isAnyError = true ;                                                                                                                                                                              
                } else {
                                errorArray.return_beyond_date = "" ;
                }
                
                if (endDate!= null && startDate!=null ) {
                                if (endDate>=startDate) {
                                                errorArray.return_beforedepart = "" ;
                                                nightNums = Math.abs(daysElapsed(startDate, endDate)) ;
                                                $("numNights").value = nightNums;
                                                resetErrorBorder('numNights');
                                                if ( nightNums < 2) {
                                                                errorArray.night_tooshort = "" ;
                                                                errorArray.return_in3days_date = "Minimum stay for packages is 2 nights"; isAnyError = true ;
                                                } else {
                                                                errorArray.return_in3days_date = "" ;
                                                }
                                } else {
                                                errorArray.return_beforedepart = "Return Date must be after depart date."
                                }
                }
                if (endDate!= null && startDate==null && !isNaN($("numNights").value)  ) {
                                startDate = new Date(endDate);
                                startDate.setDate(endDate.getDate() - $("numNights").value) ;
                                $('departDate').value = strToDisplayStr(dateToStr(startDate));
                                validateElement('departDate');
                }
                
                return isAnyError ;
}

function validateNights(){
	try {
		error = false ;
		
		/* Invalid night number */
		var numNights = parseInt($F("numNights"));
		if (isNaN(numNights)) {
			alert("Invalid number of nights: " + numNights);
			errorArray.night_invalid = "Number of nights is invalid" ; error = true ;
			document.getElementById("numNights").value= 2;
	    } else  {
			errorArray.night_invalid = "" ;
		}
		
		/* less than 2 nights */
		if (numNights < 2) {
			numNights = 2
			document.getElementById("numNights").value= numNights;
		}
		
		/* If num nights is in normal range */
		if(numNights < 30) {
			/* updating return date based on depart date and number of nights */
				
			var departDate = parseDate($F('departDate'),'down' ,'departDate');
			var returnDate = parseDate($F('returnDate'),'up' ,'returnDate' );
			if (departDate) {
				//adjustReturnDate(numNights);
				departDate.setDate(departDate.getDate() + numNights);
				var endDate = dateToStr(departDate);
				$("returnDate").value = strToDisplayStr(endDate);
				validateElement("returnDate");
			} else if ((!departDate && returnDate)) {
				startDate.setDate(returnDate.getDate() - numNights);
				var beginDate = dateToStr(startDate);
				$("departDate").value = strToDisplayStr(beginDate);
				validateElement("departDate");
				//adjustDepartDate(numNights);
			}
		}  
		
		/* Too long stay */
		else if (numNights > 30) {
			errorArray.night_toolong = "For stays of more than 30 nights, please contact reservations at 1-866-875-4565" ; error = true ;
		} else {
			errorArray.night_toolong = "" ;
		}
	} catch(err){
		
		errorArray.night_invalid = "Number of Nights is Invalid" ; error = true ;
	}
	
	return error ;
}

function validateForm() {
                document.getElementById("residual_booking_error").style.display = "none";
                
                errorArray.airport_invalid = "" ;
                errorArray.destination_invalid = "" ;
                
                
                validateElement('departDate');
                validateElement('returnDate');
                validateElement('numNights');
                validateElement('totalTravelers');
                
                if($F('destinationId') == -1){
                                errorArray.destination_invalid = "You must choose a destination.";
                                setErrorBorder('destinationId');
                }
                if(document.getElementsByName("bookOptionsRadio")[0].checked && ($F("departureCode") == "")){
                                errorArray.airport_invalid = "Depart airport is invalid.";
                                setErrorBorder(document.getElementsByName('departureKey')[0]);
                                flight = true;
                }
                var infants = 0;
                var children = 0;
                var ages = document.getElementsByName("ages[]");
                for(i = 0; i < ages.length; i++) {
                                age = ages[i].value;
                                if(age < 0) {
                                                error += "Age " + age + " is invalid<br>";
                                } else if (age > 17) {
                                                error += "Ages 18 and over are considered adults<br>";
                                } else if(isNaN(age)) {
                                                error += "You must enter a number for the child age<br>";
                                }                              
                                
                                if(age == 0 || age == 1){
                                                infants++;                                           
                                }else if(age > 11 && age < 18){
                                                children++;
                                }
                }
                
                if(flight){
                                if(infants > ($F("totalTravelers") - (infants + children) ) ){
                                                error += "For infants requiring an airline seat, pleasae call 1.866.875.4565.<br>";
                                }
                }
                
                /* String representation of all errors */
                var errorStr = "" ;
                
                /* String for alerts */
                var errorStr_alert = "" ;
                for(var err in errorArray) {
                                if (errorArray[err].length > 0) {
                                                errorStr += "<li><span>"+errorArray[err]+"</span></li>";
                                                errorStr_alert += errorArray[err]+"\n" ;
                                                errorArray[err] = "" ;
                                }
                }                              
                if (errorStr.length > 0) {
                                $("booking_error").update("<ul style='list-style-type: disc;'>"+errorStr+"</ul>");
                                $("booking_error").show();
                                return false;
                                alert(errorStr_alert);
                } else {
                                $("booking_error").hide();
                                return true ;
                }
}




/**
 * Validate the form
 **/
function checkForm(){
                var error = "";
                var departDate = Date.parse($F('departDate'));
                var returnDate = Date.parse($F('returnDate'));
                
                if((departDate == null)){
                                error += "You must choose a valid depart date<br>";
                }else if((departDate.compareTo(Date.parse('today')) < 0)){
                                error += "You must choose a valid depart date<br>";
                }else if(departDate.compareTo(Date.today().add(48).hours()) < 0){
                                error += "For trips departing within 48 hours please call 1.866.875.4565<br>";
                }
                
                
                
                if((returnDate == null)){
                                error += "You must choose a valid return date<br>";
                }else if((departDate != null) && (departDate.compareTo(returnDate) > 0)){
                                error += "You must choose a valid return date<br>";
                }
                var childAges = [];
                
                var numRooms =$F("numRooms");
                var childAge;
                var totalAdults = 0;
                var totalChildren = 0;
                var totalInfants = 0; 
                
                // add up all children, adults and infants in the form
                for(var i = 1; i <= numRooms; i++) {
                                adults = parseInt($F("adultsRoom"+i));
                                children = parseInt($F("childrenRoom"+i));
                                totalAdults += adults;
                                                                
                                for(var c = 1; c <= children; c++) {
                                                childAge = (parseInt($F("ageRoom"+i+"Child"+c)));
                                                
                                                if(childAge < 2) {
                                                                totalInfants++;
                                                }else {
                                                                totalChildren++;
                                                }
                                                childAges[totalChildren+totalInfants-1] = childAge;
                                }
                }
                                
                var flight = false;
                //If the customer is booking a flight, make sure there is a departure code
                if(document.getElementsByName("bookOptionsRadio")[0].checked){
                                flight = true;
                                
                                if($F("departureCode") == "") {
                                                error += "Depart airport is invalid<br>";
                                }
                                
                                if((totalAdults + totalChildren + totalInfants) > 6){
                                                error += "For flights involving more than 6 people please call 1.866.875.4565<br>";
                                }
                }
                
                if($F('destinationId') == -1){
                                error += "You must choose a destination<br>";
                }
                
                if(flight){
                                if(totalInfants > totalAdults){
                                                error += "For infants requiring an airline seat, please call 1.866.875.4565.<br>";
                                }
                }
                if(error == ""){
                                return true;
                }else{
                                $("booking_error").update(error);
                                $("booking_error").show();
                                return false;
                }
}

function bookOptionChange(){

                var button = document.getElementsByName("bookOptionsRadio");

                if(button[1].checked){
//                            alert("checked " + button[1].value + " not " + button[0].value);
                                document.getElementsByName("departureCode")[0].value="";
                                document.getElementById("departureTitle").style.display="none";
                                document.getElementById("departureCity").style.display="none";
                                document.getElementById("nearbyAirports").style.display="none";
                                document.getElementById("departDateLabel").innerHTML="Check-in";                              
                                document.getElementById("returnDateLabel").innerHTML="Check-out";                                                            
                                document.getElementById("BookingInfoForm_0").value="Search Hotels";         
                }else{
//                            alert("checked " + button[0].value + " not " + button[1].value);
                                document.getElementsByName("departureCode")[0].value="";
                                document.getElementById("departureTitle").style.display="";
                                document.getElementById("departureCity").style.display="";
                                document.getElementById("nearbyAirports").style.display="";
                                document.getElementById("departDateLabel").innerHTML="Depart Date";                       
                                document.getElementById("returnDateLabel").innerHTML="Return Date";                                                        
                                document.getElementById("BookingInfoForm_0").value="Search Packages";    

                }

}

function checkBestDay(){
                var params = "";
                
                var destinationId = $F('destinationId');
                
                switch(destinationId){
                                case "34":
                                                params += "&destino=" + 2;
                                                break;
                                case "48":                                            
                                                params += "&destino=" + 1;
                                                break;
                                case "49":                                            
                                                params += "&destino=" + 8;
                                                break;
                                case "50":                                            
                                                params += "&destino=" + 30;
                                                break;
                                case "51":                                            
                                                params += "&destino=" + 16;
                                                break;
                                case "52":                                            
                                                params += "&destino=" + 12;
                                                break;
                                case "53":                                            
                                                params += "&destino=" + 13;
                                                break;
                                default:
                                                break;
                }
                
                if(params != ""){

                                var startDate = Date.parse($F("departDate"));
                                var endDate = Date.parse($F("returnDate"));
                
                                params += "&anio_desde=" + startDate.getFullYear();
                                params += "&mes_desde=" + (startDate.getMonth() + 1);
                                params += "&dia_desde=" + startDate.getDate();
                                params += "&anio_hasta=" + endDate.getFullYear();
                                params += "&mes_hasta=" + (endDate.getMonth() + 1);
                                params += "&dia_hasta=" + endDate.getDate();
                
                                //default hotel listing otherwise check for flights too
                                var page = "list.aspx";
                                if(document.getElementsByName("bookOptionsRadio")[0].checked){
                                                page = "Package.aspx";
                                }
                                
                                $('BookingInfoForm').action = "http://www.e-travelsolution.com/Partners/Reservations/Hotels/" + page + "?Type=Hotel&asoc=stst&idioma=ING" + params;
                }
                
                return true;
}

function dateToStr(date){
                month = date.getMonth()+1;
                if(month < 10){
                                month = "0"+month;
                }
                day = date.getDate();
                if(day < 10){
                                day = "0"+day;
                }
                return date.getFullYear()+"-"+month+"-"+day;
}

function strToDisplayStr(str){
                var displayStr = "";
                var date = /(\d{4})-(\d{2})-(\d{2})/;
                if(date.test(str)){
                                var year = RegExp.$1;
                                var month = RegExp.$2;
                                var day = RegExp.$3;
                                displayStr = month+"/"+day+"/"+year;
                }
                return displayStr;
}

 /**
  * Calculate the number of nights
  */
 var lastChanged;
function departDateChange(){
                switch(lastChanged){
                                case "numNights":
                                                numNightsChange();
                                                break;
                                case "returnDate":
                                                returnDateChange();
                                                break;
                                default:
                                                
                }
}

function checkForInfants(){
                var message = "Infants under the age of 2 are considered lap children.<br>";
                var ages = document.getElementsByName("ages[]");
                var infants = 0;
                for(i = 0; i < ages.length; i++) {
                                age = ages[i].value;
                                if(age == 0 || age == 1) {
                                                infants++;
                                }
                }
                
                if(infants > 0){
                                document.getElementById("infantmessage").innerHTML = message;
                                document.getElementById("infantmessage").style.display = "";
                }else{
                                document.getElementById("infantmessage").innerHTML = "";
                                document.getElementById("infantmessage").style.display = "none";
                }
}

function checkDepartDate(){
                var numNights = parseInt($F("numNights"));
                if(numNights > 0){
                                numNightsChange();
                }
}

function numNightsChange(){
                var numNights = parseInt($F("numNights"));
                
                startDate = Date.parse($F("departDate"));
                
                startDate.setDate(startDate.getDate() + numNights);
                
                endDate = dateToStr(startDate);
                
                $("returnDate").value = strToDisplayStr(endDate);
                
                lastChanged = "numNights";
}

function daysElapsed(date1,date2) {
    var difference = "";
    if((date1 != null) && (date2 != null)){
                                difference = Date.UTC(date2.getYear(),date2.getMonth(),date2.getDate(),0,0,0) - Date.UTC(date1.getYear(),date1.getMonth(),date1.getDate(),0,0,0);
                difference = difference/1000/60/60/24;
    }
    return difference;
}

function returnDateChange(){
                var numNights = parseInt($F("numNights"));
                
                startDate = Date.parse($F('departDate'));
                endDate = Date.parse($F('returnDate'));

                if(endDate>=startDate) {
                                var diffDays = Math.abs(daysElapsed(startDate, endDate));
                                $("numNights").value = diffDays;
                                lastChanged = "returnDate";
								validateNights();
                }else{
                                alert("Departure Date is after Return Date");
                }              
}



/**
 *  (print the age input fields)
 **/
function printAgeInputs(){
                var output = "";
                var totalTravelers = $F("totalTravelers");
                
                document.getElementById("booking_error").style.display = "none";

                if((parseInt(totalTravelers) > 0) && (!isNaN(totalTravelers))){
                                
                                if(totalTravelers <= 6 && totalTravelers >= 1){
                                                for(i = 0; ((i < totalTravelers - 1) && (i < 5)); i++){
                                                                output += "<input name=\"ages[]\" type=\"text\" size=\"2\" style=\"width:25px\" /> ";
                                                }

                                                document.getElementById("childrensAges").innerHTML = output;
                                }else{
                                                output = "For more than 6 people please call 1.866.875.4565<br>";
                                                document.getElementById("booking_error").innerHTML = output;
                                                document.getElementById("booking_error").style.display = "";
                                }
                } else if(isNaN(totalTravelers)){

                                output = totalTravelers + " is not a number<br>";
                                
                                $("booking_error").update(output);
                                $("booking_error").show();
                                $("totalTravelers").value = "";
                } else if(totalTravelers < 1) {
                                                output = "You  must have at least one traveler<br>";
                                                document.getElementById("booking_error").innerHTML = output;
                                                document.getElementById("booking_error").style.display = "";
                }
}



function numRoomsChange(){
	var output = "";
	var numRooms =$F("numRooms") ;
	var str = "";
	if((parseInt(numRooms) > 0) && (!isNaN(numRooms))){
		if(numRooms <= 6 && numRooms >= 1){
			for(i = 1; (i <= numRooms) && (i <= 6); i++){
				if(i == 1){
					output += "<div style=\"height:15px;width:150px;\">";
					output += "      <div style=\"width:50px;float:left;\">&nbsp;</div>";
					output += "      <div style=\"width:50px;float:left;\">";
//					output += "        <div style=\"width:50px;margin-left:0px;float:left;\">";
					output += "           Adults";
					output += "      </div>";
					output += "      <div style=\"float:left;width=50px;\">";
					output += "           Children";
					output += "      </div>";
					output += "<div style='clear:both;'></div>";
					output += "</div>";
					
				}
				output += "<div id=\"roomsRow\" style=\"width:100%; float:left;\">";
				output += "   <div id=\"roomCount\" style=\"width:50px;float:left;text-align:left;\">";
				output +=  "      <div style='float:left; width:50px;' id=\"roomCount" + i + "\">";
				if(numRooms > 1){
					output += "Room " + i + ":";
				}else{
					output += "&nbsp;";	
				}
				output += "       </div>";
				output += "   </div>";
				output += "<div style='float:left;width:50px' id='adults'>";
				output += "   <div id=\"adults" + i + "\">";
				output +=  "      <select id='adultsRoom" + i + "' name='adultsRoom" + i + "'>";
				for(j = 1; j <= 6; j++) { 
					if(j==2) {
						output += "         <option value='" + j + "' selected>" + j + "</option>";
					} else {
						output += "         <option value='" + j + "'>" + j + "</option>";
					}
				}
				output += "       </select>";
				output += "   </div>";
				output += "</div>";
				output += "<div style='float:left;' id=\"children" + i + "\">";
				output += "   <select onchange='printChildAgeBoxes(" + i + ")' id='childrenRoom" + i + "' name='childrenRoom" + i + "'>";
				for(h = 0; h <= 4; h++) { 
					output +=  "<option value='" + h + "'>" + h + "</option>";
				}
				output += "   </select>";
				output += "</div>";
				output += "<div style='clear:both;'/>";
				output += "<div style='display:none;' id='childAgeDiv" + i + "'/>";
				output += "</div>";
			}
			document.getElementById("roomOccupanciesDiv").innerHTML = output;
		}else{
			output = "For more than 6 people please call 1.866.875.4565<br>";
			document.getElementById("booking_error").innerHTML = output;
			document.getElementById("booking_error").style.display = "";
		}
	}
}

	function printChildAgeBoxes(rowNum) {
                var numChildren = document.getElementById("childrenRoom" + rowNum + "").value;
                var childAgeDiv = document.getElementById("childAgeDiv" + rowNum + "");
                var output = "";
				
                output += "<div id='childAgesRow" + rowNum + "' style='float:right;margin-bottom:5px;margin-top:5px;margin-right:5px; margin-left:15px;display:block;text-align:left;'>";
				if(numChildren > 0 ) {
					output +=   "Child Ages (during travel)<br/>";
                
					for(i = 1; i <= numChildren; i++) {
									if(i == 3) {
													output += "<br/>";
									} 
									output += "<span id='childAgeSelect" + rowNum + "" + i + "' style='display:inline;'>";
									output +=                            "<select id='ageRoom" + rowNum + "Child" + i + "' name='ageRoom" + rowNum + "Child" + i + "'>";
									output += "<option value='1'> 0-1 </option>"; 
									for(j = 2; j < 18; j++) {
													output += "<option value='" + j + "'>" + j + "</option>";
									}
									output += "</select>";
									output += "</span>";
					} 
				}
                output += "</div>";
                output += "<div style='clear:both;' />";
                childAgeDiv.innerHTML = output;
                childAgeDiv.style.display = ""; 
                
}

function printChildAgeBoxesHorizontal(rowNum) {
                var numChildren = document.getElementById("childrenRoom" + rowNum + "").value;
                var childAgeDiv = document.getElementById("childAgeDiv" + rowNum + "");
                var output = "";
                output += "<div id='childAgesRow" + rowNum + "' style='float:right; margin-left:15px;display:block;text-align:left;'>";
				
				if(numChildren > 0 ) {
					output += "Child Ages (during travel)<br/>";
					
					for(i = 1; i <= numChildren; i++) {
									output += "<span id='childAgeSelect" + rowNum + "" + i + "' style='display:inline;'>";
									output +=                            "<select id='ageRoom" + rowNum + "Child" + i + "' name='ageRoom" + rowNum + "Child" + i + "'>";
									output += "<option value='1'> 0-1 </option>"; 
									for(j = 2; j < 18; j++) {
													output += "<option value='" + j + "'>" + j + "</option>";
									}
									output += "</select>";
									output += "</span>";
					} 
				}
                output += "</div>";
                output += "<div style='clear:both;' />";
                childAgeDiv.innerHTML = output;
                childAgeDiv.style.display = ""; 
                
}

/*
function numRoomsChange(){
	var output = "";
	var numRooms =$F("numRooms") ;
	var str = "";
	if((parseInt(numRooms) > 0) && (!isNaN(numRooms))){
		if(numRooms <= 6 && numRooms >= 1){
			for(i = 1; (i <= numRooms) && (i <= 6); i++){
				if(i == 1){
					output += "<div style=\"height:20px;width:100%;float:left;\">";
					output += "<div style=\"width:50px;margin-left:50px;float:left;\">";
					output += "Adults";
					output += "</div>";
					output += "<div style=\"float:left;\">";
					output += "Children";
					output += "</div>";
					output += "</div>";
					output += "<div style='clear:both;'/>";
				}
				output += "<div id=\"roomsRow\" style=\"width:100%; float:left;\">";
				output += "<div id=\"roomCount\" style=\"width:50px;float:left;text-align:left;\">";
				output +=  "<div style='float:left; width:150px;' id=\"roomCount" + i + "\">";
				if(numRooms > 1){
					output += "Room " + i + ":";
				}else{
					output += "&nbsp;";	
				}
				output += "</div>";
				output += "</div>";
				output += "<div style='float:left;width:50px' id='adults'>";
				output +=  "<div id=\"adults" + i + "\">";
				output +=  "<select id='adultsRoom" + i + "' name='adultsRoom" + i + "'>";
				for(j = 1; j <= 6; j++) { 
					output += "         <option value='" + j + "'>" + j + "</option>";
				}
				output +=                                            "</select>";
				output +=                            "</div>";
				output += "</div>";
				output +=   "<div style='float:left;' id=\"children" + i + "\">";
				output +=   "<select onchange='printChildAgeBoxes(" + i + ")' id='childrenRoom" + i + "' name='childrenRoom" + i + "'>";
				for(h = 0; h <= 4; h++) { 
								output +=  "<option value='" + h + "'>" + h + "</option>";
				}
				output +=                                            "</select>";
				output +=                            "</div>";
				output += "<div style='clear:both;'/>";
				output += "<div style='display:none;' id='childAgeDiv" + i + "'/>";
				output += "</div>";
			}
			document.getElementById("roomOccupanciesDiv").innerHTML = output;
		}else{
			output = "For more than 6 people please call 1.866.875.4565<br>";
			document.getElementById("booking_error").innerHTML = output;
			document.getElementById("booking_error").style.display = "";
		}
	}
}

	function printChildAgeBoxes(rowNum) {
                var numChildren = document.getElementById("childrenRoom" + rowNum + "").value;
                var childAgeDiv = document.getElementById("childAgeDiv" + rowNum + "");
                var output = "";
                output += "<div id='childAgesRow" + rowNum + "' style='float:right;margin-bottom:5px;margin-top:5px;margin-right:5px; margin-left:15px;display:block;text-align:left;'>";
                output +=                            "Child Ages (during travel)<br/>";
                
                for(i = 1; i <= numChildren; i++) {
                                if(i == 3) {
                                                output += "<br/>";
                                } 
                                output += "<span id='childAgeSelect" + rowNum + "" + i + "' style='display:inline;'>";
                                output +=                            "<select id='ageRoom" + rowNum + "Child" + i + "' name='ageRoom" + rowNum + "Child" + i + "'>";
                                output += "<option value='1'> 0-1 </option>"; 
                                for(j = 2; j < 18; j++) {
                                                output += "<option value='" + j + "'>" + j + "</option>";
                                }
                                output += "</select>";
                                output += "</span>";
                } 
                output += "</div>";
                output += "<div style='clear:both;' />";
                childAgeDiv.innerHTML = output;
                childAgeDiv.style.display = ""; 
                
}
*/