function toggleLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}

function popUp(URL,WIDTH,HEIGHT) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=" + WIDTH + ",height=" + HEIGHT + "');");
}

function successNotification(ID) {
	new Effect.Highlight(ID, {duration: 3, startcolor: '#ffff99', endcolor: '#e7fbe7', restorecolor: '#e7fbe7'});
}
function failureNotification(ID) {
	new Effect.Highlight(ID, {duration: 3, startcolor: '#ff0000', endcolor: '#cc0000', restorecolor: '#cc0000'});
}

// used for the 'X Close' button on Add/Edit story success
function slideClosed(ID) {
	new Effect.toggle(ID,'appear');
}

// used for the 'What does this page do?' tabs
function tabSlide(ID) {
	new Effect.toggle(ID,'slide');
}

// This is used for content swapping. Originally setup by Matt C.
function displayBlocks() {
  allNodes = document.getElementsByClassName("cp_ajax");
  for(i = 0; i < allNodes.length; i++) {
      var url = allNodes[i].href;
      allNodes[i].style.display = 'none';
      var myAjax = new Ajax.Request (url,{method: 'get', onComplete: showResponse});
  }
}
function showResponse(originalRequest) {
  for(i = 0; i < allNodes.length; i++) {
    $(allNodes[i].title).innerHTML = originalRequest.responseText;
  }
}

// Grabs html for tooltips.
function getTooltipText(id) {
	lasttooltipevent = 'mouseover';
		var tooltipLocation = '/other/tooltips/?q=' + id;
		//var tooltipLocation = 'media/sample.xml';
			xmlhttp.open("GET",tooltipLocation,true);
			xmlhttp.onreadystatechange=function()	{
													 if (xmlhttp.readyState==4) {
													 	if (lasttooltipevent=='mouseover') {
														  	var response = xmlhttp.responseText;
															overlib(response, STICKY, CAPTION,'just ignore this but keep it',CLOSECLICK, ABOVE, RIGHT, OFFSETY, -15, OFFSETX, 19);
														}
													 }
													}
		xmlhttp.send(null);
}

var lasttooltipevent = '';
/*
 We remember the last tool tip event (Mouseout, mouseover) when deciding to open the bubble info.
*/
function closeToolTip(id) {
	lasttooltipevent = 'mouseout';
	cClick();
}

// Create Ajax Popup Login Box
function popup(url,ie5url,width,height) {
  // if a "closeable" boolean is passed, track it. It is the 4th item on the index of arguments.
  if (arguments.length == 5) {
   closeable = arguments[4];
  } else {
   closeable = 0;
  }
  if (closeable == 1) {
	url = url + '&closeable=1';
  }
  if ((navigator.userAgent.indexOf("MSIE")!=-1) && (navigator.userAgent.indexOf("Mac")!=-1)) {
    document.location.href = ie5url;   
  } else {
    var win = new Dialog.alert({url: url, options: {method: 'get'}}, {windowParameters: {className: "popup", width: width, height: height, zindex: 1500}, okLabel: "x", buttonClass: "hideClose"});
    // To prevent ugliness, we hide all object tags (flash movies)
    document.getElementsByTagName("object").className = "hide";
    document.getElementsByTagName("embed").className = "hide";
  }
}

// Create Ajax Popup Login Box
function popup_new(url,ie5url,width,height) {

  // if a "closeable" boolean is passed, track it. It is the 4th item on the index of arguments.
  if (arguments.length == 5) {
	  closeable = arguments[4];
  } 
  else {
	  closeable = 0;
  }
  if (closeable == 1) {
	  url = url + '&closeable=1';
  }

  if ((navigator.userAgent.indexOf("MSIE")!=-1) && (navigator.userAgent.indexOf("Mac")!=-1)) {
    document.location.href = ie5url;   
  } 
  else {
	// Windows with an URL as content
	// We want this to not be resizable or draggable so we set those to false
	// The dialog2 is the name of the class prefix for use in the style sheets
	// Title sets the title of the window (this can be blank for the login window)
	win2 = new Window('regdialog2', {
								  bottom:0, left:0, width:width, height:height, 
								  resizable: false, closable: closeable, minimizable: false, maximizable: false, draggable: false, 
								  url: url, showEffectOptions: {duration:0}, hideEffectOptions: {duration:0}})
	win2.setDestroyOnClose();
	// We now set the window to show center and set modal to true
	win2.showCenter(true);
  }
}


function getCurrentDateTime(theFormat){
	//
	// returns a nice date/time string for the current timestamp, depending on what format you request
	// INPUT:	date format - REQUIREd
	// 			formats:
	//				1 - US short date (mm/dd/yyyy):		01/01/2006
	//				2 - long date: 						Monday, January 1, 2006
	//				3 - long date and time (12-hour): 	Monday, January 1, 2006 9:00 AM
	//				4 - time (12-hour): 				9:00 AM
	// OUTPUT:	formatted date/time string
	//PRECONDITIONS: 
	//			blah
	//POSTCONDITIONS: 
	//			blah blah
	//NOTES/CAVEATS/WARNINGS:
	//			This function works with a local time string (not GMT/UTC)
	//
	var theReturnVal = "";
	var today = new Date();
	
	var arDays = new Array('Sunday','Monday','Tuesday','Wednesday',
	'Thursday','Friday','Saturday');

	var arFullMonths = new Array('January','February','March','April',
	'May','June','July','August','September','October','November','December');

	var Year = today.getFullYear();
	var Month = leadingZero(today.getMonth()+1);
	var DayName = arDays[today.getDay()];
	var MonthFullName = arFullMonths[today.getDay()];
	var Day = today.getDate();
	var DayLeading = leadingZero(today.getDate());
	var Hours = today.getHours();
	var ampm = "AM";
	
	if (Hours == 0) Hours = 12;
	if (Hours > 11)
		ampm = "PM";
	if (Hours > 12)
		Hours -= 12;
	var HoursLeading = leadingZero(Hours);
	var Minutes = leadingZero(today.getMinutes());
	var Seconds = leadingZero(today.getSeconds());

	switch(theFormat){
		case 1:
			theReturnVal = Month + '/' + Day + '/' + Year;
			break;

		case 2:
			theReturnVal = DayName + ', ' + MonthFullName + ' ' + Day + ', ' + Year;
			break;

		case 3:
			theReturnVal = DayName + ', ' + MonthFullName + ' ' + Day + ', ' + Year + ' ' + Hours + ':' + Minutes + ' ' + ampm;
			break;

		case 4:
			theReturnVal = Hours + ':' + Minutes + ' ' + ampm;
			break;

		default:
			theReturnVal = Month + '/' + Day + '/' + Year;
	}

	return theReturnVal;
}

function leadingZero(nr)
{
	if (nr < 10){ 
		nr = "0" + nr;
	}
	return nr;
}

