// Hvilke funksjoner skal lastes naar siden er ferdig loadet?
function addLoadEvent(func) {
    var oldonload = window.onload;

    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}


/* Mail-kamuflering */
function ml(ar, na) {
    str = eval('String.fromCharCode(' + ar + ')');

    if (na == '') {
        na = str;
    }

    document.write('<a href="mailto:' + str + '">' + na + '</a>');
}

function mt(ar, na) {
    str = eval('String.fromCharCode(' + ar + ')');

    if (na == '') {
        na = str;
    }

    document.write("<a href=\"javascript:void(window.open('http://www.vg.no/tips/?til=" + str + "', 'popup', 'width=450,height=500,scrollbars=no'));\">" + na + "</a>");
}
// Funksjon for å legge til en onClick event paa hele siden
function addOnclickEvent(func) {
 	    var oldonclick = document.onclick;
 	
 	    if (typeof document.onclick != 'function') {
 	        document.onclick = func;
 	    } else {
 	        document.onclick = function() {
	            oldonclick();
 	            func();
 	        }
 	    }
}
// Funksjon for popup
// Bruk: legg til class "popup" i linken som åpner linken i ekstern vindu
// Optional: legg til "height=xx" og "width="xx" for å definere stoerr. paa vinduet
myOnclick = function(e)
{
  var target = e ? e.target : window.event.srcElement;

  while (target && !/^(a|body)$/i.test(target.nodeName))
  {
    target = target.parentNode;
  }

  if (target && (target.className=='popup'))
      {  
	if (target.getAttribute('width') && target.getAttribute('height'))
	{
		var w = target.getAttribute('width');
		var h = target.getAttribute('height');
		var config = "width="+w+",height="+h;
	    var external = window.open(target.href,"window",config);
	}
	else
		  {
		    var external = window.open(target.href);
		  }
		  return external.closed;
	}		  
}
addOnclickEvent(myOnclick);