function pageload () {
	loadFont();
	loadStyle();
}


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 delCookie (name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) +
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

function loadFont () {
	var h = document.getElementById("middle");
	var j = h.getAttribute("src");
	h.setAttribute("src", "../web_resources/internet/images/footerlogosright/1.png");
	
	var contentSize = getCookie('contentSize');
	if (contentSize) {
		var k = document.getElementById("inner");
		k.style.fontSize = contentSize + 'em';
	}
	
	var navSize = getCookie('navSize');
	if (navSize) {
		var k = document.getElementById("leftnav");
		k.style.fontSize = navSize + 'em';
	}
}

function loadStyle () {
	var style = getCookie('whichStyle');
	if (style) {
		href = document.getElementsByTagName("link")[5];
		var myOldString = href.href;
		// split the href value by '/'
		myOldStringArray = myOldString.split('/');
		
		// get the last entry in the array
		var i = myOldStringArray.length -1;
		var myNewString = myOldString.replace(myOldStringArray[i], style + '_color.css');
		href.href = myNewString;
	}
}

function changeFont (scale) {
	var contentSize = 0; // var to indicate body font size
	var navSize = 0; // var to indicate the navigation font size
	
	if (scale == '0.9') {
		contentSize = '0.9';
		navSize = '0.9';
	} else if (scale == '1') {
		contentSize = '1';
		navSize = '1';
	} else if (scale == '1.1') {
		contentSize = '1.3';
		navSize = '1';
	}
	
	var content = document.getElementById("inner");
	content.style.fontSize = contentSize + 'em';
	setCookie('contentSize', contentSize);
	
	var nav = document.getElementById("leftnav");
	nav.style.fontSize = navSize + 'em';
	setCookie('navSize', navSize);
}

function changeStyle (style) {
	// get the first stylesheet reference
	href = document.getElementsByTagName("link")[5];
	var myOldString = href.href;
	
	// split the href value by '/'
	myOldStringArray = myOldString.split('/');
	
	// get the last entry in the array
	var i = myOldStringArray.length -1;
	
	// replace it with our new value
	var myNewString = myOldString.replace(myOldStringArray[i], style + '_color.css');
	
	// assign the new value to the 'link'
	href.href = myNewString;
	setCookie('whichStyle', style);
}

function addDate () {
	var currentTime = new Date();
	var month = currentTime.getMonth() + 1;
	var day = currentTime.getDate();
	var year = currentTime.getFullYear();
	var k = document.getElementById("style");
	k.innerHTML += 'Todays Date: ' + day + "/" + month + "/"  + year;
}
	

function disableEnterKey(e)
{
     var key;      
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox      

     return (key != 13);
}

jQuery.noConflict();
jQuery(document).ready(function(){
	
	var i = rand(4);
	jQuery("#masthead").css("background-image", "url(http://www.gloucestershire.police.uk/internetresources/images/mastheads/" + i + ".png)");
	jQuery("#news").load("/GP_QuickPublish/item8110.html");
	
	
	jQuery("#play").click(function () {
		if(loadedTT==2) {
		 	ToggleOnOff();
		} 
		clearTimeout(TimerID);
		PlayTT(); 
	});	
	jQuery("#stop").click(function () {
		TTStopPlaying();
	});	
	jQuery("#download").click(function () {
		SaveTT();
	});	
	jQuery("#tree").treeview({
				collapsed: true,
				animated: "fast",
				control:"#sidetreecontrol",
				persist: "location"
	});
	
});


function rand ( n )
{
  return ( Math.floor ( Math.random ( ) * n + 1 ) );
}





window.onload = pageload;
