var appVer = navigator.appVersion.toLowerCase();
var iePos  = appVer.indexOf('msie');
var ieVer = 0;
var podefscommand = false;
var iebug = false;
var isiPad = navigator.userAgent.match(/iPad/i) != null;

if (iePos !=-1) {
	ieVer = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
	if(ieVer < 7) iebug = true;
	if(ieVer > 5.5) podefscommand = true;
}


var tags = { "select":iebug, "applet":true };
var apagou = [];


/*///////////////////////   ABRE FECHA MENU   /////////////////////*/

var tempo;

if(site=="admin")
{
	addEvent(window, "load", function()
	{
		tempo = setTimeout(fechamenu, 100);
		
	}, false);
}


function abremenu(){
	try 
	{	
		if(tempo) clearTimeout(tempo);
		
		document.getElementById("div_menu").style.clip = "rect(0 510px 600px 0)";
		document.getElementById("div_menu").style.zindex = 1000;
		document.getElementById("noticias").style.zindex = 999;
	}
	catch(e){}
}

function fechamenu(){
	tempo = setTimeout(fechamenuAgora, 100);
}

function fechamenuAgora(){
	try 
	{
		document.getElementById("div_menu").style.clip = "rect(0 220px " + (home? 330 : 600) + "px 0)";
		document.getElementById("div_menu").style.zindex = 2;
		document.getElementById("noticias").style.zindex = 3;
	}
	catch(e){}
}




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()
{
	try
	{
		if(($('#meio_conteudo').height() + 190) < altura_menu)
		{
			$('#meio_conteudo').css("height", (altura_menu - 190) + "px");
		}	
	}
	catch(e){}
	
}, false);

function validateEmail(elementValue)
{
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
   return emailPattern.test(elementValue); 
}
 
function form(campo){
	if(window.navigator.appName.toLowerCase().indexOf("microsoft") > -1){
		return document.formulario.item(campo);
	}
	else {
		return document.formulario[campo];
	}
}

function soNumeros(obj) {

	tecla = event.keyCode;
	
	if(tecla == 8 || tecla == 9 || tecla == 46 || (tecla >= 37 && tecla <= 40) || (tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105)){
		return true;
	}
	else return false;

}

function abrir(url){
	window.open(url, "_blank");
}

function janela(url, w, h){
	try {
		jan = open(url, "", "width=" + w + ",height=" + h + ",left=" + ((screen.availWidth-w)/2) + ",top=" + ((screen.availHeight-h)/2));
		jan.focus();
	}
	catch(e){
		alert(idioma=="port"? "Por favor desabilite seu anti-popup." : "Please disable your anti-popup.");
	}
}

function janelaScroll(url, w, h){
	try {
		jan = open(url, "", "scrollbars=yes,width=" + w + ",height=" + h + ",left=" + ((screen.availWidth-w)/2) + ",top=" + ((screen.availHeight-h)/2));
		jan.focus();
	}
	catch(e){
		alert(idioma=="port"? "Por favor desabilite seu anti-popup." : "Please disable your anti-popup.");
	}
}

function webcast(tri, ano){
	janela("../infofinan/webcast.asp?tri=" + tri + "&ano=" + ano, 790, 540);
}

function balancos(){
	window.open("http://www.mediagroup.com.br/BalInt/index.asp?empresa=Indusval&tabela=1&idioma=" + (idioma=="esp"? "port" : idioma), "BalInt" + idioma, 
				"width=" + (screen.availWidth-10) + ",height=" + (screen.availHeight-60) + ",top=0,left=0,resizable=yes,scrollbars=yes,status=yes");
}

function shadowbox(titulo, url, w, h){

	Shadowbox.init({ overlayOpacity: 0.8, overlayColor: '#cccccc', skipSetup: true, modal: false });

	Shadowbox.open({
		player:     'iframe',
		title:      titulo,
		content:    url,
		height:     h,
		width:      w
	});
}

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 valida_cpf_cnpj(cpf_cnpj)
{
	if(valida_cpf(cpf_cnpj))
	{
		return true;
	}
	else
	{
		return valida_cnpj(cpf_cnpj);
	}
}

function valida_cpf(cpf)
{
  var numeros, digitos, soma, i, resultado, digitos_iguais;
  digitos_iguais = 1;
  if (cpf.length < 11)
		return false;
  for (i = 0; i < cpf.length - 1; i++)
		if (cpf.charAt(i) != cpf.charAt(i + 1))
			  {
			  digitos_iguais = 0;
			  break;
			  }
  if (!digitos_iguais)
		{
		numeros = cpf.substring(0,9);
		digitos = cpf.substring(9);
		soma = 0;
		for (i = 10; i > 1; i--)
			  soma += numeros.charAt(10 - i) * i;
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(0))
			  return false;
		numeros = cpf.substring(0,10);
		soma = 0;
		for (i = 11; i > 1; i--)
			  soma += numeros.charAt(11 - i) * i;
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(1))
			  return false;
		return true;
		}
  else
		return false;
}

function valida_cnpj(cnpj)
{
  var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
  digitos_iguais = 1;
  if (cnpj.length < 14 && cnpj.length < 15)
		return false;
  for (i = 0; i < cnpj.length - 1; i++)
		if (cnpj.charAt(i) != cnpj.charAt(i + 1))
			  {
			  digitos_iguais = 0;
			  break;
			  }
  if (!digitos_iguais)
		{
		tamanho = cnpj.length - 2
		numeros = cnpj.substring(0,tamanho);
		digitos = cnpj.substring(tamanho);
		soma = 0;
		pos = tamanho - 7;
		for (i = tamanho; i >= 1; i--)
			  {
			  soma += numeros.charAt(tamanho - i) * pos--;
			  if (pos < 2)
					pos = 9;
			  }
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(0))
			  return false;
		tamanho = tamanho + 1;
		numeros = cnpj.substring(0,tamanho);
		soma = 0;
		pos = tamanho - 7;
		for (i = tamanho; i >= 1; i--)
			  {
			  soma += numeros.charAt(tamanho - i) * pos--;
			  if (pos < 2)
					pos = 9;
			  }
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(1))
			  return false;
		return true;
		}
  else
		return false;
}


function pula(atual, proximo){
	if(atual.value.length==atual.maxLength) $(proximo).focus();
}

function validaNum(numero, quantidade){
	return (/^\d+$/.test(numero)&&numero.length>=quantidade);
}

// ==========================================================================

// 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 = 202;
	else document.embeds["flash_" + qual].height = 202;
}

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;
	}
}

// ==========================================================================

function TrocaIdioma(novoidioma){

local = Mid(location.href,43,12);
if (local != "fornecedores")
{
		location = location.href.replace("/" + idioma + "/", "/" + novoidioma + "/");
}
else
{
	if (novoidioma == "eng"){location = '../../../eng/institucional/home/';}
	if (novoidioma == "esp"){location = '../../../esp/institucional/home/';}
}
	
	

}

function ingles()
{
	location = "../../../eng"; 
}

function espanhol()
{
	location = "../../../esp";
}

function Mid(str, start, len)
{
    if (start < 0 || len < 0) return "";
    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
          iEnd = iLen;
    else
          iEnd = start + len;
    return String(str).substring(start,iEnd);
}

// ===========================================================================


function flash(movie, flashvars, width, height, retorna, swfid){
	if(!swfid)
	{
		swfid = movie.split("/");
		swfid = swfid[swfid.length-1].replace(".swf", "");
	}
	if(podefscommand)
	{ 
		flashvars += "&podefscommand=sim";
		document.write('<scr' + 'ipt for="' + swfid + '" event="FSCommand(funcao)">eval(funcao);</sc' + 'ript>');
	}
	strSWF= '<object id="' + swfid + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '">'+
			'<param name="movie" value="' + movie + '">'+
			'<param name="quality" value="high">'+
			'<param name="menu" value="false">'+
			'<param name="wmode" value="transparent">'+
			'<param name="salign" value="LT">'+
			'<param name="FlashVars" value="' + flashvars + '">'+
			'<embed name="' + swfid + '" src="' + movie + '" width="' + width + '" height="' + height + '" salign="LT" flashvars="' + flashvars + '" 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);
}



function chIEPNGfix()
{
	img = document.getElementsByTagName("img");
	
	for(x = 0; x < img.length; x++)
	{
			
		if(img[x].src.indexOf(".png") > 0)
		{
			img[x].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img[x].src + "',sizingMethod='scale')";
			img[x].src = "../../../imagens/px.gif";
		}
	}
}

if(iebug) addEvent(window, "load", chIEPNGfix, false);



function slideDown(div){

	if($("#" + div).css("display")=="none") 
	{
		$("#" + div).slideDown("normal");
	} 
	else 
	{
		$("#" + div).slideUp("normal");
	}

}




/////////////   MENU ///////////////

var tempoMenu;
var yMenu = 0; 
var h = 0;
var limiteYtop = 85; // limite superior

function moveMenu(){
	tempoMenu = setInterval("posicionaMenu()", 10);
}

function paraMenu(){
	if(tempoMenu) clearInterval(tempoMenu);
}

var doc = document.documentElement;
var body = document.body;

function posicionaMenu(){
	try {
		t = (window.pageYOffset? window.pageYOffset : ((doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientTop || 0)));
		pgh = ((doc && doc.scrollHeight || body && body.scrollHeight || 0) - (doc.clientHeight || 0));
		h = Math.ceil(yMenu + ((t - yMenu + 10) / 8));
		h = h<limiteYtop? limiteYtop: h;
		yMenu = h;
		$("#div_menu").css("top", yMenu + "px");
	}
	catch(e){  }		
}

if(home==false)
{	
	addEvent(window, "load", function(){
	
		try {
			moveMenu();
		}
		catch(e){}
		
	}, false);
}




function abrir(url){
	window.open(url, "_blank");
}

function janela(url, w, h){
	try {
		jan = open(url, "", "width=" + w + ",height=" + h + ",left=" + ((screen.availWidth-w)/2) + ",top=" + ((screen.availHeight-h)/2));
		jan.focus();
	}
	catch(e){
		alert(idioma=="port"? "Por favor desabilite seu anti-popup." : "Please disable your anti-popup.");
	}
}

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;
}

otitulo = document.title;


function flash_topo(_titulo)
{
	$(document).ready(function()
	{		
		if($.flash.hasVersion(8))
		{
			$('#titulo').flash(
				{
					swf: '../../../imagens/titulo_pg' + (site=='ri'? '_ri' : '') + '.swf',
					flashvars: { titulo: _titulo.replace(/\&/g, "%26") },
					width: 720,
					height: 75,
					hasVersion: 8,
					hasVersionFail: function (options) 
					{
						imagem_topo(_titulo);
						
						return false; 
					}
				}
			);
		}
		else 
		{
			imagem_topo(_titulo);	
		}
	});	
}

function imagem_topo(_titulo)
{
	img = Math.ceil(Math.random() * 5);
	$('#fotos').css("background-image", "url('../../../imagens/fotos/" + img + ".jpg')").css('border-radius', '10px').html('<div style="background-color:#aabbc2;float:left;color:#fff;padding:15px;font-size:20px;font-weight:bold;font-family:\'Trebuchet MS\', Arial, Helvetica, sans-serif;margin:102px 0 0 30px;border-radius:5px;">' + _titulo + '</div>');
}
