function mediumFontSize()
{
	var titleOfActiveStyle = getActiveStyleSheet("fontsize");
	setActiveStyleSheet("Size:10pt","fontsize");
}

function decreaseFontSize()
{
	var titleOfActiveStyle = getActiveStyleSheet("fontsize");
	if(titleOfActiveStyle == null)	
		titleOfActiveStyle = "Size:8pt";
	if(titleOfActiveStyle == "Size:9pt")
		setActiveStyleSheet("Size:8pt","fontsize");
}

function increaseFontSize()
{
	var titleOfActiveStyle = getActiveStyleSheet("fontsize");
	if(titleOfActiveStyle == null)	
		titleOfActiveStyle = "Size:8pt";	
	if(titleOfActiveStyle == "Size:8pt")	
		setActiveStyleSheet("Size:9pt","fontsize");
}

function setActiveStyleSheet(title,type) {
  var i, a, main;
  if(title=='Background: White')
  {
	current_bgcolor='White';
  }
  else if(title=='Background: Red')
  {
	current_bgcolor='Red';
  }
   else if(title=='Background: Yellow')
  {
	current_bgcolor='Yellow';
  }
   else if(title=='Background: Green')
  {
	current_bgcolor='Green';
  }
  else if(title=='Background: Blue')
  {
	current_bgcolor='Blue';
  }
  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 delCookie(name,path) 
{ 
alert("Del");
alert(name+"-"+path);

	if (getCookie(name)) 
  	{ 
		document.cookie = name + "=" +
    		((path == null) ? "" : "; path=" + path)  +
   	 	"; expires=Thu, 01-Jan-70 00:00:01 GMT";
 	 }
    
}

function getCookie(name)
{ var cname = name + "=";               
  var dc = document.cookie;             
  if (dc.length > 0) 
  { begin = dc.indexOf(cname);       
    if (begin != -1) 
    { begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
      return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}

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");

function reload1()
{
     setActiveStyleSheet("null","fontsize");  
     setActiveStyleSheet('Font: Normal','weight');
     setActiveStyleSheet('Background: White','contrast');
}
