
function replaceThem(x)
{
	var replace = document.createElement('img');
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id)
		{
			var y = replace.cloneNode(true);
			y.src = '';
			y.alt = x[i].firstChild.nodeValue;
			x[i].replaceChild(y,x[i].firstChild);
		}
	}

}

function imageReplacement()
{
	replaceThem(document.getElementsByTagName('div'));
}

function changeFontSize(type){
	var cookieFont=getCookie("fontsize");
	var size=80;
	if(cookieFont){
		size=parseInt(cookieFont);
	}
	
	if(type=='+1'){
		if(size<120) size=size+10;
	}else if(type=='-1'){
		if(size>70) size=size-10;
	}else{
		size=type;
	}

	setCookie("fontsize",size);
	document.getElementById("page").style.fontSize = size+"%";
}

function changePageWidth(width){;
	setCookie("screensize",width);
	if(width=='*'){
		document.getElementById("page").style.width = "100%";
		/*document.getElementById("w3c").style.width = "100%";*/
	}else{
		document.getElementById("page").style.width = width+"px";
		/*document.getElementById("w3c").style.width = width+"px";*/
	}
}


function toggleStyling(){
	var currentStyling=getCookie("styling");
	if(currentStyling!=null){
		if(currentStyling=='full'){
			currentStyling='basic';
			
		}else{
			currentStyling='full';
		}
		setCookie("styling",currentStyling);		
	}else{
		setCookie("styling","full");
	}
	window.location.reload();
}

function setCookie ( name, value, expY, expM, expD, path, domain, secure )
{
  var cookieString = name + "=" + escape ( value );
  if ( expY )
  {
    var expires = new Date ( expY, expM, expD );
    cookieString += "; expires=" + expires.toGMTString();
  }else{
    // Never expire
 	var expires = new Date();
	expires.setTime(expires.getTime() + 2000*24*60*60*1000);
    cookieString += "; expires=" + expires.toGMTString();  
  }
  if ( path )
        cookieString += "; path=" + escape ( path );
  if ( domain )
        cookieString += "; domain=" + escape ( domain );
  if ( secure )
        cookieString += "; secure";  
  document.cookie = cookieString;
}

function deleteCookie ( cookieName )
{
  var cookieDate = new Date ( );  // current date time
  cookieDate.setTime ( cookieDate.getTime() - 1 );
  document.cookie = cookieName += "=; expires=" + cookieDate.toGMTString();
}

function getCookie ( cookieName )
{
  var results = document.cookie.match ( cookieName + '=(.*?)(;|$)' );

  if ( results )
    return ( unescape ( results[1] ) );
  else
    return null;
}

function initialise(){
	
	var fontsize=getCookie("fontsize");
	var screensize=getCookie("screensize");
	
	// Change the font size to the cookie persisted version
	if(fontsize>0){
		changeFontSize(fontsize);
	}else{
		changeFontSize(100);
	}

	// Change the screen size to the cookie persisted version
	if(screensize!=null){
		changePageWidth(screensize);
	}else{
		changePageWidth(820);
	}
	

	
}