function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function updateCookies(size) {
	var fontValue = readCookie("toyota_fontsize");
	if (fontValue != null) {
		//Delete and Create New One
		createCookie("toyota_fontsize","",-1);
		createCookie("toyota_fontsize",size,7);
	} else {
		//Create New One
		createCookie("toyota_fontsize",size,7);
	}
}

function makeSmall() {
	updateCookies("small");
	$("#small-not-selected").attr("id","small-selected");
	$("#large-selected").attr("id","large-not-selected");
	$("body").css("font-size","73%");
	
}

function makeLarge() {
	updateCookies("large");
	$("#large-not-selected").attr("id","large-selected");
	$("#small-selected").attr("id","small-not-selected");
	$("body").css("font-size","83%");
	
}

$(document).ready(function() {
	//normalize the CSS in smallText and largeText.
	$("#smallText").css("font-size","100%");
	$("#largeText").css("font-size","100%");
	$("body").css("font-size","73%");
	
	var fontValue = readCookie("toyota_fontsize");
	
	//alert("cookies :"+fontValue);
	if (fontValue != null) {
		if (fontValue == "small") {
			makeSmall();
		} else if (fontValue == "large") {
			makeLarge();
		}
	}
});
