/* Validação de formulários ~~ :) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

	function validaFrm(frm){
  
	  var d 	   = eval('document.'+ frm);
	  var numCampo = d.elements.length;
	  var erro     = "";
	  
	  //* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	  
	  for(i = 0; i < numCampo; i++){
	  
		  var cmp       = d.elements[i].title; // title - exibe o erro
		  var aCampo    = d.elements[i].alt;   // alt   - direfencia o tipo do campo
		  var nomeCampo = d.elements[i].name;  // name  - faz os testes
		  var maxL		= d.elements[i].size;  // tamanho - para mudar o focus pro proximo campo
		  
		  
		if(cmp != ""){ //se houver title, valida o campo
		  
			  var campo = eval('document.' + frm + '.' + nomeCampo);
			  var valor = campo.value;

			 switch(aCampo){
			  
				  //~~~~~~~~~~~~ Campo de Texto Simples
				  
				  case "": 
				  
					if(valor == ""){
					
					erro += "- O campo <strong>" + cmp + "</strong> est&aacute; vazio.<br/>";
					
					}
				  
				  break;
				  
				  
				  //~~~~~~~~~~~~ Campo de email
			  
				  case "email": 
				  
					if(valor != ""){
					
						var arroba = valor.indexOf("@");
						var ponto  = valor.indexOf(".");
						
						if( (arroba == -1) || (ponto == -1) ){
						erro += "- O campo <strong>" + cmp + "</strong> possui um e-mail inv&aacute;lido.<br/>";
						}
					
					}
					
					else{
					erro += "- O campo <strong>" + cmp + "</strong> est&aacute; vazio.<br/>";
					}
				  
				  break;
					
				  case "select": 
				  
					if(valor == "0"){
					
						erro += "- O campo <strong>" + cmp + "</strong> precisa ser selecionado.<br/>";
					}
					
				  break;
				  
			  
				  
				  //~~~~~~~~~~~~ Campo de telefone
			  
				  case "fone": 
				  
					if(valor != ""){
					
						checkKeycode();			
						if( (arroba == -1) || (ponto == -1) ){
						erro += "- O campo <strong>" + cmp + "</strong> possui um e-mail inv&aacute;lido.<br/>";
						}
					
					}
					
					else{
					erro += "- O campo <strong>" + cmp + "</strong> est&aacute; vazio.<br/>";
					}
				  
				  break;
				  
				  
			  } //switch
		  
		  }	//if	
					  
	  } //for
	  
	  //* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	  
	  if(erro != "") { //exibe erro
	  
	  var divErr = document.getElementById('erros');
	  
	  var msgErro = "\
	  <div style='padding:10px; border: solid 1px #ccc; background: #fafafa;'><strong>Erros encontrados:</strong><br/><br/>" + erro + "</div><br clear='left'/>";
	  
	  divErr.innerHTML = msgErro;
	  
	  alert ("Ocorreu algum erro ao tentar enviar o formulario.\nPor favor, verifique os campos e tente novamente.");
	  }
	  
	  else { //envia formulário
	  
		  if(frm.indexOf('Editor') != -1)
		  rtoStore();
	  
	  eval("document." + frm).submit();
	  }
  
	} // function



	function FONE(value, cmp, frm){
		
		if( (value.length == 2) || (value.length == 7) ){
			
			eval('document.'+ frm + '.' + cmp).value = value + ' ';
		
		}
	
	}


	function DATA(value, cmp, frm){
		
		if( (value.length == 2) || (value.length == 5) ){
			
			eval('document.'+ frm + '.' + cmp).value = value + '/';
		
		}
	
	}


	function HORA(value, cmp, frm){
		
		if(value.length == 2){
			
			eval('document.'+ frm + '.' + cmp).value = value + ':';
		
		}
	
	}


	function CEP(value, cmp, frm){
		
		if(value.length == 5){
			
			eval('document.'+ frm + '.' + cmp).value = value + '-';
		
		}
	
	}


	function MESANO(value, cmp, frm){
		
		if(value.length == 2){
			
			eval('document.'+ frm + '.' + cmp).value = value + '/';
		
		}
	
	}


	function CPF(value, cmp, frm){
		
		if( (value.length == 3) || (value.length == 7) ){
			
			eval('document.'+ frm + '.' + cmp).value = value + '.';
		
		}
		
		else if(value.length == 11){
			
			eval('document.'+ frm + '.' + cmp).value = value + '-';
		
		}
		
	}


	function CNPJ(value, cmp, frm){
		
		if( (value.length == 3) || (value.length == 7) ){
			
			eval('document.'+ frm + '.' + cmp).value = value + '.';
		
		}
		
		else if(value.length == 11){
			
			eval('document.'+ frm + '.' + cmp).value = value + '/';
		
		}
		
		else if(value.length == 16){
			
			eval('document.'+ frm + '.' + cmp).value = value + '-';
		
		}
		
	}
	

/* Abre popup ~~ :) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

	function popup(pag,w,h,barra){
	
	
		wi = screen.width/2  - (w/2);
		he = screen.height/2 - (h/2);
		
			var win = window.open(pag, "Pop",
			"toolbar=no,location=no,directories=no,scrollbars="+barra+",resizable=no,width="+w+",height=" + h + ",status=no,top=" + he + ",left=" + wi );
			win.focus();
	
	} // function
	
	
/* Altera tamanho do popup ~~ :) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

	function popImg(){
	
		var wImg = document.images[0].width;
		var hImg = document.images[0].height;
		
		resizeTo(wImg+12,hImg+32);

} // function
 	function exlcluir(cad){
 		document.frmContato.action="egresso/excluir.php?cad="+cad;
 		document.frmContato.submit();

		
		}
		
function valida(){
cont=0;
  if (document.cadastro.email.value == ""){
     alert("O campo Email deve ser preenchido!");
     document.cadastro.email.focus();
	 cont++;
   }
 if (document.cadastro.senha.value == ""){
     alert("O campo Senha deve ser preenchido!");
     document.cadastro.senha.focus();
	 cont++;
   }
  if (document.cadastro.email.value != ""){
	parte1 = document.cadastro.email.value.indexOf("@");
	parte2 = document.cadastro.email.value.indexOf(".");
	parte3 = document.cadastro.email.value.length;
		if (!(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) {
			alert ("Email Errado");
			document.cadastro.email.focus();
			cont++;
		}
   }
   
  if(cont==0){
	document.cadastro.submit();
   }


}

