function largeImage(width,height,imageNumber,template,row,rows)
{
	row++;
	var imageDiv = document.getElementById("imageDiv");
	
	while (imageDiv.hasChildNodes())
	{
		imageDiv.removeChild(imageDiv.firstChild);
		
	}
	
	var image = document.createElement('img');
	image.className = "displayImage";
	image.src='/generic/image?image=' + template;
	image.id='image' + imageNumber;
	image.style.background = "url(/generic/image?image=" + imageNumber + ")";
	image.style.width=width + "px";	
	image.style.height=height + "px";	
	
	var remainder = row % rows;
	var addon = 0;
	if(remainder > 0) addon = rows - remainder;
	var line = (row + addon) / rows;
	if(line > 3)
	{		
		image.style.position = "relative";
		var offset = ((line-3) * height) + "px";
		image.style.top = offset;
	}
	
	imageDiv.appendChild(image);
}

function removeImage(imageNumber)
{
	var imageDiv = document.getElementById("imageDiv");
	while (imageDiv.hasChildNodes())
	{
		imageDiv.removeChild(imageDiv.firstChild);
	}
	
	//var image = document.getElementById('image' + imageNumber);
	//image.className = "hideImage";
}

function showTutorText(message,siteNumber)
{
	myWindow = window.open('/','mywin','left=100,top=100,width=300,height=200,toolbar=0,resizable=0');
	myWindow.document.write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>");
	myWindow.document.write("<html><head><link rel='stylesheet' type='text/css' href='/styles/style" + siteNumber + ".css'>");
	myWindow.document.write("<title>Tutor Details</title></head>");
	myWindow.document.write("<body>");
	myWindow.document.write("<div class='showBrochureTutorText'><h2>About the tutor</h2>" + message + "</div>");
	myWindow.document.write("</body>");
	myWindow.document.write("</html>");
	myWindow.document.title = "Tutor Details";	
	myWindow.document.close();
}

var newWindow = null;

function imageWindow(imageNumber,height,width,caption)
{
	link = "";
	if(newWindow) newWindow.close();
	newWindow = window.open(link,"image",'left=150,top=150,width=' + width + ',height=' + height + ',toolbar=0,resizable=0,border=1,menubar=0');
	newWindow.document.write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>");
	newWindow.document.write("<html><head>");
	newWindow.document.write("\n<script type='text/javascript'>");
	newWindow.document.write("\nfunction closeWindow()");
	newWindow.document.write("\n{");
	newWindow.document.write("\nthis.close();");
	newWindow.document.write("\n}");
	newWindow.document.write("\n</script>");
	newWindow.document.write("<title>" + caption + "</title></head>");
	newWindow.document.write("<body style='padding:0px;margin:0px;width:" + width + ";height:" + height + "'>");
	newWindow.document.write("<img style='border-style:none;position:relative;top:0px;left:0px;' class='imageWindow' src='/generic/image?image=" + imageNumber + "' />");
	newWindow.document.write("</body>");
	newWindow.document.write("</html>");
	newWindow.focus();
}
function googleMap() 
{   
	var div = document.getElementById("googlemap");
	if(div)
	{
		var lonlat = div.title;
		var comma = lonlat.indexOf(",");
		var lat = lonlat.substring(0,comma);
		var lon = lonlat.substring(comma+1);	
		var myLatlng = new google.maps.LatLng(lat,lon);
		var myOptions = {zoom:18,center: myLatlng,mapTypeId:google.maps.MapTypeId.SATELLITE};
		var map = new google.maps.Map(div, myOptions); 
		var marker = new google.maps.Marker({position: myLatlng,map: map}); 
	}
}






var days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

function selectBookingDate()
{
	
	var selectDateDiv = document.getElementById("selectDate");
	if(selectDateDiv)
	{
		var today = new Date();
		var dayNo = 0;
		var startMonth = today.getMonth();
		for(var month = 1; month < 13; month++)
		{
			var monthDiv = document.createElement('div');
			monthDiv.className = "monthDiv";
			
			var monthHeader = document.createElement('div');
			if(startMonth == 12) startMonth = 0;
			monthHeader.innerHTML = months[startMonth];
			monthHeader.className = "monthHeader";
			monthDiv.appendChild(monthHeader);
			
			var dayHeader1 = document.createElement('div');
			dayHeader1.className = "weekDayHeader";
			dayHeader1.innerHTML = "M";
			monthDiv.appendChild(dayHeader1);
			
			var dayHeader2 = document.createElement('div');
			dayHeader2.className = "weekDayHeader";
			dayHeader2.innerHTML = "T";
			monthDiv.appendChild(dayHeader2);
			
			var dayHeader3 = document.createElement('div');
			dayHeader3.className = "weekDayHeader";
			dayHeader3.innerHTML = "W";
			monthDiv.appendChild(dayHeader3);
			
			var dayHeader4 = document.createElement('div');
			dayHeader4.className = "weekDayHeader";
			dayHeader4.innerHTML = "T";
			monthDiv.appendChild(dayHeader4);
			
			var dayHeader5 = document.createElement('div');
			dayHeader5.className = "weekDayHeader";
			dayHeader5.innerHTML = "F";
			monthDiv.appendChild(dayHeader5);
			
			var weekendHeader1 = document.createElement('div');
			weekendHeader1.className = "weekendHeader";
			weekendHeader1.innerHTML = "S";
			monthDiv.appendChild(weekendHeader1);
			
			var weekendHeader2 = document.createElement('div');
			weekendHeader2.className = "weekendHeader";
			weekendHeader2.innerHTML = "S";
			monthDiv.appendChild(weekendHeader2);
			
			var clearLeft1 = document.createElement('div');
			clearLeft1.className = "clearLeft";
			monthDiv.appendChild(clearLeft1);
			
			// How many blank days?
			
			for(var count = 1; count < today.getDay(); count++)
			{
				var dayDiv = document.createElement('div');
				dayDiv.className = "weekDayDiv";
				monthDiv.appendChild(dayDiv);
			}
			
			var dayDiv = new Array();
			
			while(today.getMonth() == startMonth)
			{
				dayDiv[dayNo] = document.createElement('div');
				//dayDiv.onclick = confirmDate;
				dayDiv[dayNo].className = "weekDayDiv";
				if(bookings.length >= dayNo)
				{
					if(bookings[dayNo] == 100)
					{
						dayDiv[dayNo].style.color = "rgb(255,0,0)";
						dayDiv[dayNo].title = "This day is not available";
					}
					else 
					{
						dayDiv[dayNo].style.color = "rgb(0,255,0)";
						dayDiv[dayNo].title = dayNo;
					}
				}
				else 
				{
					dayDiv[dayNo].style.color = "rgb(0,255,0)";
					dayDiv[dayNo].title = dayNo;
				}
				dayDiv[dayNo].innerHTML = today.getDate();
				//			dayDiv[dayNo].onclick = function() {confirmDate(dayNo);};
				dayDiv[dayNo].onclick = (function(dayNo){return function (){confirmDate(dayNo)}})(dayNo);
				monthDiv.appendChild(dayDiv[dayNo]);
				today.setDate(today.getDate() + 1);
				count++;
				dayNo++;
				if(count > 7)
				{
					var clearLeft2 = document.createElement('div');
					clearLeft2.className = "clearLeft";
					monthDiv.appendChild(clearLeft2);
					count = 1;
				}
			}
			selectDateDiv.appendChild(monthDiv);
			startMonth++;
		}
	}
}
var newWindow = null;
function confirmDate(dayDiv)
{
	link = "";	
	if(newWindow) newWindow.close();
	newWindow = window.open(link,"image",'left=150,top=150,width=500,height=500,toolbar=1,resizable=1,border=1,menubar=1');
	newWindow.document.write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>");
	newWindow.document.write("<html><head>");
	newWindow.document.write("\n<link rel='stylesheet' type='text/css' href='/styles/master.css'/>");
	
	newWindow.document.write("\n<script language='JavaScript' src='/scripts/booking.js' type='text/javascript'></script>");
	
	newWindow.document.write("<title>Booking Form</title></head>");
	newWindow.document.write("<body style=padding:0px;margin-left:10px;width:500px;height:500px;background:rgb(240,240,240);>");
	newWindow.document.write("<form onSubmit='return closeWindow()'>");
	//  newWindow.document.write("<form onSubmit='window.opener.focus()'>");
	
	var fromDate = new Date();
	fromDate.setDate(fromDate.getDate() + dayDiv);
	
	
	
	//       newWindow.document.write("<p>day=" + dayDiv + " Please fill in the following details, then confirm your booking.</p>");	
	//        newWindow.document.write("<p>You are booking for " + fromDate.toString('dateFormat.FULL') + "</p>");
	
	
	
	
	
	newWindow.document.write("<p>You are booking for " + days[fromDate.getDay()] + " " + fromDate.getDate() + " " + months[fromDate.getMonth()] + " " + fromDate.getFullYear() + "</p>");
	
	//now.format("m/dd/yy");
	
	
	newWindow.document.write("<p>Please fill in the following details, then confirm your booking.</p>");
	newWindow.document.write("First Name: <input type='text' id='firstName'></input> Family Name: <input type='text' id='familyName'></input>");
	newWindow.document.write("\n<br/><br/>Email: <input type='text' id='email' name='email'></input>");
	newWindow.document.write("\n<br/><br/>Phone Number: <input type='text' name='phone'></input>");
	newWindow.document.write("<br/><p>How many paintballs do you wish to order?</p>");
	newWindow.document.write("<input type='checkbox' name='140paintballs' value='ON'/> 140 ");
	newWindow.document.write("<input type='checkbox' name='300paintballs' value='ON'/> 300 ");
	newWindow.document.write("<input type='checkbox' name='500paintballs' value='ON'/> 500 ");
	newWindow.document.write("<input type='checkbox' name='800paintballs' value='ON'/> 800 ");
	newWindow.document.write("<input type='checkbox' name='1000paintballs' value='ON'/> 1000 ");
	newWindow.document.write("<input type='checkbox' name='2000paintballs' value='ON'/> 2000 ");
	newWindow.document.write("<br/><br/><input type='submit' value='Confirm Booking' name='confirmBooking'/>");
	newWindow.document.write("</form>");
	newWindow.document.write("<br/><br/><a href='page?page=Terms' target='Terms'>Terms and Conditions</a>");
	newWindow.document.write("</body>");
	newWindow.document.write("</html>");
	newWindow.focus();
}

function rent()
{
	var valueLabel = document.getElementById("propertySelectorValueLabel");
	valueLabel.innerHTML = "Rent £s PCM";
	
	var values = [100,200,300,400,500,600,700,800,900,1000,1250,1500,2000,2500];
	var valueMin = document.getElementById("valueMin");
	for(count = valueMin.options.length; count >= 0; count--){valueMin.remove(count);}
	for(count = 0; count < values.length; count++)
	{
		var option = document.createElement("OPTION");
		option.text = values[count];
		option.value = values[count];
		valueMin.options.add(option);
	}
	
	var valueMax = document.getElementById("valueMax");
	for(count = valueMax.options.length; count >= 0; count--){valueMax.remove(count);}
	
	var option = document.createElement("OPTION");
	option.text = values[values.length-1];
	option.value = values[values.length-1];
	valueMax.options.add(option);
	
	for(count = 0; count < (values.length-1); count++)
	{
		var option = document.createElement("OPTION");
		option.text = values[count];
		option.value = values[count];
		valueMax.options.add(option);
	}
}
function sale()
{
	var valueLabel = document.getElementById("propertySelectorValueLabel");
	valueLabel.innerHTML = "Price £Ks ";
	var values = [10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,175,200,225,250,300,350,400,450,500,600,700,800,900,1000];
	var valueMin = document.getElementById("valueMin");
	for(count = valueMin.options.length; count >= 0; count--){valueMin.remove(count);}
	for(count = 0; count < values.length; count++)
	{
		var option = document.createElement("OPTION");
		option.text = values[count];
		option.value = values[count];
		valueMin.options.add(option);
	}
	
	var valueMax = document.getElementById("valueMax");
	for(count = valueMax.options.length; count >= 0; count--){valueMax.remove(count);}
	var option = document.createElement("OPTION");
	option.text = values[values.length-1];
	option.value = values[values.length-1];
	valueMax.options.add(option);
	for(count = 0; count < (values.length-1); count++)
	{
		var option = document.createElement("OPTION");
		option.text = values[count];
		option.value = values[count];
		valueMax.options.add(option);
	}
}
var slideWindow = null;
function slideShow(siteNumber,type,img1,img2,img3,img4,img5,img6,img7,img8,img9,img10)
{
	var images = new Array();
	images[0] = img1;
	images[1] = img2;
	images[2] = img3;
	images[3] = img4;
	images[4] = img5;
	images[5] = img6;
	images[6] = img7;
	images[7] = img8;
	images[8] = img9;
	images[9] = img10;
	
	imageCount = 0;
	for(count = 0;count < 10; count++)
	{
		if(images[count] != '') imageCount++;
	}
	width = 640;
	height= 480;
	imagePath = "/scripts/" + siteNumber + "/uploads/data/";
	if(type == "rent") imagePath += "rentman/";
	else imagePath += "reapit/";
	imageName = images[0];
	
	link = "";
	if(slideWindow) slideWindow.close();
	slideWindow = window.open(link,"image",'left=150,top=150,width=' + width + ',height=' + (height+20) + ',toolbar=0,resizable=0,border=1,menubar=0');
	slideWindow.document.write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>");
	slideWindow.document.write("<html><head>");

	slideWindow.document.write("<link rel='stylesheet' type='text/css' href='/styles/style1148.css'/>");
	
	slideWindow.document.write("\n<script type='text/javascript'>");
	slideWindow.document.write("\nvar currentImage = 0;");
	slideWindow.document.write("\nvar images = new Array();");
	slideWindow.document.write("\nimages[0] = '" + images[0] + "';");
	slideWindow.document.write("\nimages[1] = '" + images[1] + "';");
	slideWindow.document.write("\nimages[2] = '" + images[2] + "';");
	slideWindow.document.write("\nimages[3] = '" + images[3] + "';");
	slideWindow.document.write("\nimages[4] = '" + images[4] + "';");
	slideWindow.document.write("\nimages[5] = '" + images[5] + "';");
	slideWindow.document.write("\nimages[6] = '" + images[6] + "';");
	slideWindow.document.write("\nimages[7] = '" + images[7] + "';");
	slideWindow.document.write("\nimages[8] = '" + images[8] + "';");
	slideWindow.document.write("\nimages[9] = '" + images[9] + "';");
	
	slideWindow.document.write("\nfunction nextSlide()");
	slideWindow.document.write("\n{");
	slideWindow.document.write("\ncurrentImage++;");
	slideWindow.document.write("\nwhile(images[currentImage] == '' && currentImage != 10){currentImage++;}");
	slideWindow.document.write("\nif(currentImage == 10) currentImage = 0;");
	slideWindow.document.write("\nvar slideShowImage = document.getElementById('slideShowImage').src = '" + imagePath +  "' + images[currentImage];");
	slideWindow.document.write("\n}");
	
	slideWindow.document.write("\nfunction backSlide()");
	slideWindow.document.write("\n{");
	slideWindow.document.write("\ncurrentImage--;");
	slideWindow.document.write("\nwhile(images[currentImage] == '' && currentImage != -1){currentImage--;}");
	slideWindow.document.write("\nif(currentImage == -1) currentImage = 0;");
	slideWindow.document.write("\nvar slideShowImage = document.getElementById('slideShowImage').src = '" + imagePath +  "' + images[currentImage];");
	slideWindow.document.write("\n}");
	
	slideWindow.document.write("\n</script>");
	slideWindow.document.write("<title>Slide Show</title></head>");
	slideWindow.document.write("<body style='padding:0px;margin:0px;width:" + width + ";height:" + (height+20) + ";'>");

	slideWindow.document.write("<div class='slideShowImageDiv'><img id='slideShowImage' src='" + imagePath + imageName + "' /></div>");


	if(imageCount > 1)
	{
		slideWindow.document.write("<div onclick='backSlide()' style='font-family:verdana;color:white;height:20px;width:50%;background:rgb(128,128,128);text-align:center;float:left;'>< back</div>");
		slideWindow.document.write("<div onclick='nextSlide()' style='font-family:verdana;color:white;height:20px;width50%;background:rgb(100,100,100);text-align:center;'>next ></div>");
	}
	else
	{
		slideWindow.document.write("<div style='font-family:verdana;color:white;height:20px;width100%;background:rgb(100,100,100);text-align:center;'>Just one image</div>");
	}
	slideWindow.document.write("</body>");
	slideWindow.document.write("</html>");
	slideWindow.focus();
}


var geocoder;
var map;
function googleMapFromPostCode(address) 
{  
	geocoder = new google.maps.Geocoder(address);      
	var myOptions = 
	{
		zoom: 15,
			scrollwheel: false,
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			streetViewControl: true
		}
	map = new google.maps.Map(document.getElementById("googlemap"), myOptions);
	if (geocoder) {
		geocoder.geocode( { 'address': address}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
					map.setCenter(results[0].geometry.location);
					
					var infowindow = new google.maps.InfoWindow(
						{ content: address,
							size: new google.maps.Size(150,50)
						});
					var image = '/images/generic/mappin.gif';
					var marker = new google.maps.Marker({
						position: results[0].geometry.location,
						map: map, 
							title:address,
							icon:image
						}); 
					google.maps.event.addListener(marker, 'click', function() {
						infowindow.open(map,marker);
					});
					
				} else {
					alert("No results found");
				}
			} else {
				alert("Geocode was not successful for the following reason: " + status);
			}
		});
	}
}

