//Clase de control de textos 

//Metodo constructor
function textControl( cssDir, min, max ) {
	this.getCookie = textControlGetCookie;
	this.setCookie = textControlSetCookie;
	this.sizeChange = textControlSizeChange;
	this.increase = textControlIncrease;
	this.decrease = textControlDecrease;
	this.textsizeCssDir = cssDir;
	this.minSize = min;
	this.maxSize = max;
	this.actualSize = this.getCookie( 'customTextSize' );
	if( ! this.actualSize ) {
		this.actualSize = 1;
	}
	else {
		this.actualSize = parseInt( this.actualSize );
		if( this.actualSize != 1 ) {
			this.sizeChange( this.actualSize );
		}
	}
}

//Metodo para recuperar la cookie
function textControlGetCookie( name ) {
   var start = document.cookie.indexOf( name+"=" );
   var len = start+name.length+1;
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
   if (start == -1) return null;
   var end = document.cookie.indexOf(";",len);
   if (end == -1) end = document.cookie.length;
   return unescape(document.cookie.substring(len,end));
}

//Metodo para establecer o sobreescribir la cookie
function textControlSetCookie( name, value, expires, path, domain, secure ) {
    var cookieString = name + "=" +escape(value) +
       ( (expires) ? ";expires=" + expires.toGMTString() : "") +
       ( (path) ? ";path=" + path : "") +
       ( (domain) ? ";domain=" + domain : "") +
       ( (secure) ? ";secure" : "");
    document.cookie = cookieString;
}

//Metodo de control de tamanos de textos
function textControlSizeChange( size ) {
	var i;
	for( i = 0; i < document.styleSheets.length; i++ ) {
		if( document.styleSheets[ i ].href.indexOf( 'textsize' ) != -1 ) {
			break;
		}
	}
	this.actualSize = size;
	this.setCookie( 'customTextSize', size );
    var styleSheet = document.styleSheets[ i ].ownerNode;
    var newstyleSheetHref = this.textsizeCssDir + '/textsize' + size + '.css';
    if( ! styleSheet ) {
    	//Explorer
    	document.styleSheets[ i ].href = newstyleSheetHref;
    }
    else {
    	//Firefox
    	styleSheet.setAttribute( 'href', newstyleSheetHref );
    }
}


function textControlIncrease( ) {
	if( this.actualSize < this.maxSize ) {
		this.sizeChange( this.actualSize + 1 );
	}
}

function textControlDecrease( ) {
	if( this.actualSize > this.minSize ) {
		this.sizeChange( this.actualSize - 1 );
	}
}

