/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e2) {
			xmlHttp = false;
		}
	}
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
	xmlHttp = new XMLHttpRequest();
}

var statusD;
var statusDText;
var responseD;

function callServer(url, params, sD, sDText, rD) {
	statusD = sD;
	statusDText = sDText;
	responseD = rD;
	// Open a connection to the server
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	// Setup a function for the server to run when it's done
	xmlHttp.onreadystatechange = sendResponse;
	// Send the request
	xmlHttp.send(params);
}

function sendResponse(){
	error("");
	var response = "";
	if (xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200){
			response = xmlHttp.responseText;
			document.getElementById(statusD).innerHTML = "";
			if(response.indexOf("ERROR_MESSAGE_")!=-1){
				response = response.substring(response.indexOf("ERROR_MESSAGE_")+14,response.length);
				error(response);
			}else{
				document.getElementById(responseD).innerHTML = response;
			}
		}else{
			document.getElementById(statusD).innerHTML = "";
			response = "Sorry, an error occurred. Please try again later! <font color='#FF0000'><strong>Code="+xmlHttp.status+"</strong></font>";//+xmlHttp.responseText;
			error(response);
		}
		//unpopp();
	}else{
		response = "<img src='/i/processing.gif'>" + " <strong>" + statusDText + " </strong>";
		document.getElementById(statusD).innerHTML = response;
	}
}

function error(err){
	document.getElementById("errorD").innerHTML = err;
}