function changingFontweight()
{
	var titleOfActiveStyle = getActiveStyleSheet("weight");
	if(titleOfActiveStyle == null)	
		titleOfActiveStyle = "bold:nor";	
	if(titleOfActiveStyle == "bold:nor")	
		setActiveStyleSheet1("bold:bol","weight");
	if(titleOfActiveStyle == "bold:bol")	
		setActiveStyleSheet1("bold:nor","weight");
	
}
function changingFontsize()
{
	var titleOfActiveStyle = getActiveStyleSheet("fontsize");
	if(titleOfActiveStyle == null)	
		titleOfActiveStyle = "fontsmalltextstyle";	
	if(titleOfActiveStyle == "fontsmalltextstyle")	
		setActiveStyleSheet1("fontbigtextstyle","fontsize");
	if(titleOfActiveStyle == "fontbigtextstyle")	
		setActiveStyleSheet1("fontsmalltextstyle","fontsize");
	
}
function setActiveStyleSheet1(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 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;
      
    }
  }
 
  if(title=="colbrownbg")
  {
    document.getElementById('subimg').src="/barn/upload/images/templates/BrownButton.gif";
  
  }
  else if(title=="colgreenbg")
  {
  document.getElementById('subimg').src="/barn/upload/images/templates/GreenButton.gif";
  }
  else if(title=="colbluebg")
  {
  document.getElementById('subimg').src="/barn/upload/images/templates/light_blueButton.gif";
  }
   else if(title=="colyellowTbluebg")
  {
  document.getElementById('subimg').src="/barn/upload/images/templates/BlueYellowButton.gif";
  }
  else
  {
   var url= document.URL;
   var kra=/krakkasida/;
	var ung=/unglingasida/
	if(url.search(kra)!=-1)
	{
		document.getElementById('subimg').src="/barn/upload/images/kidsimages/orangeButton.gif";
	}
	else if (url.search(ung)!=-1)
	{
		document.getElementById('subimg').src="/barn/upload/images/teensimages/GreenDefButton.gif";
	}
	else
	{
		document.getElementById('subimg').src="/barn/upload/images/teensimages/TSFPSearchImg.gif";
	}
   }
}
function isStyleSheetType(str,type){
  if      (str == "")                             { return true; }
  else if (type == "fontsize" && str.match(/^font/))    {return true;}
  else if (type == "width" && str.match(/\d/))    {return true;}
  else if (type == "color" && str.match(/^col/))    {return true;}
  else if (type == "weight" && str.match(/^bol/))    {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();
  setActiveStyleSheet1(title,"fontsize");
  
  cookie = readCookie("wstyle");
  title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet1(title,"width");
   
 cookie = readCookie("cstyle");
 title = cookie ? cookie : getPreferredStyleSheet();
 setActiveStyleSheet1(title,"color");

cookie = readCookie("bstyle");
 title = cookie ? cookie : getPreferredStyleSheet();
 setActiveStyleSheet1(title,"weight");
}
window.onunload = function(e) {

  var title = getActiveStyleSheet("fontsize"); 
  createCookie("style", title, 365);
 var title = getActiveStyleSheet("width");
  createCookie("wstyle", title, 365);
 var title = getActiveStyleSheet("color");
  createCookie("cstyle", title, 365);
  var title = getActiveStyleSheet("weight");
  createCookie("bstyle", title, 365);
  
  /*alert(getActiveStyleSheet("fontsize")+getActiveStyleSheet("width")+getActiveStyleSheet("color"))*/

  
 }

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

var cookie = readCookie("wstyle");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet1(title,"width");

var cookie = readCookie("cstyle");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet1(title,"color");
 
