// XML HTTP Requests - Variables

var xmlHttp;
var xmlHttpCategory;
var xmlHttpCategoryDeck;
var xmlHttpStartup;
var xmlHttpLeadsForm;

// Checks to see if other files can respond to this one
function alertCheck()
{
	alert('test');
}

// XML HTTP Requests - Ajax Output Functions

function updateGrid(page, category, startuplow, startuphigh, section)
{	
	xmlHttp=GetXmlHttpObject()
	
	if (xmlHttp==null)
	{
		 alert ("Browser does not support HTTP Request for updateGrid()")
		 return
	}

	var url;
	var include_file;
	
	if(section == "index")
		include_file = "findafranchiseajax.php";
	else if(section == "homebased")
		include_file = "findafranchisehomebasedajax.php";
	else if(section == "international")
		include_file = "findafranchiseinternationalajax.php";
	else if(section == "lowcost")
		include_file = "findafranchiselowcostajax.php";
	else if(section == "highreturn")
		include_file = "findafranchisehighreturnajax.php";
	else if(section == "parttime")
		include_file = "findafranchiseparttimeajax.php";
	else {}
	
	url = "includes/" + include_file +  "?page=" + page + "&category=" + category + "&startuplow=" + startuplow + "&startuphigh=" + startuphigh;
	
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function updateCategoryDeck(category)
{
	xmlHttpCategoryDeck=GetXmlHttpObjectCategory()
	
	if (xmlHttpCategoryDeck==null)
	{
		 alert ("Browser does not support HTTP Request for updateCategoryDeck()")
		 return
	}

	var url="includes/categorydeckajax.php?category=" + category; 
	
	xmlHttpCategoryDeck.onreadystatechange=categoryDeckChanged 
	xmlHttpCategoryDeck.open("GET",url,true);
	xmlHttpCategoryDeck.send(null);
}

function updateCategoryTitle(category)
{
	xmlHttpCategory=GetXmlHttpObjectCategory()
	
	if (xmlHttpCategory==null)
	{
		 alert ("Browser does not support HTTP Request for updateCategoryTitle()")
		 return
	}

	var url="includes/categorytitleajax.php?category=" + category; 
	
	xmlHttpCategory.onreadystatechange=categoryTitleChanged 
	xmlHttpCategory.open("GET",url,true);
	xmlHttpCategory.send(null);
}

function updateStartupMenu(category, section)
{

	xmlHttpStartup=GetXmlHttpObjectStartup()
	
	if (xmlHttpStartup==null)
	{
		 alert ("Browser does not support HTTP Request for updateStartupMenu()")
		 return
	}

	var url;
	var include_file;
	
	if(section == "index")
		include_file = "startupcostsmenuajax.php";
	else if(section == "homebased")
		include_file = "startupcostsmenuhomebasedajax.php";
	else if(section == "international")
		include_file = "startupcostsmenuinternationalajax.php";
	else if(section == "lowcost")
		include_file = "startupcostsmenulowcostajax.php";
	else if(section == "highreturn")
		include_file = "startupcostsmenuhighreturnajax.php";
	else if(section == "parttime")
		include_file = "startupcostsmenuparttimeajax.php";
	else {}
	
	url = "includes/" + include_file +  "?category=" + category;
	
	xmlHttpStartup.onreadystatechange=startupChanged 
	xmlHttpStartup.open("GET",url,true);
	xmlHttpStartup.send(null);
	
}

// XML HTTP Request - Change State Functions

function categoryTitleChanged() 
{ 
	if (xmlHttpCategory.readyState==4 || xmlHttpCategory.readyState=="complete")	
	{
		if(document.getElementById("ajax_category_title"))
			document.getElementById("ajax_category_title").innerHTML=xmlHttpCategory.responseText;
	}	
	else {}
}

function categoryDeckChanged() 
{ 
	if (xmlHttpCategoryDeck.readyState==4 || xmlHttpCategoryDeck.readyState=="complete")	
	{
		if(document.getElementById("ajax_category_deck"))
			document.getElementById("ajax_category_deck").innerHTML=xmlHttpCategoryDeck.responseText;
	}	
	else {}


}

function startupChanged() 
{ 
	if (xmlHttpStartup.readyState==4 || xmlHttpStartup.readyState=="complete")	
	{
		document.getElementById("ajax_startup_costs").innerHTML=xmlHttpStartup.responseText;
	}	
	else {}


}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")	
		document.getElementById("ajax_rows").innerHTML=xmlHttp.responseText;
	else if(xmlHttp.readyState==1) // Waiting for ajax response
	{
		text = "<img src=\"images/loadingAnimation.gif\" border=\"0\">";

		document.getElementById("ajax_load").innerHTML=text;
	}
	else {}
}

// XML HTTP Request - Objects

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;
}

function GetXmlHttpObjectCategory()
{
	var xmlHttpCategory=null;
	
	try
	 {
		 // Firefox, Opera 8.0+, Safari
		 xmlHttpCategory=new XMLHttpRequest();
	 }
	 
	catch (e)
	 {
		 //Internet Explorer
		 try
		  {
			xmlHttpCategory=new ActiveXObject("Msxml2.XMLHTTP");
		  }
		 catch (e)
		  {
			xmlHttpCategory=new ActiveXObject("Microsoft.XMLHTTP");
		  }
	 }
	 
	return xmlHttpCategory;
}

function GetXmlHttpObjectStartup()
{
	var xmlHttpStartup=null;
	
	try
	 {
		 // Firefox, Opera 8.0+, Safari
		 xmlHttpStartup=new XMLHttpRequest();
	 }
	 
	catch (e)
	 {
		 //Internet Explorer
		 try
		  {
			xmlHttpStartup=new ActiveXObject("Msxml2.XMLHTTP");
		  }
		 catch (e)
		  {
			xmlHttpStartup=new ActiveXObject("Microsoft.XMLHTTP");
		  }
	 }
	 
	return xmlHttpStartup;
}

function GetXmlHttpObjectCategoryDeck()
{
	var xmlHttpCategoryDeck=null;
	
	try
	 {
		 // Firefox, Opera 8.0+, Safari
		 xmlHttpCategoryDeck=new XMLHttpRequest();
	 }
	 
	catch (e)
	 {
		 //Internet Explorer
		 try
		  {
			xmlHttpCategoryDeck=new ActiveXObject("Msxml2.XMLHTTP");
		  }
		 catch (e)
		  {
			xmlHttpCategoryDeck=new ActiveXObject("Microsoft.XMLHTTP");
		  }
	 }
	 
	return xmlHttpCategoryDeck;
}

function GetXmlHttpObjectLeadsForm()
{
	var xmlHttpLeadsForm=null;
	
	try
	 {
		 // Firefox, Opera 8.0+, Safari
		 xmlHttpLeadsForm=new XMLHttpRequest();
	 }
	 
	catch (e)
	 {
		 //Internet Explorer
		 try
		  {
			xmlHttpLeadsForm=new ActiveXObject("Msxml2.XMLHTTP");
		  }
		 catch (e)
		  {
			xmlHttpLeadsForm=new ActiveXObject("Microsoft.XMLHTTP");
		  }
	 }
	 
	return xmlHttpLeadsForm;
}