

function setInitDates(){
	var cookieArrDate;
	var cookieDepDate;
	var my_date = new Date();
	var my_new_date;
	
	cookieArrDate=readCookie('maltonArrival');
	cookieDepDate=readCookie('maltonDeparture');
	cookieNoRooms=readCookie('maltonNoRoomsIndex');
	cookieRoomType=readCookie('maltonRoomTypeIndex');
	
	if (cookieArrDate==null){
		my_date.setDate(my_date.getDate() + 1);
		updateDDH(my_date,"arr");
		document.bookingform.arrivalDate.value=my_date.format("dd/mm/yyyy");
	
	}
	else{
		
		M = cookieArrDate.match(/(\d\d).(\d\d).(\d\d\d\d)/)
		my_new_date = new Date(M[3], M[2]-1, M[1])
		
		my_new_date.setDate(my_new_date.getDate());
				
		updateDDH(my_new_date,"arr");
		document.bookingform.arrivalDate.value=my_new_date.format("dd/mm/yyyy");
	
	}

	if (cookieDepDate==null){
		
	my_date.setDate(my_date.getDate() + 1);
	updateDDH(my_date,"dep");
	document.bookingform.departureDate.value=my_date.format("dd/mm/yyyy");
	
	
	}
	else{
	
	M = cookieDepDate.match(/(\d\d).(\d\d).(\d\d\d\d)/)
	my_new_date = new Date(M[3], M[2]-1, M[1])

	my_new_date.setDate(my_new_date.getDate());
	updateDDH(my_new_date,"dep");
	document.bookingform.departureDate.value=my_new_date.format("dd/mm/yyyy");
	
	}

	//set cookies for no of rooms and room type	
	if(cookieNoRooms) document.bookingform.no_rooms.selectedIndex = cookieNoRooms;
	if(cookieRoomType) document.bookingform.room_type.selectedIndex = cookieRoomType;
	
	interstitialShowHide('hide');
		
	return;
}

function updateDDH (new_date, arrdep){
	if (arrdep=="arr"){
		document.bookingform.arrMonth.value=new_date.getMonth()+1;
		document.bookingform.arrDate.value=new_date.getDate();
		document.bookingform.arrYear.value=new_date.getFullYear();
		return;
	}
	else if (arrdep=="dep"){
		document.bookingform.depMonth.value=new_date.getMonth()+1;
		document.bookingform.depDate.value=new_date.getDate();
		document.bookingform.depYear.value=new_date.getFullYear();
		return;
	}
	else {
		alert("Neither arrival or departure date sent");
	}
}

function updateArrDate(){
	var my_date2=new Date(document.bookingform.arrYear.value,document.bookingform.arrMonth.value-1,document.bookingform.arrDate.value);
	document.bookingform.arrivalDate.value=my_date2.format("dd/mm/yyyy");
	my_date2.setDate(my_date2.getDate()+1);
	document.bookingform.departureDate.value=my_date2.format("dd/mm/yyyy");
	updateDDH(my_date2,"dep");
	return;
}
function updateDepDate(){
	var my_date2=new Date(document.bookingform.depYear.value,document.bookingform.depMonth.value-1,document.bookingform.depDate.value);
	document.bookingform.departureDate.value=my_date2.format("dd/mm/yyyy");
}
function arrCalUpdate(cal){
	updateDDH(cal.date,"arr");

	var my_date=cal.date;
	my_date.setDate(my_date.getDate() + 1);
	updateDDH(my_date,"dep");
	document.bookingform.departureDate.value=cal.date.format("dd/mm/yyyy");
}
function depCalUpdate(cal){
	updateDDH(cal.date,"dep");
}


function mouseIn(){
	document.bookingform.findaroom.src="images/find-a-room/button-2.png";

}

function mouseOut(){
	document.bookingform.findaroom.src="images/find-a-room/button-1.png";

}

function interstitialShowHide(val){
	if (val=='show'){
	document.getElementById('interstitial-id').style.visibility = 'visible';
	document.getElementById('interstitial-id').style.position = 'relative';
	}
	else {
	document.getElementById('interstitial-id').style.visibility = 'hidden';
	document.getElementById('interstitial-id').style.position = 'absolute';
	}

	return;
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}




function maltonDates(arrivalVal,departureVal,room_type,no_rooms){
	createCookie('maltonArrival',arrivalVal,1);
	createCookie('maltonDeparture',departureVal,1);
	createCookie('maltonRoomTypeIndex',room_type,1);
	createCookie('maltonNoRoomsIndex',no_rooms,1);
	return;


}




