var isIE = navigator.appName.indexOf("Microsoft") != -1;
var isIE5 = navigator.userAgent.indexOf('MSIE 5.0') > 0;
var isOpera = navigator.userAgent.indexOf("Opera") != -1;
var isSafari = navigator.userAgent.indexOf("AppleWebKit") != -1;
var isFirefox = navigator.userAgent.indexOf( "Firefox/" ) != -1;
var isNetscape = navigator.userAgent.indexOf( "Netscape/" ) != -1;

function ltrim(s) {
 return s.replace( /^\s*/, "" );
 }

 function rtrim(s) {
 return s.replace( /\s*$/, "" );
 }

 function trim(s){
 return rtrim(ltrim(s));
}

function formatPhone (field) {
 field.value = trim(field.value);

 var ov = field.value;
 var v = "";
 var x = -1;

 // is this phone number 'escaped' by a leading plus?
 if (0 < ov.length && '+' != ov.charAt(0)) { // format it
 // count number of digits
 var n = 0;
 if ('1' == ov.charAt(0)) { // skip it
 ov = ov.substring(1, ov.length);
 }

 for (i = 0; i < ov.length; i++) {
 var ch = ov.charAt(i);

 // build up formatted number
 if (ch >= '0' && ch <= '9') {
 if (n == 0) v += "(";
 else if (n == 3) v += ") ";
 else if (n == 6) v += "-";
 v += ch;
 n++;
 }
 // check for extension type section;
 // are spaces, dots, dashes and parentheses the only valid non-digits in a phone number?
 if (! (ch >= '0' && ch <= '9') && ch != ' ' && ch != '-' && ch != '.' && ch != '(' && ch != ')') {
 x = i;
 break;
 }
 }
 // add the extension
 if (x >= 0) v += " " + ov.substring(x, ov.length);

 // if we recognize the number, then format it
 if (n == 10 && v.length <= 40) field.value = v;
 }
 return true;
}

var loadEvents = new Array();
function html_entity_decode(str) {
	var ta=document.createElement("textarea");
	ta.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
	return ta.value;
}
function grab_tag_contents(tagId) {
	return html_entity_decode(document.getElementById(tagId).innerHTML)
}
function eval_field_value(tagId) {
	return eval(html_entity_decode(document.getElementById(tagId).value))
}
var strDomain = document.domain;
//Use the syntax addLoadEvent(whichFunction) to add a body.onload event to the page. Do not use this together with onload="foo()" hard-coded in the body tag --  the embedded script call will override the addLoadEvent handler. 
function addLoadEvent(whichFunction) { 
	if (window.onload) { 
		if (window.onload != callLoadEvents) { loadEvents[0] = window.onload; window.onload = callLoadEvents; }         
		loadEvents[loadEvents.length] = whichFunction; }
	else { window.onload = whichFunction; } }
function callLoadEvents() { for (var i = 0; i < loadEvents.length; i++) { loadEvents[i](); } } 

function setCookie(strName, strValue) { 
	strExpiry = new Date();
	strExpiry.setDate(strExpiry.getDate() + 3650);
	document.cookie = strName + '=' + strValue + ';expires=' + strExpiry.toGMTString() }

var strCookie = document.cookie;
function getCookieValue(strName) { 
	var strValue = '';
	if (strCookie.length < 1) { return strValue }
	var arrCookieStrings = strCookie.split('; ');
	for (var i = 0; i < arrCookieStrings.length; i++) { 
		var strPair = arrCookieStrings[i];
		if (strPair.indexOf(strName) == 0) { 
			strValue = strPair.substr(strName.length + 1, strPair.length); } }
	return strValue; }
function stripHtmlTags(strContent) { return strContent.stripScripts().stripTags().gsub('&nbsp;',' ').unescapeHTML(); }