function voltar(){
var texto ='<h6>Login</h6><ul id="login"><li><a tabindex="1" href="javascript:login(\'0\')">Cliente</a></li>'
	texto+='<li><a tabindex="2" href="javascript:login(\'2\',true)">Usu�rio</a></li>';
	texto+='<li><a tabindex="3" href="javascript:login(\'1\',true)">Credenciado</a></li></ul>';
	document.getElementById('loginbox').innerHTML=texto;

}
function protocolo_entrega(p,d){
var end="protocolo_entrega.php?p="+p+"&d="+d;
window.open(end,"rec","height=600,width=800, top=0, left=0,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");	
}
function ctrl_deps(nm){
	var visualiza='block';
	if(navigator.appName!='Microsoft Internet Explorer'){
		visualiza='table-row';
	}
	var el = document.getElementById(nm);
	if (el.style.display=='none') {
	document.getElementById(nm).style.display =visualiza;
	}else{
	document.getElementById(nm).style.display ='none';
	}
}
 function Trim(stri){

	while (stri.charAt(0) == " ")
		stri = stri.substr(1,stri.length -1);
	while (stri.charAt(stri.length-1) == " ")
		stri = stri.substr(0,stri.length-1);
	return stri;
}

function formok(){
	if (document.getElementById("nome").value==''){
		alert('Preencha o nome corretamente!');
		return false;	
	} 
	if (document.getElementById("emailcontato").value.indexOf('@')<1){
		alert('Preencha o email corretamente!');
		return false;	
	} 
}

function login(op,root){//0-cliente 1-credenciado 2-usuario root=true, aponta pro diretorio no php
	var table = "<table width=\"100%\" border=\"0\">";
	var ftable = "</table>";
	var tdlabel="<td width=\"30%\">";
	var tdbox="<td width=\"70%\">";
	var ftd="</td>";
	var tr="<tr>";
	var ftr="</tr>";
	var dir="";
	var tipo=new Array();
		tipo['0']="CL";
		tipo['1']="CR";
		tipo['2']="US";
	
	if (root) dir="./php/";
	if((op=='0')||(op=='1')){
		var tamanho='14';
		var label  ='CNPJ:';
	}else{
		var tamanho='19';
		var label  ='Cart�o:';
	}
	var texto  = '<form method="post" action="'+dir+'efetuar_login.php">';
		texto += '<h6>login</h6>';
		texto +=table+tr+tdlabel+label+ftd+tdbox
			  + '<input id="cod" tabindex="1" name="cod" class="caixa" type="text" size="14" maxlength="'+tamanho+'">'
			  + ftd+ftr;
		texto +=tr+tdlabel+'Senha:'+ftd+tdbox
			  +'<input id="sen" tabindex="2" name="sen" class="caixa" type="password" size="14" >'
			  + ftd+ftr+ftable;
		texto += '<input class="titulo" id="ok" tabindex="3" type="submit"  value="OK">&nbsp;&nbsp;&nbsp;';
		texto += '<input class="titulo" id="volt" type="button" onClick="javascript:voltar()"  value="Voltar">';
		texto += '<input id="tipo" name="tipo" value="'+tipo[op]+'" type="hidden">';
		texto += '</form>';
		document.getElementById('loginbox').style.align="left";
		document.getElementById('loginbox').innerHTML=texto;
		}
function vis(n,c){
if (c==0) document.getElementById(n).style.display="none";
if (c==1) document.getElementById(n).style.display="block";
}





function TestaExcessao( NomeTest){
     var result = false;
     var NomeTest = NomeTest.toUpperCase;
    if (( NomeTest == 'DO') ||
       ( NomeTest == 'DA')  ||
       ( NomeTest == 'DOS') ||
       ( NomeTest == 'DAS') ||
       ( NomeTest == 'DE')  ||
       ( NomeTest == 'E'))
       result= true;
	return  result;
  }
  
  
function NomeAbreviado( nome, iLength){
   var result =  nome;
   var Indice=0;
   var FullName='';
   var aName=new Array();
   var C=0;
   var LastName='';
   var I=0;
  if (nome.length >  iLength){
     Indice = 0;
     FullName =  nome + ' ';
	 FullNameTemp=FullName;
    while (FullName.length > 0){
     var  sAux = FullName.substr(0,FullName.indexOf(' ')+1);
	  if (!TestaExcessao( sAux)){
         Indice++;
         aName[Indice] =  sAux;
      }
      //Delete( FullName, 1, Pos( ' ', FullName ) );
	   FullName = FullName.replace(sAux,"");//str_replace( sAux,"", FullName);
	  //echo alerta( FullName);
    }
     LastName =  aName[ Indice];
    if ( LastName.length >  iLength ){
       result =  aName[0];
      exit();
    }
     Indice =  Indice -1;
     C =  Indice;
	 FullName=FullNameTemp;
    while (FullName.length >  iLength){
      if ( C == 0)
         FullName =  LastName;
      else{
         FullName = '';
         aName[ C]= aName[ C].substr(0,1) +'.';
        for( I = 1; I<= Indice; I++)
           FullName =  FullName +' ' +  aName[ I];
        //Delete(FullName,1,1);
		 //FullName=substr_replace( FullName, '', 0, 1);
         FullName =  FullName + ' ' +  LastName;
        if ( Indice >  C){ 
          if (aName[1].length > 2)
             Indice =  Indice - 1;
          else
			 C =  C -1;
		  }
        else
           C =  C -1;
      }
    }
     result =  FullName;
  }
return  Trim(result);
  }
  
  
  function calcvalidacpf(CePeeFe){
 var CPF = CePeeFe; // Recebe o valor digitado no campo
 var ret=true;
// Verifica se o campo � nulo
if (CPF == '') {
  alert('Este campo � de preenchimento obrigat�rio!');
  ret=false;
   }

// Aqui come�a a checagem do CPF
var POSICAO, I, SOMA, DV, DV_INFORMADO;
var DIGITO = new Array(10);
DV_INFORMADO = CPF.substr(9, 2); // Retira os dois �ltimos d�gitos do n�mero informado

// Desemembra o n�mero do CPF na array DIGITO
for (I=0; I<=8; I++) {
  DIGITO[I] = CPF.substr( I, 1);
}

// Calcula o valor do 10� d�gito da verifica��o
POSICAO = 10;
SOMA = 0;
   for (I=0; I<=8; I++) {
      SOMA = SOMA + DIGITO[I] * POSICAO;
      POSICAO = POSICAO - 1;
   }
DIGITO[9] = SOMA % 11;
   if (DIGITO[9] < 2) {
        DIGITO[9] = 0;
}
   else{
       DIGITO[9] = 11 - DIGITO[9];
}

// Calcula o valor do 11� d�gito da verifica��o
POSICAO = 11;
SOMA = 0;
   for (I=0; I<=9; I++) {
      SOMA = SOMA + DIGITO[I] * POSICAO;
      POSICAO = POSICAO - 1;
   }
DIGITO[10] = SOMA % 11;
   if (DIGITO[10] < 2) {
        DIGITO[10] = 0;
   }
   else {
        DIGITO[10] = 11 - DIGITO[10];
   }

// Verifica se os valores dos d�gitos verificadores conferem
DV = DIGITO[9] * 10 + DIGITO[10];
   if (DV != DV_INFORMADO) {
      alert('CPF inv�lido');
      formulario.CPF.value = '';
      formulario.CPF.focus();
      ret=false;
   }
return ret
 }
 
 
 function  remAcento(sStrAcentoo){
  var sStrAcento=sStrAcentoo;
  var I=0;
  var newsStrAcento='';
  for (I=0;I<sStrAcento.length;I++){
    switch(sStrAcento[I]) {
		 case "�" :
		 case "�" :
		 case "�" :
		 case "�" :
		 case "�" :  		newsStrAcento += "a";
		  					break;
		 
		 case "�" :
		 case "�" :
		 case "�" :
		 case "�" : 	  	newsStrAcento += "e";
		   					break;
		
		 case "�" :
		 case "�" :
		 case "�" :
		 case "�" : 	  	newsStrAcento += "i";
		   					break;
		 
		 case "�" :
		 case "�" :
		 case "�" :
		 case "�" :
		 case "�" : 	  	newsStrAcento += "o";
		   					break;
		 
		 case "�" :
		 case "�" :
		 case "�" :
		 case "�" : 	  	newsStrAcento += "u";
		   					break;
		 
		 case "�" : 	  	newsStrAcento += "n";
							break;
	
		 case "�" : 	  	newsStrAcento += "c";
							break;
	
		 case "�" :
		 case "�" :
		 case "�" :
		 case "�" :
		 case "�" : 	  	newsStrAcento += "A";
							break;
	
		 case "�" :
		 case "�" :
		 case "�" :
		 case "�" : 	  	newsStrAcento += "E";
							break;
	
		 case "�" :
		 case "�" :
		 case "�" :
		 case "�" : 	  	newsStrAcento += "I";
							break;
	 
		 case "�" :
		 case "�" :
		 case "�" :
		 case "�" :
		 case "�" : 	  	newsStrAcento += "O";
							break;
	
		 case "�" :
		 case "�" :
		 case "�" :
		 case "�" : 	  	newsStrAcento +=  "U";
							break;
	
		  case "�": 	  	newsStrAcento +=  "N";
							break;
	
		  case "�": 	  	newsStrAcento += "C";
							break;
		  default:          newsStrAcento += sStrAcento[I];
		  }
		  
    }
  return newsStrAcento;
}

function passanome(){
//  var habilitado=!document.getElementById('txtnomeabr').readOnly;
//  if (habilitado)
	document.getElementById('txtnomeabr').value=NomeAbreviado(remAcento(document.getElementById('txtnome').value),25);
}

function isNum( string ){
	var strValidos = "0123456789"
	var c=0;
	for(c=0;c<string.length;c++)
		if ( strValidos.indexOf(string.substr(c,1)) == -1 )
			return false;
			
	return true;
}

function alertnotnum(element){
	var string=document.getElementById(element);
	if (!isNum(string.value)){
		alert('Permitido somente n�meros neste campo!');
		document.getElementById(element).focus();
		}
	
}
function abre_tr(pr,dt,nm,cd){
		var url="transacoes_reembolsar_data.php?prod="+pr+"&data="+dt+"&nm="+nm+"&cd="+cd;
		window.open(url,"tr"," height = 550, width = 650,left=250,top=100,toolbar=0,resizable=0, scrollbars=1");
		}

function abre_ap(ap){
		var url="analise_reembolso.php?sint&ap="+ap;
		window.open(url,"ap"," height = 550, width = 650,left=250,top=100,toolbar=0,resizable=0, scrollbars=1");
		window.open(url,"ap"," height = 550, width = 650,left=250,top=100,toolbar=0,resizable=0, scrollbars=1");
		}
function abre_ap_print(ap){
		var url="print_analise_reembolso.php?sint&ap="+ap;
		window.open(url,"ap"," height = 550, width = 650,left=250,top=100,toolbar=0,resizable=0, scrollbars=1");
		}		
