//Load CSS to set font size in main document area - check if stored in cookie, store if new

var tsSetSize=readCookie('TextSize');
///debug alert('setSize reads: '+tsSetSize);
var expiryDate=new Date;
expiryDate.setFullYear(expiryDate.getFullYear()+5);

var size1='<link href="/assets/templates/textsize1.css"  rel="stylesheet" title="small" type="text/css" />';
var size1a='<link href="/assets/templates/textsize1.css"  rel="alternate stylesheet" title="small" type="text/css" />';
var size15='<link href="/assets/templates/textsize15.css"  rel="stylesheet" title="medium" type="text/css" />';
var size15a='<link href="/assets/templates/textsize15.css"  rel="alternate stylesheet" title="medium" type="text/css" />';
var size2='<link href="/assets/templates/textsize2.css"  rel="stylesheet" title="big" type="text/css" />';
var size2a='<link href="/assets/templates/textsize2.css"  rel="alternate stylesheet" title="big" type="text/css" />';

// debug alert (screenWidth());

if (tsSetSize) {
	if  (tsSetSize=="15") {
		document.write(size15);
		document.write(size1a);
		document.write(size2a);
		}

	if  (tsSetSize=="2") {
		document.write(size2);
		document.write(size15a);
		document.write(size1a);
		}
	}
else	{
	tsSetSize = "1";	
	document.write(size1);
	document.write(size15a);
	document.write(size2a);
		}

function setTextSize() {
	if  (tsSetSize=="1") {
		tSize = "15";
		}
	else if (tsSetSize=="15"){
		tSize = "2";
		}
	else { 
		tSize = "1";
		}
	cookieString= 'TextSize='+tSize;
	cookieString+=';expires='+expiryDate.toGMTString();
	cookieString+=';path=/';
	document.cookie= cookieString;
	window.location.reload(true);
	}

function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)  	{ 
    offset = document.cookie.indexOf(search);
    if (offset != -1) {	 
		  offset += search.length;
		  end = document.cookie.indexOf(";", offset);
		  if (end == -1) end = document.cookie.length;
		  cookieValue = unescape(document.cookie.substring(offset, end))
    		}
  		}
	return cookieValue;
}

function screenWidth() {
//adapted from www.howtocreate.co.uk/tutorials/javascript/browserwindow
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myWidth;
}