/*
*	----------------------------------------------------------------------------
*	TextEngine.js
*	Inclusión no intrusiva de iconos de accesibilidad.
*	Aumento y disminución de texto, alto contraste, impresión.
*
*	Autor:		Pablo Suárez León <psuarez@technosite.es>
*	Fecha:		25/06/2008
*	Versión:	1.1
*  Comentario: Modificada para que la Cookie se destruya al cerrar el navegador
*	----------------------------------------------------------------------------
*/

var TextEngine = {
    bodyObj: null,

    init: function(parentId) {
        /* Elemento padre */
        parentObj = document.getElementById(parentId);

        /* Elemento body */
        this.bodyObj = document.getElementsByTagName('BODY')[0];
                
        /* Creación de los enlaces */
		increase = document.createElement('a');
		increase.href = 'javascript:void(null)';
		increase.onclick = this.increaseText;
		abbr1 = document.createElement('abbr');
		abbr1.title = 'Aumentar tamaño del texto';
		abbr1.appendChild(document.createTextNode('A+'));
		increase.appendChild(abbr1);
		
		decrease = document.createElement('a');
		decrease.href = 'javascript:void(null)';
		decrease.onclick = this.decreaseText;
		abbr2 = document.createElement('abbr');
		abbr2.title = 'Reducir tamaño del texto';
		abbr2.appendChild(document.createTextNode('A-'));
		decrease.appendChild(abbr2);
		
		li1 = document.createElement('li');
		li1.className = 'liFirst';
		li1.appendChild(decrease);
		
		li2 = document.createElement('li');
		li2.className = 'liLast';
		li2.appendChild(increase);
		
		ul = document.createElement('ul');
		ul.appendChild(li1);
		ul.appendChild(li2);
		
		/* Insercción de los elementos */
		parentObj.appendChild(ul);
        
        /* Comprobar si existe la cookie y redimensionar */
        if (act = CookieEngine.GetCookie('textEngine')) {
            TextEngine.bodyObj.style.fontSize = act;
        }
    },

    increaseText: function() {
        var size = TextEngine.getTextSize() * 1.2 + 'em';
        TextEngine.bodyObj.style.fontSize = size;
        /* Guardar cookie */
        CookieEngine.SaveCookie('textEngine', size);
    },

    decreaseText: function() {
        var size = TextEngine.getTextSize() / 1.2 + 'em';
        TextEngine.bodyObj.style.fontSize = size;
        /* Guardar cookie */
        CookieEngine.SaveCookie('textEngine', size);
    },

    resetText: function() {
        TextEngine.bodyObj.style.fontSize = '1em';
        /* Eliminar cookie */
        CookieEngine.SaveCookie('textEngine', '1em');
    },

    getTextSize: function() {
        if (this.bodyObj.style.fontSize) {
            return parseFloat(this.bodyObj.style.fontSize);
        }
        else {
            return .87;
        }
    }
}


CookieEngine = {

    GetCookieValue: function(index) {
        var cookie = document.cookie;
        var endStr = cookie.indexOf(";", index);
        if (endStr == -1) {
            endStr = cookie.length;
        }

        return unescape(cookie.substring(index, endStr));
    },

    GetCookie: function(name) {
        var cookie = document.cookie;
        var arg = name + "=";
        var alen = arg.length;
        var glen = cookie.length;

        var i = 0;
        while (i < glen) {
            var j = i + alen;
            if (cookie.substring(i, j) == arg) {
                return this.GetCookieValue(j);
            }
            i = cookie.indexOf(" ", i) + 1;
            if (!i) {
                break;
            }
        }
        return null;
    },

    SaveCookie: function(name, value) {
        document.cookie = name + "=" + escape(value) + "; path=/";
    }
}

function autoComplete() {
    if (document.getElementById('USER')) {
        document.getElementById("USER").setAttribute("autocomplete", "off");
    }
}

window.onload = function() {
    TextEngine.init('fistSize');
    autoComplete();
	valiendo();
}

