// JavaScript Document

/*
 * Identify if AJAX is compatible with browser
 */
var httpObject;

function getHTTPObject()
{ 
var xmlhttp;

if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  
  return xmlhttp;  
}

/*
 * Search Recipes
 */
function searchRecipes()
{
	var _searchKey = document.getElementById("txtSearch").value;
	loadSearchRecipes(_searchKey, 0 , 10, 'search')
}

function loadSearchRecipes(_searchItem, recipe_eu, recipe_limit, _searchBy)
{
  var httpObject = getHTTPObject();
  if (httpObject != null) 
  {
	var ajax_link = "load_recipe.php?" + _searchBy + "=" + _searchItem + "&start=" + recipe_eu + "&limit=10";
	httpObject.open("GET", ajax_link, true);
	httpObject.send(null);
	httpObject.onreadystatechange = function ()
									{
									  if(httpObject.readyState == 4)
									  {
										document.getElementById("txtRecipes").innerHTML = httpObject.responseText;
									  }
									}	
  }
  else
  {
  	alert('No xmlhttp');
  }
}
/*
 *  Load Recipes
 */
function loadRecipes(category_id, recipe_eu, recipe_limit)
{
  var httpObject = getHTTPObject();
  if (httpObject != null) 
  {
	var ajax_link = "load_recipe.php?category=" + category_id + "&start=" + recipe_eu + "&limit=" + recipe_limit;
	httpObject.open("GET", ajax_link, true);
	httpObject.send(null);
	httpObject.onreadystatechange = function ()
									{
									  if(httpObject.readyState == 4)
									  {
										document.getElementById("txtRecipes").innerHTML = httpObject.responseText;
									  }
									}	
  }
  else
  {
  	alert('No xmlhttp');
  }
}

function stateChanged(httpObject)
{
  if (httpObject.readyState==4)
  {
    document.getElementById("txtRecipes").innerHTML = httpObject.responseText;
  }
}


