nie = (navigator.appName.indexOf("Microsoft") == -1);

function getel(doc, id)
{
    return doc.getElementById(id);
}

function el(id)
{
    return getel(document, id);
}

function pel(id)
{
    return getel(window.parent.document, id);
}

function escreve(s)
{
	document.write(s);
}

function adjust1()
{
    if (el('k0'))
        el('k0').style.display = 'none';
    if (el('k1'))
        el('k1').style.display = 'none';
    if (el('k2'))
        el('k2').style.display = 'none';
    if (el('lr'))
        el('lr').style.display = 'none'
}


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
}

/* 29/09/2008 */
function escreveFlash(id, src, width, height, align, salign, transparent, mozila, versao, onmouseover, onmouseout, style)
{
    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 + '"' : '') +
        (typeof(style) != "undefined" ? ' style="' + style + '"' : '') +
        '><param name="quality" value="high" />' +
        (src != '' ? '<param name="movie" value="' + src + '" />' : '') +
        (salign != '' ? '<param name="salign" value="' + salign + '" />' : '') +
        (transparent ? '<param name="wmode" value="transparent" />' : '') +
        '<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" ' : '') +
            '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);
        setTimeout(cmd, 500);
    }

    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 ampliar(id, pw, ph, base)
{
	if (pw > 760)
		pw = 760;
	if (ph > 570)
		ph = 570;

	w = (screen.width-30);
	w = pw+10 > w ? w : pw+10;
	h = (screen.height-30);
	h = ph+10 > h ? h : ph+10;
	
	janela = window.open('about:blank','pict_big','toolbar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=no,menubar=no,width='+(w)+',height='+(h)+',top='+(((screen.height-h)/2)-30)+',left='+(((screen.width-w)/2)-10))
	janela.document.write('<HTML><TITLE>Imagem ampliada</TITLE>');
	janela.document.write('<BODY style="margin: 0px; padding: 0px">');
	janela.document.write('<TABLE BORDER=0 cellpadding=0 cellspacing=0 width=100% height=100%><TR><TD width=100% height=100% align=center valign=middle>');
	janela.document.write('<A HREF="" onclick="window.close(); return false"><IMG id=pic ALT="Clique para fechar" SRC="' + base + 'ModuleHandlers/Content/picture.aspx?idContentPicture=' + (id) + '&w='+(janela.document.body.clientWidth-10)+'&h='+(janela.document.body.clientHeight-10)+'" BORDER=0 style="border: 1px solid gray"></a>');
	janela.document.write('</TD></TR></TABLE></BODY></HTML>');	
	
	janela.focus()
	
}

function newImage(arg) {
	if (document.images) {  
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function imprime()
{
	setTimeout("window.print()", 500);
}

var ie5=document.all && !window.opera
var lastHeight = 0;
var autoHeight = 0;
var autoHSet = 0;
function adjustIFrameSize () 
{
    if (!el('iframe-content'))
        return;
        
	iframeElement = getel(window.parent.document, 'ifcontent');
	iframeWindow = window.parent.frames[name];
	if (nie)
        iframeElement.style.height = '';
        
    ifc = el('iframe-content');
    ifc.style.height = '';

    cc = el('content');
    cc.style.height = '';
        
    h = 0;
    hMin = 0;
    h = ifc.offsetHeight;
    hMin = 330;
    h = h > hMin ? h : hMin;    
	lastHeight = h;
	
    iframeElement.style.height = (h) +'px';
    pel('iframe-interna-wp').style.height = (h) +'px';
    
    if (ifc.offsetHeight < h)
        ifc.style.height = (h) + 'px';
    if (cc.offsetHeight < h-36)
        cc.style.height = (h-36) + 'px';
	
	if ((autoHeight) && (!autoHSet))
	{
	    autoHSet = 1;
	    setTimeout('autoH()', 500);
	}
}

function autoH()
{
    h = el('iframe-content').offsetHeight;
    hMin = 330;
    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++)
    {
        df = el(els[i]);
        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;
        }
        
	    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 != 0)
		    iurl += '&idContent=' + (ifc.idcontent);
	    if (ifc.idcontentsection != 0)
		    iurl += '&idContentSection=' + (ifc.idcontentsection);
	    ifc.location = htmlbase + iurl;
	}
	else
	    window.location = iurl;
}

function abreGaleria(id, idContentPicture)
{
	janela = window.open(htmlbase + 'galeria.aspx?idContent=' + (id) + (typeof(idContentPicture) != 'undefined' ? '&idContentPicture=' + (idContentPicture) : ""),'galeria','toolbar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=no,menubar=no,width=611,height=477,top='+((screen.height-477)/2)+',left='+((screen.width-611)/2));
	janela.focus();
	return false;
}

function abre(url, ifc)
{
    if (ifc)
        window.parent.frames['ifcontent'].location = htmlbase + url;
    else
        window.location = htmlbase + 'padrao.aspx?' + url;
}


/* ----------------------------------------------- */

var menuItens = new arr(0);
var menuComplete = 0;
var menuLoaded = 0;

function addMenuItem(id, src, preloadId, paramsStr)
{
    menuItens.length++;
    i = menuItens.length-1;
    menuItens[i] = new arr(4);
    menuItens[i][0] = id;
    menuItens[i][1] = src;
    menuItens[i][2] = preloadId;
    menuItens[i][3] = paramsStr;
}

function menuDone()
{
    menuComplete = 1;
}

function mostraMenu()
{
    preloaded = movieIsLoaded(mv('menuPreload'));
    loaded = movieIsLoaded(mv('menuPreload'));

    if ((!menuComplete) || (!preloaded) || (!loaded))
        setTimeout('mostraMenu()', 100);
    else if (!menuLoaded)
    {
        menuLoaded = 1;
        for (i=0; i<menuItens.length; i++)
        {
            cmd = 'loadMovie(\'' + menuItens[i][0] + '\', \'' + menuItens[i][1] + '\', [' + menuItens[i][3] + '])';
            setTimeout(cmd, i*100);

            // para manter visivel no mozila
            menuItens[i][3] = menuItens[i][3].replace(/\'/g, '\\\'');
            cmd = 'loadFlashWithPreload(\'' + menuItens[i][0] + '\', \'' + menuItens[i][1] + '\', \'' + menuItens[i][2] + '\', \'' + menuItens[i][3] + '\')';
            setTimeout(cmd, (i * 100) + 1000);
        }
    }
}

function umclique(base, sel)
{
	val = sel.options[sel.selectedIndex].value;
	if (val != '')
		window.location = base + val;
}

// *********************************************************************************************************************

if (!window.parent.activeMenu)
    window.parent.activeMenu = 0;

function abreMenu(e,id)
{
	window.parent.isOverButton = id;
	window.parent.isOverMenu=0;
	showmenu(e,eval('ms' + id), id);		
}
function fechaMenu(id, subitens)
{
	if (id == window.parent.isOverButton)
	{
		window.parent.isOverButton = 0;
		window.parent.delayhidemenu();
	}
}

var defaultMenuWidth=70;

var ie5=document.all && !window.opera
var ns6=document.getElementById

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
}

var activeSub = 0;

function showmenu(e, data, id)
{
    window.parent.docIfMenu = window.parent.frames['ifmenu'];

    window.parent.hidemenu();
    window.parent.hideSubSub();
    
    mv('m' + id).SetVariable('hideOver', 'no');
    mv('m' + id).SetVariable('isOverSub', 'yes');
    
    window.parent.activeMenu = id;
    
    src = ie5 ? e.srcElement : e.target;
    
    if (!document.all&&!document.getElementById)
        return;
        
    window.parent.clearhidemenu();

    window.parent.menuobj = pel('submenu');
    c1obj = pel('coluna1');
    c1obj.style.paddingRight = '';

    colunas = (data.length > 10 ? 2 : 1);
    c2pos = -1;
    if (colunas == 2)
        c2pos = Math.ceil(data.length / 2);
    c2pos--;
    c1htm = '<ul id=menuUL1>';
    mul = 'menuUL1';
    for (i=0; i<data.length; i++) {
        if (data[i] == null)
            continue;
        sep = ((data[i][3]) && (i<data.length-1));
        c1htm += '<li id=liMenu' + (i) + ' ' + (sep ? 'style="padding-bottom: 13px"' : '') + '><a ';
        if (((data[i][4] == 0) || (data[i][1] != '')) && (data[i][1].indexOf('=paragon_cases_segmento&') == -1))   // se ((não tiver sub-itens) ou (se houver um link para a seção)) e (não for cases)
            c1htm += 'href="' + data[i][1] + '" target="' + data[i][2] + '" onclick="' + (data[i][1] == '' ? 'return false' : 'hidemenu()') + '">';
        else
            c1htm += 'href="#" onclick="showSubSub(this, eval(\'docIfMenu.ms' + (id) + '[' + (i) + ']\')); return false">';
        c1htm += (data[i][0]) + '</a>';
        if (sep)
            c1htm += '<div id=liMenuSep><div id=liMenuSep2 name=liMenuSep2 menu=' + mul + '>\n</div></div>';
        c1htm += '</li>';
        if (i == c2pos)
        {
            c1htm += '</ul><ul id=menuUL2>';
            mul = 'menuUL2';
        }
    }
    c1htm += '</ul>';
    
    c1obj.innerHTML = c1htm;

    if (window.parent.menuobj.offsetWidth < src.offsetWidth)
        c1obj.style.paddingRight = (src.offsetWidth-window.parent.menuobj.offsetWidth) + 'px';
    
    ift = element_top(pel('ifmenu'));
    window.parent.menuobj.style.top = (ift + element_top(src)) + (window.parent.imain ? 29 : 31) + "px";
    ifl = element_left(pel('ifmenu'));
    window.parent.menuobj.style.left = (ifl + element_left(src)) + "px";

    seps = window.parent.document.getElementsByName('liMenuSep2');
    for (i = 0; i < seps.length; i++) {
        w = 0;
        if (colunas != 2) {
            w = (pel(seps[i].getAttribute('menu', 2)).offsetWidth+8);
        }
        else
        {
            seps[i].style.left = '0px';
            w = ((pel(seps[i].getAttribute('menu', 2)).offsetWidth)-15);
        }

        seps[i].style.width = (w) + 'px';
    }

    window.parent.menuobj.style.visibility="visible"
    
    return false;
}

function showSubSub(lnk, data)
{
    // event.cancelBubble = 1;

    if (activeSub)
        activeSub.style.fontWeight = 'normal';
    activeSub = lnk;
    lnk.style.fontWeight = 'bold';

    c2obj = el('coluna2');
    closeobj = el('close');
    c2htm = '<a id="active" href="#"></a><ul id=submenuUL1><li id=liActive><a>' + data[0] + '</a></li>';
    mul = 'submenuUL1';

    c1obj = el('coluna1');
    c1obj.style.paddingRight = '';

    data2 = data[4];
    
    colunas = (data2.length > 10 ? 2 : 1);
    c2pos = -1;
    if (colunas == 2)
        c2pos = Math.ceil(data2.length / 2);
    c2pos--;
    for (i=0; i<data2.length; i++)
    {
        if (data2[i] == null)
            continue;
        sep = ((data2[i][3]) && (i < data2.length - 1));
        c2htm += '<li id=liSubMenu' + (i) + ' ' + (sep ? 'style="padding-bottom: 13px"' : '' ) + '><a ';
        c2htm += 'href="' + data2[i][1] + '" target="' + data2[i][2] + '" onclick="' + (data2[i][1] == '' ? 'return false' : 'hidemenu()') + '">';
        c2htm += data2[i][0];
        c2htm += '</a>';
        if (sep)
            c2htm += '<div id=liMenuSep><div id=liMenuSep3 name=liMenuSep3 menu=' + (mul) + '>\n</div></div>';
        c2htm += '</li>';
        if (i == c2pos)
        {
            c2htm += '</ul><ul id=submenuUL2><li id=liActive><a style="background-image: none">&nbsp;</a></li>';
            mul = 'submenuUL2';
        }
    }

    c2htm += '</ul>';
    
    c2obj.innerHTML = c2htm;
    c2obj.style.display = 'block';
    
    seps = document.getElementsByName('liMenuSep3');
    for (i=0; i<seps.length; i++)
    {
        if (colunas != 2)
            seps[i].style.width = (el(seps[i].getAttribute('menu', 2)).offsetWidth)+'px';
        else
        {
            seps[i].style.left = '0px';
            seps[i].style.width = ((el(seps[i].getAttribute('menu', 2)).offsetWidth)-26)+'px';
        }
        // seps[i].style.width = (c2obj.offsetWidth-1) + 'px';
    }
    
    closeobj2 = el('close2');
    closeobj2.style.height = (window.parent.menuobj.offsetHeight - 30) + 'px';

    closeobj2.style.display = 'block';
    c2obj.style.display = 'block';
    closeobj.style.display = 'block';
}

function hideSubSub()
{
    // window.event.cancelBubble = 1;
    c2obj = el('coluna2');
    closeobj = el('close');
    closeobj2 = el('close2');
    c2obj.style.display = 'none';
    closeobj.style.display = 'none';
    closeobj2.style.display = 'none';
    if (activeSub)
        activeSub.style.fontWeight = 'normal';
}

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"
		if (docIfMenu.mv('m' + window.activeMenu)) {
		    docIfMenu.mv('m' + window.activeMenu).SetVariable('isOverSub', 'no');
            docIfMenu.mv('m' + window.activeMenu).SetVariable('hideOver', 'yes');
        }
	}
}

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()",750)
}

function clearhidemenu(){
if (window.delayhide)
clearTimeout(delayhide)
}

/* ********** */
var bannerIndex = -1;
var allBannersCreated = 0;
var bannerAutoChangeDelay=10000;
var loadAllBannersIndex = 1;
function loadBanners()
{
    if (banners.length == 0)
        return;
        
    criaBanner(banners[0], 'banner0');
    setTimeout('loadAllBanners()', 500);
    
    // ajusta botões de navegação
    // ...
    
    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=0.5)";
   		    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);
        acendeBotaoBanner(bannerIndex);
    }
    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);
            acendeBotaoBanner(bannerIndex);
        }
        else
            setTimeout('mostraBanner(' + (fast) + ')', 100);
    }
}

function acendeBotaoBanner(indice)
{
    for (y=1; y<=banners.length; y++)
        if (el('buttonb' + (y)))
            el('buttonb' + (y)).className = 'buttonb';
    if (el('buttonb' + (indice+1)))
        el('buttonb' + (indice+1)).className = 'buttonbActive';
}

/* ----------------------------------------------- */

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';
}

function mostraLogin()
{
    el('index-login-wrapper').style.display = 'block';
    document.forms[0].email.focus();
    document.forms[0].email.select();
    clearTimeout(timeoutId);
}

var timeoutId = 0;

function iniciaAbreHome(base)
{
    timeoutId = setTimeout('abreHome(\'' + base + '\')', 20000);
}

function abreHome(base)
{
    window.location = base + 'padrao.aspx';
}

function getElementTop(elem) 
{
	yPos = elem.offsetTop;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
	}
	return yPos;
}

function getElementLeft(elem) 
{
	yPos = elem.offsetLeft;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
	}
	return yPos;
}

function showCalendar(txt, but)
{
    divc = el('divcal');
            
    if (divc.style.display == 'block')
    {
        divc.style.display = 'none'; 
        return;
    }
            
    ifc = el('ifcal');
    ifc.src = htmlbase + 'controles/calendar.aspx?date=' + txt.value + '&rnd=' + (Math.random());

    divc.style.top = (getElementTop(but) + but.offsetHeight + 4) + 'px';
    divc.style.left = (getElementLeft(but)) + 'px';
    divc.style.display = 'block'; 

    divc.control = txt;
    
	setTimeout('document.onclick = hideCal;', 100);
}

function hideCal()
{
    el('divcal').style.display = 'none'; 
	document.onclick = '';
}

function calClick(date)
{
    hideCal();
    divc = el('divcal');
    divc.control.value = date;
    divc.control.focus();
}

function reloadSubMenus()
{
    ifc = window.parent.document.frames['ifcontent'];
    if (ifc && getel(ifc.document, 'iframe-interna'))
        ifc.location.reload(1);
}

function buscaClick()
{
    bm = pel('busca-menu');
    vis = bm.style.display == 'block';
    bm.style.display = vis ? 'none' : 'block';
    if (!vis)   
    {
        buscaOver();
        pel('busca-box').focus();
    }
    else
    {
        pel('busca-box').value = '';
        window.focus();
    }
    buscaOut();
}

function buscaOver()
{
    el('busca').className = 'buscaOver';
}

function buscaOut()
{
    bm = pel('busca-menu');
    vis = bm.style.display == 'block';
    if (!vis)
        el('busca').className = '';
}

function busca(ifc)
{
    s = 'busca.aspx?p=' + document.forms['formbusca'].p.value;
    tr = document.forms['formbusca'].treinamentos;
    if (tr)
    {
        if (tr[0].checked)
            s += '&treinamentos=' + tr[0].value;
        else if (tr[1].checked)
            s += '&treinamentos=' + tr[1].value;
    }
    if (document.forms['formbusca'].site)
        s += '&site=' + document.forms['formbusca'].site.value;
    
    window.frames['ifmenu'].buscaClick();
    
    abre(s, ifc);
}

/* ************** */

var estiloAtivo = '';
var ww = 0;
var cc = 0;

function mainAdjust(estilo)
{
    if (estilo != estiloAtivo)
    {
        ww = estilo == 'ww';
        cc = estilo == 'cc';
        
        c = document.getElementById('lnkCss');
        c.setAttribute('href', 'css/estilo_' + estilo + '.css');
        
        el('ifmenu').src = 'about:blank';
        url = 'controles/menu.aspx?menu=' + estilo + '&home=false';
        cmd = 'el(\'ifmenu\').src = \'' + url + '\'';
        setTimeout(cmd, 500);

        el('iflogin').src = 'about:blank';
        url = 'controles/cxLoginInterna.aspx?' + (ww ? 'paragon' : 'cc') + '=true&rnd=' + (Math.random());
        cmd = 'el(\'iflogin\').src = \'' + url + '\'';
        setTimeout(cmd, 500);

        el('imgLogoTop').src = 'images/flash_paragon_' + estilo + '.gif';
        el('imgLogoTop').style.display = 'block';
        el('logos').style.display = ww ? 'block' : 'none';
        el('adress').style.width = ww ? '178px' : '550px';
        el('pAdressWW').style.display = ww ? 'block' : 'none';
        el('pAdressCC').style.display = cc ? 'block' : 'none';
        el('filtrosBusca').style.display = cc ? 'block' : 'none';

        el('imgIndique').src = 'paint/texto.ashx?s=lt&id=home_indique&e=' + (ww ? 9 : 10);
        el('imgIndique').style.display = 'block';
        el('imgContato').src = 'paint/texto.ashx?s=lt&id=home_contato&e=' + (ww ? 9 : 10);
        el('imgContato').style.display = 'block';

        el('hdSiteBusca').value = estilo;

        el('lnkLogo').href = ww ? htmlbase : htmlbase + 'cc_temp/';
        
        estiloAtivo = estilo;
    }
    
}

function loginAdjust(mostrar, ww, reload)
{
    el('iflogin').style.display = mostrar ? 'block' : 'none';
    if (reload)
        window.frames['iflogin'].location = htmlbase + 'controles/cxLoginInterna.aspx?' +
            (ww ? 'paragon' : 'cc') + '=true&rnd=' + (Math.random());
    
}

/* ************** */

function validaCep(oSrc, args) {
    args.IsValid = args.Value.length == 8;
}

function abreFechaIdiomas() {
    el('lista-idiomas').style.display = (el('lista-idiomas').style.display != 'block' ? 'block' : 'none');
    window.focus();
    setTimeout('document.onclick = Document_Click1', 100);
}

function Document_Click1() {
    if (el('lista-idiomas'))
        el('lista-idiomas').style.display = 'none';
    document.onclick = '';
};

function trocaIdioma(id) {
    window.parent.location = 'default.aspx?changeLanguage=' + id + '&rnd=' + (Math.random());
}

function chkManterIdiomaClick(vl) {
    var expire = new Date();
    expire.setTime(new Date().getTime() + 3600000 * 24 * 5000);
    document.cookie = 'keepLanguage' + "=" + (vl ? 1 : 0) + ";expires=" + expire.toGMTString();
}