<!--
var oAjax = getXmlHttpRequestObject();
function getXmlHttpRequestObject()
{

    if (window.XMLHttpRequest)
    {
        return new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
	else
    {
       alert("Your browser does not support Ajax.");
    }
}

function setTabsIndex()
{
	document.getElementById("date").tabIndex = 1;
	document.getElementById("meal").tabIndex = 2;
	document.getElementById("food_categ").tabIndex = 3;
	document.getElementById("food").tabIndex = 4;
	document.getElementById("food_serv").tabIndex = 5;
	document.getElementById("amount").tabIndex = 6;
	if(document.all)
	{
		document.all.date.tabIndex = 1;
		document.all.meal.tabIndex = 2;
		document.all.food_categ.tabIndex = 3;
		document.all.food.tabIndex = 4;
		document.all.food_serv.tabIndex = 5;
		document.all.amount.tabIndex = 6;
	}
}

function doSwitchRedirect(iValue)
{
	var __dest = document.getElementById('dest');
	if(iValue == 1)
	{
		__dest.value = 1;
	}
	else if(iValue == 2)
	{
		__dest.value = 2;	
	}
	document.addfood.submit();
}

function doDeleteByID(iValue)
{
	oAjax.onreadystatechange=function()
	{
		//var search_loader = document.getElementById('src_loader_gif');
		//search_loader.style.display='block';
		if(oAjax.readyState==4)
			{
			//search_loader.style.display='none';
			var container = document.getElementById('results');
			container.innerHTML = oAjax.responseText;
	
			}
	}
	oAjax.open("GET","search.php?ifood="+iValue,true);
	oAjax.send(null);

	
}


function displayToolTip(idParam)
{
	
	var arrToolTips = new Array();
	arrToolTips[0] = "Remove the food from your food database.";
	arrToolTips[1] = "Edit the name , category and nutritional info for this food.";	
	var __toolContainer = document.getElementById("tipContainer");
	if(idParam == '__dbremove')
	{
		__toolContainer.innerHTML = arrToolTips[0];
	}
	else if(idParam == '__etip')
	{
		__toolContainer.innerHTML = arrToolTips[1];
	}
	
}

function hideToolTip()
{
		var __toolContainer = document.getElementById("tipContainer");
		__toolContainer.style.display = "none";
		__toolContainer.innerHTML = "";
}

function showOption(sTarget)
{
	var __add = document.getElementById('add_food_form');
	var __edit = document.getElementById('food_edit_list');
	var __del = document.getElementById('food_remove_list');
	if(sTarget == 'add')
	{
		__add.style.display = "block";	
		__edit.style.display = "none";	
		__del.style.display = "none";				
	}
	else if(sTarget == 'edit')
	{
		__add.style.display = "none";	
		__edit.style.display = "block";	
		__del.style.display = "none";					
	}	
	else if(sTarget == 'delete')
	{
		__add.style.display = "none";	
		__edit.style.display = "none";			
		__del.style.display = "block";			
	}	
}


function verifyChange(value)
{
	var __menuContainer = document.getElementById('addmeal');
	var __field = document.getElementById('field');
	if(value == 3 || value == 4 || value == 5)
	{
		__menuContainer.style.display = "block";
		__field.style.display = "block";
	}
	else
	{
		__menuContainer.style.display = "none";
		__field.style.display = "none";		
	}
}



function HS_GetURL(Link){
	if (document.getElementById("add_from_fav").checked)
	{
		Link += "&checked=fav";
	}
	else
	{
		if (document.getElementById("add_from_search").checked)
		{
			Link += "&checked=search";
		}
	}
	window.location = Link;
}//HS_GetURL

function showFoodsForm(location)
{
	switch (location)
	{
		case "db":
			document.getElementById("oDbFoods").style.display = "block";
			document.getElementById("oFavFoods").style.display = "none";
			document.getElementById("srcFrm").style.display = "none";
			document.getElementById("add_food").style.display = "none";			
			break;
		case "fav":
			document.getElementById("oDbFoods").style.display = "none";
			document.getElementById("oFavFoods").style.display = "block";
			document.getElementById("srcFrm").style.display = "none";
			document.getElementById("add_food").style.display = "none";			
			break;
		case "search":
			document.getElementById("oDbFoods").style.display = "none";
			document.getElementById("oFavFoods").style.display = "none";
			document.getElementById("srcFrm").style.display = "block";
			document.getElementById("add_food").style.display = "none";			
			break;
		case "add_food":
			document.getElementById('add_from_db').checked = false;
			document.getElementById('add_from_fav').checked = false;
			document.getElementById('add_from_search').checked = false;
												
			document.getElementById("oDbFoods").style.display = "none";
			document.getElementById("oFavFoods").style.display = "none";
			document.getElementById("srcFrm").style.display = "none";
			document.getElementById("add_food").style.display = "block";			
			break;			
	}
	document.getElementById("checked_db").value = location;
	document.getElementById("checked_fav").value = location;
	document.getElementById("checked_search").value = location;
}//showFoodsForm

function HS_Get_Search_Food()
{
	var xmlHttpReq = false;
	var self = this;
	var food_string = document.getElementById("food");
	// Mozilla/Safari
	if (window.XMLHttpRequest)
	{
		self.xmlHttpReq = new XMLHttpRequest();
	}//if
	// IE
	else if (window.ActiveXObject)
	{
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}//else if
	self.xmlHttpReq.open('POST', "http://www.projectweightloss.com/index.php", true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function()
	{
		if (self.xmlHttpReq.readyState == 4 && self.xmlHttpReq.status == 200)
		{
			var search_container = document.getElementById("search");
			search_container.innerHTML = self.xmlHttpReq.response;
			
		}//if
	}//function
	self.xmlHttpReq.send("handler=diet&action=search&food="+food_string);
}//HS_Get_Search_Food


function HS_FoodDefinitionsPopulate(FormHandler,AllowEmpty)
{		
	for(var k = FormHandler.food.options.length-1; k>=0; k--)
	{
		FormHandler.food.options[k] = null;
	}//for
	FormHandler.food.options[0] = new Option("...loading...");
	FormHandler.calories.value = "0";
	var Categ = FormHandler.food_categ.options[FormHandler.food_categ.selectedIndex].value;
	
	//alert(Categ);
	
	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest)
	{
		self.xmlHttpReq = new XMLHttpRequest();
	}//if
	// IE
	else if (window.ActiveXObject)
	{
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}//else if
	
	self.xmlHttpReq.open('POST', "http://www.projectweightloss.com/index.php", true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.setRequestHeader("Content-length", Categ.length+AllowEmpty.length);
	self.xmlHttpReq.setRequestHeader("Connection", "close");
	self.xmlHttpReq.onreadystatechange = function()
	{
		if (self.xmlHttpReq.readyState == 4 && self.xmlHttpReq.status == 200)
		{
			HS_PullData(self.xmlHttpReq.responseXML,FormHandler.food,'food');
		}//if
	}//function
	self.xmlHttpReq.send("handler=diet&action=food_def&food_categ="+Categ+"&allow_empty="+AllowEmpty);
	for(var k = FormHandler.food_serv.options.length-1; k>=0; k--)
	{
		FormHandler.food_serv.options[k] = null;
	}//for
	FormHandler.food_serv.options[0] = new Option("Please select...");
}//HS_FoodDefinitionsPopulate


function HS_FavFoodDefinitionsPopulate(FormHandler,AllowEmpty,memId)
{		
	for(var k = FormHandler.food.options.length-1; k>=0; k--)
	{
		FormHandler.food.options[k] = null;
	}//for
	FormHandler.food.options[0] = new Option("...loading...");
	FormHandler.calories.value = "0";
	var Categ = FormHandler.food_categ.options[FormHandler.food_categ.selectedIndex].value;
	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest)
	{
		self.xmlHttpReq = new XMLHttpRequest();
	}//if
	// IE
	else if (window.ActiveXObject)
	{
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}//else if
	self.xmlHttpReq.open('POST', "http://www.projectweightloss.com/index.php", true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function()
	{
		if (self.xmlHttpReq.readyState == 4 && self.xmlHttpReq.status == 200)
		{
			HS_PullData(self.xmlHttpReq.responseXML,FormHandler.food,'food');
		}//if
	}//function
	self.xmlHttpReq.send("handler=diet&action=fav_food_def&food_categ="+Categ+"&allow_empty="+AllowEmpty+"&mem_id="+memId);
	for(var k = FormHandler.food_serv.options.length-1; k>=0; k--)
	{
		FormHandler.food_serv.options[k] = null;
	}//for
	FormHandler.food_serv.options[0] = new Option("Please select...");
}//HS_FavFoodDefinitionsPopulate

function HS_FoodServingsPopulate(FormHandler,AllowEmpty,system)
{		
	for(var k = FormHandler.food_serv.options.length-1; k>=0; k--)
	{
		FormHandler.food_serv.options[k] = null;
	}//for
	FormHandler.food_serv.options[0] = new Option("...loading...");
	FormHandler.calories.value = "0";
	var Food = FormHandler.food.options[FormHandler.food.selectedIndex].value;
	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest)
	{
		self.xmlHttpReq = new XMLHttpRequest();
	}//if
	// IE
	else if (window.ActiveXObject)
	{
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}//else if
	self.xmlHttpReq.open('POST', "http://www.projectweightloss.com/index.php", true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function()
	{
		if (self.xmlHttpReq.readyState == 4 && self.xmlHttpReq.status == 200)
		{
			HS_PullData(self.xmlHttpReq.responseXML,FormHandler.food_serv,'serving');
		}//if
	}//function
	
	self.xmlHttpReq.send("handler=diet&action=servings&food="+Food+"&allow_empty="+AllowEmpty+"&system="+system);
}//HS_FoodServingsPopulate

function HS_SearchFoodServingsPopulate(FormHandler,val,AllowEmpty,system)
{		
	for(var k = FormHandler.food_serv.options.length-1; k>=0; k--)
	{
		FormHandler.food_serv.options[k] = null;
	}//for
	FormHandler.food_serv.options[0] = new Option("...loading...");
	FormHandler.calories.value = "0";
	var Food = val;
	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest)
	{
		self.xmlHttpReq = new XMLHttpRequest();
	}//if
	// IE
	else if (window.ActiveXObject)
	{
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}//else if
	self.xmlHttpReq.open('POST', "index.php", true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function()
	{
		if (self.xmlHttpReq.readyState == 4 && self.xmlHttpReq.status == 200)
		{
			HS_PullData(self.xmlHttpReq.responseXML,FormHandler.food_serv,'serving');
		}//if
	}//function
	
	self.xmlHttpReq.send("http://www.projectweightloss.com/handler=diet&action=servings&food="+Food+"&allow_empty="+AllowEmpty+"&system="+system);
}//HS_SearchFoodServingsPopulate

function HS_PullData(XMLData,FieldHandler,ItemName)
{
	for (var k = FieldHandler.options.length-1; k>=0; k--)
	{
		FieldHandler.options[k] = null;
	}//for
	var Items = XMLData.getElementsByTagName(ItemName);
	for (var i=0;i<Items.length;i++)
	{
		var ItemID = Items[i].firstChild.firstChild.nodeValue;
		var ItemName = Items[i].firstChild.nextSibling.firstChild.nodeValue;
		FieldHandler.options[i] = new Option(ItemName,ItemID);
	}//for
}//HS_PullData

function HS_Display_Calories(FormHandler)
{
	if (!FormHandler.food.options[0].selected && !FormHandler.food_serv.options[0].selected && !FormHandler.amount.options[0].selected)
	{
		FormHandler.calories.value = Math.round(Math.round(FormHandler.food.options[FormHandler.food.selectedIndex].value.substring(FormHandler.food.options[FormHandler.food.selectedIndex].value.indexOf("_") + 1) * FormHandler.food_serv.options[FormHandler.food_serv.selectedIndex].value.substring(FormHandler.food_serv.options[FormHandler.food_serv.selectedIndex].value.indexOf("_") + 1) * eval(FormHandler.amount.options[FormHandler.amount.selectedIndex].value) / 10) / 10);
		
	}
	else
	{
		FormHandler.calories.value = "0";
	}
}//HS_Display_Calories

function HS_SearchFoodDisplay_Calories(FormHandler)
{
	foods = document.getElementsByName("food");
	for (i=0; i<foods.length; i++)
	{
		if (foods[i].checked)
		{
			food = foods[i].value;
			if (food != "0" && !FormHandler.food_serv.options[0].selected && !FormHandler.amount.options[0].selected)
			{
				FormHandler.calories.value = Math.round(Math.round(food.substring(food.indexOf("_") + 1) * FormHandler.food_serv.options[FormHandler.food_serv.selectedIndex].value.substring(FormHandler.food_serv.options[FormHandler.food_serv.selectedIndex].value.indexOf("_") + 1) * eval(FormHandler.amount.options[FormHandler.amount.selectedIndex].value) / 10) / 10);
				
			}
			else
			{
				FormHandler.calories.value = "0";
			}
			return;
		}
	}
}//HS_SearchFoodDisplay_Calories

function removeFromMenu(foodId)
{
	if (confirm("Are you sure you want to remove this food from your menu?"))
	{
		if (document.getElementById("add_from_fav").checked)
		{
			checked = "&cur_checked=fav";
		}
		else
		{
			if (document.getElementById("add_from_search").checked)
			{
				checked = "&cur_checked=search";
			}
			else
			{
				checked = "";
			}
		}
		myPath = window.location.search.replace("?", "");
		window.location = "index.php?handler=diet&action=remove&food_id=" + foodId + "&ret_loc=" + escape(myPath) + checked;
	}
}//removeFromMenu

function removeFromFav(foodId)
{
	if (confirm("Are you sure you want to remove this food from your favorite food database?"))
	{
		if (document.getElementById("add_from_fav").checked)
		{
			checked = "&cur_checked=fav";
		}
		else
		{
			if (document.getElementById("add_from_search").checked)
			{
				checked = "&cur_checked=search";
			}
			else
			{
				checked = "";
			}
		}
		myPath = window.location.search.replace("?", "");
		window.location = "index.php?handler=diet&action=remove_favorites&food_id=" + foodId + "&ret_loc=" + escape(myPath) + checked;
	}
}//removeFromFav

function addToFav(foodId)
{
	if (document.getElementById("add_from_fav").checked)
	{
		checked = "&cur_checked=fav";
	}
	else
	{
		if (document.getElementById("add_from_search").checked)
		{
			checked = "&cur_checked=search";
		}
		else
		{
			checked = "";
		}
	}
	myPath = window.location.search.replace("?", "");
	window.location = "index.php?handler=diet&action=add_to_favorites&food_id=" + foodId + "&ret_loc=" + escape(myPath) + checked;
}//addToFav

function datePicker(loc, mem_id, country, time_zone, img_path, month, year)
{
	loaderTxt = "Loading...";
	document.getElementById("datePicker"+loc).innerHTML = "<div style=\"padding: 10px; font-size: 10pt;\">"+loaderTxt.blink()+"</span>";
	month = (month == null) ? "0" : month;
	year = (year == null) ? "0" : year;
	switch (loc)
	{
		case "Db":
			thisForm = document.forms[0];
			break;
		case "Fav":
			thisForm = document.forms[1];
			break;
		case "Search":
			thisForm = document.forms[2];
			break;
	}
	var sDate = document.getElementById("date").value;
	document.getElementById("datePicker"+loc).style.display = "block";
	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest)
	{
		self.xmlHttpReq = new XMLHttpRequest();
	}//if
	// IE
	else if (window.ActiveXObject)
	{
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}//else if
	self.xmlHttpReq.open('POST', "index.php", true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function()
	{
		if (self.xmlHttpReq.readyState == 4 && self.xmlHttpReq.status == 200)
		{
			document.getElementById("datePicker"+loc).innerHTML = self.xmlHttpReq.responseText;
		}//if
	}//function
	//replaced value : thisForm.date.value => sDate
	self.xmlHttpReq.send("handler=calendar&action=date_picker&cur_date="+escape(sDate)+"&cur_url="+escape(window.location.search.replace("?", ""))+"&country="+country+"&mem_id="+mem_id+"&img_path="+img_path+"&form="+loc+"&time_zone="+time_zone+"&req_month="+month+"&req_year="+year);
}//datePicker

function pickDate(loc, thisDate)
{
	switch (loc)
	{
		case "Db":
			iCurForm = "0";
			sCurForm = "db";
			break;
		case "Fav":
			iCurForm = "1";
			sCurForm = "fav";			
			break;
		case "Search":
			iCurForm = "2";
			sCurForm = "search";			
			break;
	}
	document.getElementById("date").value = thisDate;
	//sCurForm.date.value = thisDate;
	//document.forms[iCurForm].date.value = thisDate;
	document.getElementById("datePicker"+loc).style.display = "none";
	document.getElementById("datePicker"+loc).innerHTML = "";
}//pickDate



//-->
