
//··········································································································
//	Error Management
//··········································································································

var mobjErrorRequest = null;

function onErrorHandler(strMsg, strUrl, strLin) 
{
	try
	{
		sendError("x01="+strUrl+"&x02="+strMsg+"&x03="+strLin);
		showError(strMsg, strUrl, strLin);
	}

	catch(exception)
	{
		showError("onErrorHandler: " + exception.message, "error.js", 0);
	}
}

function sendError(strPrm)
{
	try
	{
		if (setErrorRequestObject() == true)
		{
			mobjErrorRequest.open("POST", mstrBaseUrl + "fldsys/controller.asmx/onClientErrorLog?"+strPrm, false);
			mobjErrorRequest.onreadystatechange = null;
			mobjErrorRequest.setRequestHeader("content-type", "text/plain");
			mobjErrorRequest.setRequestHeader("content-length", 38);
			mobjErrorRequest.send(null);
			abortErrorRequest();
		}
		else
		{
			showError("sendError: setErrorRequestObject failed.", "error.js", 0);
		}
	}
	
	catch(exception)
	{
		showError("sendError: " + exception.message, "error.js", 0);
	}
}

function showError(strMsg, strUrl, strLin) 
{
	alert("Warning. An error has occurred.\r\nUrl: " + strUrl + "\r\nMessage: " + strMsg + "\r\nLine: " + strLin);
}

function setErrorRequestObject() 
{
	try
	{	
		abortErrorRequest();
		if (window.XMLHttpRequest)
		{
			mobjErrorRequest = new XMLHttpRequest();
			return true;
		}
		else if (window.ActiveXObject)
		{
			mobjErrorRequest = new ActiveXObject("Microsoft.XMLHTTP");
			return true;
		}
		else
		{
			showError("setErrorRequestObject: Problem creating the request object.", "error.js", 0);
			return false;
		}
	}
	
	catch(exception)
	{
		showError("setErrorRequestObject: " + exception.message, "error.js", 0);
		return false;
	}
}

function abortErrorRequest() 
{
	try
	{	
 		if (isErrorBusy() == true)
		{mobjErrorRequest.abort();}
	}
	
	catch(exception)
	{
		showError("abortErrorRequest: " + exception.message, "error.js", 0);
	}

	finally
	{
		mobjErrorRequest = null;
	}
}

function isErrorBusy() 
{
	try
	{	
		var blnReturn = false;
 		if (mobjErrorRequest != null)
		{
 			if (mobjErrorRequest.readyState == 1 || mobjErrorRequest.readyState == 2 || mobjErrorRequest.readyState == 3)
			{
				blnReturn = true;
			}
		}
		return blnReturn;
	}
	
	catch(exception)
	{
		showError("isErrorBusy: " + exception.message, "error.js", 0);
		return false;
	}
}
