﻿///<reference path="jquery-1.6.1.min.js" />
///<reference path="jquery.alerts.js" />
///<reference path="base64.js" />
///<reference path="cookies.js" />

var CKEDITOR_BASEPATH = '/external/ckeditor/';

$(document).ready(function () {
    SetEvents();
    SetData();
    SpecialMethods();
});

function SetEvents() {
    $("#CPH_LeftMenu_LeftMenu a[id^='INACT_HREF_']").hover(function () {
        var theID = $(this).attr('id').replace('INACT_HREF_', '');
        $('#ACT_TBL_' + theID).animate({ 'backgroundColor': '#ff0000' }, 50);
        $('#ACT_TD_' + theID).animate({ 'backgroundColor': '#ff0000' }, 50);
        $('#INACT_HREF_' + theID).animate({ 'color': '#ffffff' }, 50);
        $('#ACT_IMG_' + theID).attr('src', '/images/act_cls.png');
    }, function () {
        var theID = $(this).attr('id').replace('INACT_HREF_', '');
        $('#ACT_TBL_' + theID).animate({ 'backgroundColor': '#D5D5D5' }, 50);
        $('#ACT_TD_' + theID).animate({ 'backgroundColor': '#D5D5D5' }, 50);
        $('#INACT_HREF_' + theID).animate({ 'color': '#000000' }, 50);
        $('#ACT_IMG_' + theID).attr('src', '/images/nact_cls.png');
    });
}

function SetData() {
    $('#TBL_Overview').css('color', '#000000');
    $('#TBL_Overview td[colspan!="4"] a').css('font-size', '11pt');
}



function ActivateTab(Nmbr) {
    $('#tabs').tabs('select', Nmbr);
}

function BuildUserMenu() {
    if (cookies.CookieRead('IsLogon')) {
        $('#UserContainer').remove();
        Dimatec.WebServices.Core.GetUserContainer(function (args) {
            $('#form1').append(args);
            //var pos = $('#INACT_HREF_999').offset();
            //var height = $('#INACT_HREF_999').height();
            var pos = $("a[name='INACT_HREF_999']").offset();
            var height = $("a[name='INACT_HREF_999']").height();
            $('#UserContainer').css('left', (pos.left) + 'px');
            $('#UserContainer').css('top', (pos.top + height + 4) + 'px');
            $('#BtmContentEdit').hover(function () {
                $(this).css('textDecoration', 'underline');
                RenderBtmBorder($('#CPH_Bottom_Bottom'));
            },
            function () {
                $(this).css('textDecoration', 'none');
                RemoveBtmBorder();
            }
        );
            $('#BtmContentEdit').click(function () {
                BtmContentEdit();
            });

            $('#LeftContentEdit').hover(function () {
                $(this).css('textDecoration', 'underline');
                RenderBtmBorder($('#CPH_LeftMenu_LeftMenu'));
            },
            function () {
                $(this).css('textDecoration', 'none');
                RemoveBtmBorder();
            }
        );
            $('#LeftContentEdit').click(function () {
                LeftContentEdit();
            });
            $('#ImgContentEdit').hover(function () {
                $(this).css('textDecoration', 'underline');
                RenderBtmBorder($('#CPH_TopImage_TopImage'));
            },
            function () {
                $(this).css('textDecoration', 'none');
                RemoveBtmBorder();
            }
        );
            $('#ImgContentEdit').click(function () {
                ImgContentEdit();
            });
            $('#CntContentEdit').hover(function () {
                $(this).css('textDecoration', 'underline');
                RenderBtmBorder($('#CPH_Content_Content'));
            },
            function () {
                $(this).css('textDecoration', 'none');
                RemoveBtmBorder();
            }
        );
            $('#CntContentEdit').click(function () {
                CntContentEdit();
            });

            $('#UserContainer a').css({ textDecoration: 'none', color: '#565a5a', fontWeight: 'bold' });
            $('#UserContainer').fadeIn(400);
        }, OnError, OnTimeOut);
    } else {
        $('#UserContainer').remove();
        $('#LnkLogon').attr('href', 'javascript:Logon();');
    }
}

function BtmContentEdit() {
    Dimatec.WebServices.Core.GetBottomData(function (fn) {
        $('#BtmEditContainer').remove();
        $('#form1').append(fn);
        $("#BtmEditContainer").dialog({ bgiframe: true, height: 240, width: 480, title: 'Fusszeile anpassen', modal: true, resizable: false, autoOpen: false,
            buttons: {
                'Speichern': function () {
                    //Hier die Speichern Funktion implementieren!
                    //SetBottomData
                    var objResult = new Object;
                    objResult.Content = $('#FldBtmContentValue').val();
                    Dimatec.WebServices.Core.SetBottomData(objResult, function (fn) {
                        if (fn.Result) {
                            $(this).dialog('close');
                            window.location.reload();
                        } else {
                            jAlert(fn.ResultText, 'Warnung');
                        };
                    }, OnError, OnTimeOut);
                },
                'Abbrechen': function () {
                    $(this).dialog('close');
                }
            },
            close: function () {
                $(this).dialog('destroy');
                $(this).remove();
            }
        });
        $('#BtmEditContainer').dialog('open');
    }, OnError, OnTimeOut);
}

function TopContentEdit() {

}

function LeftContentEdit() {
    var objInput = new Object;
    Dimatec.WebServices.Core.GetLeftMenuContent(objInput, function (args) {
        $('#LeftMenuEditContainer').remove();
        $('<div id="LeftMenuEditContainer" />').appendTo('#form1');
        var ind = $('<div id="LeftMenuEditBox" style="width: 100%; height: 100%; text-decoration: none; font-size: 10pt; font-weight: bold; font-family: Arial, Helvetica, sans-serif;" />');
        RecurseBuildLeftMenu(ind, args);
        $('#LeftMenuEditContainer').append(ind);

        $("#LeftMenuEditContainer img[id*='DelElement_']").click(function () {
            var xVO = $(this);
            jAlert('M&ouml;chten Sie den Eintrag wirklich löschen? Bitte beachten, das alle untergeordneten Elemente mit entfernt werden!', 'Warnung', function (r) {
                if (r) {
                    var ElementID = $(xVO).attr('id').replace('DelElement_', '');
                    var InObject = new Object;
                    InObject.PageID = ElementID;
                    InObject.Action = 'Delete';
                    InObject.MenuSet = args;
                    LeftMenuAction(InObject);
                };
            });
        });

        $("#LeftMenuEditContainer img[id*='EditElement_']").click(function () {
            var ElementID = $(this).attr('id').replace('EditElement_', '');
            var InObject = new Object;
            InObject.PageID = ElementID;
            Dimatec.WebServices.Core.EditLeftMenuEntry(InObject, function (args) {
                $('#MenuEdit').remove();
                $('#form1').append(args);
                $('#MenuEdit').dialog({ bgiframe: true, height: 640, width: 640, title: 'Men&uuml;punkt bearbeiten', modal: true, resizable: false, autoOpen: false,
                    buttons: {
                        'Speichern': function () {
                            //Linkes Menue speichern!
                            SaveLeftMenuEntry();
                        },
                        'Beenden': function () {
                            $(this).dialog('close');
                        }
                    },
                    close: function () {
                        $(this).dialog('destroy');
                        $(this).remove();
                        LeftContentEdit();
                    }
                });

                $('#MenuEdit').dialog('open');
            }, OnError, OnTimeOut);
        });

        $("#LeftMenuEditContainer img[id*='UpElement_']").click(function () {
            var ElementID = $(this).attr('id').replace('UpElement_', '');
            var InObject = new Object;
            InObject.PageID = ElementID;
            InObject.Action = 'Up';
            InObject.MenuSet = args;
            LeftMenuAction(InObject);

        });

        $("#LeftMenuEditContainer img[id*='DwnElement_']").click(function () {
            var ElementID = $(this).attr('id').replace('DwnElement_', '');
            var InObject = new Object;
            InObject.PageID = ElementID;
            InObject.Action = 'Down';
            InObject.MenuSet = args;
            LeftMenuAction(InObject);
        });

        $("#LeftMenuEditContainer img[id*='AddElement_']").click(function () {
            var ElementID = $(this).attr('id').replace('AddElement_', '');
            AddChoice(ElementID, args);
        });

        $('#LeftMenuEditContainer ul').css('list-style-type', 'none');
        $('#LeftMenuEditContainer li').css('margin-top', '3px');
        $('#LeftMenuEditContainer li').css('margin-bottom', '3px');

        $("#LeftMenuEditContainer").dialog({ bgiframe: true, height: 600, width: 800, title: 'Linkes Menü bearbeiten', modal: true, resizable: false, autoOpen: false,
            buttons: {
                'Schliessen': function () {
                    $(this).dialog('close');
                }
            },
            close: function () {
                $(this).dialog('destroy');
                $(this).remove();
                window.location.reload();
            }
        });
        $('#LeftMenuEditContainer').dialog('open');

    }, OnError, OnTimeOut);
}

function AddChoice(PageID, Menu) {
    $('#AddMenuChoice').remove();
    Dimatec.WebServices.Core.GetMenuChoice(function (args) {
        $('#form1').append(args);
        $('#AddMenuChoice').dialog({ bgiframe: true, height: 200, width: 460, title: 'Neues Element hinzuf&uuml;gen - Bitte ausw&auml;hlen', modal: true, resizable: false, autoOpen: false,
            buttons: {
                'Auswählen': function () {
                    SetMenuChoice(PageID, Menu);
                },
                'Abbrechen': function () {
                    $(this).dialog('close');
                }
            },
            close: function () {
                $(this).dialog('destroy');
                $(this).remove();
            }
        });
        $('#AddMenuChoice').dialog('open');
    }, OnError, OnTimeOut);
}

function SetMenuChoice(PageID, args) {
    var Choice = $('input:radio[name=AddChoice]:checked').val();
    $('#AddMenuChoice').dialog('close');
    var InObject = new Object;
    InObject.PageID = PageID;
    InObject.Action = Choice;
    InObject.MenuSet = args;
    LeftMenuAction(InObject);
}

function SaveLeftMenuEntry() {
    if ($("input[name='MnuName']").val().length == 0) {
        jAlert('Das Feld Name darf nicht leer sein!', 'Fehler');
        return;
    }
    var InObject = new Object;
    InObject.Name = $("input[name='MnuName']").val();
    InObject.Title = $("input[name='MnuTitle']").val();
    InObject.PageID = $("label[name='MnuID']").text();
    InObject.MetaKeywords = $("input[name='MetaKeywords']").val();
    InObject.URLList = $("textarea[name='MnuURLs']").val();
    if ($("input[name='MnuItalic']").attr('checked') == 'checked') {
        InObject.IsItalic = true;
    } else {
        InObject.IsItalic = false;
    };
    if ($("input[name='MnuBold']").attr('checked') == 'checked') {
        InObject.IsBold = true;
    } else {
        InObject.IsBold = false
    };
    if ($("input[name='OnlyPreview']").attr('checked') == 'checked') {
        InObject.OnlyPreview = true;
    } else {
    InObject.OnlyPreview = false;
    };

    InObject.SpecialScripts = $("textarea[name='SpecialScripts']").val();
    InObject.SpecialMethods = $("textarea[name='SpecialMethods']").val();
    InObject.GoogleLinkPrio = $("select[name='GoogleLinkPrio']").val();
    if ($("select[name='MnuSelectSubLink']").val() != null) {
        InObject.SubLinkTo = $("select[name='MnuSelectSubLink']").val();
    } else {
        InObject.SubLinkTo = -999;
    };

    Dimatec.WebServices.Core.SaveLeftMenuEntry(InObject, function (args) {
        if (args.IsError) {
            jAlert(args.ErrorDescription, "Fehler beim Speichern");
        }
        //window.location.reload();
        $('#MenuEdit').dialog('close');
    }, OnError, OnTimeOut);
}

function LeftMenuAction(objIn) {
    Dimatec.WebServices.Core.SetLeftMenuContent(objIn, function (args) {
        if (args.ReloadIt) {
            window.location.reload();
        } else {

            LeftContentEdit();
        }

    }, OnError, OnTimeOut);
}

function RecurseBuildLeftMenu(xMem, args) {
    for (var i = 0; i < args.length; i++) {
        if (i == 0)
            var ul = $('<ul />');

        var li = $('<li />');
        var xEntry = 'Platzhalter';

        if (args[i].Name != '&nbsp;') {
            xEntry = args[i].Name;
        }

        if (!args[i].OnlyPreview) {
            //xEntry = '<strong>' + xEntry + '</strong>';
            li.css('color', '#00AA00');
        } else {
            li.css('color', '#AA0000');
        }

        if (i >= 0 & i < args.length - 1)
            xEntry += '<img src="/images/icons/arrow_down_green_24.png" id="DwnElement_' + args[i].PageID + '" alt="Nach unten" title="Element nach unten verschieben" style="cursor: pointer; width: 24px; height: 24px; border: none; vertical-align: middle; margin-left: 10px;" />';
        if (i <= args.length - 1 & i > 0)
            xEntry += '<img src="/images/icons/arrow_up_green_24.png" id="UpElement_' + args[i].PageID + '" alt="Nach oben" title="Element nach oben verschieben" style="cursor: pointer; width: 24px; height: 24px; border: none; vertical-align: middle; margin-left: 10px;" />';

        if (args[i].Name != '&nbsp;') {
            xEntry += '<img src="/images/icons/add_24.png" alt="Element hinzufügen" id="AddElement_' + args[i].PageID + '" title="Element hinzufügen" style="cursor: pointer; width: 24px; height: 24px; border: none; vertical-align: middle; margin-left: 10px;" />';
            xEntry += '<img src="/images/icons/spanner_24.png" id="EditElement_' + args[i].PageID + '" alt="Bearbeiten" title="Element bearbeiten" style="cursor: pointer; width: 24px; height: 24px; border: none; vertical-align: middle; margin-left: 10px;" />';
        }
        if (args[i].PageID != 1)
            xEntry += '<img src="/images/icons/cancel_24.png" id="DelElement_' + args[i].PageID + '" alt="Element entfernen" title="Element entfernen" style="cursor: pointer; width: 24px; height: 24px; border: none; vertical-align: middle; margin-left: 10px;" />';

        $(li).html(xEntry);
        $(ul).append(li);
        RecurseBuildLeftMenu($(li), args[i].SubMenuList);
        $(xMem).append(ul);
    }
}

function ImgContentEdit() {
    jAlert('Diese Funktion wird zu einem späteren Zeitpunkt zur Verfügung gestellt!', 'Achtung');
}

var tmpEditPageID;
function CntContentEdit() {
    $('#ContentEditContainer').remove();
    $('<div id="ContentEditContainer" />').appendTo('#form1');
    $('#ContentEditContainer').append('<div id="ContentEditBox" />');
    $("#ContentEditContainer").dialog({ bgiframe: true, height: 780, width: 830, title: 'Inhalt bearbeiten', modal: true, resizable: false, autoOpen: false,
        buttons: {
            'Speichern': function () {
                document.body.style.cursor = 'wait';
                var Ed = $('#ContentEditBox').ckeditorGet();
                var txt = Ed.getData();
                Ed.destroy();
                if (txt.length == 0) {
                    jAlert('Das Formular darf zum speichern nicht leer sein.', 'Achtung');
                    return;
                };
                var objInput = new Object;
                objInput.Content = txt;
                objInput.PageID = tmpEditPageID;
                Dimatec.WebServices.Core.SetCntContent(objInput, function (args) {
                    document.body.style.cursor = 'default';
                    $('#CPH_Content_Content').html(txt);
                    $("#ContentEditContainer").dialog('close');
                }, OnError, OnTimeOut);
            },
            'Abbrechen': function () {
                $("#ContentEditContainer").dialog('close');
            }
        },
        close: function () {
            cookies.CookieWrite('PageID', tmpEditPageID);
            tmpEditPageID = null;
            $(this).dialog('destroy');
            $(this).remove();
        },
        open: function () {
            $.getScript('/external/ckeditor/ckeditor.js', function () {
                $.getScript('/external/ckeditor/adapters/jquery.js', function () {
                    $.getScript('/external/ckfinder/ckfinder.js', function () {
                        $('#ContentEditBox').ckeditor(function () {
                            CKFinder.setupCKEditor(this, { basePath: '/external/ckfinder', rememberLastFolder: false });
                            Dimatec.WebServices.Core.GetCntContent(function (args) {
                                tmpEditPageID = args.PageID;
                                var Ed = $('#ContentEditBox').ckeditorGet();
                                Ed.setData(args.Content);
                            }, OnError, OnTimeOut);
                        });
                    });
                });
            });
        }
    });
    $('#ContentEditContainer').dialog('open');
}

function EditUser() {
    jAlert('Diese Funktion wird zu einem späteren Zeitpunkt zur Verfügung gestellt!', 'Achtung');
}

function RenderBtmBorder(Element) {
    var LyTop;
    var LyLeft;
    var LyWidth;
    var LyHeight;
    var OffSt = $(Element).offset();
    LyLeft = OffSt.left;
    LyTop = OffSt.top;
    LyWidth = $(Element).outerWidth();
    LyHeight = $(Element).outerHeight();
    $('#Btm_Brdr_Edit').remove();
    $('<div id="Btm_Brdr_Edit" style="position: absolute;" />').appendTo('#form1');
    $('#Btm_Brdr_Edit').hide();
    $('#Btm_Brdr_Edit').css('top', parseInt(LyTop - 3) + 'px');
    $('#Btm_Brdr_Edit').css('left', parseInt(LyLeft - 3) + 'px');
    $('#Btm_Brdr_Edit').css('width', parseInt(LyWidth + 3) + 'px');
    $('#Btm_Brdr_Edit').css('height', parseInt(LyHeight + 3) + 'px');
    $('#Btm_Brdr_Edit').css('border', 'solid 3px #333399');
    $('#Btm_Brdr_Edit').css('backgroundColor', '#aaaaff');
    $('#Btm_Brdr_Edit').css('z-index', '4');
    $('#Btm_Brdr_Edit').fadeTo(400, 0.8);
}

function RemoveBtmBorder() {
    $('#Btm_Brdr_Edit').remove();
}

function Logof() {
    cookies.CookieDelete('UserID');
    cookies.CookieDelete('UserName');
    cookies.CookieDelete('UserRole');
    cookies.CookieDelete('UserType');
    cookies.CookieWrite('IsLogon', false);
    window.location.href = '/StartSeite';
}

function CloseUserMenu() {
    $('#UserContainer').fadeOut(50, function () {
        $('#UserContainer').remove();
    });
}

function openMailDialog(inObj) {
    $('#MailDialog').remove();
    Dimatec.WebServices.Core.GetMailBody(inObj, function (args) {
        $('#form1').append(args);
        $('#MailDialog').dialog({ bgiframe: true, height: 700, width: 650, title: 'Mail versenden', modal: true, resizable: false, autoOpen: false,
            buttons: {
                'Absenden': function () {
                    var SendObject = new Object;
                    SendObject.Salutation = $("select[name^='MailSalutation']").val();
                    SendObject.MailTitle = $("select[name^='MailTitle']").val();
                    SendObject.MailFirstName = $("input[name^='MailFirstName']").val();
                    SendObject.MailLastName = $("input[name^='MailLastName']").val();
                    SendObject.MailCompany = $("input[name^='MailCompany']").val();
                    SendObject.MailDepartment = $("input[name^='MailDepartment']").val();
                    SendObject.MailPhoneNumber = $("input[name^='MailPhoneNumber']").val();
                    SendObject.MailMailAddress = $("input[name^='MailMailAddress']").val();
                    SendObject.MailTo = $("select[name^='MailTo']").val();
                    SendObject.MailText = $("textarea[name^='MailText']").val();

                    Dimatec.WebServices.Core.SendMail(SendObject, function (args) {
                        if (args.HasError) {
                            jAlert(args.MailError, "Fehler");
                        } else {
                            jAlert('Vielen Dank, Ihre Nachricht wurde übermittelt!', 'Hinweis', function () {
                                $('#MailDialog').dialog('close');
                            });
                        };
                    }, OnError, OnTimeOut);

                },
                'Abbrechen': function () {
                    $(this).dialog('close');
                }
            },
            close: function () {
                $(this).dialog('destroy');
                $(this).remove();
            }
        });
        $('#MailDialog').dialog('open');

    }, OnError, OnTimeOut);
}

function MarkElement(el) {
    $(el).css('border', '2px solid #ff0000');
}

function UnMarkElement(el) {
    $(el).css('border', '');
}

function AddMailEntry() {    
    Dimatec.WebServices.Core.GetNewMailElement(function (args) {
        $('#sortable').append(args);

        $('#DeleteMailEntry').css('display', '');
        $('#AddMailEntry').css('display', '');
        $('#MailConfigContainer').removeAttr('colspan');
        $("#sortable").sortable({
            placeholder: "ui-state-highlight"
        });
        $("#sortable").disableSelection();
    }, OnError, OnTimeOut);


}

function DeleteMailEntry() {
    var cnt = $('#sortable li').size();
    if (cnt > 0) {
        var theID = $("input[name='MailEmpfaenger']:checked").val()
        if (typeof theID == 'undefined') {
            jAlert('Sie müssen einen Eintrag zum l&ouml;schen ausw&auml;hlen', 'Fehler');
        } else {
            $('#ListElement_' + theID).remove();
        }
    } else {
        jAlert('Es muss sich mindestens ein Element in der List befinden!', 'Ahctung');
    }
}

function DeleteEmbeddedEntry() {
    var cnt = $("input[name='rd_Embed_Action']:checked").val();
    if (cnt == undefined) return -1;
    cnt = String(cnt).replace('EMB_RAD_VAL_', '');
    $('#EMB_TR_' + cnt).remove();
}

function DeleteExcludeEntry() {
    var cnt = $("input[name='rd_Exclude_Action']:checked").val();
    if (cnt == undefined) return -1;
    cnt = String(cnt).replace('EXC_RAD_VAL_', '');
    $('#EXC_TR_' + cnt).remove();
}

function EditSiteSettings() {
    $('#SiteSettings').remove();
    Dimatec.WebServices.Core.GetSiteSettings(function (args) {
        $('#form1').append(args);
        $('#SiteSettings').dialog({ bgiframe: true, height: 600, width: 800, title: 'Site-Einstellungen', modal: true, resizable: false, autoOpen: false,
            buttons: {
                'Speichern': function () {
                    var bolChk = true;
                    var InObject = new Object;
                    InObject.GoogleAnalytics = $("textarea[name='GoogleAnalytics']").val();
                    InObject.MailObject = new Array();
                    $('#sortable li').each(function (index) {
                        var eID = String(this.id).replace('ListElement_', '');
                        // if (eID > 0) {
                        if ($(this).find("input[name^='MName_']").val().length == 0) {
                            jAlert('Das Feld "Name im Men&uuml;" darf nicht leer sein', 'Achtung');
                            bolChk = false;
                            return false;
                        };
                        if ($(this).find("input[name^='MTo_']").val().length == 0) {
                            jAlert('Das Feld "Empf&auml;nger" darf nicht leer sein', 'Achtung');
                            bolChk = false;
                            return false;
                        };
                        var recObject = new Object;
                        recObject.SortOrder = index + 1;
                        recObject.ID = eID;
                        recObject.Name = $(this).find("input[name^='MName_']").val();
                        recObject.MailTo = $(this).find("input[name^='MTo_']").val();
                        recObject.MailCC = $(this).find("input[name^='MCC_']").val();
                        InObject.MailObject.push(recObject);
                        //};
                    });

                    //$('#tblEmbedded tr').each(function (index) {
                    InObject.EmbeddedObject = new Array();
                    $('#tblEmbedded [id^="EMB_TR_"]').each(function (index) {
                        var embObject = new Object;
                        var thisID = $(this).attr('id').substring($(this).attr('id').lastIndexOf('_') + 1);
                        embObject.ID = thisID;
                        embObject.Tag = $(this).find("input[name='EMB_TAG_NAME_" + thisID + "']").val();
                        embObject.Value = $(this).find("input[name='EMB_VAL_NAME_" + thisID + "']").val();
                        InObject.EmbeddedObject.push(embObject);
                    });

                    InObject.ExcludeValues = new Array();
                    $('#tblExcluded [id^="EXC_TR_"]').each(function (index) {
                        var thisIDx = $(this).attr('id').substring($(this).attr('id').lastIndexOf('_') + 1);
                        InObject.ExcludeValues.push($(this).find("input[name='EXC_VAL_NAME_" + thisIDx + "']").val());
                    });

                    InObject.MailServerName = $("input[name='MailServerName']").val();
                    InObject.MailServerPort = $("input[name='MailServerPort']").val();
                    InObject.UseCredentials = $("input[name='UseCredentials']").is(':checked');
                    InObject.MailUser = $("input[name='MailUser']").val();
                    InObject.MailPassword = $("input[name='MailPassword']").val();
                    InObject.MailSender = $("input[name='MailSender']").val();
                    InObject.MailSubject = $("input[name='MailSubject']").val();
                    InObject.MetaDescription = $("input[name='MetaDescription']").val();
                    InObject.ProjectName = $("input[name='ProjectName']").val();
                    InObject.BaseURL = $("input[name='BaseURL']").val();
                    if (!bolChk) return;

                    Dimatec.WebServices.Core.SetSiteSettings(InObject, function (args) {

                    }, OnError, OnTimeOut);
                    $(this).dialog('close');
                },
                'Abbrechen': function () {
                    $(this).dialog('close');
                }
            },
            close: function () {
                $(this).dialog('destroy');
                $(this).remove();
            }
        });
        $('#SiteSettings').dialog('open');


    }, OnError, OnTimeOut);
}

function CheckEmbeddedCode(strIN) {
    var inObject = new Object;
    inObject.EmbeddedCode = $("input[name='EMB_VAL_NAME_" + strIN + "']").val();
    if (String(inObject.EmbeddedCode).length == 0) {
        jAlert('Die Eingabe ist leer, hier kann nichts gepr&uuml;ft werden');
        return;
    }
    Dimatec.WebServices.Core.CheckEmbeddedCode(inObject, function (fn) {
        if (fn.HasError) {
            jAlert(fn.CheckResult, "Fehler");
        } else {
            jAlert(fn.CheckResult, "Alles OK");
        }
    }, OnError, OnTimeOut);

}

function AddEmbeddedEntry() {
    Dimatec.WebServices.Core.GetNewEmbeddedElement(function (args) {
        $('#tblEmbedded > tbody:last').append(args);
    }, OnError, OnTimeOut);
}

function AddExcludeEntry() {
    Dimatec.WebServices.Core.GetNewExcludeValueElement(function (args) {
        $('#tblExcluded > tbody:last').append(args);
    }, OnError, OnTimeOut);
}

function Logon() {
    $('#dialog-modal').remove();
    Dimatec.WebServices.Core.GetUserLogon(function (args) {
        $('#form1').append(args);
        $("#dialog-modal").dialog({ bgiframe: true, height: 240, width: 480, title: 'Benutzer anmelden', modal: true, resizable: false, autoOpen: false,
            buttons: {
                'Anmelden': function () {
                    if ($('#fldUserName').val().length == 0 || $('#fldPassword').val().length == 0) {
                        jAlert('Das Feld Benutzername und Passwort d&uuml;rfen f&uuml;r den Anmeldevorgang nicht leer sein!', 'Warnung');
                    } else {
                        var LogonObject = new Object;
                        LogonObject.UserName = Base64.encode_base64($('#fldUserName').val());
                        LogonObject.Password = Base64.encode_base64($('#fldPassword').val());

                        Dimatec.WebServices.Core.Logon(LogonObject, function (fn) {
                            cookies.CookieWrite('IsLogon', fn.IsLogon);
                            if (fn.IsLogon) {
                                cookies.CookieWrite('UserID', fn.UserID);
                                cookies.CookieWrite('UserName', fn.UserName);
                                cookies.CookieWrite('UserRole', fn.UserRole);
                                cookies.CookieWrite('UserType', fn.UserType);
                                //$('#INACT_HREF_999').text = 'Angemeldet';
                                $("a[name='INACT_HREF_999']").text = 'Angemeldet';
                                window.location.reload();
                            } else {
                                jAlert(fn.Message, 'Fehler');
                            }
                        }, OnError, OnTimeOut);
                    }
                    $(this).dialog('close');
                },
                'Abbrechen': function () {
                    $(this).dialog('close');
                }
            },
            close: function () {
                $(this).dialog('destroy');
                $(this).remove();
            }
        });
        $('#dialog-modal').dialog('open');
    }, OnError, OnTimeOut);
}

function OnError(args) {

}

function OnTimeOut() {

}
