/* Ehsan Darrudi
Iran National Science Foundation
www.insf.org
(c) 2005-2012

Some of the codes have been borrowed from tutorial websites. 
In this case the name of the original author and/or the 
copyright notice proceed the code. */

// General Functions ------------------------------------------------------------------

function createXHR(xhrObj) 
{
	if (xhrObj && xhrObj.readyState < 4) 
	{
		xhrObj.abort();
		xhrObj = null;
	}	
	
	if (!xhrObj) 
	{
		if (window.XMLHttpRequest) 
		{
			// branch for native XMLHttpRequest object - Mozilla
			try 
			{
				xhrObj = new XMLHttpRequest();
			} 
			catch (e) 
			{
				xhrObj = null;
			}
		} 
		else if (window.createRequest) 
		{
			/* For ICEbrowser -- untested.
			 * per their site 
			 * http://support.icesoft.com/jive/entry.jspa?entryID=471&categoryID=21
			 * There are a number of restrictions on the implementation.
			 */
			try 
			{
				xhrObj = window.createRequest();
			}
			catch (e) 
			{
				xhrObj = null;
			}
		} 
		else if (window.ActiveXObject) 
		{
			// branch for IE/Windows ActiveX version
			try 
			{
				xhrObj = new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch(e) 
			{
				try
				{
					xhrObj = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e) 
				{
					xhrObj = null;
				}
			}
		} 
	}
	return xhrObj;
}

function AjaxGetFileInfo(callback, obj) 
{
	var xhr = createXHR();	
	
	url = '/AjaxCalls.php?call=GetFileInfo&file=' + obj.href;
		
	function cb() 
	{
		if (xhr.readyState == 4) 
		{
			if (xhr.status == 200) 
			{
				callback(obj, xhr.responseText);
			}
		}
	}
		
	if (xhr) 
	{
		xhr.open("GET", url, true);
		xhr.onreadystatechange = cb;
		xhr.send(null);
	}
} 

//-----------------------------------------------------------------------------------
