function checkHotelForm(frm){
	var start_date = parseInt( document.getElementById("txtStartDate").value );
	var end_date = parseInt( document.getElementById("txtEndDate").value );
	var destination_select = document.getElementById("cboDestination");
	var adults_select = document.getElementById("cboAdults");
	var children_select = document.getElementById("cboChildren");
	
	var destination = parseInt( destination_select.options[ destination_select.selectedIndex ].value );	
	var adults = parseInt( adults_select.options[ adults_select.selectedIndex ].value );	
	var children = parseInt( children_select.options[ children_select.selectedIndex ].value );	

	var ret_value = true;
	var ret_msg = new Array();
			
	if( isNaN( destination ) ){
		ret_value = false;
		ret_msg.push( "Please select a destination." );
	}
			
	if( ! ( start_date > 0 && end_date > 0 && end_date > start_date ) ){
		ret_value = false;
		ret_msg.push( "Check-in and Check-out dates are not valid." );
	}

	if( adults + children >= 15 ){
		ret_value = false;
		ret_msg.push( "If you are booking for groups of 15 or more people, use the Group Bookings option." );
	}
	
	if( ret_value == false ){
		alert( ret_msg.join("\n") );	
	}
	return ret_value;
}

function tieCheckHotelForm(){
	var hotel_form = document.getElementById("frmSearch");
	hotel_form.onsubmit = function(){
		return checkHotelForm(this);
	};
}

function tiePopups(){
	var classes = ["popup_image","popup_rooms"];
	var links = document.getElementsByTagName("a");
	var type = "";
	for( var i = 0 ; i < links.length ; i++ ){
		if( links[i].className ){
			for( var x = 0 ; x < classes.length ; x++ ){
				if( links[i].className.toString().indexOf( classes[x] ) >= 0 ){
					var tmp = links[i];
					// type = classes[x];
					tmp.onclick = function(){
						w( this.href, this.className );
						return false;
					};
					tmp.onkeypress = function(){
						w( this.href, this.className );						
						return false;						
					};
				}	
			}
		}
	}
}

addEvent( window,"load",tieCheckHotelForm );
addEvent( window,"load",tiePopups );
