﻿var gotologin = false;
var userid = "";
var q = "";

$(function() {

    $('a').focus(function() { $(this).blur(); });
    $('.autofocus').focus();

    /* updated 29-06-2011 */
    if (pageid == loginpageid) {
        $.cookie("LoginlandingID", 50, { path: '/' });
    }

    if (userid.length == 0) {
        $.cookie("LoginlandingID", null);
    }
    else if (userid.length > 0 && (pageid == 50 || pageid == 54)) {
        $.cookie("LoginlandingID", pageid, { path: '/' });
    }
    else if (userid.length > 0 && $.cookie("LoginlandingID") && pageid == loginpageid) {
        $('.paragraph4 .module').html("<p class='center'>" + allreadyintxt + "</p>");
        location.href = "/Default.aspx?ID=" + $.cookie("LoginlandingID");
    }

    $('.fblike iframe').attr("src", "http://www.facebook.com/plugins/like.php?href=" + location.href + "&layout=button_count&show_faces=true&width=682&action=like&locale=da_DK&font=arial&colorscheme=dark&height=23");
    setTimeout("$('.fblike iframe').attr('width', '100px');", 500);

    $(".list1 .listitem, .list4 .listitem").mouseenter(function() {
        $(this).css({ 'background-image': 'url(/Files/System/graphic/list1-bghover.png)', 'background-repeat': 'repeat-x', 'background-position': 'left bottom' }).find("p").css({ 'color': '#000000' }).find("i").css({ 'color': '#ffffff' });
    }).mouseleave(function() {
        $(this).css({ 'background-image': 'url(/Files/System/graphic/list1-bgnormal.png)', 'background-repeat': 'repeat-x', 'background-position': 'left bottom' }).find("p").css({ 'color': '#878787' }).find("i").css({ 'color': '#000000' });
    }).css({ 'cursor': 'pointer' }).click(function() {
        location.href = $(this).find("a").attr("href");
    });

    $(".date").each(function() {
        $(this).text($(this).text().replace(/\//gi, "."));
    });

    if ($(".useinlegend h1.h1").length) {
        $(".legend p").append(" > <a href='#' title='" + $(".useinlegend h1.h1").text() + "'>" + $(".useinlegend h1.h1").text() + "</a>");
    }

    function getUrlVars() {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for (var i = 0; i < hashes.length; i++) {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    }

    if ($("#searchgoto").length > 0) {
        /* redirect to correct url */
        if (!getUrlVars()['PageNum']) {
            var split_rel = $("#searchgoto").attr("rel").split(";");
            location.href = window.location.pathname + "?PageNum=1&PID=" + split_rel[1];
        }
        var searchgoto_int = 1;
        /* before loop */
        if (parseInt(getUrlVars()['PageNum']) != 1) {
            $("#searchgoto").append("<a href='" + window.location.pathname + "?PageNum=1&PID=" + getUrlVars()['PID'] + ((getUrlVars()['ProductID']) ? "&ProductID=" + getUrlVars()['ProductID'] : "") + ((getUrlVars()['RelationID']) ? "&RelationID=" + getUrlVars()['RelationID'] : "") + "' title=''>&lsaquo;&lsaquo;</a>");
        }
        if (parseInt(getUrlVars()['PageNum']) > 1) {
            $("#searchgoto").append("<a href='" + window.location.pathname + "?PageNum=" + (getUrlVars()['PageNum'] - 1) + "&PID=" + getUrlVars()['PID'] + ((getUrlVars()['ProductID']) ? "&ProductID=" + getUrlVars()['ProductID'] : "") + ((getUrlVars()['RelationID']) ? "&RelationID=" + getUrlVars()['RelationID'] : "") + "' title=''>&lsaquo;</a>");
        }
        if ((parseInt(getUrlVars()['PageNum'])) >= (searchgoto_int * 2) && parseInt(getUrlVars()['PageNum']) != 2) {
            $("#searchgoto").append("<a href='" + window.location.pathname + "?PageNum=1&PID=" + getUrlVars()['PID'] + ((getUrlVars()['ProductID']) ? "&ProductID=" + getUrlVars()['ProductID'] : "") + ((getUrlVars()['RelationID']) ? "&RelationID=" + getUrlVars()['RelationID'] : "") + "' title=''>1</a>");
        }
        if ((parseInt(getUrlVars()['PageNum'])) >= (searchgoto_int * 2) && parseInt(getUrlVars()['PageNum']) != 2) {
            $("#searchgoto").append(" .. ");
        }
        /* loop */
        for (var i = 1; i <= parseInt($("#searchgoto").attr("rel")); i++) {
            if (i > (parseInt(getUrlVars()['PageNum']) + searchgoto_int) || i < (parseInt(getUrlVars()['PageNum']) - searchgoto_int)) {
                continue;
            }
            $("#searchgoto").append("<a href='" + window.location.pathname + "?PageNum=" + i + "&PID=" + getUrlVars()['PID'] + ((getUrlVars()['ProductID']) ? "&ProductID=" + getUrlVars()['ProductID'] : "") + ((getUrlVars()['RelationID']) ? "&RelationID=" + getUrlVars()['RelationID'] : "") + "' title=''" + ((i == parseInt(getUrlVars()['PageNum'])) ? " class='active'" : "") + ">" + i + "</a>");
        }
        /* after loop */
        if (parseInt($("#searchgoto").attr("rel")) - (parseInt(getUrlVars()['PageNum'])) >= (searchgoto_int + 1)) {
            $("#searchgoto").append(" .. ");
        }
        if (parseInt($("#searchgoto").attr("rel")) - (parseInt(getUrlVars()['PageNum'])) >= (searchgoto_int + 1)) {
            $("#searchgoto").append("<a href='" + window.location.pathname + "?PageNum=" + parseInt($("#searchgoto").attr("rel")) + "&PID=" + getUrlVars()['PID'] + ((getUrlVars()['ProductID']) ? "&ProductID=" + getUrlVars()['ProductID'] : "") + ((getUrlVars()['RelationID']) ? "&RelationID=" + getUrlVars()['RelationID'] : "") + "' title=''>" + parseInt($("#searchgoto").attr("rel")) + "</a>");
        }
        if (parseInt(getUrlVars()['PageNum']) != parseInt($("#searchgoto").attr("rel"))) {
            $("#searchgoto").append("<a href='" + window.location.pathname + "?PageNum=" + (parseInt(getUrlVars()['PageNum']) + 1) + "&PID=" + getUrlVars()['PID'] + ((getUrlVars()['ProductID']) ? "&ProductID=" + getUrlVars()['ProductID'] : "") + ((getUrlVars()['RelationID']) ? "&RelationID=" + getUrlVars()['RelationID'] : "") + "' title=''>&rsaquo;</a>");
        }
        if (parseInt(getUrlVars()['PageNum']) < parseInt($("#searchgoto").attr("rel"))) {
            $("#searchgoto").append("<a href='" + window.location.pathname + "?PageNum=" + parseInt($("#searchgoto").attr("rel")) + "&PID=" + getUrlVars()['PID'] + ((getUrlVars()['ProductID']) ? "&ProductID=" + getUrlVars()['ProductID'] : "") + ((getUrlVars()['RelationID']) ? "&RelationID=" + getUrlVars()['RelationID'] : "") + "' title=''>&rsaquo;&rsaquo;</a>");
        }
        /* remove if empty */
        if (parseInt($("#searchgoto").attr("rel")) == 0) {
            $("#searchgoto").text("");
        }
    }

    /* fix height setup1 */
    if ($(".setup1").length > 0) {
        /* set begin height */
        var heightfix = 0;
        /* reset to max. height */
        if (heightfix < parseInt($(".setup1 .column4 .list").height())) { heightfix = parseInt($(".setup1 .column4 .list").height()) }
        if (heightfix < parseInt($(".setup1 .column5 .list").height())) { heightfix = parseInt($(".setup1 .column5 .list").height()) }
        /* set max. height */
        $(".setup1 .column4 .list, .setup1 .column5 .list").css({ 'height': heightfix + 'px' });
    }

    /* fix height setup3 */
    if ($(".setup3").length > 0) {
        /* set begin height */
        var heightfix = 0;
        /* reset to max. height */
        if (heightfix < parseInt($(".setup3 .column3").height())) { heightfix = parseInt($(".setup3 .column3").height()) }
        if (heightfix < parseInt($(".setup3 .column4").height())) { heightfix = parseInt($(".setup3 .column4").height()) }
        /* set max. height */
        $(".setup3 .column3, .setup3 .column4").css({ 'height': heightfix + 'px' });
    }

    /* fix height setup3 */
    if ($(".setup4").length > 0) {
        /* set begin height */
        var heightfix = 0;
        /* reset to max. height */
        if (heightfix < parseInt($(".setup4 .column4 .list").height())) { heightfix = parseInt($(".setup4 .column4 .list").height()) }
        if (heightfix < parseInt($(".setup4 .column5 .list").height())) { heightfix = parseInt($(".setup4 .column5 .list").height()) }
        /* set max. height */
        $(".setup4 .column4 .list, .setup4 .column5 .list").css({ 'height': heightfix + 'px' });
        /* set begin num */
        var legend_num = 0;
        $('.legend').find('a').each(function() {
            /* add + to num */
            legend_num++;
            /* remove 1st num */
            if (legend_num > 1) {
                /* set inpath to productgroup a */
                $('.productgroups a[href=\"' + $(this).attr('href') + '\"]').addClass('inpath');
            }
        });
    }

    /*
    if ($(".brands ul").length > 0) {
    $("html").mouseup(function() {
    timeout1 = setTimeout("timeoutclose1();", 100);
    });
    $(".brands ul").addClass("selectReplacement").prepend("<li class='label'><a>Se vores m&aelig;rker</a></li>").click(function() {
    clearTimeout(timeout1);
    $(this).addClass("selectOpen");
    $(this).mouseleave(function() {
    timeout1 = setTimeout("timeoutclose1();", 500);
    });
    });
    $(".brands ul li[class='label']").addClass("selected");
    }
    */

    if ($(".brands_v2 ul").length > 0) {
        var timeout1_v2 = null;
        $('.brands_v2 .scroll').show().css({ 'max-height': ($('.brands_v2 .scroll ul li').height() * 14) }).jScrollPane().hide();
        $('.brands_v2 .title').click(function() {
            $('.brands_v2 .scroll').show();
            $('.brands_v2').mouseenter(function() {
                clearTimeout(timeout1_v2);
            }).mouseleave(function() {
                timeout1_v2 = setTimeout("$('.brands_v2 .scroll').hide();", 500);
            });
        });
    }

    if ($(".shops ul").length > 0) {
        $("html").mouseup(function() {
            timeout2 = setTimeout("timeoutclose2();", 100);
        });
        $(".shops ul").addClass("selectReplacement").prepend("<li class='label'><a>Find din butik</a></li>").click(function() {
            clearTimeout(timeout2);
            $(this).addClass("selectOpen");
            $(this).mouseleave(function() {
                timeout2 = setTimeout("timeoutclose2();", 500);
            });
        });
        if (getUrlVars()['ProductID']) {
            $(".shops li[rel='" + getUrlVars()['ProductID'] + "']").addClass("selected").find("a").attr("href", "javascript:void(0);");
        } else {
            $(".shops ul li[class='label']").addClass("selected");
        }
    }

    if ($("#relationid").length > 0) {
        $("html").mouseup(function() {
            timeout3 = setTimeout("timeoutclose3();", 100);
        });
        $("#relationid").click(function() {
            clearTimeout(timeout3);
            $(this).addClass("selectOpen");
            $(this).mouseleave(function() {
                timeout3 = setTimeout("timeoutclose3();", 500);
            });
        });
        if (getUrlVars()['RelationID']) {
            $("#relationid li[rel='" + getUrlVars()['RelationID'] + "']").addClass("selected").find("a").attr("href", "javascript:void(0);");
        } else {
            $("#relationid li[class='label']").addClass("selected").find("a").attr("href", "javascript:void(0);");
        }
    }

    $(".productgroups li").mouseenter(function() {
        //  $(this).find("a").addClass("inpath")
        $(this).find("ul").css({ 'display': 'block' });
    }).mouseleave(function() {
        //  $(this).find("a").removeClass("inpath")
        $(this).find("ul").css({ 'display': 'none' });
    });

    if ($(".redirect").length > 0) {
        if ($(".redirect").attr('href') == "history.back(-1);") { history.back(-1); }
        else { location.href = $(".redirect").attr('href'); }
    }

    if (userid.length > 0) {
        $('.subnavigation1 li').hide();
        $('.subnavigation1 ul').append("<li><a href='/Admin/Public/extranetlogoff.aspx?ID=" + loginpageid + "' title='" + logouttxt + "'>" + logouttxt + "</a></li>");
    }

    $('input[name=UserManagement_Form_Email]').blur(function() {
        $('input[name=UserManagement_Form_UserName]').val($(this).val());
    });

    $('input[name=UserManagement_Form_NewPassword]').blur(function() {
        $('input[name=UserManagement_Form_NewPasswordConfirm]').val($(this).val());
    });

    $('form').each(function() {
        var obj_form = $(this);
        $(this).find('.submitter').click(function() {
            //  obj_form.css({'background':'red'});

            if (obj_form.attr('name') == "ExtUserForm" && $("input[name='Username']").val() && $("input[name='ForgotPassword']").is(":checked")) {
              $.ajax({
                  type: "POST",
                  url: "/Ajax/GetPassword.aspx?username="+$("input[name='Username']").val()+"&emne=Dit kodeord til Esthetique Kundeklub",
                  success: function(msg) {
                      alert("Dit kodeord er nu afsendt til den indtastet e-mail.");
                      window.location.reload();
                  },
                  error: function(result) {
                      alert(result.status + ' ' + result.statusText);
                  }
              });
              return false;
            }

            var obj = $(this);
            var do_focus = true;
            var sta_return = true;
            var str_message = '';
            obj_form.find('.neededemail input, input.neededemail').each(function() {
                //  $(this).css({'background':'pink'});
                var filter = /^[^@]+@[^@]+.[a-z]{2,}$/i;
                if ($(this).val() == "" || !filter.test($(this).val()) || ($(this).val() == 'void@esthetique.dk' && obj.attr('class') == 'loginbtn1 submitter')) {
                    sta_return = false;
                    //  alert('Feltet 2 er ikke udfyldt korrekt.');
                    str_message += $(this).closest('tr').find('td p:first, td label:first').text().replace(':', '') + ' er ikke udfyldt korrekt.\n';
                    $(this).addClass('needfill');
                    if (do_focus === true) { $(this).focus(); do_focus = false; }
                } else { $(this).removeClass('needfill'); }
            });
            obj_form.find('.needed input, input.needed').each(function() {
                //  $(this).css({'background':'blue'});
                if ($(this).val() == "") {
                    sta_return = false;
                    //  alert('Feltet 1 er ikke udfyldt korrekt.');
                    str_message += $(this).closest('tr').find('td p:first, td label:first').text().replace(':', '') + ' er ikke udfyldt korrekt.\n';
                    $(this).addClass('needfill');
                    if (do_focus === true) { $(this).focus(); do_focus = false; }
                } else { $(this).removeClass('needfill'); }
            });
            obj_form.find('.neededselects').each(function() {
                //  $(this).css({'border':'1px solid green'});
                var sta_selects = false;
                $(this).find('input').each(function() {
                    //  $(this).css({'border':'1px solid green'});
                    if ($(this).is(':checked')) {
                        sta_selects = true;
                    }
                });
                if (sta_selects === false) {
                    sta_return = false;
                    //  alert('Feltet 3 er ikke udfyldt korrekt.');
                    str_message += $(this).closest('tr').find('td p:first, td label:first').text().replace(':', '') + ' er ikke udfyldt korrekt.\n';
                    if (do_focus === true) { $(this).find('input:first').focus(); do_focus = false; }
                }
            });
            if (sta_return === false) {
                alert('Et eller flere felter er ikke udfyldt korrekt:\n\n' + str_message);
                return false;
            }

            if (obj_form.attr('name') == "ESTUserManagementAddForm") {
                $.ajax({
                    type: "POST",
                    url: "/Ajax/CreateUser.aspx?" +
            "loginid=" + userid + "&" +
            "name=" + encodeURIComponent($("#UserManagement_Form_Name").val()) + "&" +
            "address=" + encodeURIComponent($("#UserManagement_Form_Address").val()) + "&" +
            "zip=" + encodeURIComponent($("#UserManagement_Form_Zip").val()) + "&" +
            "city=" + encodeURIComponent($("#UserManagement_Form_City").val()) + "&" +
            "phone=" + encodeURIComponent($("#UserManagement_Form_PhoneMobile").val()) + "&" +
            "email=" + encodeURIComponent($("#UserManagement_Form_Email").val()) + "&" +
            "password=" + encodeURIComponent($("#UserManagement_Form_NewPassword").val()),
                    success: function(msg) {
                        if (msg != "error") {
                            if ($("input[name=direct]:checked").val() == 1) {
                                $("#status").html("<p>&nbsp;</p><p>Kunden <b>" + $("#UserManagement_Form_Name").val() + "</b> er oprettet.</p>");
                                $("#UserManagement_Form_Name, #UserManagement_Form_PhoneMobile, #UserManagement_Form_Zip,#UserManagement_Form_City, #UserManagement_Form_Address").attr("value", "");
                                $("#UserManagement_Form_Email").attr("value", "void@esthetique.dk");
                                $("#UserManagement_Form_NewPassword").attr("value", "1234");
                                $("#UserManagement_Form_Name").focus();
                            } else if ($("input[name=direct]:checked").val() == 2) {
                                location.href = "/kundeklub/butik/find-kunde/registrer-bonuspoints.aspx?userID=" + msg; return;
                            } else if ($("input[name=direct]:checked").val() == 3) {
                                location.href = "/kundeklub/butik/find-kunde.aspx?q=" + $("#UserManagement_Form_Name").val(); return;
                            }
                        } else if (msg == "error") {
                            $("#status").html("<p>&nbsp;</p><p>Kunden <b>" + $("#UserManagement_Form_Name").val() + "</b> er <i>ikke</i> oprettet.</p>");
                        }
                    },
                    error: function(result) { alert(result.status + ' ' + result.statusText); }
                });
                return;
            }

            if (obj_form.attr('name') == "ESTUserManagementEditForm") {
                var split_rel = $(this).attr("rel").split(";");
                $.ajax({
                    type: "POST",
                    url: "/Ajax/CreateUser.aspx?" +
            "status=edit&" +
            "userid=" + split_rel[0] + "&" +
            "name=" + encodeURIComponent($("#UserManagement_Form_Name").val()) + "&" +
            "address=" + encodeURIComponent($("#UserManagement_Form_Address").val()) + "&" +
            "zip=" + encodeURIComponent($("#UserManagement_Form_Zip").val()) + "&" +
            "city=" + encodeURIComponent($("#UserManagement_Form_City").val()) + "&" +
            "phone=" + encodeURIComponent($("#UserManagement_Form_PhoneMobile").val()) + "&" +
            "email=" + encodeURIComponent($("#UserManagement_Form_Email").val()),
                    success: function(msg) {
                        if (msg == "ok") {
                            $("#status").html("<p>&nbsp;</p><p>Kunden <b>" + $("#UserManagement_Form_Name").val() + "</b> er redigeret.</p>");
                        } else if (msg == "error") {
                            $("#status").html("<p>&nbsp;</p><p>Kunden <b>" + $("#UserManagement_Form_Name").val() + "</b> er <i>ikke</i> redigeret.</p>");
                        }
                    },
                    error: function(result) { alert(result.status + ' ' + result.statusText); }
                });
                return;
            }

            if (obj_form.attr('name') == "ESTUserManagementSendNewsletter") {
                if (confirm("Vil du afsende nyhedsbrevet?")) {
                    var split_rel = $(this).attr("rel").split(";");
                    var subject = $("input[name=subject]");
                    var contentdata = FCKeditorAPI.GetInstance('FCKeditor1').GetHTML(true);
                    contentdata = contentdata.replace(/</gi, "$");
                    contentdata = encodeURIComponent(contentdata);
                    var dataToSend = { 'loginid': split_rel[0], 'content': contentdata, 'title': encodeURIComponent(subject.val()) }
                    $.ajax({
                        type: "POST",
                        url: "SendEmailService.asmx/SendNewsEmail",
                        data: "loginid=" + split_rel[0] + "&content=" + contentdata + "&title=" + encodeURIComponent(subject.val()),
                        //contentType: "application/json; charset=utf-8",
                        dataType: "xml",
                        processData: false,
                        success: function(msg) {
                            var xml = $(msg);
                            if (xml.find("string").text() == "ok") {
                                alert("Nyhedsbrevet er sendt.");
                            } else if (xml.find("string").text() == "error") {
                                alert("Nyhedsbrevet er ikke sendt.");
                                /* work around - some emails has not receive newsletter Judy:I have changed the function. So if msg is 'error', it means there is no single email has sent. 2011-05-16*/
                            }
                        },
                        error: function(result) { alert(result.status + ' ' + result.statusText); }
                    });
                }
                return;
            }



            //alert("ok");
            obj_form.submit();
        });
    });

    $("input[name='ForgotPassword']").removeAttr('checked').click(function() {
        $(this).closest("form").find(".passwordtxt").closest("tr").css({ 'display': ((!$(this).is(":checked")) ? 'table-row' : 'none') });
        if ($(this).is(":checked")) {
            $(this).closest("form").find(".usernametxt").text(language1);
            $(this).closest("form").find(".submitter").val("SEND");
        }
        else {
            $(this).closest("form").find(".usernametxt").text(language2);
            $(this).closest("form").find(".submitter").val("LOGIN");
        }
    });

    $(".deleteuser2").click(function() {
        var split_rel = $(this).attr("rel").split(";");
        if (confirm("Vil du slettes som kunde og derved afmeldes kundeklub?")) {
            //  alert(split_rel[0] + " " + userid);
            $.ajax({
                type: "POST",
                url: "/Ajax/DeleteUser.aspx?status=delete&userid=" + userid,
                success: function(msg) {
                    alert("Du er nu slettet som kunde");
                    location.href = "/Admin/Public/extranetlogoff.aspx?ID=" + loginpageid;
                    //window.location.reload();
                },
                error: function(result) {
                    alert(result.status + ' ' + result.statusText);
                }
            });
        }
    });

    $(".deleteuser").click(function() {
    var split_rel = $(this).attr("rel").split(";");
    if (confirm("Vil du slette kunde, " + split_rel[1])) {
          
                       $.ajax({
                            type: "POST",
                            url: "/Ajax/DeleteUser.aspx?status=delete&userid=" + split_rel[0],
                            success: function(msg) {
                               // alert("Du er nu slettet som kunde");
                                //location.href = "/Admin/Public/extranetlogoff.aspx?ID=" + loginpageid;
                               window.location.reload();
                            },
                            error: function(result) {
                                alert(result.status + ' ' + result.statusText);
                            }
                        });
        }
        return;
    });

    $(".extractPoint").each(function() {
        var split_rel = $(this).attr("rel").split(";");
        if (split_rel[1] < 10) {
            $(this).remove();
        }
    });

    $(".extractPoint").click(function() {
        if (confirm('Vil du udtr\346kke 10 bonuspoints v\346rdi 150,00?')) {
            var split_rel = $(this).attr("rel").split(";");
            $.ajax({
                type: "POST",
                url: "/Ajax/HandleUserBuy.aspx?status=extract&userid=" + split_rel[0] + "&loginid=" + userid,
                success: function(msg) {
                    window.location.reload();
                },
                error: function(result) {
                    alert(result.status + ' ' + result.statusText);
                }
            });
        }
    });

    $(".cancelBuy").click(function() {
        var split_rel = $(this).attr("rel").split(";");
        if (confirm("Vil du tage bonuspionts retur fra den " + split_rel[1] + "?")) {
            $.ajax({
                type: "POST",
                url: "/Ajax/HandleUserBuy.aspx?status=cancel&id=" + split_rel[0],
                success: function(msg) {
                    window.location.reload();
                },
                error: function(result) {
                    alert(result.status + ' ' + result.statusText);
                }
            });
        }
    });

    $("input[name=pointQnt]").blur(function() {
        if ($(this).val()) {
            $(this).val(parseInt($(this).val()));
        }
    });

    $(".insertBuy").click(function() {
        var split_rel = $(this).attr("rel").split(";");
        if (confirm("Vil du registerer et k\u00F8b p\u00E5 " + $("input[name=pointQnt]").val() + ",00?")) {
            $.ajax({
                type: "POST",
                url: "/Ajax/HandleUserBuy.aspx?status=insert&userid=" + split_rel[0] + "&loginid=" + userid + "&amount=" + $("input[name=pointQnt]").val(),
                success: function(msg) {
                    if (msg == "ok") {
                        $("#status").html("<p>&nbsp;</p><p>Der er registreret et k&oslash;b p&aring; " + $("input[name=pointQnt]").val() + ",00.</p>");
                        $("input[name=pointQnt]").val("")
                    } else if (msg == "error") {
                        $("#status").html("<p>&nbsp;</p><p>Kunden <b>" + $("#UserManagement_Form_Name").val() + "</b> er <i>ikke</i> redigeret.</p>");
                    }
                },
                error: function(result) {
                    alert(result.status + ' ' + result.statusText);
                }
            });
        }
    });

    if ($("textarea[name=FCKeditor1]").length > 0) {
        var oFCKeditor = new FCKeditor('FCKeditor1'); /* name or id */
        oFCKeditor.BasePath = '/Files/System/fckeditor/';
        oFCKeditor.Config['SkinPath'] = '/Files/System/fckeditor/editor/skins/silver/';
        oFCKeditor.ToolbarSet = 'EST';
        oFCKeditor.Height = 500;
        oFCKeditor.ReplaceTextarea();
    }

    // delete: $.cookie("q", null);
    // set: $.cookie("q", pageid, { path: '/' });
    // get $.cookie("q");

    if (q.length > 0) {
        $.cookie("q", q, { path: '/' });
    }

    $("a.btn1[href=/kundeklub/butik/find-kunde.aspx]").each(function() {
        $(this).attr("href", $(this).attr("href") + "?q=" + $.cookie("q"));
    });

    /*
    var stdparagraph = 1;
    setnewsletterparagraph(stdparagraph);
    $('.newsletter_cntparagraph').each(function() {
    for (var i = 1; i <= 3; i++) { $(this).append('<option value="'+i+'">'+i+'</option>'); }
    $(this).val(stdparagraph);
    }).change(function() {
    setnewsletterparagraph($(this).val());
    $(this).blur();
    });
    */

    if ($(".keepalive").length > 0) {
        var time = (1 * 1000 * 60);
        setTimeout("keepalive(" + time + ")", time);
    }

    /* updated 29-06-2011 - begin */
    $("a[href^='/Admin/Public/extranetlogoff.aspx']").click(function() {
        $.cookie("LoginlandingID", null);
    });
    /* updated 29-06-2011 - end */

});

/*
function timeoutclose1() {
  $(".brands ul").removeClass("selectOpen");
}
*/

function timeoutclose2() {
  $(".shops ul").removeClass("selectOpen");
}
function timeoutclose3() {
  $("#relationid").removeClass("selectOpen");
}

function keepalive(time) {
  var currentTime = new Date();
  $.ajax({
    type: "GET",
    url: "/Default.aspx?ID="+pageid+"&keepalive=1&uniqtime="+currentTime.getTime(),
    success: function(msg) {
      setTimeout("keepalive("+time+")", time);
    //alert(msg);
    //var currentTime = new Date(); $('body').append("<p>"+currentTime.getHours()+":"+currentTime.getMinutes()+":"+currentTime.getSeconds()+" - keepalive eksikveret.</p>");
    },
    error: function(result) {
      /* updated 30-06-2011 - begin */
      $.cookie("LoginlandingID", null);
      /* updated 30-06-2011 - end */
      alert('Af en eller flere tekniske grunde vil du nu blive logget af. Du er herefter velkommen til at logge ind igen.');
      location.href = "/Admin/Public/extranetlogoff.aspx?ID=47";
    }
  });
  //var currentTime = new Date();  $('body').append("<p>"+currentTime.getHours()+":"+currentTime.getMinutes()+":"+currentTime.getSeconds()+" - keepalive aktiveret.</p>");
}

/*
function setnewsletterparagraph(cnt) {
  var objparagraph = $('.newsletter_stdparagraph').hide();
  for (var i = 1; i <= cnt; i++) {
    if ($('#newsletter_stdparagraph'+i).length == 0) {
      var obj = $('.newsletter_hlrparagraph').append(objparagraph.html());
      obj.find('fieldset:last legend').text('Artikel '+i);
      obj.find('fieldset:last').attr('id','newsletter_stdparagraph'+i);
      obj.find('fieldset:last input,fieldset:last select,fieldset:last textarea').each(function() {
        $(this).attr('name',$(this).attr('name')+i);
      });
    }
  }
  var i = 1;
  $('.newsletter_hlrparagraph fieldset').each(function() {
    if (i > cnt) { $('#newsletter_stdparagraph'+i).remove(); } i++;
  });
}
*/
