﻿/// <reference path="cookies.js" />
/// <reference path="jquery-1.4.2.min.js" />
/// <reference path="MicrosoftAjax.js" />
/// <reference path="WSMethods.js" />
/// <reference path="MultiEditContent.js" />
/// <reference path="EditCalendar.js" />
/// <reference path="ContextMenu.js" />
/// <reference path="PageEditComponent.js" />
/// <reference path="DialogInvitation.js" />
/// <reference path="PageContact.js" />
/// <reference path="GuestBook.js" />

function initApp() {
    if (CookieRead("UserID") == '')
        FirstTimeInit();
    CheckLogonMask();
    switch (CookieRead('ActivateMail')) {
        case '-1':
            switch (CookieRead('ActMailError')) {
                case '123':
                    jAlert('Beim freischalten des neuen Benutzers ist ein Fehler aufgetreten. Bitte senden Sie uns eine e-Mail an info@dasbabyalbum.de. Vielen Dank.', 'Fehler bei Benutzerfreischaltung');
                    break;
            }
            break;
        case '1':
            jAlert('Vielen Dank für Ihre Anmeldung bei www.dasbabyalbum.de. Um die Registrierung abzuschließen, bitten wir Sie im folgenden Dialog einige Eingaben vorzunehmen. Felder die mit einem roten Stern markiert sind, sind Pflichtpfelder.', 'Hinweis', function() {
                OpenUserEditDialog(true);
            });
            break;
        case '2':
            jAlert('Herzlichen Glückwunsch, nach dem Anmelden können Sie das soeben hinzugefügte Babyalbum unter "Meine Alben" finden, dort anklicken und betrachten.', 'Hinweis');
            CheckLogonMask();
            break;
        case '3':
            jAlert('Bevor Sie sich das Album anschauen können, bitten wir Sie, die Registrierung im folgenden Dialog abzuschließen. Felder die mit einem roten Stern markiert sind, sind Pflichtfelder.', 'Hinweis', function() {
                OpenUserEditDialog(true);
            });
            break;
        case '4':
            jAlert('Herzlichen Glückwunsch, nach dem Anmelden, können Sie die soeben hinzugefügten Babyalben unter "Meine Alben" finden, dort anklicken und betrachten.', 'Hinweis');
            CheckLogonMask();
            break;
        case '5':
            break;
        case '6':
            jAlert('Vielen Dank, wir haben soeben die e-Mail versendet.', 'Hinweis');
            break;
        case '7':
            jAlert('Um die Registrierung abzuschließen bitten wir Sie im folgenden Dialog, einige Eingaben zu machen. Felder die mit einem roten Stern markiert sind, sind Pflichtfelder', 'Hinweis', function() {
                CookieWrite('IsLogon', '1');
                OpenUserEditDialog(true);
            });
            break;
    }
   
    CookieDelete('ActivateMail');
    CookieDelete('ActMailError');
}

function CheckLogonMask() {
    if (CookieRead('UserID') == 'E8EE2D4D-402D-40a0-B20D-FC0A74325503') {
        $('#create-user').css('display', '');
        $('#edit-user').css('display', 'none');
        $('#logof-user').css('display', 'none');
        $('#new-user').css('display', '');
        $('#MyAlbum').css('display', 'none');
    } else {
        $('#create-user').css('display', 'none');
        $('#edit-user').css('display', '');
        $('#logof-user').css('display', '');
        $('#new-user').css('display', 'none');
        $('#MyAlbum').css('display', '');
        if (!CookieRead('FirstName') && !CookieRead('LastName')) {
            SetMsgLogon('Benutzer: ');
        } else {
            SetMsgLogon('Benutzer: ' + CookieRead('FirstName') + ' ' + CookieRead('LastName'));
        }
    }
    SetEditMode();
}

function SetEditMode() {
    if (CookieRead('UserMatchAlbum') == '1' && CookieRead('EditMode') == '1') {
        WebTest.WSData.GetContextMode(CookieRead('PageID'), CookieRead('AlbumID'), onSetEditMode, OnError, OnTimeOut);
    } else {
        onSetEditMode(false)
    }
}

function onSetEditMode(args) {
//    if (String(location.href).toLowerCase().substring(String(location.href).toLowerCase().lastIndexOf('/') + 1) != 'default.aspx') {
//        location.href = 'default.aspx';
//    }
    if (CookieRead('UserMatchAlbum') != '-1' && CookieRead('MyAlbum') != '1' && CookieRead('MyAlbum') != '3' && CookieRead('MyAlbum') != '4') {
        if (CookieRead('EditMode') == '-1') {
            $('#EditBook').css('display', '');
            $('#HelpBook').css('display', '');
            $('#UnEditBook').css('display', 'none');
            CookieWrite('ContextMode', '-1');
        } else {
            if (args == true) {
                CookieWrite('ContextMode', '1');
            } else {
                CookieWrite('ContextMode', '-1');
            }
            $('#UnEditBook').css('display', '');
            $('#EditBook').css('display', 'none');
        }
        if (parseInt(CookieRead('PageID')) > 0 && parseInt(CookieRead('PageID')) < 999) {
            $('#PageOption').css('display', '');
        } else {
            $('#PageOption').css('display', 'none');
        }
    } else {
        CookieWrite('EditMode', -1);
        CookieWrite('ContextMode', '-1');
        $('#EditBook').css('display', 'none');
        $('#HelpBook').css('display', 'none');
        $('#UnEditBook').css('display', 'none');
        $('#PageOption').css('display', 'none');
    }
    
    if (CookieRead('MyAlbum') == '3' && CookieRead('UserMode') == '255') {
        if (CookieRead('EditExt') == 1) {
            $('#EditExtSite').css('display', 'none');
            $('#UnEditExtSite').css('display', '');
        } else {
            $('#EditExtSite').css('display', '');
            $('#UnEditExtSite').css('display', 'none');
        }
    } else {
        $('#EditExtSite').css('display', 'none');
        $('#UnEditExtSite').css('display', 'none');
    }
    
    //Gästebuch
    if(CookieRead('MyAlbum') == '4') {
        //Schaltfläche "Neuer Gästebucheintrag" einblenden
        $('#CreateGuestBookEntry').css('display', '');
    } else {
        //Schaltfläche "Neuer Gästebucheintrag" ausblenden
        $('#CreateGuestBookEntry').css('display', 'none');
        CookieWrite('GBookState', '-1');
    }
    
    if (CookieRead('EditMode') == '1') {
        OpenWaitDialog();
        $.getScript('scripts/ui.draggable.js', function() {
            $.getScript('scripts/ui.droppable.js', function() {
                $.getScript('scripts/ui.resizable.js', function() {
                    $.getScript('scripts/contextmenu.js', function() {
                        $.getScript('scripts/elements.js', function() {
                            CloseWaitDialog();
                        });
                    });
                });
            });
        });
    }
    
    $('#EditWelcome').css('display', 'none');
    if (CookieRead('UserMode') == '255') {
        $('#EditWelcome').css('display', '');
    }
    SetPageParameters();
}

function SetPageParameters() {
    WebTest.WSData.GetPageParameter(CookieRead('AlbumID'), CookieRead('PageID'), onSetPageParameters, OnError, OnTimeOut);
}

function onSetPageParameters(args) {
    document.title = 'www.dasbabyalbum.de';
    if (args.ChildName.length > 0)
        document.title += ' - ' + args.ChildName;

    if (args.PageName.length > 0)
        document.title += ' - ' + args.PageName;

    __doPostBack('ctl00_ContentUpdatePanel', '');
}



function SetEditBook() {
    $('#WaitDialog').dialog('open');
    CookieWrite('EditMode', 1);
    SetEditMode();
    $('#WaitDialog').dialog('close');
}

function SetUnEditBook() {
    CookieWrite('EditMode', -1);
    SetEditMode();
}

function FirstTimeInit() {
    if (CookieRead("Rewritten") != '1') {
        CookieWrite('MyAlbum', '-1');
        CookieWrite('GBookState', '-1');
        CookieWrite('AlbumID', 'EEC71A96-3552-4280-98EE-7B626F443B7C');
    }
    CookieWrite('EditMode', -1);
    CookieWrite('ContextMode', -1);
    CookieWrite('UserMode', '0');
    CookieWrite('UserID', 'E8EE2D4D-402D-40a0-B20D-FC0A74325503');
    CookieWrite('PageSet', 'default');
    CookieWrite('BookSet', 'default');
    CookieWrite('BGSet', 'default');
    CookieWrite('PageID', 0);
    CookieWrite('UserMatchAlbum', -1);
    CookieWrite('UserFolder', -1);
    CookieWrite('IsLogon', -1);

    //Der Cookiewert MaxPage wird im Postback des UpdatePanels ermittelt und an die Seite übertragen, für später steht alternativ die WS-Methode GetMaxPageCount zur Verfügung!
    GetMaxPageCount();
    SetMsgLogon('Benutzer: Nicht angemeldet');
    document.getElementById('ctl00_css_def').href = 'css/' + CookieRead('PageSet') + '/sitemaster.css';
    if (CookieRead('WelcomeMessage') == false) {
        $("#hdSiteContent").val('0');
        GetSiteContent('0');
    }
}

function ResetUser() {
    CookieWrite('UserID', 'E8EE2D4D-402D-40a0-B20D-FC0A74325503');
    CookieWrite('PageSet', 'default');
    CookieWrite('BookSet', 'default');
    CookieWrite('BGSet', 'default');
    CookieWrite('UserMatchAlbum', -1);
    CookieWrite('ContextMode', -1);
    CookieWrite('EditMode', -1);
    CookieDelete('FirstName');
    CookieDelete('LastName');
    CookieWrite('UserFolder', -1);
    CookieWrite('IsLogon', -1);
    CookieWrite('MyAlbum', -1);
    CookieWrite('UserMode', '0');
    CookieWrite('PageID', '0');
    SetMsgLogon('Benutzer: Nicht angemeldet');
    CheckUserMatchAlbum();
    SetEditMode();
}

function NextGBPage() {
    var CurPage = parseInt(CookieRead('GBookState'));
    WebTest.WSData.GetGuestBookMaxPage(function(MaxPage) {
        if (CurPage >= MaxPage) {
            CookieWrite('GBookState', '9999');
            SetEditMode();
            return;
        } else {
            if (CurPage == 9999)
                return;
        }

        if (CurPage == 0) {
            CookieWrite('GBookState', MaxPage);
        } else {
            CookieWrite('GBookState', CurPage + 2);
        }
        SetEditMode();
    }, OnError, OnTimeOut);
}

function PrevGBPage() {
    var CurPage = parseInt(CookieRead('GBookState'));
    WebTest.WSData.GetGuestBookMaxPage(function(MaxPage) {
        if (CurPage == 9999) {
            CookieWrite('GBookState', MaxPage);
            SetEditMode();
            return;
        }

        if (CurPage == 0)
            return;

        if (CurPage <= 1) {
            CookieWrite('GBookState', '0');
        } else {
            CookieWrite('GBookState', CurPage - 2);
        }
        SetEditMode();
    }, OnError, OnTimeOut);
}

function RemoveGuestBookEntry(RemID) {
    WebTest.WSData.RemoveGBEntry(RemID, function(args) {
        SetEditMode();
    }, OnError, OnTimeOut);
}

function nextPage() {
    if (CookieRead('AlbumID') == 'EEC71A96-3552-4280-98EE-7B626F443B7C' && CookieRead('IsLogon') == '-1') {
        var CurPage = parseInt(CookieRead('PageID'));
        var MaxPage = parseInt(CookieRead('MaxPage'));
        if (CurPage + 1 == MaxPage) {
            CookieWrite('PageID', '999');
            SetEditMode();
            return;
        } else {
            if (CurPage == 999)
                return;
        }

        if (CurPage == 0) {
            CookieWrite('PageID', '1');
        } else {
            CookieWrite('PageID', CurPage + 2);
        }
        SetEditMode();
    } else {
        WebTest.WSData.CheckUserReadAlbum(CookieRead('UserID'), CookieRead('AlbumID'), function(args) {
            if (args) {
                var CurPage = parseInt(CookieRead('PageID'));
                var MaxPage = parseInt(CookieRead('MaxPage'));
                if (CurPage + 1 == MaxPage) {
                    CookieWrite('PageID', '999');
                    SetEditMode();
                    return;
                } else {
                    if (CurPage == 999)
                        return;
                }

                if (CurPage == 0) {
                    CookieWrite('PageID', '1');
                } else {
                    CookieWrite('PageID', CurPage + 2);
                }
                SetEditMode();
            } else {
                //alert('Keine Berechtigung');
                $.getScript('scripts/DialogInvitation.js', function() {
                    BuildInviteDialog();
                });
            }
        }, OnError, OnTimeOut);
    }
}

function prevPage() {
    if (CookieRead('AlbumID') == 'EEC71A96-3552-4280-98EE-7B626F443B7C' && CookieRead('IsLogon') == '-1') {
        var CurPage = parseInt(CookieRead('PageID'));
        var MaxPage = parseInt(CookieRead('MaxPage'));
        if (CurPage == 999) {
            CookieWrite('PageID', MaxPage - 1);
            SetEditMode();
            return;
        }
        if (CurPage == 0)
            return;

        if (CurPage == 1) {
            CookieWrite('PageID', '0');
        } else {
            CookieWrite('PageID', CurPage - 2);
        }
        SetEditMode();
    } else {
        WebTest.WSData.CheckUserReadAlbum(CookieRead('UserID'), CookieRead('AlbumID'), function(args) {
            if (args) {
                var CurPage = parseInt(CookieRead('PageID'));
                var MaxPage = parseInt(CookieRead('MaxPage'));
                if (CurPage == 999) {
                    CookieWrite('PageID', MaxPage - 1);
                    SetEditMode();
                    return;
                }
                if (CurPage == 0)
                    return;

                if (CurPage == 1) {
                    CookieWrite('PageID', '0');
                } else {
                    CookieWrite('PageID', CurPage - 2);
                }
                SetEditMode();
            } else {
                //alert('Keine Berechtigung');
                $.getScript('scripts/DialogInvitation.js', function() {
                    BuildInviteDialog();
                });
            }
        }, OnError, OnTimeOut);
    }
}

function gotoPage(ElementID) {
    if (CookieRead('AlbumID') == 'EEC71A96-3552-4280-98EE-7B626F443B7C' && CookieRead('IsLogon') == '-1') {
        CookieWrite('PageID', $('#' + ElementID).val());
        SetEditMode();
    } else {
        WebTest.WSData.CheckUserReadAlbum(CookieRead('UserID'), CookieRead('AlbumID'), function(args) {
            if (args) {
                CookieWrite('PageID', $('#' + ElementID).val());
                SetEditMode();
            } else {
                //alert('Keine Berechtigung');
                $.getScript('scripts/DialogInvitation.js', function() {
                    BuildInviteDialog();
                });
            }
        }, OnError, OnTimeOut);
    }
}

function SetMsgLogon(msg) {
    $('#msgLogon').html(msg);
}

function ClearLogonFields() {
    $('#fldUser').val('');
    $('#fldPassword').val('');
}

$(document).ready(function() {
    initApp();
    function log(event, data, formatted) {
        //alert(formatted.substring(0, formatted.indexOf('(') - 1));
        //Die Zahl auslesen
        if (typeof (formatted) != 'undefined') {
            var PgNr = formatted.substring(formatted.indexOf('(') + 1, formatted.indexOf('(') + 2);
            var ChildName;
            if (PgNr == 1) {
                ChildName = formatted.substring(0, formatted.indexOf('(') - 1);
                //2009-12-15, Entfernen wegen Test URL-Rewriting!
                //WebTest.WSData.GetAlbumIDByName(ChildName, OpenAlbum, OnError, OnTimeOut);
                //var LocName = String(ChildName).replace(" ", "_").replace("ä", "ae").replace("ö", "oe").replace("ü", "ue").replace("ß", "ss");
                //location.href = LocName;
                location.href = String(ChildName).replace(" ", "_");
            } else {
                ChildName = formatted.substring(0, formatted.indexOf('(') - 1);
                CookieWrite('ChildName', Base64.encode_base64(ChildName));
                OpenSearchAlbums()
            }
            $('#SearchAlbum').val('');
        }
    }

    $('#SearchAlbum').autocomplete('searchalbum.ashx', {
        width: 200,
        selectFirst: false,
        mustMatch: false
    });

    $("#SearchAlbum").result(log).next().click(function() {
        $(this).prev().search();
    });

    $('#WaitDialog').dialog({ modal: true, autoOpen: false, width: 240, height: 120, bgiframe: true, resizable: false });

    $('#WelcomeMessage').dialog({ modal: true, autoOpen: false, width: 800, height: 600, bgiframe: true, resizable: false,
        buttons: {
            'Schließen': function() {
                $(this).dialog('close');
            }
        }
    });

    $('#AlbumSettings').dialog({ modal: true, autoOpen: false, width: 800, height: 600, bgiframe: true, title: 'Globale Albumeinstellungen bearbeiten', resizable: false,
        buttons: {
            'Übernehmen': function() {

            },
            'Abbrechen': function() {
                $(this).dialog('close');
            }
        },
        close: function() {

        }
    });

    $('#logof-user').click(function() {
        ResetUser();
        CheckLogonMask();
    })
        .hover(
            function() {
                $(this).addClass("ui-state-hover");
            },
            function() {
                $(this).removeClass("ui-state-hover");
            }
        ).mousedown(function() {
            $(this).addClass("ui-state-active");
        })
         .mouseup(function() {
             $(this).removeClass("ui-state-active");
         });

    //OpenUserEditDialog();
    $('#edit-user').click(function() {
        OpenUserEditDialog(false);
    })
        .hover(
            function() {
                $(this).addClass("ui-state-hover");
            },
            function() {
                $(this).removeClass("ui-state-hover");
            }
        ).mousedown(function() {
            $(this).addClass("ui-state-active");
        })
         .mouseup(function() {
             $(this).removeClass("ui-state-active");
         });

    $('#Welcome').click(function() {
        $("#hdSiteContent").val('5');
        GetSiteContent('5');
    })
	.hover(
			function() {
			    $(this).addClass("ui-state-hover");
			},
			function() {
			    $(this).removeClass("ui-state-hover");
			}
		).mousedown(function() {
		    $(this).addClass("ui-state-active");
		})
		.mouseup(function() {
		    $(this).removeClass("ui-state-active");
		});

    $('#create-user').click(function() {
        CreateLogonWindow();
    })
		.hover(
			function() {
			    $(this).addClass("ui-state-hover");
			},
			function() {
			    $(this).removeClass("ui-state-hover");
			}
		).mousedown(function() {
		    $(this).addClass("ui-state-active");
		})
		.mouseup(function() {
		    $(this).removeClass("ui-state-active");
		});

    $('#new-user').click(function() {
        CreateNewUserDialog();
    })
		.hover(
			function() {
			    $(this).addClass("ui-state-hover");
			},
			function() {
			    $(this).removeClass("ui-state-hover");
			}
		).mousedown(function() {
		    $(this).addClass("ui-state-active");
		})
		.mouseup(function() {
		    $(this).removeClass("ui-state-active");
		});

    $('#EditBook').click(function() {
        SetEditBook();
    })
		.hover(
			function() {
			    $(this).addClass("ui-state-hover");
			},
			function() {
			    $(this).removeClass("ui-state-hover");
			}
		).mousedown(function() {
		    $(this).addClass("ui-state-active");
		})
		.mouseup(function() {
		    $(this).removeClass("ui-state-active");
		});

    $('#HelpBook').click(function() {
        $("#hdSiteContent").val('4');
        GetSiteContent('4');
    })
	.hover(
			function() {
			    $(this).addClass("ui-state-hover");
			},
			function() {
			    $(this).removeClass("ui-state-hover");
			}
		).mousedown(function() {
		    $(this).addClass("ui-state-active");
		})
		.mouseup(function() {
		    $(this).removeClass("ui-state-active");
		});

    $('#UnEditBook').click(function() {
        SetUnEditBook();
    })
		.hover(
			function() {
			    $(this).addClass("ui-state-hover");
			},
			function() {
			    $(this).removeClass("ui-state-hover");
			}
		).mousedown(function() {
		    $(this).addClass("ui-state-active");
		})
		.mouseup(function() {
		    $(this).removeClass("ui-state-active");
		});

    $('#PageOption').click(function() {
        OpenWaitDialog();
        $.getScript('scripts/ui.tabs.js', function() {
            $.getScript('scripts/PageEditComponent.js', function() {
                $.getScript('scripts/PageEdit.js', function() {
                    $.getScript('scripts/jquery.prettyphoto.js', function() {
                        BuildPageEditDialog();
                        PageEditOpen();
                        CloseWaitDialog();
                    });
                });
            });
        });
    })
    	.hover(
	    	function() {
	    	    $(this).addClass("ui-state-hover");
	    	},
		    function() {
		        $(this).removeClass("ui-state-hover");
		    }
	    ).mousedown(function() {
	        $(this).addClass("ui-state-active");
	    })
	    .mouseup(function() {
	        $(this).removeClass("ui-state-active");
	    });


    $('#ShowImpressum').click(function() {
        $("#hdSiteContent").val('1');
        GetSiteContent('1');
    })
		.hover(
			function() {
			    $(this).addClass("ui-state-hover");
			},
			function() {
			    $(this).removeClass("ui-state-hover");
			}
		).mousedown(function() {
		    $(this).addClass("ui-state-active");
		})
		.mouseup(function() {
		    $(this).removeClass("ui-state-active");
		});

    $('#ShowFAQ').click(function() {
        $('#hdSiteContent').val('2');
        GetSiteContent('2');
    })
		.hover(
			function() {
			    $(this).addClass("ui-state-hover");
			},
			function() {
			    $(this).removeClass("ui-state-hover");
			}
		).mousedown(function() {
		    $(this).addClass("ui-state-active");
		})
		.mouseup(function() {
		    $(this).removeClass("ui-state-active");
		});

    $('#ShowHello').click(function() {
        $('#hdSiteContent').val('3');
        GetSiteContent('3');
    })
		.hover(
			function() {
			    $(this).addClass("ui-state-hover");
			},
			function() {
			    $(this).removeClass("ui-state-hover");
			}
		).mousedown(function() {
		    $(this).addClass("ui-state-active");
		})
		.mouseup(function() {
		    $(this).removeClass("ui-state-active");
		});

    $('#ShowContact').click(function() {
        OpenWaitDialog();
        $.getScript('scripts/PageContact.js', function() {
            BuildContactDialog();
            CloseWaitDialog();
        });
    })
		.hover(
			function() {
			    $(this).addClass("ui-state-hover");
			},
			function() {
			    $(this).removeClass("ui-state-hover");
			}
		).mousedown(function() {
		    $(this).addClass("ui-state-active");
		})
		.mouseup(function() {
		    $(this).removeClass("ui-state-active");
		});

    $('#ShowGuestBook').click(function() {
        GotoGuestBook();
    })
		.hover(
			function() {
			    $(this).addClass("ui-state-hover");
			},
			function() {
			    $(this).removeClass("ui-state-hover");
			}
		).mousedown(function() {
		    $(this).addClass("ui-state-active");
		})
		.mouseup(function() {
		    $(this).removeClass("ui-state-active");
		});

    $('#CreateGuestBookEntry').click(function() {
        OpenWaitDialog();
        $.getScript('scripts/GuestBook.js', function() {
            BuildGuestBookDialog();
            CloseWaitDialog();
        });
    })
		.hover(
			function() {
			    $(this).addClass("ui-state-hover");
			},
			function() {
			    $(this).removeClass("ui-state-hover");
			}
		).mousedown(function() {
		    $(this).addClass("ui-state-active");
		})
		.mouseup(function() {
		    $(this).removeClass("ui-state-active");
		});
    $('#NewAlbum').click(function() {
        CreateNewAlbumDialog();
    })
		.hover(
			function() {
			    $(this).addClass("ui-state-hover");
			},
			function() {
			    $(this).removeClass("ui-state-hover");
			}
		).mousedown(function() {
		    $(this).addClass("ui-state-active");
		})
		.mouseup(function() {
		    $(this).removeClass("ui-state-active");
		});
    $('#MyAlbum').click(function() {
        OpenMyAlbum();
    })
		.hover(
			function() {
			    $(this).addClass("ui-state-hover");
			},
			function() {
			    $(this).removeClass("ui-state-hover");
			}
		).mousedown(function() {
		    $(this).addClass("ui-state-active");
		})
		.mouseup(function() {
		    $(this).removeClass("ui-state-active");
		});

    $('#StartPage').click(function() {
        GotoStartPage();
    })
		.hover(
			function() {
			    $(this).addClass("ui-state-hover");
			},
			function() {
			    $(this).removeClass("ui-state-hover");
			}
		).mousedown(function() {
		    $(this).addClass("ui-state-active");
		})
		.mouseup(function() {
		    $(this).removeClass("ui-state-active");
		});

    $('#ShowPartner').click(function() {
        GotoExtSite(5);
    })
		.hover(
			function() {
			    $(this).addClass("ui-state-hover");
			},
			function() {
			    $(this).removeClass("ui-state-hover");
			}
		).mousedown(function() {
		    $(this).addClass("ui-state-active");
		})
		.mouseup(function() {
		    $(this).removeClass("ui-state-active");
		});

    $('#EditExtSite').click(function() {
        CookieWrite('EditExt', '1');
        $.getScript('external/fckeditor/fckeditor.js', function() {
            SetPageInEditMode();
        });
    })
		.hover(
			function() {
			    $(this).addClass("ui-state-hover");
			},
			function() {
			    $(this).removeClass("ui-state-hover");
			}
		).mousedown(function() {
		    $(this).addClass("ui-state-active");
		})
		.mouseup(function() {
		    $(this).removeClass("ui-state-active");
		});

    $('#UnEditExtSite').click(function() {
        CookieDelete('EditExt');
        SetPageInUnEditMode();
    })
		.hover(
			function() {
			    $(this).addClass("ui-state-hover");
			},
			function() {
			    $(this).removeClass("ui-state-hover");
			}
		).mousedown(function() {
		    $(this).addClass("ui-state-active");
		})
		.mouseup(function() {
		    $(this).removeClass("ui-state-active");
		});

});
