/**
 *
 * Function for enhancing all occurancies of <a> and <form> tags with rel="external" with a target="_blank"
 *
 * @author Dave de Fijter <dave@fijter.nl>
 *
 * @editor Rory Bol, LETO Grafisch Serviceburo, <rory@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
        }
    }
}


/**
 *
 * Function for starting google maps api
 *
 * Get your own personal code at:
 * http://code.google.com/intl/nl/apis/maps/signup.html
 *
 * See for more info:
 * http://code.google.com/intl/nl/apis/maps/documentation/introduction.html#Loading_the_Maps_API
 *
 **/
function GInitialize() {
      if (GBrowserIsCompatible()) {
        // Create the map
        var map = new GMap2(document.getElementById("map_canvas"));
        // Set the center of the starting point
        map.setCenter(new GLatLng(52.080957, 4.880054), 16);
        // Make a cloud (or not)
        //map.openInfoWindow(map.getCenter(), document.createTextNode("Hello, world"));
        // Create the zoom controls which you like to have
        map.addControl(new GSmallZoomControl());
        map.addControl(new GMapTypeControl());
        // Make an array with markers
        var locations = [
//            [52.080700, 4.879982],
            [52.080700, 4.879982]
        ];

        // Change the icon image
        var letomapsicon = new GIcon(); 
        letomapsicon.image = 'http://www.letoservice.nl/nl/img/letomapslogo.png';
        letomapsicon.shadow = 'http://www.letoservice.nl/nl/img/letomapslogo.png';
        letomapsicon.iconSize = new GSize(67, 25);
        letomapsicon.shadowSize = new GSize(67, 25);
        letomapsicon.iconAnchor = new GPoint(0, 25);
        letomapsicon.infoWindowAnchor = new GPoint(5, 1);

        // Place all the defined markers
        for (var i = 0; i < locations.length; i++) {
            var point = new GLatLng(locations[i][0], locations[i][1]);
            var marker = new GMarker(point, {icon:letomapsicon});
            map.addOverlay(marker);
        }
      }
    }


/**
 *
 * Function which creates a pop-up for viewing large images
 *
 **/
function makeWindow(URL) {
    popX=640
    popY=430
    posX=((screen.availWidth/2)-(popX/2))
    posY=((screen.availHeight/2)-(popX/2))
    window.open(URL,"Pagename","height=450,width=650,margin=0,toolbar=0,menubar=0,directories=0,scrollbars=0,left="+posX+",top="+posY);
}
