/**
 * @author Administrator
 */
window.onload = initAll;

//normal font size: if 62.5%,should be  0.625
//interval:the rate if 2%,should be  0.02    
var normalfontSize = 0.625,interval = 0.2;
var minSize=0.625,maxSize=1.6;
function initAll()
{
	document.getElementById("FontMinus").onclick = setMinus;
	document.getElementById("FontReset").onclick = setNormal;
	document.getElementById("FontPlus").onclick = setPlus;
	
	var fontSize = GetCookie();
	if (fontSize != "") {
		//for data type convertion
		fontSize = fontSize * 1;
		
		fontSize = fontSize.toFixed(3);
		fontSize = fontSize * 100;
		fontSize = fontSize + "%";
		document.getElementById("body").style.fontSize = fontSize;
	}
}

function setMinus()
{
	SetFontSize("Minus");
	return false;
}

function setPlus()
{
	SetFontSize("Add");		
	return false;
}
function setNormal()
{
	SetFontSize("Normal");
	return false;
}

function SetFontSize(signal)
{
	/*var x = document.getElementsByTagName("*");
	for(var i=0;i<x.length;i++)
	{
		if(x[i].style.fontSize != "")
		{
			
		}
	}*/
	var fontSize= GetCookie();
	if(fontSize=="")
	{
		fontSize = normalfontSize;
	}
	
	//for data type convertion
	fontSize = fontSize*1;
	
	var newvalue;
	if(signal=="Add")
	{
		newvalue = parseFloat(fontSize) * (1+parseFloat(interval));
		if(newvalue>maxSize)
		{
			newvalue = maxSize;
		}
		
	}
	else if(signal=="Minus")
	{
		newvalue = parseFloat(fontSize) * (1-parseFloat(interval));
		if(newvalue<minSize)
		{
			newvalue = minSize;
		}
	}
	else if(signal=="Normal")
	{
		newvalue = normalfontSize;
	}
	
	newvalue = newvalue.toFixed(3); 
	fontSize=newvalue * 100;
	fontSize = fontSize + "%";
	document.getElementById("body").style.fontSize=fontSize;
	
	WriteCookie(newvalue);
	
}


function WriteCookie(value)
{
	var expireDate = new Date();
	expireDate.setMonth(expireDate.getMonth()+ 6);
	document.cookie = "fontSize=" + value + ";expires=" + expireDate.toGMTString();
}

function GetCookie()
{
	var fontSize="";
	if(document.cookie !="")
	{
		var cookies = document.cookie.split("; ");
		for(var i=0;i<cookies.length;i++)
		{
			if(cookies[i].split("=")[0]=="fontSize")
			{
				fontSize = cookies[i].split("=")[1];
				return fontSize;
			}
		}
	}
	return normalfontSize;
}

