// +--------------------------------------------------------------------------+
// | Tomorrow's Edition: Common JavaScript Function Library                   |
// | By: Joseph Reiter                                                        |
// +--------------------------------------------------------------------------+


// +--------------------------------------------------------------------------+
// | *** SECTION 1: CONFIGURATION ***                                         |
// +--------------------------------------------------------------------------+

// TE Calendar Standalone Script Location
var TECalendarLocation = '/cgi-bin/te/te_calendar.pl';

// TE Calendar Standalone Script Location
var TEEventListingLocation = '/cgi-bin/te/te_events_listings.pl';

// Initialize TE Preview Window Variable
var TEPreviewWindow = '';

// Array to store checked state of lists of checkboxes
var TE_Check_Flag= new Array();


// +--------------------------------------------------------------------------+
// | *** SECTION 2: EVENT TOOL SPECIFIC FUNCTIONS ***                         |
// +--------------------------------------------------------------------------+

function TE_Events_Listings() {

	var TE_Events_Listings_URL = TEEventListingLocation;

	if ((document.EventFilters.te_user.value) && (document.EventFilters.te_pass.value)) {

		if (TE_Events_Listings_URL == TEEventListingLocation) {

			TE_Events_Listings_URL = TE_Events_Listings_URL + '?';

		} else {

			TE_Events_Listings_URL = TE_Events_Listings_URL + '&';

		}

		TE_Events_Listings_URL += 'te_user=' + document.EventFilters.te_user.value + '&te_pass=' + document.EventFilters.te_pass.value;

	}

	if (document.EventFilters.te_type) {

		if (document.EventFilters.te_type.value == 'News') {

			if (TE_Events_Listings_URL == TEEventListingLocation) {

				TE_Events_Listings_URL = TE_Events_Listings_URL + '?';

			} else {

				TE_Events_Listings_URL = TE_Events_Listings_URL + '&';

			}

			TE_Events_Listings_URL += 'te_type=News';

		}

	}

	if (document.EventFilters.Date.value) {

		if (TE_Events_Listings_URL == TEEventListingLocation) {

			TE_Events_Listings_URL = TE_Events_Listings_URL + '?';

		} else {

			TE_Events_Listings_URL = TE_Events_Listings_URL + '&';

		}

		TE_Events_Listings_URL = TE_Events_Listings_URL + 'Date=' + document.EventFilters.Date.value;

	}

	if (document.EventFilters.Audience.value) {

		if (TE_Events_Listings_URL == TEEventListingLocation) {

			TE_Events_Listings_URL = TE_Events_Listings_URL + '?';

		} else {

			TE_Events_Listings_URL = TE_Events_Listings_URL + '&';

		}

		TE_Events_Listings_URL = TE_Events_Listings_URL + 'Audience=' + document.EventFilters.Audience.value;

	}

	if (document.EventFilters.EventType) {

		if (document.EventFilters.EventType.value) {

			if (TE_Events_Listings_URL == TEEventListingLocation) {

				TE_Events_Listings_URL = TE_Events_Listings_URL + '?';

			} else {

				TE_Events_Listings_URL = TE_Events_Listings_URL + '&';

			}

			TE_Events_Listings_URL = TE_Events_Listings_URL + 'EventType=' + document.EventFilters.EventType.value;

		}

	}

	if (document.EventFilters.NewsType) {

		if (document.EventFilters.NewsType.value) {

			if (TE_Events_Listings_URL == TEEventListingLocation) {

				TE_Events_Listings_URL = TE_Events_Listings_URL + '?';

			} else {

				TE_Events_Listings_URL = TE_Events_Listings_URL + '&';

			}

			TE_Events_Listings_URL = TE_Events_Listings_URL + 'NewsType=' + document.EventFilters.NewsType.value;

		}

	}

	if (document.EventFilters.Location) {

		if (document.EventFilters.Location.value) {

			if (TE_Events_Listings_URL == TEEventListingLocation) {

				TE_Events_Listings_URL = TE_Events_Listings_URL + '?';

			} else {

				TE_Events_Listings_URL = TE_Events_Listings_URL + '&';

			}

			TE_Events_Listings_URL = TE_Events_Listings_URL + 'Location=' + document.EventFilters.Location.value;

		}

	}

	if (document.EventFilters.NewsSubject) {

		if (document.EventFilters.NewsSubject.value) {

			if (TE_Events_Listings_URL == TEEventListingLocation) {

				TE_Events_Listings_URL = TE_Events_Listings_URL + '?';

			} else {

				TE_Events_Listings_URL = TE_Events_Listings_URL + '&';

			}

			TE_Events_Listings_URL = TE_Events_Listings_URL + 'NewsSubject=' + document.EventFilters.NewsSubject.value;

		}

	}

	makeRequest2(TE_Events_Listings_URL);

}


function TE_Login_Validator(theForm) {

	if (theForm.Username.value == "") {

		alert("Please enter your username.");
		theForm.Username.focus();
		return (false);

	}

	if (theForm.Plain.value == "") {

		alert("Please enter your password.");
		theForm.Plain.focus();
		return (false);

	}

	theForm.te_user.value = hex_md5(theForm.Username.value);
	theForm.Username.value = "";

	theForm.te_pass.value = hex_md5(theForm.Plain.value);
	theForm.Plain.value = "";

	return (true);

}


function TE_Add_Login_Validator(theForm) {

	if (theForm.Username.value == "") {

		alert("Please enter your username.");
		theForm.Username.focus();
		return (false);

	}

	if (theForm.Plain.value == "") {

		alert("Please enter your password.");
		theForm.Plain.focus();
		return (false);

	}

	if (theForm.FirstName.value == "") {

		alert("Please enter your first name.");
		theForm.FirstName.focus();
		return (false);

	}

	if (theForm.LastName.value == "") {

		alert("Please enter your last name.");
		theForm.LastName.focus();
		return (false);

	}

	if (theForm.EmailAddress.value == "") {

		alert("Please enter your email address.");
		theForm.EmailAddress.focus();
		return (false);

	}

	if (!(isEmail(theForm.EmailAddress.value))) {

		alert("Please enter a valid email address.");
		theForm.EmailAddress.focus();
		return (false);

	}

	theForm.te_new_user.value = hex_md5(theForm.Username.value);
	theForm.Username.value = "";

	theForm.te_new_pass.value = hex_md5(theForm.Plain.value);
	theForm.Plain.value = "";

	return (true);

}


function Modify_Event_Validator(theForm) {

  if (theForm.EventName.value == "") {

    alert("Please enter the event name.");
    theForm.EventName.focus();
    return (false);

  }

  if (theForm.SpeakerBioLink.value != "") {

	if (!(isUrl(theForm.SpeakerBioLink.value))) { 
		alert("Please enter a valid speaker bio web address.\n\n    Ex: http://www.example.com/");
    	theForm.SpeakerBioLink.focus();
    	return (false);
	}

  }

  if (theForm.EventDescription.value == "") {

    alert("Please enter a short event description.");
    theForm.EventDescription.focus();
    return (false);

  }

  if (theForm.EventDescriptionLong.value == "") {

    alert("Please enter a long event description.");
    theForm.EventDescriptionLong.focus();
    return (false);

  }

  if (theForm.EventWebLink.value != "") {

	if (!(isUrl(theForm.EventWebLink.value))) { 
		alert("Please enter a valid event web site address.\n\n    Ex: http://www.example.com/");
    	theForm.EventWebLink.focus();
    	return (false);
	}

  }

  if ((theForm.EventRSVPLink.value != "") && (theForm.EventRSVPEmailLink.value != "")) {

	alert("Please enter only one RSVP type.  (Web Site Link or Email Address)");
    theForm.EventRSVPLink.focus();
	return (false);

  }

  if (theForm.EventRSVPLink.value != "") {

	if (!(isUrl(theForm.EventRSVPLink.value))) { 
		alert("Please enter a valid RSVP web site address.\n\n    Ex: http://www.example.com/");
    	theForm.EventRSVPLink.focus();
    	return (false);
	}

  }

  if (theForm.EventRSVPEmailLink.value != "") {

	if (!(isEmail(theForm.EventRSVPEmailLink.value))) {
		alert("Please enter a valid RSVP email address link.");
		theForm.EventRSVPEmailLink.focus();
		return (false);
	}

  }

  if (theForm.EventStartDateTime.value == "") {

    alert("Please enter a start date and time for the event.");
    theForm.EventStart.focus();
    return (false);

  }

  if (theForm.EventEndDateTime.value == "") {

    alert("Please enter an end date and time for the event.");
    theForm.EventEnd.focus();
    return (false);

  }

  if (theForm.EventStartDateTime.value > theForm.EventEndDateTime.value) {

    alert("The event start date and time can not be after the end date and time.");
    theForm.EventStart.focus();
    return (false);

  }

  if (theForm.EventWebcastLink.value != "") {

	if (!(isUrl(theForm.EventWebcastLink.value))) { 
		alert("Please enter a valid webcast address.\n\n    Ex: http://www.example.com/webcast.ram");
    	theForm.EventWebcastLink.focus();
    	return (false);
	}

  }

  if (theForm.EventWebcastDateTime.value !="") {

    if (theForm.EventWebcastDateTime.value > theForm.EventEndDateTime.value) {

      alert("The webcast date and time can not be after the event end date and time.");
      theForm.EventWebcastDateTime.focus();
      return (false);

    }

    if (theForm.EventWebcastDateTime.value < theForm.EventStartDateTime.value) {

      alert("The webcast date and time can not be before the event start date and time.");
      theForm.EventWebcastDateTime.focus();
      return (false);

    }

  }
  
  if (((theForm.EventWebcastLink.value !="") || (theForm.EventWebcastDateTime.value !="")) && (!((theForm.EventWebcastLink.value !="") && (theForm.EventWebcastDateTime.value !="")))) {

    alert("To setup a webcast, both a webcast link and a webcast date / time must be specified.");
    theForm.EventWebcastLink.focus();
    return (false);

  }

  if (theForm.EventFacilityName.value == "") {

    alert("Please enter a facility name for the event.");
    theForm.EventFacilityName.focus();
    return (false);

  }

  if (theForm.EventAddress.value == "") {

    alert("Please enter the address of the facility for the event.");
    theForm.EventAddress.focus();
    return (false);

  }

  if (theForm.EventContact.value == "") {

    alert("Please enter a contact name for the event.");
    theForm.EventContact.focus();
    return (false);

  }

  if (theForm.EventContactPhone.value == "") {

    alert("Please enter the phone number of the contact for the event.");
    theForm.EventContactPhone.focus();
    return (false);

  }

  if (checkInternationalPhone(theForm.EventContactPhone.value)==false) {

    alert("Please enter a valid phone number for the contact for the event.");
    theForm.EventContactPhone.focus();
    return (false);

  }

  if (theForm.EventContactEmail.value == "") {

    alert("Please enter the email address of the contact for the event.");
    theForm.EventContactEmail.focus();
    return (false);

  }

  if (!(isEmail(theForm.EventContactEmail.value))) {

    alert("Please enter a valid email address for the contact for the event.");
    theForm.EventContactEmail.focus();
    return (false);

  }

  if (theForm.EventActivationDate.value == "") {

    alert("Please enter an activation date for the event.");
    theForm.EventActivation.focus();
	return (false);

  }

  return (true);

}


function Modify_News_Validator(theForm) {

  if (theForm.NewsType.value == "") {

    alert("Please select the news type.");
    theForm.NewsType.focus();
    return (false);

  }

  if (isChecked(theForm.NewsSubject)==false) {

    alert("Please specify the subject of the news.");
    theForm.NewsSubject[0].focus();
    return (false);

  }

  if (isChecked(theForm.NewsAudience)==false) {

    alert("Please specify the audience interested in the news.");
    theForm.NewsAudience[0].focus();
    return (false);

  }

  if (theForm.NewsHeadline.value == "") {

    alert("Please enter the headline.");
    theForm.NewsHeadline.focus();
    return (false);

  }

  if (theForm.NewsContentDate.value == "") {

    alert("Please enter the news date.");
    theForm.NewsContentDisplayDate.focus();
    return (false);

  }

  if (theForm.NewsShortDescription.value == "") {

    alert("Please enter a short description of the news.");
    theForm.NewsShortDescription.focus();
    return (false);

  }

  if (theForm.NewsShortDescription.value.toLowerCase() == theForm.NewsHeadline.value.toLowerCase()) {

    alert("Please do not use the same text for the short description as the headline.  Try using a sentence or two from the news/article text to paraphrase the news/article for the short description.");
    theForm.NewsShortDescription.focus();
    return (false);

  }

  if (tinyMCE.activeEditor.getContent() == "") {

    if (theForm.NewsType.value == "Articles (link)") {

      alert("Please enter a long description of the news.");

    } else {

      alert("Please enter the full article text.");

    }

    // First throw focus near the field, then focus on the TinyMCE field
    theForm.NewsShortDescription.focus();

    // TinyMCE focus is causing trouble in IE (form submits, true is returned)
    // so disable in IE for now
    if (navigator.appName != 'Microsoft Internet Explorer') { tinyMCE.activeEditor.execCommand('mceFocus'); }

    return (false);

  }

  if ((theForm.NewsType.value == "Articles (link)") && (theForm.NewsExternalLink.value == "")) {

    alert("Please enter a link to the article.");
    theForm.NewsExternalLink.focus();
    return (false);

  }

  if (theForm.NewsExternalLink.value != "") {

    if (!(isUrl(theForm.NewsExternalLink.value))) { 

      alert("Please enter a valid link to the article.\n\n    Ex: http://www.example.com/");
      theForm.NewsExternalLink.focus();
      return (false);

    }

  }

  if (theForm.NewsType.value == "Press Releases") {

    if (theForm.NewsAuthor.value == "") {

      alert("Please enter the name(s) of the author(s).");
      theForm.NewsAuthor.focus();
      return (false);

    } else if (theForm.NewsAuthorContactInformation.value == "") {

      alert("Please enter the author contact information.");
      theForm.NewsAuthorContactInformation.focus();
      return (false);

    }

  }

  return (true);

}


function TEGeneratePreviewWindow(theForm,originalFormAction) {

  if ((theForm) && (originalFormAction)) {

	// Make sure everyone starts with a fresh window
	TEClosePreviewWindow();

	// Prepare preview window and temporarily change the target and action of the form
	if (document.ModifyEntry.te_type) {
		if (document.ModifyEntry.te_type.value == 'News') {
			theForm.action = '/cgi-bin/te/te_news_view.pl';
			TEPreviewWindow = window.open('','PreviewWindow','width=988,height=568,scrollbars=yes,toolbar=no,resizable=no');
		}
	} else {
		theForm.action = '/cgi-bin/te/te_preview.pl';
		TEPreviewWindow = window.open('','PreviewWindow','width=488,height=553,scrollbars=yes,toolbar=no,resizable=no');
	}
	theForm.target = 'PreviewWindow';

	theForm.submit();

	// Reset values for any subsequent form submits
	theForm.target = '_self';
	theForm.action = originalFormAction;
	return (true);

  }

}


function TEClosePreviewWindow() {

	if(!TEPreviewWindow.closed && TEPreviewWindow.location) {

		// Make sure everyone starts with a fresh window
		TEPreviewWindow.close();

	}

}


// +--------------------------------------------------------------------------+
// | FUNCTION: LOCAL OR INTERNATIONAL                                         |
// +--------------------------------------------------------------------------+
// | If U.S. is selected as the country, displays US address format... if not |
// | displays an international address format and set of variables.           |
// +--------------------------------------------------------------------------+

function localOrInternational(SelectedOption,FormName) {
	var myRegxp = /United States/i;
	DomesticStateRow = document.getElementById('EventStateDomestic');
	InternationalStateRow = document.getElementById('EventStateWorldwide');

//	if (myRegxp.test(SelectedOption)) {
	if ((SelectedOption == 'United States') || (SelectedOption == '')) {
		// It is a domestic address, show U.S. State List
		DomesticStateRow.style.display = "";
		InternationalStateRow.style.display = "none";
		FormName.EventState.disabled = false;
		FormName.EventStateInternational.disabled = true;
	} else {
		// It is not a domestic address, show International State Field
		DomesticStateRow.style.display = "none";
		InternationalStateRow.style.display = "";
		FormName.EventState.disabled = true;
		FormName.EventStateInternational.disabled = false;
	}
}


// +--------------------------------------------------------------------------+
// | FUNCTION: NEWS OPTIONAL REQUIRED FIELDS                                  |
// +--------------------------------------------------------------------------+
// | If certain news types are selected in the form, certain other fields are |
// | then required.                                                           |
// +--------------------------------------------------------------------------+

function newsOptionalRequiredFields(SelectedOption) {
	LinkToArticleSpan = document.getElementById('LinkToArticle');
	AuthorSpan = document.getElementById('Author');
	AuthorContactInfoSpan = document.getElementById('AuthorContactInfo');
	LongDescriptionSpan = document.getElementById('LongDescription');
	FullArticleTextSpan = document.getElementById('FullArticleText');

	if (SelectedOption == 'Articles (link)') {
		// It is an article with an external link
		LinkToArticleSpan.style.display = "";
		LongDescriptionSpan.style.display = "";
		FullArticleTextSpan.style.display = "none";

	} else {
		// It is not an article with an external link
		LinkToArticleSpan.style.display = "none";
		LongDescriptionSpan.style.display = "none";
		FullArticleTextSpan.style.display = "";
	}


	if (SelectedOption == 'Press Releases') {
		// It is a press release
		AuthorSpan.style.display = "";
		AuthorContactInfoSpan.style.display = "";
	} else {
		// It is not a press release
		AuthorSpan.style.display = "none";
		AuthorContactInfoSpan.style.display = "none";
	}

}


// +--------------------------------------------------------------------------+
// | *** SECTION 3: GENERAL PURPOSE FUNCTIONS ***                             |
// +--------------------------------------------------------------------------+

// +--------------------------------------------------------------------------+
// | FUNCTION: CONVERT TO UNIX TIME                                           |
// +--------------------------------------------------------------------------+
// | Converts a specified time into a string of UNIX time.                    |
// |                                                                          |
// | Usage: var = ConvertToUnixTime(TimeToConvert);                           |
// |                                                                          |
// |  ** Required Parameters **                                               |
// |       TimeToConvert: Date specified (ex: '12/25/2006')                   |
// +--------------------------------------------------------------------------+

function ConvertToUnixTime(TimeToConvertInput) {

	TimeToConvert = new Date(TimeToConvertInput); 
	return (TimeToConvert.getTime() / 1000);

}


// +--------------------------------------------------------------------------+
// | FUNCTION: ALERT HELP                                                     |
// +--------------------------------------------------------------------------+
// | Alerts a predefined help message.  This help message is pulled from an   |
// | associative array.                                                       |
// |                                                                          |
// | Usage: alertHelp(HelpToDisplay);                                         |
// |                                                                          |
// |  ** Required Parameters **                                               |
// |       HelpToDisplay: Date specified (ex: 'Modify An Entry')              |
// +--------------------------------------------------------------------------+

function alertHelp(HelpToDisplay) {

	// Create an associative array to display help messages
	var Help_Messages= new Array()
	Help_Messages["Login"]="EVENTS TOOL HELP: Login\n\nYour username and password are \"case sensitive\",\nthat is, enter both exactly as provided to you\nin terms of upper and lower case letters.\n\nNOTE: If you are having trouble logging in,\nplease contact technical support for assistance.";
	Help_Messages["Main Menu"]="EVENTS TOOL HELP: Main Menu\n\nSelect the tasks you need to accomplish from the\nlist of tasks available below.";
	Help_Messages["Main Menu Events"]="EVENTS TOOL HELP: Events Actions\n\nSelect from the list of tasks related to creating,\nediting, or approving events.";
	Help_Messages["Event Select"]="EVENTS TOOL HELP: Select Event To Modify\n\nSearch for events to modify using the filters and/or\nthe calendar below.";
	Help_Messages["Event Approve Select"]="EVENTS TOOL HELP: Select Event To Approve\n\nSelect event to approve / reject from the list of\npending event listings below.\n\nNOTE: You will only see events listed that you are\nauthorized to approve.";
	Help_Messages["Event Approve or Reject"]="EVENTS TOOL HELP: Approve / Reject An Event\n\nSelect the pages that the event is authorized to\nappear on.  Click on the name of the page below\nto see each page.";
	Help_Messages["Event Approve or Reject Buttons"]="EVENTS TOOL HELP: Approve / Reject An Event\n\nClicking the \"Save\" button will apply the changes\nyou requested.  Clicking the \"Cancel\" button will\ncancel your request without saving the changes.";
	Help_Messages["Modify An Entry"]="EVENTS TOOL HELP: Modify An Entry\n\nEnter as much information as you know about the\nevent.  You can always modify your entry later\nand enter / change any additional information.\n\nNOTE: All fields marked with a red asterisk (*)\nare required.";

	if(Help_Messages[HelpToDisplay]) {

		alert(Help_Messages[HelpToDisplay]);

	}

}


function TEDeleteRecordConfirmation() {

	if (window.confirm('EVENTS TOOL WARNING: CONFIRM ENTRY DELETION\n\nDeleting an entry is NOT ACCURATELY UNDO-ABLE. Once you\ndelete an entry from this system, restoring from backups\nmay cause more problems than the deletion itself as you\nWILL LOSE ANY OTHER RECENT CHANGES to the events tool\nsystem and will have to manually re-enter them.\n\nIf you are sure you want to delete, click Ok to continue.\nIf you are not sure, click Cancel.')) {

		// They've clicked Ok, delete the record.
		return (true);

	} else {

		// They've clicked Cancel, don't do anything
		return (false);

	}

}


// +--------------------------------------------------------------------------+
// | FUNCTION: TEXT COUNTER                                                   |
// +--------------------------------------------------------------------------+
// | Dynamic Version by: Nannette Thacker                                     |
// | http://www.shiningstar.net                                               |
// | Original by: Ronnie T. Moore                                             |
// | Web Site: The JavaScript Source                                          |
// |                                                                          |
// | Modified by: Joseph Reiter                                               |
// | (added getElementById support)                                           |
// |                                                                          |
// | Use one function for multiple text areas on a page.  Limit the number of |
// | characters per textarea.                                                 |
// +--------------------------------------------------------------------------+

function textCounter(field,cntFieldId,maxLimit) {

	if (field.value.length > maxLimit) {

		// if too long...trim it!
		field.value = field.value.substring(0, maxLimit);

	}

	// Update 'characters left' counter
	document.getElementById(cntFieldId).innerHTML = maxLimit - field.value.length;

}


// +--------------------------------------------------------------------------+
// | FUNCTION: ADD LOAD EVENT                                                 |
// +--------------------------------------------------------------------------+
// | By: Simon Willison                                                       |
// | http://simon.incutio.com/                                                |
// |                                                                          |
// | Adds an event to be processed on page load.                              |
// +--------------------------------------------------------------------------+

function addLoadEvent(func) {

	var oldonload = window.onload;
	if (typeof window.onload != 'function') {

		window.onload = func;

	} else {

		window.onload = function() {

			if (oldonload) {

				oldonload();

			}

			func();

		}

	}

}


// ------------------------------------------
// | Check for valid email addresses.       |
// ------------------------------------------

function isEmail(str) {

  // are regular expressions supported?
  var supported = 0;

  if (window.RegExp) {

    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;

  }

  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));

}


// ------------------------------------------
// | Check for valid email addresses links. |
// ------------------------------------------

function isEmailLink(str) {

  // are regular expressions supported?
  var supported = 0;

  if (window.RegExp) {

    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;

  }

  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  var r3 = /(mailto):?/
  return (!r1.test(str) && r2.test(str) && r3.test(str));

}


// ------------------------------------------
// | Check for valid urls.                  |
// ------------------------------------------

function isUrl(str) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(str);
}


// ------------------------------------------
// | Check for valid numbers in strings.    |
// ------------------------------------------

function isNumber(str) {

  // Variables
  var checkOK = "0123456789";
  var checkStr = str;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";

  for (i = 0;  i < checkStr.length;  i++) {

    ch = checkStr.charAt(i);

    for (j = 0;  j < checkOK.length;  j++)

      if (ch == checkOK.charAt(j))
        break;

    if (j == checkOK.length) {

      allValid = false;
      break;

    }

    if (ch != ",")
      allNum += ch;

  }

  return allValid;

}


/* ------------------------------------------
   | Check for non-null and valid telephone |
   | numbers (including International ones) |
   ------------------------------------------ */

/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";

// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "().- ";

// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";

// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

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 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++) {

    // Check that current character isn't whitespace.
    var c = s.charAt(i);
    if (bag.indexOf(c) == -1) returnString += c;

  }

  return returnString;

}

function checkInternationalPhone(strPhone) {

  s=stripCharsInBag(strPhone,validWorldPhoneChars);
  return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);

}


// ------------------------------------------
// | Checks if any checkboxes are checked.  |
// ------------------------------------------
function isChecked(theFormField) {

	for (i = 0; i < theFormField.length; i++) {

		if (theFormField[i].checked == true) {

			// If any checkbox is checked, return true
			return (true);

		}
			
	}

	// No checkboxes were checked
	return (false);

}


function TE_Check(field, field_check) {

	if (TE_Check_Flag[field_check] == "true") {

		for (i = 0; i < field.length; i++) {

			field[i].checked = false;
			
		}

		TE_Check_Flag[field_check] = "false";
		return "Check All";
		
	} else {

		for (i = 0; i < field.length; i++) {

			field[i].checked = true;

		}

		TE_Check_Flag[field_check] = "true";
		return "Uncheck All";
		
	}

}


// +--------------------------------------------------------------------------+
// | *** SECTION 4: AJAX FUNCTIONS ***                                        |
// +--------------------------------------------------------------------------+

// DO NOT MODIFY
var http_request = false;

function makeRequest(url,replaceurl) {

	http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...

		http_request = new XMLHttpRequest();

		if (http_request.overrideMimeType) {

			//http_request.overrideMimeType('text/xml');
			http_request.overrideMimeType('text/html');

		}

	} else if (window.ActiveXObject) { // IE

		try {

			http_request = new ActiveXObject("Msxml2.XMLHTTP");

		}

		catch (e) {

			try {

				http_request = new ActiveXObject("Microsoft.XMLHTTP");

			}

			catch (e) {}

		}

	}

	if (!http_request) {

		// Unable to create an XMLHTTP instance... give up
		return false;

	}

	var random_number = Math.random()+"";
	var random_integer = parseInt(random_number * 100000000000000000);

	// Get Date variable from URL
	var ExtractGETVars = url;
	var getVars = new Array();
	var locvartemp = ( ExtractGETVars.indexOf( "?" ) + 1 ) ? ExtractGETVars.substr( ExtractGETVars.indexOf( "?" ) + 1 ) : "";
	locvartemp = locvartemp.split( "&" );
	for( var x = 0; x < locvartemp.length; x++ ) {
		var lvTempVar = locvartemp[x].split( "=" );
		getVars[ unescape( lvTempVar[0] ) ] = unescape( lvTempVar[1] );
	}

	document.EventFilters.Date.value = getVars["Date"];

	// Use the appropriate script name for javascript
	var url = url.replace(replaceurl,TECalendarLocation);

	if (url.indexOf("?")==-1) {
		var url = url + "?s=n";
	}

	var url = url + "&ReplaceURL=" + replaceurl + "&seed=" + random_integer;

	if ((document.EventFilters.te_user.value) && (document.EventFilters.te_pass.value)) {
		
		url = url + "&te_user=" + document.EventFilters.te_user.value + "&te_pass=" + document.EventFilters.te_pass.value;

	}

	http_request.onreadystatechange = alertContents;
	http_request.open('GET', url, true);
	http_request.send(null);

}


function alertContents() {

	if (http_request.readyState == 4) {

		if (http_request.status == 200) {

			var CalendarHTML = document.getElementById('CalendarHTML');
			TE_Events_Listings();
//			CalendarHTML.innerHTML = http_request.responseText;

		}

	}

}


function makeRequest2(url) {

	http_request2 = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...

		http_request2 = new XMLHttpRequest();

		if (http_request2.overrideMimeType) {

			//http_request2.overrideMimeType('text/xml');
			http_request2.overrideMimeType('text/html');

		}

	} else if (window.ActiveXObject) { // IE

		try {

			http_request2 = new ActiveXObject("Msxml2.XMLHTTP");

		}

		catch (e) {

			try {

				http_request2 = new ActiveXObject("Microsoft.XMLHTTP");

			}

			catch (e) {}

		}

	}

	if (!http_request2) {

		// Unable to create an XMLHTTP instance... give up
		return false;

	}

	var random_number = Math.random()+"";
	var random_integer = parseInt(random_number * 100000000000000000);

	// Get Date variable from URL
	var ExtractGETVars = url;
	var getVars = new Array();
	var locvartemp = ( ExtractGETVars.indexOf( "?" ) + 1 ) ? ExtractGETVars.substr( ExtractGETVars.indexOf( "?" ) + 1 ) : "";
	locvartemp = locvartemp.split( "&" );
	for( var x = 0; x < locvartemp.length; x++ ) {
		var lvTempVar = locvartemp[x].split( "=" );
		getVars[ unescape( lvTempVar[0] ) ] = unescape( lvTempVar[1] );
	}

//	document.EventFilters.Date.value = getVars["Date"];

	if (url == TEEventListingLocation) {
		var url = url + "?seed=" + random_integer;
	} else {
		var url = url + "&seed=" + random_integer;
	}
	
	http_request2.onreadystatechange = alertContents2;
	http_request2.open('GET', url, true);
	http_request2.send(null);

}


function alertContents2() {

	if (http_request2.readyState == 4) {

		if (http_request2.status == 200) {

			var EventListingHTML = document.getElementById('EventListingD');
			EventListingHTML.innerHTML = http_request2.responseText;

			if (http_request.responseText) {
				var CalendarHTML = document.getElementById('CalendarHTML');
				CalendarHTML.innerHTML = http_request.responseText;
			}

		}

	}

}
