function popup(imagem, caminho) {
	var img = caminho + "/" + imagem;
	
	if (imagem != "" && caminho != "") {
		win = window.open("estrutura/popup.php?img=" + img, null, "toolbar=0,status=0,directories=0,width=800,height=600");
	}
}

// Função para abrir página com Resultados da Enquete
function openResult() {
	var enquete = 0;
	var opcao = 0;

	enquete = document.forms[1].elements('enq_id').value;

	for (i=0; i < document.forms[1].rd_enquete.length; i++) {
		if ( document.forms[1].rd_enquete[i].checked ) {
			opcao = document.forms[1].rd_enquete[i].value;
		}
	}
	
	if (opcao ==  0) {
		alert('Por favor, selecione uma opção de resposta.')
		return false;
	} else {
		window.open('estrutura/resultEnquete.php?enquete='+enquete+'&opcao='+opcao, 'Resultado', 'toolbar=0,status=0,directories=0,scrollbars=1,width=500,height=300');
	}
}

// Função para abrir página que envia e-mail a ser registrado/removido
/*function sendEmail() {
	var email = '';
	var opcao = 0;

	email = document.forms[2].elements('txt_email').value;

	for (i=0; i < document.forms[2].rd_news.length; i++) {
		if ( document.forms[2].rd_news[i].checked ) {
			opcao = document.forms[2].rd_news[i].value;
		}
	}
	
	if (email ==  '') {
		alert('Por favor, digite o e-mail a ser registrado/removido.');
		document.forms[2].elements('txt_email').focus();
		return false;
	} else {
		window.open('estrutura/resultNews.php?email='+email+'&opcao='+opcao, 'Resultado', 'toolbar=0,status=0,directories=0,width=500,height=180');
	}
}
*/


function sendEmail() {
	var email = '';
	var opcao = 0;

	//email = document.forms[2].elements('txt_email').value;
	
	email = document.getElementById("txt_email").value;

	for (i=0; i < document.form3.rd_news.length; i++) {
		if ( document.form3.rd_news[i].checked ) {
			opcao = document.form3.rd_news[i].value;
		}
	}
	
	if (email ==  '') {
		alert('Por favor, digite o e-mail a ser registrado/removido.');
		document.form3.elements('txt_email').focus();
		return false;
	} else {
		window.open('estrutura/resultNews.php?email='+email+'&opcao='+opcao, 'Resultado', 'toolbar=0,status=0,directories=0,width=500,height=180');
	}
}

//Função para tratamento dos campos CPF/CNPJ da Área Privativa
function alterCpfCnpj(opcao) {
	//cpfcnpj = document.forms[4].elements('txt_cpfcnpj');
	//cpfcnpj.value = '';
	cpfcnpj = document.getElementById("txt_cpfcnpj");
	if (opcao == 1) {
		cpfcnpj.maxLength = 14;
		//document.getElementById('txt_cpfcnpj').setAttribute('onKeyDown', 'FormataCPF(cpfcnpj,event)');

		//cpfcnpj.onKeyDown = FormataCPF(cpfcnpj,event);
		//cpfcnpj.onKeyDown =MascaraCNPJ(cpfcnpj);
		//cpfcnpj.onkeydown = MascaraCampo(cpfcnpj,event,'###.###.###-##');
		//document.getElementById('txt_cpfcnpj').maxLength = 14;
		
		document.getElementById('txt_cpfcnpj').setAttribute('onKeyDown', 'mascara(this,\'00.000.000/0000-00\')');

		
	} else {
		cpfcnpj.maxLength = 18;
	//	cpfcnpj.onKeyDown = MascaraCampo(cpfcnpj,event,'##.###.###/####-##');
		//document.getElementById('txt_cpfcnpj').maxLength = 18;
	}
	cpfcnpj.focus();
}

function alteraMask(opcao){
	var cpf1= document.getElementById("cpf1");
	var cpf2= document.getElementById("cpf2");
	var txt = document.getElementById("txt_cpfcnpj");
	var txt2 = document.getElementById("txt_cpfcnpj2");

	if(opcao == 1){
		txt.value="";
		txt2.value="";
		cpf2.style.display="none";
		cpf1.style.display="block";
	}
	if(opcao == 2){
		txt.value="";
		txt2.value="";
		cpf1.style.display="none";
		cpf2.style.display="block";
	}
}

//Função para tratamento do campo No. de Registro da Área Privativa
function add01() {
	num = document.getElementById("txt_registro");
	if (num.value.length != 5) {
		alert('O Número de Registro deverá conter 5 dígitos.');
		num.value = '';
		num.focus();
		return false;
	} else {
		num.value = num.value.substring(0, 5) + "/01";
		//return true;
		window.open('http://201.33.18.86:8080/cms/em_construcao.html', 'janela1', 'location=yes');
	}
} 

function FormataCPF(Campo, teclapres){
	var tecla = teclapres.keyCode;
	
	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1;
	
	if (tecla != 9 && tecla != 8){
		if (tam > 3 && tam < 7)
			Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
		if (tam >= 7 && tam <10)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
		if (tam >= 10 && tam < 12)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
		}
}

// As três próximas funções são para Máscara de campos
function FormataCNPJ(Campo, teclapres){

   if(window.event){
    var tecla = teclapres.keyCode;
   }else  tecla = teclapres.which;

   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);
      }
}
function Ordem_(Campo,arrpos,teclapres_key,strtext){ 
    if (((arrpos == "/") || (arrpos == ".") || (arrpos == ",") || (arrpos == ":") || (arrpos == " ") || (arrpos == "-")) && !(teclapres_key == 8)){ 
        separador = arrpos 
        masktext = strtext + separador 
        Campo.value = masktext 
    } 
} 
function executa(Campo,strtext){ 
    event.returnValue = false 
    if (strtext != "") { 
        Campo.value = strtext 
    } 
} 
// Fim das funções para Máscara de campos


function abreMenu(obj) {
	var lis = obj.getElementsByTagName("div");
	var menu = document.getElementById("menu").getElementsByTagName("div");
	
	for(i=0; i<menu.length; i++){
		menu[i].style.display="none";
	}
	lis[0].style.display="block";
}

/*function abreMenu(obj) {
	var lis = obj.getElementsByTagName("div");
	var i = 0;
	if(lis[0].style.display=="block")lis[0].style.display="none";
	else lis[0].style.display="block";

}
*/

