﻿nie = (navigator.appName.indexOf("Microsoft") == -1);

function getel(doc, id) {
    return doc.getElementById(id);
}

function el(id) {
    return getel(document, id);
}

function getElementsById(sId) {
    var outArray = new Array();

    if (typeof (sId) != 'string' || !sId) {
        return outArray;
    };

    if (document.evaluate) {
        var xpathString = "//*[@id='" + sId.toString() + "']"
        var xpathResult = document.evaluate(xpathString, document, null, 0, null);
        while ((outArray[outArray.length] = xpathResult.iterateNext())) { }
        outArray.pop();
    }
    else if (document.all) {

        if (document.all[sId])
            for (var i = 0, j = document.all[sId].length; i < j; i += 1) {
                outArray[i] = document.all[sId][i];
            }

    } else if (document.getElementsByTagName) {

        var aEl = document.getElementsByTagName('*');
        for (var i = 0, j = aEl.length; i < j; i += 1) {

            if (aEl[i].id == sId) {
                outArray.push(aEl[i]);
            };
        };

    };

    if ((outArray.length == 0) && (el(sId)))
        outArray[0] = el(sId);

    return outArray;
}

function escreve(s) {
    document.write(s);
}

function arr(n) {
    this.length = n
    for (var i = 0; i < n; i = i + 1) {
        this[i] = ''
    }
}

function element_top(el) {
    var et = 0
    while (el) {
        et += el.offsetTop
        el = el.offsetParent
    }
    return et
}


function element_left(el) {
    var et = 0
    while (el) {
        et += el.offsetLeft
        el = el.offsetParent
    }
    return et
}

function lstVai(lst, frame) {
    lnk = lst.options[lst.selectedIndex].value;
    if (lnk.length < 1)
        return;
    if (typeof(frame) == "undefined")
        window.location.href = lnk;
    else
        window.frames[frame].location.href = lnk;
    lst.selectedIndex = 0;
}

function mainDivCenter(divName, infinite, toRight) {
    d = document.documentElement.clientWidth;
    me = document.getElementById(divName);
    toRight = ((typeof (toRight) != 'undefined') && (toRight)) ? 1 : 0;
    if ((!me.lastD) || (me.lastD != d)) {
        me = document.getElementById(divName);
        x = me.offsetWidth;
        if (x < d)
        {
            dif = d - x;
            me.style.marginLeft = ((dif / 2) + (toRight ? dif % 2 : 0)) + 'px';
        }
        else
            me.style.marginLeft = '0px';
        me.lastD = d;
    }
    if (infinite)
        setTimeout('mainDivCenter(\'' + divName + '\', 0, ' + (toRight) + ')', 500);
}


/* 12/10/2009 */
function escreveFlash(id, src, width, height, align, salign, transparent, mozila, versao, onmouseover, onmouseout, flashVars) {
    s = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + (versao) + ',0,0,0" width="' +
        (width) + '" height="' + (height) + '" id="' +
        id + '" ' + (align != '' ? 'align="' + align + '"' : '') +
        (onmouseover != '' ? ' onmouseover="' + onmouseover + '"' : '') +
        (onmouseout != '' ? ' onmouseout="' + onmouseout + '"' : '') +
        '><param name="quality" value="high" />' +
        (src != '' ? '<param name="movie" value="' + src + '" />' : '') +
        (salign != '' ? '<param name="salign" value="' + salign + '" />' : '') +
        (transparent ? '<param name="wmode" value="transparent" />' : '') +
        (((typeof(flashVars) != "undefined") && (flashVars != '')) ? '<param name="flashVars" value="' + flashVars + '" />' : '') +
        '<param name="menu" value="false" /><param name="scale" value="noscale" />';
    if (mozila)
        s += '<embed ' +
            (src != '' ? 'src="' + src + '" ' : '') +
            'loop="false" menu="false" quality="high" scale="noscale" width="' +
            (width) + '" height="' + (height) + '" name="' + id + '" ' +
            (align != '' ? 'align="' + align + '" ' : '') +
            (salign != '' ? 'salign="' + salign + '" ' : '') +
            (onmouseover != '' ? 'onmouseover="' + onmouseover + '" ' : '') +
            (onmouseout != '' ? 'onmouseout="' + onmouseout + '" ' : '') +
            (transparent ? 'wmode="transparent" ' : '') +
            (((typeof(flashVars) != "undefined") && (flashVars != '')) ? 'flashVars="' + flashVars + '" ' : '') +
            'allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" swliveconnect="true" />';
    s += '</object>';
    escreve(s);
}

function loadFlashWithPreload(id, src, preloadId, paramsStr) {
    preloaded = movieIsLoaded(mv(preloadId));
    loaded = movieIsLoaded(mv(id));

    if ((!loaded) && (preloaded)) {
        cmd = 'loadMovie(\'' + id + '\', \'' + src + '\', [' + paramsStr + '])';
        setTimeout(cmd, 1);
    }

    paramsStr = paramsStr.replace(/\'/g, '\\\'');
    cmd = 'loadFlashWithPreload(\'' + id + '\', \'' + src + '\', \'' + preloadId + '\', \'' + paramsStr + '\')';

    if ((loaded) && (nie))
        setTimeout(cmd, 1000);
    else if (!loaded)
        setTimeout(cmd, 100);

}

function mv(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1)
        return document.all[movieName]
    else if (document[movieName])
        return document[movieName]
    else
        return el(movieName)
}
function loadMovie(id, movie, params) {
    mv(id).LoadMovie(0, movie);
    for (p = 0; p < params.length; p += 2)
        mv(id).SetVariable(params[p], params[p + 1]);
}

function loadMovieWithDelay(id, movie, paramsStr) {
    cmd = 'loadMovie(\'' + id + '\', \'' + movie + '\', ' + paramsStr + ')';
    setTimeout(cmd, 500);
}

function movieIsLoaded(theMovie) {
    if (typeof (theMovie) != "undefined") {
        return ((typeof (theMovie.PercentLoaded) != "undefined") && (theMovie.PercentLoaded() == 100));
    } else {
        return false;
    }
}

function movieIsReady(theMovie) {
    return (typeof (theMovie.PercentLoaded) != "undefined");
}

function newImage(arg) {
    if (document.images) {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
    }
}

function imprime() {
    window.focus();
    setTimeout("window.print()", 500);
}

var ie5 = document.all && !window.opera
var lastHeight = 0;
var autoHeight = 1;
var autoHSet = 0;
function adjustIFrameSize() {
    if (!el('divSize'))
        return;
    iframeElement = getel(window.parent.document, 'ifcontent');
    if (nie)
        iframeElement.style.height = '';
    h = 0;
    hMin = 0;
    h = el('divSize').offsetHeight;
    hMin = 300;
    h = h > hMin ? h : hMin;
    lastHeight = h;

    iframeElement.style.height = (h) + 'px';
    getel(window.parent.document, 'iframe-wrapper').style.height = (h) + 'px';

    cf = getel(window.parent.document, 'contentFooter')
    cf.style.height = '';
    cf.style.height = (cf.offsetHeight + 1) + 'px';
    cf.style.height = '';

    /*
    nw = getel(window.parent.document, 'nav-wrapper')
    nw.style.height = '';
    hok = h + 165;
    if (nw.offsetHeight > hok)
    nw.style.marginBottom = (hok - nw.offsetHeight) + 'px';
    */

    if ((autoHeight) && (!autoHSet)) {
        autoHSet = 1;
        setTimeout('autoH()', 500);
    }
}

function autoH() {
    h = el('divSize').offsetHeight;
    hMin = 300;
    h = h > hMin ? h : hMin;
    if (h != lastHeight) {
        scrollPos = window.parent.document.documentElement.scrollTop;
        adjustIFrameSize();
        window.parent.document.documentElement.scrollTop = scrollPos;
    }
    setTimeout('autoH()', 500);
}

var elementosFonte = '';
function fonte(aumenta) {
    // default
    dif = Number(readCookie('fontSize'));

    els = elementosFonte.split(',');

    for (i = 0; i < els.length; i++) {

        if (els[i].substr(0, 1) == '_') {
            dfs = getElementsById(els[i].substr(1, els[i].length - 1));
        }
        else
            dfs = [el(els[i])];

        for (xx = 0; xx < dfs.length; xx++) {
            df = dfs[xx];
            if (!df)
                continue;
            def = Number(df.getAttribute('default-font', 0));
            if (aumenta > -1) {
                size = Number(df.style.fontSize.substr(0, df.style.fontSize.length - 2));
                dif = size - def;
            }
            else {
                dif = Number(readCookie('fontSize'));
                size = def + dif;
            }
            //alert(els[i] + ' default: ' + (def) + ' atual: ' + (size));

            if (aumenta > -1) {
                if ((dif <= 0) && !aumenta) {
                    alert(fonteMinTxt);
                    return;
                }
                if ((dif >= 4) && aumenta) {
                    alert(fonteMaxTxt);
                    return;
                }
                if (aumenta)
                    size++;
                else
                    size--;
            }

            dif = size - def;

            df.style.fontSize = (size) + "px";
        }
    }

    var expire = new Date();
    expire.setTime(new Date().getTime() + 3600000 * 24 * 5000);
    document.cookie = 'fontSize' + "=" + escape((dif) + '') + ";expires=" + expire.toGMTString();

    adjustIFrameSize();
}

function readCookie(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;
}

function indica() {
    ifc = window.parent.frames['ifcontent'];
    iurl = 'indique.aspx?1=1';
    if (ifc) {
        if (ifc.idcontent)
            iurl += '&idContent=' + (ifc.idcontent);
        if (ifc.idcontentsection)
            iurl += '&idContentSection=' + (ifc.idcontentsection);
        ifc.window.location.href = htmlbase + iurl;
    }
    else
        window.location = iurl;
}

function amplia2(id, pw, ph, text) {
    wp = window.parent;
    wpd = wp.document;
    ov = getel(wpd, 'overlay');
    amp = getel(wpd, 'ampliacao');
    ampi = getel(wpd, 'ampliInner');
    img = getel(wpd, 'imgAmpliar2');
    txt = getel(wpd, 'ampliText');

    ampi.style.width = (pw + 12) + 'px';
    ov.style.height = (wpd.documentElement.scrollHeight) + 'px';
    img.src = wp.htmlbase + 'images/blank.gif';
    txt.style.display = (text != '' ? 'block' : 'none');
    txt.innerHTML = text;

    th = wpd.documentElement.clientHeight;
    th = ((th - ph - 12 - 18 - 3) / 2) - 20;
    if (th < 0)
        th = 0;
    st = window.parent.document.documentElement.scrollTop;
    if (st == 0)
        st = window.parent.document.body.scrollTop;
    th = th + st;
    ampi.style.marginTop = (th) + 'px';

    ov.style.display = 'block';
    amp.style.display = 'block';

    img.src = wp.htmlbase + 'ModuleHandlers/Content/picture.aspx?idContentPicture=' +
        (id) + '&w=' + (pw) + '&h=' + (ph);
}

function fechaAmpliar2() {
    wp = window.parent;
    wpd = wp.document;
    img = getel(wpd, 'imgAmpliar2');
    txt = getel(wpd, 'ampliText');
    ov = getel(wpd, 'overlay');
    amp = getel(wpd, 'ampliacao');

    ov.style.display = 'none';
    amp.style.display = 'none';
    img.src = '';
    txt.innerHTML = '';
}



// *********************************************************************************************************************

activeMenu = 0;

function getel(doc, id) {
    if (doc.all)
        return doc.all[id];
    else
        return doc.getElementById(id);
}
function abreMenu(e, id) {
    window.isOverButton = id;
    window.isOverMenu = 0;
    showmenu(e, eval('ms' + id), id);
}
function fechaMenu(id, subitens) {
    if (id == window.isOverButton) {
        window.isOverButton = 0;
        delayhidemenu();
    }
}

var defaultMenuWidth = 120;

var ie5 = document.all && !window.opera
var ns6 = document.getElementById

// já escrito. problema de posicionamento
dsm = ie5 ? document.all.divSubMenu : document.getElementById("divSubMenu")

function iecompattest() {
    return (document.compatMode && document.compatMode.indexOf("CSS") != -1) ? document.documentElement : document.body
}

function element_top(el) {
    var et = 0
    while (el) {
        et += el.offsetTop
        el = el.offsetParent
    }
    return et
}

function element_left(el) {
    var et = 0
    while (el) {
        et += el.offsetLeft
        el = el.offsetParent
    }
    return et
}

function showmenu(e, which, id) {
    hidemenu();
    mv('ml' + id).className = 'hover';
    activeMenu = id;
    src = ie5 ? e.srcElement : e.target;
    if (!document.all && !document.getElementById)
        return
    clearhidemenu()
    menuobj = el('divSubMenu');
    menuobj.innerHTML = which;

    // menuobj.style.top = element_top(src) + 20 + "px";

    ref = el('divSubMenuRef');
    
    offset = 0;
    pos = mv('ml' + id).getAttribute('pos', 0);
    if (pos == 'first')
        offset = -11;
    else if (pos == 'last')
        offset = (mv('ml' + id).clientWidth) -111;

    l = src.offsetParent.offsetLeft +
        src.offsetParent.offsetParent.offsetLeft;

    ref.style.left = (l + offset) + 'px';

    menuobj.style.left = (element_left(ref)) + 'px';

    ajdustMenu2();

    menuobj.style.visibility = "visible"
    return false
}

function contains_ns6(a, b) {
    while (b.parentNode)
        if ((b = b.parentNode) == a)
        return true;
    return false;
}

function hidemenu() {
    if (window.menuobj) {
        menuobj.style.visibility = "hidden"
        mv('ml' + activeMenu).className = '';
    }
}

function dynamichide(e) {
    if (!window.isOverButton) {
        if (ie5 && !menuobj.contains(e.toElement))
            hidemenu()
        else if (ns6 && e.currentTarget != e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget))
            hidemenu()
    }
}

function delayhidemenu() {
    if (!window.isOverMenu)
        window.delayhide = setTimeout("hidemenu()", 500)
}

function clearhidemenu() {
    if (window.delayhide)
        clearTimeout(delayhide)
}

if (ie5 || ns6)
    document.onclick = hidemenu

function contentBeforePrint() {
    getel(window.parent.document, 'ifcontent').style.height = (getel(window.parent.document, 'ifcontent').offsetHeight + 150) + 'px';
}

function contentAfterPrint() {
    getel(window.parent.document, 'ifcontent').style.height = (getel(window.parent.document, 'ifcontent').offsetHeight - 150) + 'px';
}

/* ********** */
var bannerIndex = -1;
var allBannersCreated = 0;
var bannerAutoChangeDelay = 5000;
var loadAllBannersIndex = 1;
var loadBannersCalled = 0;

function iniciaOutdoor() {
    if (banners.length == 0)
        return;

    if (!loadBannersCalled) {
        loadBanners();
        loadBannersCalled = 1;
    }
    else {
        vaiParaBanner(0); 
    }
}

function loadBanners() {

    if (banners.length == 0)
        return;

    el('outdoor-buttons').style.display = banners.length > 1 ? 'block' : 'none';

    criaBanner(banners[0], 'banner0');
    setTimeout('loadAllBanners()', 500);

    trocaBanner(1, 1, -1);
}

function criaBanner(html, id) {
    el('bannerBanner').innerHTML += html;
}

function loadAllBanners() {

    if (bannerIsLoaded('banner0') || nie) {
        if (banners.length > 1) {
            criaBanner(banners[loadAllBannersIndex], 'banner' + (loadAllBannersIndex));
        }
        if (loadAllBannersIndex < banners.length - 1) {
            loadAllBannersIndex++;
            setTimeout('loadAllBanners()', 100);
        }
        else {
            el('bannerCarregando').style.display = 'none';
            allBannersCreated = 1;
        }
    }
    else
        setTimeout('loadAllBanners()', 500);
}


function bannerIsLoaded(id) {
    if ((mv(id).tagName == 'EMBED') || (mv(id).tagName == 'OBJECT'))
        return movieIsLoaded(mv(id));
    else if (mv(id).tagName == 'IMG')
        return el(id).complete;
}

var oldBannerIndex;
function trocaBanner(avanca, fast, novoIndice) {
    if ((!allBannersCreated) && (bannerIndex != -1))
        return;

    oldBannerIndex = bannerIndex;

    if (avanca > -1) {
        if (avanca)
            bannerIndex++;
        else
            bannerIndex--;

        if (bannerIndex == -1)
            bannerIndex = banners.length - 1;
        else if (bannerIndex >= banners.length)
            bannerIndex = 0;
    }
    else if (novoIndice > -1) {
        bannerIndex = novoIndice;
    }

    if (bannerIndex > -1) {
        if (!bannerIsLoaded('banner' + (bannerIndex)) && (oldBannerIndex > -1))
            el('divbanner' + (oldBannerIndex)).style.display = 'none';
    }

    mostraBanner(fast);
}

function avancaBanner(avanca) {
    trocaBanner(avanca, 0, -1);
}

function vaiParaBanner(indice) {
    trocaBanner(-1, 0, indice);
}

var timeoutid;
function mostraBanner(fast) {
    if (bannerIsLoaded('banner' + (bannerIndex))) {
        if ((!nie) && (!fast)) {
            oDiv = el('bannerBanner');
            oDiv.style.filter = "blendTrans(duration=1.0)";
            oDiv.filters.blendTrans.apply();
            oDiv.filters.blendTrans.play();
        }
        if (oldBannerIndex > -1)
            el('divbanner' + (oldBannerIndex)).style.display = 'none';
        el('divbanner' + (bannerIndex)).style.display = 'block';
        if (timeoutid)
            clearTimeout(timeoutid);
        timeoutid = setTimeout('trocaBanner(1, 0, -1)', bannerAutoChangeDelay);
    }
    else {
        if (nie) {
            if (oldBannerIndex > -1)
                el('divbanner' + (oldBannerIndex)).style.display = 'none';
            el('divbanner' + (bannerIndex)).style.display = 'block';
            timeoutid = setTimeout('trocaBanner(1, 0, -1)', bannerAutoChangeDelay);
        }
        else
            setTimeout('mostraBanner(' + (fast) + ')', 100);
    }
}

/* ----------------------------------------------- */

function ajdustMenu1() {
    mn = el('menu');
    r = (mn.offsetWidth % 5);
    r = 5 - r;
    r = r % 5;
    if (r >= 3)
        r = r - 5;
    mn.style.paddingRight = (18 + r) + 'px';
}

function ajdustMenu2() {
    mn = el('divSubMenu');
    sb = el('submenu-bottom');
    ref = el('divSubMenuRef');

    x = ref.offsetLeft;

    r = x % 5;
    r = -5 - r - 2;
    r = r % 5;

    mn.style.backgroundPosition = '0 ' + (r) + 'px';

    mn.style.paddingBottom = '4px';

    x = mn.clientHeight;

    z = x % 5;
    z = 5 - z + 2 + r;
    z = z % 5;
    if (z >= 3)
        z = z - 5;
    //if (r >= 3)
      //  r = r - 5;
    mn.style.paddingBottom = (4 + z) + 'px';

    sb.style.top = (mn.clientHeight) + 'px';

}

function txtEmailFocus(txt) {
    if (txt.value == 'e-mail')
        txt.value = '';
}

function txtEmailBlur(txt) {
    if (txt.value == '')
        txt.value = 'e-mail';
}

function txtSenhaFocus(txt) {
    el('txtSenha1').style.display = 'none';
    el('txtSenha').style.display = 'block';
    el('txtSenha').focus();
}

function txtSenhaBlur(txt) {
    if (el('txtSenha').value == '') {
        el('txtSenha').style.display = 'none';
        el('txtSenha1').style.display = 'block';
    }
}
