function URLEncode(plaintext)
{
    // The Javascript escape and unescape functions do not correspond
    // with what browsers actually do
    var SAFECHARS = "0123456789" +                    // Numeric
                    "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +    // Alphabetic
                    "abcdefghijklmnopqrstuvwxyz" +
                    "-_.!~*'()";                    // RFC2396 Mark characters
    var HEX = "0123456789ABCDEF";

    var encoded = "";
    for (var i = 0; i < plaintext.length; i++ ) {
        var ch = plaintext.charAt(i);
        if (ch == " ") {
            encoded += "+";                // x-www-urlencoded, rather than %20
        } else if (SAFECHARS.indexOf(ch) != -1) {
            encoded += ch;
        } else {
            var charCode = ch.charCodeAt(0);
            if (charCode > 255) {
                alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
                          "(URL encoding only supports 8-bit characters.)\n" +
                          "A space (+) will be substituted." );
                encoded += "+";
            } else {
                encoded += "%";
                encoded += HEX.charAt((charCode >> 4) & 0xF);
                encoded += HEX.charAt(charCode & 0xF);
            }
        }
    }

    return encoded;
};
function saveCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000))
		var expires = "; expires="+date.toGMTString()
	}
	else expires = ""
	document.cookie = name+"="+value+expires+"; path=/"
}

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
}

function deleteCookie(name) {
	saveCookie(name,"",-1)
}

//deleteCookie("atFontSize");

fontSize = 1;
fontSizeMin = 1;
fontSizeMax = 1.5;
fontSizeStep = .1;


function setFontSize() {
	savedFontSize = readCookie("atFontSize");
	if (savedFontSize != null) {
		fontSize = parseFloat(savedFontSize);
		if (fontSize < fontSizeMin) {
			fontSize = fontSizeMin;
		} else if (fontSize > fontSizeMax) {
			fontSize = fontSizeMax;
		}
	}
	document.getElementById('maincol').style.fontSize = fontSize+'em';

	checkBodyHeight();
}

function changeFontSize(dir) {
	if (dir=='increase') {
		if (fontSize <= (fontSizeMax - fontSizeStep)) {
			fontSize = parseInt((fontSize * 10) + (fontSizeStep * 10)) / 10;
		}
	} else {
		if (fontSize >= (fontSizeMin + fontSizeStep)) {
			fontSize = parseInt((fontSize * 10) - (fontSizeStep * 10)) / 10;
		}
	}
	saveCookie("atFontSize", fontSize, 365);
	document.getElementById('maincol').style.fontSize = fontSize+'em';
	
	checkBodyHeight();
}			

function checkBodyHeight() {
	if (typeof document.body.style.maxHeight == "undefined") {
		var objLcX = document.getElementById('leftcol').offsetHeight;
		var objMcX = document.getElementById('maincol').offsetHeight;
		if (objMcX < objLcX) { document.getElementById('maincol').style.height = (objLcX+5)+'px'; }
	}
	document.getElementById('maincol').style.height = 'auto';
}


String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}




/* START JS Browser detect code */
var bow="n";
var bow1="n";

bName = navigator.appName;
bVer = parseInt(navigator.appVersion);

if (bName == "Netscape" && bVer >= 3)
{
	bow = "ok";
	bow1 = "ok";
}
else if (bName == "Microsoft Internet Explorer" && bVer > 3)
{
	bow = "ok";
	bow1="ok";
}
else if (bName == "Microsoft Internet Explorer" && bVer >=2)
{
	bow = "ok";
}

var IS_AOL=0;

if (navigator.userAgent)
{
	if (navigator.userAgent.indexOf("AOL") >=0)
	{
		IS_AOL=1;
		bow1="n";
	}
}
else
{
	bow="n"
	bow1="n";
}
/* END JS Browser detect code */

/* changeImage function modified to work with the open/close images on the schedule page */
function changeImage(row,s,sched)
{
	var h = (s==1)?"r":"";
	var row_src = (parseInt(sched)>=1)?'r'+sched:row;

	if(document.images) document.images[row].src = eval(h + row_src + ".src");
}

/* go to a page in the main window */
/*function openPageInMain(pageUrl){
	if(!window.opener || window.opener.closed){
		window.opener = window.open(pageUrl,'','');
		return false;
	}else{
		window.opener.document.location.href = pageUrl;
		window.opener.focus();
		return false;
	}
}
*/
function openPageInMain(pageUrl){
	if(window.opener){
		if(!window.opener.closed){
			window.opener.document.location.href = pageUrl;
			window.opener.focus();
			return false;
		}else{
			window.opener = window.open(pageUrl,'','');
			return false;
		}
	}else{
		window.opener = window.open(pageUrl,'','');
		return false;
	}
	return true;
}

/* general utility function that accepts parameters for url of filename (f),
target Window (t), 
menubar (m - yes/no), location (l - yes/no), 
scrollbars (s - yes/no), resizeable (r - yes/no), 
window width (w), window height (h). 
Default values are laid out in the function.

23/10: add directories and toolbar options (fred)*/
function openPrintWin(strLink,strWindowName)
{
	return openWindow(strLink,strWindowName,"yes","no","yes","yes",670,550,"yes","no","no");	
}

function openBBWin(strLink,strWindowName)
{
	return openWindow(strLink,strWindowName,"no","no","yes","yes",620, 450,"no","no","no");	
}

function openEmailWin(strLink,strWindowName)
{
	return openWindow(strLink,strWindowName,"no","no","yes","yes",620, 450,"no","no","no");	
}

function openPDFWin(strLink,strWindowName)
{
	return openWindow(strLink,strWindowName,"no","no","yes","yes",620, 450,"no","no","no");	
}

function openVideoWin(strLink,strWindowName, winWidth, winHeight)
{
	return openWindow(strLink,strWindowName,"no","no","yes","yes", winWidth, winHeight,"no","no","no");	
}

function openCalenderWin(strLink,strWindowName)
{
	return openWindow(strLink,strWindowName,"no","no","yes","yes",471, 450,"no","no","no");	
}

function openWebcastWin(strLink,strWindowName)
{
	return openWindow(strLink,strWindowName,"no","no","yes","yes",620, 450,"no","no","no");	
}

function openWindow(f, t, m, l, s, r, w, h, st, tool, d)
{
	var fn_filename = "";
	var fn_target = "_blank";
	var fn_menubar = "yes";
	var fn_location = "yes";
	var fn_scrollbars = "yes";
	var fn_resizable = "yes";
	var fn_width = "600";
	var fn_height = "400";
	var fn_status = "yes";
	var fn_toolbar = "yes";
	var fn_directories = "yes";
	
	if (arguments.length > 0)
	{
		if (f != "" || f != null) fn_filename = f;
		if (t != "" || t != null) fn_target = t;
		if (m == "no") fn_menubar = m;
		if (l == "no") fn_location = l;
		if (s == "no") fn_scrollbars = s;
		if (r == "no") fn_resizable = r;
		if (w > 0) fn_width = w;
		if (h > 0) fn_height = h;
		if (st == "no") fn_status = st;
		if (tool == "no") fn_toolbar = tool;
		if (d == "no") fn_directories = d;
	}
	
	self.name="mainWin";
	
    if (bow!="ok") return (true);
	
	argumentString = 'menubar='+fn_menubar+',location='+fn_location+',scrollbars='+fn_scrollbars+',resizable='+fn_resizable+',width='+fn_width+',height='+fn_height+',status='+fn_status+',toolbar='+fn_toolbar+',directories='+fn_directories;
	
	remote =  window.open(fn_filename,fn_target,argumentString);

    if (remote == null) return true;

    if(bow1 == "ok"){
		window.setTimeout('focusWin()',1000);
	}
	return (false);
}

function focusWin(){
	if(!remote.closed){
		remote.focus();
	}
}

/* short cut function for opening banner ad or external link windows 
uses the openWindow general utility which should be above */
function openLinkWin(fName,targetName,winWidth,winHeight)
{
    if (bow!="ok") return (true);

	var fn_fName = "";
	var fn_targetName = "_blank";
	var fn_winWidth = 620;
	var fn_winHeight = 400;

	if (arguments.length > 0)
	{
		if (fName != "" || fName != null) fn_fName = fName;
		if (targetName != "" || targetName != null) fn_targetName = targetName;
		if (winWidth > 0) fn_winWidth = winWidth;
		if (winHeight > 0) fn_winHeight = winHeight;
	}

	return openWindow(fn_fName,fn_targetName,'yes','yes','yes','yes',fn_winWidth,fn_winHeight,'yes','yes','yes')
}


//************************************************************************
// sets a cookie
function setCookie(sKey, sValue, sExpires, sDomain, sPath){
	sExpires = (sExpires != null) ? ';expires=' + sExpires : '';
	sDomain = (sDomain != null) ? ';domain=' + sDomain : '';
	sPath = (sPath != null) ? ';path=' + sPath : '';
	document.cookie = sKey + '=' + sValue + sExpires + sDomain + sPath;
	return true;
}

function isEmpty(inStr){
	if(trim(inStr).length == 0){
		return true;
	}else{
		return false;
	}
}

//************************************************************************
// trims a form element
function trim(tmpStr) 
{
  var atChar;
 
  if (tmpStr.length > 0) atChar = tmpStr.charAt(0);
  while (isSpace(atChar)) 
  {
    tmpStr = tmpStr.substring(1, tmpStr.length);
    atChar = tmpStr.charAt(0);
  }
  if (tmpStr.length > 0) atChar = tmpStr.charAt(tmpStr.length-1);
  while (isSpace(atChar)) 
  {
    tmpStr = tmpStr.substring(0,( tmpStr.length-1));
    atChar = tmpStr.charAt(tmpStr.length-1);
  }
//  alert("here'"+tmpStr+"'");
  return tmpStr;
}

function isSpace(inChar) 
{
  return (inChar == ' ' | inChar == '\t' || inChar == '\n');
}

function printPage(){
	if(window.print){
		window.print();
	}
}
function doSearchSubmit(oFormElement){
	if(trim(oFormElement.keywords.value).length == 0){
		alert('Please enter the text that you wish to search for.');
		oFormElement.keywords.value = '';
		return false;
	}else{
		return true;
	}
}

function doSubmitShareValueCalculator(objForm)
{
	var ErrorMessage = "";
	var strShares = trim(objForm.CalcNumberOfShares.value);
	if (strShares == "")
		ErrorMessage = ErrorMessage + "Please enter the number of shares.\n";
	else if (isNaN(strShares))
		ErrorMessage = ErrorMessage + "Please enter the number of shares as a numeric value.\n";
	else if (parseInt(strShares,10) < 0)
		ErrorMessage = ErrorMessage + "Please enter the number of shares as a numeric value greater than 0.\n";
				
	if (ErrorMessage != "")
	{
		alert(ErrorMessage);
		return false;
	} else {
		return true;
	}
}

//opens window without returning a value.
function openWindowNR(){
	window.open(arguments[0], arguments[1], arguments[2]);
}

/* tabbed table code*/
var img = new Array();
function preloadImages() {
	alert("jesuschrist");
	for (var i = 0; i < images.length; i++) {
		img[i] = new Object();
		img[i]["active"] = new Image();
		img[i]["active"].src = images[i]["active"];
		img[i]["inactive"] = new Image();
		img[i]["inactive"].src = images[i]["inactive"];
	}
}
function swapImages(makeActive) {
	for (var i = 0; i < img.length; i++) {
		document.getElementById('showhide_' + (i+1)).firstChild.src = img[i]["inactive"].src;
	}
	document.getElementById('showhide_' + makeActive).firstChild.src = img[makeActive-1]["active"].src;
}
function showHide(targetID) {
	foldDivs(targetID);
	document.getElementById('hide_' + targetID).style.display = '';
	swapImages(targetID);
}
function foldDivs(dontFold) {
	var els = document.getElementsByTagName("div");
	for (var i = 0; i < els.length; i++) {
		if (els[i].id.indexOf("hide_") > -1) {
			if (els[i].id != 'hide_' + dontFold) els[i].style.display = 'none';
		}
	}
}
/* end tabbed table code*/
var newwin;
function launchwin(winurl,winname,winfeatures) {
	newwin = window.open(winurl,winname,winfeatures);
}