var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject() {
	var xmlHttp;
	if (window.ActiveXObject) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			xmlHttp = false;
		}
	} else {
		try {
			xmlHttp = new XMLHttpRequest();
		} catch (e) {
			xmlHttp = false;
		}
	}
	if (!xmlHttp) {
		alert("Error creating the XMLHttpRequest object.");
	} else {
		return xmlHttp;
	}
}

function callCheckLogin(checkLoginURL, username, cryptedPassword) {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
		var params = "CBXuser=" + username + "&CBXpass=" + cryptedPassword;
		xmlHttp.open("POST", 'checkLogin.php', true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		if(!document.all) {
			xmlHttp.setRequestHeader("Connection", "close");
		}
		xmlHttp.onreadystatechange = handleLoginCallBack;
		xmlHttp.send(params);
	}
}

function handleLoginCallBack() {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			var xmlDoc = xmlHttp.responseXML;
			window.location.href = xmlDoc.getElementsByTagName('redirection_url')[0].childNodes[0].nodeValue;
		}
	}
}