Encoder = {

	// When encoding do we convert characters into html or numerical 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 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 encodes 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;
	}

}










var general = {


	ajaxRequest : function(scriptURL, handle) {
		
		var rand = new Date().getTime();
		if (/\?/.test(scriptURL)) scriptURL += "&ajax_random="+rand;
		else scriptURL += "?&ajax_random="+rand;
		
		if (/www\./.test(window.location.href)) {
			if (!(/www\./.test(scriptURL))) {
				scriptURL = scriptURL.replace("http://", "http://www.");
			}
		}
		else {
			if (/www\./.test(scriptURL)) {
				scriptURL = scriptURL.replace("www.", "");
			}
		}
		
		var xmlHttp;
		try {
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e) {
			// Internet Explorer
			try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					alert("Your browser does not support AJAX! Please update to the latest version.");
					return false;
				}
			}
		}
		
		xmlHttp.onreadystatechange = function() {
			
			if(xmlHttp.readyState==4) {
				handle(xmlHttp.responseText);
			}
		}
		
		//try {
			xmlHttp.open("GET", scriptURL, true);
			xmlHttp.send(null);
		//}
		/*catch(err) {
		
			scriptURL = scriptURL.replace("www.", "");
			
			try {
				xmlHttp.open("GET", scriptURL, true);
				xmlHttp.send(null);
			}
			catch(err) {
				alert(err);
			}
		}*/
	},
	
	urlEscape : function(str) {
		
		//str = str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
		
		//var temp_div = document.createElement('div');
		//temp_div.innerHTML = str;
		//str = temp_div.nodeValue;
		
		//var tarea = document.createElement('textarea');
		//tarea.innerHTML = str;
		//str = tarea.value;
		
		
		/*str = str.replace('&amp;', '&');
		str = str.replace('&nbsp;', ' ');
		str = str.replace('&quot;', '"');
		str = str.replace('&lt;', '<');
		str = str.replace('&gt;', '>');*/
		
		//str = str.replace("$", "");
		str = str.replace("(", "");
		str = str.replace(")", "");
		//str = str.replace("?", "");
		//str = str.replace(";", "");
		
		str = Encoder.htmlDecode(str);
		
		str = str.replace("$", "");
		str = str.replace("(", "");
		str = str.replace(")", "");
		str = str.replace("?", "");
		str = str.replace(";", "");
		
		str = escape(str);
		
		return str;
	},
	
	formGetString : function(form) {
		
		if (typeof(form) == 'string') form = document.getElementById(formID);
		
		var varString = '';
		
		var inputs = form.getElementsByTagName("input");
		for (var i = 0; i < inputs.length; i++) {
			
			if (inputs[i].name == "") continue;
			
			var child = inputs[i];
			var type = child.getAttribute("type").toLowerCase();
			
			if (type == "text" || type == "hidden") varString += "&"+general.urlEscape(child.name)+"="+general.urlEscape(child.value);
				
			if (type == "checkbox") {
			
				if (child.checked) varString += "&"+general.urlEscape(child.name)+"="+general.urlEscape(child.value);
				else varString += "&"+general.urlEscape(child.name)+"="
			}
			
			if (type == "radio") if (child.checked) varString += "&"+general.urlEscape(child.name)+"="+general.urlEscape(child.value);
		}
		
		inputs = form.getElementsByTagName("select");
		for (var i = 0; i < inputs.length; i++) {
			
			if (inputs[i].name == "") continue;
			if (inputs[i].selectedIndex != '-1')
				varString += "&"+general.urlEscape(inputs[i].name)+"="+general.urlEscape(inputs[i].options[inputs[i].selectedIndex].value);
		}
		
		inputs = form.getElementsByTagName("textarea");
		for (var i = 0; i < inputs.length; i++) {
			if (inputs[i].name == "") continue;
			varString += "&"+general.urlEscape(inputs[i].name)+"="+general.urlEscape(inputs[i].value);
		}
		
		return varString;
	},
	

	
	
	blocker : function(_class) {
		
		_class = (typeof(_class) == 'undefined') ? '' : _class;
		
		var id = 'general_blocker';
		var blocker = general.createElement('div', _class+"_"+id, _class+'_blocker');
		
		//blocker.style.zIndex = "1000";
		blocker.style.width = '100%';
		blocker.style.height = '100%';
		blocker.style.position = 'fixed';
		blocker.style.top = '0px';
		blocker.style.left = '0px';
		
		if (_class == '') {
			blocker.style.backgroundColor = '#000';
			blocker.style.opacity = '0.3';
			blocker.style.filter = 'alpha(opacity=30)';
		}
		document.body.appendChild(blocker);
		
		return _class+"_"+id;
	},
	
	confirmation : function(_class, _title, _message, action) {
		
		var _id = "_general_confirmation_box";
		
		var blockerID = general.blocker(_class);
		
		var wrapper = general.createElement('div', _id, _class);
		if (_class == '') {
			wrapper.style.position = 'fixed';
			wrapper.style.top = '50%';
			wrapper.style.left = '50%';
			wrapper.style.marginLeft = '-220px';
			wrapper.style.marginTop = '-95px';
			wrapper.style.width = '400px';
			wrapper.style.padding = '0px 0px 20px 0px';
			wrapper.style.backgroundColor = '#FFF';
			wrapper.style.border = '1px solid #555';
		}
		
		var title = general.createElement('div', _id+'_title', _class+'_title');
		title.appendChild( document.createTextNode(_title) );
		if (_class == '') {
			title.style.padding = '8px';
			title.style.backgroundColor = '#555';
			title.style.color = '#FFF';
			title.style.fontSize = '13px';
			title.style.textAlign = 'center';
			title.style.fontWeight = 'bold';
		}
		
		var message = general.createElement('p', _id+'_message', _class+'_message');
		message.appendChild( document.createTextNode(_message) );
		if (_class == '') {
			message.style.padding = '15px 10px 15px 10px';
		}
		
		var yesBtn = general.createElement('div', _id+'_yes_btn', _class+'_yes_btn');
		yesBtn.appendChild( document.createTextNode('Yes') );
		yesBtn.onclick = function() {
			var temp = document.getElementById(_id);
			document.body.removeChild(temp);
			temp = document.getElementById(blockerID);
			document.body.removeChild(temp);
			
			action();
		};
		if (_class == '') {
			yesBtn.style.cssFloat = 'left';
			yesBtn.style.styleFloat = 'left';
			yesBtn.style.width = '120px';
			yesBtn.style.margin = '0px 40px 0px 40px';
			yesBtn.style.padding = '5px 0px 5px 0px';
			yesBtn.style.cursor = 'pointer';
			yesBtn.style.backgroundColor = '#DDD';
			yesBtn.style.textAlign = 'center';
			yesBtn.style.fontWeight = 'bold';
		}
		
		var noBtn = general.createElement('div', _id+'_no_btn', _class+'_no_btn');
		noBtn.appendChild( document.createTextNode('No') );
		noBtn.onclick = function() {
			var temp = document.getElementById(_id);
			document.body.removeChild(temp);
			temp = document.getElementById(blockerID);
			document.body.removeChild(temp);
		};
		if (_class == '') {
			noBtn.style.width = '120px';
			noBtn.style.margin = '0px 40px 0px 240px';
			noBtn.style.padding = '5px 0px 5px 0px';
			noBtn.style.cursor = 'pointer';
			noBtn.style.backgroundColor = '#DDD';
			noBtn.style.textAlign = 'center';
			noBtn.style.fontWeight = 'bold';
		}
		
		wrapper.appendChild(title);
		wrapper.appendChild(message);
		wrapper.appendChild(yesBtn);
		wrapper.appendChild(noBtn);
		
		document.body.appendChild(wrapper);
	},
	
	notification : function(_class, _title, _message) {
		
		var _id = "_general_notification_box";
		
		var blockerID = general.blocker(_class);
		
		var wrapper = general.createElement('div', _id, _class);
		if (_class == '') {
			wrapper.style.position = 'fixed';
			wrapper.style.top = '50%';
			wrapper.style.left = '50%';
			wrapper.style.marginLeft = '-220px';
			wrapper.style.marginTop = '-95px';
			wrapper.style.width = '400px';
			wrapper.style.padding = '0px 0px 20px 0px';
			wrapper.style.backgroundColor = '#FFF';
			wrapper.style.border = '1px solid #555';
		}
		
		var title = general.createElement('div', _id+'_title', _class+'_title');
		title.appendChild( document.createTextNode(_title) );
		if (_class == '') {
			title.style.padding = '8px';
			title.style.backgroundColor = '#555';
			title.style.color = '#FFF';
			title.style.fontSize = '13px';
			title.style.textAlign = 'center';
			title.style.fontWeight = 'bold';
		}
		
		var message = general.createElement('p', _id+'_message', _class+'_message');
		message.appendChild( document.createTextNode(_message) );
		if (_class == '') {
			message.style.padding = '15px 10px 15px 10px';
		}
		
		var btn = general.createElement('div', _id+'_btn', _class+'_btn');
		btn.appendChild( document.createTextNode('OK') );
		btn.onclick = function() {
			var temp = document.getElementById(_id);
			document.body.removeChild(temp);
			temp = document.getElementById(blockerID);
			document.body.removeChild(temp);
		};
		if (_class == '') {
			btn.style.width = '120px';
			btn.style.margin = '0px auto 0px auto';
			btn.style.padding = '5px 0px 5px 0px';
			btn.style.cursor = 'pointer';
			btn.style.backgroundColor = '#DDD';
			btn.style.textAlign = 'center';
			btn.style.fontWeight = 'bold';
		}
		
		wrapper.appendChild(title);
		wrapper.appendChild(message);
		wrapper.appendChild(btn);
		document.body.appendChild(wrapper);
	},
	
	
	
	
	
	
	
	
	setMessage : function(id, theClass, message) {
		
		var element = document.getElementById(id);
		element.className = theClass;
		element.innerHTML = message;
	},
	
	hide : function(id) {
		document.getElementById(id).style.display = 'none';
	},
	
	show : function(id) {
		document.getElementById(id).style.display = '';
	},
	
	toggleVisibility : function(id, button) {
		
		var target = document.getElementById(id);
		general.setVisibility(id, button, (target.style.display == 'none'));
	},
	
	setVisibility : function(id, button, show) {
		
		button = typeof(button) != 'undefined' ? button : 0;
		if (typeof(button) == 'string') button = document.getElementById(button);
		
		var target = document.getElementById(id);
		
		if (show) {
			
			if (button != 0) button.className = button.className.replace("expand", "collapse");
			target.style.display = '';
		}
		
		else {
			
			if (button != 0) button.className = button.className.replace("collapse", "expand");
			target.style.display = 'none';
		}
	},
	
	
	
	
	
	
	hasClass : function(obj, name) {
	
		var re = new RegExp("(^| )"+name+"( |$)");  
		
		return re.test(obj.className);
	},
	
	addClass : function(target, theClass) {
	
		if (!general.hasClass(target, theClass)) {
		
			if (target.className == "")
				target.className = theClass;
			else
				target.className += " " + theClass;
		}
	},

	removeClass : function(target, theClass) {
	
		var pattern = new RegExp("(^| )"+theClass+"( |$)");
		
		target.className = target.className.replace(pattern, "$1");
		target.className = target.className.replace(/ $/, "");
		target.className = target.className.replace(/^ /, "");
	},
	
	swapClass : function(target, oldClass, newClass) {
		
		if (!general.hasClass(target, oldClass)) return;
		
		general.removeClass(target, oldClass);
		general.addClass(target, newClass);
	},
	
	
	
	
	
	
	insertAfter : function(referenceNode, newNode) {
	
		referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
	},
	
	createElement : function(_type, _id, _className) {
		
		var object = document.createElement(_type);
		
		if (_id != "") {
			
			object.id = _id;
			if (_type == "input" || _type == "textarea" || _type == "select") object.name = _id;
		}
		
		if (_className != "") object.className = _className;
		
		return object;
	},
	
	
	
	
	
	
	validate : function(obj) {
	
		var rules = [
					/./,
					/^\d+$/,
					/(^\d+\.{1}\d*$)|(^\d+$)|(^\.\d+$)/,
					/^\w+$/,
					/^[\w\-]+$/,
					
					/^\d{4}$/,
					/^\d{2}$/,
					/(^0?[1-9]$)|(^1[012]$)/,
					/(^0?[1-9]$)|(^[12]\d$)|(^3[01]$)/,
					
					/^[0-9\-\.\(\) extnsio]{7,25}$/,
					/^\d{3}\-\d{3}\-\d{4}$/,
					/^\d{3}\-\d{3}\-\d{4}([ x]{1,2}\d{1,5})?$/,
					/^\d{3}\-\d{3}\-\d{4}.{0,10}$/,
					
					/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/
					];
		
		var classes = [
					"v_required",
					"v_positive_integer",
					"v_positive_decimal",
					"v_word_characters",
					"v_word_characters_hyphen",
					
					"v_long_year",
					"v_short_year",
					"v_month",
					"v_day",
					
					"v_phone_flexible", //(.- 0123456789
					"v_phone_1", //###-###-####
					"v_phone_2", //###-###-#### followed by 2 space or x, followed by 1-4 digits
					"v_phone_3", //###-###-#### followed by anything up to 10 characters
					
					"v_email"
					];
		
		for (var i in rules) {
			
			if ( general.hasClass(obj, classes[i]) ) {
				
				if (!rules[i].test(obj.value)) 
					if (!(general.hasClass(obj, "v_optional") && obj.value == "")) return false;
			}
		}
		
		return true;
	},
	
	validateAndStyle : function(element, invalidStyle) {
		
		invalidStyle = (typeof(invalidStyle) == 'undefined') ? '' : invalidStyle;
		
		var result = general.validate(element);
		
		if (result) general.removeClass(element, invalidStyle);
		else general.addClass(element, invalidStyle);
		
		return result;
	},
	
	validateForm : function(form, invalidStyle) {
		
		invalidStyle = (typeof(invalidStyle) == 'undefined') ? '' : invalidStyle;
		
		var result = true;
		
		// Supports matching 0-9
		var matching = [[], [], [], [], [], [], [], [], [], []];
		var elements = [[], [], [], [], [], [], [], [], [], []];
		
		for (var i = 0; i < form.elements.length; i++) {
		
			var element = form.elements[i];
			
			if (invalidStyle == '') {
				if (!general.validate(element)) result = false;
			}
			else {
				if (!general.validateAndStyle(element, invalidStyle)) result = false;
			}
			
			var matches = /v_match(\d+?)/.exec(element.className);
			if (matches)  {
				if (matches[1]*1 >= 0 && matches[1]*1 <= 9) {
					matching[ matches[1]*1 ].push(element.value);
					elements[ matches[1]*1 ].push(element);
				}
			}
		}
		
		//check matching
		for (var i = 0; i < 10; i++) {
			
			if (matching[i].length == 0) continue;
			
			var matchingResult = true;
			
			for (var j = 1; j < matching[i].length; j++) {
				
				if (matching[i][j] != matching[i][0]) {
					
					matchingResult = false;
					result = false;
				}
			}
			
			if (!matchingResult) {
				for (var j = 0; j < matching[i].length; j++) {
					general.addClass(elements[i][j], invalidStyle);
				}
			}
		}	
		
		return result;
	},
	
	
	
	
	
	
	/*
	If the trees' location and placementType props are defined, then this function will handle it and return null.
	Otherwise, it will return an array of arrays.
	Ex: [ [first tree parent nodes], [second tree parent nodes], etc ]
	*/
	
	writeHTML : function(response) {
		
		// DEBUG, TAKE OUT IN RELEASE ------
		if (response.charAt(0) != "{") {
			alert(response);
			return;
		}
		// END DEBUG -----------------------
		
		if (response == "") return;
		
		var json = eval("("+response+")");
		
		if (typeof(json.htmlTrees) == 'undefined') return;
		
		var treeNodes = [];
		
		for (var i = 0; i < json.htmlTrees.length; i++) {
			
			if (typeof(json.htmlTrees[i].location) == 'undefined') continue;
			if (typeof(json.htmlTrees[i].addType) == 'undefined') continue;
			
			var result = general.writeHTMLBlock(json.htmlTrees[i], json.htmlTrees[i].location, json.htmlTrees[i].addType);
			
			if (result !== null) treeNodes.push(result);
		}
		
		return treeNodes;
	},
	
	/*
	type : ex: div, input, p, table
	attributes: id => 'the_id', name => 'the_name', readonly => 'readonly', etc
	children: an array of objects like this
	innerHTML: the text of a text node (a node with type=='text')
	*/
	
	writeHTMLBlock : function(json, location, placementType) {
		
		if (typeof(json.type) == 'undefined') {
			
			alert("writeHTMLBlock error: node does not have a type property defined!");
			return "";
		}
		
		// Parent of the json node-tree
		if (json.type == '') {
			
			if (typeof(json.children) == 'undefined' && placementType != 'replace') {
				return null;
			}
			
			// If no children, but we are set to replace, clear out the replace target's innerHTML
			if (typeof(json.children) == 'undefined' && location != '') {
				if (placementType == 'replace') {
					var place = document.getElementById(location);
					if ( place.hasChildNodes() ) {
						while ( place.childNodes.length >= 1 ) place.removeChild( place.firstChild );       
					}
				}
				return null;
			}
			if (json.children.length == 0 && location != '') {
				if (placementType == 'replace') {
					var place = document.getElementById(location);
					if ( place.hasChildNodes() ) {
						while ( place.childNodes.length >= 1 ) place.removeChild( place.firstChild );       
					}
				}
				return null;
			}
			
			var element = general.writeHTMLBlock(json.children[0], 0, 0);
			var additionalNodes = [];
			
			if (json.children.length > 1) {
				
				for (var i = 1; i < json.children.length; i++) {
					
					var child = general.writeHTMLBlock(json.children[i], 0, 0);
					additionalNodes[i-1] = child;
				}
			}
			
			placementType = typeof(placementType) == 'undefined' ? 'append' : placementType;
			
			var place = (location != "") ? document.getElementById(location) : null;
			
			switch (placementType) {
			
				case 'replace':
					
					if ( place.hasChildNodes() ) {
						while ( place.childNodes.length >= 1 ) place.removeChild( place.firstChild );       
					}
					
					place.appendChild(element);
					for (var i = 0; i < additionalNodes.length; i++) general.insertAfter(((i == 0) ? element : additionalNodes[i-1]), additionalNodes[i]);
					break;
				
				case 'insertAfter':
					place.parentNode.insertBefore(element, place.nextSibling);
					for (var i = 0; i < additionalNodes.length; i++) general.insertAfter(((i == 0) ? element : additionalNodes[i-1]), additionalNodes[i]);
					break;
				
				case 'insertBefore':
					place.parentNode.insertBefore(element, place);
					for (var i = 0; i < additionalNodes.length; i++) general.insertAfter(((i == 0) ? element : additionalNodes[i-1]), additionalNodes[i]);
					break;
					
				case 'prepend':
					place.insertBefore(element, place.firstChild);
					for (var i = 0; i < additionalNodes.length; i++) general.insertAfter(((i == 0) ? element : additionalNodes[i-1]), additionalNodes[i]);
					break;
				
				case 'append':
					place.appendChild(element);
					for (var i = 0; i < additionalNodes.length; i++) general.insertAfter(((i == 0) ? element : additionalNodes[i-1]), additionalNodes[i]);
					break;
					
				default:
					
					var returnArray = [];
					
					returnArray.push(element);
					for (var i = 0; i < additionalNodes.length; i++) returnArray.push(additionalNodes[i]);
					
					return returnArray;
					break;
			}
			
			return null;
		}
		
		// Child of the node-tree, create self props and recursively create descendants
		else {
			
			if (json.type == 'text') return document.createTextNode(json.innerHTML);
			
			var element = document.createElement(json.type);
			
			if (typeof(json.attributes) != 'undefined') {
				
				for (var i in json.attributes) {
					
					switch (i) {
						case 'id':
							element.id = json.attributes[i];
							break;
							
						case 'name':
							element.name = json.attributes[i];
							break;
							
						case 'class':
							element.className = json.attributes[i];
							break;
							
						case 'onabort':
						case 'onblur':
						case 'onchange':
						case 'onclick':
						case 'ondblclick':
						case 'onerror':
						case 'onfocus':
						case 'onkeydown':
						case 'onkeypress':
						case 'onkeyup':
						case 'onload':
						case 'onmousedown':
						case 'onmousemove':
						case 'onmouseout':
						case 'onmouseover':
						case 'onmouseup':
						case 'onreset':
						case 'onresize':
						case 'onselect':
						case 'onsubmit':
						case 'onunload':
							var evalCode = "(function(code){"+
								"element."+i+" = function() { eval(code); };"+
							"})(json.attributes[i]);";
							eval(evalCode);
							break;
							
						default:
							element.setAttribute(i, json.attributes[i]);
					}
				}
			}
			
			if (typeof(json.children) != 'undefined') {
				
				for (var i = 0; i < json.children.length; i++) {
					
					var child = general.writeHTMLBlock(json.children[i], 0, 0);
					element.appendChild(child);
				}
			}
			
			return element;
		}
	},
	
	
	
	
	
	
	
	
	
	escapeRegEx : function(text) {
		
		// Make sure '\\' is first
		var chars = ["\\", "/", "-", "(", ")", "[", "]", ".", "*", "+", "?"];
		
		for (var i in chars) {
			
			text = text.replace(chars[i], "\\"+chars[i]);
		}
		
		return text;
	}
	
	
}



var TCF = {

	scholarshipSearch : function(form) {
		
		var text = form.scholarship_search.value;
		
		if (/\/$/.test(form.action)) form.action += text;
		else form.action += '/'+text;
		form.submit();
	}

}
