var displayTotal = 0;
var faceoffBack = 0;

function XmlhttpObject()
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();

    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
	
return req;
}

var req = new XmlhttpObject();
//Global varibles 

function clearText()
{
	if(document.frmSearch.search.value=="Enter Keyword")
	{
		document.frmSearch.search.value='';
	}
}


function LTrim(value)
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

function RTrim(value)
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

function trim(value)
{
	return LTrim(RTrim(value));
}

function emailValidation(email)
{
	
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if(filter.test(email))
	{
		return true;
	}
	else
	{
		return "invalid";
	}
}

function updateTotal()
{
	var imgVars=document.getElementsByTagName('img');
	var foodId=new Array();
	var j=0;
	for(var i=0; i<imgVars.length; i++)
	{	
		var absPathArr=(imgVars[i].src).split("/");
		var num=absPathArr.length
		var imgName=absPathArr[num-1];
		if(imgName=="close.gif")
		{
			foodId[j]=imgVars[i].id;
			j++;
			}
		
		//return;
	}
	getTotal(foodId);
}

function getTotal(foodId)
{
	var totalFat=0;
	var totalFatDV=0;
	var totalSatFat=0;
	var totalSatFatDV=0;
	var totalCholesterol=0;
	var totalCholesterolDV=0;
	var totalSodium=0;
	var totalSodiumDV=0;
	var totalCarbs=0;
	var totalSugar=0;
	var totalProtein=0;
	for(i=0;i<foodId.length;i++)
	{
		id=foodId[i];
		totalFat +=foodData[id]["Fat"];


		totalFatDV +=foodData[id]["FatDV"];
		totalSatFat +=foodData[id]["SatFat"];
		totalSatFatDV +=foodData[id]["SatFatDV"];
		totalCholesterol +=foodData[id]["Cholesterol"];
		totalCholesterolDV +=foodData[id]["CholesterolDV"];
		totalSodium +=foodData[id]["Sodium"];

		totalSodiumDV +=foodData[id]["SodiumDV"];
		totalCarbs +=foodData[id]["Carbs"];
		totalSugar +=foodData[id]["Sugar"];
		totalProtein +=foodData[id]["Protein"];
	}
	
}


function checkImage(thisCheck,catId,foodId,foodDetailStr)
{
	
	if(thisCheck.id==foodId)
	{
		thisCheck.src="images/close_blank.gif";
		thisCheck.id='';
		
		// now to assign value in hidden field to add meal...

		document.getElementById('addMeal').value = foodId;
		
		document.getElementById('itemAdded').value = foodId;
	}
	else
	{
		thisCheck.src="images/close.gif";
		thisCheck.id +=foodId;
		document.getElementById('addMeal').value = "0";
		
	}

}

function selOnchangeCat(id)
{
	if(id !='')
	{
		 
		
		url="getFoodDetail.php?id=" + id;
		req.open("GET",url);
		
		req.onreadystatechange=function()
		{
			if(req.readyState==4 && req.status==200)
			{
				var res=req.responseText;
				var divObj=document.getElementById('nutritional_border_center1');
				divObj.innerHTML='';
				divObj.innerHTML=res;
			}
		}
		req.send(null);
	}
}


function selRestroOnchange(id)
{
	if(id !='')
	{
		url="getCat.php?id=" + id;
		req.open("GET",url);
		
		req.onreadystatechange=function()
		{
			if(req.readyState==4 && req.status==200)
			{
				var res=req.responseText;
				var divObj=document.getElementById('restuarent');
				divObj.innerHTML='';
				divObj.innerHTML=res;
			}
		}
		req.send(null);
	}

}

/*
function getTotal(id)
{
	var res;
	if(id !='')
	{
		var req=false;
		if(window.XMLHttpRequest)
		{
			req=new XMLHttpRequest();
		}
		else if(window.ActiveXObject)
		{
			req=new window.ActiveXObject("Microsoft.XMLHTTP");
		}
		
		
		url="getTotal.php?id=" + id;
		req.open("GET",url);
		
		req.onreadystatechange=function()
		{
			if(req.readyState==4 && req.status==200)
			{
				res=req.responseText;
				str='<inout type="hidden" id="getTotalResponse" name="getTotalResponse" value=" +
				document.write('<input ty');
				return false;
				
				return res;
				
				var foodTotalArr=new Array();
				foodTotalArr=response.split('#');
				totalFat=foodTotalArr[0];
				totalFatDV=foodTotalArr[1];
				totalSatFat=foodTotalArr[2];
				totalSatFatDV=foodTotalArr[3];
				totalCholesterol=foodTotalArr[4];
				totalCholesterolDV=foodTotalArr[5];
				totalSodium=foodTotalArr[6];
				totalSodiumDV=foodTotalArr[7];
				totalCarbs=foodTotalArr[8];
				totalSugar=foodTotalArr[9];
				totalProtein=foodTotalArr[10];
				
				
			}
		}
		req.send(null);
	}
	return res;
	window.location="calculator_2.php?res="+ res + "&cat=" + cat;
}
*/

var did;
function AddRestro(restroId)
{
	var restroId = restroId;
	var chkNumberOfResto = document.getElementById('chkCounter').value;
	var id;

	if(chkNumberOfResto > 3 )
	{
		alert("Sorry! you can not add more than 3 Restaurant");
		return false;
	}
	
	
	if(restroId == 0 )
	{
		alert("Please Select a Restaurant");
		return false;
	}
	else
	{
		document.getElementById('face_off_gray_center').style.display = 'block';
		 
		url="get_restro_name.php?id="+restroId+"&back="+faceoffBack+"&count="+chkNumberOfResto;
		var nextFunct=false;
		req.open("GET",url,false);
			
		req.send(null);
		
		var res=req.responseText;
			
		if(res=='already')
				alert('This resturant is already added.');
		else
		{
			var divObj=document.getElementById('name'+chkNumberOfResto);
			divObj.innerHTML='';
			divObj.innerHTML=res;
			for(var i=1;i<chkNumberOfResto;i++)
			{
				var tmpdiv	=	'div'+i;
				if(document.getElementById(tmpdiv)){
					if(faceoffBack!=1)
						document.getElementById(tmpdiv).className	=	"tab_button";
				}
				
			}

			document.getElementById('chkCounter').value++;
			did	=	document.getElementById('chkCounter').value;
			nextFunct=true;
			
			var refreshTime = 1000; // 1sec
			//window.setTimeout("switchAd()", refreshTime);
			
			switchAd();
		}
	}
}

//Function added by Ajay Singh on 6-feb-2008 to change color of active restro.
function changeColor(flag)
{
	if(document.getElementById('div1'))
		document.getElementById('div1').className	=	"tab_button";
	
	if(document.getElementById('div2'))
		document.getElementById('div2').className	=	"tab_button";
	
	if(document.getElementById('div3'))
		document.getElementById('div3').className	=	"tab_button";

	var tmp	=	'div'+flag;
	document.getElementById(tmp).className	=	"active_tab_button";

}

function changeLi(flag)
{
	if(document.getElementById('div1'))
		document.getElementById('div1').className	=	"";
	
	if(document.getElementById('div2'))
		document.getElementById('div2').className	=	"";
	
	if(document.getElementById('div3'))
		document.getElementById('div3').className	=	"";

	var tmp	=	'div'+flag;
	document.getElementById(tmp).className	=	"compare_active";
}


//Function added by Ajay Singh on 19-Jan-2008 to remove restro from added list.
function delRestro(id, counter)
{
	var restroId = id;
	var id;
		
	if(restroId == 0 )
	{
		alert("Please Select a Restaurant");
		return false;
	}
	else
	{
		url="get_restro_name.php?action=remove&id="+restroId+"&count="+counter;
		req.open("GET",url,true);
		
		var nextFunct=false;
		req.onreadystatechange=function()
		{
			if(req.readyState==4 )
			{
				var res=req.responseText;
				if(res=="remove")
				{
					var divObj=document.getElementById('name'+counter);
					divObj.innerHTML='';
					document.getElementById('chkCounter').value--;
					var chkNumberOfResto = document.getElementById('chkCounter').value;
					if(chkNumberOfResto == 0 )
					{
						document.getElementById('face_off_gray_center').style.display = 'none';
						
					}
				}
			else
				{
					
					nextFunct=true;
					
				}
			}
		}
		req.send(null);

var refreshTime = 1000; // 1sec
 window.setTimeout("switchAd()", refreshTime);

 
	}


}

function switchAd()
{
	var id=did;
	if(id==4)
			getMenu(document.getElementById('3').value,0,8);
	else if(id==3)
			getMenu(document.getElementById('2').value,0,8);
	else
			getMenu(document.getElementById('1').value,0,8);

}



function getMenu(divId,limit1,limit2)
{

	var id		= divId;
	var limit1	= limit1;
	var limit2	= limit2;
 
 
 	document.getElementById('button').style.display = 'none';
	url="get_menu.php?id="+id+"&limit1="+limit1+"&limit2="+limit2;
	req.open("GET",url,false);
		
	req.send(null);
	var res=req.responseText;
	var divObj=document.getElementById('menulist');
	divObj.innerHTML='';
	divObj.innerHTML=res;
}


function menuDetail(catId)
{
	url="get_menu_details.php?id="+catId;

	req.open("GET",url,false);

	req.send(null);
	var res=req.responseText;
	var divObj=document.getElementById('menulist');
	divObj.innerHTML='';
	divObj.innerHTML=res;

	document.getElementById('button').style.display = 'block';
}


function getFoodDetails(foodId)
{

	url="get_food_details.php?id="+foodId;
	
	req.open("GET",url,true);
	
	req.onreadystatechange=function()
	{
		if(req.readyState==4 )
		{
			var res=req.responseText;
			var divObj=document.getElementById('menulist');
			divObj.innerHTML='';
			divObj.innerHTML=res;

			document.getElementById('button').style.display = 'block';
		}
	}
	req.send(null);
}


function getFoodItemDetails()
{
	var itemIds = '';
			
	if(document.itemSelectionForm.itemList.length===undefined)
	{
		if(document.itemSelectionForm.itemList.checked)
		{ 
			foodId = document.itemSelectionForm.itemList.value;
			if(itemIds==''){
				itemIds	=	foodId;
			}
			else{
				itemIds	=	itemIds +"," + foodId;
			}
			document.itemSelectionForm.itemList.checked=false;
		}
	}

	else
	{
		var tmpVar	=	0;
		for (counter = 0; counter < document.itemSelectionForm.itemList.length; counter++)
		{
			// If a checkbox has been selected it will return true
			// (If not it will return false)
			if (document.itemSelectionForm.itemList[counter].checked)
			{ 
				tmpVar	=	1;
				foodId = document.itemSelectionForm.itemList[counter].value;
				if(itemIds=='')
				{
					itemIds	=	foodId;
				}
				else
				{
					itemIds	=	itemIds +"," + foodId;
				}
				document.itemSelectionForm.itemList[counter].checked=false;
				
			}

		}
		if(tmpVar==0)
		{
			alert("Please Select a Meal Item.");
			return false;
		}
	}
		
	url="get_food_details.php?id="+itemIds;
	
	req.open("GET",url,true);
	
	req.onreadystatechange=function()
	{
		if(req.readyState==4 )
		{
			var res=req.responseText;
			var divObj=document.getElementById('menulist');
			divObj.innerHTML='';
			divObj.innerHTML=res;

			document.getElementById('button').style.display = 'block';
		}
	}
	req.send(null);

}


/*function addToMeal(foodId)
{	alert('foodId='+foodId);
alert(document.menu_form.foodList.length);
	var foodIds = '';
	if(foodId =="" && document.menu_form.foodList.length==0) 
	{
		alert("Please Select a Meal");
		return false;
	}

	if(document.menu_form.foodList.length==0){
		alert("Please Select a Meal");
		return false;
	}
	
	if(foodId !=0)
	{	
		alert('foodId2='+foodId);
		if(document.menu_form.foodList.length===undefined)
		{
			if(document.menu_form.foodList.checked)
			{ 
				foodId = document.menu_form.foodList.value;
				if(foodIds=='')
				{
					foodIds	=	foodId;
				}
				else
				{
					foodIds	=	foodIds +"," + foodId;
				}
				document.menu_form.foodList.checked=false;
			}
		}
		else
		{
			for (counter = 0; counter < document.menu_form.foodList.length; counter++)
			{
				// If a checkbox has been selected it will return true
				// (If not it will return false)
				if (document.menu_form.foodList[counter].checked)
				{ 
					foodId = document.menu_form.foodList[counter].value;
					if(foodIds=='')
					{
						foodIds	=	foodId;
					}
					else
					{
						foodIds	=	foodIds +"," + foodId;
					}
					document.menu_form.foodList[counter].checked=false;
				}

			}
		}
	}

	
	if(foodId == 0)
		url="add_meal.php";
	else
		url="add_meal.php?id="+foodIds;

	

	req.open("GET",url,false);
	
	req.send(null);
	var res=req.responseText;
			var divValue = document.getElementById('gray_background_withborder').innerHTML;
			//var divValue = document.getElementById('meal_item').innerHTML;
			//alert(divValue);
			if(divValue == "No Items in your Meal")
			{
				var divObj=document.getElementById('gray_background_withborder');
				//var divObj=document.getElementById('meal_overview');
				//alert(divObj);
				divObj.innerHTML='';
				divObj.innerHTML=res;
			}
			else
			{
				var divObj=document.getElementById('gray_background_withborder');
				//var divObj=document.getElementById('meal_item');
				
				divObj.innerHTML='';
				divObj.innerHTML=res;
				document.getElementById('addMeal').value = "0";
			}
}
*/


function addToMeal(foodId)
{	
	var foodIds = '';
	if(foodId =="" && document.menu_form.foodList.length==0) 
	{
		alert("Please Select a Meal");
		return false;
	}

		
	if(foodId !=0 || foodId=='')
	{	
		var checkvar	=	0;
		if(document.menu_form.foodList.length===undefined)
		{
			if(document.menu_form.foodList.checked)
			{ 
				foodId = document.menu_form.foodList.value;
				if(foodIds=='')
				{
					foodIds	=	foodId;
				}
				else
				{
					foodIds	=	foodIds +"," + foodId;
				}
				checkvar	=	1;
				document.menu_form.foodList.checked=false;
			}
		}
		else{
		for (counter = 0; counter < document.menu_form.foodList.length; counter++)
		{
			// If a checkbox has been selected it will return true
			// (If not it will return false)
			if (document.menu_form.foodList[counter].checked)
			{ 
				foodId = document.menu_form.foodList[counter].value;
				if(foodIds==''){
					foodIds	=	foodId;
				}
				else{
					foodIds	=	foodIds +"," + foodId;
				}
				checkvar	=	1;		
				document.menu_form.foodList[counter].checked=false;
			}

		}
	}
		if(checkvar==0){
			if(foodId !=0){
				alert("Please Select a Meal");
				return false;
			}
		}
	}

	
	if(foodId == 0)
		url="add_meal.php";
	else
		url="add_meal.php?id="+foodIds;

	req.open("GET",url,false);
	req.send(null);
	
	var res=req.responseText;
	var divValue = document.getElementById('gray_background_withborder').innerHTML;
	
	if(divValue == "No Items in your Meal"){
		var divObj=document.getElementById('gray_background_withborder');
		divObj.innerHTML='';
		divObj.innerHTML=res;
	}
	else{
		var divObj=document.getElementById('gray_background_withborder');
		divObj.innerHTML='';
		divObj.innerHTML=res;
	}
	document.getElementById('addMeal').value = "0";
	if(document.getElementById('gray_background_withborder').innerHTML== "No Items in your Meal"){
		document.getElementById('cmprBtn').style.display = "none";
	}
	window.scrollTo(0,0);
}



function removeMeal(foodId)
{
	
	if( (foodId =="") && (foodId != "0") )
	{
		alert("Please Select a Meal");
		return false;
	}
		
	url="add_meal.php?action=remove&id="+foodId;
	req.open("GET",url,true);
	
	req.onreadystatechange=function()
	{
		if(req.readyState==4 )
		{
			var res = req.responseText;
			var divFood	=	"foodId"+foodId;
			
			//if(res==1)
			//{
				var divObj=document.getElementById('gray_background_withborder');
				//var divObj=document.getElementById('meal_item');

				divObj.innerHTML='';
				divObj.innerHTML=res;
			//}
		}
	}
	req.send(null);
}


function compare(foodId)
{
	if(foodId == "")
	{
		alert("No Food Item Is Selected To Compare");
		return false;
	}
	else
	{
		document.location.href="compare_nutrition.php?lt=0";
	}
}


function pageMenu(id,limit1,limit2)
{
	
	url="get_page_menu.php?id="+id+"&limit1="+limit1+"&limit2="+limit2;
	req.open("GET",url,true);
			
	req.onreadystatechange=function()
	{
		if(req.readyState==4 )
		{
			var res=req.responseText;
			var divObj = document.getElementById('face_off_white_center');
			divObj.innerHTML='';
			divObj.innerHTML=res;
		}
	}
	req.send(null);

}


function calculator(id,limit1,limit2)
{
	document.location.href="calculator.php?section=restaurant&id="+id+"&lt="+limit1;
}


function checkImage(thisCheck,catId,foodId)
{
	if(thisCheck.id==foodId)
	{
		thisCheck.src="images/close_blank.gif";
		thisCheck.id='';
		
		// now to assign value in hidden field to add meal...

		document.getElementById('addMeal').value  = document.getElementById('addMeal').value+","+foodId;
		
		//document.getElementById('itemAdded').value = foodId;
	}
	else
	{
		thisCheck.src="images/close.gif";
		thisCheck.id +=foodId;
		document.getElementById('addMeal').value = "0";
	}
}

//Function added by Ajay Singh on 18-Jan-2008 to display bar graph
function displayGraph()
{
	if(displayTotal==1)
		document.getElementById('graphShow').innerHTML = "<iframe  id='iframe_chart' frameborder='0'  width='541' height='230' scrolling='no' src='calculator_nutrition_chart.php'></iframe>";
	else
		document.getElementById('graphShow').innerHTML	=	'';
	
	//document.getElementById('iframe_chart').src = document.getElementById('iframe_chart').src;
}


function calculateTotal()
{ 
	url="calculate_total_meal.php";

	document.getElementById('addMeal').value ="";
	//displayTotal	=	1;
	req.open("GET",url,false);

	req.send(null);

	var res=req.responseText;
	var divObj=document.getElementById('totalresult');
	divObj.innerHTML='';
	divObj.innerHTML=res;
	
}


function displayTotalMenu()
{
	url="calculator_menu.php";
	req.open("GET",url,true);

	req.onreadystatechange=function()
	{
		if(req.readyState==4 )
		{
			var res=req.responseText;

			var divValue = document.getElementById('gray_background_withborder').innerHTML;
			calculateTotal();
			//var divValue2 = document.getElementById('nutritionTable').innerHTML;
			if(divValue == "No Items in your Meal")
			{
				
			}
			else
			{
				var divObj=document.getElementById('nutritionTable');
				divObj.innerHTML='';
				divObj.innerHTML=res;
			}
		}
	}
	req.send(null);

}


function calculatorAddMeal(foodId)
{
	if( (foodId =="") && (foodId != "0") )
	{
		alert("Please Select a Meal");
		return false;
	}
	else
	{
		var id = document.getElementById('addMeal').value;
		
		url="calculator_add_meal.php?food_id="+id;
		document.getElementById('addMeal').value ="";
		req.open("GET",url,true);
		
		req.onreadystatechange=function()
		{
			if(req.readyState==4 )
			{
				var res=req.responseText;
				var divValue = document.getElementById('gray_background_withborder').innerHTML;
				//var divValue = document.getElementById('meal_item').innerHTML;
				if(divValue == "No Items in your Meal")
				{
					var divObj=document.getElementById('gray_background_withborder');
					//var divObj=document.getElementById('meal_item');

					divObj.innerHTML='';
					divObj.innerHTML=res;
				}
				else
				{
					
					var divObj=document.getElementById('gray_background_withborder');
					//var divObj=document.getElementById('meal_item');

					divObj.innerHTML='';
					divObj.innerHTML=divValue+"<br>"+res;
				}
			}
		}
		req.send(null);
	}

}

function SelectMeal(thisCheck,catId,foodId,foodDetailStr)
{
	
	if(thisCheck.checked)
	{
		if(thisCheck.id==foodId)
		{
		
			var mealHid	=document.getElementById('addMeal').value;
			if(mealHid =='' || mealHid ==0)
			{
				document.getElementById('addMeal').value = foodId;
			}
			else
			{
				document.getElementById('addMeal').value = mealHid + ","+foodId;
			}
			document.getElementById('itemAdded').value = foodId;
				 
		}
		else
		{
			 
			thisCheck.id +=foodId;
			document.getElementById('addMeal').value = "0";
		}
	}
	else
	{
		
	}

}


function SelectMultiMeal(catId,foodId,foodDetailStr)
{
	
	document.getElementById('addMeal').value = foodId;
}


function calculatorAddMultiMeal(foodItemId)
{ 
	var foodIds = '';
	if(foodItemId!==-1 && foodItemId!==0)
	{
		foodIds	=	document.calculator_menuForm.foodList.value;
	/*
	if(document.calculator_menuForm.foodList.length===undefined)
	{
		if(document.calculator_menuForm.foodList.checked)
		{ 
			foodId = document.calculator_menuForm.foodList.value;
			if(foodIds=='')
			{
				foodIds	=	foodId;
			}
			else
			{
				foodIds	=	foodIds +"," + foodId;
			}
			document.calculator_menuForm.foodList.checked=false;
		}
	}
	else
	{
		for (counter = 0; counter < document.calculator_menuForm.foodList.length; counter++)
		{
			// If a checkbox has been selected it will return true
			// (If not it will return false)
			if (document.calculator_menuForm.foodList[counter].checked)
			{ 
				foodId = document.calculator_menuForm.foodList[counter].value;
				if(foodIds=='')
				{
					foodIds	=	foodId;
				}
				else
				{
					foodIds	=	foodIds +"," + foodId;
				}
				document.calculator_menuForm.foodList[counter].checked=false;
			}

		}
	} */
}

	//if (foodId =="" && foodId !=0)
	if (foodIds =="" && foodItemId!=0 && foodItemId!==-1)
	{
		alert("Please Select a Meal");
		return false;
	}
	else
	{
		url="calculator_add_meal.php?food_id="+foodIds;		
		document.getElementById('addMeal').value ="";
		req.open("GET",url,false);
		req.send(null);
	
		var res=req.responseText;
			
		var divValue = document.getElementById('gray_background_withborder').innerHTML;
		//var divValue = document.getElementById('meal_item').innerHTML;
		if(divValue == "No Items in your Meal")
		{
			var divObj=document.getElementById('gray_background_withborder');
			//var divObj=document.getElementById('meal_item');
			divObj.innerHTML='';
			divObj.innerHTML=res;
		}
		else
		{
			var divObj=document.getElementById('gray_background_withborder');
			//var divObj=document.getElementById('meal_item');
			divObj.innerHTML='';
			divObj.innerHTML=res;
		}

		calculateTotal();
	}
}


//Function added by Ajay Singh on 17-Jan-2008 to remove food from meal
function calculateorRemoveMeal(foodId)
{
	//document.getElementById('graphShow').innerHTML	=	'';
	if(foodId == "removeAll")
	{
		url="calculator_add_meal.php?action=removeAll&food_id=";
	}
	else
		url="calculator_add_meal.php?action=remove&food_id="+foodId;		
	
	req.open("GET",url,true);
		
	req.onreadystatechange=function()
	{
		if(req.readyState==4 )
		{
			var res=req.responseText;
			if(res == "No Items in your Meal")
			{
				displayTotal = 0;
			}
			var divValue = document.getElementById('gray_background_withborder').innerHTML;
			//var divValue = document.getElementById('meal_item').innerHTML;
			if(divValue == "No Items in your Meal")
			{
				var divObj=document.getElementById('gray_background_withborder');
				//var divObj=document.getElementById('meal_item');
				divObj.innerHTML='';
				divObj.innerHTML=res;
			}
			else
			{
				var divObj=document.getElementById('gray_background_withborder');
				//var divObj=document.getElementById('meal_item');
				divObj.innerHTML='';
				divObj.innerHTML=res;
			}

			if(foodId == "removeAll")
			{
				displayTotal = 0;
				if(document.getElementById('totalresult'))
					document.getElementById('totalresult').innerHTML='';
			}
			else if(displayTotal==1)
			{
				calculateTotal();
			}
		}
	}
	req.send(null);

}

	
	function clearMeal()
	{
		document.getElementById('gray_background_withborder').innerHTML = "No Items in your Meal";
		//document.getElementById('meal_item').innerHTML = "No Items in your Meal";
		document.getElementById('totalresult').innerHTML = '';
	}

	
	//This function added By Ajay Singh on 5-feb-2008 to check email
	function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID.Please enter valid email ID.")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID.Please enter valid email ID.")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		     alert("Invalid E-mail ID.Please enter valid email ID.")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID.Please enter valid email ID.")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		     alert("Invalid E-mail ID.Please enter valid email ID.")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		     alert("Invalid E-mail ID.Please enter valid email ID.")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		     alert("Invalid E-mail ID.Please enter valid email ID.")
		    return false
		 }

 		 return true					
	}

	//This function added by Ajay Singh on 5-feb-2008 to validate contact us form.
	function checkContactForm()
	{
		if(document.contactUsForm.senderName.value=='')
		{
			alert("Please enter your name.");
			document.contactUsForm.senderName.focus();
			return false;
		}
		
		if(document.contactUsForm.senderEmail.value=='')
		{
			alert("Please enter your email.");
			document.contactUsForm.senderEmail.focus();
			return false;
		}

		if (echeck(document.contactUsForm.senderEmail.value)==false){
			document.contactUsForm.senderEmail.value="";
			document.contactUsForm.senderEmail.focus();
			return false;
		}

		if(document.contactUsForm.subject.value=='')
		{
			alert("Please enter subject for email.");
			document.contactUsForm.subject.focus();
			return false;
		}

		if(document.contactUsForm.message.value=='')
		{
			alert("Message body is empty. Please write few words. Your suggession help us to improve functionality.");
			return false;
		}

		document.contactUsForm.submit();
		return true;
	}


//This function added by Ajay Singh on 5-feb-2008 to validate contact us form.
	function checkTellFriendForm()
	{
		if(document.tellFriendForm.senderName.value=='')
		{
			alert("Please enter your name.");
			document.tellFriendForm.senderName.focus();
			return false;
		}
		
		if(document.tellFriendForm.senderEmail.value=='')
		{
			alert("Please enter your email.");
			document.tellFriendForm.senderEmail.focus();
			return false;
		}

		if (echeck(document.tellFriendForm.senderEmail.value)==false){
			document.tellFriendForm.senderEmail.value="";
			document.tellFriendForm.senderEmail.focus();
			return false;
		}

		var rep1	=	document.tellFriendForm.recipient1Name.value;
		var rep2	=	document.tellFriendForm.recipient2Name.value;
		var rep3	=	document.tellFriendForm.recipient3Name.value;

		var rep1Email	=	document.tellFriendForm.recipient1Email.value;
		var rep2Email	=	document.tellFriendForm.recipient2Email.value;
		var rep3Email	=	document.tellFriendForm.recipient3Email.value;

		if(rep1=='' && rep2=='' && rep3=='')
		{
			alert("Please enter at least 1 recipient.");
			document.tellFriendForm.recipient1Name.focus();
			return false;
		}

		if(rep1Email=='' && rep2Email=='' && rep3Email=='')
		{
			alert("Please enter at least 1 recipient.");
			document.tellFriendForm.recipient1Email.focus();
			return false;
		}
		
		if((rep1!='' && rep1Email=='') || (rep1Email!='' && rep1==''))
		{
			alert("Please enter recipient1's email/name.");
			document.tellFriendForm.recipient1Email.focus();
			return false;
		}

		if((rep2!='' && rep2Email=='') || (rep2Email!='' && rep2==''))
		{
			alert("Please enter recipient2's email/name.");
			document.tellFriendForm.recipient2Email.focus();
			return false;
		}

		if((rep3!='' && rep3Email=='') || (rep3Email!='' && rep3==''))
		{
			alert("Please enter recipient3's email/name.");
			document.tellFriendForm.recipient3Email.focus();
			return false;
		}

		if (rep1Email!='' && echeck(rep1Email)==false){
			document.tellFriendForm.recipient1Email.value="";
			document.tellFriendForm.recipient1Email.focus();
			return false;
		}

		if (rep2Email!='' && echeck(rep2Email)==false){
			document.tellFriendForm.recipient2Email.value="";
			document.tellFriendForm.recipient2Email.focus();
			return false;
		}

		if (rep3Email!='' && echeck(rep3Email)==false){
			document.tellFriendForm.recipient3Email.value="";
			document.tellFriendForm.recipient3Email.focus();
			return false;
		}

		
		if(document.tellFriendForm.message.value=='')
		{
			alert("Message body is empty. Please write few words. Your suggession help us to improve functionality.");
			return false;
		}

		document.tellFriendForm.submit();
		return true;
	}

	function makeBlank(flag)
	{
		//alert(document.searchForm.searchbox.value=='');
		if(document.searchForm.searchbox.value=='' || document.searchForm.searchbox.value=='Search Restaurants')
		{
			document.searchForm.searchbox.value = '';
		}
	}

	function checkSearch()
	{
		if(document.searchForm.searchbox.value=='' || document.searchForm.searchbox.value=='Search Restaurents')
		{
			alert("Please enter restaurent name for search.");
			document.searchForm.searchbox.focus();
			return false;
		}

		document.searchForm.submit();
		return true;
	}


	/* 
	Folowing function remove all the options from a select dd
	parameter: select object
	*/
	function RemoveAll(select)
	{
		select.options.length = 0;
	}


	/* 
	Following function  find the index  of a option in the select dd with the specified value
	parameter1: select object
	parameter1: value of the required option
	*/

	function findIndexOf(select,OptionValue){

	var index=-1;
	for(i=0; i<select.length; i++)
		{
		if(select.options[i].value==OptionValue)
		   {
			 index=i;
			 break;
		   }
		}
	return index;
	}



	/* 
	Following function  slect an option in the select dd with the specified value
	parameter1: select object
	parameter1: value of the option to be select
	*/

	function selectOptionValue(select,OptionValue)
	{
		index=findIndexOf(select,OptionValue);
		if(index!=-1){
			select.options[index].selected = true;
		}else{
			//alert('OptionValue='+OptionValue+' Not found');
		}
	}

	
	/* 
	Following function Add an option In the specified select dd
	parameter1: select object
	parameter1: option Text 
	parameter1: option Value 
	parameter1: pos index 
	*/

	function  addOption(select,OptionText,OptionValue,pos){
		select.options[pos] = new Option(OptionText, OptionValue);
	}

	
	function getRestroDD(name,select_dd,selected_value){
		
		var select_id=document.getElementById(select_dd);
		var url	=	'get_restro_faceoff.php?action=getcity&name='+name;
		
		req.open("GET",url,false);
		req.send(null);
		
		var result=req.responseText;
		pos=0;
		//alert(result);
		eval(result);
		RemoveAll(select_id);
		for(i in cities) { 
			var rest_name = cities[i].replace(/<\/?[^>]+>/gi, '');
			rest_name = rest_name.replace(/&#039;/gi, '\'');
			addOption(select_id,rest_name,i,pos++);
		}
		selectOptionValue(select_id,selected_value);
		/*
			req.onreadystatechange=function()
			{
				if(req.readyState==4 )
				{
					var result=req.responseText;
					pos=0;
					//alert(result);
					eval(result);
					RemoveAll(select_id);
					for(i in cities) { 
						var rest_name = cities[i].replace(/<\/?[^>]+>/gi, '');
						rest_name = rest_name.replace(/#039;/gi, '\'');
						addOption(select_id,rest_name,i,pos++);
					}
					selectOptionValue(select_id,selected_value);
				}
			}
			req.send(null);*/
	}


	function selRestro(selId,name)
	{
		for(var i=1;i<28;i++){
			var liId	=	"li"+i;
			//alert(liId);
			document.getElementById(liId).className	=	"";
		}
		
		document.getElementById(selId).className = "list_active";

		getRestroDD(name,'restroName','');

	}
