function checkEnter(event, elem)
{ 	
	var code = 0;
	code = event.keyCode;
	if (code==13)
		chkSearchSubmit(elem);
}


function chkSearch(elem){
var str = elem.value
var fieldName = elem.name;

switch (fieldName) 
{ 
   case "siteSearch" : 
      var defaultText = "SITE SEARCH";
      break; 
   case "sectionSearch" : 
      var defaultText = "SECTION SEARCH";
      break; 
   default : 
      var defaultText = "SITE SEARCH";
      break; 
} 

if (elem.value.length == 0){
   elem.value = defaultText;
}

if (str == defaultText){
   elem.value='';
   elem.focus();
}

}

function chkSearchSubmit(elem){
var i;
i = document.forms[0].elements[elem];

switch (elem) 
{ 
   case "siteSearch" : 
      var defaultText = "SITE SEARCH";
      break; 
   case "sectionSearch" : 
      var defaultText = "SECTION SEARCH";
      document.forms[0].searchField.value = 2;
      break; 
   default : 
      var defaultText = "SITE SEARCH";
      break; 
} 

if (i.value == defaultText){
   alert('Please enter your search criteria');
   i.focus();
   return false;
}

document.forms[0].submit();

return true

}

function bookmarkRefresh() {
	displayResults();
	document.getElementById('divWinText0').innerHTML = cn2;
}


function AddItemAndFlyIcon(URL, Desc, RelativeXPos, RelativeYPos, mSec)
{
	addBriefcaseEntry(URL, Desc);
	MoveTo('briefcaseEntry', RelativeXPos, RelativeYPos, mSec);
}

function clearBriefcase()
{
	deleteCookie("briefcase");
	bookmarkRefresh();
}

function addBriefcaseEntry(URL, Desc)
{
	var theCookie = getCookie("briefcase");
	var theCookieValue = "";
	
	// is there any value currently?
	if (theCookie == null)
		{
		;
		// do nothing to prep it, as the default blank string will do nicely
		}
	else
		{
		theCookieValue = theCookie;
		}
		
	// set up the new value to append...
	var theNewCookieValue = escape(URL) + "{xxx}" + escape(Desc);
	
	// add it on...
	if (theCookieValue == "")
		theCookieValue = theNewCookieValue;
	else
		theCookieValue = theCookieValue + "|" + theNewCookieValue;
		
	// save it for later...
	var exp = new Date()
	var oneYearFromNow = exp.getTime() + (365 * 24 * 60 * 60 * 1000)
	exp.setTime(oneYearFromNow)
	setCookie("briefcase", theCookieValue, exp);
	bookmarkRefresh();
}

function getAllEntryURLs()
{
	// return a string array of the URLs in the list...
	var theCookie = getCookie("briefcase");
	var theURLArray = new Array();
	
	if (theCookie == null)
		{
		return null;
		}
	else
		{
		// clean it up
		theCookie = unescape(theCookie);

		// break it into a string array of the entries...
		var Sets = theCookie.split("|");
		var iLoop;
		for (iLoop=0;iLoop<Sets.length;iLoop++)
			{
			// pull out the URL part...
			var theParts = Sets[iLoop].split("{xxx}");
			theURLArray.push(theParts[0]);
			}
		}
	return theURLArray;
}

function getAllEntryDescriptions()
{
	// return a string array of the Descriptions in the list...
	var theCookie = getCookie("briefcase");
	var theDescArray = new Array();
	
	if (theCookie == null)
		{
		return null;
		}
	else
		{
		// clean it up
		theCookie = unescape(theCookie);

		// break it into a string array of the entries...
		var Sets = theCookie.split("|");
		var iLoop;
		for (iLoop=0;iLoop<Sets.length;iLoop++)
			{
			// pull out the description part...
			var theParts = Sets[iLoop].split("{xxx}");
			theDescArray.push(theParts[1]);
			}
		}
	return theDescArray;
}

function BriefcaseHasEntries()
{
	var theCookie = getCookie("briefcase");
	if (theCookie == null)
		return false;
	else
		return true;
}

function dumpURLs()
{
	var theURLs = getAllEntryURLs();
	var iLoop;
	if (theURLs == null)
		{
		alert("No URLs exist.");
		}
	else
		{
		for (iLoop=0;iLoop<theURLs.length;iLoop++)
			{
			alert(theURLs[iLoop]);
			}
		}
}

function dumpDescriptions()
{
	var theDescriptions = getAllEntryDescriptions();
	if (theDescriptions == null)
		{
		alert("No Descriptions exist.");		
		}
	else
		{
		for (iLoop=0;iLoop<theDescriptions.length;iLoop++)
			{
			alert(theDescriptions[iLoop]);
			}
		}
}


// utility functions for cookies

function setCookie(name, value, expires, path, domain, secure) 
{
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function getCookie(name)
{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);

	if (begin == -1)
		{
		begin = dc.indexOf(prefix);
		if (begin != 0)
			return null;
		} 
	else
		begin += 2;

	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;

	return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain)
{
	if (getCookie(name)) 
		{
		document.cookie = name + "=" + 
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
		}
}

// DHTML functions
function SetPos(e,iX,iY) {
  LeftPos(e,iX);
  TopPos(e,iY);
}

//function MoveTo(e,x,y,initx,inity,uTime) 
function MoveTo(e,x,y,uTime) 
{
	if (!(e=safeGetElementById(e))) 
		return;
	if (!e.timeout) 
		e.timeout = 25;
	e.xTarget = x; 
	e.yTarget = y; 
	e.slideTime = uTime; 
	e.stop = false;
	//e.yA = e.yTarget - TopPos(e); 
	//e.xA = e.xTarget - LeftPos(e); // A = distance
	//e.yA = e.yTarget - inity; 
	//e.xA = e.xTarget - initx; // A = distance
	e.yA = e.yTarget; 
	e.xA = e.xTarget; // A = distance
	e.B = Math.PI / (2 * e.slideTime); // B = period
	//e.yD = TopPos(e); 
	//e.xD = LeftPos(e); // D = initial position
	e.yD = 0; 
	e.xD = 0; // D = initial position
	var d = new Date(); 
	e.C = d.getTime();
	if (!e.moving) 
		{
		Move(e);
		}
}

function Move(e) 
{
	if (!(e=safeGetElementById(e))) 
		return;
	var now, s, t, newY, newX;
	now = new Date();
	t = now.getTime() - e.C;
	if (e.stop) 
		{
		e.moving = false;
		}
	else if (t < e.slideTime)
		{
		setTimeout("Move('"+e.id+"')", e.timeout);
		s = Math.sin(e.B * t);
		newX = Math.round(e.xA * s + e.xD);
		newY = Math.round(e.yA * s + e.yD);
		SetPos(e, newX, newY);
		e.moving = true;
		}  
	else 
		{
		SetPos(e, e.xTarget, e.yTarget);
		HideElement(e);
		e.moving = false;
		}  
}

// basic position functions, trying to be as browser compatible as possible...
function LeftPos(e,iX) 
	{
	if(!(e=safeGetElementById(e))) 
		{
		return 0;
		}
	var css=IsBrowserDefined(e.style);
	if (css && IsBrowserStringProperty(e.style.left)) 
		{
		if(IsBrowserNumericProperty(iX))
			{
			e.style.left=iX+'px';
			}
		else
			{
			iX=parseInt(e.style.left);
			if(isNaN(iX))
				{
				iX=0;
				}
			}
		}
	else if (css && IsBrowserDefined(e.style.pixelLeft))
		{
		if(IsBrowserNumericProperty(iX))
			{
			e.style.pixelLeft=iX;
			}
		else 
			{
			iX=e.style.pixelLeft;
			}
		}
	return iX;
}

function TopPos(e,iY) 
{
	if(!(e=safeGetElementById(e)))
		return 0;
	var css=IsBrowserDefined(e.style);
	if(css && IsBrowserStringProperty(e.style.top))
		{
		if(IsBrowserNumericProperty(iY))
			e.style.top=iY+'px';
		else 
			{
			iY=parseInt(e.style.top);
			if(isNaN(iY))
				iY=0;
			}
		}
	else if (css && IsBrowserDefined(e.style.pixelTop))
		{
		if(IsBrowserNumericProperty(iY))
			e.style.pixelTop=iY;
		else
			iY=e.style.pixelTop;
		}
	return iY;
}

function HideElement(e) 
{
	if(!(e=safeGetElementById(e))) 
		return;
	if(e.style && IsBrowserDefined(e.style.visibility)) 
		e.style.visibility='hidden';
}

function IsBrowserDefined() 
{
	for(var i=0; i<arguments.length; ++i)
		{
		if(typeof(arguments[i])=='undefined') 
			return false;
		}
	return true;
}

function IsBrowserStringProperty(s) 
{
	return typeof(s)=='string';
}

function IsBrowserNumericProperty(n)
{
	return typeof(n)=='number';
}

function safeGetElementById(e) 
{
	if(typeof(e)!='string') 
		return e;
	if(document.getElementById)
		e=document.getElementById(e);
	else if(document.all) 
		e=document.all[e];
	else 
		e=null;
	return e;
}
