
/*
 * Javascript for xpopup widget
 */

function xpopupOpen(evt, obj, width, height) {

	// Return immediately if object doesn't exist
	obj = getRawObject(obj);
	if (! obj) {
		return;
	}

	// Stop the event from propagating to lower elements
    evt = (evt) ? evt : ((event) ? event : null);
    if (evt) {
        evt.cancelBubble = true;
    }

	// Hide SELECT controls as these bleed thru xpopup DIV
    cl=document.getElementsByTagName('select');
    for (cn = 0; cn < cl.length; cn++){ 
        cl[cn].style.visibility = 'hidden';
	}
	/*
    cl=document.getElementsByTagName('embed');
    for (cn = 0; cn < cl.length; cn++){ 
        cl[cn].style.visibility = 'hidden';
	}
	*/

	if (!width) {
        width = 60;
	}
	if (!height) {
        height = 60;
	}

    innerDiv = getInnerDIV(obj);

	winHeight = getInsideWindowHeight();
	winWidth = document.body.offsetWidth;

	// Set the width as a percentage of browser window size
    popWidth = Math.round(winWidth * width / 100);
    setStyle(obj, "width", popWidth + "px");

    // Only set the width of the inner DIV with are NOT in IE
    if (!isIE) {
        innerWidth = popWidth - 26;
        setStyle(innerDiv, "width", innerWidth + "px");
    }

	// Set the height as a percentage of browser window size
    popHeight = Math.round(winHeight * height / 100);
    setStyle(innerDiv, "height", popHeight + "px");

    // Calculate the co-ordinates to set the popup in the middle
	popTop = (winHeight - popHeight) / 2 + document.body.scrollTop;
	popLeft = (winWidth - popWidth) / 2;

    // Set the popup position
	setStyle(obj, "top", popTop + "px");
	setStyle(obj, "left", popLeft + "px");

	// Display it
	setStyle(obj, "display", "block");
}

function jws_xpopupOpen(obj, width, height) {

	// Return immediately if object doesn't exist
	obj = getRawObject(obj);
	if (! obj) {
		return(-1);
	}

	// Hide SELECT controls as these bleed thru xpopup DIV
    cl=document.getElementsByTagName('select');
    for (cn = 0; cn < cl.length; cn++){ 
        cl[cn].style.visibility = 'hidden';
	}
	/*
    cl=document.getElementsByTagName('embed');
    for (cn = 0; cn < cl.length; cn++){ 
        cl[cn].style.visibility = 'hidden';
	}
	*/

	if (!width) {
        width = 60;
	}
	if (!height) {
        height = 60;
	}

    innerDiv = getInnerDIV(obj);

	winHeight = getInsideWindowHeight();
	winWidth = document.body.offsetWidth;

	// Set the width
    popWidth = width;
    setStyle(obj, "width", popWidth + "px");

    // Only set the width of the inner DIV if we are NOT using IE
    if (!isIE) {
        /*
        innerWidth = popWidth - 26;
        setStyle(innerDiv, "width", innerWidth + "px");
        */
        setStyle(innerDiv, "width", "100%");
    }

	// Set the height
    popHeight = height;
    setStyle(innerDiv, "height", popHeight + "px");

    // Calculate the co-ordinates to set the popup in the middle
	popTop = (winHeight - popHeight) / 2 + document.body.scrollTop;
	popLeft = (winWidth - popWidth) / 2;

    // Set the popup position
	setStyle(obj, "top", popTop + "px");
	setStyle(obj, "left", popLeft + "px");

	// Display it
	setStyle(obj, "display", "block");

    return(0);
}

function xpopupClose(evt, obj) {

	// Stop the event from propagating to lower elements
    evt = (evt) ? evt : ((event) ? event : null);
    if (evt) {
        evt.cancelBubble = true;
    }

	parentobj = getParentPopup(obj);
	if (parentobj) {
		setStyle(parentobj, "display", "none");
	}

	// Show SELECT controls
    cl=document.getElementsByTagName('select');
    for (cn = 0; cn < cl.length; cn++){ 
        cl[cn].style.visibility = 'visible';
	}
	/*
    cl=document.getElementsByTagName('embed');
    for (cn = 0; cn < cl.length; cn++){ 
        cl[cn].style.visibility = 'visible';
	}
	*/
}

function getParentPopup(obj) {
    var elem = getRawObject(obj);
    if (isW3C && elem) {
        if (elem.nodeType == 1 && elem.tagName.toLowerCase() == 'div'
			&& elem.className == "xpopup") {
            return elem;
        }
        else {
            return getParentPopup(elem.parentNode);
        }
    }
}

/* Locate inner DIV for this popup */
function getInnerDIV(obj) {
    var elem = getRawObject(obj);
    if (isW3C && elem) {
        var children = elem.childNodes;
        for (var i=0; i<children.length; i++) {
            if (children[i].nodeType == 1 
                && children[i].tagName.toLowerCase() == 'div' 
                && children[i].className == "xpopupinner") {
                    return children[i];
            }
        }
    }
}

function noop() {
}

