	
function CP_getCalendar() {
	var now = new Date();
	if (this.type == "WINDOW") { var windowref = "window.opener."; }
	else { var windowref = ""; }
	var result = "";
	if (this.type == "WINDOW") {
		result += "<HTML><HEAD><TITLE>Calendar</TITLE>"+this.getStyles()+"</HEAD><BODY MARGINWIDTH=0 MARGINHEIGHT=0 TOPMARGIN=0 RIGHTMARGIN=0 LEFTMARGIN=0>\n";
		result += '<CENTER><TABLE WIDTH=100% BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>\n';
		}
	else {
		result += '<TABLE CLASS="'+this.cssPrefix+'cpBorder" CELLSPACING=0 CELLPADDING=0>\n';
		result += '<TR><TD ALIGN=CENTER>\n';
		result += '<CENTER>\n';
		}
	if (this.displayType=="date" || this.displayType=="week-end") {
		if (this.currentDate==null) { this.currentDate = now; }
		if (arguments.length > 0) { var month = arguments[0]; }
			else { var month = this.currentDate.getMonth()+1; }
		if (arguments.length > 1 && arguments[1]>0 && arguments[1]-0==arguments[1]) { var year = arguments[1]; }
			else { var year = this.currentDate.getFullYear(); }
		var daysinmonth= new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
		if ( ( (year%4 == 0)&&(year%100 != 0) ) || (year%400 == 0) ) {
			daysinmonth[2] = 29;
			}
		var current_month = new Date(year,month-1,1);
		var display_year = year;
		var display_month = month;
		var display_date = 1;
		var weekday= current_month.getDay();
		var offset = 0;
		
		offset = (weekday >= this.weekStartDay) ? weekday-this.weekStartDay : 7-this.weekStartDay+weekday ;
		if (offset > 0) {
			display_month--;
			if (display_month < 1) { display_month = 12; display_year--; }
			display_date = daysinmonth[display_month]-offset+1;
			}
		var next_month = month+1;
		var next_month_year = year;
		if (next_month > 12) { next_month=1; next_month_year++; }
		var last_month = month-1;
		var last_month_year = year;
		if (last_month < 1) { last_month=12; last_month_year--; }
		var date_class;
		if (this.type!="WINDOW") {
			result += "<TABLE WIDTH='100%' BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>";
			}
		result += '<TR>\n';
		var refresh = windowref+'CP_refreshCalendar';
		var refreshLink = 'javascript:' + refresh;
		if (this.isShowNavigationDropdowns) {
			result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="78" COLSPAN="3"><select CLASS="'+this.cssPrefix+'cpMonthNavigation" name="cpMonth" onChange="'+refresh+'('+this.index+',this.options[this.selectedIndex].value-0,'+(year-0)+');">';
			for( var monthCounter=1; monthCounter<=12; monthCounter++ ) {
				var selected = (monthCounter==month) ? 'SELECTED' : '';
				result += '<option value="'+monthCounter+'" '+selected+'>'+this.monthNames[monthCounter-1]+'</option>';
				}
			result += '</select></TD>';
			result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="10">&nbsp;</TD>';

			result += '<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="56" COLSPAN="3"><select CLASS="'+this.cssPrefix+'cpYearNavigation" name="cpYear" onChange="'+refresh+'('+this.index+','+month+',this.options[this.selectedIndex].value-0);">';
			var wv_date = new Date();
			var wv_year = wv_date.getFullYear();
			for( var yearCounter=2002; yearCounter<=wv_year+1; yearCounter++ ) {
				var selected = (yearCounter==year) ? 'SELECTED' : '';
				result += '<option value="'+yearCounter+'" '+selected+'>'+yearCounter+'</option>';
				}
			result += '</select></TD>';
			}
		else {
			if (this.isShowYearNavigation) {
				result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="10"><A CLASS="'+this.cssPrefix+'cpMonthNavigation" HREF="'+refreshLink+'('+this.index+','+last_month+','+last_month_year+');">&lt;</A></TD>';
				result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="58"><SPAN CLASS="'+this.cssPrefix+'cpMonthNavigation">'+this.monthNames[month-1]+'</SPAN></TD>';
				result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="10"><A CLASS="'+this.cssPrefix+'cpMonthNavigation" HREF="'+refreshLink+'('+this.index+','+next_month+','+next_month_year+');">&gt;</A></TD>';
				result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="10">&nbsp;</TD>';

				result += '<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="10"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="'+refreshLink+'('+this.index+','+month+','+(year-1)+');">&lt;</A></TD>';
				if (this.isShowYearNavigationInput) {
					result += '<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="36"><INPUT NAME="cpYear" CLASS="'+this.cssPrefix+'cpYearNavigation" SIZE="4" MAXLENGTH="4" VALUE="'+year+'" onBlur="'+refresh+'('+this.index+','+month+',this.value-0);"></TD>';
					}
				else {
					result += '<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="36"><SPAN CLASS="'+this.cssPrefix+'cpYearNavigation">'+year+'</SPAN></TD>';
					}
				result += '<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="10"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="'+refreshLink+'('+this.index+','+month+','+(year+1)+');">&gt;</A></TD>';
				}
			else {
				result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="15%">';
				
				if (checkCurrentMonth("prev",month,year)) {
					result += '<A HREF="'+refreshLink+'('+this.index+','+last_month+','+last_month_year+');"><img src=\"../../images/cal_back.gif" /></A>';
				}
				else {
					result += '<img src=\"../../images/cal_back_disabled.gif" />\n';
				}
				result += '</TD>\n';
				
				result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="65%"><SPAN>'+this.monthNames[month-1]+' '+year+'</SPAN></TD>\n';
				
				result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="15%">';

				if (checkCurrentMonth("next",month,year)) {
					result += '<A HREF="'+refreshLink+'('+this.index+','+next_month+','+next_month_year+');"><img src=\"../../images/cal_forward.gif" /></A>\n';
				}
				else {
					result += '<A HREF="'+refreshLink+'('+this.index+','+next_month+','+next_month_year+');"><img src=\"../../images/cal_forward.gif" /></A>\n';
				}
				
				result += '</TD>\n';
				}
			}
		result += '</TR></TABLE>\n';
		result += '<TABLE BORDER=0 HEIGHT=150 CELLSPACING=2 CELLPADDING=1 ALIGN=CENTER STYLE="margin:0px 10px">\n';
		result += '<TR>\n';
		for (var j=0; j<7; j++) {

			result += '<TD CLASS="'+this.cssPrefix+'cpDayColumnHeader" WIDTH="14%"><SPAN CLASS="'+this.cssPrefix+'cpDayColumnHeader">'+this.dayHeaders[(this.weekStartDay+j)%7]+'</TD>\n';
			}
		result += '</TR>\n';
		for (var row=1; row<=6; row++) {
			result += '<TR>\n';
			for (var col=1; col<=7; col++) {
				var disabled=false;
				if (this.disabledDatesExpression!="") {
					var ds=""+display_year+LZ(display_month)+LZ(display_date);
					eval("disabled=("+this.disabledDatesExpression+")");
					}
				var dateClass = "";
				if ((display_month == this.currentDate.getMonth()+1) && (display_date==this.currentDate.getDate()) && (display_year==this.currentDate.getFullYear())) {
					dateClass = "cpCurrentDate";
					}
					
				else if (otherDate(addZeros(display_date)+"/"+addZeros(display_month)+"/"+display_year)) {
					dateClass = "cpOtherDate"
				}				
				
				else if (display_month == month) {
					dateClass = "cpCurrentMonthDate";
					}
				else {
					dateClass = "cpOtherMonthDate";
					}
				if (disabled || this.disabledWeekDays[col-1]) {
					if (otherDate(addZeros(display_date)+"/"+addZeros(display_month)+"/"+display_year)) {
						result += '	<TD CLASS="'+this.cssPrefix+dateClass+'"><SPAN CLASS="'+this.cssPrefix+dateClass+'Disabled cpOtherDate">'+display_date+'</SPAN></TD>\n';
					}
					else {
						result += '	<TD CLASS="'+this.cssPrefix+dateClass+'"><SPAN CLASS="'+this.cssPrefix+dateClass+'Disabled">'+display_date+'</SPAN></TD>\n';
					}
				}
				else {
					var selected_date = display_date;
					var selected_month = display_month;
					var selected_year = display_year;
					if (this.displayType=="week-end") {
						var d = new Date(selected_year,selected_month-1,selected_date,0,0,0,0);
						d.setDate(d.getDate() + (7-col));
						selected_year = d.getYear();
						if (selected_year < 1000) { selected_year += 1900; }
						selected_month = d.getMonth()+1;
						selected_date = d.getDate();
						}
					result += '	<TD CLASS="'+this.cssPrefix+dateClass+'"><A HREF="javascript:'+windowref+this.returnFunction+'('+selected_year+','+selected_month+','+selected_date+');'+windowref+'CP_hideCalendar(\''+this.index+'\');disableCheckoutDates();updateCheckout();updateNights();" CLASS="'+this.cssPrefix+dateClass+'">'+display_date+'</A></TD>\n';
					}
				display_date++;
				if (display_date > daysinmonth[display_month]) {
					display_date=1;
					display_month++;
					}
				if (display_month > 12) {
					display_month=1;
					display_year++;
					}
				}
			result += '</TR>';
			}
		var current_weekday = now.getDay() - this.weekStartDay;
		if (current_weekday < 0) {
			current_weekday += 7;
			}
		result += '<TR>\n';
		result += '</TR></TABLE></CENTER></TD></TR>\n';
		result += '<TR><TD COLSPAN=7 ALIGN=CENTER CLASS="'+this.cssPrefix+'cpTodayText">\n';
		result += '		<A CLASS="'+this.cssPrefix+'cpTodayText" HREF="javascript:'+windowref+'CP_hideCalendar(\''+this.index+'\');">'+this.todayText+'</A>\n';
		result += '		<BR>\n';
		result += '	</TD></TR></TABLE>\n';
	}

	if (this.displayType=="month" || this.displayType=="quarter" || this.displayType=="year") {
		if (arguments.length > 0) { var year = arguments[0]; }
		else { 
			if (this.displayType=="year") {	var year = now.getFullYear()-this.yearSelectStartOffset; }
			else { var year = now.getFullYear(); }
			}
		if (this.displayType!="year" && this.isShowYearNavigation) {
			result += "<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>";
			result += '<TR>\n';
			result += '	<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="22"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="javascript:'+windowref+'CP_refreshCalendar('+this.index+','+(year-1)+');">&lt;&lt;</A></TD>\n';
			result += '	<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="100">'+year+'</TD>\n';
			result += '	<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="22"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="javascript:'+windowref+'CP_refreshCalendar('+this.index+','+(year+1)+');">&gt;&gt;</A></TD>\n';
			result += '</TR></TABLE>\n';
			}
		}
		
	if (this.displayType=="month") {
		result += '<TABLE WIDTH=120 BORDER=0 CELLSPACING=1 CELLPADDING=0 ALIGN=CENTER>\n';
		for (var i=0; i<4; i++) {
			result += '<TR>';
			for (var j=0; j<3; j++) {
				var monthindex = ((i*3)+j);
				result += '<TD WIDTH=33% ALIGN=CENTER><A CLASS="'+this.cssPrefix+'cpText" HREF="javascript:'+windowref+this.returnMonthFunction+'('+year+','+(monthindex+1)+');'+windowref+'CP_hideCalendar(\''+this.index+'\');" CLASS="'+date_class+'">'+this.monthAbbreviations[monthindex]+'</A></TD>';
				}
			result += '</TR>';
			}
		result += '</TABLE></CENTER></TD></TR></TABLE>\n';
		}
	
	if (this.displayType=="quarter") {
		result += '<BR><TABLE WIDTH=120 BORDER=1 CELLSPACING=0 CELLPADDING=0 ALIGN=CENTER>\n';
		for (var i=0; i<2; i++) {
			result += '<TR>';
			for (var j=0; j<2; j++) {
				var quarter = ((i*2)+j+1);
				result += '<TD WIDTH=50% ALIGN=CENTER><BR><A CLASS="'+this.cssPrefix+'cpText" HREF="javascript:'+windowref+this.returnQuarterFunction+'('+year+','+quarter+');'+windowref+'CP_hideCalendar(\''+this.index+'\');" CLASS="'+date_class+'">Q'+quarter+'</A><BR><BR></TD>';
				}
			result += '</TR>';
			}
		result += '</TABLE></CENTER></TD></TR></TABLE>\n';
		}

	if (this.displayType=="year") {
		var yearColumnSize = 4;
		result += "<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>";
		result += '<TR>\n';
		result += '	<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="50%"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="javascript:'+windowref+'CP_refreshCalendar('+this.index+','+(year-(yearColumnSize*2))+');">&lt;&lt;</A></TD>\n';
		result += '	<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="50%"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="javascript:'+windowref+'CP_refreshCalendar('+this.index+','+(year+(yearColumnSize*2))+');">&gt;&gt;</A></TD>\n';
		result += '</TR></TABLE>\n';
		result += '<TABLE WIDTH=120 BORDER=0 CELLSPACING=1 CELLPADDING=0 ALIGN=CENTER>\n';
		for (var i=0; i<yearColumnSize; i++) {
			for (var j=0; j<2; j++) {
				var currentyear = year+(j*yearColumnSize)+i;
				result += '<TD WIDTH=50% ALIGN=CENTER><A CLASS="'+this.cssPrefix+'cpText" HREF="javascript:'+windowref+this.returnYearFunction+'('+currentyear+');'+windowref+'CP_hideCalendar(\''+this.index+'\');" CLASS="'+date_class+'">'+currentyear+'</A></TD>';
				}
			result += '</TR>';
			}
		result += '</TABLE></CENTER></TD></TR></TABLE>\n';
		}
	if (this.type == "WINDOW") {
		result += "</BODY></HTML>\n";
		}
	return result;
	}

if (window.location.href.indexOf("-popup.htm") < 0) {
	var yesterday = new Date();
	yesterday.setDate(yesterday.getDate() - 1);
	
	var nextyear = disabledNextYearDates();
	var checkinCal = new CalendarPopup("calendar");
	checkinCal.addDisabledDates(null,formatDate(yesterday,"yyyy-MM-dd")); 
	checkinCal.addDisabledDates(formatDate(nextyear,"yyyy-MM-dd")); 
	var checkoutCal = new CalendarPopup("calendar");
	checkoutCal.addDisabledDates(null,formatDate(yesterday,"yyyy-MM-dd")); 
	checkinCal.addDisabledDates(formatDate(nextyear,"yyyy-MM-dd")); 
}

function showCheckinCal() {
	var checkin = document.getElementById("checkin");
	saveFocus("checkin");
	checkinCal.select(checkin,'checkin','dd/MM/yyyy'); 
}

function showCheckoutCal() {
	var checkout = document.getElementById("checkout");
	updateCheckout(); 
	saveFocus("checkout");
	checkoutCal.select(checkout,'checkout','dd/MM/yyyy');
}

function showHotelCheckinCal() {
	var hotelcheckin = document.getElementById("hotelcheckin");
	checkinCal.select(hotelcheckin,'hotelcheckin','dd/MM/yyyy'); 
}

function disableCheckoutDates() {
	var checkin_date = document.getElementById("checkin").value; //get check in date
	if (checkin_date != "dd/MM/yyyy") {
		checkoutCal = "";
		checkoutCal = new CalendarPopup("calendar");
		var checkin_dates = checkin_date.split("/");
		var checkin_day = checkin_dates[0];
		var checkin_month = checkin_dates[1] - 1;
		var checkin_year = checkin_dates[2];
		var checkin = new Date(checkin_year,checkin_month,checkin_day);
		checkoutCal.addDisabledDates(null,formatDate(checkin, "yyyy-MM-dd"));
		checkoutCal.addDisabledDates(formatDate(nextyear,"yyyy-MM-dd"),null); 
		//checkoutCal.addDisabledDates(null,formatDate(checkin, "dd-MM-yyyy"));
		//checkoutCal.addDisabledDates(formatDate(nextyear,"dd-MM-yyyy"),null); 
	}
}

function updateCheckout() {
	var checkin_date = document.getElementById("checkin");
	var checkout_date = document.getElementById("checkout");
	
	if (checkin_date.value != "dd/mm/yyyy" && checkout_date.value == "dd/mm/yyyy") {
		var checkin_dates = checkin_date.value.split("/");
		var checkin_day = checkin_dates[0];
		var checkin_month = checkin_dates[1] - 1;
		var checkin_year = checkin_dates[2];
		var new_checkout_date = new Date(checkin_year,checkin_month,checkin_day);
		new_checkout_date.setDate(new_checkout_date.getDate() + 1);
		checkout_date.value = formatDate(new_checkout_date, "dd/MM/yyyy");
	}
	
	if (checkin_date != "dd/mm/yyyy" && checkout_date != "dd/mm/yyyy") {
		var date_checkin_date = getDateObject(checkin_date.value);
		var date_checkout_date = getDateObject(checkout_date.value);
		if (date_checkin_date >= date_checkout_date) {
			var newdate = new Date(date_checkin_date.setDate(date_checkin_date.getDate() + 1));
			checkout_date.value = addZeros(newdate.getDate())+"/"+addZeros(newdate.getMonth()+1)+"/"+takeYear(newdate)
		}		
		
	}
	
	
}


function addZeros(thedate) {
	thedate += ""; 
	if (thedate.length == 1) {
		thedate = "0"+thedate; 
	}
	return thedate;
}

function takeYear(theDate) {
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}

function updateNights() {
	var checkin_date = document.getElementById("checkin").value;
	var checkout_date = document.getElementById("checkout").value;
	if (checkin_date != "dd/mm/yyyy" && checkout_date != "dd/mm/yyyy") {
		
		var date_checkin = getDateObject(checkin_date);
		
		var date_checkout = getDateObject(checkout_date);
		
		var date_difference = parseInt((date_checkout.getTime() - date_checkin.getTime()) / (1000 * 60 * 60 * 24));
		
		var nightsfield = document.getElementById("numberofnights");
		if (date_difference > 0) {
			nightsfield.innerHTML = date_difference;
		}
		else {
			nightsfield.innerHTML = "0";
		}
		
	}
}

var currentFocus;
function saveFocus(element) {
	switch(element) {
		case "checkin":
			currentFocus = "checkin";
			break;
		case "checkout":
			currentFocus = "checkout";
			break;
	}
	return currentFocus	
}


function getDateObject(thedate) {
	var split_dates = thedate.split("/");
	var day = split_dates[0];
	var month = split_dates[1] - 1;
	var year = split_dates[2];
	var date_object = new Date(year,month,day);
	return date_object;
}

function otherDate(thedate) {
		
	switch(currentFocus) {
		
		case "checkin":
			var checkout_date = document.getElementById("checkout").value;
			if (checkout_date != "dd/mm/yyyy") {
				if (checkout_date == thedate) {
					return true;
				}
			}
			break;
		
		case "checkout":
			var checkin_date = document.getElementById("checkin").value;
			if (checkin_date != "dd/mm/yyyy") {
				if (checkin_date == thedate) {
					return true;
				}
			}
			break;
	}
	
	return false;
	
}

function disabledNextYearDates() {
	var thedate = new Date(); 
	
	var cyear = takeYear(thedate); 
	var cmonth = thedate.getMonth();
	
	var nyear = cyear+2; 
	var nmonth = cmonth+2; 
	
	if (nmonth == 12) {
		nmonth = 0;
		nyear = nyear+2;
	}
	
	var nextyeardate = new Date(nyear,nmonth);
	return nextyeardate;
	
}

function checkCurrentMonth(actiontype,month,year) {
	

	var currentdate = new Date();
	var caldate = new Date(year,month-1,1);
	
	switch(actiontype) {
		case "prev":
			var thisdate = new Date(takeYear(currentdate),currentdate.getMonth());
			if (caldate <= thisdate) {
				return false;
			}
			else {
				return true;
			}
			break;
		case "next":
			var nextyeardate = new Date(takeYear(currentdate)+1,currentdate.getMonth());
			if (caldate >= nextyeardate) {
				return false;
			}
			else {
				return true;
			}
			break;
	}			
	
}

function addLoadEvent(func) {
	if (window.location.href.indexOf("-popup.htm") < 0) {
		var oldonload = window.onload;
		if (typeof window.onload != "function") {
			window.onload = func;
		}
		else {
			window.onload = function() {
				oldonload();
				func();
			}
		}
	}
}

/* FUNCTION TESTS THAT THE USERS BROWSER IS CAPABLE OF USING THE DOM */

function isDOMCompatible() {
	if (document.getElementById) {
		return true;
	}
	return false;
}

/* FUNCTION WRITES THE SEARCH FORM FIELDS TO A COOKIE ON SUBMITTING THE FORM */

function saveForm(theform) {
		
	//loop through all fields on the form
	var cookiestring = "";
	var ratings = "";
	for (var i=0;i<theform.elements.length;i++) {
		switch(theform.elements[i].name) {
			//checkin
			case "checkin":
				cookiestring+="checkin="+theform.elements[i].value;
				break;
			//checkout
			case "checkout":
				cookiestring+="&checkout="+theform.elements[i].value;
				break;

			case "o":
				if (ratings != "") {
					ratings = "&r="+ratings.substring(0,ratings.length-1);
				}
				if (theform.elements[i].value != "popular") {
					cookiestring+=ratings+"&o="+theform.elements[i].value;
				}
			}
		
	}
	//write the cookie
	document.cookie = "search="+cookiestring;	
	
	
}


/* THIS SECTION ADDS THE DYNAMIC CONTENT TO THE SEARCH FORM SO THAT IT CAN STILL BE USED BY NON-JAVASCRIPT USERS */

function initSearchForm() {
	
	//add the number of nights display
	var datediv = document.getElementById("dates");
	var numnights = createNumNights();
	datediv.appendChild(numnights);
	
	//add calendars
	var checkincal = createCal("checkin");
	var checkoutcal = createCal("checkout");
	var checkinspan = datediv.getElementsByTagName("span")[0];
	var checkoutspan = datediv.getElementsByTagName("span")[1];
	//add checkin cal
	checkinspan.appendChild(checkincal);
	//add checkout cal
	checkoutspan.appendChild(checkoutcal);
	
	//strip extra room types
	//var roomtype2 = document.getElementById("rt2");
	//roomtype2.parentNode.removeChild(roomtype2);
	//var roomtype3 = document.getElementById("rt3");
	//roomtype3.parentNode.removeChild(roomtype3);
	
	//add the add new room type checkbox and label
	//var addroom = createAddRoom();
	//var roomdiv = document.getElementById("rooms");
	//roomdiv.appendChild(addroom);
	
	//change the header
	if (document.getElementById("right") && readCookie("search")) {
		document.getElementById("search-form-ln").getElementsByTagName("h1")[0].innerHTML = "Change your search";
	}
	
}



/* FUNCTION CREATES THE CHECKIN CALENDAR */
function createCal(cal) {
	var callink = document.createElement("a");
	//callink.href = "#";
	callink.title = "select your dates on a calendar";
	switch(cal) {
		case "checkin":
			callink.onclick = function() {showCheckinCal();return false;};
			break;
		case "checkout":
			callink.onclick = function() {showCheckoutCal();return false;};
			break;
	}
	var calimg = document.createElement("img");
	calimg.src = "../../images/searchform-calendar.gif";
	
	calimg.setAttribute("width","24");
	calimg.setAttribute("height","15");
	
	callink.appendChild(calimg);
	
	return callink;
	
}

addLoadEvent(initSearchForm);

function checkinput(){

frm = document.bookingform;
var chkin=frm.checkin.value;
var chkout=frm.checkout.value; 
var today = "20080729";


tm1=chkin.split("/");
tm2=chkout.split("/");      
      
	time1 = tm1[2]+tm1[1]+tm1[0];
	time2 = tm2[2]+tm2[1]+tm2[0];
	
	check1= time1-today;
	check2= time2-time1;
	
	if(!ValidateForm(document.bookingform.checkin)){
		return;
	}
	
	if(!ValidateForm(document.bookingform.checkout)){
		return;
	}

	if(check1 < 0){
		alert("Check in date must than today");
		return false;
	}
	if(check2 <= 0){
		alert("Check out date must than check in date");
		frm.checkout.focus();
		return false;
	}
	if(frm.first_name.value == ""){
		alert("Please insert your name!");
		frm.first_name.focus();
		return;
	}
	if(frm.email_address.value == ""){
		alert("Please insert your email!");
		frm.email_address.focus();
		return;
	}
	if(!isemail(frm.email_address.value)){
		alert("Your email do not match!");
		frm.email_address.focus();
		return;
	}
	if(!ischeckin(frm.checkin.value)){
		alert("Your date do not match!");
		frm.checkin.focus();
		return;
	}
	
	frm.submit();
}


function checkkey(e){
	var mykey=e.keyCode? e.keyCode : e.charCode
	if (mykey==13) checkinput();
}

function isemail(email_address) {
	var re = /^(\w|[^_]\.[^_]|[\-])+(([^_])(\@){1}([^_]))(([a-z]|[\d]|[_]|[\-])+|([^_]\.[^_]) *)+\.[a-z]{2,3}$/i
	return re.test(email_address);
}

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function ValidateForm(dt){
	
	//var dt=document.bookingform.checkin
	
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }
