// JavaScript Document
//This script is Written by Gurvinder Singh Bains (http://www.gsbmazztech.com).
//Please feel free to edit and make changes to this script as per your requierment.
//Just keep this comment intact. Thank you.

//###################Steps for Font function on page#####################
//1. On Page load Check for cookie
//2. If no cookie found, then create one else read the font calue from cookie and set it to the tag element
//3. On Font increase or Decrease calls, overrite the cookie with new value and reset the tag element font style value


function checkcookie(name)
	{
		var currentCookieValue = readcookie(name)
		//Check to see if the cookie exist
		if(currentCookieValue)
			LoadTagElementFontStyle(currentCookieValue);
		else
			{
				createCookie('gwretinafontsize',12,30);
				LoadTagElementFontStyle(12);
			}
	}
	
function readcookie(name)
	{
		//pass the cookie name to local variable and append = sign
		var thisCookie = name + "=";
		
		//Now split the cookie with ';' coz cookie formatt is "name=valu;expire=time;path=/"
		var ca = document.cookie.split(';');
		
		//now run the loop to read the array
		for(var i=0;i < ca.length;i++)
			{
				var c = ca[i];
				while (c.charAt(0)==' ') 
					c = c.substring(1,c.length); //Keep moving ahead till the first char is reached
				if (c.indexOf(thisCookie) == 0)
					return c.substring(thisCookie.length,c.length); //Return the value of cookie
			}
		return null;  
		
	}
	
function createCookie(name,value,days)
	{
		//first we check if a days value is provided. 
		//If Not provided we make expiration = 0, which means as soon as the browser is closed the cookie expires.
		//If provided then we do our date calculation for miliseconds of time the cookie will be active.
		//Finally we will set the cookie.
		if (days) 
			{
				var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
			}
		else 
		var expires = 0;
		
		document.cookie = name+"="+value+expires+"; path=/";
	}
	
function LoadTagElementFontStyle(value){document.body.style.fontSize = value+"px";}

function increaseFontSize(name)
	{
	    var incCookieValue = readcookie(name)
		incCookieValue++;
		createCookie(name,incCookieValue,30)
		LoadTagElementFontStyle(incCookieValue)
		return false;
	}

function decreaseFontSize(name)
	{
		var decCookieValue = readcookie(name)
		decCookieValue--;
		createCookie(name,decCookieValue,30)
		LoadTagElementFontStyle(decCookieValue)
		return false;
	}
	


