/********************************************************************************
 *
 * Oracast Inc. AJAX API's
 *
 * API MANIFEST:
 *        + CheckAjax()                       // check for ajax support
 * 				+ GetXxmlHttpObject()				        // xmlHttp object for ajax
 *				+ writeObject(id,value)				      // writes an html-based value to a specific object
 *				+ hideObject(id)					          // hides a specific object
 *				+ destroyObject(id)					        // destroys/removes an object from the document body
 *				+ setClass(id,cssClass)				      // assigns a cssClass to a specific object
 *				+ loadingBox(id,className,html,x,y)	// dynamically creates a div/layer and displays it to the user (x,y coordinates)
 *
 * Version: 1.0
 * Created: 2007-09-12
 * Updates:
 ********************************************************************************/
var xmlHttp;
var ajaxSupported = true;


//********************************************************************************
// CheckAjax(): Check to make sure ajax is support
//********************************************************************************
function CheckAjax() {
  xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null)
	{
	  alert ("Your browser does not support AJAX. User experience may be effected.");
	  ajaxSupported = false;
	  return;
	} 
}


//********************************************************************************
// GetXmlHttpObject(): Get the right xmlHttp object based on the user's browser
//********************************************************************************
function GetXmlHttpObject()
{
	var xmlHttp=null;

	try
	 {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	 }
	catch (e)
	 {
	  // Internet Explorer
	   try
	    {
	      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	   catch (e)
	    {
	      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	 }
	return xmlHttp;
}


//********************************************************************************
// writeObject(id,value): Method that displays a message to the user by writing a specified value to the target div
//********************************************************************************
function writeObject(id,value) {
	document.getElementById(id).innerHTML=value;
}


//********************************************************************************
// hideObject(id): Method that hides a specified element
//********************************************************************************
function hideObject(id) {
	document.getElementById(id).style.display = 'none';
}


//********************************************************************************
// showObject(id): Method that shows a specified element
//********************************************************************************
function showObject(id) {
	document.getElementById(id).style.display = '';
}


//********************************************************************************
// destroyObject(id): Method that destroys/removes an object from the document
//********************************************************************************
function destroyObject(id) {
	document.body.removeChild(document.getElementById(id));	
}


//********************************************************************************
// setClass(id,cssClass): Method that sets/modifies the class of an object
//********************************************************************************
function setClass(id,cssClass) {
	document.getElementById(id).className=cssClass;
}


// NEED SCROLL TO PAGE LOCATION



// NEED FADE THEN HIDE/Destroy WITH TIMER



// GET screenXPos, screenYPos, mouseXPos, mouseYPos


/*****************************************************************************************************
*
* Default Loading Box (simple popup box/div that displays a message)
*
*****************************************************************************************************/
function loadingBox(id,className,html,x,y) {

	// create the element
	var div = document.createElement("div");
	div.id = id;
	div.className = className;
	div.innerHTML = html;
	document.body.appendChild(div);
	div.style.left = x + "px";
  div.style.top = y + "px";
	return div;
}


/*****************************************************************************************************
*
* Default Dialog Box (popup box/div that has a header/body/footer to display info to the user
*
*****************************************************************************************************/
dialogBox = function(id,className,html,x,y) {
	// create the element
	var wrapper = document.createElement("div");
	wrapper.id = id;
	wrapper.className = className;
	wrapper.innerHTML = html;
	document.body.appendChild(wrapper);	// move to dialogBox.prototype.Show()
	wrapper.style.left = x + "px";
  wrapper.style.top = y + "px";
	return wrapper;
}

insertObject = function(parentId,object,id,className,html) {
	var obj = document.createElement(object);
	obj.id = id;
	obj.className = className;
	obj.innerHTML = html;
	var parent = document.getElementById(parentId);
	parent.appendChild(obj);
}
