// Some useful functions

var DOM = new Object();
DOM.userAgent = navigator.userAgent.toLowerCase();
DOM.isKonq = DOM.userAgent.indexOf('konqueror') != -1;
DOM.isGecko = !DOM.isKonq && DOM.userAgent.indexOf('gecko') != -1;
DOM.isOpera = DOM.userAgent.indexOf('opera') != -1;
DOM.isIE = DOM.userAgent.indexOf('msie') != -1 && !DOM.isOpera;
DOM.isIE7 = DOM.isIE && window.XMLHttpRequest;

function getElementsByClass(searchClass, node, tag) {
    var classElements = new Array();
    if (node == null) {
        node = document;
    }
    if (tag == null) {
        tag = '*';
    }
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
        if (pattern.test(els[i].className)) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}

function bookmarkSite(title, url) {
    if (document.all) {
        window.external.AddFavorite(url, title);
    } else if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    }
}

function swapTextSize(downFalseUpTrue) {
    var mainArticleText = getElementsByClass('mainArticleText')[0];
    var mainArticleBody = getElementsByClass('mainArticleBody')[0];
    if (typeof downFalseUpTrue == 'undefined') {
        mainArticleText.style.fontSize = '1em';
        mainArticleBody.style.fontSize = '1em';
        return;
    } else if (!downFalseUpTrue) {
        mainArticleText.style.fontSize = '0.8em';
        mainArticleBody.style.fontSize = '0.8em';
    } else {
        mainArticleText.style.fontSize = '1.1em';
        mainArticleBody.style.fontSize = '1.1em';
    }
}

function viewportSize() {
    var viewportwidth;
    var viewportheight;
    if (typeof window.innerWidth != 'undefined') {
        // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
        viewportwidth = window.innerWidth;
        viewportheight = window.innerHeight;
    } else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)  {
        // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
        viewportwidth = document.documentElement.clientWidth;
        viewportheight = document.documentElement.clientHeight;
    } else {
        // older versions of IE
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
        viewportheight = document.getElementsByTagName('body')[0].clientHeight;
    }
    return { x: viewportheight, y: viewportwidth };
}

// Date & time

var RelojID24 = null;
var RelojEjecutandose24 = false;

function MostrarFecha() {  
    var nombres_dias = new Array("Domingo", "Lunes", "Martes", "Mi&eacute;rcoles", "Jueves", "Viernes", "S&aacute;bado");
    var nombres_meses = new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
    var fecha_actual = new Date();
    dia_mes = fecha_actual.getDate();
    dia_semana = fecha_actual.getDay();
    mes = fecha_actual.getMonth() + 1;
    anio = fecha_actual.getFullYear();
    // escribe en pagina
    document.write(nombres_dias[dia_semana] + " " + dia_mes + " de " + nombres_meses[mes - 1] + " de " + anio);
}

function DetenerReloj24() {
    if (RelojEjecutandose24) {
        clearTimeout(RelojID24);
    }
    RelojEjecutandose24 = false;
}

function MostrarHora24 () {
    var ahora = new Date();
    var horas = ahora.getHours();
    var minutos = ahora.getMinutes();
    var segundos = ahora.getSeconds();
    var ValorHora;
    // establece las horas
    if (horas < 10) {
        ValorHora = "0" + horas;
    } else {
        ValorHora = "" + horas;
    }
    // establece los minutos
    if (minutos < 10) {
        ValorHora += ":0" + minutos;
    } else {
        ValorHora += ":" + minutos;
    }
    // establece los segundos
    //~ if (segundos < 10) {
        //~ ValorHora += ":0" + segundos;
    //~ } else {
        //~ ValorHora += ":" + segundos;
    //~ }
    document.getElementById('liveTime').innerHTML = ValorHora + ' hs.';
    // si se desea tener el reloj en la barra de estado, reemplazar la anterior por esta
    // window.status = ValorHora
    RelojID24 = setTimeout("MostrarHora24()", 1000);
    RelojEjecutandose24 = true;
}

function IniciarReloj24 () {
    DetenerReloj24();
    MostrarHora24();
}


// Onload actions

window.onload = function() {
    //IniciarReloj24();
    if (DOM.isIE || DOM.isIE7) {
        //document.getElementById('mainBodyContainer').style.width = '1004px';
    }
    /*
    var viewport = viewportSize();
    if (viewport.y < 1004) {
        var sidebar = document.getElementById('right');
        sidebar.style.clear = 'both';
    }
    */
}
