/*
 * To be used with overlib
 */
var http_request = false;
function makePOSTRequest(url, parameters, onReplyFunc, isCClick) {
	
	http_request = false;
	onReplyFunc = (typeof(onReplyFunc) != 'undefined') ? onReplyFunc : alertContents;
	isCClick = (typeof(isCClick) != 'undefined') ? isCClick : true;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			// set type accordingly to anticipated content type
			//http_request.overrideMimeType('text/xml');
			http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
//			alert(e);
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
//				alert(e);
			}
		}
	}
	if (!http_request) {
		alert('A problem occured, please notify the site administrator.');
		return false;
	}

	http_request.onreadystatechange = onReplyFunc;
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
	if (isCClick)
		cClick();
}

function alertContents() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			overlib('Message Sent',CAPTION,'Success',CENTERPOPUP,WRAP,CELLPAD,15,TIMEOUT,4000,BGCLASS,'cb-tips-bg modal');
//			document.getElementById('debug_data').innerHTML = http_request.responseText;
		} else if (http_request.status == 403){
			overlib('Forbidden Access.<br>If you think this was done wrongfully, please contact us.',CAPTION,'Failure!',CENTERPOPUP,WRAP,TIMEOUT,6000,BGCLASS,'cb-tips-bg modal');
		} else {
			overlib('An error has occured.<br>If this problem repeat itself, please report to the Administrator.',CAPTION,'Failure!',CENTERPOPUP,WRAP,TIMEOUT,6000,BGCLASS,'cb-tips-bg modal');
		}
	}
}

function noAlert(){}

function sendPOSTRequest(url,body,onReplyFunc,isCClick) {
//	alert("url="+url+"\nbody="+body);
	makePOSTRequest(url, body, onReplyFunc,isCClick);
}


