var xmlHttp;
var xmlHttp2;
var base_url = document.location.host;
base_url="http://"+base_url+"/";
//-------------generating xmlHttp object
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	 {
		 // Firefox, Opera 8.0+, Safari
		 xmlHttp=new XMLHttpRequest();
	 }
	catch (e)
	 {
	 //Internet Explorer
		 try
		  {
			  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		  }
		 catch (e)
		  {
			  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
	 }
	return xmlHttp;
}
//-----------------getting left side news for main page
function DoLogin(UserName,Password,option){ 
 	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request")
		 return
	 }	 
	var url="users.php";
	url=url+"?action="+option;	
	url=url+"&UserName="+UserName;	
	url=url+"&Password="+Password;	
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = handleDoLogin; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}
	function handleDoLogin(){
		
			document.getElementById('DivErrors').innerHTML = "<img src='images/bigrotation.gif'>&nbsp;Processing Pleasse wait";		
		if(xmlHttp.readyState == 4){ 
			if(xmlHttp.responseText==2)
			{
				window.location.href="home.php";	
			}
			else
			  document.getElementById('DivErrors').innerHTML = "User Name/Password is invalid";		
		}
}//function

function DelImage(ImgID)
{
	 	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request")
		 return
	 }	 
	var url="options.php";
	url=url+"?action=DelImg";	
	url=url+"&ImgID="+ImgID;	
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = handleDelImg; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}
	function handleDelImg(){
		
			document.getElementById('DivErrors').innerHTML = "<img src='images/bigrotation.gif'>&nbsp;Processing Pleasse wait";		
		if(xmlHttp.readyState == 4){ 			
				window.location.href="listing.php";
		}

}
//===============
function LoadContents()
{
 	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request")
		 return
	 }	 
	var url="body.php";
	url=url+"?sid="+Math.random();
	xmlHttp.onreadystatechange = handleLoadContents; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}
	function handleLoadContents(){
		
			document.getElementById('BodyContenst').innerHTML = "<img src='images/bigrotation.gif'>&nbsp;Processing Pleasse wait";		
		if(xmlHttp.readyState == 4){ 			
				document.getElementById('DivErrors').innerHTML =xmlHttp.responseText;
		}

}

//===============
function showPage(str,CatID) { 
	 
	//This sub will populate a table with all the states and get the 
	//pagination built
	
	//Make the AJAX connection for both the navigation and content
	xmlHttp=GetXmlHttpObject()
	xmlHttp2=GetXmlHttpObject()
	
	//If we cant do the request error out
	if (xmlHttp==null || xmlHttp2==null ) {
	 	alert ("Browser does not support HTTP Request")
	 	return
	}
		
	//First build the navigation panel
	var url="GetInfo.php"
	url=url+"?p="+str
	url=url+"&id="+CatID
	url=url+"&t=nav"
	url=url+"&sid="+Math.random()

	//Once the page finished loading put it into the div
	xmlHttp2.onreadystatechange=navDone 

	//Get the php page
	xmlHttp2.open("GET",url,true)
	xmlHttp2.send(null)
	
	//Build the url to call
	//Pass variables through the url
	var url="GetInfo.php"
	url=url+"?p="+str
	url=url+"&id="+CatID
	url=url+"&t=con"
	url=url+"&sid="+Math.random()
	
	//Once the page finished loading put it into the div
	xmlHttp.onreadystatechange=stateChanged 
	
	//Get the php page
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)

}

function navDone() { 
	//IF this is getting called when the page is done loading then fill the pagination div
	if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete") { 
	 	//Update the Div tag with the outputted text
	 	document.getElementById("pgNavigation").innerHTML=xmlHttp2.responseText 
	} 
}

function stateChanged() { 
	//IF this is getting called when the page is done loading the states then output the div
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
	 	//Update the Div tag with the outputted text
	 	document.getElementById("pgContent").innerHTML=xmlHttp.responseText 
	} 
}


function Validate_business1(BusinessName){ 
 	var res = '';
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request")
		 return
	 }	 
	var url=base_url+"options.php";
	url=url+"?action=Validate_business";	
	url=url+"&BusinessName="+BusinessName;	
	url=url+"&sid="+Math.random();
	alert(url);
	xmlHttp.onreadystatechange = handleValidate_business; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}
	function handleValidate_business(){
		if(xmlHttp.readyState == 4){ 
			//alert(xmlHttp.responseText);
			res = xmlHttp.responseText;
			alert(res);
			return res;
			
		}
}//function


