/*
*	----------------------------------------------------------------------------
*	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,
    button: null,

    init: function(parentId, inc) {

        /* Elemento padre */
        parentObj = document.getElementById(parentId);

        /* Elemento body */
        this.bodyObj = document.getElementsByTagName('BODY')[0];
                
        /* Creación del botón */
        this.button = document.createElement('INPUT');
        this.button.type = "button";
        this.button.value = "A" + inc;
        this.button.className="png-trans";
        
        if (inc=="+")
            this.button.onclick = this.increaseText;
        else
            this.button.onclick = this.decreaseText;
            
        parentObj.appendChild(this.button);
        
        /* 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 1;
        }
    }
}


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('sizetext1','+');
    TextEngine.init('sizetext2','-');
    autoComplete();
}

