﻿var __LastParent;
var __LastNode;
var btnOk_ClientID;
var btnCancel_ClientID;

function pageLoad(sender, args) {
    var modal = $find("modalUpdate");
    if (modal)
        modal.add_hidden(OnModalPopupHidden);

    InitializeUpdateProgress();
}

/*************** Update Progress ***************/
var prm = Sys.WebForms.PageRequestManager.getInstance();
var postBackElement;

function InitializeUpdateProgress() {
    prm.add_initializeRequest(InitializeRequest);
    prm.add_endRequest(EndRequest);

//    var btnCancel = $get(btnCancel_ClientID);
}

function InitializeRequest(sender, args) {
    if (prm.get_isInAsyncPostBack())
        args.set_cancel(true);

    $(".update_progress").css("display", "block");
//    postBackElement = args.get_postBackElement();
}
function EndRequest(sender, args) {
    $(".update_progress").css("display", "none");
} 

/******************* Modal Popup *************/
function ShowPopup(title, contentControlID, okText, onOkScript, cancelTitle) {
    __ShowPopup(title, $get(contentControlID), okText, onOkScript, cancelTitle);
}

function ShowMessageBox(title, text) {
    __ShowPopupWithText(title, text);
}

function ShowConfirm(title, text, onOkScript) {
    //    $get("modalPopup_Title").innerHTML = title;
    //    $get("modalPopup_Content").innerHTML = "<span>" + text + "</span>";

    //    var btnOk = $get(btnOk_ClientID);
    //    btnOk.value = "Ja";
    //    btnOk.onclick = onOkScript;
    //    $get(btnCancel_ClientID).value = "Nein";

    //    $find("modalUpdate").show();

    __ShowPopupWithText(title, text, "Ja", onOkScript, "Nein");
}

function __ShowPopupWithText(title, newContent, okText, onOkScript, cancelTitle) {
    __ShowPopup(title, document.createTextNode(newContent), okText, onOkScript, cancelTitle);
}

function __ShowPopup(title, newContentNode, okText, onOkScript, cancelTitle) {
    $get("modalPopup_Title").innerHTML = title;

    var content = $("#modalPopup_Content");
    __LastParent = newContentNode.parentNode;
    __LastNode = newContentNode;
    content.append(newContentNode);
    if (newContentNode.style)
        newContentNode.style.display = "block";

    var btnOk = $get(btnOk_ClientID);
    var btnCancel = $get(btnCancel_ClientID);

    if (okText != null) {
        btnOk.value = okText;
        if (onOkScript != null)
            btnOk.onclick = onOkScript;

        if (cancelTitle != null) {
            btnCancel.style.display = "inline";
            btnCancel.value = cancelTitle;
        }
        else {
            btnCancel.style.display = "none";
            btnCancel.value = "Abbrechen";
        }
    }
    else {
        btnOk.value = "OK";
        btnOk.onclick = null;
        btnCancel.style.display = "none";
    }

    var modal = $find("modalUpdate");
    modal.show();
}

function OnModalPopupHidden() {
    var content = $("#modalPopup_Content");

    if (__LastParent != null && __LastNode != null) {
        __LastNode.style.display = "none";
        __LastParent.appendChild(__LastNode);
    }
    content.empty();
}


//$(document).ready(function() {
//    $(".trash").mouseenter(trash_MouseOver);
//    $(".trash").mouseleave(trash_MouseOut);
//});

function trash_MouseOver(element) {
    var elem = element;
    elem.old_src = elem.src;
    var newSrc = elem.old_src;
    var index = elem.src.lastIndexOf("/");
    newSrc = newSrc.substring(0, index);
    elem.src = newSrc + "/" + "Trash-Full.png";
}

function trash_MouseOut(element) {
    var elem = element;
    elem.src = elem.old_src;
}

