﻿function RadioChecked(param) {
    {
        var frm = document.forms[0];

        // Take all elements of the form
        for (i = 0; i < frm.length; i++) {
            // itinerate the elements searching "RadioButtons"
            if (frm.elements[i].type == "radio") {
                // Unchecked if the RadioButton is != param
                if (param != frm.elements[i].id) {
                    document.getElementById('tr' + frm.elements[i].id).style.backgroundColor = '#ffffff';
                    frm.elements[i].checked = false;
                }
                else {
                    document.getElementById('tr' + param).style.backgroundColor = '#cdf7b6';
                }
            }
        }
    }
}
function OpenParentDialogWindow(Url, WindowName, width, height) {    
    var oWindow = window.radopen(Url, WindowName);    
    if (oWindow != null) {
        //oWindow.Center();
        oWindow.MoveTo((screen.width - width) / 2, (screen.height - height) / 2);
        oWindow.SetWidth(width);
        oWindow.SetHeight(height);
    }
}

function RowMouseOut(param) {
    if (document.getElementById(param).style.backgroundColor != '#cdf7b6') {
        document.getElementById(param).style.backgroundColor = '#ffffff';
    }
}

function RowMouseOver(param) {
    if (document.getElementById(param).style.backgroundColor != '#cdf7b6') {
        document.getElementById(param).style.backgroundColor = '#ffeecc';
    }
}

function clearText(objTextbox, Message) {
    if (document.getElementById(objTextbox).value == Message) {
        document.getElementById(objTextbox).value = "";
    }
}

function resetText(objTextbox, Message) {
    if (document.getElementById(objTextbox).value == '') {
        document.getElementById(objTextbox).value = Message
    }
}







/* function to show and hide the element using visibility */
function hideElementbyClass(classname) {
    var inc = 0;
    var alltags = document.all ? document.all : document.getElementsByTagName("*");

    for (i = 0; i < alltags.length; i++) {
        if (alltags[i].className == classname)
            if (alltags[i].style.visibility == "hidden") {
            alltags[i].style.visibility = "visible";
        } else {
            alltags[i].style.visibility = "hidden";
        }
        //customcollection[inc++]=alltags[i]; 
    }
}

/* function to show and hide the element using display property */
function hideElementbyClassDisplay(classname) {
    var inc = 0;
    var alltags = document.all ? document.all : document.getElementsByTagName("*");

    for (i = 0; i < alltags.length; i++) {
        if (alltags[i].className == classname)
            if (alltags[i].style.display == "none") {
            alltags[i].style.display = "block";
        } else {
            alltags[i].style.display = "none";
        }
        //customcollection[inc++]=alltags[i]; 
    }
}

/* function to show and hide the element, also change the button text */
function showhideElement(elementID, buttonID) {

    if (document.getElementById(elementID).style.display == "none" || document.getElementById(elementID).style.display == "") {
        document.getElementById(elementID).style.display = "block";
        document.getElementById(buttonID).innerHTML = "Hide";
    } else {
        document.getElementById(elementID).style.display = "none";
        document.getElementById(buttonID).innerHTML = "Show";
    }
}

/* function to show and hide the element, also change the button text */
function showhideElementSummary(elementID, ElementSummaryID) {

    if (document.getElementById(elementID).style.display == "none" || document.getElementById(elementID).style.display == "") {
        document.getElementById(elementID).style.display = "block";
        document.getElementById(ElementSummaryID).style.display = "none";
    } else {
        document.getElementById(elementID).style.display = "none";
        document.getElementById(ElementSummaryID).style.display = "none";
    }
}



/* function to show and hide the element using visibility */
function hideElementbyClass(classname) {
    var inc = 0;
    var alltags = document.all ? document.all : document.getElementsByTagName("*");

    for (i = 0; i < alltags.length; i++) {
        if (alltags[i].className == classname)
            if (alltags[i].style.visibility == "hidden") {
            alltags[i].style.visibility = "visible";
        } else {
            alltags[i].style.visibility = "hidden";
        }
        //customcollection[inc++]=alltags[i]; 
    }
}

/* function to show and hide the element using display property */
function hideElementbyClassDisplay(classname) {
    var inc = 0;
    var alltags = document.all ? document.all : document.getElementsByTagName("*");

    for (i = 0; i < alltags.length; i++) {
        if (alltags[i].className == classname)
            if (alltags[i].style.display == "none") {
            alltags[i].style.display = "block";
        } else {
            alltags[i].style.display = "none";
        }
        //customcollection[inc++]=alltags[i]; 
    }
}


/* function to change the button text */
function showhideCalories(buttonID) {

    if (document.getElementById(buttonID).innerHTML == "show") {
        document.getElementById(buttonID).innerHTML = "hide";
    } else {
        document.getElementById(buttonID).innerHTML = "show";
    }

    hideElementbyClass('titlecalper');
    hideElementbyClass('mealplancalories');
    hideElementbyClassDisplay('mealplantotalcal');
}

function printIt() {
    var a = window.open('', '', 'width=1,height=1');
    a.document.open("text/html");
    a.document.write('<html><head><title>printing bite4life</title><link rel="stylesheet" type="text/css" href="/member/app_themes/default/structural.css" /><style>div#ArticleTools{display:none;}</style></head><body>');
    a.document.write(document.getElementById('ContentContainer').innerHTML);
    a.document.write('</body></html>');
    a.document.close();
    a.print();
    a.close();
}
function GetRadWindow()
{
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow;//Will work in Moz in all cases, including clasic dialog
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz az well)

    return oWindow;
}  

function CloseOnReload()
{
    GetRadWindow().SetUrl("/member/blank.htm");
    GetRadWindow().Close();
}

function RefreshParentPage() {

    GetRadWindow().BrowserWindow;
    GetRadWindow().SetUrl("/member/blank.htm");
    GetRadWindow().Close();
}

function CallFunctionOnParentPage(fnName)
 {
    var oWindow = GetRadWindow();
   
    if (oWindow.BrowserWindow[fnName] && typeof(oWindow.BrowserWindow[fnName]) == "function")
    {
       oWindow.BrowserWindow[fnName](oWindow);
       oWindow.SetUrl("/member/blank.htm");
       oWindow.Close();
    }
    else
    {
         CloseOnReload();
    }
}

function CallPreviousWindow(previousWindowName)
{
    var oWindow = GetRadWindow();
    var dialogEvent = oWindow.GetWindowManager().GetWindowByName(previousWindowName);
    var contentWin = dialogEvent.GetContentFrame().contentWindow;

    //Make sure there is refreshMe method on page

    try {
        contentWin.RefreshMe();
        oWindow.SetUrl("/member/blank.htm");
        oWindow.Close();
    }
    catch (err) {
        CallFunctionOnParentPage('RefreshMe');
    } 
}

function CallPreviousWindowOnClose(previousWindowName) {
    var oWindow = GetRadWindow();
    var dialogEvent = oWindow.GetWindowManager().GetWindowByName(previousWindowName);
    var contentWin = dialogEvent.GetContentFrame().contentWindow;

    oWindow.SetUrl("/member/blank.htm");
    oWindow.Close();
}

function OpenDialogWindow(Url, WindowName, width, height) {

    var parentPage = GetRadWindow().BrowserWindow;
    var parentRadWindowManager = parentPage.GetRadWindowManager();
    var oDialog = parentRadWindowManager.Open(Url, WindowName);

    if (height > 0 && width > 0) {
        oDialog.MoveTo((screen.width - width) / 2, (screen.height - height) / 2); 
        oDialog.SetWidth(width);
        oDialog.SetHeight(height);
    }
}