//  '  default_javascript.js

function selectedValue(selectControl) 
{
  return selectControl.options[selectControl.selectedIndex].value;
}


function TestIncludeLocation()
{
	alert('Include location found under '+document.SessionVariables.strWebsiteURL.value+'.');
}


function JumpToSelected (selSelectObject)
{
   if (selSelectObject.options[selSelectObject.selectedIndex].value != "")
	   { 
	     location.href = selSelectObject.options[selSelectObject.selectedIndex].value;
	   }
}


// Function to jump to another forum.
function ForumJump(URL) 
{
	if (URL.options[URL.selectedIndex].value != "") 
		{
		self.location.href = URL.options[URL.selectedIndex].value;
		}
	return true;
}


// Function to open pop-up window.
// Example: openWin('','preview','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=1000,height=600');

function openWin(theURL, winName, features) 
{
  	window.open(theURL,winName,features);
}


// Function to open preview window.
function OpenPreviewWindow(targetPage, formName) 
{
	now = new Date;  
	
	// Open the window first. 	
   	openWin('','preview','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=1000,height=600');
   		
   	// Now submit form to the new window.
   	formName.action = targetPage + "?ID=" + now.getTime();	
	formName.target = "preview";
	formName.submit();
}


////////////////////////////////////////////////////////////////


// A version-independent stack object prototype for JScript. 
// We use an index into the array to increase efficiency instead of making expensive calls to slice(); 
// old values will just be blown away on subsequent push() operations.

function Stack() 
{
   // Private data
   var stackPtr;
   var stackArr;

   // Methods
   this.Push = internal_push;
   this.Pop = internal_pop;
   this.Clear = internal_clear;
   this.Length = internal_length;

   // Init this instance.
   internal_clear();
}

// Push an element onto the top (end) of the stack. 
// @Precondition: elem is not null
// @Postcondition: stack.length == stack.length + 1

function internal_push(elem) 
{ 
   stackArr[++stackPtr] = elem;
}

// Retrieve an element off of the top (end) of the stack.
// @Precondition: stack is not null
// @Postcondition Old Stack.Length() == StackLength() + 1

function internal_pop() 
{
   if (stackPtr >= 0) 
   {
      return(stackArr[stackPtr--]);
   } 
   else 
   {
      throw("Cannot pop off of an empty stack.");
   }
}

// Clear the stack and start anew.

function internal_clear() 
{
   stackPtr = -1;
   stackArr = new Array();
}

// Obtain the current stack length. Since we use an index into the array,
// Length() != internalArray.Length.

function internal_length() 
{
   return(stackPtr + 1);
}



////////////////////////////////////////////////////////////////



function FormatNumber(num, decimalNum, blnLeadingZero, blnParens, blnCommas)
// FormatNumber(Expression, NumDigitsAfterDecimal, IncludeLeadingDigit, UseParensForNegativeNumbers, GroupDigits)
/**********************************************************************
	IN:
		num - the number to format
		decimalNum - the number of decimal places to format the number to
		blnLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		blnParens - true / false - use parenthesis around negative numbers
		blnCommas - true / false - put commas as number separators.
 
	RETURN:
		The formatted number
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "(not a number)";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!blnLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas.
	if (blnCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (blnParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string.
}




// Change the format of the passed number to currency.
//Remove the $ sign if you don't want the returned value to include it.
var prefix="$"
var wholeOrDecimal

function formatCurrencyInput(thisObject)
{
	thisObject.value=formatCurrency(thisObject.value);
	if (thisObject.value.charAt(0)=="$")
	return
	wholeOrDecimal="whole"
	var tempNum=thisObject.value
	for (i=0; i<tempNum.length; i++)
		{
		if (tempNum.charAt(i)==".")
			{
			wholeOrDecimal="decimal"
			break
			}
		}
	if (wholeOrDecimal=="whole")
		thisObject.value=prefix+tempNum+".00"
	else
		{
		if (tempNum.charAt(tempNum.length-2)==".")
			{
			thisObject.value=prefix+tempNum+"0"
			}
		else
			{
			tempNum=Math.round(tempNum*100)/100
			thisObject.value=prefix+tempNum
			}
		}
}



// Original:  Cyanide_7 (leo7278@hotmail.com)
// Web Site:  http://www7.ewebcity.com/cyanide7 
// The JavaScript Source! -- http://javascript.internet.com 

function formatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}


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+$/,"");
}

// example of using trim, ltrim, and rtrim
// var myString = " hello my name is ";
// alert("*"+myString.trim()+"*");
// alert("*"+myString.ltrim()+"*");
// alert("*"+myString.rtrim()+"*");

//Examples for using the HTML encode object:

// Set the type of encoding to numerical entities -- e.g., &#60; instead of &nbsp;
// Encoder.EncodeType = "numerical";

// ... or set it to encode to HTML entities -- e.g., &nbsp; instead of &#60;
// Encoder.EncodeType = "entity";

// HTML-encode text from an input element, but prevent double encoding -- &amp;amp;.
// var encoded = Encoder.htmlEncode(document.getElementById('input'));

// Encode, but allow double encoding -- any existing entities such as &amp; will be converted to &amp;amp;
// var dblEncoded = Encoder.htmlEncode(document.getElementById('input'),true);

// Decode the now-encoded text.
// var decoded = Encoder.htmlDecode(encoded);

// Check whether the text still contains HTML/Numerical entities
// var containsEncoded = Encoder.hasEncoded(decoded);

Encoder = {

	// When encoding, we convert characters into HTML entities or "numerical" (ISO-8859-1) entities.
	EncodeType : "entity",  // entity OR numerical

	isEmpty : function(val)
	{
		if(val)
		{
			return ((val===null) || val.length==0 || /^\s+$/.test(val));
		}
		else
		{
			return true;
		}
	},
	
	// Convert HTML entities into numerical entities.
	HTML2Numerical : function(s)
	{
		var arr1 = new Array('&nbsp;','&iexcl;','&cent;','&pound;','&curren;','&yen;','&brvbar;','&sect;','&uml;','&copy;','&ordf;','&laquo;','&not;','&shy;','&reg;','&macr;','&deg;','&plusmn;','&sup2;','&sup3;','&acute;','&micro;','&para;','&middot;','&cedil;','&sup1;','&ordm;','&raquo;','&frac14;','&frac12;','&frac34;','&iquest;','&agrave;','&aacute;','&acirc;','&atilde;','&Auml;','&aring;','&aelig;','&ccedil;','&egrave;','&eacute;','&ecirc;','&euml;','&igrave;','&iacute;','&icirc;','&iuml;','&eth;','&ntilde;','&ograve;','&oacute;','&ocirc;','&otilde;','&Ouml;','&times;','&oslash;','&ugrave;','&uacute;','&ucirc;','&Uuml;','&yacute;','&thorn;','&szlig;','&agrave;','&aacute;','&acirc;','&atilde;','&auml;','&aring;','&aelig;','&ccedil;','&egrave;','&eacute;','&ecirc;','&euml;','&igrave;','&iacute;','&icirc;','&iuml;','&eth;','&ntilde;','&ograve;','&oacute;','&ocirc;','&otilde;','&ouml;','&divide;','&oslash;','&ugrave;','&uacute;','&ucirc;','&uuml;','&yacute;','&thorn;','&yuml;','&quot;','&amp;','&lt;','&gt;','&oelig;','&oelig;','&scaron;','&scaron;','&yuml;','&circ;','&tilde;','&ensp;','&emsp;','&thinsp;','&zwnj;','&zwj;','&lrm;','&rlm;','&ndash;','&mdash;','&lsquo;','&rsquo;','&sbquo;','&ldquo;','&rdquo;','&bdquo;','&dagger;','&dagger;','&permil;','&lsaquo;','&rsaquo;','&euro;','&fnof;','&alpha;','&beta;','&gamma;','&delta;','&epsilon;','&zeta;','&eta;','&theta;','&iota;','&kappa;','&lambda;','&mu;','&nu;','&xi;','&omicron;','&pi;','&rho;','&sigma;','&tau;','&upsilon;','&phi;','&chi;','&psi;','&omega;','&alpha;','&beta;','&gamma;','&delta;','&epsilon;','&zeta;','&eta;','&theta;','&iota;','&kappa;','&lambda;','&mu;','&nu;','&xi;','&omicron;','&pi;','&rho;','&sigmaf;','&sigma;','&tau;','&upsilon;','&phi;','&chi;','&psi;','&omega;','&thetasym;','&upsih;','&piv;','&bull;','&hellip;','&prime;','&prime;','&oline;','&frasl;','&weierp;','&image;','&real;','&trade;','&alefsym;','&larr;','&uarr;','&rarr;','&darr;','&harr;','&crarr;','&larr;','&uarr;','&rarr;','&darr;','&harr;','&forall;','&part;','&exist;','&empty;','&nabla;','&isin;','&notin;','&ni;','&prod;','&sum;','&minus;','&lowast;','&radic;','&prop;','&infin;','&ang;','&and;','&or;','&cap;','&cup;','&int;','&there4;','&sim;','&cong;','&asymp;','&ne;','&equiv;','&le;','&ge;','&sub;','&sup;','&nsub;','&sube;','&supe;','&oplus;','&otimes;','&perp;','&sdot;','&lceil;','&rceil;','&lfloor;','&rfloor;','&lang;','&rang;','&loz;','&spades;','&clubs;','&hearts;','&diams;');
		
		var arr2 = new Array('&#160;','&#161;','&#162;','&#163;','&#164;','&#165;','&#166;','&#167;','&#168;','&#169;','&#170;','&#171;','&#172;','&#173;','&#174;','&#175;','&#176;','&#177;','&#178;','&#179;','&#180;','&#181;','&#182;','&#183;','&#184;','&#185;','&#186;','&#187;','&#188;','&#189;','&#190;','&#191;','&#192;','&#193;','&#194;','&#195;','&#196;','&#197;','&#198;','&#199;','&#200;','&#201;','&#202;','&#203;','&#204;','&#205;','&#206;','&#207;','&#208;','&#209;','&#210;','&#211;','&#212;','&#213;','&#214;','&#215;','&#216;','&#217;','&#218;','&#219;','&#220;','&#221;','&#222;','&#223;','&#224;','&#225;','&#226;','&#227;','&#228;','&#229;','&#230;','&#231;','&#232;','&#233;','&#234;','&#235;','&#236;','&#237;','&#238;','&#239;','&#240;','&#241;','&#242;','&#243;','&#244;','&#245;','&#246;','&#247;','&#248;','&#249;','&#250;','&#251;','&#252;','&#253;','&#254;','&#255;','&#34;','&#38;','&#60;','&#62;','&#338;','&#339;','&#352;','&#353;','&#376;','&#710;','&#732;','&#8194;','&#8195;','&#8201;','&#8204;','&#8205;','&#8206;','&#8207;','&#8211;','&#8212;','&#8216;','&#8217;','&#8218;','&#8220;','&#8221;','&#8222;','&#8224;','&#8225;','&#8240;','&#8249;','&#8250;','&#8364;','&#402;','&#913;','&#914;','&#915;','&#916;','&#917;','&#918;','&#919;','&#920;','&#921;','&#922;','&#923;','&#924;','&#925;','&#926;','&#927;','&#928;','&#929;','&#931;','&#932;','&#933;','&#934;','&#935;','&#936;','&#937;','&#945;','&#946;','&#947;','&#948;','&#949;','&#950;','&#951;','&#952;','&#953;','&#954;','&#955;','&#956;','&#957;','&#958;','&#959;','&#960;','&#961;','&#962;','&#963;','&#964;','&#965;','&#966;','&#967;','&#968;','&#969;','&#977;','&#978;','&#982;','&#8226;','&#8230;','&#8242;','&#8243;','&#8254;','&#8260;','&#8472;','&#8465;','&#8476;','&#8482;','&#8501;','&#8592;','&#8593;','&#8594;','&#8595;','&#8596;','&#8629;','&#8656;','&#8657;','&#8658;','&#8659;','&#8660;','&#8704;','&#8706;','&#8707;','&#8709;','&#8711;','&#8712;','&#8713;','&#8715;','&#8719;','&#8721;','&#8722;','&#8727;','&#8730;','&#8733;','&#8734;','&#8736;','&#8743;','&#8744;','&#8745;','&#8746;','&#8747;','&#8756;','&#8764;','&#8773;','&#8776;','&#8800;','&#8801;','&#8804;','&#8805;','&#8834;','&#8835;','&#8836;','&#8838;','&#8839;','&#8853;','&#8855;','&#8869;','&#8901;','&#8968;','&#8969;','&#8970;','&#8971;','&#9001;','&#9002;','&#9674;','&#9824;','&#9827;','&#9829;','&#9830;');
		return this.swapArrayVals(s,arr1,arr2);
	},	

	// Convert numerical (ISO-8859-1) entities into HTML entities.
	NumericalToHTML : function(s){
		var arr1 = new Array('&#160;','&#161;','&#162;','&#163;','&#164;','&#165;','&#166;','&#167;','&#168;','&#169;','&#170;','&#171;','&#172;','&#173;','&#174;','&#175;','&#176;','&#177;','&#178;','&#179;','&#180;','&#181;','&#182;','&#183;','&#184;','&#185;','&#186;','&#187;','&#188;','&#189;','&#190;','&#191;','&#192;','&#193;','&#194;','&#195;','&#196;','&#197;','&#198;','&#199;','&#200;','&#201;','&#202;','&#203;','&#204;','&#205;','&#206;','&#207;','&#208;','&#209;','&#210;','&#211;','&#212;','&#213;','&#214;','&#215;','&#216;','&#217;','&#218;','&#219;','&#220;','&#221;','&#222;','&#223;','&#224;','&#225;','&#226;','&#227;','&#228;','&#229;','&#230;','&#231;','&#232;','&#233;','&#234;','&#235;','&#236;','&#237;','&#238;','&#239;','&#240;','&#241;','&#242;','&#243;','&#244;','&#245;','&#246;','&#247;','&#248;','&#249;','&#250;','&#251;','&#252;','&#253;','&#254;','&#255;','&#34;','&#38;','&#60;','&#62;','&#338;','&#339;','&#352;','&#353;','&#376;','&#710;','&#732;','&#8194;','&#8195;','&#8201;','&#8204;','&#8205;','&#8206;','&#8207;','&#8211;','&#8212;','&#8216;','&#8217;','&#8218;','&#8220;','&#8221;','&#8222;','&#8224;','&#8225;','&#8240;','&#8249;','&#8250;','&#8364;','&#402;','&#913;','&#914;','&#915;','&#916;','&#917;','&#918;','&#919;','&#920;','&#921;','&#922;','&#923;','&#924;','&#925;','&#926;','&#927;','&#928;','&#929;','&#931;','&#932;','&#933;','&#934;','&#935;','&#936;','&#937;','&#945;','&#946;','&#947;','&#948;','&#949;','&#950;','&#951;','&#952;','&#953;','&#954;','&#955;','&#956;','&#957;','&#958;','&#959;','&#960;','&#961;','&#962;','&#963;','&#964;','&#965;','&#966;','&#967;','&#968;','&#969;','&#977;','&#978;','&#982;','&#8226;','&#8230;','&#8242;','&#8243;','&#8254;','&#8260;','&#8472;','&#8465;','&#8476;','&#8482;','&#8501;','&#8592;','&#8593;','&#8594;','&#8595;','&#8596;','&#8629;','&#8656;','&#8657;','&#8658;','&#8659;','&#8660;','&#8704;','&#8706;','&#8707;','&#8709;','&#8711;','&#8712;','&#8713;','&#8715;','&#8719;','&#8721;','&#8722;','&#8727;','&#8730;','&#8733;','&#8734;','&#8736;','&#8743;','&#8744;','&#8745;','&#8746;','&#8747;','&#8756;','&#8764;','&#8773;','&#8776;','&#8800;','&#8801;','&#8804;','&#8805;','&#8834;','&#8835;','&#8836;','&#8838;','&#8839;','&#8853;','&#8855;','&#8869;','&#8901;','&#8968;','&#8969;','&#8970;','&#8971;','&#9001;','&#9002;','&#9674;','&#9824;','&#9827;','&#9829;','&#9830;');
		
		var arr2 = new Array('&nbsp;','&iexcl;','&cent;','&pound;','&curren;','&yen;','&brvbar;','&sect;','&uml;','&copy;','&ordf;','&laquo;','&not;','&shy;','&reg;','&macr;','&deg;','&plusmn;','&sup2;','&sup3;','&acute;','&micro;','&para;','&middot;','&cedil;','&sup1;','&ordm;','&raquo;','&frac14;','&frac12;','&frac34;','&iquest;','&agrave;','&aacute;','&acirc;','&atilde;','&Auml;','&aring;','&aelig;','&ccedil;','&egrave;','&eacute;','&ecirc;','&euml;','&igrave;','&iacute;','&icirc;','&iuml;','&eth;','&ntilde;','&ograve;','&oacute;','&ocirc;','&otilde;','&Ouml;','&times;','&oslash;','&ugrave;','&uacute;','&ucirc;','&Uuml;','&yacute;','&thorn;','&szlig;','&agrave;','&aacute;','&acirc;','&atilde;','&auml;','&aring;','&aelig;','&ccedil;','&egrave;','&eacute;','&ecirc;','&euml;','&igrave;','&iacute;','&icirc;','&iuml;','&eth;','&ntilde;','&ograve;','&oacute;','&ocirc;','&otilde;','&ouml;','&divide;','&oslash;','&ugrave;','&uacute;','&ucirc;','&uuml;','&yacute;','&thorn;','&yuml;','&quot;','&amp;','&lt;','&gt;','&oelig;','&oelig;','&scaron;','&scaron;','&yuml;','&circ;','&tilde;','&ensp;','&emsp;','&thinsp;','&zwnj;','&zwj;','&lrm;','&rlm;','&ndash;','&mdash;','&lsquo;','&rsquo;','&sbquo;','&ldquo;','&rdquo;','&bdquo;','&dagger;','&dagger;','&permil;','&lsaquo;','&rsaquo;','&euro;','&fnof;','&alpha;','&beta;','&gamma;','&delta;','&epsilon;','&zeta;','&eta;','&theta;','&iota;','&kappa;','&lambda;','&mu;','&nu;','&xi;','&omicron;','&pi;','&rho;','&sigma;','&tau;','&upsilon;','&phi;','&chi;','&psi;','&omega;','&alpha;','&beta;','&gamma;','&delta;','&epsilon;','&zeta;','&eta;','&theta;','&iota;','&kappa;','&lambda;','&mu;','&nu;','&xi;','&omicron;','&pi;','&rho;','&sigmaf;','&sigma;','&tau;','&upsilon;','&phi;','&chi;','&psi;','&omega;','&thetasym;','&upsih;','&piv;','&bull;','&hellip;','&prime;','&prime;','&oline;','&frasl;','&weierp;','&image;','&real;','&trade;','&alefsym;','&larr;','&uarr;','&rarr;','&darr;','&harr;','&crarr;','&larr;','&uarr;','&rarr;','&darr;','&harr;','&forall;','&part;','&exist;','&empty;','&nabla;','&isin;','&notin;','&ni;','&prod;','&sum;','&minus;','&lowast;','&radic;','&prop;','&infin;','&ang;','&and;','&or;','&cap;','&cup;','&int;','&there4;','&sim;','&cong;','&asymp;','&ne;','&equiv;','&le;','&ge;','&sub;','&sup;','&nsub;','&sube;','&supe;','&oplus;','&otimes;','&perp;','&sdot;','&lceil;','&rceil;','&lfloor;','&rfloor;','&lang;','&rang;','&loz;','&spades;','&clubs;','&hearts;','&diams;');
		
		return this.swapArrayVals(s,arr1,arr2);
	},


	// Numerically encode all unicode characters.
	numEncode : function(s)
	{
		
		if( this.isEmpty(s) ) return "";

		var e = "";
		for (var i = 0; i < s.length; i++)
		{
			var c = s.charAt(i);
			if (c < " " || c > "~")
			{
				c = "&#" + c.charCodeAt() + ";";
			}
			e += c;
		}
		return e;
	},
	
	// HTML decode numerical and HTML entities back to original values.
	htmlDecode : function(s)
	{
		var c,m,d = s;
		
		if( this.isEmpty(d) ) return "";

		// convert HTML entites back to numerical entites first
		d = this.HTML2Numerical(d);
		
		// look for numerical entities &#34;
		arr = d.match(/&#[0-9]{1,5};/g);
		
		// if no matches found in string then skip
		if(arr != null)
		{
			for( var x = 0; x < arr.length; x++ )
			{
				m = arr[x];
				c = m.substring(2,m.length-1); //get numeric part which is refernce to unicode character
				// if its a valid number we can decode
				if(c >= -32768 && c <= 65535)
				{
					// decode every single match within string
					d = d.replace(m, String.fromCharCode(c));
				}
				else
				{
					d = d.replace(m, ""); //invalid so replace with nada
				}
			}			
		}

		return d;
	},		

	// encode an input string into either numerical or HTML entities
	htmlEncode : function(s,dbl)
	{
		if( this.isEmpty(s) ) return "";

		// do we allow double encoding? E.g will &amp; be turned into &amp;amp;
		dbl = dbl | false; //default to prevent double encoding
		
		// if allowing double encoding we do ampersands first
		if(dbl)
		{
			if( this.EncodeType == "numerical" )
			{
				s = s.replace(/&/g, "&#38;");
			}
			else
			{
				s = s.replace(/&/g, "&amp;");
			}
		}

		// convert the xss chars to numerical entities ' " < >
		s = this.XSSEncode(s,false);
		
		if( this.EncodeType == "numerical" || !dbl )
		{
			// Now call function that will convert any HTML entities to numerical codes.
			s = this.HTML2Numerical(s);
		}

		// Now encode all chars above 127 -- e.g., unicode.
		s = this.numEncode(s);

		// now we know anything that needs to be encoded has been converted to numerical entities we
		// can encode any ampersands & that are not part of encoded entities
		// to handle the fact that I need to do a negative check and handle multiple ampersands &&&
		// I am going to use a placeholder

		// if we don't want double encoded entities we ignore the & in existing entities
		if(!dbl)
		{
			s = s.replace(/&#/g,"##AMPHASH##");
		
			if( this.EncodeType == "numerical" )
			{
				s = s.replace(/&/g, "&#38;");
			}
			else
			{
				s = s.replace(/&/g, "&amp;");
			}

			s = s.replace(/##AMPHASH##/g,"&#");
		}
		
		// replace any malformed entities
		s = s.replace(/&#\d*([^\d;]|$)/g, "$1");

		if(!dbl)
		{
			// safety check to correct any double encoded &amp;
			s = this.correctEncoding(s);
		}

		// now do we need to convert our numerical encoded string into entities
		if( this.EncodeType == "entity" )
		{
			s = this.NumericalToHTML(s);
		}

		return s;					
	},

	// Encodes the basic 4 characters used to malform HTML in XSS hacks
	XSSEncode : function(s,en)
	{
		if( !this.isEmpty(s) )
		{
			en = en || true;
			// do we convert to numerical or html entity?
			if(en)
			{
				s = s.replace(/\'/g,"&#39;"); //no HTML equivalent as &apos is not cross-browser supported
				s = s.replace(/\"/g,"&quot;");
				s = s.replace(/</g,"&lt;");
				s = s.replace(/>/g,"&gt;");
			}
			else
			{
				s = s.replace(/\'/g,"&#39;"); //no HTML equivalent as &apos is not cross-browser supported
				s = s.replace(/\"/g,"&#34;");
				s = s.replace(/</g,"&#60;");
				s = s.replace(/>/g,"&#62;");
			}
			return s;
		}
		else
		{
			return "";
		}
	},

	// returns true if a string contains html or numerical encoded entities
	hasEncoded : function(s)
	{
		if( /&#[0-9]{1,5};/g.test(s) )
		{
			return true;
		}
		else if ( /&[A-Z]{2,6};/gi.test(s) )
		{
			return true;
		}
		else
		{
			return false;
		}
	},

	// will remove any unicode characters
	stripUnicode : function(s)
	{
		return s.replace(/[^\x20-\x7E]/g,"");
	},

	// corrects any double encoded &amp; entities e.g &amp;amp;
	correctEncoding : function(s)
	{
		return s.replace(/(&amp;)(amp;)+/,"$1");
	},


	// Function to loop through an array swaping each item with the value from another array e.g swap HTML entities with Numericals
	swapArrayVals : function(s,arr1,arr2)
	{
		if ( this.isEmpty(s) ) return "";
		var re;
		if ( arr1 && arr2 )
		{
			//ShowDebug("in swapArrayVals arr1.length = " + arr1.length + " arr2.length = " + arr2.length)
			// array lengths must match
			if ( arr1.length == arr2.length )
			{
				for ( var x = 0, i = arr1.length; x < i; x++ )
				{
					re = new RegExp(arr1[x], 'g');
					s = s.replace(re,arr2[x]); //swap arr1 item with matching item from arr2	
				}
			}
		}
		return s;
	},

	inArray : function( item, arr ) 
	{
		for ( var i = 0, x = arr.length; i < x; i++ )
		{
			if ( arr[i] === item )
			{
				return i;
			}
		}
		return -1;
	}

}

// Synonym
function HTML_Encode(strString)
{
		HTML_Encode = Encoder.htmlEncode(strString)
}

// Synonym
function HTML_Decode(strString)
{
		HTML_Decode = Encoder.htmlDecode(strString)
}

function URLDecode(strString) 
{
  return unescape(strString); 
}


////////////////////////////////////////////////////////////////
// In VBScript:
// The Asc() function returns the ASCII value for the first character of the string. 
// The charCodeAt method takes for parameter an index and returns the ASCII code for the character at the specified index in the string. So if you need to get ASCII value for the first character, pass 0 for the AsciiNum parameter.

function Asc(String)
{
	return String.charCodeAt(0);
}

function Chr(String,AsciiNum)
{
	return String.fromCharCode(AsciiNum)
}

////////////////////////////////////////////////////////////////


function Left(str, n)
{
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n)
{
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}


////////////////////////////////////////////////////////////////

function printPreview()
{
var OLECMDID = 7;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 1 - open window
* 4 - Save As
*/
var PROMPT = 1;		 // 2 = DONTPROMPTUSER
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = "";
}



////////////////////////////////////////////////////////////////

//Clock
var timerID = null
var timerRunning = false

function StopClock()
{
	if(timerRunning)
		clearTimeout(timerID)
	timerRunning = false
}

function StartClock()
{
	StopClock()
	ShowTime()
}

function ShowTime()
{
	var now = new Date()
	var hours = now.getHours()
	var minutes = now.getMinutes()
	var seconds = now.getSeconds()
	var timeValue = "" + ((hours > 12) ? hours - 12 : hours)
	timeValue  += ((minutes < 10) ? ":0" : ":") + minutes
	timeValue  += ((seconds < 10) ? ":0" : ":") + seconds
	timeValue  += (hours >= 12) ? " PM" : " AM"
	//document.moon.time.value = timeValue 
	timerID = setTimeout("ShowTime()",1000)
	timerRunning = true
}
	
function ShowTimeSince()
{
	var now = new Date()
	var duration = now	
	// <% = dtmResponseTime %>
	// - < % = CDate(strResponseHours & ":" & strResponseMinutes & ":" & strResponseSeconds) % >
	var hours = duration.getHours()
	var minutes = duration.getMinutes()
	var seconds = duration.getSeconds()
	var timeValue = "" + hours
	// ((hours > 12) ? hours - 12 : hours)
	timeValue  += ((minutes < 10) ? ":0" : ":") + minutes
	timeValue  += ((seconds < 10) ? ":0" : ":") + seconds
	// timeValue  += (hours >= 12) ? " PM" : " AM"
	document.ResponseTime.time.value = timeValue 
	timerID = setTimeout("ShowTimeSince()",1000)
	timerRunning = true
}


////////////////////////////////////////////////////////////////


function preloadImages(strImagesPath)
{
	preloadedImage1 = new Image
	preloadedImage1.src = strImagesPath+"folder-closed.gif"
	preloadedImage2 = new Image
	preloadedImage2.src = strImagesPath+"folder-open.gif"
	preloadedImage1 = new Image
	preloadedImage1.src = strImagesPath+"folder-closed-large.gif"
	preloadedImage2 = new Image
	preloadedImage2.src = strImagesPath+"folder-open-large.gif"
}


////////////////////////////////////////////////////////////////


function ObjectShowHide(ID) 
{
     // alert('clicked');
     var objBox = document.getElementById(ID);
     var objImage = document.getElementById(ID + '_image');
     var objShowHide = document.getElementById(ID + '_ShowOrHide');
    
     if ( document.getElementById(ID).style.display != "none" ) 
	      {
			  objBox.style.display = "none";
			  objImage.src = document.getElementById("strImagesPath").value + "folder-closed-large.gif";
			  objShowHide.innerHTML = "Show";
			  SaveCookie(ID, 'Hide');
	      }
     else 
	      {
			  objBox.style.display = "";
			  objImage.src = document.getElementById("strImagesPath").value + "folder-open-large.gif";
			  objShowHide.innerHTML = "Hide";
			  SaveCookie(ID, 'Show');
	      }
}


function ObjectShowHideSmall(ID) 
{
     //alert('clicked')
     var objBox = document.getElementById(ID);
     var objImage = document.getElementById(ID + '_image');
     var objShowHide = document.getElementById(ID + '_ShowOrHide');
    
     if (document.getElementById(ID).style.display != "none") 
	      {
	      objBox.style.display = "none";
	      objImage.src = document.getElementById("strImagesPath").value+"folder-closed-small.gif";
	      objShowHide.innerHTML = "Show";
	      SaveCookie(ID, 'Hide');
	      }
     else 
	      {
	      objBox.style.display = "";
	      objImage.src = document.getElementById("strImagesPath").value+"folder-open-small.gif";
	      objShowHide.innerHTML = "Hide";
	      SaveCookie(ID, 'Show');
	      }
}



function ObjectShowHideLarge(ID) 
{
     // alert('clicked');
     var objBox = document.getElementById(ID);
     var objImage = document.getElementById(ID + '_image');
     var objShowHide = document.getElementById(ID + '_ShowOrHide');
    
     if ( document.getElementById(ID).style.display != "none") 
	      {
			  objBox.style.display = "none";
			  objImage.src = document.getElementById("strImagesPath").value + "folder-closed-large.gif";
			  objShowHide.innerHTML = "Show";
			  SaveCookie(ID, 'Hide');
	      }
     else 
	      {
			  objBox.style.display = "";
			  objImage.src = document.getElementById("strImagesPath").value + "folder-open-large.gif";
			  objShowHide.innerHTML = "Hide";
			  SaveCookie(ID, 'Show');
	      }
}


function ObjectShowHide_13x13(ID) 
{
     // alert('clicked');
     var objBox = document.getElementById(ID);
     var objImage = document.getElementById(ID + '_image');
     var objShowHide = document.getElementById(ID + '_ShowOrHide');
    
     if ( document.getElementById(ID).style.display != "none" ) 
	      {
			  objBox.style.display = "none";
			  objImage.src = document.getElementById("strImagesPath").value + "folder-closed_13x13.jpg";
			  objShowHide.innerHTML = "Show";
			  SaveCookie(ID, 'Hide');
	      }
     else 
	      {
			  objBox.style.display = "";
			  objImage.src = document.getElementById("strImagesPath").value + "folder-opened_13x13.jpg";
			  objShowHide.innerHTML = "Hide";
			  SaveCookie(ID, 'Show');
	      }
}


function ObjectShow(ID) 
{
     //alert('clicked')
     var objBox = document.getElementById(ID);
     var objImage = document.getElementById(ID + '_image');
     var objShowHide = document.getElementById(ID + '_ShowOrHide');

      objBox.style.display = "";
      objImage.src = document.getElementById("strImagesPath").value+"folder-open-large.gif";
      objShowHide.innerHTML = "Hide";
}

function ObjectHide(ID) 
{
     //alert('clicked')
     var objBox = document.getElementById(ID);
     var objImage = document.getElementById(ID + '_image');
     var objShowHide = document.getElementById(ID + '_ShowOrHide');
    
      objBox.style.display = "none";
      objImage.src = document.getElementById("strImagesPath").value+"folder-closed-large.gif";
      objShowHide.innerHTML = "Show";
}


function ShowHide(ID) 
{
    //alert('clicked')
    var objBox = document.getElementById(ID)
     var objImage = document.getElementById(ID + '_image')
    
     if (document.getElementById(ID).style.display == "") 
	     {
	      objBox.style.display = "none";
	      objImage.src = document.getElementById("strImagesPath").value+"max-arrow.gif";
	      SaveCookie(ID, 'Hide');
	     }
     else 
	     {
	      objBox.style.display = "";
	      objImage.src = document.getElementById("strImagesPath").value+"min-arrow.gif";
	      SaveCookie(ID, 'Show');
	     }
}




function ElementShowHide(ID) 
{
     // alert('clicked');
     var objBox = document.getElementById(ID);
     var objImage = document.getElementById(ID + '_image');
     var objShowHide = document.getElementById(ID + '_ShowOrHide');
    
     if ( document.getElementById(ID).style.display != "none" ) 
	      {
			  objBox.style.display = "none";
			  objImage.src = document.getElementById("strImagesPath").value + "folder-closed-large.gif";
			  objShowHide.innerHTML = "Show";
			  SaveCookie(ID, 'Hide');
	      }
     else 
	      {
			  objBox.style.display = "";
			  objImage.src = document.getElementById("strImagesPath").value + "folder-open-large.gif";
			  objShowHide.innerHTML = "Hide";
			  SaveCookie(ID, 'Show');
	      }
}


function ElementShowHideSmall(ID) 
{
     //alert('clicked')
     var objBox = document.getElementById(ID);
     var objImage = document.getElementById(ID + '_image');
     var objShowHide = document.getElementById(ID + '_ShowOrHide');
    
     if (document.getElementById(ID).style.display != "none") 
	      {
	      objBox.style.display = "none";
	      objImage.src = document.getElementById("strImagesPath").value+"folder-closed-small.gif";
	      objShowHide.innerHTML = "Show";
	      SaveCookie(ID, 'Hide');
	      }
     else 
	      {
	      objBox.style.display = "";
	      objImage.src = document.getElementById("strImagesPath").value+"folder-open-small.gif";
	      objShowHide.innerHTML = "Hide";
	      SaveCookie(ID, 'Show');
	      }
}



function ElementShowHideLarge(ID) 
{
     // alert('clicked');
     var objBox = document.getElementById(ID);
     var objImage = document.getElementById(ID + '_image');
     var objShowHide = document.getElementById(ID + '_ShowOrHide');
    
     if ( document.getElementById(ID).style.display != "none") 
	      {
			  objBox.style.display = "none";
			  objImage.src = document.getElementById("strImagesPath").value + "folder-closed-large.gif";
			  objShowHide.innerHTML = "Show";
			  SaveCookie(ID, 'Hide');
	      }
     else 
	      {
			  objBox.style.display = "";
			  objImage.src = document.getElementById("strImagesPath").value + "folder-open-large.gif";
			  objShowHide.innerHTML = "Hide";
			  SaveCookie(ID, 'Show');
	      }
}


function ElementShowHide_13x13(ID) 
{
     // alert('clicked');
     var objBox = document.getElementById(ID);
     var objImage = document.getElementById(ID + '_image');
     var objShowHide = document.getElementById(ID + '_ShowOrHide');
    
     if ( document.getElementById(ID).style.display != "none" ) 
	      {
			  objBox.style.display = "none";
			  objImage.src = document.getElementById("strImagesPath").value + "folder-closed_13x13.jpg";
			  objShowHide.innerHTML = "Show";
			  SaveCookie(ID, 'Hide');
	      }
     else 
	      {
			  objBox.style.display = "";
			  objImage.src = document.getElementById("strImagesPath").value + "folder-opened_13x13.jpg";
			  objShowHide.innerHTML = "Hide";
			  SaveCookie(ID, 'Show');
	      }
}


function ElementShow(ID) 
{
     //alert('clicked')
     var objBox = document.getElementById(ID);
     var objImage = document.getElementById(ID + '_image');
     var objShowHide = document.getElementById(ID + '_ShowOrHide');

      objBox.style.display = "";
      objImage.src = document.getElementById("strImagesPath").value+"folder-open-large.gif";
      objShowHide.innerHTML = "Hide";
}

function ElementHide(ID) 
{
     //alert('clicked')
     var objBox = document.getElementById(ID);
     var objImage = document.getElementById(ID + '_image');
     var objShowHide = document.getElementById(ID + '_ShowOrHide');
    
      objBox.style.display = "none";
      objImage.src = document.getElementById("strImagesPath").value+"folder-closed-large.gif";
      objShowHide.innerHTML = "Show";
}





// ==================================================================================================

function setCookie(cookieName, value, expireDays)
{
var expirationDate = new Date();  // current date & time
expirationDate.setDate(expirationDate.getDate() + expireDays);
document.cookie = cookieName + "=" + escape(value) + ((expiredays==null) ? "" : ";expires=" + expirationDate.toGMTString());
}

function getCookie(cookieName)
{
if (document.cookie.length > 0)
  {
  var c_start = document.cookie.indexOf(cookieName + "=");
  if ( c_start != -1 )
    {
    c_start = c_start + cookieName.length + 1;
    var c_end = document.cookie.indexOf(";", c_start);
    if ( c_end == -1 ) c_end = document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function getAllCookies()	// as a string of name=value; pairs
{
	return unescape(document.cookie);
}

// var x = returnCookieValue("username");
function returnCookieValue(cookieName)
{
  var results = document.cookie.match ( '(^|;) ?' + cookieName + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

// deleteCookie("username");
function deleteCookie(cookieName)
{
  var cookieDate = new Date();  // current date & time
  cookieDate.setTime(cookieDate.getTime() - 1);
  document.cookie = cookieName += "=; expires=" + cookieDate.toGMTString();
}

// expireCookie("username");
function expireCookie(cookieName)
{
  var cookieDate = new Date();  // current date & time
  cookieDate.setTime(cookieDate.getTime() - 1);
  document.cookie = cookieName += "=; expires=" + cookieDate.toGMTString();
}


function checkCookie_UserName()
{
username = getCookie('username');
if ( username != null && username != "" )
  {
  alert('Welcome again ' + username + '!');
  }
else
  {
  username = prompt('Please enter your name:', "");
  if (username != null && username != "")
    {
    setCookie('username', username, 365);
    }
  }
}


function SaveCookie(name, value)
{
 var expirationDate = new Date();
 expirationDate.setTime (expirationDate.getTime() + (24 * 60 * 60 * 1000 * 365));
 document.cookie = name + "=" + escape(value) + "; expires=" + expirationDate;
}


////////////////////////////////////////////////////////////////


// JavaScript function for loading an XML string into an XML document object.

function loadXMLStringToXMLDoc(xmlString) 
{
if (window.DOMParser)
  {
  parser = new DOMParser();
  xmlDoc = parser.parseFromString(xmlString,"text/xml");
  }
else // Internet Explorer
  {
  xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async = "false";
  xmlDoc.loadXML(xmlString); 
  }
return xmlDoc;
}
// Example:
// xmlDoc = loadXMLStringToXMLDoc(xmlString);
// aryFields = xmlDoc.getElementsByTagName("field");		/ 0 indexed

// Example:
// xmlDoc = loadXMLStringToXMLDoc(xmlString);
// aryTitles = xmlDoc.getElementsByTagName("title");
// for (i = 0; i < aryTitles.length; i++)
//  {
//  document.write(aryTitles[i].childNodes[0].nodeValue);
//  document.write("<br />");
//  }

// Traversing Nodes -- The following code loops through the child nodes that are also element nodes of the root node:
// Example:
// xmlDoc = loadXMLStringToXMLDoc(xmlString);
// x = xmlDoc.documentElement.childNodes;
// for (i = 0; i < x.length; i++)
// {
//   if (x[i].nodeType == 1)
	 // Process only element nodes (type 1)  
// 	 {	
//   document.write(x[i].nodeName);
//   document.write("<br />");
//   }
// }


// JavaScript function for loading an XML file (document) into an XML document object.

function loadXMLDoc(strPathtoXMLDocument)
{
if (window.XMLHttpRequest)
  {
  xhttp = new XMLHttpRequest();
  }
else
  {
  xhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
xhttp.open("GET", strPathtoXMLDocument, false);	// Async = false
xhttp.send("");
return xhttp.responseXML;
}


////////////////////////////////////////////////////////////////



// Copyright 2002 Bontrager Connection, LLC
// <script type="text/javascript" language="JavaScript">
// var calendarDate = getCalendarDate();
// var clockTime = getClockTime();
// document.write('Date is ' + calendarDate);
// document.write('<br>');
// document.write('Time is ' + clockTime);
//
function getCalendarDate()
{
   var months = new Array(13);
   months[0]  = "January";
   months[1]  = "February";
   months[2]  = "March";
   months[3]  = "April";
   months[4]  = "May";
   months[5]  = "June";
   months[6]  = "July";
   months[7]  = "August";
   months[8]  = "September";
   months[9]  = "October";
   months[10] = "November";
   months[11] = "December";
   var now         = new Date();
   var monthnumber = now.getMonth();
   var monthname   = months[monthnumber];
   var monthday    = now.getDate();
   var year        = now.getYear();
   if(year < 2000) { year = year + 1900; }
   var dateString = monthname +
                    ' ' +
                    monthday +
                    ', ' +
                    year;
   return dateString;
} // function getCalendarDate()

function getClockTime()
{
   var now    = new Date();
   var hour   = now.getHours();
   var minute = now.getMinutes();
   var second = now.getSeconds();
   var ap = "AM";
   if (hour   > 11) { ap = "PM";             }
   if (hour   > 12) { hour = hour - 12;      }
   if (hour   == 0) { hour = 12;             }
   if (hour   < 10) { hour   = "0" + hour;   }
   if (minute < 10) { minute = "0" + minute; }
   if (second < 10) { second = "0" + second; }
   var timeString = hour +
                    ':' +
                    minute +
                    ':' +
                    second +
                    " " +
                    ap;
   return timeString;
} // function getClockTime()


