//================================================================================
// AJAX Server-side validation
// Biola Web Services
// Based on "Degradable AJAX Form Validation" by Chris Campbell
// http://particletree.com/features/smart-validation-with-ajax
//================================================================================

var http = getHTTPObject();
var validate_url = "validate_ajax.cfm"

function getHTTPObject() {
	var xmlhttp;
	/*@cc_on
	  @if (@_jscript_version >= 5)
	    try {
	      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	    } catch (e) {
	      try {
	        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	      } catch (E) {
	        xmlhttp = false;
	      }
	    }
	  @else
	  xmlhttp = false;
	  @end @*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}
	return xmlhttp;
}

function handleHTTPResponse() {
	if (http.readyState == 4) {
		sResults = http.responseText.split(";");
		
			var error_box = document.getElementById(sResults[1] + "-val");
			var label = getLabelForId(sResults[1]);
			var element = document.getElementById(sResults[1]);
		
			if (sResults[2] == "yes") {
				label.className = "completed";
				error_box.innerHTML = "good";
			} else if (sResults[2] == "corrected") {
				label.className = "completed";
				error_box.innerHTML = sResults[3];
				element.value = sResults[4];
			} else if (sResults[2] == "no") {
				label.className = "problem";
				error_box.innerHTML = sResults[3];
			}
		
			error_box.innerHTML = sResults[3];
	}
}

function handleSessionResponse() {
	if (http.readyState == 4) {
		sResults = http.responseText.split(";");
		
		box = document.getElementById(sResults[1] + "-val");
		box.innerHTML = sResults[2];
	}
}

function handleTextResponse() {
	if (http.readyState == 4) {
		sResults = http.responseText.split(";");
		
		box = document.getElementById('confirm_' + sResults[1]);
		box.innerHTML = sResults[2];
	}
}

function validateMe(element) {
	http.open("GET", validate_url + "?elementname=" + escape(element.id) + "&value=" + escape(element.value), true);
	
	http.onreadystatechange = handleHTTPResponse
	http.send(null);
}

function validateSession(index) {
	element = document.getElementById("sessiondates" + getPostForIndex(index));
	
	http.open("GET", "validate_sessions.cfm" + "?elementname=" + escape(element.id) + "&session=" + escape(element.value), true);
	
	http.onreadystatechange = handleSessionResponse
	http.send(null);
}

function validateElement(elementname, elementvalue) {
	http.open("GET", validate_url + "?elementname=" + escape(elementname) + "&value=" + escape(elementvalue), true);
	
	http.onreadystatechange = handleHTTPResponse
	http.send(null);
}

function validateText(name, txt) {
	http.open("GET", "validate_text.cfm" + "?elementname=" + escape(name) + "&text=" + escape(txt), true);
	
	http.onreadystatechange = handleTextResponse
	http.send(null);
}

function getLabelForId(id) {
	var label, labels = document.getElementsByTagName('label');
	for (var i = 0; (label = labels[i]); i++) {
		if (label.htmlFor == id) {
			return label;
		}
	}
	return false;
}








//================================================================================
// SESSION DATE PICKER
//   Allows a user to visually choose which dates their event is occurring on,
//   with more flexibility than weekly and daily controls.
//   David Baxter, Biola University
//   August/September 2005
//================================================================================

function buildcal(element) {
	var el = element.name.split("-");
	(el.length > 1) ? (i = el[1]) : (i = 1);

	if ((document.getElementById("startdate_month" + getPostForIndex(i)).value != "") & (document.getElementById("startdate_day" + getPostForIndex(i)).value != "") & (document.getElementById("startdate_year" + getPostForIndex(i)).value != "") & (document.getElementById("enddate_month" + getPostForIndex(i)).value != "") & (document.getElementById("enddate_day" + getPostForIndex(i)).value != "") & (document.getElementById("enddate_year" + getPostForIndex(i)).value != "")) {
		buildCalendar(document.getElementById("startdate_month" + getPostForIndex(i)).value + "/" + document.getElementById("startdate_day" + getPostForIndex(i)).value + "/" + document.getElementById("startdate_year" + getPostForIndex(i)).value, document.getElementById("enddate_month" + getPostForIndex(i)).value + "/" + document.getElementById("enddate_day" + getPostForIndex(i)).value + "/" + document.getElementById("enddate_year" + getPostForIndex(i)).value, i);
	}
}

	// Sets up a place for calendar data to go until we're ready to send it to the browser
	var calcache = "";

/**
 * buildCalendar(startDateString, endDateString, index)
 *   Creates an HTML calendar for the range of dates from startDateString through endDateString, placing the result
 *   into the appropriate "sessioncal" div (based upon the index).
 */
	function buildCalendar(startDateString, endDateString, index) {
		var startDate = new Date(startDateString);
		var endDate = new Date(endDateString);
		var datesToOutput = datediff(startDate, endDate);
		
		cleanList(startDate, endDate, index);  // Removes dates outside of our bounds
	
		var datesDone = 0; // Number of dates done so far
		var currDate = startDate;
		var currDay = 0; // Day of the week we're on right now
		
		ptc_begincal(index);
	
		// Print blank elements for empty days at beginning of the week
		while (currDay < startDate.getDay()) {
			ptc_blankday(index);
			currDay++;
		}

		while (datesDone <= datesToOutput) {
			// Add dates to our list if they're not already in there
			if (!isInList(currDate, index) && edit_sync == "no") {
				addDateToList(currDate, index, true);
			} else if (!isInList(currDate, index) && edit_sync == "yes") {
				addDateToList(currDate, index, false);
			}
			
			// Print out the day
			ptc_day(index, currDate);

			// Increment everything for next iteration
			datesDone++;
			currDate.setDate(currDate.getDate() + 1);
			(currDay == 6 ? currDay = 0 : currDay++)
			if (currDay == 0) {
				ptc_newweek(index);
			}

		}

		// Print blank elements for empty days at end of the week
		while (currDay <= 6) {
			ptc_blankday(index);
			currDay++;
		}
	
		ptc_endcal(index);

		// Output the created calendar to the browser
		document.getElementById('sessioncal' + getPostForIndex(index)).innerHTML = calcache;
		calcache = "";	
		
		//Make the new element visible
		document.getElementById('sessioncal' + getPostForIndex(index)).style.visibility = "visible";
	}


/**
 * HTML FUNCTIONS
 *   These functions consolidate the HTML that the javascript has to output. All HTML should be here!
 */
	function ptc(index, content) { 
		calcache += content;	
	}
	function ptc_begincal(i) {
		//ptc(i, "<span class='sc-day-head sun'>Sun</span><span class='sc-day-head mon'>Mon</span><span class='sc-day-head tue'>Tue</span><span class='sc-day-head wed'>Wed</span><span class='sc-day-head thu'>Thu</span><span class='sc-day-head fri'>Fri</span><span class='sc-day-head sat'>Sat</span> &nbsp;  <div class='sc-week'>");
		ptc(i, "<div class='head'><div>Sun</div><div>Mon</div><div>Tue</div><div>Wed</div><div>Thu</div><div>Fri</div><div>Sat</div></div><div class='body'><div class='week'>");
	}
	function ptc_endcal(i) {
		ptc(i, "</div></div><div class='foot' id='sessiondates" + getPostForIndex(i) + "-val'>&nbsp;</div>");
	}
	function ptc_newweek(i) {
		ptc(i, "</div><div class='week'>");
	}
	function ptc_day(i, date) {
		ptc(i, "<span id='" + jsDateToISO(date) + getPostForIndex(i) + "' class='day'>" + putDay(date, i) + "</span>");
	}
	function ptc_blankday(i) {
		ptc(i, "<span class='day'>&nbsp;</span>");
	}
	function putDay(day, listindex) {
		if (isActiveInList(day, listindex)) {
			return "<a href='#' class='active' onclick=\"deactivateDay('" + jsDateToISO(day) + "'," + listindex + ");validateSession("+listindex+");return false;\"><span class='m'>" + jsMonthToHuman(day.getMonth()) + "</span><span class='d'>" + day.getDate() + "</span></a>";
		} else {
			return "<a href='#' onclick=\"activateDay('" + jsDateToISO(day) + "'," + listindex + ");validateSession("+listindex+");return false;\"><span class='m'>" + jsMonthToHuman(day.getMonth()) + "</span><span class='d'>" + day.getDate() + "</span></a>";
		}
	}


/**
 * LOOKUP/CONVERSION FUNCTIONS
 *   These functions change Javascript's wacky datatypes around to compensate for lame built-in date functions
 */
function jsMonthToHuman(month) {
	months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
	return months[month];
}

function getPostForIndex(index) {
	ret = ( (index > 1) ? ("-" + index) : ("") );	
	return ret;
}

function datediff(date1, date2) {
	var diffMs = date2.valueOf() - date1.valueOf();
	return parseInt(diffMs/1000/60/60/24);
}

function jsDateToISO(date) {
	ret = ((date.getFullYear()) + "-" + ((date.getMonth() < 9) ? ("0" + (date.getMonth() + 1)) : (date.getMonth() + 1) ) + "-" + ((date.getDate() < 10) ? ("0" + date.getDate()) : date.getDate()));
	return ret;
}

function isoDateToJs(date) {
	iso = date.split("-");
	newdate = new Date(iso[1] + "/" + iso[2] + "/" + iso[0]);
	return newdate;
}


/**
 * LOOKUP/CONVERSION FUNCTIONS
 *   These functions change Javascript's wacky datatypes around to compensate for lame built-in date functions
 */
function activateDay(isodate, listindex) {
	removeISODateFromList(isodate, listindex);
	newdate = isoDateToJs(isodate);
	addDateToList(newdate, listindex, true);
	document.getElementById(isodate + getPostForIndex(listindex)).innerHTML = putDay(newdate, listindex);
}

function deactivateDay(isodate, listindex) {
	removeISODateFromList(isodate, listindex);
	newdate = isoDateToJs(isodate);
	addDateToList(newdate, listindex, false);
	document.getElementById(isodate + getPostForIndex(listindex)).innerHTML = putDay(newdate, listindex);
}

function removeISODateFromList(isodate, listindex) {
	list = getListForIndex(listindex);
	var rereg1 = new RegExp(isodate + "~,", "gi");
	var rereg2 = new RegExp(isodate + ",", "gi");
	var rereg3 = new RegExp(isodate + "~", "gi");
	var rereg4 = new RegExp(isodate, "gi");
	list = list.replace(rereg1, "");
	list = list.replace(rereg2, "");
	list = list.replace(rereg3, "");
	list = list.replace(rereg4, "");
	putListForIndex(listindex, list);
}

function getListForIndex(index) {
	return document.getElementById('sessiondates' + getPostForIndex(index)).value;
}

function putListForIndex(index, value) {
	document.getElementById('sessiondates' + getPostForIndex(index)).value = value;
}

function isInList(date, listindex) {
	list = getListForIndex(listindex);
	if (list.indexOf(jsDateToISO(date)) >= 0) {
		return true;
	} else {
		return false;
	}
}

function isActiveInList(date, listindex) {
	list = getListForIndex(listindex);
	if (list.charAt(list.indexOf(jsDateToISO(date)) + 10) != "~") {
		return true;
	} else {
		return false;
	}
}

function addDateToList(date, listindex, active) {
	list = getListForIndex(listindex);
	var datesarray = list.split(",");
	datesarray.clean_empty();
	datesarray = datesarray.concat(jsDateToISO(date) + (active ? "" : "~"));
	datesarray.sort();
	putListForIndex(listindex, datesarray.join(","));
}

function cleanList(startDate, endDate, listindex) {
	list = getListForIndex(listindex);
	var removetilde = new RegExp("~", "gi");
	list = list.replace(removetilde, "");
	var datesarray = list.split(",");
	var range = datediff(startDate, endDate);
	
	for (var i=0; i < datesarray.length; i++) {
		diff = datediff(startDate, isoDateToJs(datesarray[i]));
		if( (diff < 0) | (diff > range) ) {
			removeISODateFromList(datesarray[i], listindex);
		}
	}
	cleanCommas(listindex);
}

function cleanCommas(listindex) {
	list = getListForIndex(listindex);
	var datesarray = list.split(",");
	datesarray.clean_empty();
	datesarray.sort();
	putListForIndex(listindex, datesarray.join(","));
}

Array.prototype.clean_empty = function() {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] == "") {
			this.splice(i, 1);
			i--;
		}
	}
	return this;
};











// Aggregate & validate checkboxes
function confirm_sites() {
	var siteslist = "";
	for( i=0 ; i<document.eventform.elements.length ; i++) {
		if ((document.eventform.elements[i].name=='sites') && (document.eventform.elements[i].checked==1)) {
			siteslist += document.eventform.elements[i].value + ",";
		}
	}
	var sitesarray = siteslist.split(",");
	sitesarray.clean_empty();
	sitesarray.sort();
	sites = sitesarray.join(",");
	validateElement("sites", sites);
}

function confirm_cats() {
	var catslist = "";
	for( i=0 ; i<document.eventform.elements.length ; i++) {
		if ((document.eventform.elements[i].name=='categories') && (document.eventform.elements[i].checked==1)) {
			catslist += document.eventform.elements[i].value + ",";
		}
	}
	var catsarray = catslist.split(",");
	catsarray.clean_empty();
	catsarray.sort();
	cats = catsarray.join(",");
	validateElement("categories", cats);
}


// Check date dropdowns for valid entries
function confirm_date(item) {
	idsplit = item.id.split("_");
	base = idsplit[0];
	post = idsplit[1].split("-");
	if (post[1]) {
		postfix = getPostForIndex(post[1]);
	} else {
		postfix = "";
	}
	
	if ((document.getElementById(base + "_month" + postfix).value.length > 0) && (document.getElementById(base + "_day" + postfix).value.length > 0) && (document.getElementById(base + "_year" + postfix).value.length > 0)) {
		//Check for not only filled in, but valid
		dteDate = new Date(document.getElementById(base + "_year" + postfix).value, (document.getElementById(base + "_month" + postfix).value) - 1, document.getElementById(base + "_day" + postfix).value);
		if ((document.getElementById(base + "_day" + postfix).value==dteDate.getDate()) && (((document.getElementById(base + "_month" + postfix).value) - 1)==dteDate.getMonth()) && (document.getElementById(base + "_year" + postfix).value==dteDate.getFullYear())) {
			getLabelForId(base+postfix).className = 'completed';
		} else {
			getLabelForId(base+postfix).className = 'problem';
		}
	} else {
		getLabelForId(base+postfix).className = 'problem';
	}
}

function confirm_later_date(item) {
	idsplit = item.id.split("_");
	base = idsplit[0];
	post = idsplit[1].split("-");
	if (post[1]) {
		postfix = getPostForIndex(post[1]);
	} else {
		postfix = "";
	}
	
	if (compare_dates(document.getElementById("enddate_year" + postfix).value, document.getElementById("enddate_month" + postfix).value, document.getElementById("enddate_day" + postfix).value, document.getElementById("startdate_year" + postfix).value, document.getElementById("startdate_month" + postfix).value, document.getElementById("startdate_day" + postfix).value)  == -1) {
		getLabelForId(base+postfix).className = 'problem';
	}
}

function confirm_valid_date(year, month, day) {
	var dteDate;
	dteDate=new Date(year,month,day);

	return ((day==dteDate.getDate()) && (month==dteDate.getMonth()) && (year==dteDate.getFullYear()));
}

function compare_dates(year1, month1, date1, year2, month2, date2) {
	if (parseInt(year1) > parseInt(year2)) return 1;
	else if (parseInt(year1) < parseInt(year2)) return -1;
	else if (parseInt(month1) > parseInt(month2)) return 1;
	else if (parseInt(month1) < parseInt(month2)) return -1;
	else if (parseInt(date1) > parseInt(date2)) return 1;
	else if (parseInt(date1) < parseInt(date2)) return -1;
	else return 0;
}


// Check time dropdowns for valid entries
function confirm_time(item, req) {
	idsplit = item.id.split("_");
	base = idsplit[0];
	post = idsplit[1].split("-");
	if (post[1]) {
		postfix = getPostForIndex(post[1]);
	} else {
		postfix = "";
	}
	
	if (((document.getElementById(base + "_hour" + postfix).value.length == 0) && (document.getElementById(base + "_minute" + postfix).value.length == 0) && (req == 'no'))  |  ((document.getElementById(base + "_hour" + postfix).value.length > 0) && (document.getElementById(base + "_minute" + postfix).value.length > 0))) {
		getLabelForId(base+postfix).className = 'completed';
	} else {
		getLabelForId(base+postfix).className = 'problem';
	}
}


// Check if things are kosher before allowing the form to submit through to the confirmation screen
function check_fields() {
	for( i=0 ; i<document.eventform.elements.length ; i++) {
		var label = getLabelForId(document.eventform.elements[i].id);
		if ((label.className == 'required') | (label.className == 'problem')) {
			return false;
		}
	}
	return true;
}

function check_cats() {
	label = getLabelForId('categories');
	if ((label.className == 'required') | (label.className == 'problem')) {
		return false;
	} else {
		return true;
	}
}

function check_sites() {
	label = getLabelForId('sites');
	if ((label.className == 'required') | (label.className == 'problem')) {
		return false;
	} else {
		return true;
	}
}

function check_dates() {
	if (document.eventform.elements['dates_type'].value == "session") {
		//Change the class of individual dates so the form will submit through
		for( i=0 ; i<document.eventform.elements['individual-RC'].value ; i++) {
			getLabelForId('date' + getPostForIndex(i)).className = "ok";
		}
	} else {
		//Change the class of session dates so the form will submit through
		for( i=0 ; i<document.eventform.elements['sessionpicker-RC'].value ; i++) {
			getLabelForId('startdate' + getPostForIndex(i)).className = "ok";
			getLabelForId('enddate' + getPostForIndex(i)).className = "ok";
			getLabelForId('starttime' + getPostForIndex(i)).className = "ok";
			getLabelForId('endtime' + getPostForIndex(i)).className = "ok";
		}
	}
}

function check_all_dates() {
	if (document.eventform.elements['dates_type'].value == "individual") {
		for( i=0 ; i<document.eventform.elements['individual-RC'].value ; i++) {
			label = getLabelForId('date' + getPostForIndex(i));
			if ((label.className == 'required') | (label.className == 'problem')) {
				return false;
			}
		}
	} else {
		for( i=0 ; i<document.eventform.elements['sessionpicker-RC'].value ; i++) {
			label = getLabelForId('startdate' + getPostForIndex(i));
			if ((label.className == 'required') | (label.className == 'problem')) {
				return false;
			}
			label = getLabelForId('enddate' + getPostForIndex(i));
			if ((label.className == 'required') | (label.className == 'problem')) {
				return false;
			}
		}
	}
	return true;
}

function check_all_times() {
	if (document.eventform.elements['dates_type'].value == "individual") {
		for( i=0 ; i<document.eventform.elements['individual-RC'].value ; i++) {
			label = getLabelForId('istarttime' + getPostForIndex(i));
			if ((label.className == 'required') | (label.className == 'problem')) {
				return false;
			}
			label = getLabelForId('iendtime' + getPostForIndex(i));
			if ((label.className == 'required') | (label.className == 'problem')) {
				return false;
			}
		}
	} else {
		for( i=0 ; i<document.eventform.elements['sessionpicker-RC'].value ; i++) {
			label = getLabelForId('starttime' + getPostForIndex(i));
			if ((label.className == 'required') | (label.className == 'problem')) {
				return false;
			}
			label = getLabelForId('endtime' + getPostForIndex(i));
			if ((label.className == 'required') | (label.className == 'problem')) {
				return false;
			}
		}
	}
	return true;
}


// Show the confirmation screen (onsubmit = "showconfirm();")
function showconfirm() {
		check_dates();
		if (!check_fields() | !check_cats() | !check_sites() | !check_all_dates() | !check_all_times()) {
			alert("You must fill in all required fields.");
		} else {
			populate_confirm();
			document.getElementById('confirm_pop').style.visibility = 'visible';
			document.getElementById('eventform').style.visibility = 'hidden';
			scroll(0,0);
		}
		return false;
	}
	
	function hideconfirm() {
		document.getElementById('confirm_pop').style.visibility = 'hidden';
		document.getElementById('eventform').style.visibility = 'visible';
		scroll(0,0);
	}
	
	function populate_confirm() {		
		document.getElementById('confirm_title').innerHTML = document.eventform.title.value;
		document.getElementById('confirm_subtitle').innerHTML = document.eventform.subtitle.value;
		document.getElementById('confirm_short_desc').innerHTML = document.eventform.short_description.value;
		document.getElementById('confirm_description').innerHTML = document.eventform.full_description.value;
			validateText("description", document.eventform.full_description.value);
		document.getElementById('confirm_cost').innerHTML = document.eventform.admission_info.value;
			setTimeout('validateText("cost", document.eventform.admission_info.value)',1000);
		document.getElementById('confirm_contactname').innerHTML = document.eventform.contact_name.value;
		document.getElementById('confirm_contactemail').innerHTML = document.eventform.contact_email.value;
		document.getElementById('confirm_contactphone').innerHTML = document.eventform.contact_phone.value;
		document.getElementById('confirm_location').innerHTML = document.eventform.location.value;
		document.getElementById('confirm_maplink').innerHTML = document.eventform.location_map.value;
		document.getElementById('confirm_sponsor').innerHTML = document.eventform.event_sponsor.value;
		document.getElementById('confirm_sponsor_url').innerHTML = document.eventform.sponsor_url.value;
		document.getElementById('confirm_reginfo').innerHTML = document.eventform.registration_info.value;
			setTimeout('validateText("reginfo", document.eventform.registration_info.value)',2000);
		if(document.eventform.department_image_small) {
			document.getElementById('confirm_img').innerHTML = "<img src='" + document.eventform.department_image_small.value + "'>";
		}
		document.getElementById('confirm_dept').innerHTML = document.eventform.department.options[document.eventform.department.selectedIndex].text;
		
		//Category Checkboxes
		var checkedboxes = "<ul>";
		for( i=0 ; i<document.eventform.elements.length ; i++) {
			if ((document.eventform.elements[i].name=='categories') && (document.eventform.elements[i].checked==1)) {
				label = getLabelForId('category' + document.eventform.elements[i].value);
				checkedboxes += "<li>" + label.innerHTML + "</li>";
			}
		checkedboxes += "</ul>";
		document.getElementById('confirm_categories').innerHTML = checkedboxes;
		}
		
		//Site Checkboxes
		var checkedboxes = "<ul>";
		for( i=0 ; i<document.eventform.elements.length ; i++) {
			if ((document.eventform.elements[i].name=='sites') && (document.eventform.elements[i].checked==1)) {
				label = getLabelForId('site' + document.eventform.elements[i].value);
				checkedboxes += "<li>" + label.innerHTML + "</li>";
			}
		}
		checkedboxes += "</ul>";
		document.getElementById('confirm_sites').innerHTML = checkedboxes;
		
		//Populate Dates
		var confirmdates = "<ul>";
		//for (i = 1; i <= dateCount; i++) {
		switch (document.getElementById('dates_type').value) {
			case "individual":
				for (i = 1; i <= document.getElementById('individual-RC').value; i++) {
					if (document.getElementById('date_month' + getPostForIndex(i))) {
						confirmdates += "<li>";
						selected_month = document.eventform.elements['date_month' + getPostForIndex(i)].selectedIndex;
						confirmdates += document.eventform.elements['date_month' + getPostForIndex(i)].options[selected_month].text + " ";
						confirmdates += document.eventform.elements['date_day' + getPostForIndex(i)].value + ", ";
						confirmdates += document.eventform.elements['date_year' + getPostForIndex(i)].value;
						if (document.eventform.elements['istarttime_hour' + getPostForIndex(i)].value != "") {
							confirmdates += "<br>" + time_to_humantime(document.eventform.elements['istarttime_hour' + getPostForIndex(i)].value, document.eventform.elements['istarttime_minute' + getPostForIndex(i)].value);
							if (document.eventform.elements['iendtime_hour' + getPostForIndex(i)].value != "") {
								confirmdates += " - " + time_to_humantime(document.eventform.elements['iendtime_hour' + getPostForIndex(i)].value, document.eventform.elements['iendtime_minute' + getPostForIndex(i)].value);
							}
						}
						confirmdates += "</li>";
					}
				}
				break;
			case "session":
				for (i = 1; i <= document.getElementById('sessionpicker-RC').value; i++) {
					if (document.getElementById('sessiondates' + getPostForIndex(i) + "-val")) {
						confirmdates += "<li>";
						confirmdates += document.getElementById('sessiondates' + getPostForIndex(i) + "-val").innerHTML;
						if (document.eventform.elements['starttime_hour' + getPostForIndex(i)].value != "") {
							confirmdates += "<br>" + time_to_humantime(document.eventform.elements['starttime_hour' + getPostForIndex(i)].value, document.eventform.elements['starttime_minute' + getPostForIndex(i)].value);
							if (document.eventform.elements['endtime_hour' + getPostForIndex(i)].value != "") {
								confirmdates += " - " + time_to_humantime(document.eventform.elements['endtime_hour' + getPostForIndex(i)].value, document.eventform.elements['endtime_minute' + getPostForIndex(i)].value);
							}
						}
						confirmdates += "</li>";
					}
				}
				break;
		}
			
		//}
		
		confirmdates += "</ul>";
		
		document.getElementById('confirm_dates').innerHTML = confirmdates;
		
	}
	
	function time_to_humantime(hour, minute) {
		out = (hour > 12) ? (hour-12) : hour;
		out += ":" + minute;
		if (minute == 0) { out += "0"; }
		out += (hour >= 12) ? " pm" : " am";
		
		return out;
	}
	
	
	
	
	
	
	
	function login_pop() {
		window.open('login.cfm', '', 'toolbar=no,scrollbars=yes,width=650,height=600,top=100,left=100');
	}

	//function upload_pop() {
		//window.open('http://calendardev.biola.edu/upload/upload_form.cfm', '', 'toolbar=no,scrollbars=yes,width=650,height=200,top=100,left=100');
	//}
	
	function format_pop() {
		window.open('http://calendar.biola.edu/text_format_guide.cfm', '', 'toolbar=no,scrollbars=yes,width=500,height=300,top=100,left=100');
	}	

	function format_pop_dev() {
		window.open('http://calendardev.biola.edu/text_format_guide.cfm', '', 'toolbar=no,scrollbars=yes,width=500,height=300,top=100,left=100');
	}	
	
	function rp_login(text) {
		document.getElementById('rp_login').innerHTML = text;
	}
	function rp_depts(text) {
		document.getElementById('rp_dept').innerHTML = text;
	}
	function rp_cats(text) {
		document.getElementById('rp_cats').innerHTML = text;
	}
	function rp_images(text) {
		document.getElementById('rp_imgs').innerHTML = text;
	}
	function rp_sites(text) {
		document.getElementById('rp_sites').innerHTML = text;
	}



	
	
	
	
	function wordcount(string) {
	  var a = string.split(/\s+/g); // split the sentence into an array of words
	  return a.length;
	}

	function checkWords(area, totalwords) {
		var remaining = totalwords - wordcount(area.value);
		//if (remaining < 0) {
		//	area.value = area.value.substring(0, (area.value.length - 1));
		//}
		document.getElementById(area.id + '-count').innerHTML = remaining;
	}