var availStartDate;
var startId;
var xmlHttp;

function AvailValidateForm()
{
	var strMessage;
	var bRetVal;
	var oForm;
	var jsCrLf;
	
	
	var weekday=new Array(7);
	weekday[0]="Sunday";
	weekday[1]="Monday";
	weekday[2]="Tuesday";
	weekday[3]="Wednesday";
	weekday[4]="Thursday";
	weekday[5]="Friday";
	weekday[6]="Saturday";

	strMessage = "";
	bRetVal = false;
	oForm = document.availtableform;
	oForm2 = document.availform;
	
	
	try
	{
		var tempVar = 0;
		
		var arrTmp = oForm2.fromdate.value.split("/");	
		
		var tempDate = new Date (arrTmp[2],(arrTmp[1]-1),arrTmp[0]);
		
		//alert(weekday[tempDate.getDay()]);
		//alert(arrTmp[2] + " " + (arrTmp[1]-1) + " " + arrTmp[0]);
		//alert(oForm.changeday.value);
		
		if(weekday[tempDate.getDay()] == oForm.changeday.value)
		{
			bRetVal = true;
		}
		else
		{
			alert("You must start your holiday on the property changeover date.");
		}
	}
	catch(e)
	{
	
	}
	
	if (bRetVal == true)
	{
		oForm2.submit()
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function getPrice(startDate, endDate, propRef, people)
{ 
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="http://www.dorsetcoastalcottages.com/CSDL/PHP/getPrice.php";
	url=url+"?startDate="+startDate;
	url=url+"&endDate="+endDate;
	url=url+"&propRef="+propRef;
	url=url+"&people="+people;
	
	xmlHttp.onreadystatechange = statePriceChanged;
	
	xmlHttp.open("GET",url,true)
	
	xmlHttp.send(null)
}

function statePriceChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("price").innerHTML = xmlHttp.responseText; 
		//alert(xmlHttp.responseText);
	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		//alert("Mozilla");
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			//	alert("IE");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			//	alert("IEError");
		}
	}
	
	return xmlHttp;
}

function toggleLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}

function highlightLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.border = style2.border? "":"1px solid red";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.border = style2.border? "":"1px solid red";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.border = style2.border? "":"1px solid red";
	}
}

function highlightById(id)
{
	if (document.getElementById)
	{
		var style2 = document.getElementById(id).style;
	}
	else if (document.all)
	{
		var style2 = document.all[id].style;
	}
	else if (document.layers)
	{
		var style2 = document.layers[whichLayer].style;
	}
	
	style2.backgroundColor = "#FFFFFF";
	style2.fontWeight = "bold";
}

function getElementsByName_iefix(tag, name)
{
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     var iarr = 0;
     var i = 0;
     for(i = 0,iarr = 0; i < elem.length; i++) {
          if(elem[i].getAttribute("name") == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}

function clearHighlights()
{
	var e = getElementsByName_iefix("td","avaTd");
	for(var i=0;i<e.length;i++)
	{
		e[i].style.backgroundColor = "#C6DDC1";
		e[i].style.fontWeight = "normal";
	}
	
	var e = getElementsByName_iefix("td","cdAvaTd");
	for(var i=0;i<e.length;i++)
	{
		e[i].style.backgroundColor = "#D6DA9A";
		e[i].style.fontWeight = "normal";
	}
	
	var e = getElementsByName_iefix("td","notAvaTd");
	for(var i=0;i<e.length;i++)
	{
		e[i].style.backgroundColor = "#AEAFB1";
		e[i].style.fontWeight = "normal";
	}
}

function date2string(myDate)
{
	var myDateString;

	var year = String(myDate.getFullYear()).substring(2);
	var month = myDate.getMonth()+1;
	var day = myDate.getDate();

	if (day<10)
	{
		day = "0"+day;
	}
	if (month<10)
	{
		month = "0"+month;
	}

	return day+"/"+month+"/"+year;
}

function updateAdults()
{
	document.bookingform.adults.value = document.getElementById('holAdults').value;
	changeHolLength();
}

function updateChildren()
{
	document.bookingform.children.value = document.getElementById('holChildren').value;
	changeHolLength();
}

function updateInfants()
{
	document.bookingform.infants.value = document.getElementById('holInfants').value;
	changeHolLength();
}

function updateCanc()
{
	document.bookingform.canc.value = document.bookingform.canc.value? "":"on";
}

function updateDonation()
{
	document.bookingform.donation.value = document.getElementById('holDonation').value;
}

function updatePets()
{
	//document.bookingform.pets.value = document.bookingform.pets.value? "":"on";
	document.bookingform.pets.value = document.getElementById('holPets').value;
}

function changeHolLength()
{
	var len = document.getElementById("holLength").value;
	clearHighlights();
	var one_day=1000*60*60*24;
	var endDate;
	
	var adults1 = parseInt(document.getElementById('holAdults').value);
	var children1 = parseInt(document.getElementById('holChildren').value);
	
	for(var i=0; i<=len; i++)
	{
		
		//var tempDay = new Date (availStartDate.getTime() + (one_day*i));
		var tempDay = new Date ((availStartDate.getFullYear()),(availStartDate.getMonth()),availStartDate.getDate()+i);
		var id = tempDay.getDate()+"-"+(tempDay.getMonth())+"-"+tempDay.getFullYear();
		
		document.getElementById('endDate').innerHTML = (tempDay.getDate())+"/"+(tempDay.getMonth()+1)+"/"+tempDay.getFullYear();
		document.getElementById('todate').value = tempDay.getDate()+"/"+(tempDay.getMonth()+1)+"/"+tempDay.getFullYear();
		endDate = new Date(tempDay.getFullYear(),tempDay.getMonth(),tempDay.getDate());
		
		try
		{	
			if(i < len)
			{
				if(document.getElementById(id).getAttribute("name") == "avaTd" || document.getElementById(id).getAttribute("name") == "cdAvaTd")
				{
					highlightById(id);
				}
				else
				{
					break;
				}
			}
			else
			{
				break;
			}
		}
		catch(err)
		{
		
		}
	}
	
	try
	{
		var thisDayTemp = availStartDate.getDate()+"-"+(availStartDate.getMonth()+1)+"-"+availStartDate.getFullYear();
		var endDayTemp = endDate.getDate()+"-"+(endDate.getMonth()+1)+"-"+endDate.getFullYear();
		getPrice(thisDayTemp, endDayTemp, document.getElementById('hiddenPropRef').value, adults1+children1);
	}
	catch(err)
	{
	
	}
}

function clickSeven(id)
{
	var arrTmp = id.split("-");
	var one_day=1000*60*60*24;
	var len = document.getElementById("holLength").value;
	var thisDay = new Date (arrTmp[2],arrTmp[1],arrTmp[0]);
	availStartDate = thisDay;
	startId = id;
	var thisDayPlus = new Date (thisDay.getTime() + (one_day*len));
	var endDate;
	
	
	var adults1 = parseInt(document.getElementById('holAdults').value);
	var children1 = parseInt(document.getElementById('holChildren').value);
	
	//alert("Test1");
	
	document.getElementById('startDate').innerHTML = thisDay.getDate()+"/"+(thisDay.getMonth()+1)+"/"+thisDay.getFullYear();
	document.getElementById('fromdate').value = thisDay.getDate()+"/"+(thisDay.getMonth()+1)+"/"+thisDay.getFullYear();
	
	//alert("Test2");
	
	clearHighlights();

	for(var i=0; i<=len; i++)
	{
		//var tempDay = new Date (availStartDate.getTime() + (one_day*i));
		var tempDay = new Date ((availStartDate.getFullYear()),(availStartDate.getMonth()),availStartDate.getDate()+i);
		var id = tempDay.getDate()+"-"+(tempDay.getMonth())+"-"+tempDay.getFullYear();
		
		document.getElementById('endDate').innerHTML = (tempDay.getDate())+"/"+(tempDay.getMonth()+1)+"/"+tempDay.getFullYear();
		document.getElementById('todate').value = (tempDay.getDate())+"/"+(tempDay.getMonth()+1)+"/"+tempDay.getFullYear();
		endDate = new Date(tempDay.getFullYear(),tempDay.getMonth(),tempDay.getDate());
		
		try
		{
			if(i < len)
			{
				if(document.getElementById(id).getAttribute("name") == "avaTd" || document.getElementById(id).getAttribute("name") == "cdAvaTd")
				{
					highlightById(id);
				}
				else
				{
					break;
				}
			}
			else
			{
				break;
			}
		}
		catch(err)
		{
		
		}
	}
	
	//alert("Selected dates " + thisDay.getDate()+"-"+(thisDay.getMonth()+1)+"-"+thisDay.getFullYear() + " to " + endDate.getDate()+"-"+(endDate.getMonth()+1)+"-"+endDate.getFullYear());
	
	var thisDayTemp = thisDay.getDate()+"-"+(thisDay.getMonth()+1)+"-"+thisDay.getFullYear();
	var endDayTemp = endDate.getDate()+"-"+(endDate.getMonth()+1)+"-"+endDate.getFullYear();
	
	getPrice(thisDayTemp, endDayTemp, document.getElementById('hiddenPropRef').value, adults1+children1);
}

function load()
{
	if (GBrowserIsCompatible())
	{
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(51.022394,0.66124), 13);
	}
}
function brochurerequestvalidateForm()
{
	var strMessage;
	var bRetVal;
	var oForm;
	var jsCrLf;
	strMessage = "";
	bRetVal = true;
	oForm = document.brochure;
	jsCrLf = String.fromCharCode(10,13);
	
	if (oForm.Surname.value == "")
	{
		strMessage = strMessage + "Please enter your full name" + jsCrLf;
	}
	if (oForm.address1.value == "")
	{
		strMessage = strMessage + "Please enter your Address" + jsCrLf;
	}
	if (oForm.postcode.value == "")
	{
		strMessage = strMessage + "Please enter your Postcode" + jsCrLf;
	}
	if (oForm.which.value == "" && (oForm.source.value == "" || oForm.source.value == "none" || oForm.source.value == "AWS"))
	{
		strMessage = strMessage + "Please tell us where you heard about us?" + jsCrLf;
	}
	if(oForm.emailoptin.checked && oForm.email.value == "")
	{
		strMessage = strMessage + "Please enter your email address if you require the email newsletter." + jsCrLf;
	}
	
	if (strMessage != "")
	{
		alert (strMessage);
		bRetVal = false;
	}
	
	if (bRetVal == true)
	{
		oForm.submit()
	}
}		


function window_display(strurl) {
  confirmWin = window.open(strurl,'theconfirmWin','toolbar=no,location=no,directories=no,status=yes,scrollbars=no,menubar=no,width=400,height=400,left=20,top=20');
  if (confirmWin.opener == null){
    confirmWin.opener = window;
  }
}

function ShowHidePrice(objDiv, strDisplay)
   {
    var strDivID=objDiv.id;
    var arrTmp=strDivID.split("_");
    if (arrTmp.length < 2)
    {
 	  alert("error: invalid object.\nobject id: "+strDivID);
 	  return false;
    }
    var strFaqId=arrTmp[1];
    var strPriceId="price_"+strFaqId;
    var objPrice=document.getElementById(strPriceId);
    if (!objPrice)
    {
 	  alert("error: price object does not exist.\nexpected id: "+strPriceId);
 	  return false;
    }
    objPrice.style.display = strDisplay;
    return true;
   }
   
   function AvailShowPrice(objDiv)
   {
    return ShowHidePrice(objDiv, "block");
   }
   
   function AvailHidePrice(objDiv)
   {
    return ShowHidePrice(objDiv, "none");
   }
	

function show_symbol_key() {
  confirmWin = window.open('http://www.norfolkcottages.co.uk/symbols.htm','symbols','toolbar=no,location=no,directories=no,status=yes,scrollbars=no,menubar=no,width=400,height=400,left=20,top=20');
  if (confirmWin.opener == null){
    confirmWin.opener = window;
  }
}



function BookingPropertyValidateFormOld()
{
		var strMessage;
		var bRetVal;
		var oForm;
		var jsCrLf;

		strMessage = "";
		bRetVal = true;
		oForm = document.bookingform;
		jsCrLf = String.fromCharCode(10,13);
		if (oForm.fromdate.value == "")
		{
			strMessage = strMessage + "Please enter a valid Arrival Date" + jsCrLf;
		}
		if (oForm.todate.value == "")
		{
			strMessage = strMessage + "Please enter a valid Departure Date" + jsCrLf;
		}
		if (oForm.adults.value == "")
		{
			strMessage = strMessage + "Please enter the number of Adults on your booking" + jsCrLf;
		}
		if (strMessage != "")
		{
			alert (strMessage);
			bRetVal = false;
		}
		
		if (bRetVal == true)
		{
			oForm.submit()
		}
}


function BookingCustomerValidateForm()
{
		var strMessage;
		var bRetVal;
		var oForm;
		var jsCrLf;

		strMessage = "";
		bRetVal = true;
		oForm = document.bookingform;
		jsCrLf = String.fromCharCode(10,13);
		if (oForm.surname.value == "")
		{
			strMessage = strMessage + "Please enter your Surname" + jsCrLf;
		}
		if (oForm.address1.value == "")
		{
			strMessage = strMessage + "Please enter your Address" + jsCrLf;
		}
		if (oForm.postcode.value == "")
		{
			strMessage = strMessage + "Please enter your Postcode" + jsCrLf;
		}
		if (oForm.workphone.value == "" && oForm.homephone.value == "" && oForm.mobile.value == "")
		{
			strMessage = strMessage + "Please enter at least one phone number" + jsCrLf;
		}
		if (oForm.email.value == "")
		{
			strMessage = strMessage + "Please enter your email address" + jsCrLf;
		}
		if (oForm.name1.value == "" || oForm.name2.value == "" || 
			oForm.name3.value == "" || oForm.name4.value == "" || 
			oForm.name5.value == "" || oForm.name6.value == "" || 
			oForm.name7.value == "" || oForm.name8.value == "" || 
			oForm.name9.value == "" || oForm.name10.value == "" || 
			oForm.name11.value == "" || oForm.name12.value == "" || 
			oForm.name13.value == "" || oForm.name14.value == "" ||
			oForm.name15.value == "" || oForm.name16.value == "" ||
			oForm.name17.value == "" || oForm.name18.value == "" || 
			oForm.name19.value == "" || oForm.name20.value == "")
		{
			strMessage = strMessage + "Please enter the name(s) of every member of your party" + jsCrLf;
		}
		
		if (oForm.age1.value == "" || oForm.age2.value == "" || 
			oForm.age3.value == "" || oForm.age4.value == "" || 
			oForm.age5.value == "" || oForm.age6.value == "" || 
			oForm.age7.value == "" || oForm.age8.value == "" || 
			oForm.age9.value == "" || oForm.age10.value == "" || 
			oForm.age11.value == "" || oForm.age12.value == "" || 
			oForm.age13.value == "" || oForm.age14.value == "" ||
			oForm.age15.value == "" || oForm.age16.value == "" ||
			oForm.age17.value == "" || oForm.age18.value == "" || 
			oForm.age19.value == "" || oForm.age20.value == "")
		{
			strMessage = strMessage + "Please enter the age(s) of every member of your party" + jsCrLf;
		}

		if ((oForm.age1.value != "xxx" && IsNumeric(oForm.age1.value)) ||
			(oForm.age2.value != "xxx" && IsNumeric(oForm.age2.value)) ||
			(oForm.age3.value != "xxx" && IsNumeric(oForm.age3.value)) ||
			(oForm.age4.value != "xxx" && IsNumeric(oForm.age4.value)) ||
			(oForm.age5.value != "xxx" && IsNumeric(oForm.age5.value)) ||
			(oForm.age6.value != "xxx" && IsNumeric(oForm.age6.value)) ||
			(oForm.age7.value != "xxx" && IsNumeric(oForm.age7.value)) ||
			(oForm.age8.value != "xxx" && IsNumeric(oForm.age8.value)) ||
			(oForm.age9.value != "xxx" && IsNumeric(oForm.age9.value)) ||
			(oForm.age10.value != "xxx" && IsNumeric(oForm.age10.value)) ||
			(oForm.age11.value != "xxx" && IsNumeric(oForm.age11.value)) ||
			(oForm.age12.value != "xxx" && IsNumeric(oForm.age12.value)) ||
			(oForm.age13.value != "xxx" && IsNumeric(oForm.age13.value)) ||
			(oForm.age14.value != "xxx" && IsNumeric(oForm.age14.value)) ||
			(oForm.age15.value != "xxx" && IsNumeric(oForm.age15.value)) ||
			(oForm.age16.value != "xxx" && IsNumeric(oForm.age16.value)) ||
			(oForm.age17.value != "xxx" && IsNumeric(oForm.age17.value)) ||
			(oForm.age18.value != "xxx" && IsNumeric(oForm.age18.value)) ||
			(oForm.age19.value != "xxx" && IsNumeric(oForm.age19.value)) ||
			(oForm.age20.value != "xxx" && IsNumeric(oForm.age20.value)))
		{
			strMessage = strMessage + "Please make sure that all ages are numbers" + jsCrLf;
		}
		
		if (oForm.which.value == "" && (oForm.source.value == "" || oForm.source.value == "none" || oForm.source.value == "AWS"))
		{
			strMessage = strMessage + "Please tell us where you heard about us?" + jsCrLf;
		}
		if (oForm.terms.checked == false)
		{
			strMessage = strMessage + "Please confirm that you agree to our booking terms and conditions" + jsCrLf;
		}
		if (strMessage != "")
		{
			alert (strMessage);
			bRetVal = false;
		}
		
		if (bRetVal == true)
		{
			oForm.submit();
		}
}			

function ShowHideBookingFormSection(objDiv, strDisplay)
   {
    var strDivID=objDiv;
    var arrTmp=strDivID.split("_");
    if (arrTmp.length < 2)
    {
 	  alert("error: invalid object.\nobject id: "+strDivID);
 	  return false;
    }
    var strFaqId=arrTmp[1];
    var strPriceId="bookform_"+strFaqId;
    var objPrice=document.getElementById(strPriceId);
    if (!objPrice)
    {
 	  alert("error: price object does not exist.\nexpected id: "+strPriceId);
 	  return false;
    }
    objPrice.style.display = strDisplay;
    return true;
   }
   
   function BookingFormShowSection(objDiv)
   {
    return ShowHideBookingFormSection(objDiv, "block");
   }
   
   function BookingFormHideSection(objDiv)
   {
    return ShowHideBookingFormSection(objDiv, "none");
   }

   function ownerpackrequestvalidateForm()
	{
		var strMessage;
		var bRetVal;
		var oForm;
		var jsCrLf;

		strMessage = "";
		bRetVal = true;
		oForm = document.ownerpack;
		jsCrLf = String.fromCharCode(10,13);
		if (oForm.Surname.value == "")
		{
			strMessage = strMessage + "Please enter your Surname" + jsCrLf;
		}
		if (oForm.address1.value == "")
		{
			strMessage = strMessage + "Please enter your Address" + jsCrLf;
		}
		if (oForm.postcode.value == "")
		{
			strMessage = strMessage + "Please enter your Postcode" + jsCrLf;
		}
		if (oForm.telnumber.value == "")
		{
			strMessage = strMessage + "Please enter your Telephone Number" + jsCrLf;
		}
		if (oForm.email.value == "")
		{
			strMessage = strMessage + "Please enter your Email Address" + jsCrLf;
		}
		if (oForm.where.value == "")
		{
			strMessage = strMessage + "Please tell us where your property is" + jsCrLf;
		}
		if (oForm.whichone.value == "" && (oForm.source.value == "" || oForm.source.value == "none" || oForm.source.value == "AWS"))
		{
			strMessage = strMessage + "Please tell us where you heard about us?" + jsCrLf;
		}
		
		if (strMessage != "")
		{
			alert (strMessage);
			bRetVal = false;
		}
		
		if (bRetVal == true)
		{
			oForm.submit()
		}
	}			

	function addToFavoritesOLD() {
		if (window.external) {
			window.external.AddFavorite(location.href, document.title) 
		} else {
			alert("Sorry! Your browser doesn't support this function."); 
		}
	}


function addToFavorites() {
    if (window.sidebar) {
        window.sidebar.addPanel(document.title, location.href,"");
    } else if( document.all ) {
        window.external.AddFavorite( location.href, document.title);
    } else if( window.opera && window.print ) {
        return true;
    }
}
function switchpic(which){
document.mainpic.src=which
}

var bigimages=new Array()    // array for images to be preloaded

function IsNumeric(PossibleNumber)
{
	var PNum = new String(PossibleNumber);
	var regex = /[^0-9]/;
	return regex.test(PNum);
}



function check_length(id, maxchars)
{
	var element = document.getElementById(id);
	var len = element.value.length;
	
	if (len > maxchars)
	{
		element.value = element.value.substr(0,maxchars);
		len = maxchars;
	}
	
	document.getElementById(id).innerHTML = len;
	document.getElementById(id).innerHTML = maxchars - len;
}


function window_display(strurl) {
  confirmWin = window.open(strurl,'theconfirmWin','toolbar=no,location=no,directories=no,status=yes,scrollbars=no,menubar=no,width=400,height=400,left=20,top=20');
  if (confirmWin.opener == null){
    confirmWin.opener = window;
  }
}

function onloadHighlight(fromdate)
{
	var arrTmp = fromdate.split("-");
	
	if(arrTmp[2].substring(0,1) == "0")
	{
		arrTmp[2] = arrTmp[2].substring(1,2);
	}
	
	var id = arrTmp[2] + "-" + (arrTmp[1]-1) + "-" + arrTmp[0];
	
	//alert(id);
	
	clickSeven(id);
}

function BookingPropertyValidateForm()
{
	var strMessage;
	var bRetVal;
	var oForm;
	var jsCrLf;
	strMessage = "";
	bRetVal = true;
	oForm = document.bookingform;
	var len = document.getElementById("holLength").value;
	//oForm = document.availform;
	jsCrLf = String.fromCharCode(10,13);
	
	if (oForm.fromdate.value == "")
	{
		strMessage = strMessage + "Please enter a valid Arrival Date" + jsCrLf;
	}
	if (oForm.todate.value == "")
	{
		strMessage = strMessage + "Please enter a valid Departure Date" + jsCrLf;
	}
	if (document.getElementById("adults").value == "" || document.getElementById("adults").value == 0)
	{
		strMessage = strMessage + "Please enter the number of Adults on your booking" + jsCrLf;
	}
	
	if(oForm.fromdate.value != "")
	{
		var arrTmp = oForm.fromdate.value.split("/");	
		var arrTmp2 = oForm.todate.value.split("/");	
			
		var thisDate = new Date();
		var thisDate1 = new Date(thisDate.getYear(), thisDate.getMonth(), thisDate.getDate()+1);			
		var thisDate7 = new Date(thisDate.getYear(), thisDate.getMonth(), thisDate.getDate()+7);
		var selectedDate = new Date(arrTmp[2],arrTmp[1]-1,arrTmp[0]);
		var selectedDate2 = new Date(arrTmp2[2],arrTmp2[1]-1,arrTmp2[0]);
		var datediff = days_between(thisDate, selectedDate);
		var datediff2 = days_between(selectedDate, selectedDate2);
		var proceedAnyway = false;
		
		if(len > datediff)
		{
			len = datediff;
		}
				
		if(selectedDate < thisDate)
		{
			strMessage = "You cannot make a booking which starts in the past.";
			proceedAnyway = false;
		}
	}
	
	if((parseInt(oForm.adults.value)) > oForm.sleeps.value)
	{
		strMessage = "The number of adults exceed the maximum allowed in the property.  Please check and try again or select another property." + jsCrLf;
		proceedAnyway = false;
	}
	
	if((parseInt(oForm.adults.value) + parseInt(oForm.children.value)) > oForm.sleeps.value)
	{
		strMessage = "The number of adults and children exceed the maximum allowed in the property.  Please check and try again or select another property." + jsCrLf;
		proceedAnyway = false;
	}
	
	if(datediff2 < 7)
	{
		var temp = selectedDate.getMonth()+1 + "-" + selectedDate.getDate();
		//alert(temp);
		//if(temp == "3-21" || temp == "3-22" || temp == "3-23" || temp == "3-24" || temp == "3-25" || temp == "3-26" || temp == "3-27" || temp == "3-28")
		//{
		//	bRetVal = false;
		//	strMessage = "Currently, short breaks are disabled for the weeks beginning 21/03/2008 and 28/03/2008." + jsCrLf;
		//}
		
		//if(selectedDate.getMonth()+1 == "4")
		//{
		//	if((selectedDate.getDate() > "4" && selectedDate.getDate() < "18"))
		//	{
		//		bRetVal = false;
		//		strMessage = "Currently, short breaks are disabled for the weeks beginning 04/04/2008 and 18/04/2008." + jsCrLf;
		//	}
		//}
		
		/*if(selectedDate.getMonth()+1 == "5")
		{
			if((selectedDate.getDate() > "23" && selectedDate.getDate() < "30"))
			{
				bRetVal = false;
				strMessage = "Currently, short breaks are disabled for the weeks beginning 23/05/2008 and 30/05/2008." + jsCrLf;
			}
		}
		
		if((selectedDate.getMonth()+1 >= 5) && (selectedDate.getMonth()+1 <= 9))
		{
			bRetVal = false;
			strMessage = "Short Breaks within this period are only accepted 2 weeks before the departure date. Please contact us on 0800 9804070 if you are experiencing problems and we will be happy to book you into the cottage of your choice." + jsCrLf;
			
			if(selectedDate.getMonth()+1 == 5)
			{
				if((selectedDate.getDate() < "23"))
				{
					bRetVal = true;
					strMessage = "";
				}
			}
			
			if(selectedDate.getMonth()+1 == 9)
			{
				if((selectedDate.getDate() > "27"))
				{
					bRetVal = true;
					strMessage = "";
				}
			}
		}
				
		if(selectedDate.getMonth()+1 == "10")
		{
			if((selectedDate.getDate() >= "24") && (selectedDate.getDate() < "31"))
			{
				//bRetVal = false;
				//strMessage = "Short Breaks within this period are only accepted 2 weeks before the departure date. Please contact us on 0800 9804070 if you are experiencing problems and we will be happy to book you into the cottage of your choice." + jsCrLf;
			}
			
		}
		
		if(selectedDate.getMonth()+1 == "12")
		{
			if(selectedDate.getDate() >= 22 && selectedDate.getDate() <= 31)
			{
				bRetVal = false;
				strMessage = "Short Breaks within this period are only accepted 2 weeks before the departure date. Please contact us on 0800 9804070 if you are experiencing problems and we will be happy to book you into the cottage of your choice." + jsCrLf;
			}
		}
		
		if(oForm.fromdate.value == "1/1/2009")
		{
			bRetVal = false;
			strMessage = "Short Breaks within this period are only accepted 2 weeks before the departure date. Please contact us on 0800 9804070 if you are experiencing problems and we will be happy to book you into the cottage of your choice." + jsCrLf;
		}
	*/
	}
	
	if(datediff < 14)
	{
		strMessage = "";
		if (document.getElementById("adults").value == "" || document.getElementById("adults").value == 0)
		{
			strMessage = strMessage + "Please enter the number of Adults on your booking" + jsCrLf;
		}
		else
		{
			bRetVal = true;
			strMessage = "";
		}
		
	}
	if((len % 7) != 0)
	{
		if(selectedDate.getMonth()+1 == "12")
		{
			if(selectedDate.getDate() >= 22 && selectedDate.getDate() <= 31)
			{
				if(len < 3)
				{
					bRetVal = false;
					strMessage = "Christmas Breaks within this period are subject to a minimum of 3 nights." + jsCrLf;
				}
				
			}
						
			if((selectedDate2.getDate() >= "22"))
			{
				if(len < 3)
				{
					bRetVal = false;
					strMessage = "Christmas Breaks within this period are subject to a minimum of 3 nights." + jsCrLf;
				}
			}
		}
		
		try
		{
			var datediff = 0;
			var fromdateTmp = document.getElementById("fromdate").value.split("/");
			var todateTmp = document.getElementById("todate").value.split("/");
			var fromdate = new Date (fromdateTmp[2],fromdateTmp[1]-1,fromdateTmp[0]);
			var todate = new Date (todateTmp[2],todateTmp[1]-1,todateTmp[0]);
			
			//alert(fromdate + " " + todate);
			
			if(fromdate < todate)
			{
				var diff = ((todate - fromdate)/(24*60*60*1000));
				
				if(diff < 7)
				{
					//alert(ShortBreaksAllowed(fromdate, todate));
				
					if(ShortBreaksAllowed(fromdate, todate) == "false")
					{
						strMessage = "Sorry, short breaks for this period are not permitted. Please see 'Short Breaks' for restriction details.";
						bRetVal = false;
					}	
				}
			}
		}
		catch(e)
		{
			strMessage = 'An error occurred taking your booking, please call us and we will be happy to help.';
			bRetVal = false;
		}
	}
	else
	{
		if(selectedDate.getMonth()+1 == "12")
		{
			if((selectedDate2.getDate() != "29"))
			{
				if((selectedDate2.getDate() >= "22"))
				{
					if(datediff < 3)
					{
						bRetVal = false;
						strMessage = "Christmas Breaks within this period are subject to a minimum of 3 nights." + jsCrLf;
					}
				}
			}
			
		}
			var datediff = 0;
			var fromdateTmp = document.getElementById("fromdate").value.split("/");
			var todateTmp = document.getElementById("todate").value.split("/");
			var fromdate = new Date (fromdateTmp[2],fromdateTmp[1]-1,fromdateTmp[0]);
			var todate = new Date (todateTmp[2],todateTmp[1]-1,todateTmp[0]);
		if(ShortBreaksAllowed(fromdate, todate) == "false")
		{
			if(selectedDate.getMonth()+1 == "12")
			{
				if(selectedDate.getDate() == 22 || selectedDate.getDate() == 29)
				{
					// Allow christmas changeovers
				}
				else
				{
					strMessage = "Unfortunately during Peak Periods all bookings must run on the designated changeover day for the cottage.  It is possible for flexibility in certain circumstances, so please call the office on 0800 9804070 to discuss.  Office is open from 9am to 6pm Mon to Friday and Saturday/Sunday 3pm to 6pm.";
					bRetVal = false;
				}
			}
			else
			{
				strMessage = "Unfortunately during Peak Periods all bookings must run on the designated changeover day for the cottage.  It is possible for flexibility in certain circumstances, so please call the office on 0800 9804070 to discuss.  Office is open from 9am to 6pm Mon to Friday and Saturday/Sunday 3pm to 6pm.";
				bRetVal = false;
			}
			
		}
		else
		{
			if(selectedDate.getMonth()+1 == "12")
			{
				if((selectedDate.getDate() != "29"))
				{
					if((selectedDate.getDate() != "22"))
					{
						if((selectedDate.getDate() > "18"))
						{
							strMessage = "Unfortunately during Peak Periods all bookings must run on the designated changeover day for the cottage.  It is possible for flexibility in certain circumstances, so please call the office on 0800 9804070 to discuss.  Office is open from 9am to 6pm Mon to Friday and Saturday/Sunday 3pm to 6pm.";
							bRetVal = false;
						}
					}
				}
			}
		}
	}

	
	var propref = document.getElementById("propref").value;
		
	if(document.getElementById("price").innerHTML == "Call")
	{
		//bRetVal = false;
		//strMessage = "We are currently not accepting bookings for this property with the criteria that you have entered.  Please contact us on 0800 9804070 between the hours of 9am - 6pm Monday to Saturday and we will be happy to help." + jsCrLf;
	}

		
	if (strMessage != "")
	{
		alert (strMessage);
		bRetVal = false;
		
		if(proceedAnyway == true)
		{
			bRetVal = true;
		}
	}
	if (bRetVal == true)
	{
		oForm.submit()
	}
}


function days_between(date1, date2) {

    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24;

    // Convert both dates to milliseconds
    var date1_ms = date1.getTime();
    var date2_ms = date2.getTime();

    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms);
    
    // Convert back to days and return
    return Math.round(difference_ms/ONE_DAY);

}

function ShortBreaksAllowed(fromdate, todate)
{
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	
	var propref = document.getElementById("propref").value;
	
	var url="http://www.dorsetcoastalcottages.com/CSDL/PHP/availability/shortBreakCheck.php";
	url = url + "?startdate=" + fromdate.getDate()+"-"+(fromdate.getMonth()+1)+"-"+fromdate.getFullYear();
	url = url + "&todate=" + todate.getDate()+"-"+(todate.getMonth()+1)+"-"+todate.getFullYear();
	url = url + "&propref=" + propref;
	url = url + "&rand=" + Math.floor(Math.random()*10000000);
	
	//alert(url);
	
	xmlHttp.open("GET",url,false);
	xmlHttp.send(null);
	
	return xmlHttp.responseText;
}