function buscarEnderecoTelefone(complParaId, documento, urlServlet){
		var objDiv = document.getElementById("divIconeEnderecoTelefone_"+ complParaId);
		var objIframe = document.getElementById("iFrameEnd_"+complParaId);
		
		objDiv.style.display ="none";
		objIframe.style.display = "block";

		objIframe.src = urlServlet+ "?documento="+documento+"&complParaId="+complParaId;
	}

function alterHeightIFrame(complParaId, objImg, inicioURL){
	var objIframe = document.getElementById("iFrameEnd_" + complParaId);
	
	if(objIframe.height == 150){
		objIframe.height = 37;
		objImg.src = inicioURL + "/images/mais.png"
	}else{
		objIframe.height = 150;
		objImg.src = inicioURL + "/images/menos.png"
	}
}

function mostraOcultaTable(idTable, objImg, inicioURL){
	var objTable = document.getElementById(idTable);
	
	if(objImg.src.indexOf('menos.png') != -1){
		objTable.style.display = "none";
		objImg.alt = "Mostrar conteúdo";
		objImg.src = inicioURL + "/images/mais.png";
	}else{
		objTable.style.display = "block";
		objImg.alt = "Ocultar conteúdo";
		objImg.src = inicioURL + "/images/menos.png";
	}
}

function excluir() {
    return (confirm("Excluir registro?"))
}

function abrirPopUp(pagina, width, height){
	window.open(pagina,"_blank","location=0,status=1,scrollbars=0,toolbar=0, width="+width+",height="+height);
}

function Trim(str){
	var i;
	var retorno = "";
	for(i = 0; i < str.length; i++){
		if(str.charAt(i) != " "){
			retorno = retorno + str.charAt(i);
		}
	}
	return retorno;
}

function formataInput(formato, input){
/// OnKeyUP
	if (((((((event.keyCode != 37) && (event.keyCode != 39)) && (event.keyCode !=46)) && (event.keyCode !=8))&& (event.keyCode !=36)) && (event.keyCode !=35)))
		if (input.value.length < formato.length) {
			if (formato.substring(input.value.length , input.value.length + 1) != "#") {
				input.value = input.value + formato.substring(input.value.length , input.value.length + 1);
			}		
		}	
}

function formatoInteiro() {
	/// OnKeyDown
//	alert(event.keyCode);
	if (((((event.keyCode >= 96 ) && (event.keyCode <= 105)) || ((event.keyCode >= 48 ) && (event.keyCode <= 57))) || (((((((event.keyCode == 37) || (event.keyCode == 39)) || (event.keyCode ==46)) || (event.keyCode ==8))|| (event.keyCode ==36)) || (event.keyCode ==35))))||(event.keyCode ==9)){
		event.returnValue = true;
	} else {
		event.returnValue = false;
	}	
}

function formataLogin(campo) {
	/// OnKeyDown
//	alert(event.keyCode);
/*
	if (((event.keyCode >= 65) && (event.keyCode <= 90)) || ((event.keyCode >= 97) && (event.keyCode <= 105)) || (event.keyCode <= 8)  ){
		event.returnValue = true;
	} else {
		event.returnValue = false;
	}
*/
campo.value = campo.value.replace(/[^0-9a-zA-Z]/g, ""); 
		
}

function formatoNumerico() {
	/// OnKeyDown
//	alert(event.keyCode);
	if (((((event.keyCode >= 96 ) && (event.keyCode <= 105)) || ((event.keyCode >= 48 ) && (event.keyCode <= 57))) || (((((((event.keyCode == 37) || (event.keyCode == 39)) || (event.keyCode ==46)) || (event.keyCode ==8))|| (event.keyCode ==36)) || (event.keyCode ==35))))||(event.keyCode ==9) || (event.keyCode ==44)){
		event.returnValue = true;
	} else {
		event.returnValue = false;
	}	
}

//-----------------------------------------------------
//Funcao: MascaraMoeda
//Sinopse: Mascara de preenchimento de moeda
//Parametro:
//   objTextBox : Objeto (TextBox)
//   SeparadorMilesimo : Caracter separador de milésimos
//   SeparadorDecimal : Caracter separador de decimais
//   e : Evento
//Retorno: Booleano
//-----------------------------------------------------
function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = 0
	var j = 0;
    var len = 0
	var len2 = 0;
    var strCheck = '-0123456789';
    var aux = ''
	var aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

function validaDoc(campo) {
	if (campo.id == "cnpj") {
		return valida_cnpj(campo.value);
	}
	else if (campo.id == "cpf") {
		return validaCPF(campo);
	}
}
function valida_cnpj(cnpj)
      {
      
      
      var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
      digitos_iguais = 1;
      if (cnpj.length < 14){
	  	alert('CNPJ Inválido');
		return false;
	  }
            
      for (i = 0; i < cnpj.length - 1; i++)
            if (cnpj.charAt(i) != cnpj.charAt(i + 1))
                  {
                  digitos_iguais = 0;
                  break;
                  }
      if (!digitos_iguais)
            {
            tamanho = cnpj.length - 2
            numeros = cnpj.substring(0,tamanho);
            digitos = cnpj.substring(tamanho);
            soma = 0;
            pos = tamanho - 7;
            for (i = tamanho; i >= 1; i--)
                  {
                  soma += numeros.charAt(tamanho - i) * pos--;
                  if (pos < 2)
                        pos = 9;
                  }
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(0)){
				alert('CNPJ Inválido');
				return false;
			}
                  
            tamanho = tamanho + 1;
            numeros = cnpj.substring(0,tamanho);
            soma = 0;
            pos = tamanho - 7;
            for (i = tamanho; i >= 1; i--)
                  {
                  soma += numeros.charAt(tamanho - i) * pos--;
                  if (pos < 2)
                        pos = 9;
                  }
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(1)){
				alert('CNPJ Inválido');
				return false;
			}
                  
            
			return true;
            }
      else{
	  	alert('CNPJ Inválido');
		return false;
	  }
            return true;
      }

	function validaCPF(campo) {

      cpf = campo.value;

      valor = true;

      erro = new String;

      

      cpf = cpf.replace(".","");

      cpf = cpf.replace(".","");

      cpf = cpf.replace("-","");

      cpf = cpf.replace("/","");

      

      

      if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 

      var nonNumbers = /\D/;

      if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n";      

      if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){

              erro += "Numero de CPF invalido!"

      }

      var a = [];

      var b = new Number;

      var c = 11;

      for (i=0; i<11; i++){

            a[i] = cpf.charAt(i);

            if (i < 9) b += (a[i] *  --c);

      }

      if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }

      b = 0;

      c = 11;

      for (y=0; y<10; y++) b += (a[y] *  c--); 

      if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }

      if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){

            erro +="CPF invalido!";

      }

      if (erro.length > 0){

            alert(erro);

            return false;

      }

      return true;

}

