
/*  Ajaxination - Simple JavaScript framework, version 1.0
 *  (c) 12 Feb 2006 Sajan John <saj@ajaxination.com>
 *  Ajaxination is an easy to use ajax framework for your Web2.0 Application.
 *  Using Ajaxination you can update multiple Div tags with just one object.
 *  Ajaxination is freely distributable under the terms of GNU license.
 *  Feel free to modify/edit the code according to your requirements .
 *  If you are adding any additional features in this framework please
 *  send me a statusBox to saj@ajaxination.com. Enjoy Ajaxination, - Ajax Simplified
 *  for updates visit : www.ajaxination.com
/*--------------------------------------------------------------------------*/

 function URLload(param,tagName,url,mode) { 
   ajax = createXMLHttpRequest(); 
   // You can even pass the action mode = post/get  and act is the parameter u wanted to pass with the url. 
   ajax.open('get', url); 
   ajax.onreadystatechange = responseHandler; 
   contentHandler.tagName = tagName; 
   setTimeout ("ajax", 500);
   ajax.send(null); 

} 

//var ajax = createXMLHttpRequest(); 
var contentHandler = new TagHandler(null); 

function createXMLHttpRequest(){
   try { return new XMLHttpRequest(); } catch(e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   return null;
}

function TagHandler(tagName) 
{ 
   var tagName; 
   return tagName; 
}

function responseHandler() { 
	var objCurrent = document.getElementById(contentHandler.tagName)
	if(ajax.readyState == 0) { objCurrent.innerHTML = "<p style='height:274px;' align='center'><br /><br /><img src='/images/icons/loading.gif' alt='loading' /><br />Loading...<br/>Please be patient.</p>"; }
	if(ajax.readyState == 1) { objCurrent.innerHTML = "<p style='height:274px;' align='center'><br /><br /><img src='/images/icons/loading.gif' alt='loading' /><br />Loading...<br/>Please be patient.</p>"; }
	if(ajax.readyState == 2) { objCurrent.innerHTML = "<p style='height:274px;' align='center'><br /><br /><img src='/images/icons/loading.gif' alt='loading' /><br />Loading...<br/>Please be patient.</p>"; }
	if(ajax.readyState == 3) { objCurrent.innerHTML = "<p style='height:274px;' align='center'><br /><br /><img src='/images/icons/loading.gif' alt='loading' /><br />Loading...<br/>Please be patient.</p>"; }

   if(ajax.readyState == 4)
	{
		if(ajax.status == 200)
		{
			objCurrent.innerHTML = "";
			var updateContent = ajax.responseText; 
		    if(updateContent) { 
				objCurrent.innerHTML = updateContent; 
			} 
		}
		else if(ajax.status == 404)
		{
			// Retrive error message or redirect to error page 
			objCurrent.innerHTML = "File not found";
		}
		else
		{
			// Give a catch all error message
			objCurrent.innerHTML = "We are currently experiencing technical difficulties and are addressing the issue.";
		}
		
	//set a tabindex to - 1 to help screen readers focus on the changed content. Then set the focus to the changed content.	
	objCurrent.tabIndex = -1;	
	objCurrent.focus(); 
	} 
} 