/**
 *
 * Function for enhancing all occurancies of <a> and <form> tags with rel="external" with a target="_blank"
 *
 * @editor 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";
        }
    }
}


/**
 *
 * Function which sets the focus on a formfield
 *
 */
function focus(variabele) {
    document.getElementById(variabele).focus();
}


/**
 *
 * Functions for getting AJAX output from a external PHP
 *
 */

function showColumns(urlvar) {
    $.get('/nl/ajax/loadcolumns.php', { templateid: urlvar }, dataLoaded, 'text');
}
function dataLoaded(data) {
    if (data == 'YY' || data == 'YN') {
        $('#editcolumn1').show();
    } else {
        $('#editcolumn1').hide();
    }
    if (data == 'YY' || data == 'NY') {
        $('#editcolumn2').show();
    } else {
        $('#editcolumn2').hide();
    }
}


/**
 *
 * Function to equal the heights of 2 divs
 *
 */

function define3columnsheight() {
    var height1;
    var height2;
    height1 = document.getElementById('column1of3').offsetHeight;
    height2 = document.getElementById('column2of3').offsetHeight;
    if (height1 > height2) {
        if (height1 > 300) {
            document.getElementById('column2of3').style.height = height1 + 'px';
        } else {
            document.getElementById('column1of3').style.height='300px';
            document.getElementById('column2of3').style.height='300px';
        }
    } else {
        if (height2 > 300) {
            document.getElementById('column1of3').style.height=height2 + 'px';
        } else {
            document.getElementById('column1of3').style.height='300px';
            document.getElementById('column2of3').style.height='300px';
        }
    }
}
