// JavaScript Document

var w = window;
var d = window.document;

function getIFrameDocument(aID){ 
	var rv = null; 
	
	// if contentDocument exists, W3C compliant (Mozilla) 
	if (document.getElementById(aID).contentDocument) { 
		rv = document.getElementById(aID).contentDocument; 
	}
	else {
		// IE 
		rv = document.frames[aID].document; 
	} 
	
	return rv; 
} 

function getAjaxObj() {
	var obj;
	if(window.XMLHttpRequest) { // Firefox, Opera 8.0+, Safari
		obj = new XMLHttpRequest();
	} else if(window.ActiveXObject) { // Internet Explorer
		try {
			obj = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			obj = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return obj;
}

//alternative to my traditional "callback" as taught in educ_it... (check if the response contains anything in the onResponse code
function checkReadyState( obj )
{
  if( obj.readyState == 4 )
  {
    if( obj.status == 200 )
	{
		return true;
    }
    else
	{
    	alert( "Problem retrieving XML data." );
    }
  }
}

//then instead of callback you would just use something like this, xmlhttp being the name of the ajax obj :
/*
function onResponse()
{
	if(checkReadyState( xmlhttp ) )
	{
		//code
	}
}
*/

function AjaxGhost( divId )
{
	try
	{
		if( !divId )
		{
			var divId = 'centerCol';	
		}
		var troy = this;
		this.achilles = getAjaxObj();
		if( window.parent.document )
		{
			var d = window.parent.document;
		}
		this.equus = d.getElementById( divId );
		// var isNote = false;
		var bgId = false;
		var isXml = false;
	}
	catch( e )
	{
		alert(e.description);
	}
	
	this.loadOnDiv = function( pathStr, paramsStr, bgInt, xmlBool ) // TODO : make it so that it can receive paramsArr too.
	{
		try
		{
			troy.achilles.open( 'POST', pathStr, true );
			troy.achilles.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
			/*if( pathStr.match('sp_note.php') )
			{
				isNote = true;	
			}*/
			if( bgInt )
			{
				bgId = bgInt;	
			}
			if( xmlBool ) // don't yet know what to do with an xml loaded here...
			{
				isXml = true;
				troy.achilles.overrideMimeType( 'text/xml' ); // VERY useful for passing a text response as xml
			}
			troy.achilles.onreadystatechange = troy._onResponse;
			if( !paramsStr )
			{
				var paramsStr = null;	
			}
			troy.achilles.send( paramsStr );
		}
		catch( e )
		{
			alert( e.description );	
		}
	}
	
	this._onResponse = function()
	{
		if( checkReadyState( troy.achilles ) )
		{
			if( !isXml )
			{
				/*if( isNote )
				{
					try
					{
						if(w.parent.document)
						{
							w.open( 'javascript: menubar(7);', '_parent' );
						}
						else
						{
							menubar(7);
						}
					}
					catch( e )
					{
						w.alert( e.description );	
					}
				}*/
				if( bgId )
				{
					try
					{
						if(w.parent.document)
						{
							w.open( 'javascript: menubar( ' + bgId + ' );', '_parent' );
						}
						else
						{
							menubar( bgId );
						}
					}
					catch( e )
					{
						w.alert( e.description );	
					}
				}
				troy.equus.innerHTML = troy.achilles.responseText;
			}
			else
			{
				// sumthin.
			}
		}
	}
}