/*
utilities.js Common functionnality for soscuisine.com
Dependencies : Prototype JavaScript framework 1.6
               Macromedia Flash Player Version Detection (1.6) (for flash functions only)
*/

var Cookies = Class.create({
    initialize: function(path, domain) {
        this.path = path || '/';
        this.domain = domain || null;
    },
    // Sets a cookie
    set: function(key, value, days) {
        if (typeof key != 'string') {
            throw "Invalid key";
        }
        if (typeof value != 'string' && typeof value != 'number') {
            throw "Invalid value";
        }
        if (days && typeof days != 'number') {
            throw "Invalid expiration time";
        }
        var setValue = key+'='+escape(new String(value));
        if (days) {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            var setExpiration = "; expires="+date.toGMTString();
        } else var setExpiration = "";
        var setPath = '; path='+escape(this.path);
        var setDomain = (this.domain) ? '; domain='+escape(this.domain) : '';
        var cookieString = setValue+setExpiration+setPath+setDomain;
        document.cookie = cookieString;
    },
    // Returns a cookie value or false
    get: function(key) {
        var keyEquals = key+"=";
        var value = false;
        document.cookie.split(';').invoke('strip').each(function(s){
            if (s.startsWith(keyEquals)) {
                value = unescape(s.substring(keyEquals.length, s.length));
                throw $break;
            }
        });
        return value;
    },
    // Clears a cookie
    clear: function(key) {
        this.set(key,'',-1);
    },
    // Clears all cookies
    clearAll: function() {
        document.cookie.split(';').collect(function(s){
            return s.split('=').first().strip();
        }).each(function(key){
            this.clear(key);
        }.bind(this));
    }
});

if (typeof Prototype == 'undefined')
    throw ("SOSCuisine Application requires the Prototype JavaScript framework");

var SOSCuisine =
{
    version: '0.1',
    prototypeVersion: parseFloat(Prototype.Version.split(".")[0] + "." + Prototype.Version.split(".")[1]),

    config: {
        urlRoot: "",
        showUserSettingsOnLoad: false,
	showMarketingOnLoad: false,
        isPrintVersion: false,
        cookieEnabled: (document.cookie.indexOf("language") != -1) ? true : false,
        languagesUrl: {}
    },

    printPreview: function printPreview(withOption)
    {
        if (withOption == true)
        {
            SOSCuisine.personalizedPrintPreferences.show();
        }
        else
        {
            window.open(document.URL + "&print_preview=1");
        }
    },

    urlInPopup:
    {
        container: null,

        initialize: function(url, options)
        {
    		if (SOSCuisine.config.cookieEnabled)
            {
    			this.container = document.getElementById("modal_dialog_content_user_settings");
                this.show();
                this.loadContent(url, options);
            }
        },

        loadContent: function(url, options)
        {
            var self = this;
        	
            self.container.style.height = "auto";
            self.container.style.backgroundImage = "";

            if (typeof options['image'] === 'undefined' || !options['image']) {
	            new Ajax.Request(url, {
	                method: "get",
	                encoding: 'iso-8859-1',
	                onSuccess: function(transport)
	                {
	            		var response = transport.responseText || '';
	            		if (response.length > 0) {
	            			response = '<div onclick="SOSCuisine.urlInPopup.hide();" style="height: 20px; text-align: center; padding-bottom: 10px;"><button>' + options['close'] + '</button></div>' + response;
	            		}
	                    self.container.innerHTML = response;
	                }.bind(this)
	            });
            }
            else {
            	var html = '<div id="mydiv" style="height: 20px; text-align: center; padding-bottom: 10px;"><button>' + options['close'] + '</button></div>';
            	html += '<img id="url_image" src="' + url + '"/>';
            	self.container.innerHTML = html;
            	
            	$("mydiv").observe("click", function () {
            		if (typeof options.onclick !== "undefined") {
            			options.onclick();
            		}
            		SOSCuisine.urlInPopup.hide();
            	});

            	Event.observe('url_image', 'load', function() {
            		if ($('url_image').getHeight() >= 600) {
            			$('url_image').height = 500;
            		}
            		self.container.style.width = ($('url_image').getWidth() + 10) + 'px';
            	});
            }
        },

        show: function()
        {
            if (window.scrollTo)
            {
                window.scrollTo(0, 0);
            }
            SOSCuisine.overlay.showOverlay();
            document.getElementById("modal_dialog_user_settings").style.visibility = "visible";
            var sidebarAds = document.getElementById("sidebar_ads");
            if (sidebarAds !== null)
            {
                sidebarAds.style.display = "none";
            }
        },

        hide: function()
        {
            document.getElementById("modal_dialog_user_settings").style.visibility = "hidden";
            var sidebarAds = document.getElementById("sidebar_ads");
            if (sidebarAds !== null)
            {
                sidebarAds.style.display = "block";
            }
            SOSCuisine.overlay.hideOverlay();
        },

        ok: function()
        {
        },

        cancel: function()
        {
            this.hide();
        }
    },
    
    /* Search box */
    searchBox:
    {
        search: function()
        {
            if (document.getElementById("search_site").checked == true)
            {
                this.googleSearch();
            }
            else
            {
                this.recipeSearch();
            }
            return true;
        },

        googleSearch: function()
        {
            var searchForm = document.getElementById('searchForm');
            searchForm.action = "http://www.google.com/custom";
            searchForm.target = 'google_window';
            document.getElementById('searchForm').method = "get";
            document.getElementById('searchInput').name = "q";
        },

        recipeSearch: function()
        {
            var searchForm = document.getElementById('searchForm');
            searchForm.action = document.getElementById('url_root').value + "recipe_browse_search.php";
            searchForm.target = '';
            document.getElementById('searchForm').method = "post";
            document.getElementById('searchInput').name = "keyword_search_string";
        }
    },

    /* Ingredient Search*/
    ingredientSearch:
    {
        validate: function(id)
        {
            this.cleanInput(document.getElementById("keyword_search_string_ingredient_1"), document.getElementById("default_keyword_search_string_ingredient_1"));
            this.cleanInput(document.getElementById("keyword_search_string_ingredient_2"), document.getElementById("default_keyword_search_string_ingredient_2"));
            this.cleanInput(document.getElementById("keyword_search_string_ingredient_3"), document.getElementById("default_keyword_search_string_ingredient_3"));
        },

        cleanInput: function(obj, defaultInput)
        {
            if (obj.value == defaultInput.value)
            {
                obj.value = "";
                return true
            }
            return false;
        }
    },

    /* TAb control for recipe page */
    tabControl:
    {
        tabs: ["RecipeContent", "NutritionInfoContent", "MyRating", "MyNotes", "Comments"],

        show: function(id)
        {
            this.switchStyle(id, "block", "selected");
        },

        hide: function(id)
        {
            this.switchStyle(id, "none", "");
        },

        switchStyle: function(_id, _display, _className)
        {
            var content = document.getElementById(_id);
            if (content != null)
            {
                var tab = document.getElementById("tab" + _id);
                if (tab != null)
                {
                    content.style.display = _display;
                    tab.className = _className;
                }
            }
        },

        changeTab: function(tab, id)
        {
            for (i = 0; i < this.tabs.length; i++)
            {
                if (this.tabs[i] == tab)
                {
                    this.show(this.tabs[i] + "_" + id);
                }
                else
                {
                    this.hide(this.tabs[i] + "_" + id);
                }
            }
        }
    },

    /*
    (April 11 2006) Microsoft 
    To create Web pages that load interactive controls that respond
    immediately to user input, use Microsoft JScript to load controls from
    external script files. You cannot write script elements inline with the
    main HTML page to load your control externally. If the script is
    written inline programmatically, for example with the writeln function,
    the loaded control will behave as if it was loaded by the HTML document
    itself and will require activation. To ensure a control is interactive
    when it is loaded, use one of the following techniques to load your
    control from an external file.    
    */

    flash:
    {
        majorVersion: 9,
        minorVersion: 0,
        requiredRevision: 0,

        write: function(url, width, height)
        {
            if (DetectFlashVer(this.majorVersion, this.minorVersion, this.requiredRevision))
            {
                document.write('<object type="application/x-shockwave-flash" data="' + SOSCuisine.common.escapeHtml(url) + '" height="' + SOSCuisine.common.escapeHtml(height) + '" width="' + SOSCuisine.common.escapeHtml(width) + '"">');
                document.write('<param name="movie" value="' + SOSCuisine.common.escapeHtml(url) + '" />');
                document.write('<param value="opaque" name="wmode"/>');
                document.write('<embed wmode="opaque" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" src="' + SOSCuisine.common.escapeHtml(url) + '" type="application/x-shockwave-flash" width="' + SOSCuisine.common.escapeHtml(width) + '" height="' + SOSCuisine.common.escapeHtml(height) + '"></embed>;');
                document.write('</object>');
            }
            else
            {
                document.write('<div class="flash_warning_container"><div class="flash_warning not_printable" style="width:' + (width - 16) + 'px; height:' + (height - 28) + 'px;">');
                document.write(SOSCuisine.config.flashWarningText);
                document.write('<p><a href="http://www.adobe.com/go/getflash/">' + SOSCuisine.config.flashDownloadText + '</a></p>');
                document.write('</div></div>');
            }
        },
        
        fixWmode: function(node)
        {
    		if (node == null)
    		{
    			node = jQuery(document);
    		}
    		jQuery(node).find('embed[wmode!="opaque"][wmode!="transparent"]').each(function(i) {
    			jQuery(this).attr("wmode", "opaque");
    		});
    		jQuery(node).find('object > param[name="wmode"][value!="opaque"][value!="transparent"]').each(function(i) {
    			var o = jQuery(this).parent();
    			jQuery(this).remove();
    			var e = document.createElement('param');
				e.setAttribute('name','wmode');
				e.setAttribute('value','opaque');
				jQuery(o).prepend(e);
				var d = jQuery(o).wrap('<div>').parent();
				var f = jQuery(o).parent().html();
				jQuery(o).remove();
				jQuery(d).html(f);
    		});
    	}	
    },

    loginBox:
    {
        clear: function(obj)
        {
            obj.value = "";
        },

        show: function(obj)
        {
            obj.style.display = "inline";
            obj.focus();
        },

        hide: function(obj)
        {
            obj.style.display = "none";
        }
    },

    ads:
    {
        hide: function()
        {
            var ads = SOSCuisine.common.getElementsByClassName("ads", "div");
            for (var i = 0; i < ads.length; i++)
            {
                var hideAds = false;
                var item = ads[i];
                var adsContainer = document.getElementById(item.id + '_ads');
                var img = adsContainer.getElementsByTagName("img")[0];

                if (adsContainer.offsetHeight < 14)
                {
                    hideAds = true;
                }

                if (img && img.src == 'http://m1.2mdn.net/viewad/817-grey.gif')
                {
                    hideAds = true;
                }

                if (hideAds == true)
                {
                    // Some browsers won't load images when his (or his container's)
                    // style attribute "display" equal "none" and we want the 
                    // images to load (at least for statistics).
                    // To achieve the same result visually while allowing
                    // the images to load, we position the images off-screen.
                    item.style.position = 'absolute';
                    item.style.left = '-9999px';
                }
            }
        }
    },

    common:
    {
        globalOnLoad: function()
        {
            SOSCuisine.ads.hide();
            SOSCuisine.flash.fixWmode();
            SOSCuisine.customElement.initialize();
            //SOSCuisine.marketing.initialize();
        },

        preloadedImages: [],
        preloadImage: function(imageUrl)
        {
            var img = new Image();
            img.src = imageUrl;
            this.preloadedImages.push(img);
        },

        imageTooltips: {
            img: null,
            container: null,
            recipeId: null,
            recipeInformationContainer: null,
            tooltipTimeout: null,
            event: null,
            cache: []
        },

        showTooltips: function(obj, contentId, contentWidth)
        {
            window.tipobj.style.backgroundImage = "";
            window.tipobj.style.height = "auto";

            document.getElementById('dhtmlpointer').src = SOSCuisine.config.urlRoot + 'scripts/ddtooltip2/arrow2.gif';
            toolTipsContent = document.getElementById(contentId).innerHTML;
            ddrivetip(toolTipsContent, contentWidth);
            SOSCuisine.common.addListener(obj, "mouseout", hideddrivetip, true);
        },

        showRecipeInformationTooltip: function(event, obj, imgPath, recipeId)
        {
            this.imageTooltips.recipeId = recipeId;
            var pointer = document.getElementById('dhtmlpointer');
            pointer.style.display = "none"
            //pointer.src = "";

            if (this.imageTooltips.container == null)
            {
                this.imageTooltips.container = new Element("div");
                this.imageTooltips.img = new Element("img");
                this.imageTooltips.img.onerror = function() {
                    this.style.visibility='hidden';
                    return true;
                }
                this.imageTooltips.recipeInformationContainer = new Element("div");

                this.imageTooltips.recipeInformationContainer.addClassName("recipeInformationTooltip");
                this.imageTooltips.recipeInformationContainer.hide();

                this.imageTooltips.container.insert(this.imageTooltips.img);
                this.imageTooltips.container.insert(this.imageTooltips.recipeInformationContainer);
                document.body.appendChild(this.imageTooltips.container);

                this.imageTooltips.container.hide();
            }

            this.imageTooltips.img.style.visibility = 'visible';
            this.imageTooltips.img.src = imgPath;

            window.tipobj.style.height = "200px";

            ddrivetip(this.imageTooltips.container.innerHTML, 600);

            window.tipobj.oldBorderWidth = window.tipobj.style.borderWidth;
            window.tipobj.oldBackgroundColor = window.tipobj.style.backgroundColor;
            window.tipobj.style.borderWidth = "0px";
            window.tipobj.style.backgroundColor = "transparent";

            this.cleanRecipeInformationTooltip();
            
            
            if (this.imageTooltips.cache[recipeId])
            {
                window.setTimeout(function()
                {
                    if (this.imageTooltips.recipeId == recipeId)
                    {
                        this.updateRecipeInformationTooltip(this.imageTooltips.cache[recipeId]);
                    }
                } .bind(this), 200)

            }
            else
            {
                // Load recipe information
                new Ajax.Request(SOSCuisine.config.urlRoot + "recipe_information_tooltip.php", {
                    method: "get",
                    encoding: 'iso-8859-1',
                    parameters: { mode: "ajax", recipe_id: recipeId },
                    onSuccess: function(transport)
                    {
                        if (this.imageTooltips.recipeId == recipeId)
                        {
                            var response = transport.responseText || "";
                            this.updateRecipeInformationTooltip(response);
                        }
                        this.imageTooltips.cache[recipeId] = response;                        
                    } .bind(this)
                });
            }
			
            Element.observe(obj, "mouseout", function()
            {
                window.tipobj.style.borderWidth = window.tipobj.oldBorderWidth;
                window.tipobj.style.backgroundColor = window.tipobj.oldBackgroundColor;
                this.setSelectVisibility("visible");
                hideddrivetip();
                Event.stopObserving(obj, "mouseout");
            } .bind(this));
        },

        updateRecipeInformationTooltip: function(content)
        {
            var recipeInformationContainers = $$('#dhtmltooltip .recipeInformationTooltip')[0];
            var recipeImg = $$('#dhtmltooltip img')[0];

            var pointer = document.getElementById('dhtmlpointer');

            document.getElementById('dhtmlpointer').style.display = ""
            document.getElementById('dhtmlpointer').src = SOSCuisine.config.urlRoot + 'scripts/ddtooltip2/arrow2.gif';

            window.tipobj.style.width = (recipeImg.offsetWidth + 340) + "px";
            window.tipobj.style.height = "auto";

            window.tipobj.style.borderWidth = window.tipobj.oldBorderWidth;
            window.tipobj.style.backgroundColor = window.tipobj.oldBackgroundColor;

            recipeInformationContainers.style.backgroundImage = "";
            recipeInformationContainers.style.height = "auto";
            recipeInformationContainers.innerHTML = content;
            recipeInformationContainers.show();
        },

        cleanRecipeInformationTooltip: function()
        {
            var recipeInformationContainers = $$('#dhtmltooltip .recipeInformationTooltip');
            if (recipeInformationContainers.length > 0)
            {
                recipeInformationContainers[0].innerHTML = "";
            }

        },

        setSelectVisibility: function(visible)
        {
            nodes = document.getElementsByTagName('select');
            for (var i = 0; i < nodes.length; i++)
            {
                nodes[i].style.visibility = visible;
            }
        },

        addListener: function(element, type, expression, bubbling)
        {
            bubbling = bubbling || false;
            if (window.addEventListener)  // standard way
            {
                element.addEventListener(type, expression, bubbling);
                return true;
            }
            else if (window.attachEvent) // IE way
            {
                element.attachEvent('on' + type, expression);
                return true;
            }
            else  // should never happen
            {
                return false;
            }
        },

        addLoadEvent: function(func)
        {
            var oldonload = window.onload;
            if (typeof window.onload != 'function')
            {
                window.onload = func;
            }
            else
            {
                window.onload = function()
                {
                    if (oldonload)
                    {
                        oldonload();
                    }
                    func();
                }
            }
        },

        /**
        * Converts HTML special characters to their entity equivalents.
        *
        * Warning: do not use prototype's escapeHTML as it is broken and doesn't escape quote (")
        *          unless they eventually fix it, then we will switch over.
        *
        *@param string s String to be escaped for HTML
        *@return string
        */
        escapeHtml: function(s)
        {
            return s.toString().replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&#34;').replace(/'/g, '&#39;');
        },

        getElementsByClassName: function(clsName, tag)
        {
            var retVal = new Array();

            if (tag == null)
            {
                tag = "*";
            }

            var elements = document.getElementsByTagName(tag);

            for (var i = 0; i < elements.length; i++)
            {
                var classes = elements[i].className.split(" ");
                for (var j = 0; j < classes.length; j++)
                {
                    if (classes[j] == clsName)
                    {
                        retVal.push(elements[i]);
                    }
                }
            }
            return retVal;
        }
    },

    customElement:
    {
        supportedCssClass: [
                                ["blink", "a", function(elm) { this.doBlink(elm) } ],
                                ["pulse", "a", function(elm) { this.doPulse(elm) } ]
                           ],

        initialize: function()
        {
            for (var i = 0; i < this.supportedCssClass.length; i++)
            {
                nodes = SOSCuisine.common.getElementsByClassName(this.supportedCssClass[i][0], this.supportedCssClass[i][1]);
                for (var j = 0; j < nodes.length; j++)
                {
                    this.supportedCssClass[i][2].call(this, nodes[j]);
                }
            }
        },

        doBlink: function(elm)
        {
            elm.originalColor = elm.style.color;
            var count = 0;
            var intervalId = window.setInterval(function()
            {
                if (elm.originalColor == elm.style.color)
                {
                    elm.style.color = '#666';
                }
                else
                {
                    elm.style.color = elm.originalColor;
                }
                if (count++ == 20)
                {
                    window.clearInterval(intervalId);
                    elm.style.color = elm.originalColor;
                }
            }, 300)
        },

        doPulse: function(elm)
        {
            new Effect.Pulsate(elm, { pulses: 3, duration: 1 });
        }
    },

    overlay: {
        showOverlay: function()
        {
            document.getElementById("overlay").style.visibility = "visible";
            //document.getElementsByTagName("body")[0].style.overflow = "hidden";
        },

        hideOverlay: function()
        {
            document.getElementById("overlay").style.visibility = "hidden";
            //document.getElementsByTagName("body")[0].style.overflow = "";
        }
    },

    personalizedPrintPreferences:
    {

        initialized: false,

        show: function()
        {
            this.setSelectVisibility('hidden');
            if (window.scrollTo)
            {
                window.scrollTo(0, 0);
            }
            SOSCuisine.overlay.showOverlay();
            document.getElementById("modal_dialog_ppp").style.visibility = "visible";
            var sidebarAds = document.getElementById("sidebar_ads");
            if (sidebarAds !== null)
            {
                sidebarAds.style.display = "none";
            }
            if (!this.initialized)
            {
                this.initCustomBehavior();
            }

        },

        hide: function()
        {
            document.getElementById("modal_dialog_ppp").style.visibility = "hidden";
            this.setSelectVisibility('visible');
            SOSCuisine.overlay.hideOverlay();
            var sidebarAds = document.getElementById("sidebar_ads");
            if (sidebarAds !== null)
            {
                sidebarAds.style.display = "block";
            }
        },

        setSelectVisibility: function(visible)
        {
            nodes = document.getElementsByTagName('select');
            for (var i = 0; i < nodes.length; i++)
            {
                nodes[i].style.visibility = visible;
            }
        },

        validateChild: function(obj)
        {
            var childContainer = document.getElementById(obj.id + "_child");
            var childValue = (obj.checked == true) ? "" : "disabled";
            if (childContainer != null)
            {
                childInputs = childContainer.getElementsByTagName("input");
                for (var i = 0; i < childInputs.length; i++)
                {
                    childInputs[i].disabled = childValue;
                }
            }
            this.updateSubmit();
        },

        updateSubmit: function()
        {
            var container = document.getElementById('modal_dialog_content_inner_ppp');
            var inputs = container.getElementsByTagName("input");
            var count = 0;
            var MandatoryCount = 0;
            for (var i = 0; i < inputs.length; i++)
            {
                if (inputs[i].type == "checkbox" && inputs[i].checked == true && inputs[i].className == "mandatory")
                {
                    count++;
                }
                if (inputs[i].className == "mandatory")
                {
                    MandatoryCount++;
                }
            }

            if (count || MandatoryCount == 0)
            {
                document.getElementById('modal_submit').disabled = "";
            }
            else
            {
                document.getElementById('modal_submit').disabled = true;
            }
        },

        post: function(printForm, url)
        {
            if (url == '')
            {
                printForm.action = document.URL + "&print_preview=1"; ;
            }
            else
            {
                if (url.indexOf('?') == -1)
                {
                    printForm.action = url + "?print_preview=1"; ;
                }
                else
                {
                    printForm.action = url + "&print_preview=1"; ;
                }
            }
            this.hide();
            printForm.submit();
        },

        initCustomBehavior: function()
        {
            for (var i in this.custom)
            {
                if (this.custom[i].initialize)
                {
                    this.custom[i].initialize();
                }
            }
        },

        custom:
       {
           recipe:
           {
               initialize: function()
               {
                   var selectedRecipes = document.getElementById('selected_recipes');
                   if (selectedRecipes)
                   {
                       var container = document.getElementById('modal_dialog_content_ppp');
                       var containerRecipe = document.getElementById('container_recipe');
                       if (!containerRecipe && selectedRecipes)
                       {
                           containerRecipe = document.createElement("div");
                           containerRecipe.id = "container_recipe";
                           container.appendChild(containerRecipe);
                           containerRecipe.innerHTML = selectedRecipes.innerHTML;
                           selectedRecipes.innerHTML = "";
                       }
                       containerRecipe.style.display = "none";
                   }
               },

               showSelectedRecipe: function()
               {
                   var containerInner = document.getElementById('modal_dialog_content_inner_ppp');
                   var containerRecipe = document.getElementById('container_recipe');
                   containerInner.style.display = "none";
                   containerRecipe.style.display = "block";
                   var selectedRecipeInput = document.getElementById('selected_recipes_menu');
                   if (selectedRecipeInput.checked == false)
                   {
                       selectedRecipeInput.click();
                   }
               },

               back: function()
               {
                   var containerRecipe = document.getElementById('container_recipe');
                   var containerInner = document.getElementById('modal_dialog_content_inner_ppp');
                   containerRecipe.style.display = "none";
                   containerInner.style.display = "block";
               },

               addRemove: function(obj, recipeId, recipeGrpId)
               {
                   recipeInput = document.getElementById("post_" + recipeId);
                   recipeGroupInput = document.getElementById("post_" + recipeGrpId);
                   if (obj.checked == true)
                   {
                       recipeInput.name = recipeInput.oldName;
                       recipeGroupInput.name = recipeGroupInput.oldName;
                   }
                   else
                   {
                       recipeInput.oldName = recipeInput.name;
                       recipeGroupInput.oldName = recipeGroupInput.name;
                       recipeInput.name = "";
                       recipeGroupInput.name = "";
                   }
               },

               toggleRecipe: function(value)
               {
                   var containerRecipe = document.getElementById('container_recipe');
                   nodes = containerRecipe.getElementsByTagName('input');
                   for (var i = 0; i < nodes.length; i++)
                   {
                       if (nodes[i].type == "checkbox")
                       {
                           if (nodes[i].checked != value)
                           {
                               nodes[i].checked = !value;
                               nodes[i].click();
                           }
                       }
                   }
               }
           }
       }
    },

    warning: {

        addWarning: function(errorMsg)
        {
            if (!SOSCuisine.config.isPrintVersion)
            {
                var warningContainer = $('warning_container');
                warningContainer.innerHTML += errorMsg + "<br />";
                warningContainer.style.display = "block";
            }
        },

        clearAllWarning: function()
        {
            var warningContainer = $('warning_container');
            warningContainer.innerHTML = "";
            warningContainer.style.display = "none";
        }
    },

    userSetting: {

        container: null,

        initialize: function()
        {
            if (SOSCuisine.config.showUserSettingsOnLoad)
            {
                if (SOSCuisine.config.cookieEnabled)
                {
                    this.container = document.getElementById("modal_dialog_content_user_settings");
                    //this.setSelectVisibility("hidden");
                    this.show();
                    this.loadContent();
                }
                else
                {
                    SOSCuisine.warning.addWarning($('warning_no_cookie').innerHTML);
                }
            }
        },

        loadContent: function()
        {
            this.container.style.backgroundImage = "url(" + SOSCuisine.config.urlRoot + "media/images/ajax-loader.gif)";
            this.container.style.height = "200px";
            new Ajax.Request(SOSCuisine.config.urlRoot + "user_settings.php", {
                method: "get",
                encoding: 'iso-8859-1',
                parameters: { mode: "ajax" },
                onSuccess: function(transport)
                {
                    this.container.style.height = "auto";
                    this.container.style.backgroundImage = "";
                    var response = transport.responseText || "";
                    this.container.innerHTML = response;
                } .bind(this)
            });
        },

        setSelectVisibility: function(visible)
        {
            nodes = document.getElementsByTagName('select');
            for (var i = 0; i < nodes.length; i++)
            {
                nodes[i].style.visibility = visible;
            }
        },

        show: function()
        {
            if (window.scrollTo)
            {
                window.scrollTo(0, 0);
            }
            SOSCuisine.overlay.showOverlay();
            document.getElementById("modal_dialog_user_settings").style.visibility = "visible";
            var sidebarAds = document.getElementById("sidebar_ads");
            if (sidebarAds !== null)
            {
                sidebarAds.style.display = "none";
            }
        },

        hide: function()
        {
            document.getElementById("modal_dialog_user_settings").style.visibility = "hidden";
            var sidebarAds = document.getElementById("sidebar_ads");
            if (sidebarAds !== null)
            {
                sidebarAds.style.display = "block";
            }
            SOSCuisine.overlay.hideOverlay();
        },

        switchLanguage: function()
        {
            var containerFrench = $('container_region_french');
            var containerEnglish = $('container_region_english');
            if (containerFrench.style.display == "none")
            {
                containerEnglish.style.display = "none";
                containerFrench.style.display = "block";
            }
            else
            {
                containerEnglish.style.display = "block";
                containerFrench.style.display = "none";
            }
        },

        switchRegion: function(region)
        {
            var formUserSettings = $("formUserSettings");
            var url = location.href;
            var lang = $('language').value;
            if (typeof SOSCuisine.config.languagesUrl[lang] != "undefined")
            {
                url = SOSCuisine.config.languagesUrl[lang];
            }
            formUserSettings.action = url;
            $("region").value = region;

            formUserSettings.submit();
        }
    },

    /*
    marketing:
    {
        container: null,

        initialize: function()
        {
            if (SOSCuisine.config.showMarketingOnLoad)
            {
                if (SOSCuisine.config.cookieEnabled)
                {
                    this.container = document.getElementById("modal_dialog_content_user_settings");
                    this.show();
                    this.loadContent();
                }
                else
                {
                    SOSCuisine.warning.addWarning($('warning_no_cookie').innerHTML);
                }
            }
        },

        loadContent: function()
        {
            this.container.style.backgroundImage = "url(" + SOSCuisine.config.urlRoot + "media/images/ajax-loader.gif)";
            this.container.style.height = "200px";
            new Ajax.Request(SOSCuisine.config.urlRoot + "marketing.php", {
                method: "get",
                encoding: 'utf-8',
                onSuccess: function(transport)
                {
                    this.container.style.height = "auto";
                    this.container.style.backgroundImage = "";
                    var response = transport.responseText || "";
                    this.container.innerHTML = response;
                }.bind(this)
            });
        },

        setSelectVisibility: function(visible)
        {
            nodes = document.getElementsByTagName('select');
            for (var i = 0; i < nodes.length; i++)
            {
                nodes[i].style.visibility = visible;
            }
        },

        show: function()
        {
            if (window.scrollTo)
            {
                window.scrollTo(0, 0);
            }
            SOSCuisine.overlay.showOverlay();
            document.getElementById("modal_dialog_user_settings").style.visibility = "visible";
            var sidebarAds = document.getElementById("sidebar_ads");
            if (sidebarAds !== null)
            {
                sidebarAds.style.display = "none";
            }
        },

        hide: function()
        {
            document.getElementById("modal_dialog_user_settings").style.visibility = "hidden";
            var sidebarAds = document.getElementById("sidebar_ads");
            if (sidebarAds !== null)
            {
                sidebarAds.style.display = "block";
            }
            SOSCuisine.overlay.hideOverlay();
        },

        ok: function()
        {
            var cookies = new Cookies();
            cookies.set('marketing', 'yes');
            var formMarketing = $("formMarketing");
            formMarketing.action = '/membre_inscription.php';
            formMarketing.submit();
        },

        cancel: function()
        {
            var cookies = new Cookies();
            cookies.set('marketing', 'no');
            this.hide();
        }
    },
    */

    meal_plan_category_family_selector:
    {
        container: null,

        initialize: function(configuration)
        {
            this.configuration = configuration;
            this.loadContent();
        },

        loadContent: function()
        {
            var that = this,
                config = that.configuration,
                childrenData = config.data[config.id],
                language = config.language,
		imageLink = '/meal_plan_directory.php?meal_plan_category_code={code}',
                link = 
                '[<a href="/meal_plan_directory.php?meal_plan_category_code={code}" title="{details}">{details}</a>' +
                ' | '+ 
                '<a href="/meal_plan_menus.php?meal_plan_category_code={code}" title="{menu_of_the_week}">{menu_of_the_week}</a>{link2}',
                table_markup;

            if (childrenData[0].parent_code === 'DIABETES' && !childrenData[0].is_subscribed) {
            	imageLink = (language === 'fr_CA' ? '/diabete/menus_intelligents' : '/diabetes/meal_plans'),
                link = '[<a href="' + (language === 'fr_CA' ? '/diabete/menus_intelligents' : '/diabetes/meal_plans') + '" title="{details}">{details}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/diabete/menus_intelligents/exemple' : '/diabetes/meal_plans/sample') + '" title="{example_of_menu}">{example_of_menu}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/diabete/menus_intelligents/abonnez_vous' : '/diabetes/meal_plans/subscribe') + '" title="{subscribe}">{subscribe}</a>]';
            }
            if (childrenData[0].parent_code === 'WEIGHT_LOSS' && !childrenData[0].is_subscribed) {
            	imageLink = (language === 'fr_CA' ? '/maigrir/menus_intelligents' : '/weight_loss/meal_plans'),
                link = '[<a href="' + (language === 'fr_CA' ? '/maigrir/menus_intelligents' : '/weight_loss/meal_plans') + '" title="{details}">{details}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/maigrir/menus_intelligents/exemple' : '/weight_loss/meal_plans/sample') + '" title="{example_of_menu}">{example_of_menu}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/maigrir/menus_intelligents/abonnez_vous' : '/weight_loss/meal_plans/subscribe') + '" title="{subscribe}">{subscribe}</a>]';
            }
            if (childrenData[0].parent_code === 'GERD' && !childrenData[0].is_subscribed) {
            	imageLink = (language === 'fr_CA' ? '/reflux_gastrique/menus_intelligents' : '/gastric_reflux/meal_plans'),
                link = '[<a href="' + (language === 'fr_CA' ? '/reflux_gastrique/menus_intelligents' : '/gastric_reflux/meal_plans') + '" title="{details}">{details}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/reflux_gastrique/menus_intelligents/exemple' : '/gastric_reflux/meal_plans/sample') + '" title="{example_of_menu}">{example_of_menu}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/reflux_gastrique/menus_intelligents/abonnez_vous' : '/gastric_reflux/meal_plans/subscribe') + '" title="{subscribe}">{subscribe}</a>]';
            }
            if (childrenData[0].parent_code === 'HYPOGLYCEMIA' && !childrenData[0].is_subscribed) {
            	imageLink = (language === 'fr_CA' ? '/hypoglycemie/menus_intelligents' : '/hypoglycemia/meal_plans'),
                link = '[<a href="' + (language === 'fr_CA' ? '/hypoglycemie/menus_intelligents' : '/hypoglycemia/meal_plans') + '" title="{details}">{details}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/hypoglycemie/menus_intelligents/exemple' : '/hypoglycemia/meal_plans/sample') + '" title="{example_of_menu}">{example_of_menu}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/hypoglycemie/menus_intelligents/abonnez_vous' : '/hypoglycemia/meal_plans/subscribe') + '" title="{subscribe}">{subscribe}</a>]';
            }
            if (childrenData[0].parent_code === 'BONE_HEALTHY' && !childrenData[0].is_subscribed) {
            	imageLink = (language === 'fr_CA' ? '/os_en_sante/menus_intelligents' : '/bone_healthy/meal_plans'),
                link = '[<a href="' + (language === 'fr_CA' ? '/os_en_sante/menus_intelligents' : '/bone_healthy/meal_plans') + '" title="{details}">{details}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/os_en_sante/menus_intelligents/exemple' : '/bone_healthy/meal_plans/sample') +'" title="{example_of_menu}">{example_of_menu}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/os_en_sante/menus_intelligents/abonnez_vous' : '/bone_healthy/meal_plans/subscribe') + '" title="{subscribe}">{subscribe}</a>]';
            }
            if (childrenData[0].parent_code === 'HEART_HEALTHY' && !childrenData[0].is_subscribed) {
            	imageLink = (language === 'fr_CA' ? '/coeur_en_sante/menus_intelligents' : '/heart_healthy/meal_plans'),
                link = '[<a href="' + (language === 'fr_CA' ? '/coeur_en_sante/menus_intelligents' : '/heart_healthy/meal_plans') + '" title="{details}">{details}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/coeur_en_sante/menus_intelligents/exemple' : '/heart_healthy/meal_plans/sample') +'" title="{example_of_menu}">{example_of_menu}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/coeur_en_sante/menus_intelligents/abonnez_vous' : '/heart_healthy/meal_plans/subscribe') + '" title="{subscribe}">{subscribe}</a>]';
            }
			if (childrenData[0].parent_code === 'PREGNANCY' && !childrenData[0].is_subscribed) {
            	imageLink = (language === 'fr_CA' ? '/grossesse/menus_intelligents' : '/pregnancy/meal_plans'),
                link = '[<a href="' + (language === 'fr_CA' ? '/grossesse/menus_intelligents' : '/pregnancy/meal_plans') + '" title="{details}">{details}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/grossesse/menus_intelligents/exemple' : '/pregnancy/meal_plans/sample') +'" title="{example_of_menu}">{example_of_menu}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/grossesse/menus_intelligents/abonnez_vous' : '/pregnancy/meal_plans/subscribe') + '" title="{subscribe}">{subscribe}</a>]';
            }
			if (childrenData[0].parent_code === 'MENOPAUSE' && !childrenData[0].is_subscribed) {
            	imageLink = (language === 'fr_CA' ? '/fr/menopause/menus-intelligents' : '/en/menopause/meal-plans'),
                link = '[<a href="' + (language === 'fr_CA' ? '/fr/menopause/menus-intelligents' : '/en/menopause/meal-plans') + '" title="{details}">{details}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/menopause/menus-intelligents/exemple' : '/en/menopause/meal-plans/sample') +'" title="{example_of_menu}">{example_of_menu}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/menopause/menus-intelligents/abonnez-vous' : '/en/menopause/meal-plans/subscribe') + '" title="{subscribe}">{subscribe}</a>]';
            }
			if (childrenData[0].parent_code === 'BREASTFEEDING' && !childrenData[0].is_subscribed) {
            	imageLink = (language === 'fr_CA' ? '/fr/allaitement/menus-intelligents' : '/en/breastfeeding/meal-plans'),
                link = '[<a href="' + (language === 'fr_CA' ? '/fr/allaitement/menus-intelligents' : '/en/breastfeeding/meal-plans') + '" title="{details}">{details}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/allaitement/menus-intelligents/exemple' : '/en/breastfeeding/meal-plans/sample') +'" title="{example_of_menu}">{example_of_menu}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/allaitement/menus-intelligents/abonnez-vous' : '/en/breastfeeding/meal-plans/subscribe') + '" title="{subscribe}">{subscribe}</a>]';
            }
			if (childrenData[0].parent_code === 'DIVERTICULITIS' && !childrenData[0].is_subscribed) {
            	imageLink = (language === 'fr_CA' ? '/fr/diverticulite/menus-intelligents' : '/en/diverticulitis/meal-plans'),
                link = '[<a href="' + (language === 'fr_CA' ? '/fr/diverticulite/menus-intelligents' : '/en/diverticulitis/meal-plans') + '" title="{details}">{details}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/diverticulite/menus-intelligents/exemple' : '/en/diverticulitis/meal-plans/sample') +'" title="{example_of_menu}">{example_of_menu}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/diverticulite/menus-intelligents/abonnez-vous' : '/en/diverticulitis/meal-plans/subscribe') + '" title="{subscribe}">{subscribe}</a>]';
            }
			if (childrenData[0].parent_code === 'DIVERTICULOSIS' && !childrenData[0].is_subscribed) {
            	imageLink = (language === 'fr_CA' ? '/fr/diverticulose/menus-intelligents' : '/en/diverticulosis/meal-plans'),
                link = '[<a href="' + (language === 'fr_CA' ? '/fr/diverticulose/menus-intelligents' : '/en/diverticulosis/meal-plans') + '" title="{details}">{details}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/diverticulose/menus-intelligents/exemple' : '/en/diverticulosis/meal-plans/sample') +'" title="{example_of_menu}">{example_of_menu}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/diverticulose/menus-intelligents/abonnez-vous' : '/en/diverticulosis/meal-plans/subscribe') + '" title="{subscribe}">{subscribe}</a>]';
            }
			if (childrenData[0].parent_code === 'PREMENSTRUAL_SYNDROME' && !childrenData[0].is_subscribed) {
            	imageLink = (language === 'fr_CA' ? '/fr/syndrome-premenstruel/menus-intelligents' : '/en/premenstrual-syndrome/meal-plans'),
                link = '[<a href="' + (language === 'fr_CA' ? '/fr/syndrome-premenstruel/menus-intelligents' : '/en/premenstrual-syndrome/meal-plans') + '" title="{details}">{details}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/syndrome-premenstruel/menus-intelligents/exemple' : '/en/premenstrual-syndrome/meal-plans/sample') +'" title="{example_of_menu}">{example_of_menu}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/syndrome-premenstruel/menus-intelligents/abonnez-vous' : '/en/premenstrual-syndrome/meal-plans/subscribe') + '" title="{subscribe}">{subscribe}</a>]';
            }
			if (childrenData[0].parent_code === 'ANEMIA' && !childrenData[0].is_subscribed) {
            	imageLink = (language === 'fr_CA' ? '/fr/anemie/menus-intelligents' : '/en/anemia/meal-plans'),
                link = '[<a href="' + (language === 'fr_CA' ? '/fr/anemie/menus-intelligents' : '/en/anemia/meal-plans') + '" title="{details}">{details}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/anemie/menus-intelligents/exemple' : '/en/anemia/meal-plans/sample') +'" title="{example_of_menu}">{example_of_menu}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/anemie/menus-intelligents/abonnez-vous' : '/en/anemia/meal-plans/subscribe') + '" title="{subscribe}">{subscribe}</a>]';
            }
			if (childrenData[0].parent_code === 'HEALTHY_VEGETARIAN' && !childrenData[0].is_subscribed) {
            	imageLink = (language === 'fr_CA' ? '/fr/vegetarien-en-sante/menus-intelligents' : '/en/healthy-vegetarian/meal-plans'),
                link = '[<a href="' + (language === 'fr_CA' ? '/fr/vegetarien-en-sante/menus-intelligents' : '/en/healthy-vegetarian/meal-plans') + '" title="{details}">{details}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/vegetarien-en-sante/menus-intelligents/exemple' : '/en/healthy-vegetarian/meal-plans/sample') +'" title="{example_of_menu}">{example_of_menu}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/vegetarien-en-sante/menus-intelligents/abonnez-vous' : '/en/healthy-vegetarian/meal-plans/subscribe') + '" title="{subscribe}">{subscribe}</a>]';
            }
			if (childrenData[0].parent_code === 'RHEUMATOID_ARTHRITIS' && !childrenData[0].is_subscribed) {
            	imageLink = (language === 'fr_CA' ? '/fr/arthrite-rhumatoide/menus-intelligents' : '/en/rheumatoid-arthritis/meal-plans'),
                link = '[<a href="' + (language === 'fr_CA' ? '/fr/arthrite-rhumatoide/menus-intelligents' : '/en/rheumatoid-arthritis/meal-plans') + '" title="{details}">{details}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/arthrite-rhumatoide/menus-intelligents/exemple' : '/en/rheumatoid-arthritis/meal-plans/sample') +'" title="{example_of_menu}">{example_of_menu}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/arthrite-rhumatoide/menus-intelligents/abonnez-vous' : '/en/rheumatoid-arthritis/meal-plans/subscribe') + '" title="{subscribe}">{subscribe}</a>]';
            }
			if (childrenData[0].parent_code === 'WEIGHT_GAIN' && !childrenData[0].is_subscribed) {
            	imageLink = (language === 'fr_CA' ? '/fr/prise-de-poids/menus-intelligents' : '/en/weight-gain/meal-plans'),
                link = '[<a href="' + (language === 'fr_CA' ? '/fr/prise-de-poids/menus-intelligents' : '/en/weight-gain/meal-plans') + '" title="{details}">{details}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/prise-de-poids/menus-intelligents/exemple' : '/en/weight-gain/meal-plans/sample') +'" title="{example_of_menu}">{example_of_menu}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/prise-de-poids/menus-intelligents/abonnez-vous' : '/en/weight-gain/meal-plans/subscribe') + '" title="{subscribe}">{subscribe}</a>]';
            }
			if (childrenData[0].parent_code === 'IMPAIRED_GLUCOSE_TOLERANCE' && !childrenData[0].is_subscribed) {
            	imageLink = (language === 'fr_CA' ? '/fr/intolerance-au-glucose/menus-intelligents' : '/en/impaired-glucose-tolerance/meal-plans'),
                link = '[<a href="' + (language === 'fr_CA' ? '/fr/intolerance-au-glucose/menus-intelligents' : '/en/impaired-glucose-tolerance/meal-plans') + '" title="{details}">{details}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/intolerance-au-glucose/menus-intelligents/exemple' : '/en/impaired-glucose-tolerance/meal-plans/sample') +'" title="{example_of_menu}">{example_of_menu}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/intolerance-au-glucose/menus-intelligents/abonnez-vous' : '/en/impaired-glucose-tolerance/meal-plans/subscribe') + '" title="{subscribe}">{subscribe}</a>]';
            }
			if (childrenData[0].parent_code === 'IRRITABLE_BOWEL_SYNDROME' && !childrenData[0].is_subscribed) {
            	imageLink = (language === 'fr_CA' ? '/fr/syndrome-intestin-irritable/menus-intelligents' : '/en/irritable-bowel-syndrome/meal-plans'),
                link = '[<a href="' + (language === 'fr_CA' ? '/fr/syndrome-intestin-irritable/menus-intelligents' : '/en/irritable-bowel-syndrome/meal-plans') + '" title="{details}">{details}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/syndrome-intestin-irritable/menus-intelligents/exemple' : '/en/irritable-bowel-syndrome/meal-plans/sample') +'" title="{example_of_menu}">{example_of_menu}</a>' +
                           ' | ' +
                           '<a href="' + (language === 'fr_CA' ? '/fr/syndrome-intestin-irritable/menus-intelligents/abonnez-vous' : '/en/irritable-bowel-syndrome/meal-plans/subscribe') + '" title="{subscribe}">{subscribe}</a>]';
            }
			
            table_markup =
                '<table>' +
                '  <tbody>' +
                '    <tr>' +
                '      <td class="meal_plan_directory_item_image" style="width: 70px">' +
                '        <a href="' + imageLink + '" title="{name}">' +
                '          <img src="{imagename}" alt="{name}" title="{name}">' +
                '        </a>' +
                '      </td>' +
                '      <td class="meal_plan_directory_item_description" style="width: 298px; text-align: left;">' +
                '        <strong>{name}</strong>' +
                '        <br>' +
                '        {free}' +
                '        {short_description}' +
                '        <br>' +
                link +
                '      </td>' +
                '    </tr>' +
                '  </tbody>' +
                '  </table>';

            YUI().use('node', 'substitute', 'oop', function(Y) {
                that.container = Y.one('#modal_dialog_content_user_settings');
                that.container.get('children').remove();
                that.container.setContent('');

                var currentChild,
                    i,
                    ulNode = Y.Node.create('<ul></ul>'),
                    closeButton;

                that.container.setStyle('width', '400px');
                that.container.append('<h2 class="not_printable">' + childrenData[0].parent_name + '</h2>');
                that.container.append(ulNode);

                for (i = 0; i < childrenData.length; ++i) {
                    currentChild = childrenData[i]; 
                    if (currentChild.is_public) {
                        ulNode.append('<li style="padding-bottom: 15px">' +
                            Y.substitute(
                                table_markup,{
                                    name: currentChild.name,
                                    parent_name: currentChild.parent_name,
                                    parent_code: currentChild.parent_code,
                                    code: currentChild.code,
                                    imagename: currentChild.image,
                                    free: (currentChild.free) ? '' : '[<span style="cursor: pointer; color: blue;" title="' + config.data.premium_tooltip + '">' + config.data.premium + '</span>]<br>',
                                    short_description: currentChild.short_description,
                                    details: currentChild.details,
                                    menu_of_the_week: currentChild.menu_of_the_week,
                                    subscribe: currentChild.subscribe,
                                    example_of_menu: currentChild.example_of_menu,
                                    link2: (currentChild.id == currentChild.subscribed_meal_plan_id) ? ']' : ' | <a href="/meal_plan_directory.php?meal_plan_category_code=' + currentChild.code + '&amp;force_login=1&amp;subscribe_to=' + currentChild.code + '" title="' + currentChild.follow + '" onclick="SOSCuisine.windowMealPlanCategorySubscribe.show(\'' + currentChild.code + '\');return false;">' + currentChild.follow + '</a>]'
                                }
                            ) + '</li>'
                        );
                    }
                }
                closeButton = Y.Node.create('<input value="' + config.data.close_button + '" type="button" />');
                closeButton.on('click', Y.bind(that.cancel, that));
                that.container.append(Y.Node.create('<div style="text-align: right; width: 100%;"></div>').append(closeButton));

            });
            this.show();
        },

        show: function()
        {
            if (window.scrollTo)
            {
                window.scrollTo(0, 0);
            }
            SOSCuisine.overlay.showOverlay();
            document.getElementById("modal_dialog_user_settings").style.visibility = "visible";
            var sidebarAds = document.getElementById("sidebar_ads");
            if (sidebarAds !== null)
            {
                sidebarAds.style.display = "none";
            }
        },

        hide: function()
        {
            document.getElementById("modal_dialog_user_settings").style.visibility = "hidden";
            var sidebarAds = document.getElementById("sidebar_ads");
            if (sidebarAds !== null)
            {
                sidebarAds.style.display = "block";
            }
            SOSCuisine.overlay.hideOverlay();
        },

        ok: function()
        {
            this.hide();
        },

        cancel: function()
        {
            this.hide();
            this.container.get('children').remove();
            this.container.setContent('');
        }
    },


    advanceSearchForm:
    {
        inputOnBlur: function(obj)
        {
            if (obj.value == "")
            {
                Element.removeClassName(obj, "selected");
            }
            else
            {
                Element.addClassName(obj, "selected");
            }
        },

        checkboxOnClick: function(obj)
        {
            var elem = Element.next(obj);
            if (obj.checked == true)
            {
                Element.addClassName(elem, "selected");
            }
            else
            {
                Element.removeClassName(elem, "selected");
            }
        },

        selectOnClick: function(obj)
        {
            if (obj.selectedIndex == 0)
            {
                Element.removeClassName(obj, "selected");
            }
            else
            {
                Element.addClassName(obj, "selected");
            }
        }
    }
};

SOSCuisine.common.addLoadEvent(SOSCuisine.common.globalOnLoad);

