var http
String.prototype.parseStr = top.parseString
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }

function AJAXStateChange() {
	if(http.readyState == 4) {
		xmlText = http.responseText ;
		try { 
			var response = eval("(" + http.responseText + ")");
		} catch (e) {
//			alert ( 'response compile error' ) 	
//			showValue ( http.responseText ) 
		} 
		try{ 
			if ( response.callback_function_text ) {
				response.callback_function = eval ( response.callback_function_text )
				response.callback_function()
			} else {
				try { 
					AJAXcallback ( response ) ; 
				} catch ( e ) {}
			}
		} catch(e) {
		//	alert ( 'no call back' ) 	
		}
	}
}

function obtainAJAX() {
	var ajax = null;
	try {
		// Firefox, Opera 8.0+, Safari
		ajax = new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				ajax = null;
			}
		}
	}
	return ajax;
}

function processChanger( obj ){
	htmlObj = obj
	http = new obtainAJAX ()
	if (http == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	http.onreadystatechange = AJAXStateChange
	url = ( obj.xmlreturn_url ) ? obj.xmlreturn_url : "xmlreturn.php"
	p = new Array()
	for (var i in htmlObj){
		p[p.length] = i + '=' + htmlObj[i]
	}
//	params = "table=" + htmlObj.table + "&field=" + htmlObj.field + "&val=" + htmlObj.val + "&action=" + htmlObj.action
	params = p.join('&')
		
	http.open("POST", url, ( obj.process_synchronously ) ? false : true );
	
	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	
	http.send(params); 
//	showProps ( http , 'http' ) 
	if ( obj.process_synchronously ) {
	//	return trim ( http.responseText )
		return http.responseText.trim()
	}
}

function retAjaxObject( url , process_synchronously ) {
	obj = new Object()
	if ( url ) {
		obj.xmlreturn_url = url
	}
	if ( process_synchronously ) {
		obj.process_synchronously = true ;
	}
	return obj
}

function sendDebugEmail( subject , messagge ) {
	return processChanger( { subj : subject , msg : message , process_synchronously : 1 , xmlreturn_url : 'debug.php' } )
}

function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

