// JavaScript Document
function readupdate()
{
	dummy = window.open("common/pragueupdate.htm","explain","dependent=yes,toolbar=no,menubar=no,status=no,directories=no,width=300,height=300,resizable=yes,scrollbars=yes,screenx=100,left=100,screeny=100,top=100");
	dummy.focus()
}

function showselectinfo()
{
	dummy = window.open("common/<%=strLang%>/selectinfo.htm","explain","dependent=yes,toolbar=no,menubar=no,status=no,directories=no,width=500,height=200,resizable=yes,scrollbars=yes,screenx=100,left=100,screeny=100,top=100");
	dummy.focus()
}

function next()
{
	if (Srch_onsubmit()) 
	{
	document.Srch.submit();
	}
}

function Srch_onsubmit() 
{
 // Validate fields 
if (CheckForm() )
  return true;
 else
  return false;	
}
     
function CheckForm()
{
	// city validation
	if (document.Srch.cboCityString.options[document.Srch.cboCityString.selectedIndex].value == "")
	{
		window.alert("You have omitted to select a destination."); 
		document.Srch.cboCityString.focus();
		return false;
	}
	else
	{
		var str = document.Srch.cboCityString.options[document.Srch.cboCityString.selectedIndex].text;
		if (str.indexOf("--",0) != -1 || str.indexOf("[",0) != -1 || str == "" )
		{
			window.alert("You have omitted to select a destination."); 
			document.Srch.cboCityString.focus();
			return false;
		}
	}

	// Make  Date variables
	var dteDept  = new Date(document.Srch.DeptMonthYr.options[document.Srch.DeptMonthYr.selectedIndex].value.toString().substr(2,4),(document.Srch.DeptMonthYr.options[document.Srch.DeptMonthYr.selectedIndex].value.toString().substr(0,2) -1), document.Srch.DeptDay.options[document.Srch.DeptDay.selectedIndex].text);
	var dteReturn  = new Date(document.Srch.ReturnMonthYr.value.toString().substr(2,6), (document.Srch.ReturnMonthYr.value.toString().substr(0,2) - 1), document.Srch.ReturnDay.value);
	
	// today's date
	var	dteNow = new Date(YAHOO.example.calendar.cal1.cfg.getProperty("mindate"));

	// if they've entered an invalid date the date function will force it to a valid date
	// if the date is invalid the day value will not match.

	if (dteDept.getDate() != parseInt(document.Srch.DeptDay.options[document.Srch.DeptDay.selectedIndex].value))
	{
		window.alert("The check-in date is invalid");
		document.Srch.DeptDay.focus();
		return false;
	}

	if (dteDept.valueOf() < dteNow.valueOf())
	{
		if (Math.abs(dteDept.valueOf() - dteNow.valueOf()) <= 86400000)
		{

		window.alert("We are unable to process a booking for this date online. Please call us to book accommodation for tonight.");
		
		}
		else
		{
		window.alert("The check-in date you have supplied has already passed");
		document.Srch.DeptDay.focus();
		}
		return false;
	}

	if (dteDept.valueOf() >= dteReturn.valueOf())
	{
		window.alert("The check-in date must be earlier than the check-out date");
		Srch.DeptDay.focus();
		return false;
	}

	if ((dteReturn.valueOf() - dteDept.valueOf())  > (31 * 86400000) )
	{
		window.alert("Please contact us for stays of more than one month");
		Srch.DeptDay.focus();
		return false;
	}

	//room validation
	
	if (document.Srch.txtRooms1.options[document.Srch.txtRooms1.selectedIndex].value == "0" & document.Srch.txtRooms2.options[document.Srch.txtRooms2.selectedIndex].value == "0" & document.Srch.txtRooms3.options[document.Srch.txtRooms3.selectedIndex].value == "0" & document.Srch.txtRooms4.options[document.Srch.txtRooms4.selectedIndex].value == "0")
	{
		window.alert("You have omitted to select your required number/type of rooms"); 
		document.Srch.txtRooms1.focus();
		return false;
	}

   if (parseInt(document.Srch.txtRooms1.options[document.Srch.txtRooms1.selectedIndex].value*2,10) + parseInt(document.Srch.txtRooms2.options[document.Srch.txtRooms2.selectedIndex].value*2,10) + parseInt(document.Srch.txtRooms3.options[document.Srch.txtRooms3.selectedIndex].value,10) + parseInt(document.Srch.txtRooms4.options[document.Srch.txtRooms4.selectedIndex].value*3,10) > 9)
    {
     window.alert("For bookings of 10 people or more please contact us by phone on +44(0)845 230 8888");
       document.Srch.txtRooms1.focus();
       return false;
      }

	return true;

}

function changeimage(imgname,newimage) {
		if (document.images) {
			document.images[imgname].src= newimage ;
		}
	}

function loadimages() {
	myimg = new Array()
	a=loadimages.arguments
	for (i=0;i<a.length;i++) {
		myimg[i] = new Image
		myimg[i].src=a[i]
		}
	}

function launch(who){
  newWind=window.open(who +".html","newWindow","status=no,toolbar=no,scrollbars=YES,width=350,height=400 screenX=100,screenY=100,top=100,left=50");
  newWind.focus();
}
										  
  function workOutDeptDate () {
var dtMonthYr, dtDay, dtCheckout, dtNoOfNights,  dtYr, dtDisplayDate, dtDisplayDay, dtDisplayMonth, dtDisplayYear, dtReturnMonthYr
var dtDisplayCheckout, dtMonth

 //Get Departure Date
dtNoOfNights = document.Srch.Nights.value
dtMonthYr = document.Srch.DeptMonthYr.value
dtDay = document.Srch.DeptDay.value
dtDisplayMonth = dtMonthYr.substring(0,2)
dtYr = dtMonthYr.substring(2,7)

//Remove 1 from Month as Months are zero based in Javascript
dtDisplayMonth = dtDisplayMonth - 1

//Add No of Nights
 dtDay = parseInt(dtDay) + parseInt(dtNoOfNights)

//create DISPLAY date
dtCheckout = new Date(dtYr, dtDisplayMonth, dtDay)

//Break Date Down
dtDisplayDay = dtCheckout.getDate().toString()
dtDisplayMonth = dtCheckout.getMonth().toString()
dtDisplayYear = dtCheckout.getFullYear().toString()

//Add a zero to day 
if (dtDisplayDay.valueOf() < 10){
	dtDisplayDay = "0" +  dtDisplayDay
}

var monthName
monthName = new Array();
monthName[0] = "January";
monthName[1] = "February";
monthName[2] = "March";
monthName[3] = "April";
monthName[4] = "May";
monthName[5] = "June";
monthName[6] = "July";
monthName[7] = "August";
monthName[8] = "September";
monthName[9] = "October";
monthName[10] = "November";
monthName[11] = "December";

//write out dates to Display Fields
document.getElementById("DisplayDate").innerHTML = dtDisplayDay + " " + monthName[dtDisplayMonth] + " " + dtDisplayYear

//add +1 back for the ASP date
dtDisplayMonth = parseInt(dtDisplayMonth)
dtDisplayMonth =  dtDisplayMonth + 1

//Add a zero to month

if (dtDisplayMonth.valueOf() < 10){
	dtDisplayMonth = "0" +  dtDisplayMonth
}

dtReturnMonthYr = dtDisplayMonth + dtDisplayYear

//write out dates to Hidden Fields
document.Srch.ReturnMonthYr.value = dtReturnMonthYr 
document.Srch.ReturnDay.value = dtDisplayDay
}