/**
 *
 * Function for enhancing all occurancies of <a> and <form> tags with rel="external" with a target="_blank"
 *
 * @author Rory Bol, LETO Grafisch Serviceburo, <r.bol@letoservice.nl>
 *
 */

function externalLinks() {
    // Return if JS DOM1 is not supported
    if (!document.getElementsByTagName) return;
    // Fetch all <a>'s
    var anchors = document.getElementsByTagName("a");
    // Loop through all <a>'s
    for (var i=0; i<anchors.length; i++) {
        var anchor = anchors[i];
        // Check if the element contains a href and a rel "external" attribute
        if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
            // Set the target to Blank for those
            anchor.target = "_blank";
        }
    }

    // Do the same for forms with a rel = external
    var forms = document.getElementsByTagName("form");
    for (var i=0; i<forms.length; i++) {
        var frm = forms[i];
        if (frm.getAttribute("action") && frm.getAttribute("title") == "external") {
            frm.target = "_blank";
        }
    }
}


/**
 *
 * Functions which sets the focus on a formfield
 *
 */

function focus(variabele) {
    document.getElementById(variabele).focus();
}

/**
 *
 * Standard function for all the AJAX items
 *
 **/

function ajax(url, urlvar, elementid) {
    var xmlHttp=null;
    try{
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    } catch (e) {
        //Internet Explorer
        try{
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    if (xmlHttp==null) {
        // alert ("Browser does not support HTTP Request")
        return
    }
    url=url+"&q="+urlvar
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    function stateChanged() {
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
            document.getElementById(elementid).innerHTML=xmlHttp.responseText
        }
    }
}