
function externalLinks() {
    var anchors = document.links;
    for (var i=0; i < (anchors.length); i++) {
         var anchor = anchors[i];
         href = anchor.getAttribute("href");
         if (href && anchor.protocol != 'javascript:' && (anchor.getAttribute("rel") == "external" ||
             anchor.hostname != document.domain))
             anchor.target = "_blank";
    }
}

window.onload = externalLinks;

function displayImage(imgurl) {

    var img = new Image();
    img.src = imgurl;

    
    img.onload = function() {
        h = img.height;
        w = img.width;
        
        leftPos = (screen.width-w)/2, topPos = (screen.height-h)/2;

        window.open(imgurl, "", "status = 0, height = " + h +  ", width = " + w + ", resizable = 0, top = " + topPos + ",left = " + leftPos)
    }
        
}/*
function hideNotes (noteElement) {
    var noteParent = noteElement.parentNode;
    var tags = noteParent.getElementsByTagName('div');
    var i;
    for (i = 0; i < tags.length; i++) {
        if (tags[i].getAttribute('class') == 'visible') {
             tags[i].setAttribute('class', 'invisible');
             break;
        
        }
    }

}
function showNote(elId) {
    var noteEl = document.getElementById('note_' + elId);
    
    hideNotes(noteEl);
    
    noteEl.setAttribute("class", "visible");

}*/
function showNote(el) {
    noteD = el.parentNode.lastChild;
    if (noteD.getAttribute("class") == "invisible" || noteD.getAttribute("className") == "invisible") {
	noteD.className = "visible";
    } else {
	noteD.className="invisible";
    }
}
function confirmation(msg, path) {
    var x = window.confirm(msg);
    if (x)
	window.location = path;
}
                    
/*
function showTip(elName) {
    // find the trigger element
    var triggerEl = document.getElementById(elName);
    
// find the height of the parent div (which is actually the parent of the parent div, due to logic considerations)
    var parentHeight = triggerEl.parentNode.parentNode.offsetHeight;
    
// find the div that we have to show and make it visible
    var tooltipEl = document.getElementById('tooltip' + elName);
    tooltipEl.style['display'] = 'block';
// <<<<<< here comes the nice part... >>>>>>
    // get the position and size of the tooltip div element and the trigger element
    triggerTop = triggerEl.offsetTop;
    tooltipTop = tooltipEl.offsetTop;
    triggerHeight = triggerEl.offsetHeight;
    tooltipHeight = tooltipEl.offsetHeight;
    // some calculations prove that this should do the trick with showing nice tooltips
    if (parentHeight < (tooltipTop + tooltipHeight)) {
        tooltipEl.style['marginTop'] = - (triggerHeight + tooltipHeight) + 'px';

    }

}

function hideTip(elName) {
    var triggerEl = document.getElementById(elName);
    var tooltipEl = document.getElementById('tooltip' + elName);
    tooltipEl.style['display'] = 'none';

}
*/
function replaceTitleOf(elem) {
    containers = elem.parentNode.parentNode.getElementsByTagName('div');
    container  = elem.parentNode;

    uneditable = containers[0];
    editable = containers[1];

    a = uneditable.getElementsByTagName('h2');
    currentTitle = a[0].innerHTML;

    input = editable.getElementsByTagName('input')[0];

    if(container.className == 'uneditable') {
        uneditable.style.display = 'none';

        input.value = currentTitle;
        editable.style.display = 'block';
    }

    if(container.className == 'editable') {
        if(elem.className == 'title-operations cancel') {
            editable.style.display = 'none';
            uneditable.style.display = 'block';
        }
    }
}
function clock() {
    var clock_time = new Date();
    
    var clock_hours = clock_time.getHours();
    var clock_minutes = clock_time.getMinutes();
    var clock_seconds = clock_time.getSeconds();
                
    if (clock_hours < 10) {
        clock_hours = '0' + clock_hours;
                            
    }
                                
    if (clock_minutes < 10) {
	clock_minutes = '0' + clock_minutes;
                                            
    }
                                                
    if (clock_seconds < 10) {
	clock_seconds = '0' + clock_seconds;
                                                            
    }
    var clock_div = document.getElementById('clock');
        clock_div.innerHTML = clock_hours + ":" + clock_minutes + ":" + clock_seconds;
    setTimeout("clock()", 1000);
}