//	Ajax gloabl variavle
var XMLobj=createXMLObject();
var params='';
//var pg =1 ;
var pg=0;

function createXMLObject()
{
	try{
		//	If browser is not IE. If Firefox ,etc
		return  new XMLHttpRequest();
	}
	catch(e){
		try{
			//	If browser is old IE
			return new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e2){
			try{
				//	If browser is IE version >6
				return new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e3){
				//	if browser does not support then show alert
				alert("Your broswer does not support ActiveXObjects.");
				return false;
			}
		}
	}
}

//	function to save the page content 
function get_values()
{
	if(document.getElementById("by_name").checked)
		params="search_by=name&search_value="+document.getElementById("search_value").value;

	if(document.getElementById("by_tubes").checked)
	{	
		//params="search_by=address&search_value="+document.getElementById("search_value").value;
		document.getElementById("frm_search").submit();
		return true;		
	}
	
	if(document.getElementById("by_postcode").checked)
	{
		document.getElementById("frm_search").submit();
		return true;
	}

	post_values();
}

//	function to save the page content 
function get_values_busi()
{
	if(document.getElementById("by_name").checked)
		params="search_by=name&search_value="+document.getElementById("search_value").value+"&search_busi="+document.getElementById("search_busi").value;

	if(document.getElementById("by_tubes").checked)
	{	
		//params="search_by=address&search_value="+document.getElementById("search_value").value;
		document.getElementById("frm_search").submit();
		return true;		
	}
	
	if(document.getElementById("by_postcode").checked)
	{
		document.getElementById("frm_search").submit();
		return true;
	}

	post_values_busi();
}



function changeValue(myValue){

	pg = 0;
	params="search_by=letter&search_value="+myValue;
	post_values_specific();
}

function changeValue_busi(myValue,myid){

	pg = 0;
	params="search_by=letter&search_value="+myValue+"&search_busi="+myid;
	post_values_specific();
}

function post_values_specific_ex()
{
	if(XMLobj.readyState==0 || XMLobj.readyState==4)
	{
		XMLobj.open("POST", "example1.php", true );
		XMLobj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		XMLobj.onreadystatechange=show_page;
		XMLobj.send(params+"&page="+pg)
	}
}

function changeValueex(myValue){

	pg = 0;
	params="search_by=letter&search_value="+myValue;
	post_values_specific_ex();
}

function next_pg_specific_ex(specificval)
{
	pg+=1;
	params=specificval;
	post_values_specific_ex();
}

function previous_pg_specific_ex(a,specificval)
{
	pg=a-1;
	params=specificval;
	post_values_specific_ex();
}


function changeValueAdmin(alphabet){
	params="search_by=name&search_value="+alphabet;
	post_admin_values();
}

//	function to get the page content
function post_values()
{
	if(XMLobj.readyState==0 || XMLobj.readyState==4)
	{
		XMLobj.open("POST", "search_restaurants.php", true );
		XMLobj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		XMLobj.onreadystatechange=show_page;
		XMLobj.send(params+"&page="+pg)
	}
}
//	function to get the page content
function post_values_busi()
{
	if(XMLobj.readyState==0 || XMLobj.readyState==4)
	{
		XMLobj.open("POST", "search_restaurants.php", true );
		XMLobj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		XMLobj.onreadystatechange=show_page;
		XMLobj.send(params+"&page="+pg)
	}
}
//

//	function to get the page content
function post_values_specific()
{
	if(XMLobj.readyState==0 || XMLobj.readyState==4)
	{
		XMLobj.open("POST", "search_restaurants_specific.php", true );
		XMLobj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		XMLobj.onreadystatechange=show_page;
		XMLobj.send(params+"&page="+pg)
	}
}
//

function post_admin_values()
{
	if(XMLobj.readyState==0 || XMLobj.readyState==4)
	{
		XMLobj.open("POST", "search_restaurants_admin.php", true );
		XMLobj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		XMLobj.onreadystatechange=show_page_admin;
		XMLobj.send(params+"&page="+pg)
	}
}
//	
function show_page_admin()
{
	if(XMLobj.readyState==4)
	{
		if(XMLobj.status==200)
		{
	 		document.getElementById("search_body").innerHTML=XMLobj.responseText;
	 	}
	 	else
	 		document.getElementById("search_body").innerHTML="Loading...";	//	showing the progressbar
	}
}

//	
function show_page()
{
	if(XMLobj.readyState==4)
	{
		if(XMLobj.status==200)
		{
	 		document.getElementById("search_result").innerHTML=XMLobj.responseText;
			//alert(XMLobj.responseText);
	 	}
	 	else
	 		document.getElementById("search_result").innerHTML="Loading...";	//	showing the progressbar
	}
}

function next_pg()
{
	pg+=1;
	post_values();
}
	
function next_pg_specific()
{
	pg+=1;
	post_values_specific();
}

function previous_pg(a)
{

	pg=a-1;
	post_values();
}

function previous_pg_specific(a)
{
	pg=a-1;
	post_values_specific();
}


//	function to get the event dates
function show_cal(c_mon,c_year)
{
	if(XMLobj.readyState==0 || XMLobj.readyState==4)
	{
		XMLobj.open("POST", "event_dates.php", true );
		XMLobj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		XMLobj.onreadystatechange=view_cal;
		XMLobj.send("month="+c_mon+"&year="+c_year);
	}
}

//	function to read the ajax response
function view_cal()
{
	if(XMLobj.readyState==4)
	{
		if(XMLobj.status==200)
		{
			//	showing the calendar
	 		document.getElementById("div_Calendar").innerHTML=XMLobj.responseText;
	 	}
	}
}

