function LoadVars() {

	if (window.XMLHttpRequest){
		this.reqObj = new XMLHttpRequest();
	}else if(window.ActiveXObject){
		this.reqObj = new ActiveXObject("Microsoft.XMLHTTP");
	}

	var lv = this;

	this.reqObj.onreadystatechange = function(){
		lv.onStateChange();
	}

	this.content = null;
}

LoadVars.prototype.toString = function(){
	var lvString ="";

	for (var prop in this){
		if (typeof this[prop] != "function" && typeof this[prop] != "object" && prop != "parseVarString"){
			var nextVar = escape(prop) +'='+escape(this[prop])+'&';
			lvString += nextVar;
		}
	}
	return lvString;
}

LoadVars.prototype.onStateChange = function(){
	if (this.reqObj.readyState == 4){
		if (this.reqObj.status == 200) {
			this.onData();
		}else{
			var statusObj = {statusNum:this.reqObj.status, statusText:this.reqObj.statusText};
			this.loaded = false;
			this.onLoadError (statusObj);
		}
	}
}

LoadVars.prototype.loaded = false;
LoadVars.prototype.contentType = "application/x-www-form-urlencoded; charset=UTF-8";
LoadVars.prototype.parseVarString = null;
LoadVars.prototype.load = function (url){
	this.openXMLReq(url, "GET");
}

LoadVars.prototype.openXMLReq = function (url, method){
	if (method == undefined){
		method = "POST";
	}

	if(method == "GET"){
		theURL = url + '?' + this.toString();
		theData = null;
	}else if(method == "POST"){
		theURL = url;
		theData = this.toString();
	}

	this.reqObj.open(method, theURL, true );

	if (method == "POST"){
		this.reqObj.setRequestHeader("Content-Type", this.contentType);
	}

	this.reqObj.send(theData);
}

LoadVars.prototype.send = function (url, method){
	this.openXMLReq(url, method);
}

LoadVars.prototype.sendAndLoad = function(url, method){
	this.openXMLReq(url, method);
}

LoadVars.prototype.onData = function(){
	if (this.parseVarString == true){
		this.decode();
	}else{
		this.content = this.reqObj.responseText;
		this.onLoad(true);
	}
}

LoadVars.prototype.decode = function(){


	this.content = new Object();
	var escText = unescape(this.reqObj.responseText);
	var varArray = escText.split('&');

	var num = varArray.length;
	var i;
	var nextPair;
	var varName;
	var varValue;

	if (varArray.length > 0){

		for (i=0; i<num; i++){

			var nextPair = varArray[i];

			var nextPairArray = new Array();

			var firstEq = nextPair.indexOf("=", 0);

			nextPairArray[0] = nextPair.substring(0, firstEq);
			nextPairArray[1] = nextPair.substring(firstEq +1, nextPair.length);

			varName = nextPairArray[0];
			varValue = nextPairArray[1];

			this.content[varName] = varValue;
		}
		this.onLoad(true);
	}else{

		this.onLoad(false);
	}

}


String.prototype.htmlEntities = function() {
	var chars = new Array ('&','à','á','â','ã','ä','å','æ','ç','è','é',
	'ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô',
	'õ','ö','ø','ù','ú','û','ü','ý','þ','ÿ','À',
	'Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë',
	'Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö',
	'Ø','Ù','Ú','Û','Ü','Ý','Þ','€','\"','ß','<',
	'>','¢','£','¤','¥','¦','§','¨','©','ª','«',
	'¬','­','®','¯','°','±','²','³','´','µ','¶',
	'·','¸','¹','º','»','¼','½','¾');

	var entities = new Array ('amp','agrave','aacute','acirc','atilde','auml','aring',
	'aelig','ccedil','egrave','eacute','ecirc','euml','igrave',
	'iacute','icirc','iuml','eth','ntilde','ograve','oacute',
	'ocirc','otilde','ouml','oslash','ugrave','uacute','ucirc',
	'uuml','yacute','thorn','yuml','Agrave','Aacute','Acirc',
	'Atilde','Auml','Aring','AElig','Ccedil','Egrave','Eacute',
	'Ecirc','Euml','Igrave','Iacute','Icirc','Iuml','ETH','Ntilde',
	'Ograve','Oacute','Ocirc','Otilde','Ouml','Oslash','Ugrave',
	'Uacute','Ucirc','Uuml','Yacute','THORN','euro','quot','szlig',
	'lt','gt','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');

	newString = this;
	for (var i = 0; i < chars.length; i++) {
		myRegExp = new RegExp();
		myRegExp.compile(chars[i],'g')
		newString = newString.replace (myRegExp, '&' + entities[i] + ';');
	}
	return newString;
}

String.prototype.UNhtmlEntities = function() {
	var chars = new Array ('&','à','á','â','ã','ä','å','æ','ç','è','é',
	'ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô',
	'õ','ö','ø','ù','ú','û','ü','ý','þ','ÿ','À',
	'Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë',
	'Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö',
	'Ø','Ù','Ú','Û','Ü','Ý','Þ','€','\"','ß','<',
	'>','¢','£','¤','¥','¦','§','¨','©','ª','«',
	'¬','­','®','¯','°','±','²','³','´','µ','¶',
	'·','¸','¹','º','»','¼','½','¾');

	var entities = new Array ('amp','agrave','aacute','acirc','atilde','auml','aring',
	'aelig','ccedil','egrave','eacute','ecirc','euml','igrave',
	'iacute','icirc','iuml','eth','ntilde','ograve','oacute',
	'ocirc','otilde','ouml','oslash','ugrave','uacute','ucirc',
	'uuml','yacute','thorn','yuml','Agrave','Aacute','Acirc',
	'Atilde','Auml','Aring','AElig','Ccedil','Egrave','Eacute',
	'Ecirc','Euml','Igrave','Iacute','Icirc','Iuml','ETH','Ntilde',
	'Ograve','Oacute','Ocirc','Otilde','Ouml','Oslash','Ugrave',
	'Uacute','Ucirc','Uuml','Yacute','THORN','euro','quot','szlig',
	'lt','gt','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');

	newString = this;
	for (var i = 0; i < entities.length; i++) {
		myRegExp = new RegExp();
		myRegExp.compile('&'+entities[i]+';','g')
		newString = newString.replace (myRegExp,  chars[i]);
	}
	return newString;
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
