	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 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 addEvent() {
		document.admin_form.action = "add_event.php";
		document.admin_form.submit();
	}
	
	function cancelAdd() {
		history.back();
	}
	
	function validateAddEventForm() {
		title = document.add_form.title.value;
		
		if (title == "") {
			alert("You must enter an event title.");
			document.add_form.title.focus();
			return false;
		}
		
		return true;
	}
	
	function editEvent(eventId) {
		document.admin_form.action = "edit_event.php";
		document.admin_form.event_id.value = eventId;
		document.admin_form.submit();
	}
		
	function confirmDeleteEvent(eventId, eventTitle) {
		if (confirm("Are you sure want to delete "+eventTitle+"?")) {
			document.admin_form.action = "delete_event.php";
			document.admin_form.event_id.value = eventId;
			document.admin_form.submit();
		}
	}
		
	function addFestival() {
		document.admin_form.action = "add_festival.php";
		document.admin_form.submit();
	}
	
	function validateAddFestivalForm() {
		title = document.add_form.title.value;
		
		if (title == "") {
			alert("You must enter a festival title.");
			document.add_form.title.focus();
			return false;
		}
		
		return true;
	}
	
	function editFestival(festivalId) {
		document.admin_form.action = "edit_festival.php";
		document.admin_form.festival_id.value = festivalId;
		document.admin_form.submit();
	}
		
	function confirmDeleteFestival(festivalId, festivalTitle) {
		if (confirm("Are you sure want to delete "+festivalTitle+"?")) {
			document.admin_form.action = "delete_festival.php";
			document.admin_form.festival_id.value = festivalId;
			document.admin_form.submit();
		}
	}
	
	function addPhoto() {
		document.admin_form.action = "add_photo.php";
		document.admin_form.submit();
	}
	
	function displayImage()  {
		photoField = "document.forms[0].photo_pick.value";
		photoNameTemp = eval(photoField);
		
		// Check file extension
		if (!checkImageFileExtension(photoNameTemp)) {			
			return false;
		}
																
		photoName = "file://"+replaceChars(photoNameTemp);
		photoDisplay = "document.forms[0].photo_pick_display.src = '"+photoName+"'";
		if (photoNameTemp != "") {
			photoDisplay = "document.forms[0].photo_pick_display.src = '"+photoName+"'";			
		} else {
			photoDisplay = "document.forms[0].photo_pick_display.src = '../images/no-image.gif'";
		}
		eval(photoDisplay);
	}
	
	function checkImageFileExtension(filename) {
		if ((filename.lastIndexOf(".jpg")==-1) && (filename.lastIndexOf(".JPG")==-1) && 
			(filename.lastIndexOf(".jpeg")==-1) && (filename.lastIndexOf(".JPEG")==-1) &&
			(filename.lastIndexOf(".gif")==-1) && (filename.lastIndexOf(".GIF")==-1)) {
			alert("You can upload only GIF and JPG files");
			return false;
		}
		return true;
	}	
	
	function showPhoto(id, width, height) {
	  newWindow = window.open('view_photo.php?id='+id, 'newWindow', 'toolbar=no, location=no, scrollbars=no, resizable=no, width='+width+', height='+height+', left=150, top=150');
	}
	
	function editPhoto(photoId) {
		document.admin_form.action = "edit_photo.php";
		document.admin_form.photo_id.value = photoId;
		document.admin_form.submit();
	}
	
	function confirmDeletePhoto(photoId, photoCaption) {
		if (confirm("Are you sure want to delete this photo?")) {
			document.admin_form.action = "delete_photo.php";
			document.admin_form.photo_id.value = photoId;
			document.admin_form.submit();
		}
	}
	
	function encodePassword() {
		password = document.login_form.password.value;
		hash = hex_md5(password);
		document.login_form.password.value = hash;
	}
	
	function validateAddFestivalForm() {
		title = document.add_form.title.value;
		startDate = document.add_form.start_date.value;
		endDate = document.add_form.end_date.value;
		
		if (title == "") {
			alert("You must enter a festival title.");
			document.add_form.title.focus();
			return false;
		}
		
		if (startDate == "" || startDate == "00-00-0000") {
			alert("You must enter a start date.");
			document.add_form.start_date.focus();
			return false;
		}
		
		if (endDate == "" || endDate == "00-00-0000") {
			alert("You must enter an end date.");
			document.add_form.end_date.focus();
			return false;
		}
		
		return true;
	}
	
	function validateEditFestivalForm() {
		title = document.edit_form.title.value;
		startDate = document.edit_form.start_date.value;
		endDate = document.edit_form.end_date.value;
		
		if (title == "") {
			alert("You must enter a festival title.");
			document.edit_form.title.focus();
			return false;
		}
		
		if (startDate == "" || startDate == "00-00-0000") {
			alert("You must enter a start date.");
			document.add_form.start_date.focus();
			return false;
		}
		
		if (endDate == "" || endDate == "00-00-0000") {
			alert("You must enter an end date.");
			document.add_form.end_date.focus();
			return false;
		}
		
		return true;
	}
	
	function validateContactForm() {
		fullName = document.contact_form.full_name.value;
		address = document.contact_form.address.value;
		phone = document.contact_form.phone.value;
		emailAddress = document.contact_form.email.value;
		query = document.contact_form.query.value;
		
		if (fullName == "") {
			alert("You must enter your full name.");
			document.contact_form.full_name.focus();
			return false;
		}
		if (address == "") {
			alert("You must enter your location.");
			document.contact_form.address.focus();
			return false;
		}
		if (phone == "" && emailAddress == "") {
			alert("Please provide either your phone number or your email address.");
			document.contact_form.phone.focus();
			return false;
		}
		if (phone != "" && !isNumeric(phone)) {
			alert("Your phone number can only contain numeric characters");
			document.contact_form.phone.focus();
			return false;
		}
		if (emailAddress != "") {
			// E-mail Validation by Henrik Petersen / NetKontoret
			// Explained at www.echoecho.com/jsforms.htm
			// Please do not remove this line and the two lines above.
			apos=emailAddress.indexOf("@"); 
			dotpos=emailAddress.lastIndexOf(".");
			lastpos=emailAddress.length-1;
			if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) {
				alert("You must enter a valid email address");
					document.contact_form.email.focus();
				return false;
			}
		}
		
		if (query == "") {
			alert("Please provide some details relating to your query.");
			document.contact_form.query.focus();
			return false;
		}
		
		return true;
	}
	
	function isNumeric(strString) {
		var strValidChars = "0123456789";
		var strChar;
		var blnResult = true;

		if (strString.length == 0) return false;
		//  test strString consists of valid characters listed above
		for (i = 0; i < strString.length && blnResult == true; i++) {
			strChar = strString.charAt(i);
			if (strValidChars.indexOf(strChar) == -1) {
				blnResult = false;
			}
		}
		return blnResult;
	}
	
	function replaceChars(entry) {
		out = "\\"; // replace this
		add = "/"; // with this
		temp = "" + entry; // temporary holder

		while (temp.indexOf(out)>-1) {
			pos= temp.indexOf(out);
			temp = "" + (temp.substring(0, pos) + add + 
			temp.substring((pos + out.length), temp.length));
		}
		return temp;
	}