﻿//--- Indien ajax
//--- prototype.js moet geladen zijn

var path_images = '/dante/images/default';
var path_icons = path_images + '/icons';

var ua = navigator.userAgent
var cssFilters = ((ua.indexOf("MSIE 5.5") >= 0 || ua.indexOf("MSIE 6") >= 0 || ua.indexOf("MSIE 7") >= 0) && ua.indexOf("Opera") < 0) ? 1 : 0
var blnFiltersEnabled = 0
var tbody
var intMouseX = 0;
var intMouseY = 0;
var blnIE = (document.all) ? 1 : 0
var blnDom = (document.getElementById) ? 1 : 0
//var popupwindow = document.getElementById('popupwindow');
var grabx = 0;
var graby = 0;
var orix = 0;
var oriy = 0;
var elex = 0;
var eley = 0;
var dragobj = null;
var intWindowWidth = 0;
var intWindowHeight = 0;
var intScrollTop = 0;
var intScrollLeft = 0;
var js_FncHide = null;

addPopupElement();

/*
Size[0]=[1000,270]
Size[1]=[300,230]
Size[2]=[300,70]
Size[3]=[10,180]
Size[4]=[500,180]
Size[5]=[320,130]
Size[6]=[500,400]
Size[7]=[800,600]
Size[8]=[550,460]
Size[9]=[550,540]
Size[10]=[500,280]
*/

//document.onmousemove = getMousePosition;

// LET OP:
// zo'n zelfde event wordt toegepast op de BODY die in het IFRAME wordt geladen
function eventEscape(e) {
    if (e == null)
        e = window.event;

    if (e.keyCode == 27)	//Escape toets
    {
        hidePopup();
    }
}

function addPopupElement() {
    if (document.getElementById('popupwindow') == null) {
        var strResult = '';
        strResult += '<div id="popupwindow" style="position: absolute; top: -1000px; visibility: hidden; left: -1000px; z-index: 999; width: 10px; height: 10px" onmousedown="grab(this);hideContent()" onmouseup="showContent()" onselectstart="return false" onkeydown="eventEscape()">';

        strResult += '	<table id="popupwindow_table" border="0" style="margin: 0; padding: 0;" cellpadding="0" cellspacing="0" width="100%" height="100%">';
        strResult += '		<tr>';
        strResult += '			<td id="popupwindow_header">';
        strResult += '				<table border="0" cellpadding="0" cellspacing="0" width="100%">';
        strResult += '					<tr>';
        strResult += '						<td id="popupwindow_header_text">HEADER&nbsp;</td>';
        strResult += '						<td id="popupwindow_header_close" onClick="hidePopup();" onmousedown="return stopBubble();"><img src="' + path_images + '/popup_close.gif" border="0" alt="Sluiten"/></td>';
        strResult += '					</tr>';
        strResult += '				</table>';
        strResult += '			</td>';
        strResult += '		</tr>';
        strResult += '		<tr>';
        strResult += '			<td valign="top" id="popupwindow_content" style="width: 100%; height: 100%; border: 0px solid black">&nbsp;</td>';
        strResult += '		</tr>';
        strResult += '	</table>';
        strResult += '	</div>';

        document.write(strResult)
    }
}


function hideContent() {
    document.getElementById('popupwindow_content').style.visibility = 'hidden'
}

function showContent() {
    document.getElementById('popupwindow_content').style.visibility = 'visible'
}



function showPopupUrl(p_strURL, p_arrSize) {
    showPopup('', '', p_strURL, p_arrSize[0], p_arrSize[1]);
}

function showPopupUrl(p_strURL, p_intWidth, p_intHeight) {
    showPopup('', '', p_strURL, p_intWidth, p_intHeight);
}


function showPopup(p_strHeader, p_strText, p_strURL, p_intWidth, p_intHeight, p_blnScroll, p_js_FncHide) {
    var blnUseMousePosition = false;
    var intOffsetX = 6;
    var intOffsetY = 6;
    var intLeft = 0;
    var intTop = 0;
    var popupwindow = document.getElementById('popupwindow');

    if (p_blnScroll == null)
        p_blnScroll = true;
    //alert(p_blnScroll);

    if (p_js_FncHide != 'undefined')
        js_FncHide = p_js_FncHide;
    else
        js_FncHide = null;

    if (popupwindow == null) {
        // element toevoegen.
    }

    getPopupWindowSize(); // afmetingen Windows (dus niet body)
    //alert(' win = ' + intWindowWidth + ',' + intWindowHeight);
    getPopupScrollOffset(); // offset van de Body (body-coordinaat op linkerkant scherm, normaal is dit 0)

    if (blnUseMousePosition) {
        getMousePosition(); // positie Mouse binnen Body
    } else {
        intOffsetX = 0;
        intOffsetY = 50;
        intMouseX = intScrollLeft + ((intWindowWidth - p_intWidth) / 2);
        intMouseY = 0;
    }

    intMouseX = parseFloat(intMouseX);
    intMouseY = parseFloat(intMouseY);
    p_intWidth = parseFloat(p_intWidth);
    p_intHeight = parseFloat(p_intHeight);
    intOffsetX = parseFloat(intOffsetX);
    intOffsetY = parseFloat(intOffsetY);
    intWindowWidth = parseFloat(intWindowWidth);
    intWindowHeight = parseFloat(intWindowHeight);
    intScrollLeft = parseFloat(intScrollLeft);
    intScrollTop = parseFloat(intScrollTop);

    if ((intMouseX + p_intWidth + intOffsetX) >= (intWindowWidth + intScrollLeft)) {
        //alert('A: x = ' + intMouseX + ' y = ' + intMouseY);
        intLeft = (intWindowWidth + intScrollLeft) - (p_intWidth + intOffsetX);
    }
    else {
        intLeft = (intMouseX + intOffsetX);
    }

    if (intLeft < intScrollLeft) {
        intLeft = intScrollLeft;
    }

    //alert('window size = ' + intWindowWidth + ' ' + intWindowHeight + '\nScroll = ' + intScrollLeft + ' ' + intScrollTop + '\nMouse = ' + intMouseX + ' ' + intMouseY);

    if ((intMouseY + p_intHeight + intOffsetY) >= (intWindowHeight + intScrollTop)) {
        //alert('B: x = ' + intMouseX + ' y = ' + intMouseY);
        intTop = (intWindowHeight + intScrollTop) - (p_intHeight + intOffsetY);
    }
    else {
        intTop = (intMouseY + intOffsetY);
    }

    if (intTop < intScrollTop + intOffsetY) {
        intTop = intScrollTop + intOffsetY;
    }

    if (blnDom == false) {
        window.open(p_strURL, p_strHeader, 'width=' + p_intWidth + 'px,height=' + p_intHeight + 'px,left=' + intLeft + ',top=' + intTop + ',scrollbars=1');
    }
    else {
        if (p_strHeader == '') {
            p_strHeader = '&nbsp;';
        }

        document.getElementById('popupwindow_header_text').innerHTML = p_strHeader;

        // (dit moet eigenlijk eerder, om positie van het window te bepalen moet je namelijk de afmetingen weten.)
        if (p_intWidth == null || p_intWidth == 0 || p_intHeight == 0) {
            popupwindow.style.width = 'auto';
            popupwindow.style.height = 'auto';
        } else {
            popupwindow.style.width = p_intWidth + 'px';
            popupwindow.style.height = p_intHeight + 'px';
        }

        popupwindow.style.left = intLeft + 'px';
        popupwindow.style.top = intTop + 'px';

      if (p_strText != '') {
            document.getElementById('popupwindow_content').innerHTML = p_strText;
        }
        else if (p_strURL != '') {
          var strScroll;
            var strStyle;
            if (p_blnScroll) {
                strScroll = "scrolling='auto'";
                strStyle = 'overflow: auto; '
            } else {
                strScroll = "scrolling='no'";
                strStyle = 'overflow: hidden; '
            }
            //alert('style = ' + strStyle + ' scroll = ' + strScroll);
            document.getElementById('popupwindow_content').innerHTML = "<iframe name='iframe_popupwindow' id='iframe_popupwindow' " + strScroll + " style='" + strStyle + " width: 100%; height: 100%;' frameborder='0' src='" + p_strURL + "'></iframe>";
            //document.getElementById('popupwindow_content').innerHTML = "<iframe name='iframe_popupwindow' id='iframe_popupwindow' scrolling='" + strScroll + "' style='overflow: auto; width: 100%; height: 100%;' frameborder='0' src='" + p_strURL + "'></iframe>";
            //alert('size = ' + document.getElementById('iframe_popupwindow').contentWindow.document.body);
        }

        popupwindow.style.visibility = 'visible';
    }
}


function getLoadingAnimation() {
    //document.getElementById('popupwindow_content').innerHTML = "<table border='0' width='100%' height='100%'><tr><td valign='middle' align='center'><img src='../images/loader.gif' border='0' width='32' height='32' alt=''/></td></tr></table>";
}


function hidePopup() {
    var popupwindow = document.getElementById('popupwindow');

    popupwindow.style.left = '-1000px';
    popupwindow.style.top = '-1000px';
    popupwindow.style.visibility = 'hidden';

    if (js_FncHide)
        js_FncHide();

    //getLoadingAnimation();
}



// vergelijk alleen met null (of de variabele bestaat), want inhoudelijk is 0 wel toegestaan.
function getMousePosition(e) {
    if (!e) e = window.event;

    /*  if (e)
    { 
    if (e.pageX || e.pageY)
    {
    intMouseX = e.pageX;
    intMouseY = e.pageY;
    }
    else if (e.clientX || e.clientY)
    {
    intMouseX = e.clientX + document.body.scrollLeft;
    intMouseY = e.clientY + document.body.scrollTop;
    }  
    }*/

    if (e) {
        if (e.pageX != null || e.pageY != null) {
            intMouseX = e.pageX;
            intMouseY = e.pageY;
        }
        else if (e.clientX != null || e.clientY != null) {
            intMouseX = e.clientX;
            intMouseY = e.clientY;
        }
    }

    getPopupScrollOffset();

    intMouseX += intScrollLeft;
    intMouseY += intScrollTop;
}



function getPopupWindowSize() {
    intWindowWidth = document.documentElement.clientWidth;
    intWindowHeight = document.documentElement.clientHeight;
    if (intWindowWidth == 0) {
        // als IE in quirks mode zit.
        intWindowWidth = document.body.clientWidth;
        intWindowHeight = document.body.clientHeight;
    }
    if (intWindowWidth == 0) {
        intWindowWidth = window.innerWidth;
        intWindowHeight = window.innerHeight;
    }
}


// vergelijk alleen met null (of de variabele bestaat), want inhoudelijk is 0 wel toegestaan.
function getPopupScrollOffset() {
    intScrollTop = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        intScrollTop = window.pageYOffset;
        intScrollLeft = window.pageXOffset;
    }
    else if (document.body != null && (document.body.scrollLeft != null || document.body.scrollTop != null)) {
        //DOM compliant
        intScrollTop = document.body.scrollTop;
        intScrollLeft = document.body.scrollLeft;
    }
    
   if ((intScrollTop == 0) && (document.documentElement != null && (document.documentElement.scrollLeft != null || document.documentElement.scrollTop != null))) {
    //if (intScrollTop == 0 && intScrollLeft == 0) {
        //IE6 standards compliant mode
        intScrollTop = document.documentElement.scrollTop;
        intScrollLeft = document.documentElement.scrollLeft;
    }

    if (intScrollTop == 0 && intScrollLeft == 0) {
        //IE6 standards compliant mode
        intScrollTop = document.body.scrollTop;
        intScrollLeft = document.body.scrollLeft;
    }

}


//Drag & Drop

var grabx = 0;
var graby = 0;
var orix = 0;
var oriy = 0;
var elex = 0;
var eley = 0;

var dragobj = null;

function falsefunc() {
    return false;
}

function grab(context) {
    getMousePosition()

    document.onmousedown = falsefunc;
    dragobj = context;
    dragobj.style.zIndex = 999;
    dragobj.style.cursor = 'move';
    document.onmousemove = drag;
    document.onmouseup = drop;
    grabx = intMouseX;
    graby = intMouseY;
    elex = orix = dragobj.offsetLeft;
    eley = oriy = dragobj.offsetTop;

}

function drag(e) {
    if (dragobj) {
        getMousePosition()

        if (dragobj.style.width == 'auto') {
            // breedte,hoogte vastzetten.
            var w, h;
            w = dragobj.offsetWidth;
            h = dragobj.offsetHeight;
            dragobj.style.width = w;
            dragobj.style.height = h;
        }

        elex = orix + (intMouseX - grabx);
        eley = oriy + (intMouseY - graby);

        dragobj.style.position = "absolute";
        dragobj.style.left = (elex).toString(10) + 'px';
        dragobj.style.top = (eley).toString(10) + 'px';
    }

    return false;
}

function drop() {
    if (dragobj) {
        dragobj.style.cursor = '';
        dragobj.style.zIndex = 999;
        dragobj = null;
    }

    document.onmouseup = null;
    document.onmousedown = null;
    document.onmousemove = null;
}

