﻿/* For checking whether or not a user is logged in and has the rights to access the particular page */
function checkAccess(id,link,tooltip)
{
    if(!lockedPages[link])
    {
        document.getElementById(id).title = tooltip;
    }
}

/* Retrieves the innerHTML of one area, and puts it into another one 

    Takes 4 parameters:
    - newContainer > ID of the div where the content should be placed.
    - oldContainer > ID of the div where the content should be retrieved.
    - clearOldContainer > boolean: controls whether or not the content in the old container should be cleared.
    - newContainerClassName > string: if this variable has a value, this class is applied to the newContainer div.
*/

function placeHtmlContent(newContainer, oldContainer, clearOldContainer, newContainerClassName) {

    oldContainerObj = document.getElementById(oldContainer);
    newContainerObj = document.getElementById(newContainer);

    if(oldContainerObj != null && newContainerObj != null) {
        oldContent = oldContainerObj.innerHTML;
        newContainerObj.innerHTML = oldContent;
        
        if(newContainerClassName != '')
            newContainerObj.className = "show " + newContainerClassName;
        else
            newContainerObj.className = "show";
                    
        if(clearOldContainer) {
            oldContainerObj.innerHTML = "";
            oldContainerObj.className = "hide";
        }
    }
}

/* modified version from placeHtmlContent to check if the oldcontent has any ads */
function placeAdContent(newContainer, oldContainer, clearOldContainer, newContainerClassName) {

    oldContainerObj = document.getElementById(oldContainer);
    newContainerObj = document.getElementById(newContainer);

    if(oldContainerObj != null && newContainerObj != null) {
        oldContent = oldContainerObj.innerHTML;
        newContainerObj.innerHTML = oldContent;
        
        if(oldContent.toLowerCase().indexOf("<img") == -1 && oldContent.toLowerCase().indexOf("<object") == -1 && oldContent.toLowerCase().indexOf("<embed") == -1)
            newContainerObj.className = "hide";
        else if(newContainerClassName != '')
            newContainerObj.className = "show " + newContainerClassName;
        else
            newContainerObj.className = "show";
                    
        if(clearOldContainer) {
            oldContainerObj.innerHTML = "";
            oldContainerObj.className = "hide";
        }
    }
}

/* Modified Oct 27th, 2005 by Tinna Karen, tinna@ec.is - E.C. Software */

function decreaseFontSize()
{
   
	var titleOfActiveStyle = getActiveStyleSheet("fontsize");

	if(titleOfActiveStyle == null)
		titleOfActiveStyle = "Size: 9pt";

	if(titleOfActiveStyle == "Size: 10pt")
		setActiveStyleSheet("Size: 9pt","fontsize");

	if(titleOfActiveStyle == "Size: 9pt")
		setActiveStyleSheet("Size: 8pt","fontsize");
		

}

function increaseFontSize()
{
	var titleOfActiveStyle = getActiveStyleSheet("fontsize");

	if(titleOfActiveStyle == null)
		titleOfActiveStyle = "Size: 9pt";

	if(titleOfActiveStyle == "Size: 8pt")
		setActiveStyleSheet("Size: 9pt","fontsize");

	if(titleOfActiveStyle == "Size: 9pt")
		setActiveStyleSheet("Size: 10pt","fontsize");

}

function setActiveStyleSheet(title,type) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && isStyleSheetType(a.getAttribute("title"),type)) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function isStyleSheetType(str,type) {
  if      (str == "")                             { return true; }
  else if (type == "fontsize" && str.match(/^Size/))    {return true;}
  else if (type == "weight" && str.match(/\Font/))    {return true;}
  else if (type == "contrast" && str.match(/^Back/))    {return true;}
  
  return false;

}

function getActiveStyleSheet(type) {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && isStyleSheetType(a.getAttribute("title"),type) && !a.disabled) 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")
       ) return a.getAttribute("title");
  }
  return null;
}


function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; 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;
}


window.onload = function(e) {
 var title = ""
 var cookie = readCookie("style");
 var title = cookie ? cookie : getPreferredStyleSheet();
 setActiveStyleSheet(title,"fontsize");
  
 cookie = readCookie("wstyle");
 title = cookie ? cookie : getPreferredStyleSheet();
 setActiveStyleSheet(title,"weight");
   
 cookie = readCookie("cstyle");
 title = cookie ? cookie : getPreferredStyleSheet();
 setActiveStyleSheet(title,"contrast");
}
  

window.onunload = function(e) {

 var title = getActiveStyleSheet("fontsize");
 createCookie("style", title, 365);
 var title = getActiveStyleSheet("weight");
 createCookie("wstyle", title, 365);
 var title = getActiveStyleSheet("contrast");
 createCookie("cstyle", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title,"fontsize");

var cookie = readCookie("cstyle");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title,"contrast");

var cookie = readCookie("wstyle");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title,"weight");