if (navigator.appName.indexOf('Microsoft') != -1){   
    clientNavigator = "IE";   
}else{   
    clientNavigator = "Other";   
} 

//**********JANELA POPUP***************
function na_open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{

	var winl = (screen.width-width)/2;
	var wint = (screen.height-height)/2;
	toolbar_str = toolbar ? 'yes' : 'no';
	menubar_str = menubar ? 'yes' : 'no';
	statusbar_str = statusbar ? 'yes' : 'no';
	scrollbar_str = scrollbar ? 'yes' : 'no';
	resizable_str = resizable ? 'yes' : 'no';
	window.open(url, name, 'left='+winl+',top='+wint+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);	
}

function displayunicode(e)
{
var unicode = e.keyCode? e.keyCode : e.charCode
alert(unicode)

}


				//**********VERIFICA A TECLA PRESSIONADA (SO DEIXA DIGITAR NUMEROS)***************
		function VerificaTecla(event,campo)
		{
		
		
// verifica o evento ativado (IE ou FF) 
var tecla = window.event ? event.keyCode : event.which; 

// verifica a parte numérica do teclado 
//if (tecla > 44 && tecla < 58 || tecla > 95 && tecla < 106 || tecla == 08) { 
if (tecla > 47 && tecla < 58) {

// quando só numero 
return false; 
} else { 

// quando letra
// retorna alerta 
//window.alert("somente números") 

// pega o texto do input 
valor_input = document.form1[campo].value; 

// pega o tamanho do texto do input e retira um (letra) 
tamanho_input = document.form1[campo].value.length-1; 

// armazena em escreve sem a letra 
escreve = valor_input.substring(0,tamanho_input) 
alert(escreve);

// escreve no input sem a letra 
document.form1[campo].value= '';
document.form1[campo].value=escreve; 
return false; 
} 

							
		}

		//**********FORMATA CAMPO DE VALOR MOEDA***************
		function FormataValor(campo,tammax,teclapres) {
			VerificaTecla(teclapres,campo)
			var tecla = teclapres.keyCode;
			vr = document.form1[campo].value;
			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 (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

			if (tecla == 8 ){	tam = tam - 1 ; }
				
			if ( tecla == 8 || tecla >= 44 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
				if ( tam <= 2 ){ 
	 				document.form1[campo].value = vr ; }
	 			if ( (tam > 2) && (tam <= 5) ){
	 				document.form1[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 			if ( (tam >= 6) && (tam <= 8) ){
	 				document.form1[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 			if ( (tam >= 9) && (tam <= 11) ){
	 				document.form1[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 			if ( (tam >= 12) && (tam <= 14) ){
	 				document.form1[campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 			if ( (tam >= 15) && (tam <= 17) ){
	 				document.form1[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
			}	

		}

	
	

function validacpfcnpj(campo,teclapres)
{
        
        
        
        valor = document.form1[campo].value;
        valor = valor.replace( ".", "" );
	    valor = valor.replace( "-", "" );
	    valor = valor.replace( "/", "" );
	    valor = valor.replace( ".", "" );
	    
	    tam = valor.length;
	    
	    //alert(valor);
	   // alert(tam);
	    
	    
	    if (tam < 11)
	    {
	        alert('CPF Inválido');
	        document.form1[campo].value = "";
			document.form1[campo].focus;
	    }	    
        if (tam > 11 && tam < 14)
	    {
	        alert('CPF Inválido');
	        document.form1[campo].value = "";
			document.form1[campo].focus;
	    }   
        if (tam > 14)
	    {
	        alert('CPF Inválido');
	        document.form1[campo].value = "";
			document.form1[campo].focus;
	    }
	    if (tam == 11)
	    {
	        if (isCPFCNPJ(valor,1) == false)
	        {
	            alert('CPF Inválido');
	            document.form1[campo].value = "";
			    document.form1[campo].focus;
	        };	        
	    }
	    if (tam == 14)
	    {
	        
	        if (isCPFCNPJ(valor,2) == false)
	        {
	            alert('CNPJ Inválido');
	             document.form1[campo].value = "";
			     document.form1[campo].focus;
	        };	        
	    }

	   
}
function isEmpty(pStrText)
		{
			var	len = pStrText.length;
			var pos;
			var vStrnewtext = "";

			for (pos=0; pos<len; pos++)
			{
				if (pStrText.substring(pos, (pos+1)) != " ")
				{
					vStrnewtext = vStrnewtext + pStrText.substring(pos, (pos+1));
				}
			}

			if (vStrnewtext.length > 0)
				return false;
			else
				return true;
		}		

		function isCPFCNPJ(campo,pType)
		{
			if( isEmpty( campo ) )
			{
				return false;
			}

			var campo_filtrado = "", valor_1 = " ", valor_2 = " ", ch = "";
			var valido = false;
        
			for (i = 0; i < campo.length; i++)
			{
				ch = campo.substring(i, i + 1);
				if (ch >= "0" && ch <= "9")
				{
					campo_filtrado = campo_filtrado.toString() + ch.toString()
					valor_1 = valor_2;
					valor_2 = ch;
				}
				if ((valor_1 != " ") && (!valido)) valido = !(valor_1 == valor_2);
			}
			if (!valido) campo_filtrado = "12345678912";

			if (campo_filtrado.length < 11)
			{
				for (i = 1; i <= (11 - campo_filtrado.length); i++)
				{
					campo_filtrado = "0" + campo_filtrado;
				}
			}

			if (pType <= 1)
			{
				if ( ( campo_filtrado.substring(9,11) == checkCPF( campo_filtrado.substring(0,9) ) ) && ( campo_filtrado.substring(11,12)=="") )
				{
					return true;
				}
			}

			//if((pType == 2) || (pType == 0))
			if (pType = 2)
			{
				if (campo_filtrado.length >= 14)
				{
					if ( campo_filtrado.substring(12,14) == checkCNPJ( campo_filtrado.substring(0,12) ) )
					{
						 return true;
					}
				}
			}
	
			return false;
		}

		function checkCNPJ(vCNPJ)
		{
			var mControle = "";
			var aTabCNPJ = new Array(5,4,3,2,9,8,7,6,5,4,3,2);
			for (i = 1 ; i <= 2 ; i++)
			{
				mSoma = 0;
				for (j = 0 ; j < vCNPJ.length ; j++)
				mSoma = mSoma + (vCNPJ.substring(j,j+1) * aTabCNPJ[j]);
				
				if (i == 2 ) mSoma = mSoma + ( 2 * mDigito );
				mDigito = ( mSoma * 10 ) % 11;
				if (mDigito == 10 ) mDigito = 0;
				mControle1 = mControle ;
				mControle = mDigito;
		        aTabCNPJ = new Array(6,5,4,3,2,9,8,7,6,5,4,3);
			}
			return( (mControle1 * 10) + mControle );
		}

		function checkCPF(vCPF)
		{
			var mControle = ""
			var mContIni = 2, mContFim = 10, mDigito = 0;
			for (j = 1 ; j <= 2 ; j++)
			{
				mSoma = 0;
				for (i = mContIni ; i <= mContFim ; i++)
				mSoma = mSoma + (vCPF.substring((i-j-1),(i-j)) * (mContFim + 1 + j - i));
				if (j == 2 ) mSoma = mSoma + ( 2 * mDigito );
				mDigito = ( mSoma * 10 ) % 11;
				if (mDigito == 10) mDigito = 0;
				mControle1 = mControle;
				mControle = mDigito;
				mContIni = 3;
				mContFim = 11;
			}
			return( (mControle1 * 10) + mControle );
		}

		
		