// $Id: generic.js,v 1.21 2003/05/15 07:59:40 enket Exp $

// FUNCTION: doPopupWindow(inURL, inName)
// This will open up our generic popup window. This is used by the help, meta,
// view and export screens.
function doPopupWindow(inURL, inName) {
    return doPopupWindowFor(window, inURL, inName);
}


// FUNCTION: doPopupWindowFor(inWindow, inURL, inName)
// This will open up our generic popup window. This is used by the help, meta,
// view and export screens, but this function will do it with a given window
// as the opener.
function doPopupWindowFor(inWindow, inURL, inName) {
    inWindow.open(inURL, inName, 'toolbar=no,dependent=yes,resizable=yes,innerHeight=550,innerWidth=500,height=550,width=500');
    return;
}


// FUNCTION: doWidePopupWindow(inURL, inName)
// This will open up our generic (wider) popup window. This is used for the
// print preview and help.
function doWidePopupWindow(inURL, inName) {
    return doWidePopupWindowFor(window, inURL, inName);
}


// FUNCTION: doWidePopupWindowFor(inWindow, inURL, inName)
// This will open up our generic (wider) popup window. This is used for the
// print preview and help, but this function will do it with a given window as
// the opener.
function doWidePopupWindowFor(inWindow, inURL, inName) {
    inWindow.open(inURL, inName, 'toolbar=no,dependent=yes,resizable=yes,innerHeight=550,innerWidth=725,height=550,width=725');
    return;
}


// FUNCTION: doFormClick(inForm, inField, inValue)
// Click an element on a form. We do this such that the user can also click on
// the text that is next to a radio button or checkbox. Oh man, we are so
// user-minded!
function doFormClick(inForm, inField, inValue) {
    var myDoc = document;
    var myForm = document.forms[inForm];
    var myElems = myForm.elements;

    for (var i = 0; i < myElems.length; i++) {
        var myElem = myElems[i];
        if (myElem.name == inField && myElem.value == inValue) {
            myElem.click();
            break;
        }
    }

    return;
}


// FUNCTION: doJumpToId(idId)
// Scroll to the element wich has attribute id=inId.
function doJumpToId(inId) {
    var myDoc = document;
    var myNode =  myDoc.getElementById(inId);
    return doJumpToNode(myNode);
}


// FUNCTION: doJumpToNode
// Scroll to the given node
function doJumpToNode(inNode) {
    var myDoc = document;
    if (myDoc.getElementById && inNode) {
        var myElement = inNode;
        var myY = 0;
        while (myElement.offsetParent)
        {
            myY += myElement.offsetTop
            myElement = myElement.offsetParent;
        }
        scrollTo(0, myY);
        return true;
    } else {
        // If the element could not be found and we are still loading the
        // document, present an error message.
        checkLoaded();
        return false;
    }
}


// FUNCTION: markLoaded(inDocument)
// Mark the given document as being loaded. This function should be called at
// the end of any onLoad page. Note that when inDocument is not defined, the
// current document will be used.
function markLoaded(inDocument) {
    if (! inDocument) {
        inDocument = document;
    }

    document.isLoaded = true;
}


// FUNCTION: isLoaded(inDocument)
// Find out whether the given document is done loading.
function isLoaded(inDocument) {
    if (! inDocument) {
        inDocument = document;
    }

    if (document.isLoaded) {
        return true;
    } else {
        return false;
    }
}


// FUNCTION: checkLoaded(inDocument)
// Find out whether a document has been loaded, and present an error message if
// not.
function checkLoaded(inDocument) {
    if (! isLoaded(inDocument)) {
        if (confirm("Het document wordt nog geladen of het laden van het document is afgebroken. Hierdoor kon de gewenste actie niet worden voltooid.\r\n\r\nWilt u het document opnieuw laden?")) {
            window.location.reload();
        }

        return false;
    } else {
        return true;
    }
}



