//  Funções Macromedia
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

// ==========================================================================

// Funções para o menu

function escondeCombos(){
	for(x = 0; x < document.forms.length; x++){
		for(y = 0; y < document.forms[x].elements.length; y++){
			if(document.forms[x].elements(y).type=="select-one"){
				document.forms[x].elements(y).style.escondido = true;
				document.forms[x].elements(y).style.visibility = "hidden";
			}
		}
	}
}

function mostraCombos(){
	for(x = 0; x < document.forms.length; x++){
		for(y = 0; y < document.forms[x].elements.length; y++){
			if(document.forms[x].elements(y).style.escondido==true){
				document.forms[x].elements(y).style.escondido = false;
				document.forms[x].elements(y).style.visibility = "";
			}
		}
	}
}

function abremenu(){
	if(document.all||document.getElementById){
		adiv_menu = findObj("div_menu");
		adiv_menu.style.clip = "rect(0px 400px 510px 0px)";
	}
	if(document.all) escondeCombos();
}

function fechamenu(){
	if(document.all||document.getElementById){
		adiv_menu = findObj("div_menu");
		adiv_menu.style.clip = "rect(0px 180px 510px 0px)";
	}
	if(document.all) mostraCombos();
}

// ==========================================================================

// Funções do Site

function busca(oque){
	if(oque==""){ 
		switch(idioma){
			case "port" :
				alert("Por favor digite algo para poder buscar.");
				break;
			case "eng" :
				alert("Please type any word to search.");
				break;
			case "esp" :
				alert("Por favor digite alguna palabra para buscar.");
				break;
		}
		return;
	}
	else self.location = "http://www.duratex.com.br/" + idioma + "/" + site + "/home/busca.asp?busca=" + oque;
}

function balancos(empresa){
	window.open("http://www.mediagroup.com.br/BalInt/index.asp?empresa=" + empresa + "&idioma=" + idioma, "BalInt" + idioma, "width=" + (screen.availWidth-10) + ",height=" + (screen.availHeight-60) + ",top=0,left=0,resizable=yes,scrollbars=yes,status=yes");
}

function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  }
} 

addEvent(window, "load", function(){

  if(document.all){

	if(parseFloat(navigator.appVersion.split("MSIE")[1]) >= 5.5){
		flas = document.body.all.tags("OBJECT");
		for(x = 0; x < flas.length; x++) flas[x].setVariable("podefscommand", "sim");
	}

  }

  for(x = 0; x < document.forms.length; x++){
	  df = document.forms[x];
	  for(y = 0; y < df.length; y++){
		  fi = df[y];
		  if(fi.type=="text"||fi.type=="select-one"){
			  addEvent(eval("document.forms[" + x + "][" + y + "]"), "focus", new Function("document.forms[" + x + "][" + y + "].style.backgroundColor='#f2f6f8'"), false);
			  addEvent(eval("document.forms[" + x + "][" + y + "]"), "blur", new Function("document.forms[" + x + "][" + y + "].style.backgroundColor='#ffffff'"), false);
		  }
	  }
  }

}, false);

function webcast(tri, ano){
	janela("../../ri/apresentacao/webcast.asp?ano=" + ano + "&tri=" + tri, 790, 530);
}

function webcast2(pasta, titulo){
	janela("../../ri/apresentacao/webcast.asp?pasta=" + pasta + "&titulo=" + titulo, 790, 530);
}

function GraficosInterativos(){
	janela("../../ri/infoacion/graficos.asp", 545, 450);
}

// ==========================================================================

// Funções Combo Flash

var combo = false;

function combo_abre(qual){
	if(combo!=false&&document.all) combo_fecha(combo);
	combo = qual;
	if(document.all) document.all["flash_" + qual].style.height = 102;
	else document.embeds["flash_" + qual].height = 102;
}

function combo_fecha(qual){
	if(qual!=false){
		if(document.all){
			document.all["flash_" + qual].style.height = 20;
			document.all["flash_" + qual].setVariable("_root.executa_funcao", "combo_fecha");
		}
		else document.embeds["flash_" + qual].height = 20;
		combo = false;
	}
}

// ==========================================================================

// Outras Funções

function MostraApaga(objeto, display){
	document.getElementById(objeto).style.display = display;
}

function EstadoDisplay(objeto){
	return document.getElementById(objeto).style.display;
}

function imprimir(){
	window.print();
}

function topo(){
	window.scrollTo(0,0);
}

function janela(url, W, H){
	try {
		L = ((screen.availWidth - W) / 2);
		T = ((screen.availHeight - H) / 2);
		if(screen.availHeight <= 600){
			L = 0;
			T = 0;
		}
		jan = window.open(url, "", "width=" + W + ",height=" + H + ",left=" + L + ",top=" + T);
		jan.focus();
	}
	catch(e){
		alert(idioma=="eng"? "Please disable your anti-popup to see this website." : "Por favor desabilite seu anti-popup para visualizar este website.");
	}
}

function AbilitaCampos(){
	AC_args = AbilitaCampos.arguments;
	for(AC_x = 2; AC_x < AC_args.length; AC_x++){
		AC_campo = eval("document." + (AC_args[0].name||AC_args[0]) + "." + AC_args[AC_x]);
		if(AC_campo.type!="select-one"&&!isNaN(AC_campo.length)){
			for(AC_y = 0; AC_y < AC_campo.length; AC_y++) AC_campo[AC_y].disabled = !AC_args[1];
		}
		else eval("document." + (AC_args[0].name||AC_args[0]) + "." + AC_args[AC_x] + ".disabled = " + !AC_args[1]);
	}
}

function ValorRadio(radio){
	tempValorRadio = false;
	for(VR_x = 0; VR_x < radio.length; VR_x++){
		if(radio[VR_x].checked){ tempValorRadio = radio[VR_x].value; break; }
	}
	return tempValorRadio;
}

function checarTodos(checkbox, checkboxes){
	for(ct_x = 0; ct_x < checkboxes.length; ct_x++){
		checkboxes[ct_x].checked = checkbox.checked;
	}
}

function validaData(dia, mes, ano){
	if(parseInt(mes, 10)==2&&parseInt(dia, 10)==29) return (parseInt(ano, 10) % 4)? 0 : 1;
	else return (/^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/.test(dia + "/" + mes + "/" + ano));
}

function validaEmail(email){
	return (/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(email));
}

function validaNum(numero, quantidade){
	return (/^\d+$/.test(numero)&&numero.length==quantidade);
}

function trim(oque) {
	
	while(oque.substring(0,1) == ' ') oque = oque.substring(1, oque.length);
	
	while(oque.substring(oque.length-1, oque.length) == ' ') oque = oque.substring(0, oque.length-1);
	
	return oque;
}

function InnerText(tag){
	tempInnerText = "";
	nodeList = tag.childNodes;
	count = nodeList.length;
	for(var IT_x=0; IT_x < count; IT_x++){
		if(typeof(nodeList[IT_x].tagName)!="undefined") tempInnerText += nodeList[IT_x].innerHTML + " ";
	}
	return tempInnerText;
 }


function MaxLength(campo, limite){
	txt = campo.value;
	if(txt.length > limite){
		campo.value = txt.substring(0,limite-1);
		alert("O número máximo de caracteres para este campo é " + limite + ".");
	}
}

function AdicionaOption(AO_combo, AO_valor, AO_texto, AO_seleciona){
	AO_jatem = false;
	for(AO_x = 0; AO_x < AO_combo.length; AO_x++){
		if(AO_combo.options[AO_x].value.toString()==AO_valor.toString()){
			AO_jatem = true;
			break;
		}
	}
	if(!AO_jatem) AO_combo.options[AO_combo.options.length] = new Option(AO_texto, AO_valor);
	if(AO_seleciona) AO_combo.value = AO_valor;
}

function soNumeros() {

	if(document.all) tecla = event.keyCode;
	else if(document.layers) tecla = event.which;

	if(tecla == 8 || tecla == 9 || tecla == 46 || (tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105)){
		return true;
	}
	else return false;

}
function validaCPF(pcpf){

 if (pcpf.length != 11) {sim=false}
 else {sim=true}

  if (sim)
  {
  for (i=0;((i<=(pcpf.length-1))&& sim); i++)
  {
   val = pcpf.charAt(i)
   if((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4")&&(val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {sim=false}
   }

   if (sim)
  {
    soma = 0
    for (i=0;i<=8;i++)
    {
     val = eval(pcpf.charAt(i))
     soma = soma + (val*(i+1))
    }

    resto = soma % 11
    if (resto>9) dig = resto - 10;
    else  dig = resto;
    if (dig != eval(pcpf.charAt(9))) { sim=false }
   else
    {

     soma = 0
    for (i=0;i<=7;i++)
     {
     val = eval(pcpf.charAt(i+1))
      soma = soma + (val*(i+1))
    }

     soma = soma + (dig * 9)
    resto = soma % 11
     if (resto>9) dig = resto -10
     else  dig = resto
   if (dig != eval(pcpf.charAt(10))) { sim = false }
    else sim = true
   }
   }
  }

  if(sim){
	  if(pcpf=="11111111111"||pcpf=="22222222222"||pcpf=="33333333333"||pcpf=="44444444444"||pcpf=="55555555555"||pcpf=="66666666666"||pcpf=="77777777777"||pcpf=="88888888888"||pcpf=="99999999999"||pcpf=="00000000000") sim=false;
	  else sim=true;
  }
  
  if(sim) return true;
  else return false;

}

function rao2006() {
	var w = 997;
	var h = 619;
	var scr = "no";
	
	
	if(screen.width == 800 || screen.height == 600) {
		w = 770;
		h = 450;
		var scr = "yes";
	}
	
	
	leftPos = 0;
	topPos = 0;
		if (screen) {
		leftPos =(window.screen.width/2) - (w/2);
		toptPos =(window.screen.height/2) - (h/2);
		}
		janela=window.open('../../../RAO/2006/'+idioma+'/pop_duratex.html','janela','width=997, height=619, left='+leftPos+', top='+toptPos+', scrollbars='+scr+', resize=no, toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=yes,');
}
		
		
		
function flash(movie, swfid, flashvars, width, height, retorna)
{	
	strSWF= '<object id="' + swfid + '" name="' + swfid + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
			'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" '+
			'width="' + width + '" height="' + height + '">'+
			'<param name="movie" value="' + movie + '">'+
			'<param name="quality" value="high">'+
			'<param name="menu" value="false">'+
			'<param name="salign" value="LT">'+
			'<param name="wmode" value="transparent">'+
			'<param name="FlashVars" value="' + flashvars + '">'+
			'<embed name="' + swfid + '" src="' + movie + '" width="' + width + '" height="' + height + '" flashvars="' + flashvars + '" '+
			'menu="false" salign="LT" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>'+
			'</object>';
	if(!retorna) this.document.write(strSWF);
	else return(strSWF);
}

