/*
 * Modified by Bispark Software -
 * added new functions  init_loader_image, call_post
 * call_normal was modified for parent_window update. Callback has been modifed as inner function object.
 */
var loader_image = null;
function init_loader_image(image) {
	loader_image = image;
}

function call_normal(url, parent_window, fptr)
{
	var myDiv = null;
	var myDoc = null;
	if (parent_window) {
				myDoc =  parent_window.document;
				myDiv = parent_window.document.getElementById("ajaxe");
			}
			else {
				myDoc =  document;
				myDiv = document.getElementById("ajaxe");
	}

	if (url.length==0) {
 	 myDiv.innerHTML="";
 	 return;
 	 }
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)  {
  		alert ("Your browser does not support AJAX!");
  		return;
 	 }
	//var url="return.php";
	//url=url+"?normal="+str;
	//url=url+"&sid="+Math.random();


	var stateChanged = function () {
		if (xmlHttp.readyState==4){
			myDiv.innerHTML=xmlHttp.responseText;
			if (fptr) {
				eval(fptr);
			}
	}
	else{
		myDiv.innerHTML="<center style='margin-top:20px; margin-bottom:20px;'><center style=' margin-top:20px; margin-bottom:20px; font-size:18px; color:#000066;'>Loading....</center><br /><img src='"+loader_image+ "' alt='Loading' title='Loading' height='31px' width='31px'></center>";
	}

	}
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}




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

function stateChanged_old()
{
	if (xmlHttp.readyState==4){
		document.getElementById("ajaxe").innerHTML=xmlHttp.responseText;

	}
	else{

		ht = document.getElementsByTagName("html");
		ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
		document.getElementById("ajaxe").innerHTML="<center style='margin-top:20px; margin-bottom:20px;'><center style=' margin-top:20px; margin-bottom:20px; font-size:18px; color:#000066;'>Loading....</center><br /><img src='"+loader_image+ "' alt='Loading' title='Loading' height='31px' width='31px'></center>";
	}
}
function log_out_NOTUSED()
{
	ht = document.getElementsByTagName("html");
	ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if (confirm('Are you sure you want to log out?'))
	{
		return true;
	}
	else
	{
		ht[0].style.filter = "";
		return false;
	}
}

function call_post(url,postData, parent_window) {

	var myDiv = null;
	var myDoc = null;
	if (parent_window) {
				myDoc =  parent_window.document;
				myDiv = parent_window.document.getElementById("ajaxe");
			}
			else {
				myDoc =  document;
				myDiv = document.getElementById("ajaxe");
	}



	var handleSuccess = function(o){
		if(o.responseText !== undefined){
		//alert(o.responseText);

			/*div.innerHTML = 'Transaction id: ' + o.tId;
			div.innerHTML += 'HTTP status: ' + o.status;
			div.innerHTML += 'Status code message: ' + o.statusText;
			div.innerHTML += '<li>HTTP headers: <ul>' + o.getAllResponseHeaders + '</ul></li>';
			div.innerHTML += 'PHP response: ' + o.responseText;
			div.innerHTML += 'Argument object: ' + o.argument; */
		}


		if(o.responseXML !== undefined){

			myDiv.innerHTML = o.responseText;

		}
		if (parent_window) {
			self.close();
		}
	}

	var handleFailure = function () {
		var message = 'failed : remote resource may not exist!';
		alert (message);

		myDiv.innerHTML=message;

		if (parent_window) {
			self.close();
		}

	}
	var callback =
	{
  		success:handleSuccess,
  		failure: handleFailure,
  		argument: ['foo','bar']
	};


	myDiv.innerHTML="<center style='margin-top:20px; margin-bottom:20px;'><center style=' margin-top:20px; margin-bottom:20px; font-size:18px; color:#000066;'>Loading....</center><br /><img src='"+loader_image+ "' alt='Loading' title='Loading' height='31px' width='31px'></center>";

	var request = YAHOO.util.Connect.asyncRequest('POST', url, callback, postData);
}


function call_async_post(url,postData, response_div_name) {
//	document.body.style.cursor = "wait";
	var myDiv = null;
	if (response_div_name) {
		myDiv = document.getElementById(response_div_name);
	}

	var handleSuccess = function(o){

		if(o.responseText !== undefined){


			if (myDiv != null) {
				myDiv.innerHTML = o.responseText;
			}
			else {
				var message = 'success : post action completed successfully!';
				alert(message);
			}

		}

	}

	var handleFailure = function () {
		//document.body.style.cursor = "auto";
		var message = 'failed : remote resource may not exist!';
		alert (message);
		if (myDiv != null) {
			myDiv.innerHTML = message;
		}


	}
	var callback =
	{
  		success:handleSuccess,
  		failure: handleFailure,
  		argument: ['foo','bar']
	};


	//myDiv.innerHTML="<center style='margin-top:20px; margin-bottom:20px;'><center style=' margin-top:20px; margin-bottom:20px; font-size:18px; color:#000066;'>Loading....</center><br /><img src='"+loader_image+ "' alt='Loading' title='Loading' height='31px' width='31px'></center>";

	var request = YAHOO.util.Connect.asyncRequest('POST', url, callback, postData);
}
