// JavaScript Document
<!-- cloak 
	function init() {
		document.forms[0].elements[1].focus();
		checkType(document.forms['addEvent'].elements['TYPE']);
		checkPlace(document.forms[0].elements['TOWN']);
	}

	function checkType(theField) {
		var theForm = document.forms['addEvent'];
		var theType = theField.value;

		if(theType==undefined) {
			theField = document.forms['addEvent'].elements['TYPE'];
			for (i=0;i<theField.length;i++){ 
				if (theField[i].checked==true)
					theType = theField[i].value;
			}
		}
		if(theType=="A" || theType=="AP") {
			//theForm.elements['START_MONTH'].disabled = true;
			theForm.elements['START_DAY'].disabled = true;
			theForm.elements['START_YEAR'].disabled = true;
			theForm.elements['ONGOING'].disabled = true;
			theForm.elements['START_TIME_HOUR'].disabled = true;
			theForm.elements['START_TIME_MINUTES'].disabled = true;
			theForm.elements['START_AMPM'].disabled = true;
			theForm.elements['TIME_ZONE'].disabled = true;
			theForm.elements['END_TIME_HOUR'].disabled = true;
			theForm.elements['END_TIME_MINUTES'].disabled = true;
			theForm.elements['END_AMPM'].disabled = true;
			theForm.elements['ONGOING'].checked = false;
			//checkVisibility(theForm.elements['ONGOING'], 'endDate')
			return false;
		}
		if(theType=="E" || theType=="OE") {
			//theForm.elements['START_MONTH'].disabled = false;
			theForm.elements['START_DAY'].disabled = false;
			theForm.elements['START_YEAR'].disabled = false;
			theForm.elements['ONGOING'].disabled = false;
			theForm.elements['START_TIME_HOUR'].disabled = false;
			theForm.elements['START_TIME_MINUTES'].disabled = false;
			theForm.elements['START_AMPM'].disabled = false;
			theForm.elements['TIME_ZONE'].disabled = false;
			theForm.elements['END_TIME_HOUR'].disabled = false;
			theForm.elements['END_TIME_MINUTES'].disabled = false;
			theForm.elements['END_AMPM'].disabled = false;
			if(theType=="OE") {
				theForm.elements['ONGOING'].checked = true;
				//checkVisibility(theForm.elements['ONGOING'], 'endDate')
			}
			else {
				//theForm.elements['ONGOING'].checked = false;
				//checkVisibility(theForm.elements['ONGOING'], 'endDate')
			}
			return false;
		}
	}
	function checkPlace(theField) {
		var theEl = document.getElementById("otherTown");
		if(theField.options[theField.selectedIndex].value=="Other") {
			document.getElementById("townHelp").style.left = '0px';
			theEl.style.visibility = "visible";
			theEl.style.zIndex = "100";
			theEl.focus();
			return false;
		}
		else {
			document.getElementById("townHelp").style.left = '-120px';
			theEl.style.visibility = "hidden";
		}
	}
	function addOtherTown(theField) {
		var theSelect = document.getElementById("townSelect");
		var theInput = document.getElementById("otherTown");
		if(theField.value=="") {
			alert("Please enter a town name.");
			theInput.focus();
		} else {
			document.getElementById('townHelp').style.left = '-120px'; 
			var townListLength = theSelect.length;
			theSelect[townListLength] = new Option("Other:", "Other", false);
			theSelect[(townListLength-1)] = new Option(theInput.value, "Other", true);
			theSelect[(townListLength-1)].selected = true;
			theInput.style.visibility = "hidden";
			document.getElementById("townSelect").style.visibility = "visible";
		}
	}
	function checkAreaCode(theField) {
		var theSelect = document.getElementById("areaCodeSelect");
		var theInput = document.getElementById("areaCodeInput");
		if(theField.options[theField.selectedIndex].value=="Other") {
			theSelect.style.visibility = "hidden";
			theInput.style.visibility = "visible";
			theInput.focus();
		}
		else
			theSelect.visibility = "visible";
	}
	function addAreaCode(theField) {
		var theSelect = document.getElementById("areaCodeSelect");
		var theInput = document.getElementById("areaCodeInput");
		if(theField.value=="") {
			alert("Please enter an area code.");
			theInput.focus();
		} else {
			theSelect[4] = new Option("Other", "Other", false);
			theSelect[3] = new Option("(" + theInput.value + ")", theInput.value, true);
			theSelect[3].selected = true;
			theInput.style.visibility = "hidden";
			document.getElementById("areaCodeSelect").style.visibility = "visible";
		}
	}
	function checkVisibility(theCheckBox, element) {
		var theEl = document.getElementById(element);
		if(theCheckBox.checked==true) {
			theEl.style.visibility = "visible";
			return false;
		}
		else
			theEl.style.visibility = "hidden";
	}
	function addDate() {
		theForm = document.addEvent;
		theForm.addDateFlag.value = true;
		theForm.submit();
	}
	function removeDate(id) {
		theForm = document.addEvent;
		theForm.removeDate.value = id;
		//alert(theForm.removeDate.value);//debug
		theForm.submit();
	}

	function showElement(id) {
		var obj= document.getElementById(id);
		obj.style.visibility = "visible";
	}
	function hideElement(id) {
		var obj= document.getElementById(id);
		obj.style.visibility = "hidden";
	}
	function setOpacity(id,value) {
		var el = document.getElementById(id);
		if(el.style) {
			el.style.opacity = value/10;
			el.style.filter = 'alpha(opacity=' + value*10 + ')';
		}
	}
	function showDatePopup() {
		var id = 'datePopup';
		var el = document.getElementById(id).style;
		var theForm = document.addEvent;
		if(el.visibility=='hidden' || el.visibility=='') {
			checkVisibility(theForm.elements['ONGOING'], 'endDate')
			setOpacity(id,0);
			showElement(id);
			for (var i=0;i<=10;i++) {
				setTimeout('setOpacity(\''+id+'\','+i+')',40*i);
			}
			document.getElementById('START_DATE_Month_ID').focus();
		}
	}
	function showUploadPopup() {
		var id = 'imageUploadPopup';
		var el = document.getElementById(id).style;
		var theForm = document.addEvent;
		if(el.visibility=='hidden' || el.visibility=='') {
			setOpacity(id,0);
			showElement(id);
			for (var i=0;i<=10;i++) {
				setTimeout('setOpacity(\''+id+'\','+i+')',40*i);
			}
		}
	}
	function showPopup(id) {
		var el = document.getElementById(id).style;
		var theForm = document.addEvent;
		if(el.visibility=='hidden' || el.visibility=='') {
			setOpacity(id,0);
			showElement(id);
			for (var i=0;i<=10;i++) {
				setTimeout('setOpacity(\''+id+'\','+i+')',40*i);
			}
		}
	}
	function addImage() {
		theForm = document.addEvent;
		theForm.addImageFlag.value = true;
		theForm.submit();
	}
	function editImagePopup(imageId, field) {
		document.addEvent.editImageId.value = imageId;
		var id = imageId;
		var el = document.getElementById(id).style;
		if(el.visibility=='hidden' || el.visibility=='') {
			setOpacity(id,0);
			showElement(id);
			for (var i=0;i<=10;i++) {
				setTimeout('setOpacity(\''+id+'\','+i+')',30*i);
			}
		}
		field.focus();
	}
	function editImage(imageId, title, credit, caption) {
		document.addEvent.editImageId.value = imageId;
		document.addEvent.editImageTitle.value = title;
		document.addEvent.editImageCredit.value = credit;
		document.addEvent.editImageCaption.value = caption;
		return true;
	}
	function deleteImg(imageId) {
		var agree=confirm("Delete image?");
		if (agree) {
			document.addEvent.deleteImage.value = imageId;
			document.addEvent.submit();
			return true;
		}
		else
			return false;
	} 

// -->

