//Cooking with Limits

//Hidden Text - top
var top_array = new Array("CWLSiteSearch");

function displaytop(the_top){
	 if (document.getElementById(the_top).style.display==""){
	   document.getElementById(the_top).style.display = "none";return
  }
  for (i=0;i<top_array.length;i++){
	   var my_top = document.getElementById(top_array[i]);
	   my_top.style.display = "none";
	 }
  document.getElementById(the_top).style.display = "";
}

// Hidden text - main
var main_array = new Array("recipes", "episodes", "site", "foodSearchBox");

function displayMain(the_main){
	 if (document.getElementById(the_main).style.display==""){
	   document.getElementById(the_main).style.display = "none";return
  }
  for (i=0;i<main_array.length;i++){
	   var my_main = document.getElementById(main_array[i]);
	   my_main.style.display = "none";
	 }
  document.getElementById(the_main).style.display = "";
}

// Hidden text - subs
var subs_array = new Array("recmeal", "recfood", "epitype", "epifood");

function displaySubs(the_sub){
	 if (document.getElementById(the_sub).style.display==""){
	   document.getElementById(the_sub).style.display = "none";return
  }
  for (i=0;i<subs_array.length;i++){
	   var my_sub = document.getElementById(subs_array[i]);
	   my_sub.style.display = "none";
	 }
  document.getElementById(the_sub).style.display = "";
}

// Food Search
function foodsearch() {
var availFoods = "avocado, beef, bison, broccoli, carrot, chicken, leeks, onion, orange, pineapple, pork, potato, quinoa, rice, tomato, turkey, oats, peaches";
var foodQuery = document.foodSearchForm.foodSearched.value; // Gets form value
var foodQuerystring = foodQuery.toLowerCase(); // gets rid of case issues
var foodQuerystring2 = foodQuerystring; // makes variable that searchResults can read
var searchResults = availFoods.search(foodQuerystring2); // performs the search

	if (searchResults >= 0) {
		window.open("http://www.cookingwithlimits.com/food-info/" + foodQuerystring2 + ".shtml", "_self");
//		document.write("Found " + searchResults); // Testing
	} else if (searchResults < 0) { // Exceptions to the rule - common plurals and two word foods
		if (foodQuerystring2 == "carrots") {
			window.open("http://www.cookingwithlimits.com/food-info/carrot.shtml", "_self");
		} else if (foodQuerystring2 == "leek") {
			window.open("http://www.cookingwithlimits.com/food-info/leeks.shtml", "_self");
		} else if (foodQuerystring2 == "onions") {
			window.open("http://www.cookingwithlimits.com/food-info/onion.shtml", "_self");
		} else if (foodQuerystring2 == "oranges") {
			window.open("http://www.cookingwithlimits.com/food-info/orange.shtml", "_self");
		} else if (foodQuerystring2 == "potatoes") {
			window.open("http://www.cookingwithlimits.com/food-info/potato.shtml", "_self");
		} else if (foodQuerystring2 == "sweet potatoes") {
			window.open("http://www.cookingwithlimits.com/food-info/sweet-potato.shtml", "_self");
		} else if (foodQuerystring2 == "sweet potato") {
			window.open("http://www.cookingwithlimits.com/food-info/sweet-potato.shtml", "_self");
		} else if (foodQuerystring2 == "tomatoes") {
			window.open("http://www.cookingwithlimits.com/food-info/tomato.shtml", "_self");
		} else if (foodQuerystring2 == "buttercup squash") {
			window.open("http://www.cookingwithlimits.com/food-info/buttercup_squash.shtml", "_self");
		} else if (foodQuerystring2 == "corn") { // Shopping Guide Links
			window.open("http://www.cookingwithlimits.com/shopping-guide/avoiding-corn-shopping-guide.shtml", "_self")
		} else if (foodQuerystring2 == "dairy") {
			window.open("http://www.cookingwithlimits.com/shopping-guide/avoiding-dairy-shopping-guide.shtml", "_self")
		} else if (foodQuerystring2 == "egg") {
			window.open("http://www.cookingwithlimits.com/shopping-guide/avoiding-eggs-shopping-guide.shtml", "_self")
		} else if (foodQuerystring2 == "nuts") {
			window.open("http://www.cookingwithlimits.com/shopping-guide/avoiding-nuts-shopping-guide.shtml", "_self")
		} else if (foodQuerystring2 == "peanuts") {
			window.open("http://www.cookingwithlimits.com/shopping-guide/avoiding-nuts-shopping-guide.shtml", "_self")
		} else if (foodQuerystring2 == "soy") {
			window.open("http://www.cookingwithlimits.com/shopping-guide/avoiding-soy-shopping-guide.shtml", "_self")
		} else if (foodQuerystring2 == "wheat") {
			window.open("http://www.cookingwithlimits.com/shopping-guide/avoiding-wheat-shopping-guide.shtml", "_self")
		} else if (foodQuerystring2 == "yeast") {
			window.open("http://www.cookingwithlimits.com/shopping-guide/avoiding-yeast-shopping-guide.shtml", "_self")
		} else {
			document.write("No results found.");
		}
	} else {
		document.write("No results found.");
	}
}
// Type Ahead

function typeAhead(objectPlace) {
	requestedData = objectPlace.value;
	fetchData('/site-common/foodsearchdata.php',requestedData,'results');
} 

function setFood(FoodNameVal) {
	document.foodSearchForm.foodSearched.value = FoodNameVal;
}

function filterData(pageRequest,objectID){
	var objectResults = document.getElementById(objectID);
	if(pageRequest.responseText != '')
	{
		objectResults.style.display = 'block';
		objectResults.innerHTML = '';
		resultsList = pageRequest.responseText.split(',');
		for(i = 0; i < resultsList.length; i++)
		{
			if(resultsList[i] != "")
				objectResults.innerHTML += '<a href="javascript:setFood(\'' + resultsList[i] + '\')" onclick="foodpopHide(\'' + objectID + '\')">' + resultsList[i] + '</a><br />';
		}
	}
	else
	{
		objectResults.style.display = 'none';
	}
}

function foodpopHide(objectID) {
	var objFoodPopUp = document.getElementById(objectID);
	objFoodPopUp.style.display = 'none';
}

//Hidden Text - sharethis
var share_array = new Array("sharethis");

function displayshare(the_share){
	 if (document.getElementById(the_share).style.display==""){
	   document.getElementById(the_share).style.display = "none";return
  }
  for (i=0;i<share_array.length;i++){
	   var my_share = document.getElementById(share_array[i]);
	   my_share.style.display = "none";
	 }
  document.getElementById(the_share).style.display = "";
}