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 getel(doc, id)
{
	if (doc.all)
		return doc.all[id];
	else
		return doc.getElementById(id);
}

var activeSection = 0;

function adjust(stl, section)
{
    activeSection = section;
    
	showBuscaRodape = (stl != 'home_aspx');
	hideMenu = (stl == 'busca_aspx');
	
	getel(document, 'buscaRodape').style.display = showBuscaRodape ? 'block' : 'none';
	getel(document, 'conteudo').style.marginBottom = showBuscaRodape ? '80px' : '0px';
	
	ajdustMenu(!hideMenu, !hideMenu);
}
function ajdustMenu(fixed, visible)
{
	getel(document, 'menu').style.marginLeft = visible ? '' : '-144px';

	getel(document, 'ifcontent').style.width = fixed ? '470px' : '625px';
	getel(document, 'conteudo').style.width = fixed ? '470px' : '625px';
	getel(document, 'conteudo').style.marginLeft = fixed ? '11px' : (visible ? '-144px' : '-10px');
	if (getel(window.frames['ifcontent'].document, 'conteudo'))
		getel(window.frames['ifcontent'].document, 'conteudo').style.width = fixed ? '470px' : '625px';

	getel(document, 'botoesTopoMenu').style.display = (!fixed && !visible) ? 'none' : 'block';
	getel(document, 'abreMenu').style.display = (!fixed && !visible) ? 'block' : 'none';
	getel(document, 'fechaMenu').style.display = (!fixed && visible) ? 'block' : 'none';
}
function escreve(s)
{
	document.write(s);
}

/* Coberturas ************************************************* */

var outItens;
var automatic = 1;
var slideTime = 10000;
var speed = 100;
var changingImage = 0;
var outItemIndex = -1;
var newIndex = -1;
var changeStep = 0;
var changeDirection = 1;
var timeoutId = -1;

function matriz(n)  {
   this.length=n
   for (var i=0;i<n;i=i+1)  {
     this[i] = ''
   }
}

function addOutItem(idContent, idContentPicture)
{
	outItens.length++;
	outItens[outItens.length-1] = new matriz(3);
	outItens[outItens.length-1].idContent = idContent;
	outItens[outItens.length-1].idContentPicture = idContentPicture;
}

function initOutdor(picturesCount, auto, slide_time, slide_change_speed)
{
	automatic = auto;
	slideTime = slide_time;
	speed = slide_change_speed;
	
	outItens = new matriz(0);
}

function initOutdor2()
{
	if (loadok)
	{
		setTimeout('loadPictures()', 100);
		setTimeout('changePicture(1, false)', 100);
	}
	else
	{
		setTimeout('initOutdor2()', 500);
	}
}

function loadPictures()
{
	for (i=0; i<outItens.length; i++)
	{
		if (!(outItens[i].ok))
		{
			// verifica se a imagem anterior já foi carregada
			if ((i > 0) && !(outItens[i-1].img.complete))
			{
				setTimeout('loadPictures()', 100);
				break;
			}
			else
			{
				outItens[i].img = newImage(getSrc(outItens[i].idContentPicture));
				outItens[i].ok = 1;
			}
		}
	}
}

function changePicture(forward, byUser, destindex)
{
	if ((changingImage) && (byUser))
		return;

	//if (byUser)
		//automatic = 0;
		
	img = getel(document, 'outPicture');
	
	if (newIndex == outItemIndex)
	{
		newIndex = outItemIndex;
		if (forward)
		{
			newIndex++;
			if (newIndex >= outItens.length)
				newIndex = 0;
		}
		else if (typeof(destindex) != "undefined")
		{
			newIndex = destindex;
		}
		else
		{
			newIndex--;
			if (newIndex < 0)
				newIndex = outItens.length-1;
		}
	}
	
	if ((outItens[newIndex].ok) && (outItens[newIndex].img.complete))
	{
		changingImage = 0;
		
		if ((!byUser) && (outItemIndex > -1))
			slowChange(1);
		else
			show(newIndex);
		
		outItemIndex = newIndex;
		
		if (automatic)
			timeoutId = setTimeout('changeSlide()', slideTime);
	}
	else
	{
		img.src = "images/blank.gif";
		changingImage = 1;
		setTimeout('changePicture(' + (forward) + ', 0)', 100);
	}
}

function getSrc(id)
{
	return 'controles/fotoAcontece.aspx?idContentPicture=' + (id);
}

function slowChange(start)
{
	try
	{
		oDiv = getel(document, 'divSlide');
		oDiv.style.filter="blendTrans(duration=2)";
   		oDiv.filters.blendTrans.apply();
		oDiv.filters.blendTrans.play();
		show(newIndex);
	}
	catch(e)
	{
		show(newIndex);
	}
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeSlide()
{
	if (automatic)
		changePicture(1, 0);
}

function show(index)
{
	getel(document, 'outPicture').src = getSrc(outItens[index].idContentPicture);
	sl = getel(document, 'slAcontece');
	if (document.activeElement != sl)
		for (i=0; i<sl.options.length; i++)
			if (sl.options[i].value == outItens[index].idContent)
			{
				sl.selectedIndex = i;
				break;
			}
}

function slAconteceClick(sl)
{
	for (i=0; i<outItens.length; i++)
		if (outItens[i].idContent == sl.options[sl.selectedIndex].value)
		{
			clearTimeout(timeoutId);
			changePicture(0, 1, i);
			break;
		}
}

var div1;
var div2;

var desloc = 1;
var time = 50;

function start()
{
	div1 = getel(document, 'divAll1');
	div2 = getel(document, 'divAll2');
	divB = getel(document, 'divBoth');
	
	document.body.style.width = (div1.clientWidth + div2.clientWidth) + 'px';
	divB.style.width = (div1.clientWidth + div2.clientWidth) + 'px';
	
	if (div1.clientWidth > 470)
	{
		div2.style.left = (div1.clientWidth+3)+'px';
		div2.style.visibility = 'visible';
		move();
	}
}

function move()
{
	div1.style.left = div1.offsetLeft - desloc + 'px';
	div2.style.left = div2.offsetLeft - desloc + 'px';
	setTimeout('move()', time);
	if ((div2.offsetLeft < 0) && (div1.offsetLeft < div2.offsetLeft))
		div1.style.left = div2.offsetLeft + div2.clientWidth;
	else if ((div1.offsetLeft < 0) && (div2.offsetLeft < div1.offsetLeft))
		div2.style.left = div1.offsetLeft + div1.clientWidth;
		
	
}

/* *********************************************************** */

function notifyMiOk(pos)
{
    m1ok = (m1ok) || (pos == 1);
    m2ok = (m2ok) || (pos == 2);
    m3ok = (m3ok) || (pos == 3);
    if (m1ok && m2ok && m3ok)
    {
        // determina a altura máxima
        maxH = 0;
        for (i=1; i<=3; i++)
        {
            miid = 'mi' + (i);
            iframeElement = getel(document, miid);
        	doc = window.frames[miid].document;
        	mih = doc.getElementById('ulItens').offsetHeight + 30;
        	if (mih > maxH)
        	    maxH = mih;
        }
        // ajusta todos
        for (i=1; i<=3; i++)
        {
            miid = 'mi' + (i);
            getel(document, miid).style.height = (maxH) + 'px';
        	doc = window.frames[miid].document;
        	doc.getElementById('bottomLeftCorner').style.bottom = '';
        	doc.getElementById('bottomLeftCorner').style.top = (maxH-2) + 'px';
        }
    }
}

function miEdit(show)
{
    if (m1ok && m2ok && m3ok)
    {
        for (i=1; i<=3; i++)
        {
            miid = 'mi' + (i);
        	doc = window.frames[miid].document;
        	doc.getElementById('hTitulo').style.display = (show ? 'none' : 'block');
        	doc.getElementById('fEscolha').style.display = (show ? 'block' : 'none');
        	if (!show)
        	    doc.getElementById('pickcolor').style.display = 'none';
        	
        }
        document.getElementById('butMiEdit').style.display = (!show ? 'inline' : 'none');
        document.getElementById('butMiEndEdit').style.display = (show ? 'inline' : 'none');
    }
}

function loadBanners()
{
    bt = getel(window.parent.document, 'bannerTesteHtml');

    bt.innerHTML = bannerSuperiorHtml;
    bs = getel(window.parent.document, 'bannerSuperior');
    if (window.parent.bannerSuperiorLastHtml != bt.innerHTML)
        bs.innerHTML = bt.innerHTML;
    bs.style.display = bt.innerHTML != '' ? 'block' : 'none';
    window.parent.bannerSuperiorLastHtml = bt.innerHTML;

    for (i=1; i<=6; i++)
    {
        b = getel(window.parent.document, 'bannerLateral' + (i));
        b.style.display = i <= banners.length ? 'block' : 'none';
        bt.innerHTML = i <= banners.length ? banners[i-1] : '';
        if (b.innerHTML != bt.innerHTML)
            b.innerHTML = i <= banners.length ? banners[i-1] : '';
    }
    
    bt.innerHTML = bannerLateral1024;
    bl = getel(window.parent.document, 'banner1024');
    if (window.parent.bannerLateral1024LastHtml != bt.innerHTML)
        bl.innerHTML = bt.innerHTML;
    getel(window.parent.document, 'banner1024Out').style.display = bt.innerHTML != '' ? 'block' : 'none';
    window.parent.bannerLateral1024LastHtml = bt.innerHTML;
    
}

function fonte(aumenta)
{
	df = document.getElementById('divFonte');
	size = df.style.fontSize.substr(0, df.style.fontSize.length-2);
	if ((size <= 11) && !aumenta)
	{
		alert('O texto já está no tamanho mínimo!');
		return;
	}
	if ((size >= 17) && aumenta)
	{
		alert('O texto já está no tamanho máximo!');
		return;
	}
	if (aumenta)
	{
		size++;
		size++;
	}
	else
	{
		size--;
		size--;
	}
	df.style.fontSize = (size) + "px";
	var expire = new Date();
	expire.setTime(new Date().getTime() + 3600000*24*5000);
	document.cookie = 'fontSize'+"="+escape((size) + '')+ ";expires="+expire.toGMTString();
	adjustIFrameSize();
}

function adjustIFrameSize () 
{
	iframeElement = getel(window.parent.document, 'ifcontent');
	iframeWindow = window.parent.frames[name];
	//if (!ie5)
	//	iframeElement.style.height = '100%';
	h = ie5 ? document.body.scrollHeight : document.documentElement.scrollHeight;
	iframeElement.style.height = h+'px';
	// getel(document, 'conteudoInterno').style.height = (h < 450 ? 450 : h) +'px';
	//if (!ie5)
	//	getel(window.parent.document, 'conteudoInterno').style.height = '100%';
}

function imprime()
{
	setTimeout("window.print()", 1000);
}

function arr(n)  {
   this.length=n
   for (var i=0;i<n;i=i+1)  {
     this[i] = ''
   }
}

/* 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);
}