function vaiPara(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function ShowHide(tmp_id) {
	if (document.getElementById(tmp_id).style.display == 'none') {
		document.getElementById(tmp_id).style.display = '';
	} else {
		document.getElementById(tmp_id).style.display = 'none';
	}
}

function pup_up2(tmp_link,tmp_w,tmp_h) {
		alert(tmp_link);
		//window.open(tmp_link,'nova','width=' + tmp_w + ', height=' + tmp_h);
}

function showLayer(id) {
	document.getElementById(id).style.display = '';
}

function hideLayer(id) {
	document.getElementById(id).style.display = 'none';
}

var $id = "";
function toggle(id)
{
	//document.body.scrollTop = 0
	if(($id != "" && $id != id) || ($id == id && document.getElementById($id).style.display == 'block'))
	{
		document.getElementById($id).style.display = 'none';
//		document.getElementById($id).parentNode.childNodes.item("a").style.backgroundPosition = '8px 8px';
	} 
	if(($id != id))
	{
		$id = id;
		//mostra o DD com o ID fornecido
		document.getElementById($id).style.display = 'block';
//		document.getElementById($id).parentNode.childNodes.item("a").style.backgroundPosition = '8px -37px';
	}
}
/*//////////////////////////////////////
//BANNERS
//////////////////////////////////////*/
function fBanners(swf, w, h){
	document.write("			<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='" + w + "' height='" + h + "' title='Comg&aacute;s'>");
	document.write("			  <param name='movie' value='" + swf + "'>");
	document.write("			  <param name='quality' value='high'>");
	document.write("			  <param name='wmode' value='transparent'/>");
	document.write("			  <param name='flashvars' value='dstk0=destaque01|link0&dstk1=destaque02|link1'/>");
	document.write("			  <embed src='" + swf + "' quality='high'  flashvars='dstk0=destaque01|link0&dstk1=destaque02|link1'  wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + w + "' height='" + h + "'></embed>");
	document.write("			</object>")
}
function setBanner(h,z)
{
	document.getElementById('banner_xp').style.height = h;
	document.getElementById('banner_xp').style.zIndex = z;

	if(z>2)
	{
		//fScrollTo(document.getElementById("banner_xp").offsetTop);
		window.scrollTo(0, (document.getElementById("banner_xp").offsetTop - 5));
	}
	else
	{
		//fScrollTo(0);
		window.scrollTo(0,0);
	}
/*
	alert(document.getElementById("banner_xp").style.documentX)
	document.location.href = "#banner_xp_ancora";
	document.location.href = document.location.href;
*/
}

function fScrollTo(y)
{
	var destino = y;
	var origem = document.body.scrollTop;
	var distancia = (destino - origem>0) ? destino - origem : (destino - origem) * -1;
	window.scrollBy(0, px);
	
	var tempo = ((distancia/100)>0) ? Math.round(distancia/100) : 1;
	var px = Math.round(distancia / 100);
	
	window.setTimeout("fScroll(" + px + "," + destino + ")", (tempo * 50));
}

function fScroll(px, destino)
{
	/*
	destino = 290
	origem = 90
	distancia = 200
	tempo 200/100 = 2
	pixels = (200 / (2*50))
	*/
	var destino = destino;
	var origem = document.body.scrollTop;
	var distancia = destino - origem;
	var documento = document.body.scrollHeight;
	var janela = navigator.appName=="Netscape" ? window.innerHeight : document.body.offsetHeight;
	window.scrollBy(0, px);
	//origem + px
	var tempo = (Math.round(distancia/100)>0) ? Math.round(distancia/100) : 1;
	var px = (Math.round(distancia / (tempo*5)>0)) ? Math.round(distancia / (tempo*5)) : 1;
	//alert("tempo = " + (tempo*50) + "\ndistância = " + distancia + "(" + destino + " - " + origem + ")\npixels = " + px);
	
	if (distancia >=1 && (documento - origem > janela))
	{
		window.setTimeout("fScroll(" + px + "," + destino + ")", (tempo * 50));
/*
		window.status = "origem = " + origem + "     |     documento = " + documento + "     |     window = " + janela + "     |     distancia = " + distancia + "     |     pixels = " + px;
	}
	else
	{
		window.status = "";
*/
	}
}

/*//////////////////////////////////////
//BANNERS
//////////////////////////////////////*/
/*//////////////////////////////////////
//ABAS
//////////////////////////////////////*/
function mostra(o, id, a, l)
{
	//o.blur();
	for(i=0; i<a.length; i++){
		//desliga abas
		document.getElementById("_" + a[i]).className='';
		//desliga box
		document.getElementById(a[i]).style.display = 'none';
	}
	//alert(a[id]);
	eval("_" + a[id] + ".className='ativa'");
	//o.className='ativa';
	document.getElementById(a[id]).style.display = 'block';

}
/*//////////////////////////////////////
//DDL
//////////////////////////////////////*/
function conecttDdl(id, json, style)
{
    this.p = 5; 
	this.json = json;
	this.aStyle = (style != undefined && style != "") ? style.split(";") : "";
	this.style = "";//style;
	this.id = id;
	this.init = init;
	this.render = render;
	this.showDdl = showDdl;
	this.hideDdl = hideDdl;
	//this.seleciona = seleciona;


	if(this.aStyle.length > 0)
	{
		for (s=0; s < this.aStyle.length -1; s++) 
		{
			this.style = this.style + this.aStyle[s] + " !important;"
		}
	}

	function init()
	{
		var evenodd;
		//var aStyle = (this.style != undefined) ? this.style.split(";") : "";
		
		document.write("<div class='conecttDdl' id='o" + this.id + "'>");
		if (this.json.itens.length > 1)
		{
			$height = "";//(this.json.itens.length>5) ? " style='height:100px !important; overflow-y:scroll;'" : "";
			
			document.write("<span><a class='ddl' href='javascript: " + this.id + ".showDdl(\"" + this.id + "\",\"" + this.json.itens.length +"\",\"" + this.json.itens[0].l +"\");'>clique para ver mais</a></span>");
			document.write("<span id='l_" + this.id + "' class='conecttDdlList' style='"+ ((this.style != "") ? this.style + ";" : "") + "'>");
			document.write("<ul>");
			
			for (var x = 0; x < this.json.itens.length; x++){
				evenodd = (x % 2 ==1) ? "even" : "odd";
				document.writeln("<li>");
				var li = this.json.itens[x].l.length > 0 ? "<a class='" + evenodd + "' href='" + this.json.itens[x].l +"'>" + this.json.itens[x].t + "</a>" : "<a class='" + evenodd + "' style='cursor: default;'>" + this.json.itens[x].t + "</a>"
				document.writeln(li);
				document.writeln("</li>");
			}
			
			document.write("</ul>");
			document.write("</span>");
		}
		else
		{
			document.write("<span><a class='lnk' href='javascript: " + this.id + ".showDdl(\"" + this.id + "\",\"" + this.json.itens.length +"\",\"" + this.json.itens[0].l +"\");'>clique para acessar</a></span>");
		}
		document.write("</div>");
		//document.write("<div class='clear' style='height: 10px; border: 1px solid red;'></div>");
	}
	
	function render()
	{
	}
	function showDdl(id, _length, _link)
	{
	
		if(_length > 1)
		{
			document.getElementById("l_" + id).style.display = "block";
			addEvent( document, 'mouseup', hideDdl, id);
		}
		else
		{
			window.location.href = _link;
		}
	}
	
	function hideDdl(evt)
	{
		var src = evt.target || evt.srcElement;
		var _hide = true;
		if (src.nodeType && src.nodeType != 1) src = src.parentNode;

		while (src)
		{
			var srcName = (src.nodeName||src.tagName||'').toLowerCase();
			//alert(srcName + " - " + src.id + " - " + _hide);
			if (src.id != null && src.id !="")
			{
				_hide = src.id.match(id) ? false: true;
			}
			else if((src.id=='l_' + id || src.id==id) && _hide != false)
			{
				_hide = true;
			}
			src = src.parentNode;
		}

		if (_hide == true)
		{
			var element;
			element = document.getElementById('l_' + id);
			element.style.display = 'none';
			removeEvent( document, 'mouseup', hideDdl);
		}
	}
	function addEvent( obj, type, fn ) 
	{
		if ( obj.attachEvent ) 
		{
			obj['e'+type+fn] = fn;
			obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
			obj.attachEvent( 'on'+type, obj[type+fn] );
		} 
		else
		{
			obj.addEventListener( type, fn, false );
		}
	}
	function removeEvent( obj, type, fn ) 
	{
		if ( obj.detachEvent ) 
		{
			obj.detachEvent( 'on'+type, obj[type+fn] );
			obj[type+fn] = null;
		} 
		else
		{
			obj.removeEventListener( type, fn, false );
		}
	} 
}

/*//////////////////////////////////////
//ACORDEON
//////////////////////////////////////*/

function conecttListInit($id){
	$d = document.getElementById($id);

	for (j = 0; j < $d.childNodes.length; j++){
		dd = $d.childNodes[j];
		if(dd.nodeType != 3 && dd.nodeName == "UL")
		{
			var node = dd.childNodes;
			
			for (i=0; i<dd.childNodes.length; i++)
			{
				if (dd.childNodes[i].nodeType != 3 && node[i].nodeName=="LI")
				{
					node[i].setAttribute("id", "l" + j + "_" +  i)
					
					//adiciona link
					if (node[i].firstChild.nodeType == 3) node[i].removeChild(node[i].firstChild)
					var oldel =  node[i].firstChild;
					var newel = document.createElement("a")
					newel.setAttribute("href", "javascript: void(conecttListToggle('l" + j + "_" +  i + "'))", 0)
					var newtext=document.createTextNode(oldel.innerHTML);
					newel.appendChild(newtext);
					
					var newh3 = document.createElement("h3")
						newh3.appendChild(newel);
					node[i].replaceChild(newh3, oldel)
					
					//desliga texto
					if (node[i].childNodes[1].nodeType == 3) node[i].removeChild(node[i].childNodes[1])
					node[i].childNodes[1].style.display = "none";
				}
			}
		}
	}
}
var $ol
function conecttListToggle($id){
	if ($ol == $id) {
		document.getElementById($ol).childNodes[1].style.display = "none";
		$ol = "";
	} else {
		//alert($ol)
		if ($ol != null && $ol != ""){
			document.getElementById($ol).childNodes[1].style.display = "none";
		}
		var node = document.getElementById($id)
		node.childNodes[1].style.display = "block";
		$ol = $id;
	}
}

/*
IFRAME
*/
function getDocHeight(doc) {
	var docHt = 0, sh, oh;
	if (doc.height) docHt = doc.height;
	else if (doc.body) {
		if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
		if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
		if (sh && oh) docHt = Math.max(sh, oh);
	}
	return docHt;
}

function setIframeHeight(iframeName) {
	var iframeWin = window.frames[iframeName];
	var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
	if ( iframeEl && iframeWin ) {
		iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
		var docHt = getDocHeight(iframeWin.document);
		// need to add to height to be sure it will all show
		if (docHt) iframeEl.style.height = docHt + 30 + "px";
	}
}
