//================================
//
//	GLOBAL SITE SETTINGS
//
//================================
	// 	-- server paths
	var gWWWPath = "http://www.linnaeafarm.org/"					// path to www folder
	var gWWWPathSecure = "https://id310.securedata.net/linnaeafarm/"		// secure path to www folder
 	var gCGIPath = "http://www.linnaeafarm.org/cgi-bin/";	    // cgi server path
 	var gCGIPathSecure = "https://id310.securedata.net/cgi-linnaeafarm/";	// secure cgi server path
	//	-- time arrays
	var aMonthsShort = new Array("Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec");
	var aMonths = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	var aDays = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
	var aDaysShort = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
	var msecOneDay = 86400000;
	var msecOneYear = 31536000000;
	//	-- defaults
	var gDefaultDaysBeforeNoticeExpires = 30;	
	//	-- email
	var gstrEmailSuffix = '@linnaeafarm.org';

	// 	-- base href tags
	function setBaseHref() 		 { document.writeln('<base href="'+gWWWPath+'">'); }
	function setBaseHrefSecure() { document.writeln('<base href="'+gWWWPathSecure+'">'); }


//================================
//
//	SHOW MAIN WINDOWS and DIALOGS
//
//================================

	// MAIN WINDOW
	function showHome() {
		top.frmMain.location = gCGIPath + 'home.cgi';
	}
	function showAlbum(strType,nYear) {
		if (!strType) { strType = '' }
		var tNow = new Date();
		if (!nYear) { nYear = timeGetYear(tNow); }
		var nMonth = tNow.getMonth();
		var nYearNext = parseInt(nYear) + 1;
		var strQ = 'TYPE='+strType+'&SY=2002&SM=0&EY='+nYear+'&EM='+nMonth;
		top.frmMain.document.location = gWWWPath+"album.html?"+strQ;
		//document.location = gCGIPath+"show_album.cgi?"+strQ;
		//if (strType.toLowerCase() == 'garden') {
		//	var strQ = 'TYPE='+strType+'&SY='+nYear+'&SM=0&EY='+nYear+'&EM=11';
		//	document.location = gCGIPath+"show_album.cgi?"+strQ;
		//}
	}
	function showAlbumPage(idPage) {
		var strCGI = "show_album_page.cgi?IDARTICLE="+idPage;
		document.location = gCGIPath+strCGI;
	}
	function showWrappedAlbumPage(idPage) {
		top.frmMain.document.location = gWWWPath+"album.html?IDARTICLE="+idPage;
	}

	//	DIALOGS
	//	-- Event dialogs
	function addEvent(nDay, nMonth, nYear, idGroup) {
		if (nDay == 0) {
			var 	tToday =  new Date();		
			var 	nDay = tToday.getDate();
			var 	nMonth = tToday.getMonth()+1;
			var 	nYear = timeGetYear(tToday);
		}
		var strCGI = "dlg_event_new.cgi?DATE=" + nDay + ":"+ nMonth + ":"+ nYear;
		showDialogCGI("NewEvent",620,680,strCGI);
	}
	function noaddEvent () {
	
	}
	function editEvent(idEvent) {
		var strCGI = "dlg_event_edit.cgi?ID="+idEvent;
		showDialogCGI("EditNotice",590,600,strCGI);
	}
	function deleteEvent(idEvent) {
		var strCGI = "dlg_event_del.cgi?ID="+idEvent;
		showDialogCGI("DeleteEvent",590,300,strCGI);
	}
	
	//	-- Notice dialogs
	function addNotice() {
		var strCGI = "dlg_notice_new.cgi";
		showDialogCGI("NewNotice",590,600,strCGI);
	}
	function editNotice(idNotice) {
		var strCGI = "dlg_notice_edit.cgi?ID="+idNotice;
		showDialogCGI("EditNotice",590,600,strCGI);
	}
	function deleteNotice(idNotice) {
		var strCGI = "dlg_notice_del.cgi?ID="+idNotice;
		showDialogCGI("DeleteNotice",590,300,strCGI);
	}
	
	//	-- Album dialogs
	function addAlbumPage() {
		var strCGI = "dlg_bulletin_new.cgi";
		showDialogCGI("NewBulletin",590,600,strCGI);
	}
	function editAlbumPage(idPage) {
		var strCGI = "dlg_bulletin_edit.cgi?ID="+idPage;
		showDialogCGI("EditBulletin",590,600,strCGI);
	}
	function deleteAlbumPage(idPage) {
		var strCGI = "dlg_bulletin_del.cgi?ID="+idPage;
		showDialogCGI("DelBulletin",590,300,strCGI);
	}
	
	
	//  CREATE DIALOG WINDOWS
	
	// -- Create minimum-crome client side browser window
	function wndOpenNewDialog(strWndName, dxPref, dyPref) {
		var dx = screen.width - 80 ;
		var dy = screen.height - 160;
		if (dxPref > dx) {dxPref = dx;}
		if (dyPref > dy) {dyPref = dy;}
		var strParams = "scrollbars,status,resizable,width=" + dxPref +",height="+ dyPref;
		var wndNew = window.open("",strWndName,strParams);
		var xWnd = parseInt((dx + 70 - dxPref)/2);
		if (xWnd < 10) { xWnd = 10; }
		wndNew.moveTo(xWnd,82);
		return wndNew;
	}
	// open dialog in own window
	function showDialog(strName,dx,dy,strURL) {
		var wndName = "wnd"+strName;
		var strPath = gWWWPath+strURL;
		var wndNew = wndOpenNewDialog(wndName,dx,dy);
		if (wndNew != null) {
			wndNew.location = strPath;
			wndNew.focus();
		} else {
			alert("Sorry, the "+strName+" window could not be opened. Please try again. If you continue having troubles, please let us know. Thank you.");
		}
	}	
	// -- Call cgi program securely to return correct dialog html for the client side window
	function showDialogCGI(strName,dx,dy,strCGI) {
		var wndName = "wnd"+strName;
		var strCGIPath = gCGIPath+strCGI;
		var wndNew = wndOpenNewDialog(wndName,dx,dy);
		if (wndNew != null) {
			wndNew.location = strCGIPath;
			wndNew.focus();
		} else {
			alert("Sorry, the "+strName+" window could not be opened. Please try again. If you continue having troubles, please let us know. Thank you.");
		}
	}	
	// -- Call cgi program securely to return correct dialog html for the client side window
	function showDialogCGISecure(strName,dx,dy,strCGI) {
		var wndName = "wnd"+strName;
		var strCGIPath = gCGIPathSecure+strCGI;
		var wndNew = wndOpenNewDialog(wndName,dx,dy);
		if (wndNew != null) {
			wndNew.location = strCGIPath;
			wndNew.focus();
		} else {
			alert("Sorry, the "+strName+" window could not be opened. Please try again. If you continue having troubles, please let us know. Thank you.");
		}
	}	
	// -- Create high-chrome client side browser window	
	function wndOpenNewWindow(strWndName, dxPref, dyPref) {
		var dx = screen.width - 80 ;
		var dy = screen.height - 160;
		if (dxPref > dx) {dxPref = dx;}
		if (dyPref > dy) {dyPref = dy;}
		var strParams = "status,menubar,scrollbars,resizable,width=" + dxPref +",height="+ dyPref;
		var wndNew = window.open("",strWndName,strParams);
		var xWnd = parseInt((dx + 70 - dxPref)/2);
		if (xWnd < 10) { xWnd = 10; }
		wndNew.moveTo(xWnd,82);
		return wndNew;
	}
	// -- Call cgi program securely to return correct dialog html for the client side window
	function showWindowCGI(strName,dx,dy,strCGI) {
		var wndName = "wnd"+strName;
		var strCGIPath = gCGIPath+strCGI;
		var wndNew = wndOpenNewWindow(wndName,dx,dy);
		if (wndNew != null) {
			wndNew.location = strCGIPath;
			wndNew.focus();
		} else {
			alert("Sorry, the "+strName+" window could not be opened. Please try again. If you continue having troubles, please let us know. Thank you.");
		}
	}	
	
	// EXTERNAL DOCUMENT WINDOWS
	
	//	-- show website
	function showWebsite(strURL) {
		if (strURL.indexOf("http") < 0) {
			strURL = "http://" + strURL;
		}
		var dy = screen.height - 200;
		var strParams = "status,toolbar,menubar,location,scrollbars,resizable,width=500,height="+ dy;
		var wndNew = window.open("","wndWebsite",strParams);
		wndNew.moveTo(10,10);
		wndNew.location = strURL;
		wndNew.focus();
	}
	function showWebsitePlus(strURL,IsInternalLink) {
		if (IsInternalLink == 0) {
			top.frmMain.location = strURL;
		} else {
			showWebsite(strURL);
		}
	}
	
	// -- show bulletin attachments
	function showDocument(strFilename) {
		var dy = screen.height - 200;
		var strParams = "status,toolbar,menubar,location,scrollbars,resizable,width=500,height="+ dy;
		var wndNew = window.open("","wndDocument",strParams);
		wndNew.moveTo(10,10);
		wndNew.location = gWWWPath+strFilename;
		wndNew.focus();
	}

	
// =======================
//
//	ADMIN FEATURES
//
// =======================	
	
	// SignIn
	function signIn() {
		var strURL = "dialogs/dlg_signin.html";
		showDialog("SignIn",590,430,strURL);
	}
	function signOut() {
		var strCGI = "submit_signout.cgi";
		top.document.location = gCGIPath+strCGI;
	}
	//	-- admin command dialogs
	function adminCommand(iCommand) {
		var urlCGI = '';
		if (iCommand == 1) { urlCGI = gCGIPath+"admin_show_sessions.cgi"; }
		else if (iCommand == 2) { urlCGI = gCGIPath+"admin_show_db.cgi"; }
		else if (iCommand == 3) { urlCGI = gCGIPath+"admin_checktmpdir.cgi"; }
		
		if (urlCGI != '') {
			var wndNew = wndOpenNewWindow("AdminTool",600,600);
			if (wndNew != null) {
				wndNew.location = urlCGI;
				wndNew.focus();
			} else {
				alert("Sorry, the Admin window could not be opened. Please try again. If you continue having troubles, please let us know. Thank you.");
			}
		} else {
			alert("Sorry, you requested a command that doesn't exist. Command ID ="+iCommand);
		}
	}


//================================
//
//	TEXT, NUMBER AND DATE FUNCTIONS
//
//================================


	
	// ---------------------------------------------
	// MAKE HYPERLINKS
	// 		looks through a string for website urls...if found turns into hyperlink before displaying
	//		-- looks for www. or http:// or https:// to start
	//		-- finds all urls
	//		-- then works backwards through string to add <a href="[foundurl]">[foundurl]</a> 
	function makeURLsHot(txt, strClassName) {
		// PART 1: SEARCH
		// init search vars
		txt += ' ';
		var strSearch = txt;	// this is string to search...shorten each time to remaining unsearched portion of the string
		var aURL = new Array();		// array of urls found
		var aposURL = new Array();  // array of url positions in txt
		var iURL = -1;				// index of current found url
		var indexLastMatch = 0;		// keeps track of where last match was 
		// create search reg ex
		var regexWeb = /(((https?:\/\/www\.)|(www\.)|(https?:\/\/)|(ftp:\/\/))[^< !:'"\)\]]*)./i;
		// do first search
		var reMatch = regexWeb.exec(strSearch);
		while (reMatch) {
			// found one -- save results
			iURL++;
			var strFound = reMatch[1];
			aURL[iURL] = strFound;
			aposURL[iURL] = indexLastMatch + reMatch.index;
			indexLastMatch = indexLastMatch + reMatch.index + strFound.length;
			// change search string to remaining part of string
			strSearch = txt.substring(indexLastMatch,txt.length);
			reMatch = regexWeb.exec(strSearch);
		}
		
		// PART 2: PUT IN HOT LINKS
		var strMatch = '';		
		var lenMatch = 0;
		var iMatch = -1;
		var strPre = '';
		var strPost = '';
		var reHTTP = /^http/i;
		var strHTTP = '';
		var rePERIOD = /\.$/;
		for (var u = iURL; u >= 0; u--) {
			// get url string
			strMatch = aURL[u];
			// remove trailing period if there is one (end of sentence)
			strMatch = strMatch.replace(rePERIOD, '');
			// figure position to put in link
			lenMatch = strMatch.length;
			iMatch = aposURL[u];
			// add http:// if not already in url
			if (!reHTTP.test(strMatch)) {
				strMatch = 'http://'+strMatch;
			}
			// put in link
			strPre = txt.substring(0,(iMatch+lenMatch));
			strPost = txt.substring((iMatch+lenMatch),txt.length);
			txt = strPre + '</a>' + strPost;
			strPre = txt.substring(0,iMatch);
			strPost = txt.substring(iMatch,txt.length);
			txt = strPre + '<a href="'+strMatch+'" target="_blank" class="'+strClassName+'">' + strPost;
		}
		// return result
		return txt;
	}

	// ---------------------------------------------
	// GET EVENT DATE HTML STRING
	// 		-- new mySQL date version
	//		-- strEStart and strEEnd format: 2003-06-28 09:00:00
	//		-- nFormat 
	//				1=long  
	//				2=short
	function getEventDateHTML(strEStart, strEEnd, nFormat) {
		strReturn = '';

		// get start date pieces
		var aD = parseMysqlDatetime(strEStart);
		var nStartYear 		= aD[0];
		var nStartMonth		= aD[1];
		var nStartDay 		= aD[2];
		var nStartHour		= aD[3];
		var nStartMinute	= aD[4];
		
		// get end date pieces
		aD = parseMysqlDatetime(strEEnd);
		var nEndYear 		= aD[0];
		var nEndMonth		= aD[1];
		var nEndDay 		= aD[2];
		var nEndHour		= aD[3];
		var nEndMinute		= aD[4];
		
		// 		-- today
		var tToday = new Date();
		tToday.setHours(12);
		var nTodayDay 		= tToday.getDate();
		var nTodayMonth 	= tToday.getMonth() + 1;
		var nTodayYear 		= timeGetYear(tToday);
		var msecToday 		= tToday.getTime();
		var msecTomorrow 	= msecToday + msecOneDay;
		
		// 		-- tE1: exact start time of event to the second
		var tE1 = new Date(nStartYear,nStartMonth-1,nStartDay, nStartHour, nStartMinute, 0); 
		var msecE1 = tE1.getTime();
		var nWeekday = tE1.getDay();
		
		// 		-- tE2: exact end time of event to the second
		var tE2 = new Date(nEndYear,nEndMonth-1,nEndDay, nEndHour, nEndMinute, 0); 
		var msecE2 = tE2.getTime();

		//		-- tE1DayBegins: first second in the day the event starts, for date comparisions
		var tE1DayBegins = new Date(nStartYear,nStartMonth-1,nStartDay, 0, 0, 0); 
		var msecE1DayBegins = tE1DayBegins.getTime();
		
		//		-- tE2DayEnds: last second in the day the event ends, for date comparisions
		var tE2DayEnds = new Date(nEndYear,nEndMonth-1,nEndDay, 23, 59, 59); 
		var msecE2DayEnds = tE2DayEnds.getTime();
		
		// TODAY, TOMORROW, DAYNAME
		if (nFormat == 1) {
			if ((msecToday > msecE1DayBegins) && (msecToday < msecE2DayEnds)) {
				strReturn += 'Today';				
			} else if ((msecTomorrow > msecE1DayBegins) && (msecTomorrow < msecE2DayEnds)) {
				strReturn += 'Tomorrow';										
			} else {
				strReturn += aDays[nWeekday];
			}
			strReturn += ', ';
		}
		// DAY MONTH - DAY MONTH
		strReturn += nStartDay + ' ' +  aMonthsShort[nStartMonth-1];
		if (nStartDay != nEndDay) {
			strReturn += ' - ' + nEndDay + ' ' + aMonthsShort[nEndMonth-1];
		}
		// HOUR:MIN A/P - HOUR:MIN A/P
		if (nStartDay == nEndDay) {
			strReturn += ', ';
			strReturn += getTimeString(nStartHour, nStartMinute);
			var nMins = ((nEndHour-nStartHour) * 60) + (nEndMinute-nStartMinute);
			if (nMins > 5) {
				strReturn += '-' + getTimeString(nEndHour, nEndMinute);	
			}		
		}
		
		return strReturn;
	}
	
	// PARSE MYSQL DATETIME
	// 		-- new mySQL date version
	//		-- mysql datetime format: 2003-06-28 09:00:00
	//		-- returns an array of pieces
	//				[0] = year
	//				[1] = month
	//				[2] = day
	//				[3] = hour
	//				[4] = minute
	//				[5] = seconds
	//				[6] = msecs from now ... negative if in the past
	function parseMysqlDatetime(datetime) {
		var aDT = new Array();

		// get start date pieces
		var aD = datetime.split(' ');
		if (aD.length == 1) { aD[1] = '00:00:01'; }
		var aDateIn	= aD[0].split('-');
		var aTimeIn	= aD[1].split(':');
		aDT[0] 		= aDateIn[0];
		aDT[1]		= parseInt(aDateIn[1],10);
		aDT[2]		= parseInt(aDateIn[2],10);
		aDT[3]		= parseInt(aTimeIn[0],10);
		aDT[4]		= parseInt(aTimeIn[1],10);
		aDT[5]		= parseInt(aTimeIn[2],10);
		
		// determine msecs from now()
		var tToday 			= new Date();
		var msecToday 		= tToday.getTime();
		var nMonthIn 		= aDT[1] - 1;
		var tIn				= new Date(aDT[0],nMonthIn,aDT[2],aDT[3],aDT[4],aDT[5]);
		var msecIn			= tIn.getTime();
		aDT[6]				  = msecIn - msecToday;
		
		return aDT;
	}

	function timeGetYear(dateIn) {
		// IE AND NETSCAPE RETURN DIFFERENT VALUES FOR GETYEAR()!
		var yearIn = dateIn.getYear();
		if (yearIn < 1900) {yearIn += 1900;}
		return yearIn;
	}
	
	function getTimeString (nH,nM) {
		var strReturn = '';
		var strAMPM = 'a';
		if (nH > 11) { strAMPM = 'p'; }
		var strHour = nH;
		var strMinute = nM;
		var strExtra0 = '';
		if (nM < 10) { strExtra0 = '0'; }
		if (nH == 0) { strHour = '12'; }
		else if (nH > 12) { strHour = nH - 12;}
		strReturn = strHour + ':' + strExtra0 + strMinute + '' + strAMPM;
		
		return strReturn;
	}

	function getTimeOfDay(tIn) {
		var i;
		var aT = new Array();
		if (tIn == '0') {
			var myDate = new Date();
			myDate = getCortesTime(myDate);
			tIn = ((myDate.getHours()) * 100) + myDate.getMinutes();
		} else {
			aT = tIn.split(":");
			tIn = (getInt(aT[0]) * 100) + getInt(aT[1]);
		}
		var gtimeSunrise = '7:18';
		var gtimeSunset = '16:35';
		aT = gtimeSunrise.split(":");
		var tRise = (getInt(aT[0]) * 100) + getInt(aT[1]);
		aT = gtimeSunset.split(":");
		var tSet = (getInt(aT[0]) * 100) + getInt(aT[1]);
		// night or dusk?
		if 			(tIn < tRise - 45)		{ i = 0; } //pre-dawn
		else if 	(tIn < tRise + 45) 		{ i = 1; } //dawn
		else if 	(tIn < 1200) 			{ i = 2; } //morning
		else if 	(tIn < tSet - 45) 		{ i = 3; } //afternoon
		else if 	(tIn < tSet + 45) 		{ i = 4; } //dusk
		else 								{ i = 5; } //night
		return i;
	}
	
	function getCortesTime(dateLocal) {
		var nMinGMTOffset = dateLocal.getTimezoneOffset();
		var nMinCortesOffset = nMinGMTOffset - 420;
		var msecCortesOffset = nMinCortesOffset * 60000; 
		dateLocal.setTime(dateLocal.getTime() + msecCortesOffset);
		return dateLocal;
	}
	
	function getInt(strIn) {
		if (strIn.charAt(0) == '0') {strIn = strIn.charAt(1);} //needed for parseInt bug with '08'
		strIn = parseInt(strIn);
		return strIn;
	}
	
	function isNotEmpty(val) {
		if ((val == null) || (val == '')) {
			return false;
		} else {
			return true;
		}
	}
	function isEmpty(val) {
		if ((val == null) || (val == '')) {
			return true;
		} else {
			return false;
		}
	}
	
	function randomN(N) { 
		// returns a random number from 0...(N-1) inclusive
		return Math.floor(N*(Math.random()%1)) ;
	}
	
	function dequote( str ) {
		str = str.replace(/['"]/g, "");
		return str;
	}
	
	function refreshPage() {
		location.reload();
	}	 
	function refreshSite() {
		top.location.reload();
	}	 
	
	function getFooterDivider() {
		var str = '<span class="footerdivider"><img src="bits/footer_dot.gif" width="6" height="6" alt="" border="0"></span>';
		return str;
	} 


//================================
//
//	MISC
//
//================================

	// ---------------------------------------------
	// IDinList
	//		-- general function that looks for a match to id in a list of ids
	//		-- id list format: id:id:id:id
	function idInList(id,idList) {
		var fReturn = false;
		idList += '';
		var aList = idList.split(":");
		for (var z = 0; z <= aList.length-1; z++) {
			if (id == aList[z]) {
				fReturn = true;
				break;
			}
		}
		return fReturn;
	}

	
//================================
//
//	POPUP MENUS
//
//================================
	
		//		-- TO SHOW A MENU: 
		//			<a href="javascript:showMenu('menu_id_name')" onMouseOut="menu_t = 1; delayHide()">Link name <img src="arrow3.gif" width="10" height="5" alt="" border="0"></a><br>
		//		-- EACH MENU COMMAND: 
		//			<a href="javascript:foo()" class="menuLink" onMouseOut="menu_t = 1; delayHide()" onMouseOver="menu_t = 2;"  onClick="menu_t = 0; delayHide();">Command Name...</a><br>
		//		-- EACH MENUHEADER (non-active text line in menu)
		//			<div class="menuheader" onMouseOut="menu_t = 1; delayHide()" onMouseOver="menu_t = 2;">text</div>

		// global menu variables
		var domMenu_cur = null;
		var domMenu_old = null;
		var menu_t = 0;
		var menu_lDelay = 3;
		var menu_lCount = 0;
		var menu_pause = 100;
		
		function showMenu(menuName){
			if (isDHTML) {
				menu_t = 2;
				// hide any existing open menu
				if (domMenu_old) {
					//domMenu_old.visibility = 'hidden'; 
					domMenu_old.display = 'none'; 
					domMenu_old.zIndex = '0'; 
					menu_t = 2; 
					menu_lCount = 0;
				}
				// get DOM for new menu
				// set position and then show new menu
				domMenu_cur = getDOM(menuName,1);
				if (domMenu_old != domMenu_cur) {	
					//domMenu_cur.visibility = 'visible';
					domMenu_cur.display = 'block';
					domMenu_cur.zIndex = 1000;
					domMenu_old = domMenu_cur;
				}
				// Resets oldDom if it is the same as the current DOM
				else { domMenu_old = null; }
			}
			// Returns a 'null' value for non-DHTML Browsers 
			else { return null; }
		}
		
		function delayHide() {
			// Checks to see if there is a menu showing and whether 
			// the global variable 'menu_t' has been set to 0
		    if ((domMenu_old) && (menu_t == 0)) {
				// Hides the old menu, resets menu conditions, 
				// and stops the function running
		        //domMenu_old.visibility = 'hidden'; 
		        domMenu_old.display = 'none'; 
		        domMenu_old.zIndex = '0';
		        domMenu_old = null;
		        menu_lCount = 0; 
		        return false;
		    }
			// Interupts the function if another menu is opened
		    if (menu_t == 2) { menu_lCount = 0; return false; }
			// Repeats the function adding 1 to lCount each time until 
			// lCount is equal to lDelay and then sets 't' to 0 so that 
			// the menu will hide when it runs again
		    if (menu_t == 1) { 
		        menu_lCount = menu_lCount + 1;
		        if (menu_lDelay <= menu_lCount) { menu_t = 0; }
		        //if (menu_lDelay >= menu_lCount) { setTimeout('delayHide(' + menu_t + ')',menu_pause); }
		        setTimeout('delayHide()',menu_pause);
		    }
		}
		

	
//================================
//
//	COOKIES
//  	Cookie Functions -- "Night of the Living Cookie" Version (25-Jul-96)
//  	Written by:  Bill Dortch, hIdaho Design <bdortch@hidaho.com>
//  	The following functions are released to the public domain.
//
//================================

	// "Internal" function to return the decoded value of a cookie
	function getCookieVal (offset) {
	  var endstr = document.cookie.indexOf (";", offset);
	  if (endstr == -1)
	    endstr = document.cookie.length;
	  return unescape(document.cookie.substring(offset, endstr));
	}
	//  get cookie specified by "name".
	function GetCookie (name) {
	  var arg = name + "=";
	  var alen = arg.length;
	  var clen = document.cookie.length;
	  var i = 0;
	  while (i < clen) {
	    var j = i + alen;
	    if (document.cookie.substring(i, j) == arg)
	      return getCookieVal (j);
	    i = document.cookie.indexOf(" ", i) + 1;
	    if (i == 0) break; 
	  }
	  return null;
	}
	//  create or update a cookie.
	function SetCookie (name,value,expires,path,domain,secure) {
	  document.cookie = name + "=" + escape (value) +
	    ((expires) ? "; expires=" + expires.toGMTString() : "") +
	    ((path) ? "; path=" + path : "") +
	    ((domain) ? "; domain=" + domain : "") +
	    ((secure) ? "; secure" : "");
	}
	//  delete a cookie
	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";
	  }
	}

	
//================================
//
//	DOM
//
//================================

var isDHTML = 0;
var isID = 0;
var isAll = 0;
var isLayers = 0;

if (document.getElementById) {isID = 1; isDHTML = 1;}
if (document.all) {isAll = 1; isDHTML = 1;}
browserVersion = parseInt(navigator.appVersion);
if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {isLayers=1; isDHTML = 1;}

// Get object's browser specific DOM reference
function getDOM(objID,fStyle) {
	if (fStyle == 1) {
		if (isID) {return (document.getElementById(objID).style);}
		else {
			if (isAll) {return (document.all[objID].style);}
			else {
				if (isLayers) {return (document.layers[objID]);}
			}
		}
	}
	else {
		if (isID) {return (document.getElementById(objID));}
		else {
			if (isAll) {return (document.all[objID]);}
			else {
				if (isLayers) {return (document.layers[objID]);}
			}
		}	
	}
}
	