////////////////////////////////////////////////////////////////////////////////
//	ajax.js
//	Mario Chirinos Colunga	
//	Aurea Desarrollo Tecnológico.
//	27/Feb/2011 - 27/Feb/2011
//------------------------------------------------------------------------------
//	Funciones para utilizar Ajax
//	Notas:
//
//	Uso: Ponga la siguiente linea en la etiqueta <head>
//	<script type="text/javascript" src="include/ajax.js"></script>
//
////////////////////////////////////////////////////////////////////////////////
//------------------------------------------------------------------------------
function loadXMLDoc(div, strGet)
{//alert(div+" : "+ strGet);
var xmlhttp;
	//alert("loadXMLDoc("+div+"," +strGet+")");
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var ajaxdiv = document.getElementById(div);
			ajaxdiv.innerHTML=xmlhttp.responseText;
			var scripts = ajaxdiv.getElementsByTagName("script");
			for(var i = 0; i < scripts.length; i++)
			{//	alert(scripts[i].innerHTML);
				eval(scripts[i].innerHTML);
			}
	    	}
	}
	xmlhttp.open("GET", strGet,true);
	xmlhttp.send();

}
//------------------------------------------------------------------------------
//On load page, init the timer which check if the there are anchor changes each 300 ms  
//$(document).ready(function(){setInterval("checkAnchor()", 3000);alert('init');});  
//------------------------------------------------------------------------------
var currentAnchor = null;  
//Function which chek if there are anchor changes, if there are, sends the ajax petition  
function checkAnchor()
{
	var page;
	//Check if it has changes  
	if(currentAnchor != document.location.hash)
	{  
		currentAnchor = document.location.hash;  
		//if there is not anchor, the loads the default section  
		if(!currentAnchor) 
		{ 
			page = "home";  
		}
		else  
		{  
			//Creates the  string callback. This converts the url URL/#main&amp;amp;id=2 in URL/?section=main&amp;amp;id=2  
			page=currentAnchor.substring(1);
		}  
		loadXMLDoc('ajaxmainarea','anchorselector.php?page='+page);
//	helpdiv.innerHTML = page;
	}
}
//------------------------------------------------------------------------------


