var helpPopup = window.createPopup();

function showHelp(helpID) {
    divHelp = document.getElementById(helpID);
    
    var helpPopBody = helpPopup.document.body;
    helpPopBody.style.backgroundColor = 'lightyellow';
    helpPopBody.style.border = 'solid black 1px';
    helpPopBody.style.padding = '5px';
    helpPopBody.style.fontFamily = 'Arial';
    helpPopBody.style.fontSize = '12px';
    helpPopBody.innerHTML = divHelp.innerHTML;

    // this hidden popup is used to calculate the height
    helpPopup.show(0, 0, 300, 0);
    
    var realHeight = helpPopBody.scrollHeight;
    // Hides the dimension detector popup object.
    helpPopup.hide();

    // Shows the actual popup object with correct height.
    helpPopup.show(0, 20, 300, realHeight, event.srcElement);            
}

function hideHelp(helpID) {
    helpPopup.hide();
}

/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}


/*
=============================================================
IsDayLightSavingsInEffect() : Returns true if daylight savings is in effect
=============================================================
*/
function IsDayLightSavingsInEffect()
{
	function makeArray()    {
		this[0] = makeArray.arguments.length;
		for (i = 0; i<makeArray.arguments.length; i++)
		this[i+1] = makeArray.arguments[i];
	}

	var daysofmonth   = new makeArray( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	var daysofmonthLY = new makeArray( 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	function LeapYear(year) {
		if ((year/4)   != Math.floor(year/4))   return false;
		if ((year/100) != Math.floor(year/100)) return true;
		if ((year/400) != Math.floor(year/400)) return false;
		return true;
	}

	function NthDay(nth,weekday,month,year) {
		if (nth > 0) return (nth-1)*7 + 1 + (7 + weekday - DayOfWeek((nth-1)*7 + 1,month,year))%7;
		if (LeapYear(year)) var days = daysofmonthLY[month];
		else                var days = daysofmonth[month];
		return days - (DayOfWeek(days,month,year) - weekday + 7)%7;
	}

	function DayOfWeek(day,month,year) {
		var a = Math.floor((14 - month)/12);
		var y = year - a;
		var m = month + 12*a - 2;
		var d = (day + y + Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400) + Math.floor((31*m)/12)) % 7;
		return d+1;
	}

	function y2k(number)    { return (number < 1000) ? number + 1900 : number; }

	var today = new Date();
	var year = y2k(today.getYear());

	var DSTstart = new Date(year,4-1,NthDay(1,1,4,year),2,0,0);
	var DSTend   = new Date(year,10-1,NthDay(-1,1,10,year),2,0,0);

	function getMS(date) {
		return Date.UTC(y2k(date.getYear()),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds())
	}

	var todayMS = getMS(today);
	var DSTstartMS = getMS(DSTstart);
	var DSTendMS = getMS(DSTend);

	if (todayMS > DSTstartMS && todayMS < DSTendMS)
		return true;
	else
		return false;
}

/*
=============================================================
IsDayLightSavingsInEffect() : Takes a UTC time in the format ("HH,MM,SS") and converts it to a string in the client format
=============================================================
*/
 
function convertServerUTCToLocaleTime(serverUTCTime)
{
	var times = serverUTCTime.split(",");
	var hour = parseInt(times[0], 10) + (IsDayLightSavingsInEffect() ? 1 : 0);
	var minute = times[1];
		
	// make a 
	var aDate = new Date(99,0,0)
	aDate.setUTCHours(hour , minute, 0);
			
	var minutes = aDate.getMinutes() < 10 ? "0" + aDate.getMinutes() : aDate.getMinutes();
	return (aDate.getHours() > 12 ? aDate.getHours() - 12 : aDate.getHours()) + ":" + minutes + " " + (aDate.getHours() > 12 ? "PM" : "AM");
	
}

/*
=============================================================
Wait For Processing Fields / Functions
=============================================================
*/
var divWait = document.getElementById("divWaitForSearch");
var contentRect; // must be global since setTimeout can't pass parameters
var divWaitForProcessing;
	
function showWaitForProcessingDiv(contentElement, hideDropDowns, delayMilliseconds)
{
	if(hideDropDowns == null)
	{
		hideDropDowns = true; // default
	}
	
	if(delayMilliseconds == null)
	{
		delayMilliseconds = 50;
	}
	
	if(hideDropDowns)
	{
		// hide any dropdowns as they show through a div
		for(var i = 0; i < document.forms[0].elements.length; i++)
		{
			ctrl = document.forms[0].elements[i];
			if(ctrl.type == "select-one")
				ctrl.style.display = "none";
		}
	}
	
	divWaitForProcessing = document.getElementById("divWaitForSearch");
	if(!contentElement)
	{
		//firefox issue
		//contentElement = document.getElementById("contentPane").childNodes[0].rows[1].cells[0]; //default	
		contentElement = document.getElementById("contentPane").getElementsByTagName("table")[0].rows[1].cells[0]; //default
	}
	
	// clear contentPane's content to reduce it to default size if greater than screen
	for(var i = 0; i < contentElement.childNodes.length; i++)
	{
		try
		{
			contentElement.childNodes[i].style.display = 'none';
		} catch(e)
		{			
		}
	}
	
	window.scrollTo(0,0);
	
	//contentRect = contentElement.getBoundingClientRect();	
	contentRect = GetBounds(contentElement);
		
	setTimeout(positionDiv, delayMilliseconds); // wait 1.5 seconds before start displaying wait message
}

function positionDiv()
{	
	divWaitForProcessing.style.top = contentRect.top;
	divWaitForProcessing.style.left = contentRect.left;
	divWaitForProcessing.style.width = contentRect.right - contentRect.left - 5;
	divWaitForProcessing.style.height = contentRect.bottom - contentRect.top;
	divWaitForProcessing.style.display = 'block';	
	
	setInterval(increasePeriods, 1000);
}

function increasePeriods()
{
	var obj = document.getElementById("spanPeriods");
	obj.style.display = 'block';
	if (document.all)
	{//IE
		obj.innerText += ".";
		if(obj.innerText.length > 5) obj.innerText = "";
	}
	else
	{		
		if(navigator.userAgent.indexOf("Firefox")!=-1)
		{//firefox, obj.innerText and obj.text does NOT work
			if (!obj.innerHTML) obj.innerHTML="";			
			obj.innerHTML += ".";	
			if(obj.innerHTML.length > 5) obj.innerHTML = "";			
		}
	}
	
	/*
	document.getElementById("spanPeriods").innerText += ".";
	
	if(document.getElementById("spanPeriods").innerText.length > 5)
		document.getElementById("spanPeriods").innerText = "";
	*/
}

/* http://www.wischik.com/lu/programmer/getbounds.html */
function GetBounds(e)
{ 
  // firefox: it's offsetLeft/offsetTop model is broken for tables that
  // are inline or absolutely positioned with margins. But it
  // supports getBoxObjectFor, which works better:
  if (document.getBoxObjectFor)
  { // just one problem: it gives the wrong answer for the table element of inline tables,
    // but the right answer for TBODY in all circumstances:
    if (e.tagName=='TABLE')
    { for (var i=0; i<e.childNodes.length; i++)
      { if (e.childNodes[i].tagName=='TBODY') {e=e.childNodes[i]; break;}
      }
    }
    var r=document.getBoxObjectFor(e);
    return {'left':r.x, 'top':r.y, 'right':r.x+r.width, 'bottom':r.y+r.height};
  }
  
  // IE: it's offsetLeft/offsetTop model is correct except in the case
  // of the last text node in a container, But getBoundingClientRect
  // works and is faster:
  if (e.getBoundingClientRect)
  { var r=e.getBoundingClientRect();
    var wx=document.documentElement.scrollLeft, wy=document.documentElement.scrollTop;
    return {'left':r.left+wx, 'top':r.top+wy, 'right':r.right+wx, 'bottom':r.bottom+wy};
  }

  // Other browsers: we'll trust and pray that their offsetLeft/offsetTop model is correct
  var x=0, y=0, w=e.offsetWidth, h=e.offsetHeight;
  while (e!=null) {x+=e.offsetLeft; y+=e.offsetTop; e=e.offsetParent;}
  return {'left':x, 'top':y, 'right':x+w, 'bottom':y+h};
}
/*
=============================================================
E-mail validation
=============================================================
*/
function emailCheck (emailStr) //refer to http://javascript.internet.com/forms/email-address-validation.html
{
	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */

	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */

	var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */

	var emailPat = /^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/

	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */

	var quotedUser="(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */

	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */

	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/* Finally, let's start trying to figure out if the supplied address is valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {

	/* Too many/few @'s or something; basically, this address doesn't
	even fit the general mould of a valid e-mail address. */

	alert("Email address seems incorrect (check @ and .'s)");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).

	for (i=0; i<user.length; i++) 
	{
		if (user.charCodeAt(i)>127) 
		{
			alert("Ths username contains invalid characters.");
			return false;
		}
	}
	
	for (i=0; i<domain.length; i++) 
	{
		if (domain.charCodeAt(i)>127) 
		{
			alert("Ths domain name contains invalid characters.");
			return false;
		}
	}

	// See if "user" is valid 
	if (user.match(userPat)==null) 
	{
		// user is not valid
		alert("The username doesn't seem to be valid.");
		return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null)
	{
		// this is an IP address
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
				alert("Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}

	// Domain is symbolic name.  Check if it's valid.	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) 
	{
		if (domArr[i].search(atomPat)==-1) 
		{
			alert("The domain name does not seem to be valid.");
			return false;
		}
	}

	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) 
	{
		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) 
	{
		alert("This address is missing a hostname!");
		return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
}

function checkEmailAddress(email) //refer to http://www.codelifter.com/main/javascript/emailaddresschecker1.html
{
	// Note: The next expression must be all on one line...
	//       allow no spaces, linefeeds, or carriage returns!
	var goodEmail = email.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	//true or false
	return goodEmail;
}

/*
=============================================================
XmlHttp Functions
=============================================================
*/
function getXmlHttpRequest()
{
	var xmlHttp = false;
	
	try
	{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");			
	}
	catch(e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");				
		}
		catch(e2)
		{
			try
			{
				xmlhttp = new XMLHttpRequest();			
			}
			catch(e2)
			{
				xmlHttp = false;
			}
		}
	}
	
	return xmlHttp;
}

/*
=============================================================
CallCenter Functions
=============================================================
*/
var aDay	= new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var aMonth	= new Array("January","February","March","April","May","June","July","August","September","October","November","December")

function DateFormat(xdate,x)
{
	/*	
		Date Format function to be used in internally by the Showdate function.
		Returns either: d, dd, ddd, dddd, m, mm, mmm, mmmm, y, yy, yyy, yyyy.
		eg. Sun Sep 28 09:22:08 EDT 2003  returns  28, 28, Sun., Sunday, 9, 09, Sep., September, 03, 03, 03, 2003
			Sun Sep 28 09:22:08 EDT 2003 = 28 28 Sun. Sunday, 9 09 Sep. September, 03 03 03 2003   
	*/
	x = x.toLowerCase();
	return (((x == "d")  ? xdate.getDate() : ((x == "dd") ? ((xdate.getDate() <= 9) ? "0"+xdate.getDate() : xdate.getDate()) : ((x == "ddd") ? aDay[xdate.getDay()].substring(0,3)+". " : ((x == "dddd") ? aDay[xdate.getDay()]+", " : ((x == "m")  ? xdate.getMonth()+1 : ((x == "mm") ? (((xdate.getMonth()+1) <= 9) ? "0"+(xdate.getMonth()+1) : xdate.getMonth()+1) : ((x == "mmm") ? aMonth[xdate.getMonth()].substring(0,3) : ((x == "mmmm") ? aMonth[xdate.getMonth()] : ((x == "y" || x == "yy" || x == "yyy") ? xdate.getFullYear().toString().substring(2,4) : ((x == "yyyy") ? xdate.getFullYear().toString() : "")))))))))))
}


function showdate(_date, _var1, _var2, _var3, _var4, _del)
{
	// Content:	Date formatter where _month = month, _day = day of week spelled out, yyyy = four digit year. 
	// The script will only display a day spelled out if the parameter is ddd, or dddd. dd or d means do not display the day.
	//
	//	Syntax: document.writeln(Showdate(date object, "ddd", "mmm", "dd", "yyyy", "-"));
	//		where date can be a field variable = rs("Datecreated"); constant= new Date(yyyy,m,dd); 
	//
	//	Results in: Thursday, January-01-1970  NOTE that the numeric month in Javascript is from 0-11
	//
	// timerID=setInterval("if (_ie){++nd; if (nd > xStyle.length) nd=0; document.all.md.innerHTML=Showdate(null, "mmm", "ddd", "yy" , "-");}",3000)
	// timerOn=true
	// ----------------------------------------------------------------------------------------

	var today	= (_date == null) ? new Date() : new Date(_date);
	_del =  ((_del == null) ? " " : _del);
	return ( DateFormat(today, _var1) + DateFormat(today, _var2) + ((_var2 != "")? _del : "") + DateFormat(today, _var3) + ((_var3 != "")? _del : "") + DateFormat(today, _var4))
}

function date2String(date)
{
	return showdate(date, '', 'yyyy', 'mm', 'dd', '')
}

function string2Date(s)
{
	var year,month,date;
	y = s.substr(0,4);
	m = s.substr(4,2)-1;
	d = s.substr(6,2);
	var mydate = new Date(y,m,d);
	return mydate;
}

/*
=============================================================
Ajax Functions
=============================================================
*/
var Ajax_RequestUrl = "AjaxHandler.aspx?q=";
function Ajax_Get(q)
{ 
    if (q.length > 0)
    {
        //Append the name to search for to the requestURL
        var url = Ajax_RequestUrl + q;
        
        Ajax_ResultString = null;//init before each call
        
        //Create the xmlHttp object to use in the request
        //stateChangeHandler will fire when the state has changed, i.e. data is received back
        //This is non-blocking (asynchronous)
        xmlHttp = Ajax_GetXmlHttpObject(Ajax_StateChangeHandler);
        
        if (xmlHttp != null)
        {
			//Send the xmlHttp get to the specified url
			Ajax_XmlHttpGet(url);
        }
    }
}

//scoped
var xmlHttp;     
var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0; 
var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0; 
var is_opera = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0; 
//netscape, safari, mozilla behave the same??? 
var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0;

// XMLHttp send GET request 
function Ajax_XmlHttpGet(url) 
{ 
    xmlHttp.open('GET', url, true); 
    xmlHttp.send(null); 
}

function Ajax_GetXmlHttpObject(handler) //returns null if error and alert
{
	var objXmlHttp = null;    //Holds the local xmlHTTP object instance

	//Depending on the browser, try to create the xmlHttp object 
	if (is_ie)
	{
		//The object to create depends on version of IE 
		//If it isn't ie5, then default to the Msxml2.XMLHTTP object 
		var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP'; 
	        
		//Attempt to create the object 
		try
		{ 
			objXmlHttp = new ActiveXObject(strObjName); 
			objXmlHttp.onreadystatechange = handler; 
		} 
		catch(e)
		{ 
			//Object creation errored 
			alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled'); 				
		} 
	} 
	else if (is_opera)
	{ 
		//Opera has some issues with xmlHttp object functionality 
		alert('Opera detected. The page may not behave as expected.');
	} 
	else
	{
		// Mozilla | Netscape | Safari 
		objXmlHttp = new XMLHttpRequest();
		objXmlHttp.onload = handler;
		objXmlHttp.onerror = handler;
	}
	
	//Return the instantiated object
	return objXmlHttp;
}

//stateChangeHandler will fire when the state has changed, i.e. data is received back 
//this is non-blocking (asynchronous) 
function Ajax_StateChangeHandler() 
{
    //readyState of 4 or 'complete' represents that data has been returned 
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
    {
		if (xmlHttp.status == 200)
		{
			//Gather the results from the callback
			var result = xmlHttp.responseText;
			
			//check if 'result' variable starting with "ERROR" string.
			var iPos = result.indexOf("ERROR");
			if (iPos == 0)
			{				
				//actual error message should be globalized in the server side
				var message = result.substr(5, result.length-5);
				alert(message);
				handleAjaxResult(null);
			}
			else
			{
				handleAjaxResult(result);
			}
        }
        else
        {
			alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
        }
        
        xmlHttp = null;        
    } 
}

function getCookie(NameOfCookie)
{

	// First we check to see if there is a cookie stored.
	// Otherwise the length of document.cookie would be zero.
	if (document.cookie.length > 0) 
	{ 
		// Second we check to see if the cookie's name is stored in the
		// "document.cookie" object for the page.

		// Since more than one cookie can be set on a
		// single page it is possible that our cookie
		// is not present, even though the "document.cookie" object
		// is not just an empty text.
		// If our cookie name is not present the value -1 is stored
		// in the variable called "begin".

		begin = document.cookie.indexOf(NameOfCookie+"="); 
		if (begin != -1) // Note: != means "is not equal to"
		{
			// Our cookie was set. 
			// The value stored in the cookie is returned from the function.

			begin += NameOfCookie.length+1; 
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end)); 
		} 
	}
	
	return null;

	// Our cookie was not set. 
	// The value "null" is returned from the function.
}

function hello(){alert("Hello");}

function setCookie(NameOfCookie, value, expiredays) 
{
	// Three variables are used to set the new cookie. 
	// The name of the cookie, the value to be stored,
	// and finally the number of days until the cookie expires.
	// The first lines in the function convert 
	// the number of days to a valid date.

	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

	// The next line stores the cookie, simply by assigning 
	// the values to the "document.cookie" object.
	// Note the date is converted to Greenwich Mean time using
	// the "toGMTstring()" function.

	document.cookie = NameOfCookie + "=" + escape(value) + 
	((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function delCookie (NameOfCookie) 
{
	// The function simply checks to see if the cookie is set.
	// If so, the expiration date is set to Jan. 1st 1970.

	if (getCookie(NameOfCookie))
	{
		document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
} 
//work with PageStyle.css (divShow, divHide)
function toggleDiv(elem)
{
	var ndDiv = document.getElementsByTagName('div'); // handle divs			 
	var	ndTr=document.getElementsByTagName('tr'); // handle tr's		

	for(var i=0;i<ndDiv.length;i++)
	{		
		if(ndDiv[i].className == 'divHide' && ndDiv[i].getAttribute(elem)=='yes' )
		{
			ndDiv[i].className = 'divShow';		
		}
		else if(ndDiv[i].className=='divShow' && ndDiv[i].getAttribute(elem)=='yes')
		{
			ndDiv[i].className = 'divHide'				
		}
	}

	for( i=0;i<ndTr.length;i++)
	{		
		if(ndTr[i].className == 'divHide' && ndTr[i].getAttribute(elem)=='yes' )
		{
			ndTr[i].className = 'divShow';		
		}
		else if(ndTr[i].className=='divShow' && ndTr[i].getAttribute(elem)=='yes')
		{
			ndTr[i].className = 'divHide'				
		}
	}
}

function showHideDiv(elem, visible)
{
	var o = document.getElementById(elem);
	if (o && o.getAttribute(elem)=='yes')
	{
		if (visible)
		{
			o.className="divShow";
		}
		else
		{
			o.className="divHide";
		}
	}
}
//elem id, image, src string, src string
function toggleSection(elem, oImg, toExpandSrc, toCollapseSrc)
{
	var o = document.getElementById(elem);
	if (o && o.getAttribute(elem)=='yes')
	{
		if (o.className=="divHide")
		{
			o.className="divShow";
			oImg.src=toCollapseSrc;
		}
		else
		{
			o.className="divHide";
			oImg.src=toExpandSrc;
		}
	}
}
//elem id string, image id string, src string, src string
function toggleSection2(elem, img, toExpandSrc, toCollapseSrc)
{
	var o = document.getElementById(elem);
	var oImg = document.getElementById(img);
	if (o && oImg && o.getAttribute(elem)=='yes')
	{
		if (o.className=="divHide")
		{
			o.className="divShow";
			oImg.src=toCollapseSrc;
		}
		else
		{
			o.className="divHide";
			oImg.src=toExpandSrc;
		}
	}
}
//id: CheckBoxList.ClientID
//checked: true or false
function setCheckBoxList(id,checked)
{
	var oTable = document.getElementById(id);
	if (oTable)
	{
		var elems = oTable.getElementsByTagName("input");
		for (var i=0;i!=elems.length;++i)
		{
			if (elems[i].getAttribute("type")=="checkbox")
			{
				elems[i].checked = checked;
			}
		}
	}
}

////////////////////////////////////////
var browserType;

if (document.layers) {browserType = "nn4"}
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {
   browserType= "gecko"
}
//keeps the element in the layout but does not show the content. 
function hideDiv(div) {
  if (browserType == "gecko" )
     document.poppedLayer = 
         eval('document.getElementById("' + div + '")');
  else if (browserType == "ie")
     document.poppedLayer = 
        eval('document.getElementById("' + div + '")');
  else
     document.poppedLayer =   
        eval('document.layers["' + div + '"]');
  document.poppedLayer.style.visibility = "hidden";
}

function showDiv(div) {
  if (browserType == "gecko" )
     document.poppedLayer = 
         eval('document.getElementById("' + div + '")');
  else if (browserType == "ie")
     document.poppedLayer = 
        eval('document.getElementById("' + div + '")');
  else
     document.poppedLayer = 
         eval('document.layers["' + div + '"]');
  document.poppedLayer.style.visibility = "visible";
}
//actually remove the element
function hideDiv2(div) {
  if (browserType == "gecko" )
     document.poppedLayer = 
         eval('document.getElementById("' + div + '")');
  else if (browserType == "ie")
     document.poppedLayer = 
        eval('document.getElementById("' + div + '")');
  else
     document.poppedLayer =   
        eval('document.layers["' + div + '"]');
  document.poppedLayer.style.display = "none";
}

function showDiv2(div) {
  if (browserType == "gecko" )
     document.poppedLayer = 
         eval('document.getElementById("' + div + '")');
  else if (browserType == "ie")
     document.poppedLayer = 
        eval('document.getElementById("' + div + '")');
  else
     document.poppedLayer = 
         eval('document.layers["' + div + '"]');
  document.poppedLayer.style.display = "inline";
}
////////////////////////////////////////

function printDiv(divId)
{
	var divToPrint=document.getElementById(divId); 
	var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
	var strOldOne = divToPrint.innerHTML;
	WinPrint.document.write(divToPrint.innerHTML);
	WinPrint.document.close();
	WinPrint.focus();
	WinPrint.print();
	WinPrint.close();
	divToPrint.innerHTML=strOldOne;
}
