TzFonts.js 2.74 KB
function locateASP()
//Returns the location of the ASP relative to the page
{
	var fullpath = location.pathname;
	var lastSlash;
	var path;
	var ASPlocation = "";
	var backslash = "../"
	var count = 0;
	
	lastSlash = fullpath.lastIndexOf("/");
	path = fullpath.substring(0, lastSlash);
	
	while (path.toLowerCase() != "" && path.toLowerCase() != "/"){
		count++; 
		lastSlash = path.lastIndexOf("/");
		path = path.substring(0, lastSlash);
	}
	
	for(var j = 1; j <= count; j++){
		ASPlocation = backslash + ASPlocation;
	}

	return ASPlocation;
}

Tz = new function(){}

Tz.Fonts = new function() {
	
	this.FontElement		= "TzSelectors";
	this.RenderContainer	= "TzFontContent";
	this.CookieName			= "TzLibroFontClass";
	this.prevEl				= "TzNorm";
	
	this.switchFont = function(strId) {
		
		var content = document.getElementById(Tz.Fonts.RenderContainer);
		if (typeof content !== 'undefined' && content !== null) {
			
			var prevelement = document.getElementById(Tz.Cookie.read(Tz.Fonts.CookieName));
if (prevelement !== null) { prevelement.style.color = "#5D9732"; }
			
			content.className = strId;
			Tz.Cookie.create(this.CookieName, strId);
			var fontelement = document.getElementById(strId);
			fontelement.style.color = "#006857";
			
		}
	}
	
	window.onload = function() {
		
		var fontcookie = Tz.Cookie.read(Tz.Fonts.CookieName);
		if(!fontcookie) {
			Tz.Cookie.create(Tz.Fonts.CookieName, Tz.Fonts.prevEl);
		} else {
			Tz.Fonts.prevEl = fontcookie;
		}
		
		var content = document.getElementById(Tz.Fonts.RenderContainer);
		if (typeof content !== 'undefined' && content !== null) {
			content.className = fontcookie;
			var fontelement = document.getElementById(Tz.Fonts.prevEl);
			if(typeof fontelement !== 'undefined' && fontelement !== null) {
				fontelement.style.color = "#006857";
			}
		}
	}
	
}

Tz.Cookie = new function() {
   this.create = function(name, value, days) {
       var expires = '';
       if (days) {
           var date = new Date();
           date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
           expires = '; expires= ' + date.toGMTString();
       }

       document.cookie = name + '=' + value + expires + '; path=/';
   }

   this.read = function read(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;
   }

   this.erase = function(name) {
       Tz.Cookie.create(name, '', -1);
   }
}