if (self.location.host != top.location.host) {
	top.location.href = self.location.href;
}

function opna_glugga(url, nafn, w, h, r, sc) {
	if (isNaN(w))  { w=620; }
	if (isNaN(h))  { h=600; }
	if (isNaN(r))  { r=0; }
	if (isNaN(sc)) { sc=0; }
	gluggi = window.open(url,nafn,"width="+w+",height="+h+",toolbar=0,status=0,resizable="+r+",menubar=0,scrollbars="+sc);
	gluggi.focus();
}

function opna_nyjan(url) {
	gluggi = window.open(url);
	gluggi.focus();
}

function ekkert () {
	var cookie = readCookie("fontsize");
	var title = (cookie) ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
}

window.onload = function(e) {
  var cookie = readCookie("fontsize");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("fontsize", title, 365);
}
////////////////////////////////////////////
function createCookie(name,value,days,path) {
	if (!path) { path = "/"; }
	var expires = "";
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	document.cookie = name+"="+value+expires;//+"; domain=document.location.host; path="+path;
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
////////////////////////////////////////////
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 
    		&& a.getAttribute("title") 
    		&& a.getAttribute("media").indexOf("screen") != -1 ) {
      a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 
    		&& a.getAttribute("title") 
    		&& !a.disabled 
    		&& a.getAttribute("media").indexOf("screen") != -1 ) 
    	return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       && a.getAttribute("media").indexOf("screen") != -1
       ) return a.getAttribute("title");
  }
  return null;
}
