	// Global variables
	var cfFunctionsUrl = '/mxFunctions.cfm'; // Location of ajax functions
	var proposalSort = ''; // String to hold responses sorting option

	// Add some useful functions
	String.prototype.isDate = function(){ return /^\d{1,2}[\/]\d{1,2}[\/]\d{2,4}$/.test(this); }
	String.prototype.isTime = function(){ return /^\d{1,2}[:]\d{2}$/.test(this); }
	String.prototype.isNumeric = function(){ return /^\d+$/.test(this); }
	String.prototype.formatNumber = function(){ a = this; while (/(\d+)(\d{3})/.test(a)) a = a.replace(/(\d+)(\d{3})/, '$1,$2'); return a; }

	// Extend prototype's Element class some
	Element.addMethods({
		// Makes it easy to append a child element with the attributes needed
		// Returns the new extended child HTML node
		// Usage:  parentElement.addChild('td', { width: '75%', align: 'right' });
		addChild: function( element, tagName, attributes ) {
			var elm = Object.extend($(document.createElement(tagName)), attributes || {});
			$(element).appendChild(elm); return elm;
		},
		// Easy way to remove all child nodes from an element
		// Returns an extended reference to the parent node
		// Usage: parentElement.removeChildren(); OR Element.removeChildren( parentElement );
		removeChildren: function( element ) {
			element = $(element);
			$A(element.childNodes).each(function(node){ element.removeChild(node); });
			return element;
		}
	});

	function setupMouseovers() {
		$A($$('img[hsrc|dsrc]','input[type=image][hsrc|dsrc]')).each(function(el) {
			el.n = new Image(); el.n.src = el.src;

			var hsrc = el.getAttribute('hsrc');
			if (hsrc != null && !hsrc.blank()) { // Add hover image
				el.h = new Image(); el.h.src = hsrc;
				el.observe('mouseover', function(){ this.src = this.h.src; }.bindAsEventListener(el));
				el.observe('mouseout', function(){ this.src = this.n.src; }.bindAsEventListener(el));
			}

			var dsrc = el.getAttribute('dsrc');
			if (dsrc != null && !dsrc.blank()) { // Add down image
				el.d = new Image(); el.d.src = dsrc;
				el.observe('mousedown', function(){ this.src = this.d.src; }.bindAsEventListener(el));
				el.observe('mouseup', function(){ this.src = this.n.src; }.bindAsEventListener(el));
			}
		});
	}

	// Event.observe(window, 'load', setupMouseovers); // Sets up all image and input tags with hsrc or dsrc attributes

// Window management ---

	function showWindow( element ) {
		element = $(element).show();
		$A(element.ancestors()).invoke('show'); // Show parents
		document.getElementsByClassName('contentWindow', element).invoke('show'); // Show Children
	}

	function showMenu( element ) {
		document.getElementsByClassName('navigation').invoke('hide'); // Hide all menus
		$(element).show(); // Show selected menu
	}

	// Apply method of each member
	function invokeAllWindows( member ) { document.getElementsByClassName('contentWindow').invoke(member); }

	function showAllViewWindows( parent ) {
		invokeAllWindows('hide'); // Hide all content windows
		$A(document.getElementsByClassName('contentWindow', $(parent))).each(function(w){
			if (w.id.indexOf('VIEW_') > -1) showWindow(w); // Show all child view windows
		});
	}

	function showAllSections() {
		invokeAllWindows('hide'); // Hide all content windows
		$A(document.getElementsByClassName('contentWindow')).each(function(w){
			if (w.hasClassName('parentWindow')) w.setStyle({ position: 'static' }); // Make sure sections don't overlap
			if (w.id.indexOf('VIEW_') > -1) showWindow(w); // Show each view window
		});
	}

// End Window management ---



var postFavoritevar = false;
var submitpostFavorite = function(programId) {
	if(postFavoritevar) {
		alert('Form is being proceesed.  Please wait.');
		return false;
	}
	postFavoritevar = true;
	var isError = false;

	var e = new wgbhObject();
	e.setCallbackHandler(returnsubmitpostFavorite);
	e.setErrorHandler(submitpostFavoriteErrorHandler);
	e.setFavorite(programId);

}
var submitpostFavoriteErrorHandler = function(statusCode, statusMsg)
{
	postFavoritevar = false;
	alert('Status: ' + statusCode + ', ' + statusMsg);
}
var returnsubmitpostFavorite = function(results) {

	postFavoritevar = false;
	if (results.ERROR ==1)
		alert(results.CONTENT);
	else if(results.CONTENT == 1) 
	  $('favLink').innerHTML = 'Remove from Favorites';
	else 
	  $('favLink').innerHTML = 'Add to Favorites';
}



var postCommentvar = false;
var submitpostComment = function(theForm) {
	var theForm = document.getElementById('postCommentForm');
	if(postCommentvar) {
		alert('Form is being proceesed.  Please wait.');
		return false;
	}
	postCommentvar = true;
	var isError = false;

	var e = new wgbhObject();
	e.setCallbackHandler(returnsubmitpostComment);
	e.setErrorHandler(submitpostCommentErrorHandler);
	e.setForm('postCommentForm');
	e.setHTTPMethod('POST');
	e.postComment();

}
var submitpostCommentErrorHandler = function(statusCode, statusMsg)
{
	postCommentvar = false;
	alert('Status: ' + statusCode + ', ' + statusMsg);
}
var returnsubmitpostComment = function(results) {

	postCommentvar = false;
	if (results.ERROR ==1)
		alert(results.MESSAGE);
	else
        {
            document.getElementById('formBlock').innerHTML='<p>Your comment has been submitted for approval</p>';
        }

}

var Core = {};

Core.getElementsByClass = function(theClass) {
	var elementArray = [];

	if (document.all)
	{
	elementArray = document.all;
	}
	else
	{
	elementArray = document.getElementsByTagName("*");
	}

	var matchedArray = [];
	var pattern = new RegExp("(^| )" + theClass + "( |$)");

	for (var i = 0; i < elementArray.length; i++)
	{
	if (pattern.test(elementArray[i].className))
	{
	  matchedArray[matchedArray.length] = elementArray[i];
	}
	}

	return matchedArray;
};

function hideClass(classObj) {
	var list = Core.getElementsByClass(classObj);
	for (var i = 0; i < list.length; i++) {
	list[i].style.display = 'none';
	}
}

function revertClass(classObj1,classObj2) {
	var list = Core.getElementsByClass(classObj2);
	for (var i = 0; i < list.length; i++) {
	list[i].className = classObj1 + ' ' + classObj2;
	}
}

function showDiv(divObj) {
	document.getElementById(divObj).style.display='block';
}

function hideDiv(divObj) {
	document.getElementById(divObj).style.display='none';
}


lastClass = 'x';
lastId = '0';
function swapClass(idObj,classObj) {
  //  alert(lastClass + idObj + 'and' + classObj);
  if (classObj != 'activeSchedule') {
      if (lastClass != 'x') {
        if (document.getElementById(lastId)) {
            document.getElementById(lastId).className = lastClass;
        }
      }
      document.getElementById(idObj).className = 'activeSchedule';
      lastId = idObj;
      lastClass = classObj;
  }
}

    function validate_required(field,alerttxt)
      {
      with (field)
      {
        if (value==null||value=="")
        {
        alert(alerttxt);return false;
        }
        else
        {
        return true;
        }
      }
      }

    function validate_form(thisform)
      {
        with (thisform)
        {

        if (validate_required(comment,"A comment is required")==false)
            {comment.focus();return false;}
      //  if (captcha.value != captcha2.value)
       //     {alert('Enter the correct text' + captcha.value + captcha2.value);return false;}
            else {return true;}

        }
      }


