
var isCtrl = false;
var isShift = false;
var ls = -1;
function MOutBgColor(obj) {
    if (obj.style.backgroundColor != "#e2e2e2") {
        obj.style.backgroundColor = "white";
    }
}
function MOverBgColor(obj) {

    if (obj.style.backgroundColor != "#e2e2e2") {
        obj.style.backgroundColor = "#f7ecea";
    }
}
function Open(obj) {
    ItemSingleSelect(obj);
    window.external.GotoSelectedBookunit();
}
function MDown(obj) {
    //trace right button of mouse
    if (event.button == 2) {
        ItemSingleSelect(obj);
        window.external.ShowNotebookContextMenu(event.clientX, event.clientY);

    }
}
function ItemSingleSelect(obj) {
    $("td div").each(function () {
        if ($(this).attr("id") != obj.id) {
            $(this).css("backgroundColor", "white");
        }
    });
    var bgColor = obj.style.backgroundColor;
    //unselected
    if (bgColor != "#e2e2e2") {
        obj.style.backgroundColor = "#e2e2e2";
    }
    window.external.GetNotebookSingleSelected(obj.id);
}
function ItemSelect(obj) {
    var i = 0;

    if (!isShift) {
        ls = $(obj).find("input").eq(0).val();
    }

    if (!isShift) {
        if (!isCtrl) {
            $("td div").each(function () {
                if ($(this).css("backgroundColor") == "#e2e2e2") {
                    i++;
                }
                if ($(this).attr("id") != obj.id) {
                    $(this).css("backgroundColor", "white");
                }
            });
        }
        var bgColor = obj.style.backgroundColor;
        //unselected
        if (bgColor == "#e2e2e2") {
            if (i <= 1) {
                obj.style.backgroundColor = "#f7ecea";
            }
        }
        else {
            obj.style.backgroundColor = "#e2e2e2";
        }

        window.external.GetNotebookSelected(obj.id, isCtrl);
    }
    else {
        if (ls == -1) {
            ls = $(obj).find("input").eq(0).val();
            var bgColor = obj.style.backgroundColor;
            obj.style.backgroundColor = "#e2e2e2";
            window.external.GetNotebookSelected(obj.id, isCtrl);

        }
        else {
            var tm = $(obj).find("input").eq(0).val();
            var ils = parseInt(ls);
            var itm = parseInt(tm);
            if (ils > itm) {
                ils = ils + itm;
                itm = ils - itm;
                ils = ils - itm;
            }
            var ids = "";

            $("td div").each(function () {
                var t = $(this).find("input").eq(0).val();
                var it = parseInt(t);
                if (ils <= it && it <= itm) {
                    $(this).css("backgroundColor", "#e2e2e2");
                    ids = ids + $(this).attr("id") + ",";
                }
                else {
                    $(this).css("backgroundColor", "white");
                }
            });

            window.external.GetNotebookSuccessiveSlt(ids);
        }
    }
    i = 0;
}
function initializelLs() {
    ls = -1;
}
function ClearSelected() {
    $("td div").each(function () {
        $(this).css("backgroundColor", "white")
    });
}
function fixPNG(myImage) {
    var arVersion = navigator.appVersion.split("MSIE");
    var version = parseFloat(arVersion[1]);
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
        var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";
        var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";
        var imgTitle = (myImage.title) ? "title='" + myImage.title + "' " : "title='" + myImage.alt + "' ";
        var imgStyle = "display:inline-block;" + myImage.style.cssText;
        var strNewHTML = "<span " + imgID + imgClass + imgTitle

      + " style=\"" + "width:" + myImage.width

      + "px; height:" + myImage.height

      + "px;" + imgStyle + ";"

      + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"

      + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";
        myImage.outerHTML = strNewHTML;
    }
}

