$(document).ready(function () {
    var className;
    $('#divremarks1').hover(
        function () {
            /*if ($('#divremarks1').css('background-color') == 'rgb(123, 214, 41)') {*/
            $('#firmaOversikt_popRemarksDiv1').show();
            /*}*/
        }, function () {
            $('#firmaOversikt_popRemarksDiv1').hide();
        });
    $('#divremarks2').hover(
        function () {
            /*if ($('#divremarks1').css('background-color') == 'rgb(123, 214, 41)') {*/
            $('#firmaOversikt_popRemarksDiv2').show();
            /*}*/
        }, function () {
            $('#firmaOversikt_popRemarksDiv2').hide();
        });
    $('#CreditInfo_lagDivButton').click(function () {
        $('#CreditInfo_lagDiv').css('left', ($('#CreditInfo_lagDivButton').position().left - 181));
        $('#CreditInfo_lagDiv').css('top', ($('#CreditInfo_lagDivButton').position().top + 10));
        $('#CreditInfo_lagDiv').css('zIndex', (parseInt($('#CreditInfo_lagDiv').css('zIndex')) + 1));
        $('#CreditInfo_lagDiv').css('display', 'block');
    });
    $('#CreditInfo_showHentDiv').click(function () {
        $('#hentDiv').css('left', ($('#CreditInfo_showHentDiv').position().left - 215));
        $('#hentDiv').css('top', ($('#CreditInfo_showHentDiv').position().top - 50));
        $('#hentDiv').css('zIndex', (parseInt($('#hentDiv').css('zIndex')) + 1));
        $('#hentDiv').css('display', 'block');
    });

    $('#sokestreng').focus(function () { $('#btnA').removeClass(); $('#btnA').addClass('focusedBtn'); });
    $('#sokestreng').focusout(function () { $('#btnA').removeClass(); $('#btnA').addClass('btn'); });
    $('#btnA').hover(function () { className = $('#btnA').attr('class'); $('#btnA').removeClass(); $('#btnA').addClass('hoverBtn'); }, function () { $('#btnA').removeClass(); $('#btnA').addClass(className); }).click(function () { $('#btnA').removeClass(); $('#btnA').addClass('activeBtn'); });

    //if ($('[id^=kategoriGrid_kategoriLagreBtn]').attr('class') != 'inactiveBtn' && $('[id^=kategoriGrid_kategoriLagreBtn]').attr('class') != 'aspNetDisabled inactiveBtn')
    //$('[id^=kategoriGrid_kategoriLagreBtn]:not([class^="aspNetDisabled"])').hover(function () { $(this).removeClass(); $(this).addClass('hoverBtn'); }, function () { $(this).removeClass(); $(this).addClass('btn'); }).click(function () { $(this).removeClass(); $(this).addClass('activeBtn'); }).focus(function () { $(this).removeClass(); $(this).addClass('focusedBtn'); }).focusout(function () { $(this).removeClass(); $(this).addClass('btn'); });
    $('a[class="btn"]').hover(function () { $(this).removeClass(); $(this).addClass('hoverBtn'); }, function () { $(this).removeClass(); $(this).addClass('btn'); }).click(function () { $(this).removeClass(); $(this).addClass('activeBtn'); }).focus(function () { $(this).removeClass(); $(this).addClass('focusedBtn'); }).focusout(function () { $(this).removeClass(); $(this).addClass('btn'); });

    if ($('input[type="button"]').attr('class') != 'datepick-trigger') {
        $('input[type="button"]').attr('class', 'inputNormal');
        $('input[type="button"]').focus(function () { $(this).removeClass(); $(this).addClass('inputFocus'); });
        $('input[type="button"]').focusout(function () { $(this).removeClass(); $(this).addClass('inputNormal'); });
        $('input[type="button"]').hover(function () { $(this).removeClass(); $(this).addClass('inputHover'); }, function () { $(this).removeClass(); $(this).addClass('inputNormal'); }).click(function () { $(this).removeClass(); $(this).addClass('inputActive'); });
    }

    $('input[type="submit"]').attr('class', 'inputNormal');
    $('input[type="submit"]').focus(function () { $(this).removeClass(); $(this).addClass('inputFocus'); });
    $('input[type="submit"]').focusout(function () { $(this).removeClass(); $(this).addClass('inputNormal'); });
    $('input[type="submit"]').hover(function () { $(this).removeClass(); $(this).addClass('inputHover'); }, function () { $(this).removeClass(); $(this).addClass('inputNormal'); }).click(function () { $(this).removeClass(); $(this).addClass('inputActive'); });

    $('a[id^=sokeResultat_foretakInfoGrid_resultatGrid_flereRollerTooltipLnk]').hover(function () { $('#all_roles').show(); }, function () { $('#all_roles').hide(); });

    $('a[id^=kalender_maanedUke]').hover(
        function () {
            var s = this.id;
            var week = s.substr(18, 1);
            var day = s.substr(22, 1);
            $('#kalender_maanedUke' + week + 'Dag' + day + '_meetingsDiv').show();
        }, function () {
            var s = this.id;
            var week = s.substr(18, 1);
            var day = s.substr(22, 1);
            $('#kalender_maanedUke' + week + 'Dag' + day + '_meetingsDiv').hide();
        });
    $("a[id^=kalender_maanedUke]").click(function () {
        var url = document.location.href;
        var dateParam = "";
        if (this.id.toString().indexOf("moreMeetingLnk") > 0) {
            $("#kalender_calendarModeLst_2").attr("checked", "checked");
            $("#kalender_calendarModeLst_0").removeAttr("checked");

            var s = this.id.toString();
            s = s.replace("moreMeetingLnk", "dateInput");
            var date = $('#' + s).attr("value").replace(new RegExp(/[^0-9]/g), "");
            if (date.length < 6) date = "0" + date;
            var realdate = date.substr(0, 4) + "20" + date.substr(4, 2);

            if (url.indexOf("?meetingsdate") > 0) {
                dateParam = url.substr(url.indexOf("?meetingsdate"), 22);
                url = url.replace(dateParam, "");
            }
            if (url.indexOf("&meetingsdate") > 0) {
                dateParam = url.substr(url.indexOf("&meetingsdate"), 22);
                url = url.replace(dateParam, "");
            }
            if (url.indexOf("mode=") > 0) {
                dateParam = url.substr(url.indexOf("mode="), 6);
                url = url.replace(dateParam, "mode=D");
            }
            window.location = url.indexOf("?") > 0 ? url + "&meetingsdate=" + realdate : url + "?meetingsdate=" + realdate;
        }
        else {
            if (url.indexOf("?meetingsdate") > 0) {
                dateParam = url.substr(url.indexOf("?meetingsdate"), 22);
                url = url.replace(dateParam, "");
            }
            if (url.indexOf("&meetingsdate") > 0) {
                dateParam = url.substr(url.indexOf("&meetingsdate"), 22);
                url = url.replace(dateParam, "");
            }
            window.location = url;
        }
    })

    $('table.infogrid tr.infogriditem td').removeClass();
    $('table.infogrid tr.infogriditem td').addClass("infogriditem");
    $('table.infogrid tr.infogridaltitem td').removeClass();
    $('table.infogrid tr.infogridaltitem td').addClass("infogridaltitem");

    $('table.gridnolinesnoheader tr.gridnolinesitem').children('td').css('border', '0 none');
    $('table.gridnolinesnoheader tr.gridnolinesaltitem').children('td').css('border', '0 none');
    $('table.gridnolines tr.gridnolinesitem').children('td').css('border', '0 none');
    $('table.gridnolines tr.gridnolinesaltitem').children('td').css('border', '0 none');
    $('table.grid tr.gridnolinesitem').children('td').css('border', '0 none');
    $('table.grid tr.gridnolinesaltitem').children('td').css('border', '0 none');

    $(".ie6topmenufirstchild").hover
                    (
                        function () {
                            $(this).removeClass();
                            $(this).addClass("ie6topmenufirstchildhover");
                        },
                        function () {
                            $(this).removeClass("ie6topmenufirstchildhover");
                            $(this).addClass("ie6topmenufirstchild");
                        }
                    );
    $("li a.topMenuNormal").hover
    (
    function () {
        $(this).removeClass("topMenuNormal");
        $(this).addClass("topMenuHover");
    },
    function () {
        $(this).removeClass("topMenuHover");
        $(this).addClass("topMenuNormal");
    }
    );
    $("ul#main-menu li.topMenuNormal").hover
                    (
                        function () {
                            $(this).children('div').children('div').show();
                        },
                        function () {
                            $(this).children('div').children('div:not([class^="header"])').hide();
                        }
                    );
    $('#main-menu .vert-menu-dd ul.treeview span a').hover
    (
                        function () {
                            $(this).removeClass();
                            $(this).addClass("hover");
                        },
                        function () {
                            $(this).removeClass();
                        }
    );
    $(".pane").hover
                    (
                        function () {
                            $(this).removeClass("pane");
                            $(this).addClass("paneHover");
                        },
                        function () {
                            $(this).removeClass("paneHover");
                            $(this).addClass("pane");
                        }
                    );
    $(".subpane").hover
                    (
                        function () {
                            $(this).removeClass("subpane");
                            $(this).addClass("subpaneHover");
                        },
                        function () {
                            $(this).removeClass("subpaneHover");
                            $(this).addClass("subpane");
                        }
                    );
    $("table.grid tr th").hover
    (
                        function () {
                            className = $(this).closest('tr').attr("class");
                            $(this).removeClass();
                            if (className == "gridheader")
                                $(this).addClass("overheader");
                            else if (className == "gridheader2")
                                $(this).addClass("overheader2");
                        },
                        function () {
                            $(this).removeClass();
                            $(this).addClass(className);
                        }
    );
    $("table.sgTbl tr th").hover
    (
                        function () {
                            className = $(this).closest('tr').attr("class");
                            $(this).removeClass();
                            if (className == "gridheader")
                                $(this).addClass("overheader");
                            else if (className == "gridheader2")
                                $(this).addClass("overheader2");
                        },
                        function () {
                            $(this).removeClass();
                            $(this).addClass(className);
                        }
    );
    $("table.gridnolines tr th").hover
    (
                        function () {
                            className = $(this).closest('tr').attr("class");

                            $(this).removeClass();
                            if (className == "gridheader")
                                $(this).addClass("overheader");
                            else if (className == "gridheader2")
                                $(this).addClass("overheader2");
                        },
                        function () {
                            $(this).removeClass();
                            $(this).addClass(className);
                        }
    );
    $("table.grid tr:first td a text").hover
                    (
                        function () {
                            className = $(this).attr("class");
                            $(this).removeClass();
                            //$(this).removeClass("gridheader");
                            if (className == "gridheader")
                                $(this).addClass("overheader");
                            else if (className == "gridheader2")
                                $(this).addClass("overheader2");
                        },
                        function () {
                            $(this).removeClass();
                            $(this).addClass(className);
                            /*$(this).removeClass("overheader");
                            $(this).addClass("gridheader");*/
                        }
                    );
    $("div.gridheader").hover
                    (
                        function () {
                            alert("div.gridheader");
                            className = $(this).attr("class");
                            $(this).removeClass();
                            if (className == "gridheader")
                                $(this).addClass("overheader");
                            else if (className == "gridheader2")
                                $(this).addClass("overheader2");
                        },
                        function () {
                            $(this).removeClass();
                            $(this).addClass(className);
                        }
                    );
    $("table#konsernstrukturGrid tr:first td").hover
                    (
                        function () {
                            $(this).removeClass();
                            $(this).addClass("overheader");
                        },
                        function () {
                            $(this).removeClass();
                            $(this).addClass("treeheader");
                        }
                    );
    $("table.gridnolines tr:first td").hover
                    (
                        function () {
                            className = $(this).attr("class");
                            $(this).removeClass();
                            if (className == "gridheader")
                                $(this).addClass("overheader");
                            else if (className == "gridheader2")
                                $(this).addClass("overheader2");
                        },
                        function () {
                            $(this).removeClass();
                            $(this).addClass(className);
                        }
                    );
    $("table#firmaKontakterGrid tr:first td").hover
                    (
                        function () {
                            $(this).removeClass("gridheader93");
                            $(this).addClass("overheader");
                        },
                        function () {
                            $(this).removeClass("overheader");
                            $(this).removeClass("gridheader");
                            $(this).addClass("gridheader93");
                        }
                    );
    /*$("input:checkbox").hover
    (
    function () {
    $(this).parents("span").removeClass("checkboxInvisibleFrame");
    $(this).parents("span").addClass("checkboxFrameHover");
    },
    function () {
    $(this).parents("span").removeClass("checkboxFrameHover");
    $(this).parents("span").addClass("checkboxInvisibleFrame");
    }
    );*/
    $("table.resultgrid tr:not(:first):odd").mouseover
                    (
                        function () {
                            className = $(this).attr("class");
                            $(this).removeClass();
                            $(this).addClass("over");
                        }
                    ).mouseout
                    (
                        function () {
                            $(this).removeClass("over");
                            $(this).addClass(className);
                        }
                    );
    $("table.resultgrid tr:not(:first):even").mouseover
                    (
                        function () {
                            className = $(this).attr("class");
                            $(this).removeClass();
                            $(this).addClass("over");
                        }
                    ).mouseout
                    (
                        function () {
                            $(this).removeClass("over");
                            $(this).addClass(className);
                        }
                    );
    $('table.gridnolines:not(#mfLayoutBrukerGrid) tbody tr:odd:not([class^="gridheader"])').mouseover
                    (
                        function () {
                            className = $(this).attr("class");
                            if ($(this).closest('table').attr("class").match(/\bgrid/)) {
                                $(this).removeClass();
                                if (className == "gridselecteditem")
                                    $(this).addClass("gridselecteditemhover");
                                else if (className == "griditem" || className == "gridaltitem")
                                    $(this).addClass("overwithlines");
                                else if (className == "gridnolinesitem" || className == "gridnolinesaltitem")
                                    $(this).addClass("over");
                            }
                        }
                    ).mouseout
                    (
                        function () {
                            if ($(this).closest('table').attr("class").match(/\bgrid/)) {
                                $(this).removeClass();
                                $(this).addClass(className);
                            }
                            /*if ($(this).closest('table').find('th').length > 0) {
                            $(this).addClass("gridnolinesaltitem");
                            } else {
                            $(this).addClass("gridnolinesitem");
                            }*/
                        }
                    );
    $('table.gridnolines:not(#mfLayoutBrukerGrid) tbody tr:even:not([class^="gridheader"])').mouseover
                    (
                        function () {
                            className = $(this).attr("class");
                            if ($(this).closest('table').attr("class").match(/\bgrid/)) {
                                $(this).removeClass();
                                if (className == "gridselecteditem")
                                    $(this).addClass("gridselecteditemhover");
                                else if (className == "griditem" || className == "gridaltitem")
                                    $(this).addClass("overwithlines");
                                else if (className == "gridnolinesitem" || className == "gridnolinesaltitem")
                                    $(this).addClass("over");
                            }
                        }
                    ).mouseout
                    (
                        function () {
                            if ($(this).closest('table').attr("class").match(/\bgrid/)) {
                                $(this).removeClass();
                                $(this).addClass(className);
                            }
                        }
                    );
    $("table.grid:not(#mfLayoutTbl) tbody tr:odd:not(.gridheader)").mouseover
                    (
                        function () {
                            className = $(this).attr("class");
                            if ($(this).closest('table').attr("class").match(/\bgrid/)) {
                                $(this).removeClass();
                                if (className == "gridselecteditem")
                                    $(this).addClass("gridselecteditemhover");
                                else if (className == "griditem" || className == "gridaltitem")
                                    $(this).addClass("overwithlines");
                                else if (className == "gridnolinesitem" || className == "gridnolinesaltitem")
                                    $(this).addClass("over");
                            }
                        }
                    ).mouseout
                    (
                        function () {
                            if ($(this).closest('table').attr("class").match(/\bgrid/)) {
                                $(this).removeClass();
                                $(this).addClass(className);
                            }
                        }
                    );
    $("table.grid:not(#mfLayoutTbl) tbody tr:even:not(.gridheader)").mouseover
                    (
                        function () {
                            className = $(this).attr("class");
                            if ($(this).closest('table').attr("class").match(/\bgrid/)) {
                                $(this).removeClass();
                                if (className == "gridselecteditem")
                                    $(this).addClass("gridselecteditemhover");
                                else if (className == "griditem" || className == "gridaltitem")
                                    $(this).addClass("overwithlines");
                                else if (className == "gridnolinesitem" || className == "gridnolinesaltitem")
                                    $(this).addClass("over");
                            }
                        }
                    ).mouseout
                    (
                        function () {
                            if ($(this).closest('table').attr("class").match(/\bgrid/)) {
                                $(this).removeClass();
                                $(this).addClass(className);
                            }
                        }
                    );
    $("table.gridnolinesnoheader tbody tr:odd:not(.gridheader)").mouseover
                    (
                        function () {
                            className = $(this).attr("class");
                            $(this).removeClass();
                            $(this).addClass("over");
                        }
                    ).mouseout
                    (
                        function () {
                            $(this).removeClass("over");
                            $(this).addClass(className);
                        }
                    );
    $("table.gridnolinesnoheader tbody tr:even:not(.gridheader)").mouseover
                    (
                        function () {
                            className = $(this).attr("class");
                            $(this).removeClass();
                            $(this).addClass("over");
                        }
                    ).mouseout
                    (
                        function () {
                            $(this).removeClass("over");
                            $(this).addClass(className);
                        }
                    );

    /*******modal free user page********/

    $(function () {

        $("#dialog:ui-dialog").dialog("destroy");

        var bedrift = $("#bedrift"),
            fornavn = $("#fornavn"),
            etternavn = $("#etternavn"),
            epost = $("#epost"),
            mobil = $("#mobil"),
            isSO = $("#isSO"),
        //drop = $("#drop"),
        //isprivat = $("#kontaktTypeLst1"),
        //iscompany = $("#kontaktTypeLst2"),
        //terms = $("#terms"),
			allFields = $([]).add(bedrift).add(fornavn).add(etternavn).add(epost).add(mobil).add(isSO)/*.add(drop).add(isprivat).add(iscompany).add(terms)*/,
			tips = $(".validateTips");

        function updateTips(t) {
            tips
				.text(t)
				.addClass("ui-state-highlight");
            setTimeout(function () {
                tips.removeClass("ui-state-highlight", 1500);
            }, 500);
        }

        function checkLength(o, n, min, max) {
            if (o.val().length > max || o.val().length < min) {
                o.addClass("ui-state-error");
                updateTips(n + " m\u00E5 best\u00E5 av minst " + min + " og ikke flere enn " + max + " tegn.");
                return false;
            } else {
                return true;
            }
        }

        /*function checkTerms(o) {
        if (o.is(':checked') == false) {
        o.addClass("ui-state-error");
        updateTips("You must accept the terms and conditions.");
        return false;
        } else {
        return true;
        }
        }*/

        function checkCompanyEditVsRadio() {
            if ($('#madatoryCompanyField').css("display") != "none" && bedrift.val().length < 2) {
                bedrift.addClass("ui-state-error");
                updateTips("Firmanavn m\u00E5 best\u00E5 av minst 2 tegn.");
                return false;
            } else {
                return true;
            }
        }

        function checkRegexp(o, regexp, n) {
            if (!(regexp.test(o.val()))) {
                o.addClass("ui-state-error");
                updateTips(n);
                return false;
            } else {
                return true;
            }
        }

        $("#dialog-form").dialog({
            autoOpen: false,
            height: 330,
            width: 400,
            modal: true,
            buttons: {
                "Jeg er klar": function () {
                    var bValid = true;
                    allFields.removeClass("ui-state-error");

                    bValid = bValid && checkCompanyEditVsRadio();
                    bValid = bValid && checkLength(fornavn, "Fornavn", 2, 24);
                    bValid = bValid && checkLength(etternavn, "Etternavn", 2, 24);
                    bValid = bValid && checkLength(epost, "E-post", 6, 80);
                    bValid = bValid && checkLength(mobil, "Mobilnummer", 8, 80);

                    // Javascript regex is English only! Æ Ø Å æ ø å must be represented as Unicode \u00E6 \u00F8 \u00E5 \u00C6 \u00D8 \u00C5
                    bValid = bValid && checkRegexp(fornavn, /^[-a-zA-Z\u00E6\u00F8\u00E5\u00C6\u00D8\u00C5]([\. -a-zA-Z\u00E6\u00F8\u00E5\u00C6\u00D8\u00C5])+$/i, "Ikke godkjente tegn i fornavn.");
                    bValid = bValid && checkRegexp(etternavn, /^[-a-zA-Z\u00E6\u00F8\u00E5\u00C6\u00D8\u00C5]([\. -a-zA-Z\u00E6\u00F8\u00E5\u00C6\u00D8\u00C5])+$/i, "Ikke godkjente tegn i etternavn.");
                    // From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
                    bValid = bValid && checkRegexp(epost, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "E-post format m\u00E5 endres, f.eks. user@bizweb.no");
                    bValid = bValid && checkRegexp(mobil, /^[0-9+]([0-9])+$/i, "Mobilnummer kan inneholde tallene 0-9 og kan begynne med +.");

                    //bValid = bValid && checkTerms(terms);

                    if (bValid) {
                        document.forms.namedItem('formProvGratis').submit();
                        $(this).dialog("close");
                    }
                } /*,
                                    Cancel: function () {
                                        $(this).dialog("close");
                                    }*/
            },
            close: function () {
                allFields.val("").removeClass("ui-state-error");
                updateTips("");
            }
        });

        $("#provgratis-dialog-form").dialog({
            autoOpen: true,
            height: 330,
            width: 400,
            modal: true,
            buttons: {
                "Jeg er klar": function () {
                    var bValid = true;
                    allFields.removeClass("ui-state-error");

                    bValid = bValid && checkCompanyEditVsRadio();
                    bValid = bValid && checkLength(fornavn, "Fornavn", 2, 24);
                    bValid = bValid && checkLength(etternavn, "Etternavn", 2, 24);
                    bValid = bValid && checkLength(epost, "E-post", 6, 80);
                    bValid = bValid && checkLength(mobil, "Mobilnummer", 8, 80);

                    // Javascript regex is English only! Æ Ø Å æ ø å must be represented as Unicode \u00E6 \u00F8 \u00E5 \u00C6 \u00D8 \u00C5
                    bValid = bValid && checkRegexp(fornavn, /^[-a-zA-Z\u00E6\u00F8\u00E5\u00C6\u00D8\u00C5]([\. -a-zA-Z\u00E6\u00F8\u00E5\u00C6\u00D8\u00C5])+$/i, "Ikke godkjente tegn i fornavn.");
                    bValid = bValid && checkRegexp(etternavn, /^[-a-zA-Z\u00E6\u00F8\u00E5\u00C6\u00D8\u00C5]([\. -a-zA-Z\u00E6\u00F8\u00E5\u00C6\u00D8\u00C5])+$/i, "Ikke godkjente tegn i etternavn.");
                    // From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
                    bValid = bValid && checkRegexp(epost, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "E-post format m\u00E5 endres, f.eks. user@bizweb.no");
                    bValid = bValid && checkRegexp(mobil, /^[0-9+]([0-9])+$/i, "Mobilnummer kan inneholde tallene 0-9 og kan begynne med +.");

                    //bValid = bValid && checkTerms(terms);

                    if (bValid) {
                        document.forms.namedItem('formProvGratis').submit();
                        $(this).dialog("close");
                    }
                } /*,
                                    Cancel: function () {
                                        $(this).dialog("close");
                                    }*/
            },
            close: function () {
                allFields.val("").removeClass("ui-state-error");
                updateTips("");
            }
        });
        /*
        $("#prov_gratis")
        .click(function () {
        $("#dialog-form").dialog("open");
        });
        */
        $("#provgratissalesonline-dialog-form").dialog({
            autoOpen: true,
            height: 330,
            width: 400,
            modal: true,
            buttons: {
                "Jeg er klar": function () {
                    var bValid = true;
                    allFields.removeClass("ui-state-error");

                    bValid = bValid && checkCompanyEditVsRadio();
                    bValid = bValid && checkLength(fornavn, "Fornavn", 2, 24);
                    bValid = bValid && checkLength(etternavn, "Etternavn", 2, 24);
                    bValid = bValid && checkLength(epost, "E-post", 6, 80);
                    bValid = bValid && checkLength(mobil, "Mobilnummer", 8, 80);

                    // Javascript regex is English only! Æ Ø Å æ ø å must be represented as Unicode \u00E6 \u00F8 \u00E5 \u00C6 \u00D8 \u00C5
                    bValid = bValid && checkRegexp(fornavn, /^[-a-zA-Z\u00E6\u00F8\u00E5\u00C6\u00D8\u00C5]([\. -a-zA-Z\u00E6\u00F8\u00E5\u00C6\u00D8\u00C5])+$/i, "Ikke godkjente tegn i fornavn.");
                    bValid = bValid && checkRegexp(etternavn, /^[-a-zA-Z\u00E6\u00F8\u00E5\u00C6\u00D8\u00C5]([\. -a-zA-Z\u00E6\u00F8\u00E5\u00C6\u00D8\u00C5])+$/i, "Ikke godkjente tegn i etternavn.");
                    // From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
                    bValid = bValid && checkRegexp(epost, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "E-post format m\u00E5 endres, f.eks. user@bizweb.no");
                    bValid = bValid && checkRegexp(mobil, /^[0-9+]([0-9])+$/i, "Mobilnummer kan inneholde tallene 0-9 og kan begynne med +.");

                    if (bValid) {
                        document.forms.namedItem('formProvGratisSalesOnline').submit();
                        $(this).dialog("close");
                    }
                }
            },
            close: function () {
                allFields.val("").removeClass("ui-state-error");
                updateTips("");
            }
        });
    });
});

