// Funcoes para mostrar ou ocultar objetos
function mostraObjeto(objeto) {
	elemento = 'document.getElementById(\'' + objeto + '\')';
	eval(elemento).style.display = 'inline';
}

function escondeObjeto(objeto) {
	elemento = 'document.getElementById(\'' + objeto + '\')';
	eval(elemento).style.display = 'none';
}

// Funcoes para mostrar ou ocultar objetos
function mostra(objeto) {
	if(document.all) { // IE4+
		elemento = 'document.all[\'' + objeto + '\']';
	} else { // NS6+
		elemento = 'document.getElementById(\'' + objeto + '\')';
	}
	if(elemento) eval(elemento).style.display = 'inline';
}

function esconde(objeto) {
	if(document.all) { // IE4+
		elemento = 'document.all[\'' + objeto + '\']';
	} else { // NS6+
		elemento = 'document.getElementById(\'' + objeto + '\')';
	}
	if(elemento) eval(elemento).style.display = 'none';
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	  window.open(theURL,winName,features);
	}

function mostraEsconde(objeto,escondeBusca) {
	if(document.all) { // IE4+
		elemento = 'document.all[\'' + objeto + '\']';
	} else { // NS6+
		elemento = 'document.getElementById(\'' + objeto + '\')';
	}
	if (eval(elemento).style.display == 'block') {
		if(escondeBusca){
			document.getElementById('catBusca').style.display = 'inline';
		}
		eval(elemento).style.display = 'none';
	} else {
		if(escondeBusca){
			document.getElementById('catBusca').style.display = 'none';
		}
		eval(elemento).style.display = 'block';
	}
}

function playFlash1() {
	var IE = navigator.appName.indexOf("Microsoft") != -1;
        var filmeplay = IE ? window.mainMovie1 : window.document.mainMovie1;
        filmeplay.Play()
};

function playFlash2() {
	var IE = navigator.appName.indexOf("Microsoft") != -1;
        var filmeplay = IE ? window.mainMovie2 : window.document.mainMovie2;
        filmeplay.Play()
};

function playFlash3() {
	var IE = navigator.appName.indexOf("Microsoft") != -1;
        var filmeplay = IE ? window.mainMovie3 : window.document.mainMovie3;
        filmeplay.Play()
};

function mascaraCPF (Campo, teclapres) {
	var tecla = teclapres.keyCode;
	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("-", "");
	vr = vr.replace("-", "");
	vr = vr.replace("-", "");
	vr = vr.replace("-", "");
	vr = vr.replace("-", "");
	tam = vr.length + 1;
	if (tecla != 9 && tecla != 8) {
		if(tam > 3 && tam < 5){
			Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
		}
		if(tam > 6 && tam < 8){
			Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, 3) + '.' + vr.substr(6, tam);
		}
		if(tam > 9 && tam < 11){
			Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, 3) + '.' + vr.substr(6, 3) + '-' + vr.substr(9, 11);
		}	
	}
}

// Funcao que altera o valor caso de erro
function marcaErro(campo) {

	// Configura qual o campo que falhou
	var campoNovo = 'document.form1.' + campo;

	// Coloca a borda de erro
	eval(campoNovo).focus();
	eval(campoNovo).style.border = '2px solid #ad2018';
}


// Funcao que altera o valor caso de erro
function desmarcaCampo(campo,cor) {

	// Campo a ser modificado
	var campoNovo = 'document.form1.' + campo;

	// Remove borda de erro
	eval(campoNovo).style.border = '1px solid '+cor;
}

// Funcao que remove o conteudo de uma tag
function alteraConteudo(objeto, conteudo) {
	if(document.all) { // IE4+
		elemento = 'document.all[\'' + objeto + '\']';
	} else { // NS6+
		elemento = 'document.getElementById(\'' + objeto + '\')';
	}
	if(elemento) eval(elemento).innerHTML = conteudo;
}

function limparFormato(num){
	var sVal='';
	var nVal = num.length;
	var sChar='';
	for(i=0;i<nVal;i++){
		sChar = num.charAt(i);
		nChar = sChar.charCodeAt(0);
		if ((nChar >=48) && (nChar <=57)) {sVal += num.charAt(i);}
	}
	return sVal;
}

function centavos(quantidade){
	var centavos = '';
	quantidade = parseInt(quantidade);
	var quantidade = new String(quantidade);
	if (quantidade.length == 0) {return '00';}
	if (quantidade.length == 1) {return '0' + quantidade;}
	if (quantidade.length == 2) {return quantidade;}
	centavos =  quantidade.substring(quantidade.length -2,quantidade.length);
	return centavos;
}

function reais(quantidade){
	quantidade = parseInt(quantidade);
	var quantidade = new String(quantidade);
	if (quantidade.length < 3) {return 0;}
	quantidade = quantidade.substring(0,quantidade.length -2);
	for (var i=0; i<Math.floor((quantidade.length-(1+i))/3); i++){
		quantidade = quantidade.substring(0,quantidade.length-(4*i+3)) + '.' + quantidade.substring(quantidade.length-(4*i+3));
	}
	return quantidade;
}

function moeda(num){
	var sVal='';
	var minus='';
	var Decimal='';
	Decimal = ',';
	if (num.lastIndexOf("-") == 0) {minus='-';}
	if (num.lastIndexOf(Decimal) < 0) {num = num + '00';}
	num = limparFormato(num);
	sVal = minus + reais(num) + ',' + centavos(num); 
	return sVal;
}

function atualizaValores(qtde, diaria, destino){
	var elemento = 'document.getElementById(\'' + destino + '\')';
	var totalDiaria = eval(qtde * diaria);

	totalDiaria = Math.round(totalDiaria, 2).toString();
	totalDiaria = totalDiaria.replace(".",",");

	if(elemento) eval(elemento).innerHTML = 'R$ ' + moeda(totalDiaria);
}

function video(arquivo) {
	window.open('video.cfm?arquivo='+arquivo,'Janela','width=480,height=360,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=0,resizable=0');
};

//popup
function popUp(url,nome,caracteristicas) { 
  window.open(url,nome,caracteristicas);
}

//AJAX
function ajax (url, sincrono, retorno)
{
 retorno = false;
 assincrono = (sincrono == true)? false : true;
 
 var xmlhttp = false;
 
 if (window.XMLHttpRequest)
 {
  xmlhttp = new XMLHttpRequest();
 }
 else
 {
  if (window.ActiveXObject)
  {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
 
 if (xmlhttp)
 {  
  xmlhttp.open('GET', url, assincrono);
 
  xmlhttp.send(null);
 
  if(assincrono)
  {
   xmlhttp.onreadystatechange=function()
   {
    if (xmlhttp.readyState==4)
    {
     if (retorno == true)
      retorno = xmlhttp.responseText;
     else
      eval(xmlhttp.responseText);
    }
   }
  }
  else
  {
   if (retorno == true)
    retorno = xmlhttp.responseText;
   else
    eval(xmlhttp.responseText);
  }
 }
 
 if(retorno)
  return retorno;
 else
  return false;
}

function trocarFoto(caminho) {
	document.getElementById('fotoAmpliada').src = caminho;
}


// Funcao para colocar a "/" automaticamente na data
function formataData(campo, teclapres) {
	var tecla = teclapres.keyCode;
	var vr = new String(campo.value);
	var tam = "";
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	tam = vr.length + 1;
	
	if (tecla != 9 && tecla != 8) 
 		{
		if (tam > 2 && tam < 5)
			campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);
		if (tam >= 5 && tam <=10)
			campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(4,4);
		
		}
}



function FormataCNPJ(Campo, teclapres){
	var tecla = teclapres.keyCode;
	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1 ;

	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 6)
			Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
		if (tam >= 6 && tam < 9)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
		if (tam >= 9 && tam < 13)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
		if (tam >= 13 && tam < 15)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
		}
}	
