	/* section added for announcements links that open a popup window */
	var win=null;

	function hideEditor() {
		try {
			if (document.getElementById('aiEditor')) {
				if (document.getElementById('hideeditor').innerText == 'hide editor') {
					document.getElementById('aiEditor').save();
					document.getElementById('bodyContent').value = aiEditor.rawHTML;
					document.getElementById('aiEditor').style.display = 'none';
					document.getElementById('bodyContent').style.display = 'inline';
					document.getElementById('hideeditor').innerText = "show editor";
				}
				else {
					document.getElementById('aiEditor').content = document.getElementById('bodyContent').value;
					document.getElementById('aiEditor').style.display = 'inline';
					document.getElementById('bodyContent').style.display = 'none';
					document.getElementById('hideeditor').innerText = "hide editor";
				}
			}
		}
		catch (e) {
			alert("Error: " + e.message);
		}

		return false;
	}

	function confirmDelete(msg) {
		return confirm("Are you sure you want to delete the record:\n\n" + msg);
	}

	function showLink(a) {
		try {
			document.getElementById('detailLinkText').innerText = a.href;
			document.getElementById('detailLinkDiv').style.display = 'inline';
		}
		catch (e) {}

		return false;
	}

	function validate(form) {
		try {
			try {
				if (document.getElementById('aiEditor') && aiEditor) {
					if (document.getElementById('aiEditor').style.display != "none") {
						aiEditor.save();
						document.getElementById('bodyContent').value = aiEditor.rawHTML;
					}
				}
			}
			catch (e) {}

			if (form.title.value == '') {
				alert("You must enter a title.");
				form.title.focus();
				return false;
			}
			else if (form.synopsis.value == ''  &&
				 document.getElementById('bodyContent').value == '') {
				alert("You must enter a synopsis or body content.");
				form.synopsis.focus();
				return false;
			}
			else if (form.sunrise_date.value == '') {
				alert("You must enter a sunrise date in the form mm/dd/yyyy.");
				form.sunrise_date.focus();
				return false;
			}

			if (form.sunrise_date.value != '') {
				if (!isDate(form.sunrise_date.value)) {
					form.sunrise_date.focus();
					return false;
				}
			}

			if (form.sunset_date.value != '') {
				if (!isDate(form.sunset_date.value)) {
					form.sunset_date.focus();
					return false;
				}
			}
		}
		catch (e) {
			alert("Validation Error: " + e.message);
		}
	}
	//********************** Date Functions ****************************
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;

	function daysInFebruary (year){
		// February has 29 days in any year evenly divisible by four,
	    // EXCEPT for centurial years which are not also divisible by 400.
	    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}
	function DaysArray(n) {
		for (var i = 1; i <= n; i++) {
			this[i] = 31
			if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
			if (i==2) {this[i] = 29}
	   }
	   return this
	}

	function stripCharsInBag(s, bag){
		var i;
	    var returnString = "";
	    // Search through string's characters one by one.
	    // If character is not in bag, append to returnString.
	    for (i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	    }
	    return returnString;
	}

	function isInteger(s){
		var i;
	    for (i = 0; i < s.length; i++){
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	    }
	    // All characters are numbers.
	    return true;
	}

	function isDate(dtStr){
		var daysInMonth = DaysArray(12)
		var pos1=dtStr.indexOf(dtCh)
		var pos2=dtStr.indexOf(dtCh,pos1+1)
		var strMonth=dtStr.substring(0,pos1)
		var strDay=dtStr.substring(pos1+1,pos2)
		var strYear=dtStr.substring(pos2+1)
		strYr=strYear
		if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
		for (var i = 1; i <= 3; i++) {
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
		}
		month=parseInt(strMonth)
		day=parseInt(strDay)
		year=parseInt(strYr)
		if (pos1==-1 || pos2==-1){
			alert("The date format should be : mm/dd/yyyy")
			return false
		}
		if (strMonth.length<1 || month<1 || month>12){
			alert("Please enter a valid month")
			return false
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
			alert("Please enter a valid day")
			return false
		}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
			alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
			return false
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
			alert("Please enter a valid date")
			return false
		}

		return true
	}
	//********************** End Date Functions ****************************

	function initEditor() {
		try {
			if (aiEditor) aiEditor.content = document.getElementById('bodyContent').value;
	    }
	    catch(e) {
	        try {
		        document.getElementById('bodyContent').style.display = 'inline';
		    }
		    catch (e) {}
	    }
	}

	function smallWindow(url) {
		var win_params='status=no,location=no,toolbar=no,menubar=no,resizable=no,scrollbars=yes,directories=no,height=275,width=380, top=300,left=200';
		win = window.open(url, 'popupWindow', win_params);

		return false;
	}

	function smallModalWindow(url) {
		var win_params='status=no,location=no,toolbar=no,menubar=no,resizable=no,scrollbars=yes,directories=no,height=275,width=380, top=300,left=200';
		return showModalDialog( url, "", win_params);
	}

	function largeWindow(url) {
		var win_params='status=no,toolbar=yes,menubar=no,scrollbars=yes,directories=no,height=500,width=850, top=100,left=100';
		win = window.open(url, 'popupWindow', win_params);

		return false;
	}

	function newXMLHttpRequest() {
		var xmlreq = false;

		if (window.XMLHttpRequest) {
		    // Create XMLHttpRequest object in non-Microsoft browsers
		    xmlreq = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
		    // Create XMLHttpRequest via MS ActiveX
		    try {
		      // Try to create XMLHttpRequest in later versions
		      // of Internet Explorer
		      xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
		    } catch (e1) {
		      // Failed to create required ActiveXObject
		      try {
			// Try version supported by older versions of Internet Explorer
			xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
		      } catch (e2) {
			// Unable to create an XMLHttpRequest with ActiveX
		      }
		    }
		}

		return xmlreq;
	}

	/*
	 * Returns a function that waits for the specified XMLHttpRequest to complete,
	 * then passes its XML response to the given handler function for AJAX support.
	 * req - The XMLHttpRequest whose state is changing.
	 * responseXmlHandler - Function to pass the XML response to.
	 */
	function getReadyStateHandler(req, responseXmlHandler) {
		// Return an anonymous function that listens to the XMLHttpRequest instance
		return function () {
		    // If the request's status is "complete"
		    if (req.readyState == 4) {
		      // Check that a successful server response was received
			if (req.status == 200) {
			    // Pass the XML payload of the response to the handler function
			    responseXmlHandler(req.responseXML);
			}
			else {
			    // An HTTP problem has occurred
	        	    alert("HTTP error: "+req.status+", headers: "+req.getAllResponseHeaders());
		    }
		    }
		}
	}
