	function getnextmonth(themonthyearID)   {
		pospos=themonthyearID.indexOf("-");
		themonth=Number(themonthyearID.substring(0,pospos));
		theyear=Number(themonthyearID.substring(pospos+1));
		themonth2=themonth+1;
		if (themonth2==13)   {
			themonth2=1;
			theyear2=theyear+1;
			}
		else   { theyear2=theyear; }
		themonthyearID2=themonth2+"-"+theyear2;
		return themonthyearID2;	
		}

	function showMonths(monthyearID)   {
		if (document.getElementById(monthyearID)==undefined) alert("Sorry - no availability data is set for this month..");
		else   {
			displayshowtxt=document.initdisplayedmonthform.browsertestf.value;
			prevmonthyearID=document.initdisplayedmonthform.prevmonthyearID.value;
			eval("document.getElementById(\""+prevmonthyearID+"\").style.display=\"none\";");
			theyear = prevmonthyearID.substring(prevmonthyearID.length - 1,prevmonthyearID.length)
			if (theyear%2==1) theclass="monthcell";
			else theclass="monthcell2";
			eval("document.getElementById(\"C"+prevmonthyearID+"\").className=\""+theclass+"\";");
			eval("document.getElementById(\""+monthyearID+"\").style.display=\""+displayshowtxt+"\";");
			eval("document.getElementById(\"C"+monthyearID+"\").className=\"monthcellnow\";");
			document.initdisplayedmonthform.prevmonthyearID.value=monthyearID;
			}
		}


	function SetupInitialMonths()   {
		// initial check of browser type by checking how CSS background color is returned by javascript !
		if (document.getElementById("browsertest").style.backgroundColor=="#ffffff")   {  displayshowtxt="block";  }
		else  {  displayshowtxt="table-row";   }
		// now set the hidden field with browsertest result so we can re-use
		document.initdisplayedmonthform.browsertestf.value=displayshowtxt;
		// start off by showing current month 
		prevmonthyearID=document.initdisplayedmonthform.prevmonthyearID.value;
		eval("document.getElementById(\""+prevmonthyearID+"\").style.display=\""+displayshowtxt+"\";");
		} 

	function toggle_button(weekimage, productID, shortbreaksearch, hvalue) {
		// get the unique part of the ID
		baseID = weekimage.name.substring(6);
		targetID = "CF" + baseID;
		// now need to extract the - chars since js eval() doesn't like it !
		abbrevbaseID=baseID.replace(/-/g,"");
		ctargetID = "check" + abbrevbaseID;
		if (weekimage.src=="http://www.cumbrian-cottages.co.uk/images/book-now.gif")  {
			document.getElementById(targetID).innerHTML = "<img id=\"CFdivA" + baseID + "\" name=\"CFdivA" + baseID + "\" src=\"/images/select-to-book.gif\" onClick=\"toggle_button(this,'" + productID + "','" + shortbreaksearch + "','" + hvalue + "');\" border=\"0\"/>";
			eval("document.bookingboxesform." + ctargetID + ".checked=false;");
			}
		else  {
			document.getElementById(targetID).innerHTML = "<img id=\"CFdivA" + baseID + "\" name=\"CFdivA" + baseID + "\" usemap=\"#map" + baseID + "\" src=\"/images/book-now.gif\" border=\"0\"/><map name=\"map" + baseID + "\"><area href=\"javascript:toggle_button(document.getElementById('CFdivA" + baseID + "'),'" + productID + "','" + shortbreaksearch + "','" + hvalue + "');\" shape=\"rect\" coords=\"1,1,28,20\" /><area href=\"javascript:CheckBooking('" + productID + "','" + shortbreaksearch + "','" + hvalue + "')\" shape=\"rect\" coords=\"29,0,142,20\" /></map>";
			eval("document.bookingboxesform." + ctargetID + ".checked=true;");
			}
		}


	function CheckBooking(productID, shortbreaksearch, hvalue)  {
		//check all selected checkboxes to make sure there are dates selected
		//and that the dates are ajacent periods

		var strCheckedDates="";
		var msg="";
		var finaldates="";
		
//alert("Our apologies - out Automated Booking System is currently undergoing maintenance.\n\n\tPlease call 01228 599960 to make your booking.");		

		for (i=0; i<document.bookingboxesform.elements.length; i++)  {
			if (document.bookingboxesform.elements[i].checked==true) { 
				elname = document.bookingboxesform.elements[i].name;
				if (strCheckedDates.indexOf(elname)==-1)   {  
					strCheckedDates = strCheckedDates + elname  + "|";  
					}
				}
			}
		arrayCheckedDates=strCheckedDates.split("|");

		// ensure no greater than 3 weeks are requested
		if (arrayCheckedDates.length > 4)   {  msg="Sorry, we only allow a maximum of 3 weeks per booking"; 	}
		else   {
			var loopstart = 1;
			var datesarevalid = 1;
			// check that gap between dates does not exceed 7 days
			for (i=0;i<arrayCheckedDates.length-1;i++)   {
				theday=Number(arrayCheckedDates[i].substring(11));
				themonth=Number(arrayCheckedDates[i].substring(9,11));
				theyear=Number(arrayCheckedDates[i].substring(7,9)) + 2000;
				thedate = new Date(theyear, themonth - 1, theday);
				thedatetime = thedate.getTime();

				// get properly formatted start date so we can use when final link to booking stage done
				if (i==0)   {
					// subtract 5.5 days (should be six but we need to allow for UTC anomalies) so we are working with the start of the week, not the end
					startdatetime = new Date(thedatetime - (86400000 * 5.5));
					finalday = startdatetime.getDate();
					finalmonth = startdatetime.getMonth() + 1;
					finalyear = startdatetime.getFullYear();
					thestartdate=finalyear+"-"+sanitise_num_tostring(finalmonth)+"-"+sanitise_num_tostring(finalday);
					}
				if (loopstart==0)   {
					diff=thedatetime - prevdatetime;
					// changed from 604800000 to 608400000 - difference of 1 sec
					if (diff > 608400000) datesarevalid = 0;
					} 
				prevdatetime = thedatetime;
				loopstart=0;
				}
			// a duration of >7 days was detected
			if (datesarevalid==0) msg="Sorry, the booked weeks must be consecutive";
			}

		if (msg!="")   { alert(msg);  }
		else   {  
			// now use size of finaldates to get the duration
			duration=(arrayCheckedDates.length-1) * 7;
			//finalURL="https://cumbrian-cottages.secure-holidays.com/book-now.aspx?productid="+productID+"&startdate="+thestartdate+"&Duration="+duration+"&shortbreaksearch="+shortbreaksearch+"&hvalue="+hvalue;
			finalURL="https://derbyshire-cottages.secure-holidays.com/book-now.aspx?productid="+productID+"&startdate="+thestartdate+"&Duration="+duration+"&shortbreaksearch="+shortbreaksearch+"&hvalue="+hvalue;
			window.location=finalURL;
			}

		}
	function extractparamfromQstring (pname, pdefaultvalue)   {
		pos1 = location.href.indexOf(pname);
		if (pos1 != -1)   {
			str1 = location.href.substring(pos1 + pname.length + 1);
			pos2 = str1.indexOf('&');
			if (pos2 != -1) thevalue = str1.substring(0, pos2);
			else thevalue = str1;
			return thevalue;
			}
		else return pdefaultvalue;
		}

	// this function pre-sets the booking text/checkbox if client comes back via browser back button
	function resetBookingCells()  {

		var productID, startdate, duration, shortbreaksearch, hvalue;

		// get values from the querystring
		productID = extractparamfromQstring ("productid", "0");
		startdate = extractparamfromQstring ("startdate", "00:00:00");
		duration = extractparamfromQstring ("Duration", "0");
		shortbreaksearch = extractparamfromQstring ("shortbreaksearch", "0");
		hvalue = Number(extractparamfromQstring ("hvalue", "0")) + 1;

		// now set the booking cells
		for (i=0; i<document.bookingboxesform.elements.length; i++)  {
			if (document.bookingboxesform.elements[i].checked==true) { 
				elname = document.bookingboxesform.elements[i].name.substring(5);
				baseID = elname.substring(0,4) + "-" + elname.substring(4,6) + "-" + elname.substring(6);
				targetID = "CF" + baseID;
				document.getElementById(targetID).innerHTML = "<img id=\"CFdivA" + baseID + "\" name=\"CFdivA" + baseID + "\" usemap=\"#map" + baseID + "\" src=\"/images/book-now.gif\" border=\"0\"/><map name=\"map" + baseID + "\"><area href=\"javascript:toggle_button(document.getElementById('CFdivA" + baseID + "'),'" + productID + "','" + shortbreaksearch + "','" + hvalue + "');\" shape=\"rect\" coords=\"1,1,28,20\" /><area href=\"javascript:CheckBooking('" + productID + "','" + shortbreaksearch + "','" + hvalue + "')\" shape=\"rect\" coords=\"29,0,142,20\" /></map>";
				}
			}
		}

	