/* code for Text size changes */
var headID = document.getElementsByTagName("head")[0];
var cssNode = document.createElement("style");
cssNode.type = 'text/css';
cssNode.id="resizingText";
//Creates cookie
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 var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
//Read Cookie
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;
}
//Erase Cookie
function eraseCookie(name) {
	createCookie(name,"",-1);
}
//Changes the page according to font size selected
function loadCss(x){
	try{
		var cssStr = '\
		#swineFlubody {font-size:' + (10+x) +'px;}\
		';		
		if(cssNode.styleSheet){
			cssNode.styleSheet.cssText = cssStr; // for IE
		} else {
			var cssText = document.createTextNode(cssStr);
			cssNode.appendChild(cssText); // breaks ie
			//cssNode.innerHTML = cssStr; // breaks saffari
		}
		if(!document.getElementById("resizingText"))headID.appendChild(cssNode);
	}catch(err){ 
		// some debugging code
	}
}
//function which calls the loadCss() and passes the font size
function increaseFontSize(incdec) {
	loadCss(incdec);
	createCookie('textsize',incdec,1); 
}
var x = readCookie('textsize')
if (x && x!=0) {
	x = parseInt(x);
	incdec = x;
	loadCss(x);
}
//function which passes the value on click of radio buttons
/*
function fontVar(){
var newTextSize=document.size.textsize.length;
if(document.size.textsize[0].checked)
	{
 increaseFontSize(5);
	}
 else if(document.size.textsize[1].checked)
	{
 increaseFontSize(3);
	}
 else if(document.size.textsize[2].checked)
	{
 increaseFontSize(2);
	}
 else if(document.size.textsize[3].checked)
	{
 increaseFontSize(1);
	}
  else if(document.size.textsize[4].checked)
	{
 increaseFontSize(-1);
	}
}
*/

/* code for changing the css file */

// *** BEGIN OF CUSTOMISABLE SECTION ***

var style_cookie_name = "style" ;
var style_cookie_duration = 130 ;

// *** END OF CUSTOMISABLE SECTION ***
//function which switches the css
function switch_style ( css_title )
{
  var i, link_tag ;
  for (i = 0, link_tag = document.getElementsByTagName("link") ;
    i < link_tag.length ; i++ ) {
    if ((link_tag[i].rel.indexOf( "stylesheet" ) != -1) &&
      link_tag[i].title) {
      link_tag[i].disabled = true ;
      if (link_tag[i].title == css_title) {
        link_tag[i].disabled = false ;
      }
    }
    setCookie( style_cookie_name, css_title,
      style_cookie_duration );
  }
}
function set_style_from_cookie()
{
  var css_title = getCookie( style_cookie_name );
  if (css_title.length) {
    switch_style( css_title );
  }
}
//stores the information in an cookie ie create cookie
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
//we create another function that checks if the cookie has been set
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
//function which passes the value on click of radio buttons
/*
function changeContrast(){
var newTextSize=document.size.theme.length;
if(document.size.theme[0].checked)
	{
 switch_style('standard');
	}
 else if(document.size.theme[1].checked)
	{
 switch_style('high');
	}
}
//function to be called on SUBMIT of Button
function onSubmit(){
	fontVar();
	changeContrast();
}
*/

	


