
function submitform(pageID, btnSubmit, foodMealMapID)
{
	document.getElementById("btnSubmit").value = btnSubmit;
	document.getElementById("cboPageID").value = pageID;
	document.getElementById("cboFoodMealMapID").value = foodMealMapID;
	document.frmEditor.submit();	
}

function editQuantity(foodMealMapId) {
	//Change show to update
	document.getElementById("showQuantity" + foodMealMapId).style.display = 'none';
	document.getElementById("editQuantity" + foodMealMapId).style.display = '';
	document.getElementById("txtAmount" + foodMealMapId).select();
	document.getElementById("txtAmount" + foodMealMapId).focus();
}

function validateCategory(field, alertText)
{
    with(field)
    {
        if(value==null || value=="" || value=="0")
        {
            alert(alertText);
            return false;
        }
        else
        {
            return true;
        }
    }
}

function validateRadio(field, alertText)
{
	var result = -1;
	var radioLength = field.length;
	
	if(radioLength == undefined)
	{
		if(field.checked || field.checked == "checked")
		{
			result = 0;
		}
	}
	else
	{
		for(counter = field.length-1; counter > -1; counter--)
		{
			if(field[counter].checked || field[counter].checked == "checked")
			{
				result = counter;
				counter = -1
			}
		}
	}
	
	if(result == -1)
	{
		alert(alertText);
		return false;
	}
}

function validateCarbForm(thisForm)
{
    with(thisForm)
    {
    	if(validateCategory(selectCarbCat, "Select a preferred Carb Category") == false)
    	{
    		return false;
    	}
    		
        if(validateRadio(radioCarb, "Select a Carb source.") == false)
        {
            return false;
        }
    }
    
    return true;
}

function validateProteinForm(thisForm)
{
    with(thisForm)
    {	 
    	if(validateCategory(selectProteinCat, "Select a preferred Protein Category") == false)
    	{
    		return false;
    	}
	
        if(validateRadio(radioProtein, "Select a Protein source.") == false)
        {
            return false;
        }
    }
    
    return true;
}

function validateFatForm(thisForm)
{
    with(thisForm)
    {
    	if(validateCategory(selectFatCat, "Select a preferred Fat Category") == false)
    	{
    		return false;
    	}

        if(validateRadio(radioFat, "Select a Fat source.") == false)
        {
            return false;
        }
    }
    
    return true;
}

var allowPrompt = true;

function warnUser(e)
{
	if (!e)
	{
		var e = window.event;
	}
	
	
	if(allowPrompt)
	{
		e.returnValue = 'All of your changes for this meal will be lost if you continue.  Click "Update & Return" to save this meal before leaving the page.';
	}
	else
	{
		// do nothing
	}
}

function noPrompt()
{
	allowPrompt = false;
}
