﻿// JScript File
var eDiv;

function showExplain() {
    var cmd;
    eDiv = document.getElementById('explainDIV');
    if (eDiv) {
        eDiv.className = 'explainDIV';
        eDiv.style.opacity = 0;
        eDiv.style.filter = 'alpha(opacity=0)';
        for (var i = 0; i < 11; i++) {
            cmd = 'setOpacity(' + i + ')';
            window.setTimeout(cmd, 50*i);}
    }
}

function setOpacity(value) {
    eDiv.style.opacity = value * 0.1;
    eDiv.style.filter = 'alpha(opacity=' + value * 10 + ')';
    if (value == 0)
        eDiv.style.display = 'none';
    if (value == 1)
        eDiv.style.display = 'block';
}

function hideExplain() {
    var cmd;
    if (eDiv) {
        for (var i = 0; i < 11; i++) {
            cmd = 'setOpacity(' + (10 - i) + ')';
            window.setTimeout(cmd, 25*i);}        
    }
}

function KeyDownHandler() {
    var ctrl;
    var i;
    if (event.keyCode == 13) {
        event.returnValue = false;
        event.cancel = true;
        //Find out the OK button to click on it
        var con = document.getElementById('cont');
        for (i = 0; i < con.childNodes.length; i++) {
            ctrl = con.childNodes[i];
            if (ctrl.id)
                if (ctrl.id.indexOf("Button1") > 0)
                    ctrl.click();}
    }
}

function editAltText(PhotoID, AltTextID, CurText, obj) {
    //if (!e) 
    if (window.event) {
        var e = window.event;
    if (e.button == 2)   //Right button
        showEditComment(PhotoID, AltTextID, CurText, obj);
    else
        if (e.button == 1)    //Left button
            e.returnValue = true;
    }
}
function editAltText2(PhotoID, AltTextID, CurText, obj) {   //reageert op ondblclick
    //if (!e) 
    if (window.event) {
        var e = window.event;
    if (e.button == 1)   //Left button
        showEditComment(PhotoID, AltTextID, CurText, obj);
    else
        if (e.button == 2)    //Right button
            e.returnValue = true;
    }
}

function showEditComment(PhotoID, AltTextID, CurText, obj) {
    var top;
    var left;
    var ctrl, ctrl2;
    var textctrl;
    //var editComment is set by the server and is true when the user is authenticated
    if (editComment == true) {
        var d = document.getElementById('comment');
        if (d) {            
            top = calculateOffsetTop(obj) + 50;
            left = calculateOffsetLeft(obj) - 5;
            d.style.left = left + "px";
            d.style.top = top + "px";
            d.style.display = 'block';        
            for (var i = 0; i < d.children.length; i++) {
                ctrl = d.children[i];
                if (ctrl.id) {
                    if (ctrl.id == "commenttext") {
                        for (var j = 0; j < ctrl.children.length; j++) {
                            ctrl2 = ctrl.children[j];
                            if (ctrl2.id.indexOf("txtComment") > 0) {
                                var ct = unescape(CurText);
                                ctrl2.value = ct;
                                ctrl2.innerText = ct;
                                ctrl2.focus();
                                textctrl = ctrl2;
                            }
                        }
                    }
                    if (ctrl.id.indexOf("txtComment") > 0) {
                        ctrl.value = unescape(CurText);
                        ctrl.focus();
                        textctrl = ctrl;
                    }
                    if (ctrl.id.indexOf("hidPhotoID") > 0)
                        ctrl.value = PhotoID;  
                    if (ctrl.id.indexOf("hidAltTextID") > 0)
                        ctrl.value = AltTextID;              
                }
            }
            d.focus();
            d.style.display='block';
        }
    }
}

function hideEditComment() {
    var d = document.getElementById('comment');
    if (d)
        d.style.display = 'none';
}

function calculateOffsetLeft(field) {
    return calculateOffset(field, "offsetLeft");
}

function calculateOffsetTop(field) {
    return calculateOffset(field, "offsetTop");
}

function calculateOffset(field, attr) {
    var offset = 0;
    while (field) {
        offset += field[attr];
        field = field.offsetParent;
    }
    return offset;
}
