function showImage(path,type,width,height) {
	//load the path into the display div
	theImage = document.createElement("img");
	theImage.src = path;
	theImage.className = type;
	theImage.width = width;
	theImage.height = height;

	thePhotoArea = xGetElementById('photoarea');
	while(thePhotoArea.hasChildNodes()) {
		thePhotoArea.removeChild(thePhotoArea.firstChild);
	}

	thePhotoArea.appendChild(theImage);
}

function centerMap() {
	//get all div elements
	allDivs = document.getElementsByTagName("div");
	for(i=0;i<allDivs.length;i++) {
		if(allDivs[i].id && allDivs[i].id.match(/gmap/)) {
			allDivs[i].style.display = "block";
			allDivs[i].style.margin = "0 auto";
			allDivs[i].style.border = "1px solid #600";
			break;
		}
	}
	
}

function changeCal(caltype,admin,cottage) {
	//type will be either 'booking' or 'activities'
	if(admin == "1") { thetype = caltype+"admin"; } else { thetype = caltype; }
	
	//get the current month and year values
	monthInput = document.getElementById(thetype+"month");
	yearInput = document.getElementById(thetype+"year");

	monthNameArray = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

	
	if(caltype == "activities" || admin == "1") {
		monthValue = monthInput.value;
		yearValue = yearInput.value;
		//change the month name and year in xGetElementById(type+"MonthName")
		xGetElementById(thetype+"MonthName").innerHTML = monthNameArray[monthValue-1]+" "+yearValue;
	} else {
		monthValue = monthInput.options[monthInput.selectedIndex].value;
		yearValue = yearInput.options[yearInput.selectedIndex].value;
	}

	
	url = "php/calendar.php?month="+monthValue+"&year="+yearValue+"&type="+caltype+"&admin="+admin+"&cottage="+cottage;
	url = preventCache(url);
	//create an ajax call to get the new calendar
	newCalendar = GetXmlHttpObject();
	newCalendar.open("GET",url,true);

	newCalendar.onreadystatechange = function() {
		if(newCalendar.readyState == 4 && newCalendar.status == 200) {
			document.getElementById(thetype+"calendar").innerHTML = newCalendar.responseText;
			
		}
	}
	newCalendar.send(null);

}

function changeCalMonth(which,caltype,admin,cottage) {
	//get the value of the month input
	if(admin == "1") { thetype = caltype+"admin"; } else { thetype = caltype; }
	currentMonth = xGetElementById(thetype+"month").value;

	if(thetype == "bookingadmin") {
		//get the cottage that we are dealing 
		theInputs = document.getElementsByTagName("input");
		for(i=0;i<theInputs.length;i++) {
			if(theInputs[i].getAttribute("type") == "radio") {
				if(theInputs[i].checked == true) {
					cottage = theInputs[i].value;
					break;
				}
			}
		}
	}
	
	switch(currentMonth) {
		case "12":
			if(which == 1) { 
				xGetElementById(thetype+"year").value = eval(xGetElementById(thetype+"year").value)+which;
				xGetElementById(thetype+"month").value = 1;
			} else { xGetElementById(thetype+"month").value = eval(currentMonth)+which; }
			break;
		case "1":
			if(which == -1) {
				xGetElementById(thetype+"year").value = eval(xGetElementById(thetype+"year").value)+which
				xGetElementById(thetype+"month").value = 12;
			} else { xGetElementById(thetype+"month").value = eval(currentMonth)+which; }
			break;
		default:
			xGetElementById(thetype+"month").value = eval(currentMonth)+which;
	}

	//activities specific functions go here
	if(caltype == "activities") {
		if(admin == "1") {
			xGetElementById("eventcalInfo").style.display = "none";
		} else {
			//make an ajax call to re-display the events on the current page in the div with id "listofevents"
			url = "php/events.php?month="+xGetElementById(thetype+"month").value+"&year="+xGetElementById(thetype+"year").value;
			url = preventCache(url);
			newList = GetXmlHttpObject();
			newList.open("GET",url,true);
			newList.onreadystatechange = function() {
				if(newList.readyState == 4 && newList.status == 200) {
					xGetElementById("listofevents").innerHTML = newList.responseText;
				}
			}
			newList.send(null);
		}
	}
	
	changeCal(caltype,admin,cottage);
}

//this function will prevent caching of ajax calls
function preventCache(url) {
	var d = new Date();
	var t = d.getTime();
	url = url+"&t="+t;
	return url;

}
