// Trim whitespace from left and right sides of a String.
function trim(s)
{
    return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}

/* Set anchor's target - use since target attribute is not valid in XHTML strict, but is
 * still a valid property (in DOM 2.0 as well) of the anchor object.
 * Example use:
    <a id="foo" href="sompage.html" onmouseover="setTarget('foo', '_blank');">Link Name</a>
 */
function setTarget(anchorID, target)
{
       var anchorDOM = findDOM(anchorID, false);
       anchorDOM.target = target;
}


function changeStyleClass(id, newStyleClass)
{
    var dom = findDOM(id, false);
    if (dom != null)
    {
        dom.className = newStyleClass;
    }
}


function longDateTime()
{
	var months = new Array("January","February","March","April","May","June","July","August","September","October","Novemeber","Decemeber");
	var days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var now = new Date();
	var day = days[now.getDay()];
	var dateNow = now.getDate();
	var month = months[now.getMonth()];
	var year = now.getFullYear();

	var hour = now.getHours();
	var minutes = now.getMinutes();
	if ( minutes < 10 ) {minutes = "0" + minutes;}
	var seconds = now.getSeconds();
	if ( seconds < 10 ) {seconds = "0" + seconds;}

	return (day + " " + dateNow + " " + month + " " + year + " at " + hour + ":" + minutes + ":" + seconds);
}

function shortDateTime()
{
	var months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec");
	var days = new Array("Sun","Mon","Tues","Wed","Thur","Fri","Sat");
	var now = new Date();
	var day = days[now.getDay()];
	var dateNow = now.getDate();
	var month = months[now.getMonth()];
	var year = now.getFullYear();

	var hour = now.getHours();
	var minutes = now.getMinutes();
	if ( minutes < 10 ) {minutes = "0" + minutes;}
	var seconds = now.getSeconds();
	if ( seconds < 10 ) {seconds = "0" + seconds;}

	return (day + " " + dateNow + " " + month + " " + year + " at " + hour + ":" + minutes + ":" + seconds);
}


function theYear()
{
	var now = new Date();
	return now.getFullYear();
}

function gotoURL(theURL)
{
	window.location.href = theURL;
}

function show(object)
{
	if (document.layers && document.layers[object] != null)
	    document.layers[object].visibility = 'visible';
	else if (document.all)
	    document.all[object].style.visibility = 'visible';
}
function hide(object)
{
	if (document.layers && document.layers[object] != null)
	    document.layers[object].visibility = 'hidden';
	else if (document.all)
	    document.all[object].style.visibility = 'hidden';
}

function readCookie(name)
{
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

//Set a cookie with the provided info.
// if monthsUntilCookieExpires is null or passed an empty string (i.e. "") - a session cookie is created.
//   otherwise pass a date in GMT format (via the Date.toGMTString() function)
//cookiePath is optional and can simply be an emtpy string ("") which would set the cookie at the
//   domain level
function setCookie(cookieName, cookieValue, monthsUntilCookieExpires, cookiePath)
{
    cookieValue = escape(cookieValue);
    var expires = "";
    if (monthsUntilCookieExpires || !(monthsUntilCookieExpires == ""))
    {
        var cookieExpires = new Date();
        cookieExpires.setMonth(cookieExpires.getMonth() + monthsUntilCookieExpires);
        cookieExpires = cookieExpires.toGMTString();
        expires = "; expires="+cookieExpires;
    }
    if (cookiePath != "")
    {
        cookiePath = "; path=" + cookiePath;
    }
    document.cookie = cookieName + "=" + cookieValue + expires + cookiePath;
  }
//Saves a form field's value as a cookie.
//   fieldID: the html ID attribute of the field to save
//   cookieName: the name of the cookie field value should be saved as. If empty ("") or null, the field's ID will be used.
//   months: number of months until cookie expires. If empty ("") or null, will default to 12 months.
function saveFormFieldValueInCookie(fieldID, cookieName, months)
{
    var fieldDOM = findDOM(fieldID, false);
    var cookieValue = fieldDOM.value;

    if (cookieValue != null && cookieValue != "")
    {
        if (cookieName == null || cookieName == "")
        {
            cookieName = fieldID;
        }
        if (months == null || months == "")
        {
            months = 12;
        }
        setCookie(cookieName, cookieValue, 12, "");
    }
}

var announcementBoxID;
// Blinking announcemnt Box Code
function announcementBlink(announcementID)
{
    announcementBoxID = announcementID;
    setInterval("blinkTheBox()", 1000);
}

function blinkTheBox()
{
    changeStyleClass(announcementBoxID, 'announcementBoxOff');
    setTimeout('turnBoxBackOn();', 400);
}

function turnBoxBackOn()
{
    changeStyleClass(announcementBoxID, 'announcementBox');
}

