/* ########### AJAX ENGINE TO SEND/RECEIVE REQUEST  ###############
*
*
*
*
*/

// define global variables.
var xmlHttp		= RequestObject();

// define global variables
var HOST = "fetcher.php"; // the php script which will fetch and return data

// create xmlHTTP request for different browsers. 
function RequestObject()
{
var xmlHttp;
	
	
	
	if(window.ActiveXObject)
	{
		var tryPossibleVersions = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHttp"];
		
		for(i=0;i<tryPossibleVersions.length;i++) {
			try
			{
				xmlHttp = new ActiveXObject(tryPossibleVersions[i]);
				break;
			}
			catch (e)
			{
			xmlHttp = false;
			}
		}
	}
	else
	{
		try
		{
		xmlHttp = new XMLHttpRequest();
		}
		catch (e)
		{
		xmlHttp = false;
		}
	}
	if (!xmlHttp)
	alert("Error creating the XMLHttpRequest object.");
	else
	return xmlHttp;

	

}

// function to call fetcher.php and updates the browser for plan type
function read_data(form) {
	
	if(xmlHttp) {
		
		
		try
		{
			
			if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
				
				
				if(form == 'about') {
					show_processing_image();
					myVar = "action=about";
					
				}
				else if(form == 'services') {
					show_processing_image();
					myVar = "action=services";
				}
				
				xmlHttp.open("POST", HOST,true);
				xmlHttp.setRequestHeader ("Content-Type","application/x-www-form-urlencoded");
				xmlHttp.onreadystatechange = read_response;
				xmlHttp.send(myVar);

			}

		
		}catch (e) {
			alert(e.toString());
		}

	}
	
}

/* @Descriptio: Function fills the plan combo dynamicaly by fetching the
*  data from AJAX response
*  @Param : Ajax response
*  @Return : Fills the plan type combo
*/

function read_response() {
	
	try
	{
		if (xmlHttp.readyState == 4)
		{
			if (xmlHttp.status == 200)
			{
				xmlResponse = xmlHttp.responseText;
				
				x_response = xmlResponse.split('***');
				switch(x_response[0]) {
					case 'about':
					hide_processing_image();	
					load_about(x_response[1], x_response[2]);
						break;
					case 'services':
						hide_processing_image();
						load_services(x_response[1], x_response[2]);
						break;
				}
			}
			else
			{
			alert("There was a problem accessing the server: " +
			xmlHttp.statusText);
			}
		}
	}
	catch (e)
	{
		alert("Error in server response pls try after some time"+e.toString());
	}
}

function load_about(page, navigation) {
	
	var o_right_div = document.getElementById('right');
	if(page != "") {
		o_right_div.innerHTML = page;
	}
	// change the navigation menu
	var o_navigation = document.getElementById('live-contact');
	o_navigation.innerHTML = navigation;
}	

function load_services(page, navigation) {
	
	var o_right_div = document.getElementById('right');
	if(page != "") {
		o_right_div.innerHTML = page;
	}
	// change the navigation menu
	var o_navigation = document.getElementById('live-contact');
	o_navigation.innerHTML = navigation;
}	