// <![CDATA[

function escrambleDesign(){
	
}

function escrambleCottages()
{
	var a,b,c,d,e,f,g,h,i
	a='<a href=\"mai'
	b='enquiries'
	c='\">'
	a+='lto:'
	b+='@'
	e='</a>'
	f=''
	b+='stewartscountrycottages.co.uk'
	g='<img src=\"'
	h=''
	i='\" alt="Email us." border="0">'

	if (f) d=f
	else if (h) d=g+h+i
	else d=b

	document.write(a+b+c+d+e)
}

function loadFlash()
{
	var so = new SWFObject("template/flash/stock images.swf?xml_path=slides.xml", "stock images", "268", "196", "7", "#ffffff");
	so.write("flashcontent");
}

function disableControls()
{
	document.getElementById('y').disabled = true;
	document.getElementById('m').disabled = true;
	document.getElementById('customerName').disabled = true;
	document.getElementById('addDateButton').style.display = 'none';
	document.getElementById('bookings').disabled = true;
	document.getElementById('removeDateButton').style.display = 'none';
}

function enableControls()
{
	if(document.getElementById('cottage').options[document.getElementById('cottage').selectedIndex].value == 'none')
	{
		disableControls();
	}
	else
	{
		document.getElementById('y').disabled = false;
		document.getElementById('m').disabled = false;
		document.getElementById('customerName').disabled = false;
		document.getElementById('addDateButton').style.display = 'block';
		document.getElementById('bookings').disabled = false;
		document.getElementById('removeDateButton').style.display = 'block';
	}
}

function getSubCategory()
{
	var xmlHttp;
	var firstbox = document.getElementById('cmsCategory');
	var secondbox = document.getElementById('cmsSubCategory');
	
	if(firstbox.selectedIndex == 0) return;
	
	var selectedOption = firstbox.options[firstbox.selectedIndex].value;
	var url = "updateSelectPage.php?c=" + selectedOption;
	
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		// Internet Explorer
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			secondbox.options.length = 0;
			textToSplit = xmlHttp.responseText;
			returnElements = textToSplit.split("||");
			secondbox.options[0] = new Option("Please Select a Sub-category:", "none");
			for(var i = 0; i < returnElements.length; i++)
			{
	            valueLabelPair = returnElements[i].split("|")
	            secondbox.options[i+1] = new Option(valueLabelPair[1], valueLabelPair[0]);
			}
		}
	}
	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function getContent()
{
	var xmlHttp;
	var firstbox = document.getElementById('cmsCategory');
	var secondbox = document.getElementById('cmsSubCategory');
	var content = document.getElementById('listContent');
	
	if(firstbox.selectedIndex == 0) return;
	if(secondbox.selectedIndex == 0) return;
	
	var selectedCategory = firstbox.options[firstbox.selectedIndex].value;
	var selectedSubCategory = secondbox.options[secondbox.selectedIndex].value;
	var url = "updateSelectPage.php?c=" + selectedCategory + "&s=" + selectedSubCategory;
	
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			content.innerHTML = xmlHttp.responseText;
		}
	}
	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function loadCalendar(cottage, month, year)
{
	var xmlHttp;
	var calendar = document.getElementById('calendar');
	var url = "ajaxCalendar.php?c=" + cottage + "&m=" + month + "&y=" + year;
	
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			calendar.innerHTML = xmlHttp.responseText;
		}
	}
	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function getMonths(property, month, year)
{
	var xmlHttp;
	var months = document.getElementById('monthDiv');
	var url = "updateCalendar.php?f=getMonths&year=" + year + "&month=" + month;
	
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			temp = '<select name=\"m\" id=\"m\" onchange=\"loadCalendar(\'' + property + '\', document.getElementById(\'m\').options[document.getElementById(\'m\').selectedIndex].value, document.getElementById(\'y\').options[document.getElementById(\'y\').selectedIndex].value)\" class=\"date\">';
			temp += xmlHttp.responseText;
			temp += "</select>";
			months.innerHTML = temp;
		}
	}
	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function getBookings()
{
	var cottage = document.getElementById('cottage');
	var url = "updateCalendar.php?c=" + cottage.options[cottage.selectedIndex].value + "&f=getBookings";
	var bookings = document.getElementById('removeDate');
	var xmlHttp;
	
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			bookings.innerHTML = "<select name='date' id='bookings' multiple>" + xmlHttp.responseText + "</select>";
		}
	}
	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function setBooking()
{
	var cottage = document.getElementById('cottage');
	var name = document.getElementById('customerName');
	var startDate = document.getElementById('startDate');
	var endDate = document.getElementById('endDate');
	var url = "updateCalendar.php?c=" + cottage.options[cottage.selectedIndex].value + "&f=setBooking" + "&name=" + escape(name.value) + "&startDate=" + escape(startDate.value) + "&endDate=" + escape(endDate.value);
	
	var bookings = document.getElementById('bookings');
	var xmlHttp;
	
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function removeBooking()
{
	var cottage = document.getElementById('cottage');
	var bookings = document.getElementById('bookings');
	var url = "updateCalendar.php?c=" + cottage.options[cottage.selectedIndex].value + "&f=removeBooking" + "&name=" + bookings.options[bookings.selectedIndex].value;
	var xmlHttp;
	
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}


// ]]>
