function abre_popup(url,h,w){
//abre_popup('incluir_grupo_usuario.asp',300,400)
var settings = 'height='+ h +',width='+ w +',top='+ ((screen.Height - h )/2) +',left='+ ((screen.Width - w )/2)
var popup = window.open(url,'win_popup',settings)
popup.focus()
}

//////////////////////////////////////////////////////////////////////
function valida_vazio(campo){
	valida_trim(campo);
	if (campo.value == "")
		{
        campo.focus();
		campo.style.border = " 2px red solid " 
		return true;
		}
	else {
	campo.style.border = ""
	  }
}//end fuction
//////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////
/*
tipos de funções encontradas aqui:

valida_vazio(campo)
valida_cnpj(campo)
valida_cpf(campo)
valida_email(campo)
valida_cep(campo)
valida_telefone(campo)
valida_ddd(campo)
valida_numerico(campo)
valida_trim(campo)
*/
//////////////////////////////////////////////////////////////////////
function valida_cpf(campo){
	valida_trim(campo);

	if ((campo.value == "")  || (isNaN(campo.value)))
		{
		campo.focus();
		//campo.style.background= cor_fundo;
		campo.style.border = " 2px red solid " 
		return true;
		}
}//end fuction
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
function valida_cnpf(campo){
	valida_trim(campo);
	if (campo.value == "")
		{
		campo.focus();
		//campo.style.background= cor_fundo;
		campo.style.border = " 2px red solid " 
		return true;
		}
	if (campo.value == "") {
		campo.focus();
		return true;
	}
	if (campo.value.length < 14 || campo.value.length > 18) {
		campo.focus();
		//campo.style.background= cor_fundo;
		campo.style.border = " 2px red solid " 
		return true;
		}
        {

var numeros = "1234567890";     
s = "";

for (x = 0 ; x < campo.value.length ; x++) 
    {
	var ch = campo.value.charAt(x);
	if ( numeros.indexOf(ch) != -1 ) {
	     s = (s + ch);	
	   }
	}
valor = s; 		
if ( (s.length != 14) ) { 
		campo.focus();
		//campo.style.background= cor_fundo;
		campo.style.border = " 2px red solid " 
		return true;
}
	
    if ( ! valida_cgc(s,valor) ){ 
		campo.focus();
		//campo.style.background= cor_fundo;
		campo.style.border = " 2px red solid " 
		return true;
	} 

		} 
	
		
		
		
		
		
		
}//end fuction
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
function valida_telefone(campo){
		valida_trim(campo);
		if (campo.value == "")
		{
		campo.focus();
		//campo.style.background= cor_fundo;
		campo.style.border = " 2px red solid " 
		return true;
		}
		
	var aux_campo;
	if ( isNaN(campo) ) {
		if ( campo.value.indexOf("-") == -1 ) {
		campo.focus();
		//campo.style.background= cor_fundo;
		campo.style.border = " 2px red solid " 
		return true;
		}	
		else {
			aux_campo = campo.value.split("-");
			if (aux_campo.length != 2) {
		campo.focus();
		//campo.style.background= cor_fundo;
		campo.style.border = " 2px red solid " 
		return true;
			}
			if (aux_campo[0].value.length < 3 || aux_campo[0].value.length > 4 || isNaN(aux_campo[0]) || aux_campo[0] == "") {
		campo.focus();
		//campo.style.background= cor_fundo;
		campo.style.border = " 2px red solid " 
		return true;
			}
			if (aux_campo[1].value.length != 4 || isNaN(aux_campo[1]) || aux_campo[1] == "") {
		campo.focus();
		//campo.style.background= cor_fundo;
		campo.style.border = " 2px red solid " 
		return true;
			}
		}
	}	 
	else {
		if (campo.value.length != 7 && campo.value.length != 8) {	
		campo.focus();
		//campo.style.background= cor_fundo;
		campo.style.border = " 2px red solid " 
		return true;
		}	
	}	
		
		
}//end fuction
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
function valida_trim(campo){
	while(''+campo.value.charAt(campo.value.length-1)==' '){
		campo.value=campo.value.substring(0,campo.value.length-1);	  
	}
	while(''+campo.value.substring(1,campo.value)==' '){
		campo.value=campo.value.substring(1,campo.value.length);	  
	}
}//end fuction
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
function valida_ddd(campo){
	valida_trim(campo);

		if (isNaN(campo.value)){
			campo.focus();
		//campo.style.background= cor_fundo;
		campo.style.border = " 2px red solid " 
			return true;
			}
		if (campo.value.length < 2){
			campo.focus();
		//campo.style.background= cor_fundo;
		campo.style.border = " 2px red solid " 
			return true;
		}
			
}//end fuction
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
function valida_numerico(campo){
	valida_trim(campo);
	if (valida_vazio(campo))
			{
		campo.focus();
		//campo.style.background= cor_fundo;
		campo.style.border = " 2px red solid " 
		return true;
		}

	if (isNaN(campo.value))
		{
		campo.focus();
		//campo.style.background= cor_fundo;
		campo.style.border = " 2px red solid " 
		return true;
		}
}//end fuction
//////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////
function valida_email(campo) {
	valida_trim(campo);

	var array_arroba;
	var array_ponto;
	campo.focus();
		//campo.style.background= cor_fundo;
		campo.style.border = " 2px red solid " 
	if ( campo.value.indexOf(" ") > 1 ) {return true;}

	if ( campo.value.indexOf("@") == -1 ) {
		return true;
	}else {
		array_arroba = campo.value.split("@");
		if (array_arroba.length != 2) {	return true;}
		if (array_arroba[0] == "" || array_arroba[1] == "")	{	return true;}
			if ( array_arroba[1].indexOf(".") == -1 ) {	
				return true;
			}else {
				array_ponto = array_arroba[1].split(".");
				for (i = 0 ; i < array_ponto.length ; i++) {
					if (array_ponto[i] == "") {	return true;}
				}
			}	
	}
	
}

//////////////////////////////////////////////////////////////////////


function valida_cep(campo){
	valida_trim(campo);

	campo.focus();
		//campo.style.background= cor_fundo;
		campo.style.border = " 2px red solid " 
	var aux_cep;
	if ( isNaN(campo.value) ) {
		if (campo.value.indexOf("-") == -1 ) {
			return true;
		}else {
			aux_cep = campo.value.split("-");
			if (aux_cep.length != 2) {	return true;}
			if (aux_cep[0].length != 5 || isNaN(aux_cep[0]) || aux_cep[0] == "") {	return true;}
			if (aux_cep[1].length != 3 || isNaN(aux_cep[1]) || aux_cep[1] == "") {	return true;}
		}
	}else {
		if (campo.length != 8) {return true;}	
	}	
}
//////////////////////////////////////////////////////////////////////  :o) 
function FormataCellphoneBr(obj,e)
{
	if (navigator.userAgent.indexOf("IE") != -1)
	{
		var keypress = window.event.keyCode;
		if (keypress > 47 && keypress < 58 && obj.value.length < 13)
			{
			if (obj.value.length == 0)
			   obj.value = "(" + obj.value;
			if (obj.value.length == 3)
			   obj.value = obj.value + ")";
			if (obj.value.length == 8)
			   obj.value = obj.value + "-";
			}
		else
			event.returnValue = false;
	}
	else
	{
		lineaux = obj.value;
		var keypress = e.which;
		if (keypress == 8)
			return true;
		if ((keypress < 48 || keypress > 57) || obj.value.length >= 13)
			return false;
		if (lineaux.length == 0)
			lineaux = "(";
		if (lineaux.length == 3)
			lineaux = lineaux + ")";
		if (lineaux.length == 8)
			lineaux = lineaux + "-";
		lineaux = lineaux + (keypress - 48);
		obj.value = lineaux;
		return false;
	}
	return true;
} 
/////////////////////////////////////////////////////////////////

function SomenteNumero(obj,e)
{
	if (navigator.userAgent.indexOf("IE") != -1)
	{
		var keypress = window.event.keyCode;
		if (keypress > 47 && keypress < 58 && obj.value.length < 14)
			{
			if (obj.value.length == 0)
			   obj.value = "" + obj.value;
			if (obj.value.length == 3)
			   obj.value = obj.value + "";
			if (obj.value.length == 8)
			   obj.value = obj.value + "";
			}
		else
			event.returnValue = false;
	}
	else
	{
		lineaux = obj.value;
		var keypress = e.which;
		if (keypress == 8)
			return true;
		if ((keypress < 48 || keypress > 57) || obj.value.length >= 13)
			return false;
		if (lineaux.length == 0)
			lineaux = "(";
		if (lineaux.length == 3)
			lineaux = lineaux + ")";
		if (lineaux.length == 8)
			lineaux = lineaux + "-";
		lineaux = lineaux + (keypress - 48);
		obj.value = lineaux;
		return false;
	}
	return true;
} 

/////////////////////////////////////////////////////////////////

function FormataHora(Campo, teclapres){
	var tecla = teclapres.keyCode;
	
	var vr = new String(Campo.value);
	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 < 9)
			Campo.value = vr.substr(0,2) + ':' + vr.substr(2,2) + ':' + vr.substr(4,2);
		}
	}
/////////////////////////////////////////////////////////////////

function FormataCEP(Campo, teclapres){

	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	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);
		
		}
}
/////////////////////////////////////////////////////////////////

function SaltaCampo(campo,prox,tammax,teclapres){

	var tecla = teclapres.keyCode;
	vr = document.forms[0].elements[campo].value;
		
	if( tecla == 109 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108){
	   document.form[campo].value = vr.substr(0, vr.length - 1); }
	else {
		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;

		if (tecla != 0 && tecla != 9 && tecla != 16 )
			if ( tam == tammax )
				document.forms[0].elements[prox].focus();
		}
}
//////////////////////////////////////////////////////////////////
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);
		}
}

/////////////////////////////////////////////////////////////////
function TestaHora(cHora){
	var hora; 
	hora = LimpaCampo(cHora.value,10);
	var tam = hora.length;
	if	(tam != 6){
		alert('A hora está incorreta');
		cHora.value = "";
		cHora.focus();
		return(false);
		}
	
	var hr = hora.substr(0,2)
	var min = hora.substr (2,2)
	var seg = hora.substr (4,2)	
	if ((hr > 23) || (min > 59) || (seg > 59)){
		alert('A hora está incorreta');
		cHora.value = "";
		cHora.focus();
		return(false);
		}
	return(true);
}
/////////////////////////////////////////////////////////////////
function TestaData(cData){
	var data; 
	data = LimpaCampo(cData.value,10);
	var tam = data.length;
	if	(tam != 8){
		alert('A data está incorreta');
		cData.value = "";
		cData.focus();
		return(false);
		}
	var dia = data.substr(0,2)
	var mes = data.substr (2,2)
	var ano = data.substr (4,4)	
	if (ano < 1994){
		alert('A data está incorreta');
		cData.value = "";
		cData.focus();
		return(false);
		}

	switch (mes){
		case '01':
			if  (dia > 31){
				alert('A data está incorreta');
				cData.value = "";
				cData.focus();
				return(false);
				}
			break;
		case '02':
			if  (dia > 29){
				alert('A data está incorreta');
				cData.value = "";
				cData.focus();
				return(false);
				}
			break;
		case '03':
			if  (dia <= 31){
				alert('A data está incorreta');
				cData.value = "";
				cData.focus();
				return(false);
				}
			break;
		case '04':
			if  (dia <= 30){
				alert('A data está incorreta');
				cData.value = "";
				cData.focus();
				return(false);
				}
			break;
		case '05':
			if  (dia <= 31){
				alert('A data está incorreta');
				cData.value = "";
				cData.focus();
				return(false);
				}
			break;
		case '06':
			if  (dia <= 30) {
				alert('A data está incorreta');
				cData.value = "";
				cData.focus();
				return(false);
				}
			break;
		case '07':
			if  (dia <= 31){
				alert('A data está incorreta');
				cData.value = "";
				cData.focus();
				return(false);
				}
			break;
		case '08':
			if  (dia <= 31){
				alert('A data está incorreta');
				cData.value = "";
				cData.focus();
				return(false);
				}
			break;
		case '09':
			if  (dia <= 30){
				alert('A data está incorreta');
				cData.value = "";
				cData.focus();
				return(false);
				}
			break;
		case '10':
			if  (dia <= 31){
				alert('A data está incorreta');
				cData.value = "";
				cData.focus();
				return(false);
				}
			break;
		case '11':
			if  (dia <= 30) {
				alert('A data está incorreta');
				cData.value = "";
				cData.focus();
				return(false);
				}
			break;
		case '12':
			if  (dia <= 31){
				alert('A data está incorreta');
				cData.value = "";
				cData.focus();
				return(false);
				}
			break;
		}	

	return(true); 
	}
///////////////////////////////////////////////////////////////////
function VerAlfaNumerico(pInd){
	var pValor = document.forms[0].elements[pInd].value
	var AuxTam = pValor.length  
	for(var j=0;j<AuxTam;j++)
		if ((!IndAlfaNumerico(pValor.charAt(j))) || (pValor.charAt(j) == " ")){
			document.forms[0].elements[pInd].focus();  
			document.forms[0].elements[pInd].value = pValor = pValor.substring(0,j)           
			} 
	}
////////////////////////////////////////////////////////////////////
function IndAlfaNumerico(N){
	for(var i=0;i<10;i++)
	if(N == i)
		return true;
	return false;    
	}


