﻿// NAVIGATION CONTROLER --- CONTROLS LINKS (SCRIPT BY THEMBA NDALA - www.thembandala.biz)
function OpenPage(page,itemid) {
	
	var NavigationRequest;  // The variable that makes Ajax possible!
	
	try{	NavigationRequest = new XMLHttpRequest();		} // Opera 8.0+, Firefox, Safari
	 
	catch (e)
	{
		try{	NavigationRequest = new ActiveXObject("Msxml2.XMLHTTP");	} // Internet Explorer Browsers
			
			 catch (e) 
			 {
						try{	NavigationRequest = new ActiveXObject("Microsoft.XMLHTTP");	}
						
						 catch (e)
						 {
							// INCOMPITIBLE BROWSER
							alert("Your browser does not support the enhanced functionality of this website, and therefore you will have an experience that differs from the intended one.\n");
							return false;
						}
			 }
	}
						
						
						//START THE REQUEST
						NavigationRequest.abort(); 		// Refreshes or Ignore the previouse request 
						
						//CONFIGURE ALL THE VARIABLES
						function hideDIV(divID) { document.getElementById(divID).style.display = "none";  }
						function showDIV(divID) { document.getElementById(divID).style.display = "block"; }		

						
						//CONFIGURE SOME PARAMETERS
						var param	= "p="+page+"&itemid="+itemid;

						NavigationRequest.open("GET", "ajax_pages.php?"+param, true);
						NavigationRequest.onreadystatechange=function() 
						{		
						
								//ON SUCCESS OUTPUT THE RESULTS
								if(NavigationRequest.readyState == 4)
								{
									if(NavigationRequest.responseText == 0) {
									hideDIV('Loading');
									showDIV('Error');										
									} //END IF RESULT = 0
									
									else {
									document.getElementById('Content').innerHTML = NavigationRequest.responseText;  
									hideDIV('Loading');									
									}
									
								
								} //END NavigationRequest.readyState == 4
								
								else {	showDIV('Loading');	 }
						
						} // END NavigationRequest.onreadystatechange=function() 
					 
					 NavigationRequest.send(null);
	
	
	} // End main Function