// JavaScript Document
/*
* File: ServerReq.js
*This file creates the instance of xmlHttpRequest object, sends and
* Receives the request and response respectively.
*/
/*
* Static script to instantiate XMLHttp object for different browsers.
*/
var clientHttpHandler;
clientHttpHandler = create();
 
/*
* This method creates the xmlHttpRequest object and returns it.
*/
function create()         
{
	var xmlHttpRequest = false;
	
	//Internet Explorer
	try
	{
		xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (xml2Exception)
	{
		try
		{
			xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (xmlException)
		{
			xmlHttpRequest = false;
		}
	}
	
	//Netscape, Mozila, Firefox, Safari, Opera
	if (!xmlHttpRequest && typeof XMLHTTPRequest == 'undefined')
	{
		try
		{
			xmlHttpRequest = new XMLHttpRequest();
		}
		catch (genException)
		{
			XMLHttpRequest = false;
		}
	}
	return xmlHttpRequest;
}
/*
* This method sends the request to the server url according to the
* Passing parameters. It sets the user’s response function to the
* onreadystatechange event of the xmlHttpRequest object.
*/
function send(httpMethod, serverUrl, isAsync, respFunc)
{
	clientHttpHandler.open(httpMethod, serverUrl, isAsync);
	if (respFunc != "") { clientHttpHandler.onreadystatechange = respFunc; }
	clientHttpHandler.send(null);
}
/*
* This method checks the state and the status of the response and
* Depending on that fetches the response text.
* readystate: 0 - uninitialized, 1 - loading, 2 - loaded, 3 - interactive, 4 - complete
*/
function receive()
{
	//var response = "";
	try
	{
		if (clientHttpHandler.readyState == 4) // Completed
		{
			if (clientHttpHandler.status == 200) // “OK”
			{
				return true;
			}
			else if (clientHttpHandler.status == 403) // “Forbidden”
			{
				alert(lang.alert_error_access_denied);
			}
			else if (clientHttpHandler.status == 404) // “URL Not Found”
			{
				alert(lang.alert_error_url_not_found);
			}
			else // Miscellaneous
			{
				//alert("Error: status code " + clientHttpHandler.status);
			}
		}
		return false;
	}
	catch (genException)
	{
	}
}

function receiveimage()
{
	//var response = "";
	try
	{
		if (clientHttpHandler.readyState == 4) // Completed
		{
			if (clientHttpHandler.status == 200) // “OK”
			{
				return 'OK';
			}
			else if (clientHttpHandler.status == 403) // “Forbidden”
			{
				return 'Forbidden';
			}
			else if (clientHttpHandler.status == 404) // “URL Not Found”
			{
				return 'NF';
			}
			else // Miscellaneous
			{
				//return 'OK';
				//alert("Error: status code " + clientHttpHandler.status);
			}
		}
		return false;
	}
	catch (genException)
	{
	}
}