$(document).ready(function(){
	$("#hotel").change(function(){
		changeHotel($(this));
	});
	$(".amountOfRooms").change(function(){
		changeNoOfRooms($(this));
	});
	$(".amountOfAdults").live("change",function(){
		changePersonsInRoom($(this));
	});
	$(".amountOfChildren").live("change",function(){
		changePersonsInRoom($(this));
	});
	$(".amountOfbabies").live("change",function(){
		changePersonsInRoom($(this));
	});

	if($("#hotel").val() == "7960") {
		removePersonsInRoom();
	}

});
function removePersonsInRoom() {
	$("#personsInRooms").html("<div style='visibility:hidden;'>"+$("#personsInRooms").html()+"</div>");
	$("#personsInRooms").closest(".row").css("height","75px");
}


function changeHotel(element) {
	var value = element.val();
	
	$.ajax({
		type: "POST",
		url: "/files/system/booking/php/general/globalFunctions.ajax.php",
		async:false,
		data: {
			ajaxCall: true,
			phpFunction: "setHotel",
			hotelid: value
		},
		success: function(response){
			if($("#hotel").val() == "7960") {
				removePersonsInRoom();
			}
			else {
				$("#personsInRooms").load("/files/system/booking/php/search/personsInRoom.php");
				$("#personsInRooms").closest(".row").css("height","");
			}
		}
	 });
}


function changeNoOfRooms(element) {
	var value = element.val();
	
	$.ajax({
		type: "POST",
		url: "/files/system/booking/php/general/globalFunctions.ajax.php",
		async: false,
		data: {
			ajaxCall: true,
			phpFunction: "setNoOfRooms",
			noOfRooms: value
		},
		success: function(response){
			if($("#hotel").val() == "7960") {
				removePersonsInRoom();
			}
			else {
				$("#personsInRooms").load("/files/system/booking/php/search/personsInRoom.php");
				$("#personsInRooms").closest(".row").css("height","");
			}		
		}
	 });
}

function changePersonsInRoom(element) {
	var id = element.attr("id").split("_");
	var type = id[0];
	var roomNr = id[1];
	var value = element.val();
	
	$.ajax({
		type: "POST",
		url: "/files/system/booking/php/general/globalFunctions.ajax.php",
		async: false,
		data: {
			ajaxCall: true,
			phpFunction: "setRoomSession",
			arg1: roomNr,
			arg2: type,
			arg3: value
		},
		success: function(response){
			if($("#hotel").val() == "7960") {
				removePersonsInRoom();
			}
			else {
				$("#personsInRooms").load("/files/system/booking/php/search/personsInRoom.php");
				$("#personsInRooms").closest(".row").css("height","");
			}
		}
	 });
}
