﻿/* COVREFLOW: */
	
	function selectItem( id ){
		//document.title = 'CoverFlow Action: Item "' + id + '" Selected, activeDetail:"'+((typeof(activeDetail)=='undefined')?'-':activeDetail)+'", activeProductID:"'+((typeof(activeProductID)=='undefined')?'-':activeProductID)+'"';
		
		if( typeof(LoadRecipeDetails_V2)=="function" ){
			
			//activeDetail = '';
			//LoadRecipeGrid_V2();
			
		    window.location.href = '#RecipeId_' + id;
            $('#RECIPE_GRID tr.selected').removeClass('selected');
            $('#RecipeId_'+id).parent().parent().addClass('selected');
			
			if( FlashActionRunning ){
			    FlashActionRunning = false;
			}else{
    			
			    if( typeof(activeDetail)!='undefined' && activeDetail!='' ){
			        activeDetail = id;
			        ReLoadRecipeDetails( id );
			    }
    			
			}
		    
	        if( typeof(activeProductID)!='undefined' && activeProductID!='' ){
	            activeProductID = '';
	            CloseExternProductDetails();
	        }
			
		}else if( typeof(LoadProductDetails_V2)=="function" ){
			
			/* workaround for numerical id's:
			var text = $('#PRODUCT_GRID .PRODUCT_GRID_HEADER_ROW').slice(id-1,id).find('a').attr('id');
			window.location.href = '#' + text;
			*/
            
			if( activeProductID!='' ){
			    if( $('#box_main_produkt').length>0 ){
                    $('#box_right_produkt, #box_left_produkt_back').fadeOut('fast', function(){
                        $('#box_main_produkt').fadeOut('normal',function(){
                            $('#content_wrapper3').removeClass('content_wrapper3detail').addClass('content_wrapper3normal');
                            //$('#content_wrapper3').css({ top:'300px' });
                            $('#box_main_produkte').css({ top:'0px' });
                            $('#CoverFlowObject').css({ height:'200px', width:'500px' });
                            //$('#breadcrumb_container').hide();
                            
                            $('#box_main_produkte').animate(
                                { marginLeft:'213px' },
                                'normal',
                                '',
                                function(){
                                    window.location.href = '#Product__RangeID_' + id;
                                    activeProductID = '';
                                    $('#box_main_produkte').unblock();
                                    $('#box_left_produkte').fadeIn('normal', function(){
                                        $('#FWLAjaxSourceContainer1').hide().remove();
                                        document.getElementById('content_wrapper3').scrollTop = 0;
                                    });
                                }
                            );
                        });
                    });
                }else{
			        window.location.href = '#Product__RangeID_' + id;
                    document.getElementById('content_wrapper3').scrollTop = 0;
			    }
			}else{
    	        window.location.href = '#Product__RangeID_' + id;
                document.getElementById('content_wrapper3').scrollTop = 0;
			}
		}
		
		document.title = tDocTitle;
		
	}

	function releaseItem( id ){
		//document.title = 'CoverFlow Action: Item "' + id + '" Clicked, activeDetail:"'+((typeof(activeDetail)=='undefined')?'-':activeDetail)+'", activeProductID:"'+((typeof(activeProductID)=='undefined')?'-':activeProductID+'"');
		
		if( typeof(LoadRecipeDetails_V2)=="function" ){
			
			if( typeof(activeDetail)!='undefined' && activeDetail!='' ){
			    activeDetail = id;
			    ReLoadRecipeDetails( id );
			}else{
			    if( typeof(activeProductID)!='undefined' && activeProductID!='' ){
			        CloseExternProductDetails();
			    }else{
			        activeDetail = id;
			        LoadRecipeDetails_V2(id, $('a[id=RecipeId_'+id+']').html() );
			    }
			}
			
		}else if( typeof(LoadProductDetails_V2)=="function" ){
			
			// the flash callback returns only a rangeid number, not a productid
			//LoadProductDetails_V2(id, $('a[id=ProductId_'+id+']').html() );
			
		}
	}
	
/* :COVREFLOW */


/* QUERYSTRING: */
	
	/*
		// Parse the current page's querystring
		var qs = new Querystring()
		
		// Parse a given querystring
		var qs2 = new Querystring("name1=value1&name2=value2")
		
		var v1 = qs2.get("name1")
		var v3 = qs2.get("name3", "default value")
	*/
	
	function Querystring(qs) { // optionally pass a querystring to parse
		this.params = new Object()
		this.get=Querystring_get
		
		if (qs == null)
			qs=location.search.substring(1,location.search.length)
	
		if (qs.length == 0) return
		
		if (qs.indexOf('?')>=0) {
			qs = qs.substr( qs.indexOf('?')+1 );
		}
	
	// Turn <plus> back to <space>
	// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
		qs = qs.replace(/\+/g, ' ')
		var args = qs.split('&') // parse out name/value pairs separated via &
		
	// split out each name=value pair
		for (var i=0;i<args.length;i++) {
			var value;
			var pair = args[i].split('=')
			var name = unescape(pair[0])
	
			if (pair.length == 2)
				value = unescape(pair[1])
			else
				value = name
			
			this.params[name] = value
		}
	}
	
	function Querystring_get(key, default_) {
		// This silly looking line changes UNDEFINED to NULL
		if (default_ == null) default_ = null;
		
		var value=this.params[key]
		if (value==null) value=default_;
		
		return value
	}
	
/* QUERYSTRING: */

/* FLAPS: */
	
	function initFLAPS(){
        
		/* REMOVE EMPTY FLAPS: */
		$('.FLAP_MAIN_TABLE tr.mid > td > a > div:empty').parent().parent().parent().remove();
		
		$('.FlapContent').hide();
		
		/* REORDER LAST FLAP: */
		$('.FLAP_MAIN_TABLE tr.last').children('td:nth-child(2)').html(
			$('.FLAP_MAIN_TABLE tr.last').prev().children('td:nth-child(2)').html()
		);
		$('.FLAP_MAIN_TABLE tr.last').prev().remove();
		
		/* ADD EVENTS TO FLAPS: */
		$('.FLAP_MAIN_TABLE tr.first > td > a').eq(0).
		    next().show().
		    prev().parent().prev().children('img').attr('src', '/Images/flap_top-left_h.jpg'); // Open first. (Attention on toggle..)
		$('.FLAP_MAIN_TABLE tr.first > td > a').toggle(
			function () {
				$(this).next().hide();
				$(this).parent().prev().children('img').attr('src', '/Images/flap_top-left_n.jpg');
			},
			function () {
		        dcsMultiTrack('WT.z_cg4', $(this).text());
				$(this).next().show();
				$(this).parent().prev().children('img').attr('src', '/Images/flap_top-left_h.jpg');
			}
		);
		$('.FLAP_MAIN_TABLE tr.mid > td > a').toggle(
			function () {
		        dcsMultiTrack('WT.z_cg4', $(this).text());
				$(this).next().show();
				$(this).parent().prev().children('img').attr('src', '/Images/flap_mid-left_h.jpg');
			},
			function () {
				$(this).next().hide();
				$(this).parent().prev().children('img').attr('src', '/Images/flap_mid-left_n.jpg');
			}
		);
		$('.FLAP_MAIN_TABLE tr.last > td > a').toggle(
			function () {
		        dcsMultiTrack('WT.z_cg4', $(this).text());
				$(this).next().show();
				$(this).parent().css('background', 'url(/Images/flap_mid-mid_n.jpg) left top repeat-x');
				$(this).parent().parent().next().show();
				$(this).parent().prev().children('img').attr('src', '/Images/flap_mid-left_h.jpg');
				$(this).parent().next().children('img').attr('src', '/Images/flap_mid-right_n.jpg');
			},
			function () {
				$(this).next().hide();
				$(this).parent().css('background', 'url(/Images/flap_bottom-mid_n.jpg) left top repeat-x');
				$(this).parent().parent().next().hide();
				$(this).parent().prev().children('img').attr('src', '/Images/flap_bottom-left_n.jpg');
				$(this).parent().next().children('img').attr('src', '/Images/flap_bottom-right_n.jpg');
			}
		);
	}
	
/* :FLAPS */

/* RECIPEGRID: */
    
    function initRecipeGrid(){
        $("#ctl00_mainCopy_RECIPE_GRID").attr({id:'RECIPE_GRID'});
        
        $("#RECIPE_GRID tr:odd").css('backgroundColor', '#E9F4C9');
        $("#RECIPE_GRID tr").addClass('RECIPE_GRID_RECIPE_ROW');
        $("#RECIPE_GRID th[scope]").parent().removeClass('RECIPE_GRID_RECIPE_ROW').addClass('RECIPE_GRID_HEADER_ROW');
        
        $("#RECIPE_GRID tr.RECIPE_GRID_RECIPE_ROW").hover(
            function () {
                lastHoverColor = $(this).css('backgroundColor');
                //$(this).css('backgroundColor', '#BBDD54');
                $(this).addClass('hover');
            },
            function () {
                //$(this).css('backgroundColor', lastHoverColor);
                $(this).removeClass('hover');
            }
        );
        $('.RatingIMG').ifixpng().css({height:'16px', width:'60px'});
    }
    
/* :RECIPEGRID */

/* SHADOWS: */
	/*
	jQuery.fn.shadow = function() {
		return this.each(function(){
			$(this).wrap('<div class="shadow_wrap1">')
				   .wrap('<div class="shadow_wrap2">')
				   .wrap('<div class="shadow_wrap3">');
			
			var wrap1 = document.createElement("div");
			wrap1.setAttribute("class", "shadow_wrap1");
			var wrap2 = document.createElement("div");
			wrap2.setAttribute("class", "wrap2");
			var wrap3 = document.createElement("div");
			wrap3.setAttribute("class", "wrap3");
			
			var outerNode = element.parentNode;
			outerNode.insertBefore(wrap1, element);
			wrap1.appendChild(wrap2);
			wrap2.appendChild(wrap3);
			outerNode.removeChild(element);
			wrap3.appendChild(element);   
		});
	};
	*/
/* :SHADOWS */

/* FLASHHANDLER: */
    
	function getFlashMovie(movieName) {
		//var isIE = navigator.appName.indexOf("Microsoft") != -1;
	    //return (isIE) ? window[movieName] : document[movieName];
        if( $.browser.msie ){
		    return window[movieName];
		}else{
		    return document[movieName];
		}
	}
	
/* :FLASHHANDLER */

/* ESCAPING: */
    
    function addslashes(str) {
        str=str.replace(/\'/g,'\\\'');
        str=str.replace(/\"/g,'\\"');
        str=str.replace(/\\/g,'\\\\');
        str=str.replace(/\0/g,'\\0');
        return str;
    }
    function stripslashes(str) {
        str=str.replace(/\\'/g,'\'');
        str=str.replace(/\\"/g,'"');
        str=str.replace(/\\\\/g,'\\');
        str=str.replace(/\\0/g,'\0');
        return str;
    }
    
/* :ESCAPING */

/* URLDENCODE: */

var Utf8 = {

    // public method for url encoding
    encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // public method for url decoding
    decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

var Url = {

    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

/* :URLDENCODE */

/* NOTUSEDYET: */
    
    function getRandInt( max ) {
        return Math.round( max * Math.random() );
    }
    
/* :NOTUSEDYET */

/* BLOCK_UI: */    
    
    function BlockUI_RecipeOverview(){
        $('#box_main_rezepte_content').block();
        $.extend( $.blockUI.defaults.overlayCSS, { backgroundColor:'#e6f2bf', opacity:'0.75' } );
        $('#box_left_content > div').block();
        $.extend( $.blockUI.defaults.overlayCSS, { backgroundColor:'#FFF', opacity:'0.5' } );
    }
    function UnblockUI_RecipeOverview(){
        $.extend( $.blockUI.defaults.overlayCSS, { backgroundColor:'#e6f2bf', opacity:'0.75' } );
        $('#more_search_options_container').block( { cursor: 'default !important' } );
        $.extend( $.blockUI.defaults.overlayCSS, { backgroundColor:'#FFF', opacity:'0.5' } );
    }
    
/* :BLOCK_UI */    

/* PRODUCT_GRID: */
    
    function AddProductGridOdd(){
        $("#ctl00_mainCopy_PRODUCT_GRID").attr({id:'PRODUCT_GRID'});
        
        //$("[class='PRODUCT_GRID_PRODUCT_ROW']:odd").css('backgroundColor', '#FDF3D8');
        /*
        $("tr.PRODUCT_GRID_PRODUCT_ROW .PRODUCT_ROW_INNER").hover(
            function () {
                lastHoverColor = $(this).css('backgroundColor');
                $(this).css('backgroundColor', '#F7D886');
            },
            function () {
                $(this).css('backgroundColor', lastHoverColor);
            }
        );
        */
        
        // onmouseover="lastHoverColor=$(this).css('backgroundColor');$(this).css('backgroundColor', '#F7D886');" onmouseout="$(this).css('backgroundColor', lastHoverColor);"
    }
    
    function initProductMenue() {
        $('.CategoryRangeSelector > tbody > tr:odd').hide().find('a').css('paddingLeft', '10px');
        $('.CategoryRangeSelector > tbody > tr:even').click(
            function (){
                if( $(this).next().css('display')=='none' ){
                    $('.CategoryRangeSelector > tbody > tr:odd').hide();
                    $(this).next().show();
                }else{
                    $(this).next().hide();
                }
            }
        );
    }
    
/* :PRODUCT_GRID */


/* THUMBNAIL_SIZER: */
    
    function initHoverImages(nr, path){
        initHoverImages_RAW('#ImageContainer_Left > .ImageWrapper_Left:nth-child('+ nr +') > img', path);
    }
    function repositionHoverImage( h, t ){
        $('img.bigthumb').css('top', (t-( $('img.bigthumb').height() - h )) + 'px' );
    }
    function initHoverImages_RAW(selector, path){
        if( getOS()=='Windows' ){
            $( selector+'' ).hover(function(){
    			
                $(this).addClass("hover").css({ zIndex: 5, position: "relative" });
    			
                var offset = $(this).position();
                offset.top = offset.top + this.parentNode.scrollTop;
                
                if( $('#ImageContainer_Left > .ImageWrapper_Left > img').length > 1 && $('#ImageContainer_Left > .ImageWrapper_Left > img').eq( $('#ImageContainer_Left > .ImageWrapper_Left > img').length - 1 ).attr('src') == $(this).attr('src') ){
                    var node = $(this).clone()
                        .addClass("bigthumb")
                        .attr({src: path, onload: setTimeout('repositionHoverImage(' + $(this).height() + ', ' + offset.top + ')', 10) })
                        .css({ left: offset.left, top: offset.top, position: "absolute", zIndex: 4, border:'#CDE77C solid 1px', backgroundColor:'#E8F4BC' })
                        .appendTo(this.parentNode)
                        .show();
                }else{
                    var node = $(this).clone()
                        .addClass("bigthumb")
                        .attr({src: path })
                        .css({ left: offset.left, top: offset.top, position: "absolute", zIndex: 4, border:'#CDE77C solid 1px', backgroundColor:'#E8F4BC' })
                        .appendTo(this.parentNode)
                        .show();
                }
                
                /*
			    if((offset.left- (owidth*(modifier-1))/2) > 0)
				    animation.left = offset.left - (owidth*(modifier-1))/2;
    			
			    if((offset.left- (owidth*(modifier-1))/2 + owidth*modifier) > this.parentNode.offsetWidth)
				    animation.left = offset.left - (owidth*(modifier-1));
    			
			    if((offset.top- (this.offsetHeight*(modifier-1))/2) > 0)
				    animation.top = offset.top - (this.offsetHeight*(modifier-1))/2;
    			
			    if((offset.top- (this.offsetHeight*(modifier-1))/2 + this.offsetHeight*modifier) > this.parentNode.scrollHeight)
				    animation.top = offset.top - (this.offsetHeight*(modifier-1));
                */
                $(this).css("opacity", 0);
    			
            }, function() {
                $(this).removeClass("hover");
                $("img.bigthumb").remove();
                $(this).css({opacity: 1, zIndex:''});
            });
        }
    }
    
/* :THUMBNAIL_SIZER */

/* RECIPE_FLASH_WRITER: */
    function thisMovie(movieName) {
        var isIE = navigator.appName.indexOf("Microsoft") != -1;
        return (isIE) ? window[movieName] : document[movieName];
        //return ($.browser.msie) ? window[movieName] : document[movieName];
    }
    
    function addCoverFlowFlash( wmode, start ){
        var so = new SWFObject(noCacheIE("coverflow.swf"), "CoverFlowObject", "500", "200", "8", "#FFFFFF");
        so.addVariable("xmlpath", "content_sources/RecipeCoverFlowContentSource.aspx?rand="+getRandInt(9999999));
        so.addVariable("type", "recipes");
        so.addVariable("wmode", "transparent");
        var tLocation = window.location.href; // ONLY NEEDED FOR DEVELOPMENT..
        if( tLocation.indexOf('qa.knorr')!=-1 || tLocation.indexOf('localhost')!=-1 ){
            so.addVariable("policyfile", "http://cmsqa.unilever.com/crossdomain.xml");
        }else{
            so.addVariable("policyfile", "http://brand-cms.unilever.com/crossdomain.xml");
        }

        if( typeof(start)=='undefined' ){
            so.addVariable("start", "3");
        }else if( start>0 ){
            so.addVariable("start", start);
        }
        
        so.addParam("allowScriptAccess", "always");
        
        so.addParam("wmode", "transparent");

        if( so.write("flash_container") ){
            sHasFlash = true;
            
            if( $.browser.msie ){
                SWFFormFixAuto();
            }
            
            initCoverFlowButtons();
        }else{
            sHasFlash = false;
        }
        /*
        var so = new SWFObject(noCacheIE("coverflow.swf"), "CoverFlowObject", "500", "200", "8", "#FFFFFF");
        so.addVariable("xmlpath", "content_sources/RecipeCoverFlowContentSource.aspx?rand="+getRandInt(9999999));
        so.addVariable("type", "recipes");
        var tLocation = window.location.href; // ONLY NEEDED FOR DEVELOPMENT..
        if( tLocation.indexOf('qa.knorr')!=-1 || tLocation.indexOf('localhost')!=-1 ){
            so.addVariable("policyfile", "http://cmsqa.unilever.com/crossdomain.xml");
        }else{
            so.addVariable("policyfile", "http://brand-cms.unilever.com/crossdomain.xml");
        }
        so.addVariable("start", "3");
        so.addParam("allowScriptAccess", "always");
        if( $.browser.msie || typeof(wmode)!='undefined' ){
            so.addParam("wmode", "transparent");
        }
        so.write("flash_container");
        
        if( $.browser.msie ){
            SWFFormFixAuto();
        }
        
        initCoverFlowButtons();

        */
    }
    
    function addMyCoverFlowFlash( wmode, start ){
        var so = new SWFObject(noCacheIE("coverflow.swf"), "CoverFlowObject", "500", "200", "8", "#FFFFFF");
        so.addVariable("xmlpath", "content_sources/MyRecipeCoverFlowContentSource.aspx?rand="+getRandInt(9999999));
        so.addVariable("type", "recipes");
        var tLocation = window.location.href; // ONLY NEEDED FOR DEVELOPMENT..
        if( tLocation.indexOf('qa.knorr')!=-1 || tLocation.indexOf('localhost')!=-1 ){
            so.addVariable("policyfile", "http://cmsqa.unilever.com/crossdomain.xml");
        }else{
            so.addVariable("policyfile", "http://brand-cms.unilever.com/crossdomain.xml");
        }

        if( typeof(start)=='undefined' ){
            so.addVariable("start", "3");
        }else if( start>0 ){
            so.addVariable("start", start);
        }
        
        so.addParam("allowScriptAccess", "always");
        
        if( $.browser.msie || ( typeof(wmode)!='undefined' && wmode!=null ) ){
            so.addParam("wmode", "transparent");
        }
        if( so.write("flash_container") ){
            sHasFlash = true;
            
            if( $.browser.msie ){
                SWFFormFixAuto();
            }
            
            initCoverFlowButtons();
        }else{
            sHasFlash = false;
        }
    }
    
    function initCoverFlowButtons(){
        
        var btnLeft = $('<a href="#" onclick="return LoadRecipeGridPage(\'page:previous\',\'\');"><img src="Images/paging-cf_l_lo.jpg" style="margin-bottom:1px;" /><img src="Images/paging-cf_l_hi.jpg" style="margin-bottom:1px;display:none;" /></a>');
        $(btnLeft)
            .css({marginRight:'10px'})
            .hover(
                function () {
                    $(this).children('img').hide().next().show();
                },
                function () {
                    $(this).children('img').show().next().hide();
                }
            );
        
        var btnRight = $('<a href="#" onclick="return LoadRecipeGridPage(\'page:next\',\'\');"><img src="Images/paging-cf_r_lo.jpg" style="margin-bottom:1px;" /><img src="Images/paging-cf_r_hi.jpg" style="margin-bottom:1px;display:none;" /></a>');
        //                                     return LoadRecipeGrid_V2('page:next','');
        $(btnRight)
            .css({marginLeft:'10px'})
            .hover(
                function () {
                    $(this).children('img').hide().next().show();
                },
                function () {
                    $(this).children('img').show().next().hide();
                }
            );
        
        if( $('#RECIPE_FOOTER_PANEL.first').length>0 ){
            btnLeft = $('<img src="Images/spacer.gif" width="20" height="17" />');
        }else if( $('#RECIPE_FOOTER_PANEL.last').length>0 ){
            btnRight = $('<img src="Images/spacer.gif" width="20" height="17" />');
        }else if( $('#RECIPE_FOOTER_PANEL.single').length>0 ){
            btnLeft = $('<img src="Images/spacer.gif" width="20" height="17" />');
            btnRight = $('<img src="Images/spacer.gif" width="20" height="17" />');
        }
        
        $('#CoverFlowObject')
            .before(btnLeft)
            .after(btnRight);
    }
    
/* :RECIPE_FLASH_WRITER */

/* INLINE_POPUPS: */
    
	function SOpen(){
        $('#RecipeSearch_PopUp_bg').css('left', ($(document).width()-524)/2 ).css('top', ($(document).height()-396)/2 );
        $('#RecipeSearch_PopUp').css('left', ($(document).width()-524)/2 ).css('top', ($(document).height()-396)/2 );
        $('#RecipeSearch_PopUp').css('height', $(document).height()-(($(document).height()-396)/2 ) );
        
		$('#RecipeSearch_PopUp_bg').show();
		$('#RecipeSearch_PopUp').fadeIn('normal', function(){
		    if( $('.selectArea .right .selectButton').length<=0 ){
			    niceform_init();
			};
		});
	}
	function SClose(){
		$('#RecipeSearch_PopUp').fadeOut('fast',function(){
			$('#RecipeSearch_PopUp_bg').hide();
		});
	};
	
	function NOpen(){
        $('#Naehrwert_PopUp_bg, #Naehrwert_PopUp').css({left:(($(document).width()-264)/2)+'px', top:(($(document).height()-174)/2)+'px', zIndex:2000 });
        
        $('#box_main_rezept, #box_right_rezept, #box_main_produkt, #box_right_produkt').block();
        $('#box_left_rezept_back, #box_left_produkt_back').hide('fast'); //, #box_left_back
	    $('#Naehrwert_PopUp_bg').show();
	    $('#Naehrwert_PopUp').fadeIn('normal');
        
	}
	function NClose(){
		$('#Naehrwert_PopUp').fadeOut('fast',function(){
			$('#Naehrwert_PopUp_bg').hide();
			$('#box_left_rezept_back, #box_left_produkt_back').show('fast'); //, #box_left_back
    	    $('#box_main_rezept, #box_right_rezept, #box_main_produkt, #box_right_produkt').unblock();

		});
	};
			
/* INLINE_POPUPS: */

/* RECIP_INITS: */
    
    function init_ProductsFromRecipe(){
        $('#box_right_rezept_content a.ProductsFromRecipe').each(function(){
            var tProductID = $(this).attr('ProductID');
            $(this).click(function(){
                $('a.ProductsFromRecipe_Active').removeClass('ProductsFromRecipe_Active');
                $(this).addClass('ProductsFromRecipe_Active');
                
                //$('#breadcrumb_container .L2').remove();
                //$('#breadcrumb_container .breadcrumb').append('<span class="L2"> > <a href="'+ $(this).attr('href') +'">'+ $(this).attr('title') +'</a> </span>');
                $('#box_main_rezept h1').html( $(this).attr('title') );
                
                $('#box_main_rezept, #box_right_rezept').block();
                $('#box_left_rezept_back').fadeOut('normal', function(){
                    $.get(
                        "content_sources/ProductDetailContentSource.aspx",
                        {
                            productId: tProductID
                        },
                        function(data){
                            
                            data = trim(data);
                            $('#box_main_rezept_content').html( $(data).find('#box_main_produkt_content').html() );
                            $('#box_main_rezept, #box_right_rezept').unblock();
                            $('#box_left_rezept_back').fadeIn('normal');
                            
                        }
                    );
                });
                return false;
            });
        });
    }
    
    function init_Naehrwaerte(){
        $('#body_ersatz > #Naehrwert_PopUp_bg, #body_ersatz > #Naehrwert_PopUp').remove();
        
        if( $('#Naehrwert_PopUp_HTML_Container .KiloKalorienValue').html()!='' ){
            
            $('#body_ersatz').append( $('#Naehrwert_PopUp_HTML_Container ').html() );
            $('#Naehrwert_PopUp_HTML_Container').remove();
            
            if( $.browser.msie && $.browser.version<=6.0 ){
                $('.recipe_detail_back_button img')
                    .ifixpng().css({width:'54px', height:'50px'});
                $('#Naehrwert_PopUp_bg, .IconsContainer img').ifixpng();
                $('#box_main_rezept h1, #box_main_rezept_content_wrapper, #box_main_rezept_clear').ifixpng();
                $('#box_right_rezept h3, #box_right_rezept_content_wrapper, #box_right_rezept_clear').ifixpng();
            }
    	    
            $('#Naehrwert_PopUp .PopUpClose').click(function(){
                NClose();
                return false;
            });
            
        }else{
            $('#btnNaehrwaertPopup').next().remove().end().remove();
        }
    }
    
/* :RECIP_INITS */


/* FONTSIZER: */
    
    function FSWriteCookie(size) {
        var a = new Date();
        a = new Date(a.getTime() + (1000*60*60*24*365) );
        document.cookie = 'FSSize='+size+'; expires='+a.toGMTString()+';';
    }
    
    function FSReadCookie(pN) {
        n = (typeof(pN)=='undefined')?'FSSize':pN;
        a = document.cookie;
        res = '';
        while(a != '') {
            cookiename = a.substring(0,a.search('='));
            cookiewert = a.substring(a.search('=')+1,a.search(';'));
            //alert( cookiewert );
            if(cookiewert == '') {cookiewert = a.substring(a.search('=')+1,a.length);}
            
            if('FSSize' == cookiename){res = cookiewert;}
            
            i = a.search(';')+1;
            if(i == 0){i = a.length}
            a = a.substring(i,a.length);
        }
        return(res);
    }
    
    function FSDelCookie() {
        document.cookie = 'FSSize=;';
    }
    
    function init_FS(){
        var FSActiveSize = FSReadCookie();
        if( FSActiveSize=='big'){
            FSSetBigStyles();
            $('#meta_fontsize').addClass('active');
        }
        $('#meta_fontsize').toggle(function(){
            if( FSActiveSize!='big' ){
                FSSetBigStyles();
                $(this).addClass('active');
            }else{
                FSSetNormalStyles();
                $(this).removeClass('active');
            }
        },function(){
            if( FSActiveSize!='big' ){
                FSSetNormalStyles();
                $(this).removeClass('active');
            }else{
                FSSetBigStyles();
                $(this).addClass('active');
            }
        }).parent().css({display:''});
    }
    
    function FSRefreshStyles(){
        var FSActiveSize = FSReadCookie();
        if(FSActiveSize=='big'){
            FSSetBigStyles();
        }
    }
    
    function FSSetBigStyles(){
        FSWriteCookie('big');
        
        $('p, #box_main_1, #box_main_rezepte_content, #box_main_produkte_content, #box_main_content_0').css({fontSize: '120%' });
        $('#box_main_content_1 h2').css({fontSize: '120%' });
        $('#box_main_content_1 h3').css({fontSize: '110%' });
        $('#RECIPE_GRID a').css({paddingTop:'4px', paddingBottom:'4px'});
        $('.RECIPE_GRID_RECIPE_ROW .RecipeColumn_E a').addClass('NoPaddingRight');
    }
    
    function FSSetNormalStyles(){
        FSWriteCookie('normal');
        
        $('p, #box_main_1, #box_main_rezepte_content, #box_main_produkte_content, #box_main_content_0').css({fontSize: '' });
        $('#box_main_content_1 h2, #box_main_content_1 h3').css({fontSize: '' });
        $('#RECIPE_GRID a').css({paddingTop:'', paddingBottom:''});
        $('.RECIPE_GRID_RECIPE_ROW .RecipeColumn_E a').removeClass('NoPaddingRight');
    }
    
/* :FONTSIZER */

function getMozV(){
    var mozV = $.browser.version;
    return mozV.replace('.',',').replace(/\./g,'').replace(',','.');
}
function getOS(){
    agt = navigator.userAgent.toLowerCase();
    sys = (navigator.platform)?navigator.platform.toLowerCase():agt;
    agt_os = ((sys.indexOf('mac')>=0)?"Macintosh":(sys.indexOf('unix')>=0 || sys.indexOf('linux')>=0 || sys.indexOf('x11')>=0 || sys.indexOf('x 11')>=0)?"Linux/Unix":(sys.indexOf('os/2')>=0)?"OS/2":(sys.indexOf('win')>=0)?"Windows":"");
    //return agt_os + '" : "' + sys + '"';
    return agt_os;
    /*
        Macintosh
        Linux/Unix
        OS/2
        Windows
    */
}

/* MyPOPUPS: */
    
    function reposPopUp(){
    	
        $('#RecipeSearch_PopUp_bg').css('left', ($(document).width()-524)/2 ).css('top', ($(document).height()-396)/2 );
        $('#RecipeSearch_PopUp').css('left', ($(document).width()-524)/2 ).css('top', ($(document).height()-396)/2 );
        //$('#RecipeSearch_PopUp').css('height', $(document).height()-(($(document).height()-396)/2 ) );
        
    }

    /* MyTags POPUP: */
        
        function openMyTagsEdit( data ){
            // {RecipeID:'',Title:'',Howto:'',SubTitle:'',Tags:'',Save:'',Back:''}
            
            msg  = '<p>' + data.Howto + '</p>';
            msg += '<strong>' + data.SubTitle + '</strong><br />';
            msg += '<textarea id="txtMyTagsEdit" style="width:300px;height:80px;">' + br2nl(data.Tags) + '</textarea>';
            
            $.prompt( msg , {
                submit: openMyTagsEditSubmit,
                title: data.Title,
		        buttons: { Back: false, Save: true },
		        buttonLabels: { Back: data.Back, Save: data.Save },
		        hiddenValues: { MyRecipeID: data.RecipeID, MyOrigin: data.Origin }
	        } );
            return false;
        }
        function openMyTagsEditSubmit(retval, obj, h){
            if( retval ){
                var myTags = obj.find('#txtMyTagsEdit').val();
                
                $('.jqi .jqimessage .error').remove();
                $.ajax({
                    type: "POST",
                    url: "MyJavaScriptBackend.aspx",
                    data: "action=SaveMyTags&recipe_id=" + h.MyRecipeID + "&text=" + myTags + "&origin=" + h.MyOrigin,
                    dataType: "json",
                    success: function(data){
                        //alert( "Data Saved: " + data.status + ", text: "+ myTags );
                        if( data.status ){
                            $('#MyTagsContainer .UserContent span').html( nl2br(myTags) );
                            $('.jqifade, .jqi').remove();
                        }else{
                            $('.jqi .jqimessage').prepend('<p class="error">ERROR: ' + data.message + '</p>');
                        }
                    },
                    error: function(){
                        $('.jqi .jqimessage').prepend('<p class="error">ERROR: Page not found (404)</p>');
                    }
                });
                return false;
            }else{
                return true;
            }
        }
        
    /* :MyTags POPUP */

    /* PWReminder POPUP: */
        
        function openPWReminder( data ){
            // { Title:'', Howto:'', SubTitle:'', Do:'', Back:'' }
            
            msg  = '<p>' + data.Howto + '</p>';
            msg += '<p><strong>' + data.SubTitle + '</strong><br />';
            msg += '<input type="text" id="txtUserMail" style="border:1px solid #AAC846; width:300px;" /></p>';
            
            $.prompt( msg , {
                submit: openPWReminderSubmit,
                title: data.Title,
		        buttons: { Back: false, Do: true },
		        buttonLabels: { Back: data.Back, Do: data.Do }
	        } );
            return false;
        }
        function openPWReminderSubmit(retval, obj){
            if( retval ){
                var UserMail = obj.find('#txtUserMail').val();
                
                $('.jqi .jqimessage .error').remove();
                $.ajax({
                    type: "POST",
                    url: "MyJavaScriptBackend.aspx",
                    data: "action=PWReminder&UserMail=" + UserMail,
                    dataType: "json",
                    success: function(data){
                        if( data.status ){
                            $('.jqifade, .jqi').remove();
                            alert( data.message );
                        }else{
                            $('.jqi .jqimessage').prepend('<p class="error">ERROR: ' + data.message + '</p>');
                        }
                    },
                    error: function(){
                        $('.jqi .jqimessage').prepend('<p class="error">ERROR: Page not found (404)</p>');
                    }
                });
                return false;
            }else{
                return true;
            }
        }
        
    /* :PWReminder POPUP */

    /* DelRecipe POPUP: */
        
        function openRecipeDelete( data ){
            // { RecipeId:'', Title:'', Howto:'', Del:'', Back:'' }
            
            msg  = '<p>' + data.Howto + '</p>';
            
            $.prompt( msg , {
                submit: openRecipeDeleteSubmit,
                title: data.Title,
		        buttons: { Back: false, Del: true },
		        buttonLabels: { Back: data.Back, Del: data.Del },
		        hiddenValues: { delRecipeID: data.RecipeId }
	        } );
            return false;
        }
        function openRecipeDeleteSubmit(retval, obj, h){
            if( retval ){
                $('.jqi .jqimessage .error').remove();
                $.ajax({
                    type: "POST",
                    url: "MyJavaScriptBackend.aspx",
                    data: "action=DeleteRecipe&recipe_id=" + h.delRecipeID,
                    dataType: "json",
                    success: function(data){
                        //alert( "Data Saved: " + data.status + ", text: "+ myTags );
                        if( data.status ){
                            $('#RecipeId_' + h.delRecipeID).parent().parent().remove();
                            $('.RECIPE_GRID_RECIPE_ROW').css('backgroundColor','');
                            initRecipeGrid();
                            $('.jqifade, .jqi').remove();
                            if( $('#box_main_rezept').length>0 ){
                                CloseRecipeDetails();
                            }
                        }else{
                            $('.jqi .jqimessage').prepend('<p class="error">ERROR: ' + data.message + '</p>');
                        }
                    },
                    error: function(){
                        $('.jqi .jqimessage').prepend('<p class="error">ERROR: Page not found (404)</p>');
                    }
                });
                return false;
            }else{
                return true;
            }
        }
        
    /* :DelRecipe POPUP */

    /* AddToMyCookBook POPUP: */
        
        function openAddToMyCookBook( data ){
            // {RecipeId:'',Status:'',CheckStatus:'',OkTitle:'',OkHowto:'',OkDo:'',nLogTitle:'',nLogHowto:'',nLogDo:'',nOkTitle:'',nOkHowto:'',Back:''}
            // Status = 'ok' | 'present' | 'no recipeId' | 'not logged in'
            // CheckStatus = true | false | undefined
            
            if( typeof(data.CheckStatus)!='undefined' && data.CheckStatus && data.Status!='not logged in'  ){
                // check the real mycookbook state of the recipe:
                $.ajax({
                    type: "POST",
                    url: "MyJavaScriptBackend.aspx",
                    data: "action=AddToFavourites_CheckStatus&recipe_id=" + data.RecipeID,
                    dataType: "json",
                    success: function(data2){
                        //alert( "Data Saved: " + data.status + ", text: "+ myTags );
                        if( data2.status ){
                            data.Status = data2.MyStatus;
                            data.CheckStatus = false;
                            openAddToMyCookBook( data );
                            //$('.jqifade, .jqi').remove();
                        }else{
                            //$('.jqi .jqimessage').prepend('<p class="error">ERROR: ' + data2.message + '</p>');
                            alert('<p class="error">ERROR: ' + data2.message + '</p>');
                        }
                    },
                    error: function(){
                        //$('.jqi .jqimessage').prepend('<p class="error">ERROR: Page not found (404)</p>');
                        alert('<p class="error">ERROR: CheckPage not found (404)</p>');
                    }
                });
                
            }else{
                
                if( data.Status=='ok' ){
                    var msg  = '<p>' + data.OkHowto + '</p>';
                    $.prompt( msg , {
                        submit: openAddToMyCookBookSubmit,
                        title: data.OkTitle,
		                buttons: { Back: false, Do: true },
		                buttonLabels: { Back: data.Back, Do: data.OkDo },
		                hiddenValues: { RecipeID: data.RecipeID, Status: data.Status }
	                } );
	            }else if( data.Status=='present' ){
                    var msg  = '<p>' + data.nOkHowto + '</p>';
                    $.prompt( msg , {
                        submit: openAddToMyCookBookSubmit,
                        title: data.nOkTitle,
		                buttons: { Back: false, Do: data.OkDo },
		                buttonLabels: { Back: data.Back, Do: data.OkDo },
		                hiddenValues: { RecipeID: data.RecipeID, Status: data.Status }
	                } );
	            }else{ // 'no recipeId' | 'not logged in'
                    var msg  = '<p>' + data.nLogHowto + '</p>';
                    $.prompt( msg , {
                        submit: openAddToMyCookBookSubmit,
                        title: data.nLogTitle,
		                buttons: { Back: false, Do: true },
		                buttonLabels: { Do: data.nLogDo, Back: data.Back },
		                hiddenValues: { RecipeID: data.RecipeID, Status: data.Status }
	                } );
	            }
    	        
	        }
            return false;
        }
        function openAddToMyCookBookSubmit(retval, obj, h){
            if( retval ){
                
                $('.jqi .jqimessage .error').remove();
                if( h.Status=='ok' || h.Status=='present' ){
                    $.ajax({
                        type: "POST",
                        url: "MyJavaScriptBackend.aspx",
                        data: "action=AddToFavourites&recipe_id=" + h.RecipeID,
                        dataType: "json",
                        success: function(data){
                            //alert( "Data Saved: " + data.status + ", text: "+ myTags );
                            if( data.status ){
                                //$('.AddRecipeToMyCookBook').remove();
                                if( $.browser.mozilla ){
                                    var tOnClick = $('#box_main_rezept .AddRecipeToMyCookBook').attr('onclick');
                                    if( typeof(tOnClick)!='undefined' && tOnClick!='' ){
                                        tOnClick = tOnClick.replace("Status:'ok'", "Status:'present'");
                                        $('#box_main_rezept .AddRecipeToMyCookBook').attr('onclick', tOnClick);
                                    }
                                }
                                $('.jqifade, .jqi').remove();
                            }else{
                                $('.jqi .jqimessage').prepend('<p class="error">ERROR: ' + data.message + '</p>');
                            }
                        },
                        error: function(){
                            $('.jqi .jqimessage').prepend('<p class="error">ERROR: Page not found (404)</p>');
                        }
                    });
	            }else{ // 'no recipeId' | 'not logged in'
                    // redirect to login..
                    $('.jqifade, .jqi').remove();
                    window.location.href = 'MyKnorr.aspx';
	            }
                return false;
            }else{
                return true;
            }
        }
        
    /* :AddToMyCookBook POPUP */
    
    /* MyComment POPUP: */
        
        function openMyCommentEdit( data ){
            // {RecipeId:'',Type:'',Title:'',Howto:'',SubTitle:'',Save:'',Back:''}
            
            var msg  = '<p>' + data.Howto + '</p>';
                msg += '<strong>' + data.SubTitle + '</strong><br />';
                msg += '<textarea id="txtMyCommentEdit" style="width:300px;height:80px;">' + data.MyComment + '</textarea>';
            
            $.prompt( msg , {
                submit: openMyCommentEditSubmit,
                title: data.Title,
		        buttons: { Back: false, Save: true },
		        buttonLabels: { Back: data.Back, Save: data.Save },
		        hiddenValues: { MyRecipeID: data.RecipeId, myCommentTargetType: data.Type, myOrigin: data.Origin }
	        } );
            return false;
        }
        function openMyCommentEditSubmit(retval, obj, h){
            if( retval ){
                var myComment = obj.find('#txtMyCommentEdit').val();
                
                $('.jqi .jqimessage .error').remove();
                $.ajax({
                    type: "POST",
                    url:  "MyJavaScriptBackend.aspx",
                    data: "action=SaveMyComment&recipe_id=" + h.MyRecipeID + "&text=" + myComment + "&origin=" + h.myOrigin,
                    dataType: "json",
                    success: function(data){
                        //alert( "Data Saved: " + data.status + ", text: "+ myComment );
                        if( data.status ){
                            if( h.myCommentTargetType=='detail' ){
                                $('#MyCommentContainer .UserContent span').html( nl2br(myComment) );
                            }else{
                                $('#MyComment' + h.MyRecipeID + 'Resources .lblMyCommentUserContent').html( nl2br(myComment) );
                            }
                            $('.jqifade, .jqi').remove();
                        }else{
                            $('.jqi .jqimessage').prepend('<p class="error">ERROR: ' + data.message + '</p>');
                        }
                    },
                    error: function(){
                        $('.jqi .jqimessage').prepend('<p class="error">ERROR: Page not found (404)</p>');
                    }
                });
                return false;
            }else{
                return true;
            }
        }
        
        /* OLD: */
        function saveMyCommentEdit(){
            $('#RecipeSearch_PopUp').block();
            var myComment = $('#txtMyCommentEdit').val();
            $.ajax({
                type: "POST",
                url: "MyJavaScriptBackend.aspx",
                data: "action=SaveMyComment&text=" + myComment,
                dataType: "json",
                success: function(data){
                    //alert( "Data Saved: " + data.status + ", text: "+ myComment );
                    if( data.status ){
                        $('#MyCommentContainer .UserContent span').html( myComment );
                    }else{
                        alert( data.message );
                    }
                    closeMyCommentEdit();
                },
                error: function(){
                    alert('Page not found (404)');
                    closeMyCommentEdit();
                }
            });
            return false;
        }
        
    /* :MyComment POPUP */

    
    /* Comment POPUP: */
        
        function openCommentEdit( data ){
            // {RecipeId:'',Origin:'',Type:'',Comments:'',Title:'',Howto:'',SubTitle:'',Save:'',Back:'',NewCommentTitle:''}
            // NewCommentTitle = 'undefined' | '' --> PageReload
            // NewCommentTitle = 'comment title'  --> Dyn. Change of CommentContent-Container
            
            var msg  = '<p>' + data.Howto + '</p>';
            msg += '<div class="SubInfoScrollBox" style="width:300px; height:100px; padding:2px 1px; margin-bottom:10px;"><div>' + data.Comments + '</div></div>';
            msg += '<strong>' + data.SubTitle + '</strong><br />';
            msg += '<textarea id="txtCommentEdit" style="width:300px;height:80px;"></textarea>';
            
            $.prompt( msg , {
                submit: openCommentEditSubmit,
                title: data.Title,
		        buttons: { Back: false, Save: true },
		        buttonLabels: { Back: data.Back, Save: data.Save },
		        hiddenValues: { AdminRecipeID: data.RecipeId, NewCommentTitle: data.NewCommentTitle, myCommentTargetType: data.Type, myOrigin: data.Origin },
		        loaded: function(){
		            $(this).find('.SubInfoScrollBox').scrollTop( $(this).find('.SubInfoScrollBox div').height() );
		        }
	        } );
            return false;
        }
        function openCommentEditSubmit(retval, obj, h){
            if( retval ){
                var myComment = obj.find('#txtCommentEdit').val();
                
                $('.jqi .jqimessage .error').remove();
                $.ajax({
                    type: "POST",
                    url:  "MyJavaScriptBackend.aspx",
                    data: "action=SaveMyComment&recipe_id=" + h.AdminRecipeID + "&text=" + myComment + "&origin=" + h.myOrigin,
                    dataType: "json",
                    success: function(data){
                        //alert( "Data Saved: " + data.status + ", text: "+ myComment );
                        if( data.status ){
                            if( h.myCommentTargetType=='detail' ){
                                $('#MyTagsContainer .UserContent span').html( nl2br(myComment) );
                            }else{
                                $('#MyComment' + h.AdminRecipeID + 'Resources .lblMyCommentUserContent').html( nl2br(myComment) );
                            }
                            $('.jqifade, .jqi').remove();
                            
                            if( typeof(h.NewCommentTitle)=='undefined' || h.NewCommentTitle=='' ){
                                window.location.reload();
                            }else{
                                var DateHeute = new Date();
                                $('#MyCommentContainer .UserContent > span').append('<h6>' + h.NewCommentTitle + ' <span>('+ DateHeute.getDate()+'.'+(DateHeute.getMonth()+1)+'.'+DateHeute.getFullYear()+')</span></h6><p>' + myComment + '</p>');
                            }
                        }else{
                            $('.jqi .jqimessage').prepend('<p class="error">ERROR: ' + data.message + '</p>');
                        }
                    },
                    error: function(){
                        $('.jqi .jqimessage').prepend('<p class="error">ERROR: Page not found (404)</p>');
                    }
                });
                return false;
            }else{
                return true;
            }
        }
        
    /* :Comment POPUP */
    
    /* AdminComment POPUP: */
        
        function openAdminCommentEdit( data ){
            // {AdminRecipeId:'',Type:'',AdminComments:'',Title:'',Howto:'',SubTitle:'',Save:'',Back:''}
            
            var msg  = '<p>' + data.Howto + '</p>';
            msg += '<div class="SubInfoScrollBox" style="width:300px; height:100px; padding:2px 1px; margin-bottom:10px;"><div>' + data.AdminComments + '</div></div>';
            msg += '<strong>' + data.SubTitle + '</strong><br />';
            msg += '<textarea id="txtMyCommentEdit" style="width:300px;height:80px;"></textarea>';
            
            $.prompt( msg , {
                submit: openAdminCommentEditSubmit,
                title: data.Title,
		        buttons: { Back: false, Save: true },
		        buttonLabels: { Back: data.Back, Save: data.Save },
		        hiddenValues: { AdminRecipeID: data.AdminRecipeId, myCommentTargetType: data.Type, myOrigin: data.Origin },
		        loaded: function(){
		            $(this).find('.SubInfoScrollBox').scrollTop( $(this).find('.SubInfoScrollBox div').height() );
		        }
	        } );
            return false;
        }
        function openAdminCommentEditSubmit(retval, obj, h){
            if( retval ){
                var myComment = obj.find('#txtMyCommentEdit').val();
                
                $('.jqi .jqimessage .error').remove();
                $.ajax({
                    type: "POST",
                    url:  "MyJavaScriptBackend.aspx",
                    data: "action=SaveMyComment&recipe_id=" + h.AdminRecipeID + "&text=" + myComment + "&origin=" + h.myOrigin,
                    dataType: "json",
                    success: function(data){
                        //alert( "Data Saved: " + data.status + ", text: "+ myComment );
                        if( data.status ){
                            if( h.myCommentTargetType=='detail' ){
                                $('#MyTagsContainer .UserContent span').html( nl2br(myComment) );
                            }else{
                                $('#MyComment' + h.AdminRecipeID + 'Resources .lblMyCommentUserContent').html( nl2br(myComment) );
                            }
                            $('.jqifade, .jqi').remove();
                            window.location.reload();
                        }else{
                            $('.jqi .jqimessage').prepend('<p class="error">ERROR: ' + data.message + '</p>');
                        }
                    },
                    error: function(){
                        $('.jqi .jqimessage').prepend('<p class="error">ERROR: Page not found (404)</p>');
                    }
                });
                return false;
            }else{
                return true;
            }
        }
        
    /* :AdminComment POPUP */
        
/* :MyPOPUPS */


function NoSubmitOnEnter(e, textBoxID) {
	var keynum
	if(window.event) { // IE
		keynum = e.keyCode;
	} else if(e.which) { // Netscape/Firefox/Opera
		keynum = e.which;
	}
	if (keynum==13) 
                 //Do nothing;
                 return false;
	else return true;
}

/* RESSOURCES: */
    
    function doFlagLogoutClick( data ){
        // { Title:'', Howto:'', Logout:'', Back:'' }
        
        msg = '<p>' + data.Howto + '</p>';
        
        $.prompt( msg , {
            callback: doFlagLogoutCallback,
            title: data.Title,
		    buttons: { Back: false, Logout: true },
		    buttonLabels: { Back: data.Back, Logout: data.Logout }
	    } );
        return false;
    }
    function doFlagLogoutCallback(retval, obj){
        if( retval ){
            window.location.href='MyRegistrierung-freischalten.aspx?logout=true';
        }
    }
    
/* :RESSOURCES */

/* FORMVALHELPER: */
    
    function checkActiveErrorMessages(){
        $('span').each(function(){
            if( $(this).css('visibility')!='hidden' && $(this).css('display')=='none' ){
                $(this).css({ display:'block' });
            }
        });
    }
    
/* :FORMVALHELPER */

/* NEW_POPUPS: */
    /*
	window.alert = function(msg, title){
	    if( typeof(title)=='undefined' ){
	        title = 'KNORR.ch';
	    }
		$.prompt( msg, {
		    title: title,
			buttons: { OK:true }
		} );
	}
	*/
    /* Rating POPUP: */
        
        function openRating( data ){
            // openRating({RecipeID:'',Title:'',Howto:'',Star1:'',Star2:'',Star3:'',Star4:'',Star5:'',Cooked:'',Rate:'',Back:''})
            
            msg  = '<p>' + data.Howto + '</p>';
            msg += '<div class="rbRatingPopupGroup">';
                msg += '<input type="radio" class="selRating" name="rbRating" id="rbRating5" value="5" /><label for="rbRating5"><img style="margin-left:12px;" src="Images/stern.png" /><img src="Images/stern.png" /><img src="Images/stern.png" /><img src="Images/stern.png" /><img src="Images/stern.png" />&nbsp;' + data.Star5 + '</label><br />';
                msg += '<input type="radio" class="selRating" name="rbRating" id="rbRating4" value="4" /><label for="rbRating4"><img style="margin-left:24px;" src="Images/stern.png" /><img src="Images/stern.png" /><img src="Images/stern.png" /><img src="Images/stern.png" />&nbsp;' + data.Star4 + '</label><br />';
                msg += '<input type="radio" class="selRating" name="rbRating" id="rbRating3" value="3" /><label for="rbRating3"><img style="margin-left:36px;" src="Images/stern.png" /><img src="Images/stern.png" /><img src="Images/stern.png" />&nbsp;' + data.Star3 + '</label><br />';
                msg += '<input type="radio" class="selRating" name="rbRating" id="rbRating2" value="2" /><label for="rbRating2"><img style="margin-left:48px;" src="Images/stern.png" /><img src="Images/stern.png" />&nbsp;' + data.Star2 + '</label><br />';
                msg += '<input type="radio" class="selRating" name="rbRating" id="rbRating1" value="1" /><label for="rbRating1"><img style="margin-left:60px;" src="Images/stern.png" />&nbsp;' + data.Star1 + '</label><br />';
                msg += '<br /><input type="checkbox" class="selRatingChk" id="chkCooked" value="1" /><label for="chkCooked" style="padding-left:15px;">' + data.Cooked + '</label><br />';
            msg += '</div>';
            
            $.prompt( msg , {
                submit: openRatingSubmit,
                title: data.Title,
		        buttons: { Back: false, Rate: true },
		        buttonLabels: { Back: data.Back, Rate: data.Rate },
		        hiddenValues: { MyRecipeID: data.RecipeID }
	        } );
            return false;
        }
        function openRatingSubmit(retval, obj, h){
            if( retval ){
                var myRating = obj.find('.selRating:checked').val();
                if( typeof(myRating)=='undefined' ){ myCooked = 0; }
                var myCooked = obj.find('.selRatingChk:checked').val();
                if( typeof(myCooked)=='undefined' ){ myCooked = 0; }
                
                $('.jqi .jqimessage .error').remove();
                $.ajax({
                    type: "POST",
                    url: "MyJavaScriptBackend.aspx",
                    data: "action=SaveRanking&recipe_id=" + h.MyRecipeID + "&rank=" + myRating + "&cooked='" + myCooked + "'",
                    dataType: "json",
                    success: function(data){
                        //alert( "Data Saved: " + data.status + ", text: "+ myTags );
                        if( data.status ){
                            if( typeof(data.BewertungsBildGross)!='undefined' && data.BewertungsBildGross!='' ){
                                $('.MyRecipeDetailRatingIcon').attr('src', data.BewertungsBildGross);
                            }
                            $('.jqifade, .jqi').remove();
                        }else{
                            $('.jqi .jqimessage').prepend('<p class="error">ERROR: ' + data.message + '</p>');
                        }
                    },
                    error: function(){
                        $('.jqi .jqimessage').prepend('<p class="error">ERROR: Page not found (404)</p>');
                    }
                });
                return false;
            }else{
                return true;
            }
        }
        
    /* :Rating POPUP */
    
/* :NEW_POPUPS */

function nl2br( str ){
    return str.replace(/\n/g,'<br />');
}
function br2nl( str ){
    return str.replace(/<br \/>/g,"\n").replace(/<br>/g,"\n");
}

       var MAX_DUMP_DEPTH = 10;
       function dumpObj(obj, name, indent, depth) {

              if (depth > MAX_DUMP_DEPTH) {

                     return indent + name + ": <Maximum Depth Reached>\n";

              }

              if (typeof obj == "object") {

                     var child = null;

                     var output = indent + name + "\n";

                     indent += "\t";

                     for (var item in obj)

                     {

                           try {

                                  child = obj[item];

                           } catch (e) {

                                  child = "<Unable to Evaluate>";

                           }

                           if (typeof child == "object") {

                                  output += dumpObj(child, item, indent, depth + 1);

                           } else {

                                  output += indent + item + ": " + child + "\n";

                           }

                     }

                     return output;

              } else {

                     return obj;

              }

}

function trim( str ){
    return str.replace (/^\s+/, '').replace (/\s+$/, '');
}