// JavaScript Document
function textSizeController(preferedStyle){
	var cssPrefix = "tamano_";
	var newSize = null; 
	var defaultSize = 1;
	var cookieStyle = null;
	var size = 1; 
	
	this.setActiveStyleSheet = function(title) {
	    var i, a, main;
    	var listo = 0;
	    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    	    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
       	     	a.disabled = true;
       	     	if(a.getAttribute("title") == title){
       	         	listo = 1;
       	        	a.disabled = false;
       	    	}
       		}
    	}
	    if(listo == 0) {
   	 		document.getElementsByTagName("link")[0].disabled = false;
   	 	}
		
		this.createCookie("style", title, 365);
	}



	this.getActiveStyleSheet = function() {
		//Devuelve el title de la primera stylesheet activa
		var i, a;

    	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
        	if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
		}
		return null;
	}



	this.getPreferredStyleSheet = function() {
		var i, a;

		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1
				&& a.getAttribute("rel").indexOf("alt") == -1
				&& a.getAttribute("title")
			) return a.getAttribute("title");
    	}
    	return null;
	}



	this.createCookie = function(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}

	this.readCookie = function(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.windowLoad = function(){
		var cookie = readCookie("style");
		var title = cookie ? cookie : getPreferredStyleSheet();
		if(title!="null")
	    	setActiveStyleSheet(title);	
	}
	this.newSize = preferedStyle ? preferedStyle : null;
	this.size = this.newSize != "" ? this.newSize : this.defaultSize;
	this.cookieStyle = this.readCookie("style");
	
}
/*

var cookie = readCookie("style");

var title = cookie ? cookie : getPreferredStyleSheet();

setActiveStyleSheet(title);  */
