﻿function pageload(hash) { }

function loadXMLDoc(url) {
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
        xmlhttp.open("GET", url, false);
        xmlhttp.send(null);
        document.getElementById('RecipeList').innerHTML = xmlhttp.responseText;
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        xmlhttp.open("GET", url, false);
        xmlhttp.send(null);
        document.getElementById('RecipeList').innerHTML = xmlhttp.responseText;
    }
}

function toggleFilterLabel(labelId) {
    $('#' + labelId).toggleClass('recipe_filter_item_active');
}

function showHideComments() {
    if ($('#recipe_comment_list:hidden').length > 0) {
        $('#recipe_comment_list').slideDown();
        $('.recipe_comment_form .recipe_comment_show').find('a').html('Skjul alle tips og kommentarer');
        window.location.hash = 'comments_top';
    } else {
        $('#recipe_comment_list').slideUp();
        $('.recipe_comment_form .recipe_comment_show').find('a').html('Vis alle tips og kommentarer');
    }
}
function reloadVideoPage(videoID) {
    currentURL = location.href.split('?');
    if (currentURL[0].indexOf('Default') == '-1') {
        newURL = currentURL[0] + '?videoID=' + videoID;
    } else {
        newURL = currentURL[0] + '?ID=' + $.url.param('ID') + '&videoID=' + videoID;
    }
    if ($.url.param('PageNum') != '') {
        newURL = newURL + '&PageNum=' + $.url.param('PageNum');
    }
    location.href = newURL;
}

function flashFallback(e) {
    if (!(e.success)) {
        $('body').append('<div class="img_bg"><img src="/Files/System/rgdk/images/bg_body2.jpg" id="fullscreenbg" alt="" /></div>');
        var FullscreenrOptions = { width: 768, height: 750, bgID: '#fullscreenbg' };
        jQuery.fn.fullscreenr(FullscreenrOptions);
        $.ajax({
            type: "GET",
            url: "/Default.aspx?ID=641&action=xmlfeed&max=10",
            dataType: "xml",
            success: function (xml) {
                var fallbackHtml = '';
                fallbackHtml += '<ul id="ffb-items" class="jcarousel-skin-tango">';
                $(xml).find('NewDataSet Table').each(function () {
                    fallbackHtml += '<li class="ffb-item">';
                    fallbackHtml += '<div class="ffb-image"><a href="/btc/Opskrift.aspx?ProductID=' + $(this).find('ProductID').text() + '" title="' + $(this).find('ProductName').text() + '"><img src="/files' + $(this).find('ProductImageLarge').text() + '" /></a></div>';
                    fallbackHtml += '<div class="ffb-text">' + $(this).find('ProductName').text() + '</div>';
                    fallbackHtml += '</li>';
                });
                fallbackHtml += '</ul><div class="ffb-back"><a href="#"></a></div><div class="ffb-forward"><a href="#"></a></div>';
                fallbackHtml += '<div id="ffb-search"><form name="EcomSearch" method="get" action="/Default.aspx"><input type="hidden" id="eComSearchField" name="ID" value="607" /><label for="recipe_search_field">Søg i opskrifter, fisk og ingredienser</label><span class="search_field"><input type="text" id="recipe_search_field" name="eComQuery" class="input_txt" value="Søg i opskrifter, fisk og ingredienser" /></span><span class="search_btn"><input type="submit" value="" id="recipe_search_btn" /></span></form></div>';

                $('#fallback-slider').append(fallbackHtml);
                $('#ffb-items').jcarousel({ start: 1, scroll: 1, wrap: 'both', size: 10 });

                // empty on focus and blur function for the search field
                $('.input_txt').each(function () {
                    var default_value = this.value;
                    $(this).focus(function () {
                        if (this.value == default_value) {
                            this.value = '';
                        }
                    });
                    $(this).blur(function () {
                        if (this.value == '') {
                            this.value = default_value;
                        }
                    });
                });
            }
        });
    }
}

// Vars and func for mobile popup
var engineWebKit = "webkit";
var deviceAndroid = "android";
var deviceIphone = "iphone";
var deviceIpod = "ipod";
var uagent = navigator.userAgent.toLowerCase();
//**************************
// Detects if the current device is an iPhone.
function DetectIphone() {
    if (uagent.search(deviceIphone) > -1)
        return true;
    else
        return false;
}
//**************************
// Detects if the current device is an iPod Touch.
function DetectIpod() {
    if (uagent.search(deviceIpod) > -1)
        return true;
    else
        return false;
}
//**************************
// Detects if the current device is an iPhone or iPod Touch.
function DetectIphoneOrIpod() {
    if (DetectIphone())
        return true;
    else if (DetectIpod())
        return true;
    else
        return false;
}
///**************************
// Detects if the current device is an Android OS-based device.
function DetectAndroid() {
    try {
        if (uagent.search(deviceAndroid) > -1)
            return true;
        else
            return false;
    }
    catch (ex) {
        return false;
    }
}
//**************************
// Detects if the current browser is based on WebKit.
function DetectWebkit() {
    try {
        if (uagent.search(engineWebKit) > -1)
            return true;
        else
            return false;
    }
    catch (ex) {
        return false;
    }
}
//**************************
// Detects if the current device is an Android OS-based device and
//   the browser is based on WebKit.
function DetectAndroidWebKit() {
    if (DetectAndroid()) {
        if (DetectWebkit())
            return true;
        else
            return false;
    }
    else
        return false;
}
function hideMobileMessage() {
    $('.mobile-wrap').css('display', 'none');
    writeAndroidCookie(true);
}
var MobileCookieWritten = false;
function writeAndroidCookie(long) {
    if (MobileCookieWritten == false) {
        if (long == true)
            $.cookie("MOBILEMESSAGE", "HIDE", { expires: 180 });
        else
            $.cookie("MOBILEMESSAGE", "HIDE");
        MobileCookieWritten = true;
    }
}

$(document).ready(function () {

    //mobile popup
    if (DetectAndroidWebKit() || DetectIphoneOrIpod()) {
        if ($.cookie("MOBILEMESSAGE") != "HIDE") {
            var data = '<div class="mobile-con">';
            data += '<div class="mobile-close"><a href="javascript:hideMobileMessage()" title="Luk popup"><img src="/Files/System/rgdk/images/btn-close-mobile-popup.png" alt="Luk popup" /></a></div>';
            data += '<div class="android-content">';
            data += '<a href="market://search?q=pname:dk.royalgreenland.android.torsk" title="Hent Fra torsk til haj på Android Market"><img src="/Files/System/rgdk/images/btn-android-link.png" alt="Hent Fra torsk til haj på Android Market" /></a>';
            data += '</div>';
            data += '<div class="itunes-content">';
            data += '<a href="http://itunes.apple.com/dk/app/fra-t-k-til-haj/id381705751?mt=8&uo=4" title="Hent Fra torsk til haj på iTunes"><img src="/Files/System/rgdk/images/btn-itunes-link.png" alt="Hent Fra torsk til haj på iTunes" /></a>';
            data += '</div>';
            data += '</div>';
            $('.mobile-wrap').html(data);
            $('.mobile-wrap').css('display', 'block');
        }
    }

    //Setup and start the fullscreen img
    /*if ($("#fullscreenbg").length > 0) {
        var FullscreenrOptions = { width: 768, height: 750, bgID: '#fullscreenbg' };
        jQuery.fn.fullscreenr(FullscreenrOptions);
    }*/

    // empty on focus and blur function for the search field
    $('.input_txt').each(function () {
        var default_value = this.value;
        $(this).focus(function () {
            if (this.value == default_value) {
                this.value = '';
            }
        });
        $(this).blur(function () {
            if (this.value == '') {
                this.value = default_value;
            }
        });
    });


    //recipe list functions
    if ($(".recipe_list_con").length > 0) {
        //hover effect on recipe list
        $('.recipe_list_item').hover(function () {
            $(this).toggleClass('recipe_list_item_active');
        });

        //call the webservice to set the previous filter
        if (location.href.indexOf('#') != -1) {
            currentAjaxHash = location.href.split('#')[1];
            if (currentAjaxHash != null) {
                ajaxHash = '/Default.aspx?ID=622&action=ws&' + currentAjaxHash;
                loadXMLDoc(ajaxHash);
            }
            //set the filter checkboxes
            filterGroups = currentAjaxHash.split('GROUPID=');
            for (i = 1; i <= filterGroups.length; i++) {
                if (filterGroups[i] != null) {
                    filterGroup = filterGroups[i].replace('&', '');
                    toggleFilterLabel('label_' + filterGroup);
                }
            }
        }
        // Initialize history plugin.
        $.historyInit(pageload, "");

        // set onlick event for buttons
        $(".recipe_filter_item label").click(function () {
            var hash = $(this).parent().find("input").val();
            hash = hash.replace(/^.*#/, '');
            $.historyLoad(hash);
            return false;
        });
    }

    //recipe comments  
    if ($("#currentProdId").length > 0) {
        var currentProdId = $("#currentProdId").html();
        $('#RecipeCommentTable_RecipeCommentProdId').val(currentProdId);
    }

    //recipe comment show click
    if ($(".recipe_comment").length > 0) {
        $('.recipe_comment_counter').css('display', 'block');
        $('#no_comments').css('display', 'none');
        $('.recipe_comment_counter_number').html($('.recipe_comment').length);

        //  $('.recipe_comment_form h2').click(function () {
        //  showHideComments();
        //});
        //if ($("#comment_sent").length > 0) {
        //  showHideComments();
        //}
    }

    //shopping list functions
    if ($(".recipe_ingredients_input").length > 0) {
        var shoppingSplit = '';
        var shoppingData = '';
        var shoppingPreCookie = '';
        var shoppingCookie = '';
        var shoppingSplitCookie = '';

        //ingredient labels
        $(".recipe_ingredients_item label").click(function (event) {
            $(this).toggleClass('recipe_ingredients_item_active');
            var $checkbox = $(this).prev();
            $checkbox.attr('checked', !$checkbox.attr('checked'));
        });

        ////open the shoppinglist with cookie content if any is present
        if ($.cookie("RGSHOPPINGLIST")) {
            //update the shoppinglist html            
            shoppingSplit = '';
            shoppingSplit = String($.cookie("RGSHOPPINGLIST")).split(';');
            for (var i = 1; i < shoppingSplit.length; i++) {
                var shopping2ndSplit = shoppingSplit[i].split('|');
                shoppingData += '<li id="ingID' + shopping2ndSplit[0] + '">' + shopping2ndSplit[1] + ' ' + shopping2ndSplit[2] + ' ' + decodeURI(shopping2ndSplit[3]) + ' <span rel=";' + shoppingSplit[i] + '" title="Fjern ' + decodeURI(shopping2ndSplit[3]) + '" class="remove"></span></li>';
            }
            $('#shopping-ul').html(shoppingData);

            //animate the shoppinglist
            $('#shopping-content').animate({
                height: $('#shopping-ul').height()
            }, 500, function () {
                $('#shopping-con').toggleClass('no-ingredients');
            });
            setTimeout(
                $('#shopping-fold').toggleClass('folding'), 300
            );
            $('#shopping-ul').fadeIn('slow');

            //clickevent for the remove button 
            $("#shopping-ul li span.remove").click(function (event) {
                if ($.cookie("RGSHOPPINGLIST") === null) {
                    shoppingCookie = '';
                } else {
                    shoppingCookie = String($.cookie("RGSHOPPINGLIST"));
                }
                shoppingCookie = shoppingCookie.replace($(this).attr('rel'), '');

                $.cookie("RGSHOPPINGLIST", shoppingCookie, { expires: 14 });
                $(this).parents('li').remove();
                if ($('#shopping-ul li').length == 0) {
                    ////close the shoppinglist
                    //update the shoppinglist
                    $('#shopping-ul').fadeOut('slow');
                    $('#shopping-ul').html(' ');

                    //animate the shoppinglist
                    $('#shopping-content').animate({
                        height: '0'
                    }, 500, function () {
                        $('#shopping-con').toggleClass('no-ingredients');
                    });
                    setTimeout(
                        $('#shopping-fold').removeClass('folding'), 300
                    );
                } else {
                    $('#shopping-content').animate({
                        height: ($('#shopping-content').height() - 25)
                    }, 500);
                }
            });



        }

        //add ingredients to shoppinglist
        $(".recipe_shoppinglist_btn a").click(function (event) {
            event.preventDefault();
            if ($('.recipe_ingredients_input:checked').length > 0) {
                shoppingSplit = '';
                shoppingData = '';
                shoppingPreCookie = '';

                //fetch current cookie
                if ($.cookie("RGSHOPPINGLIST") === null || $.cookie("RGSHOPPINGLIST") == '') {
                    shoppingCurrentCookie = '';
                    shoppingCookie = '';
                } else {
                    shoppingCookie = String($.cookie("RGSHOPPINGLIST"));
                    shoppingSplitCookie = shoppingCookie.split(';');
                }

                //update the shoppinglist
                $('.recipe_ingredients_input:checked').each(function () {
                    shoppingSplit = $(this).val().split('|');

                    if ($('#shopping-ul').html().indexOf('ingID' + shoppingSplit[0]) != -1) {

                        shoppingSplitCookie = shoppingCookie.split(';');
                        //find where in the cookie the ingredient is
                        for (var i = 1; i < shoppingSplitCookie.length; i++) {
                            if (shoppingSplitCookie[i].indexOf(shoppingSplit[0]) != -1) {
                                var arrayRow = i;
                            }
                        }

                        //make array for new cookie
                        var arraySplit = shoppingSplitCookie[arrayRow].split('|');

                        //add the 2 ingredient amounts
                        var newAmount = Number(arraySplit[1]) + Number(shoppingSplit[1]);
                        if (newAmount == '0') {
                            newAmount = '';
                        }

                        //setup the cookie data
                        shoppingPreCookie = arraySplit[0] + '|' + newAmount + '|' + arraySplit[2] + '|' + arraySplit[3];
                        shoppingSplitCookie[arrayRow] = shoppingPreCookie;
                        shoppingCookie = shoppingSplitCookie.join(';');

                        //make the new html
                        shoppingData = '<li id="ingID' + arraySplit[0] + '">' + newAmount + ' ' + arraySplit[2] + ' ' + decodeURI(arraySplit[3]) + ' <span rel=";' + shoppingPreCookie + '" title="Fjern ' + decodeURI(arraySplit[3]) + '" class="remove"></span></li>';

                        //update the row in the ingredient list
                        $('#ingID' + arraySplit[0]).replaceWith(shoppingData);
                        $('#ingID' + arraySplit[0]).effect("pulsate", { times: 1 }, 1500);

                    } else {
                        //setup the cookie data
                        shoppingPreCookie = ';' + shoppingSplit[0] + '|' + shoppingSplit[1] + '|' + shoppingSplit[2] + '|' + encodeURI(shoppingSplit[3]);
                        shoppingCookie += shoppingPreCookie;

                        //make the html
                        shoppingData = '<li id="ingID' + shoppingSplit[0] + '">' + shoppingSplit[1] + ' ' + shoppingSplit[2] + ' ' + shoppingSplit[3] + ' <span rel="' + shoppingPreCookie + '" title="Fjern ' + shoppingSplit[3] + '" class="remove"></span></li>';

                        //update the list
                        $('#shopping-ul').append(shoppingData);

                    }
                });
                //update the cookie
                $.cookie("RGSHOPPINGLIST", shoppingCookie, { expires: 14 });

                //animate or just grow the shoppinglist
                if ($('#shopping-ul').is(':hidden')) {
                    //animate shopping list
                    $('#shopping-content').animate({
                        height: $('#shopping-ul').height()
                    }, 500, function () {
                        $('#shopping-con').toggleClass('no-ingredients');
                    });
                    setTimeout(
                $('#shopping-fold').toggleClass('folding'), 300
              );
                    $('#shopping-ul').fadeIn('slow');
                } else {
                    //animate shopping list
                    $('#shopping-content').animate({
                        height: $('#shopping-ul').height()
                    }, 500);
                }

                //reset the checked inputs
                setTimeout(
                    function () {
                        $('.recipe_ingredients_input').attr('checked', false);
                        $('.recipe_ingredients_item label').removeClass('recipe_ingredients_item_active');
                    }, 500
                );

                //clickevent for the remove button 
                $("#shopping-ul li span.remove").click(function (event) {
                    if ($.cookie("RGSHOPPINGLIST") === null) {
                        shoppingCookie = '';
                    } else {
                        shoppingCookie = String($.cookie("RGSHOPPINGLIST"));
                    }
                    shoppingCookie = shoppingCookie.replace($(this).attr('rel'), '');

                    $.cookie("RGSHOPPINGLIST", shoppingCookie, { expires: 14 });
                    $(this).parents('li').remove();
                    if ($('#shopping-ul li').length == 0) {
                        ////close the shoppinglist
                        //update the shoppinglist
                        $('#shopping-ul').fadeOut('slow');
                        $('#shopping-ul').html(' ');

                        //animate the shoppinglist
                        $('#shopping-content').animate({
                            height: '0'
                        }, 500, function () {
                            $('#shopping-con').toggleClass('no-ingredients');
                        });
                        setTimeout(
                        $('#shopping-fold').removeClass('folding'), 300
                    );
                    } else {
                        $('#shopping-content').animate({
                            height: ($('#shopping-content').height() - 25)
                        }, 500);
                    }
                });

                //trackevent via GA
                _gaq.push(['_trackEvent', 'Shopping-List', 'Add to shopping list', $('#currentProdId').html()]);
            }
        });

        $("#shopping-print-btn").click(function (event) {
            event.preventDefault();
            window.open("/btc/ShoppingListPrint.aspx?shoppingaction=print", "shoppingPopup", "location=0,menubar=0,resizable=1,width=315,height=500");
        });

        $("#shopping-email-btn").click(function (event) {
            event.preventDefault();
            window.open("/btc/ShoppingListPrint.aspx?shoppingaction=email", "shoppingPopup", "location=0,menubar=0,resizable=1,width=315,height=500");
        });


    }

    //add recipe to favorite functions
    if ($("#btn-fav-recipe").length > 0) {
        var currentRecipe = String(';' + $('.recipe_col2 h1').html() + ':' + $('#currentProdId').html());

        if ($.cookie("RGFAVRECIPE")) {
            //get cookie and see if this is a favorite
            var myCookie = String($.cookie("RGFAVRECIPE"));
            if (myCookie.indexOf(currentRecipe) != -1) {
                $('#btn-fav-recipe').addClass('added');
            }

            //update the fav-board
            var currentCookie = ($.cookie("RGFAVRECIPE")).split(';');
            var liHtml = '';
            for (var i = 1; i < currentCookie.length; i++) {
                cookieSplit = currentCookie[i].split(':');
                liHtml += '<li id="fav-' + cookieSplit[1] + '"><a href="/btc/Opskrift.aspx?ProductID=' + cookieSplit[1] + '" title="Se opskriften for ' + cookieSplit[0] + '">' + cookieSplit[0] + '</a><span class="remove" title="Fjern ' + cookieSplit[0] + '" rel=";' + cookieSplit[0] + ':' + cookieSplit[1] + '"></span></li>';
            }
            $('#favorite-ul').html(liHtml);
            if (liHtml.length > 0) {
                $('#favorite-con').removeClass('no-favorites');
            }

            //clickevent for the remove button 
            $("#favorite-ul li span.remove").click(function (event) {
                if ($.cookie("RGFAVRECIPE") === null) {
                    myCookie = '';
                } else {
                    myCookie = String($.cookie("RGFAVRECIPE"));
                }
                if ($(this).parent().find('a').html() == $('.recipe_col2 h1').html()) {
                    $('#btn-fav-recipe').removeClass('added');
                }
                myCookie = myCookie.replace($(this).attr('rel'), '');
                $.cookie("RGFAVRECIPE", myCookie, { expires: 180 });
                $(this).parents('li').remove();
                if ($('#favorite-ul li').length == 0) {
                    $('#favorite-con').addClass('no-favorites');
                }
                _gaq.push(['_trackEvent', 'Favorite-recipe', 'Remove from favorites', $('#currentProdId').html()]);
            });
        }

        //activate the click event for the add button
        $("#btn-fav-recipe a").click(function (event) {
            event.preventDefault();
            //update the cookie var and make it stringy
            if ($.cookie("RGFAVRECIPE") === null) {
                myCookie = '';
            } else {
                myCookie = String($.cookie("RGFAVRECIPE"));
            }

            //check if this is a fav recipe
            if (myCookie.indexOf(currentRecipe) != -1) {
                //if it is - then remove it from the cookie and from the fav board
                myCookie = myCookie.replace(currentRecipe, '');
                $.cookie("RGFAVRECIPE", myCookie, { expires: 180 });
                $('#btn-fav-recipe').removeClass('added');

                //which li should we remove?
                idToRemove = '#fav-' + $('#currentProdId').html();
                $(idToRemove).remove();

                //update the class for the favorite-con
                if ($('#favorite-ul li').length == 0) {
                    $('#favorite-con').addClass('no-favorites');
                }
                _gaq.push(['_trackEvent', 'Favorite-recipe', 'Remove from favorites', $('#currentProdId').html()]);
            } else {
                //else add the recipe to the cookie
                myCookie += currentRecipe;
                $('#btn-fav-recipe').addClass('added');
                $('#favorite-con').removeClass('no-favorites');
                $.cookie("RGFAVRECIPE", myCookie, { expires: 180 });

                //update the fav-board
                var currentCookie = ($.cookie("RGFAVRECIPE")).split(';');
                var liHtml = '';
                for (var i = 1; i < currentCookie.length; i++) {
                    cookieSplit = currentCookie[i].split(':');
                    liHtml += '<li id="fav-' + cookieSplit[1] + '"><a href="/btc/Opskrift.aspx?ProductID=' + cookieSplit[1] + '" title="Se opskriften for ' + cookieSplit[0] + '">' + cookieSplit[0] + '</a><span class="remove" title="Fjern ' + cookieSplit[0] + '" rel=";' + cookieSplit[0] + ':' + cookieSplit[1] + '"></span></li>';
                }
                $('#favorite-ul').html(liHtml);
                if (liHtml.length > 0) {
                    $('#favorite-con').removeClass('no-favorites');
                }
                //clickevent for the remove button 
                $("#favorite-ul li span.remove").click(function (event) {
                    if ($.cookie("RGFAVRECIPE") === null) {
                        myCookie = '';
                    } else {
                        myCookie = String($.cookie("RGFAVRECIPE"));
                    }
                    if ($(this).parent().find('a').html() == $('.recipe_col2 h1').html()) {
                        $('#btn-fav-recipe').removeClass('added');
                    }
                    myCookie = myCookie.replace($(this).attr('rel'), '');
                    $.cookie("RGFAVRECIPE", myCookie, { expires: 180 });
                    $(this).parents('li').remove();
                    if ($('#favorite-ul li').length == 0) {
                        $('#favorite-con').addClass('no-favorites');
                    }
                    _gaq.push(['_trackEvent', 'Favorite-recipe', 'Remove from favorites', $('#currentProdId').html()]);
                });
                _gaq.push(['_trackEvent', 'Favorite-recipe', 'Add to favorites', $('#currentProdId').html()]);
            }
        });
    }

    //recipe comment validate
    if ($("#FormSave3").length > 0) {
        //set the captcha word
        Keywordarray = new Array(5);
        Keywordarray[0] = "rejer";
        Keywordarray[1] = "torsk";
        Keywordarray[2] = "hummer";
        Keywordarray[3] = "laks";
        Keywordarray[4] = "hellefisk";
        randno = Math.floor(Math.random() * Keywordarray.length);
        captchaWord = Keywordarray[randno];
        $('#captcha_word').html(captchaWord);

        // auto clear of field
        $('#RecipeCommentTable_RecipeCommentName,#RecipeCommentTable_RecipeCommentText').each(function () {
            var default_value = this.value;
            $(this).focus(function () {
                if (this.value == default_value) {
                    this.value = '';
                }
            });
            $(this).blur(function () {
                if (this.value == '') {
                    this.value = default_value;
                }
            });
        });

        //activate the close validation buttons
        $('.recipe_comment_validation_close').click(function () { $(this).parent().css("display", "none") });

        //set the validation on the form 
        $("#FormSave3").submit(function () {
            formValidName = false;
            formValidText = false;

            if ($("#RecipeCommentTable_RecipeCommentName").val() != "Skriv dit navn..." && $("#RecipeCommentTable_RecipeCommentName").val() != "") {
                $('#recipe_comment_validation_name').css('display', 'none');
                formValidName = true;
            } else {
                $('#recipe_comment_validation_name').css('display', 'block');
                formValidName = false;
            }

            if ($("#RecipeCommentTable_RecipeCommentText").val() != "Skriv dine kommentarer her..." && $("#RecipeCommentTable_RecipeCommentText").val() != "") {
                $('#recipe_comment_validation_text').css('display', 'none');
                formValidText = true;
            } else {
                $('#recipe_comment_validation_text').css('display', 'block');
                formValidText = false;
            }

            if ($('#recipe_comment_captcha').val() == captchaWord) {
                $('#recipe_comment_validation_captcha').css('display', 'none');
                formValidCaptcha = true;
            } else {
                $('#recipe_comment_validation_captcha').css('display', 'block');
                formValidCaptcha = false;
            }

            if (formValidName == true && formValidText == true && formValidCaptcha == true && $("#recipe_comment_validation_value").val() == '') {
                return true;
            } else {
                return false;
            }

        });

    }

    //sms competition validate
    if ($("#FormSave5").length > 0) {

        //set the smskeyword word
        smsKeyword = new Array("35kd67", "24pk68", "87ad45", "23rt87", "28vb56", "98ty42", "45vu32", "34qb78", "56yt74", "48we79");

        //activate the close validation buttons
        $('.smscomp_validation_close').click(function () { $(this).parent().css("display", "none") });

        //activate the click for smskeyword
        $('.smscomp_text a').click(function () {
            testValue = String($('#smskeyword_input').val());
            if (($.inArray(testValue, smsKeyword)) >= 0) {
                $('#smscomp_validation_keyword').css('display', 'none');
                $('.smscomp_text a').unbind('click');
                $('#smskeyword_input').attr('disabled', true);
                $("#smscomp_validation_value").val('');
                $('.smscomp_form').fadeIn();
            } else {
                $('#smscomp_validation_keyword').css('display', 'block');
            }
        });

        // auto clear of field
        $('#smsCompetition_Navn,#smsCompetition_Email,#smsCompetition_Phone').each(function () {
            var default_value = this.value;
            $(this).focus(function () {
                if (this.value == default_value) {
                    this.value = '';
                }
            });
            $(this).blur(function () {
                if (this.value == '') {
                    this.value = default_value;
                }
            });
        });

        //set the validation on the form 
        $("#FormSave5").submit(function () {
            formValidName = false;
            formValidEmail = false;
            formValidPhone = false;

            if ($("#smsCompetition_Navn").val() != "Skriv dit navn..." && $("#smsCompetition_Navn").val() != "") {
                $('#smscomp_validation_name').css('display', 'none');
                formValidName = true;
            } else {
                $('#smscomp_validation_name').css('display', 'block');
                formValidName = false;
            }
            if ($("#smsCompetition_Email").val() != "Skriv din e-mail..." && $("#smsCompetition_Email").val() != "") {
                $('#smscomp_validation_email').css('display', 'none');
                formValidEmail = true;
            } else {
                $('#smscomp_validation_email').css('display', 'block');
                formValidEmail = false;
            }
            if ($("#smsCompetition_Phone").val() != "Skriv dit tlf./mobil nummer..." && $("#smsCompetition_Phone").val() != "") {
                $('#smscomp_validation_phone').css('display', 'none');
                formValidPhone = true;
            } else {
                $('#smscomp_validation_phone').css('display', 'block');
                formValidPhone = false;
            }
            if (formValidName == true && formValidEmail == true && formValidPhone == true && $("#smscomp_validation_value").val() == '') {
                return true;
            } else {
                return false;
            }

        });

    }


    //competition2 validate
    if ($("#FormSave9").length > 0) {

        //activate the close validation buttons
        $('.comp_validation_close').click(function () { $(this).parent().css("display", "none") });

        // auto clear of field
        $('#Competition2_Name,#Competition2_Email,#Competition2_phone').each(function () {
            var default_value = this.value;
            $(this).focus(function () {
                if (this.value == default_value) {
                    this.value = '';
                }
            });
            $(this).blur(function () {
                if (this.value == '') {
                    this.value = default_value;
                }
            });
        });

        //set the validation on the form 
        $("#FormSave9").submit(function () {
            formValidName = false;
            formValidEmail = false;
            formValidPhone = false;
            formValidQuestion = false;

            if ($("#Competition2_Name").val() != "Skriv dit navn..." && $("#Competition2_Name").val() != "") {
                $('#comp_validation_name').css('display', 'none');
                formValidName = true;
            } else {
                $('#comp_validation_name').css('display', 'block');
                formValidName = false;
            }
            if ($("#Competition2_Email").val() != "Skriv din e-mail..." && $("#Competition2_Email").val() != "") {
                $('#comp_validation_email').css('display', 'none');
                formValidEmail = true;
            } else {
                $('#comp_validation_email').css('display', 'block');
                formValidEmail = false;
            }
            if ($("#Competition2_phone").val() != "Skriv dit tlf./mobil nummer..." && $("#Competition2_phone").val() != "") {
                $('#comp_validation_phone').css('display', 'none');
                formValidPhone = true;
            } else {
                $('#comp_validation_phone').css('display', 'block');
                formValidPhone = false;
            }
            if ($("input[@name='Competition2_Question1']:checked").length > 0) {
                $('#comp_validation_question').css('display', 'none');
                formValidQuestion = true;
            } else {
                $('#comp_validation_question').css('display', 'block');
                formValidQuestion = false;
            }
            if ($("input[@name='Competition2_Question2']:checked").length > 0) {
                $('#comp_validation_question2').css('display', 'none');
                formValidQuestion2 = true;
            } else {
                $('#comp_validation_question2').css('display', 'block');
                formValidQuestion2 = false;
            }

            if (formValidName == true && formValidEmail == true && formValidPhone == true && formValidQuestion == true && formValidQuestion2 == true) {
                return true;
            } else {
                return false;
            }

        });

    }


    //competition3 validate
    if ($("#FormSave10").length > 0) {

        //activate the close validation buttons
        $('.comp_validation_close').click(function () { $(this).parent().css("display", "none") });

        // auto clear of field
        $('#Competition3_Name,#Competition3_email,#Competition3_phone').each(function () {
            var default_value = this.value;
            $(this).focus(function () {
                if (this.value == default_value) {
                    this.value = '';
                }
            });
            $(this).blur(function () {
                if (this.value == '') {
                    this.value = default_value;
                }
            });
        });

        //set the validation on the form 
        $("#FormSave10").submit(function () {
            formValidName = false;
            formValidEmail = false;
            formValidPhone = false;
            formValidQuestion = false;

            if ($("#Competition3_Name").val() != "Skriv dit navn..." && $("#Competition3_Name").val() != "") {
                $('#comp_validation_name').css('display', 'none');
                formValidName = true;
            } else {
                $('#comp_validation_name').css('display', 'block');
                formValidName = false;
            }
            if ($("#Competition3_email").val() != "Skriv din e-mail..." && $("#Competition3_Email").val() != "") {
                $('#comp_validation_email').css('display', 'none');
                formValidEmail = true;
            } else {
                $('#comp_validation_email').css('display', 'block');
                formValidEmail = false;
            }
            if ($("#Competition3_phone").val() != "Skriv dit tlf./mobil nummer..." && $("#Competition3_phone").val() != "") {
                $('#comp_validation_phone').css('display', 'none');
                formValidPhone = true;
            } else {
                $('#comp_validation_phone').css('display', 'block');
                formValidPhone = false;
            }
            if ($("input[@name='Competition3_Question']:checked").length > 0) {
                $('#comp_validation_question').css('display', 'none');
                formValidQuestion = true;
            } else {
                $('#comp_validation_question').css('display', 'block');
                formValidQuestion = false;
            }

            if (formValidName == true && formValidEmail == true && formValidPhone == true && formValidQuestion == true) {
                return true;
            } else {
                return false;
            }

        });

    }

    //competition4 validate
    if ($("#FormSave11").length > 0) {

        //activate the close validation buttons
        $('.comp_validation_close').click(function () { $(this).parent().css("display", "none") });

        // auto clear of field
        $('#Competition4_name,#Competition4_email,#Competition4_phone').each(function () {
            var default_value = this.value;
            $(this).focus(function () {
                if (this.value == default_value) {
                    this.value = '';
                }
            });
            $(this).blur(function () {
                if (this.value == '') {
                    this.value = default_value;
                }
            });
        });

        //set the validation on the form 
        $("#FormSave11").submit(function () {
            formValidName = false;
            formValidEmail = false;
            formValidPhone = false;
            formValidQuestion = false;

            if ($("#Competition4_name").val() != "Skriv dit navn..." && $("#Competition4_name").val() != "") {
                $('#comp_validation_name').css('display', 'none');
                formValidName = true;
            } else {
                $('#comp_validation_name').css('display', 'block');
                formValidName = false;
            }
            if ($("#Competition4_email").val() != "Skriv din e-mail..." && $("#Competition4_email").val() != "") {
                $('#comp_validation_email').css('display', 'none');
                formValidEmail = true;
            } else {
                $('#comp_validation_email').css('display', 'block');
                formValidEmail = false;
            }
            if ($("#Competition4_phone").val() != "Skriv dit tlf./mobil nummer..." && $("#Competition4_phone").val() != "") {
                $('#comp_validation_phone').css('display', 'none');
                formValidPhone = true;
            } else {
                $('#comp_validation_phone').css('display', 'block');
                formValidPhone = false;
            }
            if ($("input[@name='Competition4_question']:checked").length > 0) {
                $('#comp_validation_question').css('display', 'none');
                formValidQuestion = true;
            } else {
                $('#comp_validation_question').css('display', 'block');
                formValidQuestion = false;
            }

            if (formValidName == true && formValidEmail == true && formValidPhone == true && formValidQuestion == true) {
                return true;
            } else {
                return false;
            }

        });

    }

    //competition5 validate
    if ($("#FormSave12").length > 0) {
        //activate the close validation buttons
        $('.comp_validation_close').click(function () { $(this).parent().css("display", "none") });

        // auto clear of field
        $('#Competition5_name,#Competition5_email,#Competition5_phone').each(function () {
            var default_value = this.value;
            $(this).focus(function () {
                if (this.value == default_value) {
                    this.value = '';
                }
            });
            $(this).blur(function () {
                if (this.value == '') {
                    this.value = default_value;
                }
            });
        });

        //set the validation on the form 
        $("#FormSave12").submit(function () {
            formValidName = false;
            formValidEmail = false;
            formValidPhone = false;
            formValidQuestion = false;

            if ($("#Competition5_name").val() != "Skriv dit navn..." && $("#Competition5_name").val() != "") {
                $('#comp_validation_name').css('display', 'none');
                formValidName = true;
            } else {
                $('#comp_validation_name').css('display', 'block');
                formValidName = false;
            }
            if ($("#Competition5_email").val() != "Skriv din e-mail..." && validateEmail($("#Competition5_email").val())) {
                $('#comp_validation_email').css('display', 'none');
                formValidEmail = true;
            } else {
                $('#comp_validation_email').css('display', 'block');
                formValidEmail = false;
            }
            if ($("#Competition5_phone").val() != "Skriv dit tlf./mobil nummer..." && $("#Competition5_phone").val() != "") {
                $('#comp_validation_phone').css('display', 'none');
                formValidPhone = true;
            } else {
                $('#comp_validation_phone').css('display', 'block');
                formValidPhone = false;
            }
            if ($("input[@name='Competition5_question']:checked").length > 0) {
                $('#comp_validation_question').css('display', 'none');
                formValidQuestion = true;
            } else {
                $('#comp_validation_question').css('display', 'block');
                formValidQuestion = false;
            }

            if (formValidName == true && formValidEmail == true && formValidPhone == true && formValidQuestion == true) {
                return true;
            } else {
                return false;
            }

        });

    }
  
  //competition5 validate
    if ($("#FormSave13").length > 0) {
        //activate the close validation buttons
        $('.comp_validation_close').click(function () { $(this).parent().css("display", "none") });

        // auto clear of field
        $('#Competition6_name,#Competition6_email,#Competition6_phone').each(function () {
            var default_value = this.value;
            $(this).focus(function () {
                if (this.value == default_value) {
                    this.value = '';
                }
            });
            $(this).blur(function () {
                if (this.value == '') {
                    this.value = default_value;
                }
            });
        });

        //set the validation on the form 
        $("#FormSave13").submit(function () {
            formValidName = false;
            formValidEmail = false;
            formValidPhone = false;
            formValidQuestion = false;

            if ($("#Competition6_name").val() != "Skriv dit navn..." && $("#Competition6_name").val() != "") {
                $('#comp_validation_name').css('display', 'none');
                formValidName = true;
            } else {
                $('#comp_validation_name').css('display', 'block');
                formValidName = false;
            }
            if ($("#Competition6_email").val() != "Skriv din e-mail..." && validateEmail($("#Competition6_email").val())) {
                $('#comp_validation_email').css('display', 'none');
                formValidEmail = true;
            } else {
                $('#comp_validation_email').css('display', 'block');
                formValidEmail = false;
            }
            if ($("#Competition6_phone").val() != "Skriv dit tlf./mobil nummer..." && $("#Competition6_phone").val() != "") {
                $('#comp_validation_phone').css('display', 'none');
                formValidPhone = true;
            } else {
                $('#comp_validation_phone').css('display', 'block');
                formValidPhone = false;
            }
            if ($("input[@name='Competition6_question']:checked").length > 0) {
                $('#comp_validation_question').css('display', 'none');
                formValidQuestion = true;
            } else {
                $('#comp_validation_question').css('display', 'block');
                formValidQuestion = false;
            }

            if (formValidName == true && formValidEmail == true && formValidPhone == true && formValidQuestion == true) {
                return true;
            } else {
                return false;
            }

        });

    }

    //competition7 validate
    if ($("#FormSave14").length > 0) {
        //activate the close validation buttons
        $('.comp_validation_close').click(function () { $(this).parent().css("display", "none") });

        // auto clear of field
        $('#Competition7_Navn,#Competition7_email,#Competition7_phone').each(function () {
            var default_value = this.value;
            $(this).focus(function () {
                if (this.value == default_value) {
                    this.value = '';
                }
            });
            $(this).blur(function () {
                if (this.value == '') {
                    this.value = default_value;
                }
            });
        });

        //set the validation on the form 
        $("#FormSave14").submit(function () {
            formValidName = false;
            formValidEmail = false;
            formValidPhone = false;
            formValidQuestion = false;

            if ($("#Competition7_Navn").val() != "Skriv dit navn..." && $("#Competition7_Navn").val() != "") {
                $('#comp_validation_name').css('display', 'none');
                formValidName = true;
            } else {
                $('#comp_validation_name').css('display', 'block');
                formValidName = false;
            }
            if ($("#Competition7_email").val() != "Skriv din e-mail..." && validateEmail($("#Competition7_email").val())) {
                $('#comp_validation_email').css('display', 'none');
                formValidEmail = true;
            } else {
                $('#comp_validation_email').css('display', 'block');
                formValidEmail = false;
            }
            if ($("#Competition7_phone").val() != "Skriv dit tlf./mobil nummer..." && $("#Competition7_phone").val() != "") {
                $('#comp_validation_phone').css('display', 'none');
                formValidPhone = true;
            } else {
                $('#comp_validation_phone').css('display', 'block');
                formValidPhone = false;
            }
            if ($("input[@name='Competition7_Question']:checked").length > 0) {
                $('#comp_validation_question').css('display', 'none');
                formValidQuestion = true;
            } else {
                $('#comp_validation_question').css('display', 'block');
                formValidQuestion = false;
            }

            if (formValidName == true && formValidEmail == true && formValidPhone == true && formValidQuestion == true) {
                return true;
            } else {
                return false;
            }

        });

    }

  
});

function validateEmail(email) {
    var regex = new RegExp(/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i);
    if (email.match(regex)) {
        return true;
    } else {        
        return false;
    }
}
