
/*=============================================
	misc utility functions
==============================================*/

var debugtoggle = false;
//var debugtoggle = true;
function debug(msg) { if (debugtoggle) {
	if (! $('debugdiv')) {
		document.body.innerHTML = document.body.innerHTML + '<div id="debugdiv"><p>DEBUG AREA<br />=====================<br />debugging CoreMetrics</p></div>';
	}
	var db = $('debugdiv');
	showDisplay(db);
	if (msg == "CLEAR") {
		db.innerHTML = "";
	} else {
		db.innerHTML = db.innerHTML + '<p>&#149; ' + msg + '</p>';
	}
	
}}




/*------------------------------------------------------------
*  Function:  getProps
*  
*  Description:
*  Builds a string from the properties of an object and their values
*  
*  Parameters:
*  which	string or object reference
*  
*  Return:
*  string
*------------------------------------------------------------*/

function getProps(which) {
	var theObj = $(which);
	var str = "";
	for (prop in theObj) {
		str += prop + ": " + eval("theObj." + prop) + " | ";
		//str += prop + " <br /> ";
	}
	return(str);
}



/*------------------------------------------------------------
*  Function:  getTarget
*  
*  Description:
*  Returns the target of a click event
*  
*  Parameters:
*  evt	mouse event
*  
*  Return:
*  object	a reference to the clicked event
*------------------------------------------------------------*/

function getTarget(evt) {
	if (evt && typeof(evt.className) != "undefined") {
		return evt;
	}

	evt = (evt) ? evt : ((window.event) ? event : null);
	if (evt) {
		var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
		if (elem) {
			return elem;
		}
	}
	return false;
}



/*------------------------------------------------------------
*  Function:  parseQuery
*  
*  Description:
*  allows us to set javascript variables by passing them in as
*  values in the query string. by default it looks for the
*  query string after the occurrence of '?' in URL of the
*  current document
*  
*  Parameters:
*  loc		string	url to search for query string
*  key		string	string which delimits query string from rest of URL
*  
*  Return:
*  none
*------------------------------------------------------------*/
function parseQuery(loc,key) {
	if (loc == null) loc = document.location.href;
	if (key == null) key = '?';
	if (loc.indexOf(key) > -1) {
		query = loc.substring(loc.indexOf(key)+key.length,loc.length);
		args = query.split('\&');
		for (i=0; i<args.length; i++) {
			chunk = args[i];
			eval(chunk.split('=')[0] + " = '" + chunk.split('=')[1] + "'");
		}
	}
}



/*------------------------------------------------------------
*  Function:  validEmail
*  
*  Description:
*  validates that an email is formatted properly
*  
*  Parameters:
*  email		string	email address
*  
*  Return:
*  true or false
*------------------------------------------------------------*/

function validEmail(email) {
    if (email.match(/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/)) {
    	return false;
    } else if (! email.match(/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z0-9]+){2,6}(\]?)$/)) {
    	return false;
    } else {
    	return true;
    }
	//var emailRegex = /^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,6}$/g;
	//return(email.match(emailRegex));
}




/*------------------------------------------------------------
*  Function:  newImage
*  
*  Description:
*  accepts a path to an image file. creates a new image object
*  and stuffs the src. used by the rollover framework
*  
*  Parameters:
*  arg		string	path to image file
*  
*  Return:
*  rslt		image object
*------------------------------------------------------------*/
function newImage(arg) {
	rslt = new Image();
	rslt.src = arg;
	return rslt;
}



/*------------------------------------------------------------
*  Function:  doBlur
*  
*  Description:
*  checks for the blur method and applies it the passed (clicked) object
*  
*  Parameters:
*  that		reference to the object being clicked
*  
*  Return:
*  none
*------------------------------------------------------------*/
function doBlur(that) {
	if (that.blur) that.blur();
}



/*------------------------------------------------------------
*  Function:  openPopupWindow
*  
*  Description:
*  opens a popup window of a passed width and height
*  and loads the passed URL in it
*  
*  Parameters:
*  url			string		page to load
*  w			integer		width of popup window
*  h			integer		height of popup window
*  features		string		window features - see below for defaults
*  
*  Return:
*  none
*------------------------------------------------------------*/
function openPopupWindow(url,w,h,features) {
	if (w == null) w = 400;
	if (h == null) h = 400;
	if (features == null) features = ",menubar=0,status=0,location=0,directories=0,resizable=1,scrollbars=1";
	
	if (url) {
		var popupWindow = window.open(url,'popupWindow','width='+w+',height='+h+features);
		popupWindow.focus();
	}
}




/*------------------------------------------------------------
*  Function:  resizeWindow
*  
*  Description:
*  resizes a window to a given width and height
*  by default, will only resize if the window is smaller than the prescribed width and/or height
*  if forceResize is passed in as true, it will force the window to the desired size
*  
*  Parameters:
*  w				integer	desired width
*  h				integer	desired height
*  forceResize		boolean	if true, forces large window to resize down to desired size
*  
*  Return:
*  none
*------------------------------------------------------------*/
function resizeWindow(w,h,forceResize) {
	if (window.innerWidth && window.innerHeight) {
		var wdiff = window.outerWidth - window.innerWidth;
		var hdiff = window.outerHeight - window.innerHeight;
		
		var windowIsSmaller = false;
		if (window.innerWidth < w) {
			endw = w + wdiff;
			windowIsSmaller = true;
		} else {
			endw = window.outerWidth;
		}
		if (window.innerHeight < h) {
			endh = h + hdiff;
			windowIsSmaller = true;
		} else {
			endh = window.outerHeight;
		}
		if (forceResize) {
			endw = w + wdiff;
			endh = h + hdiff;
		}
		
		if (windowIsSmaller || forceResize) self.resizeTo(endw,endh);
	}
}



/*------------------------------------------------------------
*  Function:  dw
*  
*  Description:
*  shorthand for document.write
*  
*  Parameters:
*  msg		string	text to be written
*  
*  Return:
*  none
*------------------------------------------------------------*/
function dw(msg) {
	document.write(msg);
}



/*------------------------------------------------------------
*  Function:  atype
*  
*  Description:
*  shorthand for alerting the type of an object
*  
*  Parameters:
*  v		variable	the object to inspect
*  
*  Return:
*  none
*------------------------------------------------------------*/
function atype(v) {
	if (debugtoggle) {
		debug(typeof(v));
	} else {
		alert(typeof(v));
	}
}



/*------------------------------------------------------------
*  Function:  randomNum
*  
*  Description:
*  returns a random number in the specified range of numbers, inclusive
*  
*  Parameters:
*  start	integer	first number in desired range
*  end		integer	last number in desired range
*  
*  Return:
*  n		integer
*------------------------------------------------------------*/
function randomNum(start,end) {
	var range = end - start + 1;
	var n = Math.floor(Math.random() * (range)) + start;
	return(n);
}



/*------------------------------------------------------------
*  Function:  formatNumberCommas
*  
*  Description:
*  formats a number (eg. 12345) with commas (12,345)
*  
*  Parameters:
*  n	integer		number to format
*  
*  Return:
*  n				string
*------------------------------------------------------------*/
function formatNumberCommas(n) {
	if (typeof(n) == "number") n = n.toString();
	if (typeof(n) == "string") {
		var re = /(-?\d+)(\d{3})/;
		while (re.test(n)) {
			n = n.replace(re, "$1,$2");
		}
		return n;
	}
	return false;
}



/*------------------------------------------------------------
*  Function:  show
*  
*  Description:
*  shows an object, if not nested in a hidden object
*  
*  Parameters:
*  which	string/object	ID of object to be shown, or reference to the object itself
*  
*  Return:
*  none
*------------------------------------------------------------*/
function show(which) {
	var obj = $(which);
	if (obj) obj.style.visibility = "inherit";
}



/*------------------------------------------------------------
*  Function:  hide
*  
*  Description:
*  hides an object from display
*  
*  Parameters:
*  which	string/object	ID of object to be shown, or reference to the object itself
*  
*  Return:
*  none
*------------------------------------------------------------*/
function hide(which) {
	var obj = $(which);
	if (obj) obj.style.visibility = "hidden";
}



/*------------------------------------------------------------
*  Function:  showDisplay
*  
*  Description:
*  sets the display value of an object to the passed in display type
*  defaults to "block"
*  
*  Parameters:
*  which	string/object	ID of object to be shown, or reference to the object itself
*  type		string			either "inline" or "block" -- defaults to "block"
*  
*  Return:
*  none
*------------------------------------------------------------*/
function showDisplay(which,type) {
	if (! type) type = "block";
	var obj = $(which);
	if (obj) obj.style.display = type;
}



/*------------------------------------------------------------
*  Function:  hideDisplay
*  
*  Description:
*  sets the display value of an object to "none"
*  
*  Parameters:
*  which	string/object	ID of object to be shown, or reference to the object itself
*  
*  Return:
*  none
*------------------------------------------------------------*/
function hideDisplay(which) {
	var obj = $(which);
	if (obj) obj.style.display = "none";
}


/*=============================================
	end misc utility functions
==============================================*/




/*=============================================
	cookie library
==============================================*/


/*------------------------------------------------------------
*  Function:  getExpDate
*  
*  Description:
*  utility function to retrieve an expiration date in proper format
*  pass three integer parameters for the number of days, hours,
*  and minutes from now you want the cookie to expire (or
*  negative values for a past date)
*  all three parameters are required, so use zeros where appropriate
*  
*  Parameters:
*  days	integer
*  hours	integer
*  minutes	integer
*  
*  Return:
*  date	string
*------------------------------------------------------------*/
function getExpDate(days, hours, minutes) {
	var expDate = new Date();
	if (typeof days == "number" && typeof hours == "number" && typeof minutes == "number") {
		expDate.setDate(expDate.getDate() + parseInt(days));
		expDate.setHours(expDate.getHours() + parseInt(hours));
		expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
		return expDate.toGMTString();
	}
}


/*------------------------------------------------------------
*  Function:  getCookieVal
*  
*  Description:
*  utility function called by getCookie()
*  
*  Parameters:
*  offset	string
*  
*  Return:
*  cookie	string
*------------------------------------------------------------*/
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

// 


/*------------------------------------------------------------
*  Function:  getCookie
*  
*  Description:
*  primary function to retrieve cookie by name
*  
*  Parameters:
*  name	string	name of cookie to be retrieved
*  
*  Return:
*  value	string	value of named cookie
*------------------------------------------------------------*/
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 "";
}



/*------------------------------------------------------------
*  Function:  setCookie
*  
*  Description:
*  store cookie value with optional details as needed
*  
*  Parameters:
*  name	string
*  value	string
*  expires	string
*  path	string
*  domain	string
*  secure	boolean
*  
*  Return:
*  none
*------------------------------------------------------------*/
function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}




/*------------------------------------------------------------
*  Function:  deleteCookie
*  
*  Description:
*  remove the cookie by setting ancient expiration date
*  
*  Parameters:
*  name	string
*  path	string
*  domain	string
*  
*  Return:
*  none
*------------------------------------------------------------*/
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";
	}
}

/*=============================================
	end cookie library
==============================================*/




/*=============================================
	rollover library
==============================================*/

// array used to store rollover states and image data
var rollovers = new Array();
// array used to store 'current' images for groups of mutually exclusive rollovers
var currents = new Array();

/*------------------------------------------------------------
*  Function:  imgOn. imgOver, imgOn, imgFreeze, imgUnfreeze
*  
*  Description:
*  shorthand functions for calling imgSwap
*  
*  Parameters:
*  which	string 	name of image to swap
*  
*  Return:
*  none
*------------------------------------------------------------*/
function imgOn(which) {
	imgSwap(which,'on');
}

function imgOver(which) {
	imgSwap(which,'over');
}

function imgOff(which) {
	imgSwap(which,'off');
}

function imgFreeze(which) {
	if (which && rollovers[which]) {
		rollovers[which].frozen = true;
	}
}

function imgUnfreeze(which) {
	if (which && rollovers[which]) {
		rollovers[which].frozen = false;
	}
}

function setCurrent(group,which) {
	currents[group] = which;
}



/*------------------------------------------------------------
*  Function:  imgSwap
*  
*  Description:
*  stub function for rollovers
*  expects an image name and state
*  checks for existence of named image, and defined state
*  also checks to see if image has been disabled -- this is used to freeze an image in a given state
*  
*  Parameters:
*  which	string 	name of image to swap
*  state	string	name of state to swap to
*  
*  Return:
*  none
*------------------------------------------------------------*/
function imgSwap(which,state) {
	if (which && rollovers[which]) {
		if (document.images[which] && rollovers[which].states[state]) {
			if (! rollovers[which].frozen) {
				document.images[which].src = rollovers[which].states[state].src;
			}
		}
	}
}


/*------------------------------------------------------------
*  Function:  newRollover
*  
*  Description:
*  this function populates the rollovers array with the image
*  objects used for the various states of a rollover
*  
*  Parameters:
*  name		string	name of image object
*  offsrc		string	path to image file for off (normal) state
*  oversrc		string	path to image file for over state
*  onsrc		string	path to image file for on (selected) state
*  disabledsrc	string	path to image file for disabled state
*  
*  Return:
*  none
*------------------------------------------------------------*/
function newRollover(name,offsrc,oversrc,onsrc,disabledsrc) {
	rollovers[name] = new Object();
	rollovers[name].states = new Array();
	rollovers[name].states['off'] = (offsrc) ? newImage(offsrc) : null;
	rollovers[name].states['over'] = (oversrc) ? newImage(oversrc) : null;
	rollovers[name].states['on'] = (onsrc) ? newImage(onsrc) : null;
	rollovers[name].states['disabled'] = (disabledsrc) ? newImage(disabledsrc) : null;
	// the following variable is used to prevent an image from being changed on rollover
	// used for disabling images that are in a disabled or selected state and shouldn't change
	rollovers[name].frozen = false;
}


/*=============================================
	end rollover library
==============================================*/



/*=============================================
	form validation library
==============================================*/


/*------------------------------------------------------------
*  Function:  verifyForm
*  
*  Description:
*  validates a form by checking all elements classed as "required". if any required elements are empty, it marks their labels with an "error" class and returns false
*  this function should be called in the form's onsubmit handler: onsubmit="verifyForm(this)"
*  also checks forms classed as "email" for email format validity
*  
*  Parameters:
*  theform		object	reference to the form to be verified
*  
*  Return:
*  true or false
*------------------------------------------------------------*/
function verifyForm(theform) {
	var msg;
	var elem;
	
	resetRequiredFields(theform);
	
	for (var e=0; e<theform.elements.length; e++) {
		if (theform.elements[e].className.match(/required/g) && theform.elements[e].value == "") {
			hiliteRequiredField(theform,theform.elements[e].id);
			if (! elem) elem = theform.elements[e];
			if (! msg) msg = "Please enter all required fields.";
		}

		if (theform.elements[e].className.match(/email/g) && ! validEmail(theform.elements[e].value)) {
			hiliteRequiredField(theform,theform.elements[e].id);
			if (! elem) elem = theform.elements[e];
			if (! msg) msg = "Please enter a valid email address.";
		}
	}
	
	if (msg && elem) {
		alert(msg);
		elem.focus();
		return false;
	} else {
		return true;
	}
}

/*------------------------------------------------------------
*  Function:  resetRequiredFields
*  
*  Description:
*  utility function called by verifyForm
*  sets class of all labels to empty
*  
*  Parameters:
*  theform		object	reference to the form to be verified
*  
*  Return:
*  none
*------------------------------------------------------------*/
function resetRequiredFields(theform) {
	if (document.getElementsByTagName) {
		var theLabels = theform.getElementsByTagName('label');
		for (var l=0; l<theLabels.length; l++) {
			theLabels[l].className = "";
		}
	}
}

/*------------------------------------------------------------
*  Function:  hiliteRequiredField
*  
*  Description:
*  utility function called by verifyForm
*  sets class of label associated with erroneous field to "error"
*  
*  Parameters:
*  theform		object	reference to the form to be verified
*  id			string	name of erroneous field
*  
*  Return:
*  none
*------------------------------------------------------------*/
function hiliteRequiredField(theform,id) {
	if (document.getElementsByTagName) {
		var theLabels = theform.getElementsByTagName('label');
		for (var l=0; l<theLabels.length; l++) {
			if (theLabels[l].htmlFor == id) {
				theLabels[l].className = "error";
			}
		}
	}
}

/*=============================================
	end form validation library
==============================================*/




/*=============================================
	misc site-specific functions
==============================================*/

function generateImgNumberString(where,n) {
	theSpan = $(where);
	//if (! n) n = randomNum(10000,10000000);
	if (! n) n = $('pagecounter').innerHTML;
	n = n.substring(n.lastIndexOf('>')+1,n.length);
	n = n.replace(/^(\d+)[\r\n.]+/,"$1");
	
	n = parseInt(n);
	if (n == parseInt(n)) {
		var s = formatNumberCommas(n);
	
		var h = '';
		var path = rootimagesfolder+"counter/";
		for (var i=0; i<s.length; i++) {
			var x = s.substr(i,1);
			if (x == ",") x = "comma";
			h += '<img src="'+path+x+'.gif" border="0" />';
		}
		
		h += '<img src="'+rootimagesfolder+'counter/peopleknowthetruth.gif" alt="People Know The Truth" border="0" />';
	
		theSpan.innerHTML = h;
		show(theSpan);
	}
}


function debugCookies() {
	debug('CLEAR');
	debug('DEBUG AREA<br />================================');
	debug('COOKIES:');
	debug('section: ' + getCookie('section'));
	debug('page: ' + getCookie('page'));
}

function passSection(that) {
	// parse out the name of the root folder to determine the section
	var section = that.location.href.replace(new RegExp('https?://[^/]+/([^/]+)/.*'),"$1");
	// remove domain from address and redirect to home, passing the page
	var page = that.location.href.replace(new RegExp('https?://[^/]+'),"");

	if (! mainpage) {
		if (! parent.mainpage) {
			// page has been loaded outside of frame
			top.location = '/home/?page=' + page;
		} else {
			parent.setSection(section,page,that.document.title);
		}
	}
}

function passContent(that) {
	if (! mainpage) {
		if (parent.mainpage) {
			var theContent = $('featurecontent');
			if (theContent)	parent.catchContent(theContent);
			var theContent = $('helpsolverightcontent');
			if (theContent)	parent.catchContent(theContent);
		}
	}
}

function catchContent(that) {
	if (mainpage) {
		if (that.id) {
			//debug(that.id);
			if (that.id == "featurecontent") {
				var theFeature = $('feature');
				if (theFeature) theFeature.innerHTML = that.innerHTML;
			}
			if (that.id == "helpsolverightcontent") {
				var theFeature = $('helpsolveright');
				if (theFeature) theFeature.innerHTML = that.innerHTML;
			}
		}
	}
}

function setSection(section,page,title) {
	unsetSection();

	imgOver('nav'+section);
	imgFreeze('nav'+section);
	setCurrent('nav','nav'+section);

	window.document.title = title;
	document.body.className = section;

	setCookie('section', section);
	setCookie('page', page);
	//debugCookies();
}

function unsetSection() {
	if (currents['nav']) {
		imgUnfreeze(currents['nav']);
		imgOff(currents['nav']);
	}
}

function fetchPage(theURL) {
	var theDiv = $('feature');
	if (theURL && theDiv) {
		unsetSection();
		var myAjax = new Ajax.Updater(theDiv, theURL, {method: 'get', onComplete:function(){} });
	}
}



function setHelpSolveSection(that) {
	var section = that.location.href.replace(new RegExp('https?://[^/]+/[^/]*/([^<]*).html.*'),"$1");
	
	if (currents['helpsolve']) {
		imgUnfreeze(currents['helpsolve']);
		imgOff(currents['helpsolve']);
	}
	imgOver('HS'+section);
	imgFreeze('HS'+section);
	setCurrent('helpsolve','HS'+section);

	//debugCookies();
}

function addExpanderHandlers() {
	var panes = document.getElementsByClassName('expander');
	for (var i=0; i<panes.length; i++) {
		var triggers = document.getElementsByClassName('expandtrigger',panes[i]);
		for (var t=0; t<triggers.length; t++) {
			triggers[t].pane = panes[i];
			triggers[t].onclick = toggleExpander;
		}
	}
}

function toggleExpander(e) {
	theTrigger = getTarget(e);
	if (theTrigger) {
		thePane = theTrigger.pane;
		if (thePane) {
			if (thePane.className.match(/collapsed/)) {
				thePane.className = thePane.className.replace(/ ?collapsed/,"");
			} else {
				thePane.className = thePane.className + " collapsed";
			}
		}	
	}
}


function tellaFriend(that) {

	postvars = ""
	for (f=0;f<that.elements.length;f++) {
		if (f>0) postvars += "&";
		postvars += that.elements[f].name + "=" + that.elements[f].value;
	}

	var theURL = "/cgi-bin/tellafriend.pl";
	
	showTellaFriendMessage("Sending...");

	new Ajax.Updater('tellafriendresponse', theURL, {method:'post', asynchronous:true, evalScripts:true, postBody:postvars, onComplete:tellaFriendComplete() });
	//new Ajax.Request(theURL, {asynchronous:true, evalScripts:true, postBody:postvars, onComplete:tellaFriendComplete() });
	
	return false;
}

function tellaFriendComplete() {
	//showTellaFriendMessage("Your message has been sent. Thanks for sharing the truth!");
	$('tellafriendform').reset();
	
	//setTimeout("showTellaFriendMessage('')",10000);
}


function validateTellaFriend(that,showalert,submitifvalid) {
	var theSendername = that.elements['sendername'];
	var theSenderemail = that.elements['senderemail'];
	var theFriendname = that.elements['friendname'];
	var theFriendemail = that.elements['friendemail'];
	var theMessage = that.elements['message'];
	var theButton = that.elements['submit'];
	
	showTellaFriendMessage("");
	
	var msg = "";
	var focuselem = null;
	var valid = true;

	if (valid) { if (theSendername.value == "") {
		valid = false;
		msg = "Please enter your name.";
		focuselem = theSendername;
	}}
	if (valid) { if (theSenderemail.value == "") {
		valid = false;
		msg = "Please enter your email address.";
		focuselem = theSenderemail;
	}}
	if (valid) { if (! validEmail(theSenderemail.value)) {
		valid = false;
		msg = "Your email address does not appear to be valid. Please check the address and try again.";
		focuselem = theSenderemail;
	}}
	if (valid) { if (theFriendname.value == "") {
		valid = false;
		msg = "Please enter your friend's name.";
		focuselem = theFriendname;
	}}
	if (valid) { if (theFriendemail.value == "") {
		valid = false;
		msg = "Please enter your friend's email address.";
		focuselem = theFriendemail;
	}}
	if (valid) { if (! validEmail(theFriendemail.value)) {
		valid = false;
		msg = "Your friend's email address does not appear to be valid. Please check the address and try again.";
		focuselem = theFriendemail;
	}}
	if (valid) { if (theMessage.value == "") {
		valid = false;
		msg = "Please enter a brief message for your friend.";
		focuselem = theMessage;
	}}

	//theButton.disabled = (valid)?false:true; 
	
	if (showalert) {
		if (focuselem) focuselem.focus();
		showTellaFriendMessage(msg);
	}
	
	if (valid && submitifvalid) tellaFriend(that);
	
	return false;
}

function showTellaFriendMessage(msg) {
	var thePane = $('tellafriendresponse');
	if (thePane) {
		thePane.innerHTML = msg;
	}
}



function setupRollovers() {
	newRollover('navintroduction',rootimagesfolder+'topnav/introduction.gif',rootimagesfolder+'topnav/introduction-over.gif');
	newRollover('navcauseeffect',rootimagesfolder+'topnav/causeeffect.gif',rootimagesfolder+'topnav/causeeffect-over.gif');
	newRollover('navconsequences',rootimagesfolder+'topnav/consequences.gif',rootimagesfolder+'topnav/consequences-over.gif');
	newRollover('navhelpsolve',rootimagesfolder+'topnav/helpsolve.gif',rootimagesfolder+'topnav/helpsolve-over.gif');
	newRollover('navmisconceptions',rootimagesfolder+'topnav/misconceptions.gif',rootimagesfolder+'topnav/misconceptions-over.gif');
	newRollover('navtellafriend',rootimagesfolder+'topnav/tellafriend.gif',rootimagesfolder+'topnav/tellafriend-over.gif');
	newRollover('navclimatecrisis',rootimagesfolder+'topnav/climatecrisis.gif',rootimagesfolder+'topnav/climatecrisis-over.gif');
	
	newRollover('counter0',rootimagesfolder+'counter/0.gif');
	newRollover('counter1',rootimagesfolder+'counter/1.gif');
	newRollover('counter2',rootimagesfolder+'counter/2.gif');
	newRollover('counter3',rootimagesfolder+'counter/3.gif');
	newRollover('counter4',rootimagesfolder+'counter/4.gif');
	newRollover('counter5',rootimagesfolder+'counter/5.gif');
	newRollover('counter6',rootimagesfolder+'counter/6.gif');
	newRollover('counter7',rootimagesfolder+'counter/7.gif');
	newRollover('counter8',rootimagesfolder+'counter/8.gif');
	newRollover('counter9',rootimagesfolder+'counter/9.gif');
	newRollover('countercomma',rootimagesfolder+'counter/comma.gif');
	newRollover('counterpeopleknowthetruth',rootimagesfolder+'counter/peopleknowthetruth.gif');
	
	newRollover('HSbuythingsthatlast',rootimagesfolder+'helpsolve/nav/buythingsthatlast.gif',rootimagesfolder+'helpsolve/nav/buythingsthatlast-over.gif');
	newRollover('HSdontwastepaper',rootimagesfolder+'helpsolve/nav/dontwastepaper.gif',rootimagesfolder+'helpsolve/nav/dontwastepaper-over.gif');
	newRollover('HSeatlessmeat',rootimagesfolder+'helpsolve/nav/eatlessmeat.gif',rootimagesfolder+'helpsolve/nav/eatlessmeat-over.gif');
	newRollover('HSgreenpower',rootimagesfolder+'helpsolve/nav/greenpower.gif',rootimagesfolder+'helpsolve/nav/greenpower-over.gif');
	newRollover('HSneutralizeemissions',rootimagesfolder+'helpsolve/nav/neutralizeemissions.gif',rootimagesfolder+'helpsolve/nav/neutralizeemissions-over.gif');
	newRollover('HSprecycle',rootimagesfolder+'helpsolve/nav/precycle.gif',rootimagesfolder+'helpsolve/nav/precycle-over.gif');
	newRollover('HSrefillablebottle',rootimagesfolder+'helpsolve/nav/refillablebottle.gif',rootimagesfolder+'helpsolve/nav/refillablebottle-over.gif');
	newRollover('HSsupportenvironmental',rootimagesfolder+'helpsolve/nav/supportenvironmental.gif',rootimagesfolder+'helpsolve/nav/supportenvironmental-over.gif');
	newRollover('HStelecommute',rootimagesfolder+'helpsolve/nav/telecommute.gif',rootimagesfolder+'helpsolve/nav/telecommute-over.gif');
	newRollover('HSvotewithdollars',rootimagesfolder+'helpsolve/nav/votewithdollars.gif',rootimagesfolder+'helpsolve/nav/votewithdollars-over.gif');
}

/*=============================================
	end misc site-specific functions
==============================================*/


/*=============================================
	begin coremetrics wrapper functions
==============================================*/

// assocatiative array of site sections and CoreMetrics categories
var coremetricsCategories = {
	home: 'Introduction',
	introduction: 'Introduction',
	causeeffect: 'Causes And Effect',
	consequences: 'Consequences',
	helpsolve: 'Climate Crisis',
	misconceptions: 'Misconception',
	misc: 'Miscellaneous'
};

function insertCoreMetricsTag(passedtitle,passedsection) {
	// parse section and title from document.location and document.title	
	var pagetitle = document.title;
	var pagesection = document.location.href.replace(new RegExp('https?://[^/]+/([^/]+)/.*'),"$1");
		
	// if section or title is passed in explicitly, use those
	var title = (passedtitle) ? passedtitle : pagetitle;
	var section = (passedsection) ? passedsection : pagesection;
	
	// look up the CoreMetrics category for the section
	var category = (coremetricsCategories[section]) ? coremetricsCategories[section] : coremetricsCategories['misc'];
	
	if (cmCreatePageviewTag) cmCreatePageviewTag(title,category,null,null);

}


/*=============================================
	end coremetrics wrapper functions
==============================================*/







/*=============================================
	startup calls
==============================================*/

/*------------------------------------------------------------
*  Function:  startup
*  
*  Description:
*  does various initialization procedures
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
var rootimagesfolder = "http://images.rodale.com/readthetruth/";
var mainpage = null;
var splashpage = null;
var pageStartup = null;
// if a given page defines its own function called 'pageStartup' it will be called on load

function startup() {
	if (! mainpage && ! splashpage) {
		passSection(this);
		passContent(this);
	}
	
	if (mainpage) {
		setupRollovers();
	}
	
	if (typeof(pageStartup) == "function") {
		pageStartup();
	}
}

window.onload = startup;

/*=============================================
	end startup calls
==============================================*/




/*=============================================
	inline calls
==============================================*/

// rollovers can be called inline so they are preloaded prior to window.onload
// to prevent flicker of css hover images

// newRollover(name,offsrc,oversrc,onsrc,disabledsrc)

/*=============================================
	end inline calls
==============================================*/





