// add to bookmarks
function AddToBookmarks (url,title) {
	if (document.all) {
		window.external.AddFavorite(url, title);
	} else if (window.sidebar) {
		window.sidebar.addPanel(title, url, "")
	} else {
		alert('Your browser does not support adding bookmarks via javascript. Please add it manually');
	}
}

//Javascript to add days, months, years to selected date
function DateAdd(startDate, numDays, numMonths, numYears)
{
	var returnDate = new Date(startDate.getTime());
	var yearsToAdd = numYears;
	
	var month = returnDate.getMonth()	+ numMonths;
	if (month > 11)
	{
		yearsToAdd = Math.floor((month+1)/12);
		month -= 12*yearsToAdd;
		yearsToAdd += numYears;
	}
	returnDate.setMonth(month);
	returnDate.setFullYear(returnDate.getFullYear()	+ yearsToAdd);
	
	returnDate.setTime(returnDate.getTime()+60000*60*24*numDays);
	
	return returnDate;

}


function checkform() {
	var theForm = document.hxparkform;
	var arrival = theForm.ArrivalHourMin.value;
	var depart = theForm.DepartureHourMin.value;
	
	arrivalyear = theForm.my.options[theForm.my.selectedIndex].value.substr(3,4);
	arrivalmonth = theForm.my.options[theForm.my.selectedIndex].value.substr(0,3);

	if(arrivalmonth == "JAN") {
	arrivalmonth = 1;
	}
	
	if(arrivalmonth == "FEB") {
	arrivalmonth = 2;
	}
	
	if(arrivalmonth == "MAR") {
	arrivalmonth = 3;
	}
	
	if(arrivalmonth == "APR") {
	arrivalmonth = 4;
	}
	
	if(arrivalmonth == "MAY") {
	arrivalmonth = 5;
	}
	
	if(arrivalmonth == "JUN") {
	arrivalmonth = 6;
	}
	
	if(arrivalmonth == "JUL") {
	arrivalmonth = 7;
	}
	
	if(arrivalmonth == "AUG") {
	arrivalmonth = 8;
	}
	
	if(arrivalmonth == "SEP") {
	arrivalmonth = 9;
	}
	
	if(arrivalmonth == "OCT") {
	arrivalmonth = 10;
	}
	
	if(arrivalmonth == "NOV") {
	arrivalmonth = 11;
	}
	
	if(arrivalmonth == "DEC") {
	arrivalmonth = 12;
	}
	

	arrivalday = theForm.day.options[theForm.day.selectedIndex].value;
	arrivalhour = theForm.ArrivalHourMin.options[theForm.ArrivalHourMin.selectedIndex].value.substr(0,2);
	arrivalmin = theForm.ArrivalHourMin.options[theForm.ArrivalHourMin.selectedIndex].value.substr(3,2);

	departyear = theForm.r_my.options[theForm.r_my.selectedIndex].value.substr(3,4);
	departmonth = theForm.r_my.options[theForm.r_my.selectedIndex].value.substr(0,3);
	
	
	if(departmonth == "JAN") {
	departmonth = 1;
	}
	
	if(departmonth == "FEB") {
	departmonth = 2;
	}
	
	if(departmonth == "MAR") {
	departmonth = 3;
	}
	
	if(departmonth == "APR") {
	departmonth = 4;
	}
	
	if(departmonth == "MAY") {
	departmonth = 5;
	}
	
	if(departmonth == "JUN") {
	departmonth = 6;
	}
	
	if(departmonth == "JUL") {
	departmonth = 7;
	}
	
	if(departmonth == "AUG") {
	departmonth = 8;
	}
	
	if(departmonth == "SEP") {
	departmonth = 9;
	}
	
	if(departmonth == "OCT") {
	departmonth = 10;
	}
	
	if(departmonth == "NOV") {
	departmonth = 11;
	}
	
	if(departmonth == "DEC") {
	departmonth = 12;
	}
	

	departday = theForm.r_day.options[theForm.r_day.selectedIndex].value;

	departhour = theForm.DepartureHourMin.options[theForm.DepartureHourMin.selectedIndex].value.substr(0,2);
	departmin = theForm.DepartureHourMin.options[theForm.DepartureHourMin.selectedIndex].value.substr(3,2);
	
	arrivaldate = new Date(arrivalyear,arrivalmonth-1,arrivalday,arrivalhour,arrivalmin);
	departdate = new Date(departyear,departmonth-1,departday, departhour, departmin);
	theday = new Date();

	if ((arrival == 'select' || depart == 'select')){
     	alert('Please enter your approximate arrival and departure time'); 
	theForm.ArrivalHourMin.focus();
        return false;
    	}
	if (departdate < arrivaldate){
     	alert('Your return date is before your arrival date'); 
	theForm.my.focus();
        return false;
    	}
	if (arrivaldate < theday){
     	alert('Your arrival date cannot be BEFORE today'); 
	theForm.r_my.focus();
        return false;
    	}
	  
    return true;
}

function checkformhotel() {
var thefrm = document.hxhotelform;

arrivalday = thefrm.day.options[thefrm.day.selectedIndex].value;
arrivalyear = thefrm.my.options[thefrm.my.selectedIndex].value.substr(3,4);
arrivalmonth = thefrm.my.options[thefrm.my.selectedIndex].value.substr(0,3);

if(arrivalday.length < 2) {
arrivalday = "0"+arrivalday;
}

thefrm.ArrivalDate.value = arrivalday+thefrm.my.options[thefrm.my.options.selectedIndex].value;



if(arrivalmonth == "JAN") {
arrivalmonth = 1;
}

if(arrivalmonth == "FEB") {
arrivalmonth = 2;
}

if(arrivalmonth == "MAR") {
arrivalmonth = 3;
}

if(arrivalmonth == "APR") {
arrivalmonth = 4;
}

if(arrivalmonth == "MAY") {
arrivalmonth = 5;
}

if(arrivalmonth == "JUN") {
arrivalmonth = 6;
}

if(arrivalmonth == "JUL") {
arrivalmonth = 7;
}

if(arrivalmonth == "AUG") {
arrivalmonth = 8;
}

if(arrivalmonth == "SEP") {
arrivalmonth = 9;
}

if(arrivalmonth == "OCT") {
arrivalmonth = 10;
}

if(arrivalmonth == "NOV") {
arrivalmonth = 11;
}

if(arrivalmonth == "DEC") {
arrivalmonth = 12;
}


arrivaldate = new Date(arrivalyear,arrivalmonth-1,arrivalday,23,59);
thedate = new Date();
jsdate = DateAdd(thedate, 320, 0, 0);

theday = new Date();

if (arrivaldate < theday){
     	alert('Your arrival date cannot be BEFORE today'); 
	thefrm.day.focus();
        return false;
    	}


if(arrivaldate > jsdate) {
thefrm.outday.value = arrivalday;
thefrm.outdate.value = thefrm.my.options[thefrm.my.selectedIndex].value;
thefrm.profile.value = "abcins";
thefrm.airport.value = thefrm.Location.value;
thefrm.method = "get";
thefrm.action = "http://www.holidayextras.co.uk/email/bookingengine/redirect_hotel.asp";
} else {
thefrm.action = "https://secure.relax-and-travel.co.uk/hotels/c/availability/";
thefrm.method = "post";
}
thefrm.submit();


}
