﻿


function resizeIframe() {

	//hide the loding message box
	
	
    // this function is used on both onload events for your-meal-details.aspx adn nutritioninfo.aspx page
	var otherH = 60;
	var rowH = 30;
	var totalMItems = 0;
	
	if(document.getElementById("totalMItems")){
		totalMItems = document.getElementById("totalMItems").value; 
	}
	var totalNItems = 0;
	if (document.getElementById("totalNItems")){
		totalNItems = document.getElementById("totalNItems").value; 
	}
	
	if(document.getElementById("PageLocation")){ //a hidden field declared on your-meal-details.aspx and nutritioninfo.aspx pages to get a different value for both pages
	    if(document.getElementById("PageLocation").value == "BUILDAMEAL"){ //coming from Build A meal page chage otherH to be larger height
		    otherH = 380 ;
		    GetTotalNu();
		}else if(document.getElementById("PageLocation").value == "ALLERGEN"){ // from allergen page
			otherH = 0;
			rowH = 20;
	    }else{ // coming from nutrition page
			parent.document.getElementById('msgDiv').style.display="none";
	        if (totalMItems!=0){ //has menu items on nutrition page then change the otherH
	            otherH = 320;
	        } else {
				otherH = -200; //hide top border onload when category id is 0 or nothing
			}
	    }
	}
	
	var FramePageHeight = 0; 
	FramePageHeight = (parseInt(totalMItems) + parseInt(totalNItems)) * rowH + parseInt(otherH);
	
    var opera = (navigator.userAgent.indexOf("Opera") >= 0)? true: false;
    var ie = (document.all && !opera)? true: false;

    if (parseInt(navigator.appVersion)>3) {
        if (ie) {
            //parent.document.body.scroll='no'; 
            parent.document.getElementById('nuInfoFrame').height=document.getElementById("framepage").scrollHeight;
        }
        else {
            //parent.document.body.scroll='no';
			
            parent.document.getElementById("nuInfoFrame").height=FramePageHeight; 
            //parent.document.getElementById('yourmealframe').height=700;
        }
    }
}


function GetTotalNu(){
    var totalFat  = 0;
    var totalCarbs = 0;
    var totalSugar = 0;
    var totalCalories  = 0;
    var totalProtein = 0;
    var totalSodium = 0;
    
	if(document.getElementById("totalFat")){
	    totalFat = document.getElementById("totalFat").value;
	}
	if(document.getElementById("totalCarbs")){
	    totalCarbs = document.getElementById("totalCarbs").value;
	}
	if(document.getElementById("totalSugar")){
	    totalSugar = document.getElementById("totalSugar").value;
	}
	if(document.getElementById("totalCalories")){
	    totalCalories = document.getElementById("totalCalories").value;
	}
	if(document.getElementById("totalProtein")){
	    totalProtein = document.getElementById("totalProtein").value;
	}
	if(document.getElementById("totalSodium")){
	    totalSodium = document.getElementById("totalSodium").value;
	}

	if(document.getElementById("tFatTF")){
	   document.getElementById("tFatTF").value = totalFat;
	}
	if(document.getElementById("tCarbsTF")){
	   document.getElementById("tCarbsTF").value = totalCarbs;
	}
	if(document.getElementById("tSugarTF")){
	   document.getElementById("tSugarTF").value = totalSugar;
	}
	if(document.getElementById("tCaloriesTF")){
	   document.getElementById("tCaloriesTF").value = totalCalories;
	}
	if(document.getElementById("tProteinTF")){
	   document.getElementById("tProteinTF").value = totalProtein;
	}
	if(document.getElementById("tSodiumTF")){
	   document.getElementById("tSodiumTF").value = totalSodium;
	}
}


function dynamic_iframe(){
    //resize the iframe according to the size of the window 
    var opera = (navigator.userAgent.indexOf("Opera") >= 0)? true: false;
    var ie = (document.all && !opera)? true: false;

    if (parseInt(navigator.appVersion)>3) {
        if (ie) {
            //parent.document.body.scroll='no'; 
            parent.document.getElementById('yourmealframe').height=document.getElementById("yourmealframepage").scrollHeight;
        }
        else {
            //parent.document.body.scroll='no';
            var currentfr=parent.document.getElementById('yourmealframe')
            //parent.document.getElementById('yourmealframe').height=700;
        }
    }
}


function toggleTR(rowID,nCount) { 
	var nuRowName = "nurow" + rowID;
	var expandDivID = "expandDiv" + rowID;
    var trs = document.getElementsByName(nuRowName); 
	var expandNItems =0
	expandNItems = document.getElementById("totalNItems").value; 
	for(var i=0; i < trs.length; i++){
		if (trs[i]==null) { 
			return; 
		} 
		var bExpand = trs[i].style.display == ''; 
		trs[i].style.display = (bExpand ? 'none' : ''); 
	}
	var expandDivValue = document.getElementById(expandDivID).className;
	if (expandDivValue == "mItem"){
		document.getElementById("totalNItems").value = parseInt(expandNItems) + parseInt(nCount);
		document.getElementById(expandDivID).className = "mItemExpand";
	}else{
		document.getElementById("totalNItems").value = parseInt(expandNItems) - parseInt(nCount);
		document.getElementById(expandDivID).className = "mItem";
	}
	resizeIframe();
	//dynamic_iframe();
	//loadintoIframe('yourmealframe', 'your-meal-details.aspx')
}


function showYourMeal(){
	//alert("test1");
    //parent.parent.document.getElementById('nuInfoFrame').src = "your-meal-details.aspx";
	//parent.parent.document.getElementById('nuInfoFrame').location.reload(true);
	//alert("test2");
    //var mealDivStyle = parent.parent.document.getElementById("yourmealDiv").style.display
    //if (mealDivStyle != "block"){
		//alert("none");
        //parent.parent.document.getElementById("yourmealDiv").style.display = 'block';
   // }
}


