/* Define an  Error Message object  */
/* Constructor for the error message */
function ErrorMessage()
	{
	var dNow = new Date;
	/* set the user settable variables to null */
	this.Function         = '';
	this.Filename         = '';
	this.Message          = '';
	this.Date             = '';
	/* set the user settable flags to default */
	this.Testing          = 0;   // testing is off
	this.TurningOffFlash  = 1;   // no changing flash

	/* set the site state to values - can be overridden */
	this.Site         = 'ThisSite';
	this.Server       = 'ThisServer';
	this.Now          = dNow.toString();
	this.Browser      = detectBrowserVersion();
	this.OS           = detectOSVersion();
	this.Flash        = detectFlashVersion();
	this.JavaScriptOn = detectJavaScriptOn();
	this.JavaScript   = detectJavaScriptVersion();
			
	/* Set the method to make the XML message */
	this.MakeXML      = ErrorMessage_Make;
			
	/* and post it back to the server */
	this.ReturnError  = PostBackError;
	}

/* Function to post back to the current page */
/* the parameter specified whether to switch to non flash or not */
function PostBackError() 
{  
	// check for presence of FlashVersion Flag in querystring
	// If there is a Flag, don't do anything
	pageURL = String(window.location);
	
	/* Dont post back if there is an Error already in the query string*/
	if (pageURL.indexOf("Error=") <= 0 )
		{
		/* Make the XML message*/
		this.MakeXML();

			    
		/* If the we are supposed to get out of Flash mode*/
			    
		/* change the  FlashVer in the Querystring*/
		if (this.TurningOffFlash)
			{
			if (this.Testing )
				alert('Turning off flash!!!');
			/* If there is not a state NVP in the query string */
			if (pageURL.indexOf('FlashVer=')< 0) 
				{
				// add one
				//alert('No FlashVer');
				if (pageURL.indexOf("?") > 0 )
					strNVP = new String('&FlashVer=0');
				else
					strNVP = new String('?FlashVer=0');
				pageURL = pageURL.concat(strNVP);
				}
			else
				{
				// Replace the existing NVP
				//alert('Resetting  FlashVer');
				rExp = /FlashVer=./;
				pageURL = pageURL.replace(rExp, 'FlashVer=0');
				}
			//alert('redirecting to URL['+ pageURL +']');
			}

		/* Add the error string to the URL*/
		if (pageURL.indexOf("?") > 0 )
			postBackPage = pageURL + '&Error=' + this.ErrorXML;
		else
			postBackPage = pageURL + '?Error=' + this.ErrorXML;
		
		/* If we are testing, put out an alert */
		/* Actually, use a prompt so we can cut and paste the URL for testing */
		if (this.Testing )
			prompt('Redirecting to URL', postBackPage);
			
		/* Redirect back to the site with the error message in the query string*/			
		window.location.replace(postBackPage);
	}

} 
/*
This function urlEncodes the query string. 
Only use this on the Query String as it encodes 
the dot as %2E and this would malform the URL if 
used on the entire URL 
*** Again, only use it on the querystring ***
*/
function urlEncode(str) 
	{
     var result = "";
     /* escape (URL Encode) the URL */

     str = escape(str);	
     /* now fix up the dots/periods */
     for (var i = 0; i < str.length; i++) 
		{
          if (str.charAt(i) == '.') 
            {
			result += "%2E";
            }
          else result += str.charAt(i);

		}
          return result;
	}

function detectBrowserVersion()
	{
	return 'detectBrowserVersion';
	}

function detectOSVersion()
	{
	return 'detectOSVersion';
	}

function detectFlashVersion()
	{
	return 'detectFlashVersion';
	}

function detectJavaScriptOn()
	{
	return 'detectJavaScriptOn';
	}

function detectJavaScriptVersion()
	{
	return 'detectJavaScriptVersion';
	}

/* Function to make the XML error message */
function ErrorMessage_Make()
	{
	/* Get the state variable form the form */
	var sErrMsg = new String;
	/* Set the Error element */
	sErrMsg =           '<Error>';

	/* Set the msg element */
	sErrMsg = sErrMsg + '<site>' + this.Site + '</site>';
	sErrMsg = sErrMsg + '<server source="client">' + this.Server + '</server>';
	sErrMsg = sErrMsg + '<date>' + this.Now + '</date>';
	sErrMsg = sErrMsg + '<msg>';
	if ( this.Function != '' )
		sErrMsg = sErrMsg + '<function>' + this.Function + '</function>';
				
	if ( this.Filename != '' )
		sErrMsg = sErrMsg + '<filename>' + this.Filename + '</filename>';

	if ( this.Message != '' )
		sErrMsg = sErrMsg + '<message>' + this.Message + '</message>';

	sErrMsg = sErrMsg + '</msg>';
	/* Set the Client state element */
	sErrMsg = sErrMsg + '<ClientState Browser="' + this.Browser + '" OS="' + this.OS + '" Flash="' + this.Flash + '" JavaScriptOn="' + this.JavaScriptOn + '" JavaScript="' + this.JavaScript + '"/>';
	sErrMsg = sErrMsg + '</Error>';
	/* encode the error message in case of some unsafe URL characters (namely the dot) */
	this.ErrorXML = urlEncode(sErrMsg);
	}

/* Create an  Error Message object  */
var objErrorMessage = new ErrorMessage();


function ThrowError(sMessage, sFunction, sFileName, blnFlashReDir)
{
	try
	{
	writeStaticMap();
	}
	catch(err)
	{
	}
}




/* TEST * TEST * TEST * TEST * TEST * TEST * TEST * TEST *  */
/* Call this function to see that all is working for the test *  */
function ThrowError_deprecated(sMessage, sFunction, sFileName, blnFlashReDir)
	{
		/* Example code to invoke and setup the error object */
		/* You must do these things at a miniumu*/
				
		/* Set the Error message elements */
		objErrorMessage.Message      = sMessage;
		objErrorMessage.Function     = sFunction;
		objErrorMessage.Filename     = sFileName;
		objErrorMessage.Testing      = 1;  // Should test alerts show.  On by default.  Testing is 0 = No 1 = Yes - default is Yes
		objErrorMessage.TurningOffFlash = blnFlashReDir; // We will be turning flash off on site 0 = No, 1 = Yes

		/* These are system variables.  you can override any of them
		objErrorMessage.Site         = 'ThisSite';
		objErrorMessage.Server       = 'ThisServer';
		objErrorMessage.Now         = '26 July 2005';
		objErrorMessage.Browser      = 'browser version';
		objErrorMessage.OS           = 'OS version';
		objErrorMessage.Flash        = 'flash version';
		objErrorMessage.JavaScriptOn = 'JavaScript on';
		objErrorMessage.JavaScript   = 'JavaScript Version';
		*/
					
		/* Post the error message back to the server */
		objErrorMessage.ReturnError(); 
	}

