/**
* A global function named - initializeMe - is created that can be used
* to arrange the execution of an arbitrary number (but probably
* implementation limited to the order of about 1500) of functions from
* the - onload - handler of a web page. The intention being to allow an
* indefinite number of other scripts to use a common interface for
* triggering their onload initialisation functions.
*
* NOTE: This function must be included before any code that attempts
* to use it.
*
* The - initializeMe - function is called with a reference to a
* function object as its first argument, and up to 4 optional
* additional arguments:-
*
* initializeMe(functRef, "idOfElement", "nameOfForm");
*
* - The function reference and any additional arguments are stored in a
* function stack, the base of which is assigned as to window.onload
* handler (or using W3C DOM addEventListener or IE attachEven, if
* available) and when the onload event is triggered the execution of
* the base of the function stack results in the execution of the
* function passed as the first argument, followed by the next function
* in the stack (which executes its function argument, And so on until
* the stack is excused. The execution of functions passed to the -
* initializeMe - function is in the order in which they are passed to
* the - initializeMe - function (first in, first executed).
*
* The function object passed as - funcRef - is called with its first
* argument being the (onload) - event - object and the values
* originally passed to the call to - initializeMe - as the optional 2nd
* to 5th arguments as its 2nd to 5th arguments (in the same order). So,
* in the example call to - initializeMe - above, the function object
* passed by reference as the first argument would have the pattern:-
*
* function(event, idString, nameString){
*    ...
* }
*
* - and the two string arguments passed to - initializeMe - would be
* passed on when it was called during the onload event.
*
* Note: The - event - object passed to the calls to the - funcRef -
* functions is browser normalised with - (ev?ev:global.event) - prior
* to the call to the function, so these function do not have to
* normalise the event objects themselves, but they also cannot make
* decisions about the DOM in use from inferences about their - event -
* argument.
*/
var initializeMe = (function(){
    var global = this;
    var base = null;
    var safe = false;
    var listenerType = (global.addEventListener && 2)||
                            (global.attachEvent && 3)|| 0;
    function getStackFunc(funcRef, arg1,arg2,arg3,arg4){
        var next = null;
        function l(ev){
            funcRef((ev?ev:global.event), arg1,arg2,arg3,arg4);
            if(next)next = next(ev);
            return (arg1 = arg2 = arg3 = arg4 = funcRef = null);
        };
        l.addItem = function(d){
            if(next){
                next.addItem(d);
            }else{
                next = d;
            }
        };
        return l;
    };
    return (function(funcRef, arg1,arg2,arg3,arg4){
        if(base){
            base.addItem(
                       getStackFunc(funcRef, arg1,arg2,arg3,arg4)
                        );
        }else{
            base = getStackFunc(funcRef, arg1,arg2,arg3,arg4);
        }
        if(!safe){
            switch(listenerType){
                case 2:
                    global.addEventListener("load", base, false);
                    safe = true;
                    break;
                case 3:
                    global.attachEvent("onload", base);
                    safe = true;
                    break;
                default:
                    if(global.onload != base){
                        if(global.onload){
                            base.addItem(getStackFunc(global.onload));
                        }
                        global.onload = base;
                    }
                    break;
            }
        }
    });
})();
//^^ : The inline execution of the outermost function expression.

// Set the default status bar message
function defaultStatus() {
  defaultStatus = "Farkouh.NET - the online home of the Farkouh family";
}
initializeMe(defaultStatus);

// Make external links open in a new window/tab
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
initializeMe(externalLinks);
