// JavaScript Document
// Global variables

var defaultReturnURL = "http://www.covercincy.org";

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// Common validation routines

// trims leading and trailing whitespace from a string
function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

// find the index of a value in an array
function getIndexOf ( searchObj, searchArray ) {
	if ( !searchArray || !searchObj ) return null;
	var searchPos = 0;
	while ( searchArray[searchPos] != searchObj && searchPos < searchArray.length ) searchPos++;
	if ( searchArray[searchPos] == searchObj ) return searchPos;
	else return null;
}

// determines if a string is empty
function isEmpty(strText) {
	if ( strText == null || strText == "" ) return true;
	else return false;
}

// isLink - check for http:// at beginning of the string
function isLink(strText) {
	if ( strText.substring(0,4) == "http" ) return true;
	else return false;
}

// makeLink - if a string does not begin with http, this function adds it
function makeLink(strText) {
	return "http://" + strText;
}

// gets the previous URL in the history array & returns as string
function getPreviousURL() {
	var myIndex
	try {
		myIndex = getIndexOf ( history.current, window.history );
	}
	catch (error) {
		myIndex = 0;
	}
	if (myIndex != 0) return window.history[myIndex - 1];
	else return defaultReturnURL;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// Page validations
function analysisForm_submit() {
	// Check for required fields
	if ( isEmpty(MM_findObj("firstName").value) )			alert("Please enter your first name.");
	else if ( isEmpty(MM_findObj("lastName").value) ) 		alert("Please enter your last name.");
	else {
		// submit
		document.analysisForm.submit();
	}
}

function eventForm_submit() {
	// Check for required fields
	if ( isEmpty(MM_findObj("name").value) ) 					alert("Please enter your name.");
	else if ( isEmpty(MM_findObj("email").value) ) 				alert("Please enter an email address so that we can confirm your registration.");
	else {
		// submit
		document.eventForm.submit();
	}
}
