////////////////////////////////////////////////////////////////////////////////
// Developer:   Jessie R. Hernández
// Created for: William Perez
// Date:        20040427
// Description: Enables performing Client-Side Includes.
////////////////////////////////////////////////////////////////////////////////


/**
 * Creates a browser-specific XmlHttpRequest object.
 * @param handler the default handler to use.
 * @return an instance of the browser-specific XmlHttpRequest object.
 */
function createXmlHttpReq(handler)
{
	var result = null;

	try
	{
		// Mozilla
		result = new XMLHttpRequest();
		result.onload = handler;
		result.onerror = handler;
	}
	catch( e )
	{
		try
		{
			result = new ActiveXObject( "Msxml2.XMLHTTP" ); // "Microsoft.XMLHTTP"
			result.onreadystatechange = handler;
		}
		catch( e2 )
		{
			alert( "You need to enable Active Scripting and ActiveX controls!" );
		} // endtry
	} // endtry

	return result;
} // function createXmlHttpReq(handler)

////////////////////////////////////////////////////////////////////////////////

/**
 * Dummy handler.
 */
function dummyHandler()
{
} // function dummyHandler()

////////////////////////////////////////////////////////////////////////////////

/**
 * Includes the contents of a URL at the called location.
 * @param url the URL to fetch.
 */
function include(url)
{
	var response = "";
	var xmlhttp = createXmlHttpReq( dummyHandler );

	// send a synchronous GET request to the server
    xmlhttp.open( "GET", url, false );
    xmlhttp.send( null );

    // get the response text
	response = xmlhttp.responseText;

	// write the response
	document.write( response );
} // function include(url)

/*function UTF8ToLatin1(text)
{
	var character = '\0';
	var result = "";

	for( var index = 0; index < text.length; ++index )
	{
		character = text.charCodeAt( index );

		if( character == 195 )
		{
			++index;

			character = text.charCodeAt( index );

			if( character > 127 )
			{
				result += String.fromCharCode( character + 64 );
			}
			else // character <= 127
			{
				if( character == 38 )
				{
					// There was an incident where i-grave was represented as "&shy;"
					result += String.fromCharCode( 237 );
					index += 4;
				}
			} // endif
		}
		else if( character > 255 )
		{
			alert( text.substr( index - 3, 10 ) );
			alert( character );
			//result += String.fromCharCode( character - 0xFF10 );
		}
		else // character != 195
		{
			result += String.fromCharCode( character );
		} // endif
	} // endfor

	return result;
}
*/