/*

*** Funcão para retornar apensa numeros de um string ***

function SoNumero(s)



*** Função para inclusão da mascara para cpf ***

ex: onKeyPress="mask_cpf(this);"

function mask_cpf(field)



*** Função para inclusão da mascara para campo data ***

ex: onKeyPress="mask_data(this);"

function mask_data(field)



Função para validação de data 

ex: onblur="CheckDate(this)"

function CheckDate(field)



Função para validação de data 

ex: onblur="CheckHour(this)"

function CheckHour(field)



*** Função para inclusão da mascara para campo hora ***

ex: onKeyPress="mask_hora(this);"

function mask_hora(field)



*** Função para retirar letras e numero de um campo inteiro ***

ex: onBlur="javascript:this.value=mask_int(this.value);"

function mask_int(n)



*** Função para validação do digito verificador do cpf ***

Retorna true se o CPF esta OK. 

ex: onBlur="CheckCpf(this)"

function CheckCpf(field) 



*** Função para ordenação do objeto SELECT ***

function bublesort( lista )

  *** Função usada internamente pela funcao "bublesort"  

  function troca( lista , i, j) 



*** Função para mover todos os OPTIONS do Objeto SELECT "origem" ***

    para o SELECT "destino"

function moveDOTodos(origem, destino)



*** Função para mover somente os OPTIONS selecionados do Objeto SELECT "origem" ***

    para o SELECT "destino"

function moveDOSelecionados(origem, destino)



*** Função para mover somente os OPTIONS selecionados do Objeto SELECT "destino" ***

    para o SELECT "origem"

function moveODSelecionados(origem, destino)



*** Função para mover todos os OPTIONS do Objeto SELECT "destino" ***

    para o SELECT "origem"

function moveODTodos(origem, destino)



*** Função para limpar o Objeto SELECT ***

function limpalista( lista )



*** Função que cria um array do tamanho passado como parametro ***

function CriaArray (n) 



*** Função para verificar se o host tem o plug-in Acrobat reader ***

function detectPlugin()

*/



//Funcão para retornar apensa numeros de um string

function SoNumero(s)

{

  var i=0; 

  var r=""; 

  var l="0123456789"; 

  for (i=0; i < s.length; i++)

  {

    if (l.indexOf(s.charAt(i))>=0)

    {

	  r=r+s.charAt(i);

    } 

  }

  return r;

}



/* 

Função para inclusão da mascara para cpf 

ex: onKeyPress="mask_cpf(this);"

*/

function mask_cpf(field)

{

	if ((event.keyCode<48)||(event.keyCode>57)){

		event.returnValue = false;

		}

    else {

    	if((field.value.length==3)||(field.value.length==7))

			field.value=field.value + "." ;

		else {

    		if(field.value.length==11)

				field.value=field.value + "-" ;

		}

	}

}



/* 

Função para inclusão da mascara para campo data

ex: onKeyPress="mask_data(this);"

/*
Função para inclusão da mascara para campo data
ex: onKeyPress="mask_data(this);"
*/
function mask_data(e,field,checkDate) {

  var tecla = window.event ? e.keyCode : e.which;
  var retorno = true;

  if (tecla == 13) {

    retorno = false;

    // o terceiro parametro é opcional, portanto deve ser verificado aqui
    if (new String(checkDate).toUpperCase() != "UNDEFINED") {
      var data = document.getElementById("formatoData");
      if (CheckDateNoMessage(field)) {
        data.style.color = "black";
        data.innerHTML = "Data no formato dd/mm/aaaa";
        document.frm_videos.categoria.focus();
      } else {
        data.style.color = "red";
        data.innerHTML = "Data inválida";
        field.focus();
      }
    } else {
      if ((field.value.length > 0) && (!CheckDateNoMessage(field))) {
        field.value = "";
        field.focus();
      } else
        getNextElement(field).focus();
    }

  } else  
    retorno = isNumKey(tecla,false);

  if (window.event) e.returnValue = retorno;



  // aplica a formatacao no padrao dd/mm/aaaa
  if ((retorno) && (!isSpecialKey(tecla))){
    if (field.value.length == 2) {
      field.value += "/";
    }

    if (field.value.length == 5) {
      field.value += "/";
    }
  }

  return(retorno);
}
/* 

Função para inclusão da mascara para campo hora

ex: onKeyPress="mask_hora(this);"

*/

function mask_hora(field)

{

	if ((event.keyCode<48)||(event.keyCode>57)){

		event.returnValue = false;

		}

    else {

    	if (field.value.length==2)

			field.value=field.value + ":";			

		}

}






function F_telefone(field){
      field.value;
  if (field.value.length == 0){
     alert("Favor digitar número de Telefone.");
     field.focus();
     field.select();
     return false;
  } else if (field.value.length < 10){    
    alert("Favor digitar Telefone corretamente.");
    field.focus();
    field.select();
    return false;
  }else {
    field.value = "(" + field.value.substring(0,2) + ")" + field.value.substring(2,6)+"-" + field.value.substring(6,10);
  }
}




/* 

Função para retirar letras e numero de um campo inteiro

ex: onBlur="javascript:this.value=mask_int(this.value);"

*/

function mask_int(n)

{

  return SoNumero(n);

}



/* 

Função para validação do digito verificador do cpf

Retorna true se o CPF esta OK. 

ex: onBlur="CheckCpf(this)"

*/



function digitoCPF(parametroCPF)

{

  var xCPF  = parametroCPF;

  var MatrizAux1 = new Array;

  var MatrizAux2 = new Array;

  

  xSoma = 0;

  

  for(i=0;i<10;i++)

  {

    MatrizAux1[i] = 11 - (i + 1);     // 10-9-8-7-6-5-4-3-2-1 obs: O "1" nao é utilizado

    MatrizAux2[i] = 12 - (i + 1);     // 11-10-9-8-7-6-5-4-3-2

  }

  

  for (i=0;i<xCPF.length;i++)

    xSoma = xSoma + (parseInt(xCPF.substr(i,1)) * MatrizAux1[i]);



  xDig1 = (xSoma * 10) % 11;

  

  if (xDig1 == 10)

    xDig1 = 0;

    

  xCPF	= xCPF + xDig1.toString();

  xSoma	= 0;



  for (i=0;i<xCPF.length;i++)

  {

    xSoma = xSoma + (parseInt(xCPF.substr(i,1)) * MatrizAux2[i]);

  }



  xDig2 = (xSoma * 10) % 11;



  if (xDig2 == 10)

    xDig2 = 0;



  return xDig1.toString() + xDig2.toString();

}



function digitoCGC(parametroCGC)

{

  xCGC = parametroCGC;

  xSoma = 0;

  ver1 = "543298765432";

  ver2 = "6543298765432";



  for(i=0;i < xCGC.length;i++)

    xSoma = xSoma + parseInt(xCGC.substr(i,1)) * parseInt(ver1.substr(i,1));



  xDig1= (xSoma * 10) % 11;



  if (xDig1 == 10)

    xDig1 = 0;

    

  xCGC = xCGC + xDig1.toString();

  xSoma	= 0;



  for (i=0;i < xCGC.length;i++)

    xSoma = xSoma + parseInt(xCGC.substr(i,1)) * parseInt(ver2.substr(i,1));

  xDig2 = (xSoma * 10) % 11;



  if(xDig2 == 10)

    xDig2= 0;



  return xDig1.toString() + xDig2.toString();

}



function CheckCpf(field) 

{



  var tempCGCCPF = SoNumero(field.value);



  var result=true;  



  if (tempCGCCPF.length != 11     || tempCGCCPF.length != 14     ||

      tempCGCCPF == "00000000000" || tempCGCCPF == "11111111111" || tempCGCCPF == "22222222222" ||

      tempCGCCPF == "33333333333" || tempCGCCPF == "44444444444" || tempCGCCPF == "55555555555" ||

      tempCGCCPF == "66666666666" || tempCGCCPF == "77777777777" || tempCGCCPF == "88888888888" ||

      tempCGCCPF == "99999999999")

    result=false;



  if (tempCGCCPF.length == 11)

  {

    result = digitoCPF(tempCGCCPF.substr(0,9)) == tempCGCCPF.substr(9,2);

    mensagem = "CPF Incorreto!";

  }





  if (tempCGCCPF.length == 14)

  {

    result = digitoCGC(tempCGCCPF.substr(0,12)) == tempCGCCPF.substr(12,2);

    mensagem = "CGC Incorreto!";

  }



  if (!result)

  {

    alert(mensagem);

    field.focus();

  }



  return result;

}



/* 

Função para validação de conteudo do campo

Retorna true se o campo for nulo ou branco 

ex: onblur="isNull(this)"

*/

function isNull(field)

{

 result=false;

 if ((field.value.substr(0,1) == " ") || (field.value=="") || (field.value==null))

 {

   alert("O Campo deve ser preenchido ! ["+field.name+"]");

   field.focus();

   result=true;

 }

 return result;

}



/* 

Função para validação de data 

ex: onblur="CheckDate(this)"

*/



function CheckDate(field)

{

  var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

  var dateExists = true;

  var day = parseInt(field.value.substring(0,2),10);

  var month = parseInt(field.value.substring(3,5),10);

  var year = parseInt(field.value.substring(6,10),10);

  

	if (field.value != '')

	{

	  if (!day || !month || !year)

	  {

	    alert('Favor preencher a data no formato dd/mm/aaaa !');

	    field.focus();

			field.select();

	    return false;

	  }

		

		if (year <= 1900)

		{

	    alert('Data inválida!');

	    field.focus();

			field.select();

	    return false;			

		}

	  if (year/4 == parseInt(year/4)) monthLength[1] = 29;

	  if (day > monthLength[month-1]) dateExists = false;

	  if (day < 1) dateExists = false;

	  if (month < 1 || month > 12) dateExists = false;



	  if (!dateExists) 

	  {

	    alert("Data Incorreta !!!");

			field.focus();

	    field.select();	

	    return false;

	  }

	}

  return true;

}



/* 

Função para validação de hora 

ex: onblur="CheckHour(this)"

*/



function CheckHour(field)

{

	

  var HourExists = true;  

  var tempo  =   field.value;

  

  if (tempo.length != 0){

    tempo   = tempo.lpad(4, '0');  

    var hora   = tempo.substring(0,2);

  

    if (tempo.length == 4)  

      var minuto = tempo.substring(2,4); 

	

    if (tempo.length == 5)  

      var minuto = tempo.substring(3,5); 



    if ((hora < 0) || (hora > 23)) 

	  HourExists = false; 

   

    if ((minuto < 0) || (minuto > 59)) 

	  HourExists = false;  

	

	field.value = hora + ":" + minuto;

		

    if (!HourExists){

      alert("Hora Incorreta !!!");

	  field.focus();

	  field.value = "";

	  return false;

    }

  }

}







/* 

 função para substituir validação do digito verificador do cpf 

 ex: onkeydown="return tabOnEnter(this, event);" 

*/



function tabOnEnter (field, evt) {

var keyCode = document.layers ? evt.which : document.all ? evt.keyCode : evt.keyCode;  

  if (keyCode != 13) 

    return true;

  else {

    getNextElement(field).focus();

    return false;

  }

}

	 

function getNextElement (field) {

var form = field.form; 

  for (var e = 0; e < form.elements.length; e++)

    if (field == form.elements[e])

	{

	  if ((form.elements[e+1].readOnly)||(form.elements[e+1].disabled))

	    field = form.elements[e+1]; 

	  else

       break;

    }

  return form.elements[++e % form.elements.length];

  

  alert("teste");

}

	 

function FormataValor(campo,tammax,teclapres) {

	var tecla = teclapres.keyCode;

	vr = document.all[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 >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){

		if ( tam <= 2 ){ 

	 		document.all[campo].value = vr ; }

	 	if ( (tam > 2) && (tam <= 5) ){

	 		document.all[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }

	 	if ( (tam >= 6) && (tam <= 8) ){

	 		document.all[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }

	 	if ( (tam >= 9) && (tam <= 11) ){

	 		document.all[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.all[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.all[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 ) ;}

	}

		

		

}



/* Verificar número de cartão de crédito... */ 



function isCreditCard(st) 

{

  if (st.length > 19)

    return (false);



  sum = 0;

  mul = 1;

  l   = st.length;

  for (i = 0; i < l; i++) 

  {

    digit    = st.substring(l-i-1,l-i);

    tproduct = parseInt(digit ,10)*mul;

    if (tproduct >= 10)

      sum += (tproduct % 10) + 1;

    else

      sum += tproduct;

    if (mul == 1)

      mul++;

    else

      mul--;

  }



  if ((sum % 10) == 0)

    return (true);

  else

    return (false);

}



function strip(val) 

{

  val = "" + val;

  if (val == null)

    return "";

  var result = "";

  for (i=0;i<val.length;i++) 

  {

    character = val.charAt(i);

    if ("0123456789".indexOf(character) != -1)

      result += character;

  }

  return result;

}



function verificaCartao(form_element,numero_cartao) 

{

  var stripped_entry = strip(numero_cartao);

  

	var x,tamAntigo;

 	var numCartaoNovo;



  numCartaoNovo = "";



	if ((stripped_entry.length != 16) && (stripped_entry.length != 0))

	{

		tamAntigo = 16 - stripped_entry.length;

		for(x=0;x<tamAntigo;x++)

		{

			if (x == 5)

			{

				numCartaoNovo = numCartaoNovo + '2';

			}

			else

			{

				numCartaoNovo = numCartaoNovo + '0';

			}

		}

		for(x=tamAntigo;x<16;x++)

		{

			numCartaoNovo = numCartaoNovo + stripped_entry.charAt(x-tamAntigo);

		}

		form_element.value = numCartaoNovo;

		stripped_entry = numCartaoNovo;

		numero_cartao = numCartaoNovo;

	}



  if ((numero_cartao != "") && (!isCreditCard(stripped_entry)))

  {

    alert('O número do cartão não é válido. '

        + 'Verifique o número e tente novamente.');

  	form_element.focus();

    return false;

  }

  return true;

}





/* ...Verificar número de cartão de crédito */



function Dia(Data_DDMMYYYY)

{

  string_data = Data_DDMMYYYY.toString();

  posicao_barra = string_data.indexOf("/");

  if (posicao_barra!= -1)

  {

    dia = string_data.substring(0,posicao_barra);

    return dia;

  }

  else

  {

    return false;

  }

}



function Mes(Data_DDMMYYYY)

{

  string_data = Data_DDMMYYYY.toString();

  posicao_barra = string_data.indexOf("/");

  if (posicao_barra!= -1) 

  {

    dia = string_data.substring(0,posicao_barra);

    string_mes = string_data.substring(posicao_barra+1,string_data.length);

    posicao_barra = string_mes.indexOf("/");

    if (posicao_barra!= -1)

    {

      mes = string_mes.substring(0,posicao_barra);

      mes = Math.floor(mes);

      return mes;

    }

    else

    {

      return false;

    }

  }

  else

  {

    return false;

  }

}



function Ano(Data_DDMMYYYY)

{

  string_data = Data_DDMMYYYY.toString();

  posicao_barra = string_data.indexOf("/");

  if (posicao_barra!= -1)

  {

    dia = string_data.substring(0,posicao_barra);

    string_mes = string_data.substring(posicao_barra+1,string_data.length);

    posicao_barra = string_mes.indexOf("/");

    if (posicao_barra!= -1)

    {

      mes = string_mes.substring(0,posicao_barra);

      mes = Math.floor(mes);

      ano = string_mes.substring(posicao_barra+1,string_mes.length);

      return ano;

    } 

    else

    {

      return false;

    }

  }

  else

  {

    return false;

  }

}



function idade(data)

{

  var datasys = new Date();

  Var_Dia1=datasys.getDate();

  Var_Mes1=datasys.getMonth();

  Var_Mes1=Math.floor(Var_Mes1)-1;

  Var_Ano1=datasys.getYear();

  var data1 = new Date(Var_Ano1,Var_Mes1,Var_Dia1);



  Var_Dia2=Dia(data);

  Var_Mes2=Mes(data);

  Var_Mes2=Math.floor(Var_Mes2)-1;

  Var_Ano2=Ano(data);

  var data2 = new Date(Var_Ano2,Var_Mes2,Var_Dia2);



  var diferenca = data1.getTime() - data2.getTime();

  var diferenca = Math.floor(diferenca / (1000 * 60 * 60 * 24));

  var i = Math.floor(diferenca / 365);

  return i;

}



function tira_apostrofo(s)

{

//  alert("s = " + s);

  var i = 1;

  var size = s.length;

  var s2   = '';



  for (i=0; i<size; i++)

  {

    if (s.charAt(i) != "'")

	  s2 = s2 + s.charAt(i);

	

  }

  return s2;

}

 

function NomeAbrev(nome)

{

  var nomes = new Array();

  var result = nome;

  nome = nome + " ";

  p = nome.indexOf(" ");

  if (p > 0)

  {

	totalnomes = 0;

    while (p > 0)

	{

	  totalnomes++;

	  nomes[totalnomes-1] = nome.substring(0,p);

	  nome = nome.substring(p+1,nome.length);

	  p = nome.indexOf(" ");

    }

	if (totalnomes > 2)

	{

	  for(i=1;i<totalnomes-1;i++)

	  {

   	    if (nomes[i].length > 3)

		  nomes[i] = nomes[i].substring(0,1);

	  }

	  result = "";

	  for(i=0;i<=totalnomes-1;i++)

	  {

	    if (i > 0)

		{

		  if ((nomes[i].length == 1)||(nomes[i].length > 3))

		    result = result + nomes[i] + " ";

		}

		else

          result = result + nomes[i] + " ";

  	  }

	  if (result.length > 20)

	  {

		result = nomes[0] + " ";

		result = result + nomes[totalnomes-1];

	  }

	  result = result.substring(0,19);

	}

  }

  return result; 

}



function CriaArray (n) 

{ 

	this.length = n;

	for (var i = 0 ; i < n ; i++) 

	  { this[i] = ""; }   

} 



function limpalista( lista )

{

	lista.options.length = 0;   

} 



function moveODTodos(origem, destino)

{

	for (var i = 0 ; i < origem.options.length ; i++) 

	 destino.options[destino.length] = new Option(origem.options[i].text,

												  origem.options[i].value);

	limpalista( origem );    												  

	

	bublesort( destino );   

}  



function moveODSelecionados(origem, destino)

{

	var num_excluidos = 0;

	

	excluir_id = new CriaArray(origem.length);

	

	for (i = 0 ; i < origem.length ; i++) 

	 if (origem.options[i].selected) 

	   {

		 destino.options[destino.length] = new Option(origem.options[i].text,

													  origem.options[i].value);													  

		 excluir_id[num_excluidos] = i;		 

		 num_excluidos++;

	   }

	   

	for (i = 0 ; i < num_excluidos ; i++) 

	 origem.options.remove(excluir_id[i]-i);

	 

	if ( num_excluidos > 0 )

  	  bublesort( destino );   



}  

 

function moveDOSelecionados(origem, destino)

{

	var num_excluidos = 0;

	

	excluir_id = new CriaArray(destino.length);

	

	for (i = 0 ; i < destino.length ; i++) 

	 if (destino.options[i].selected) 

	   {

		 origem.options[origem.length] = new Option(destino.options[i].text,

													  destino.options[i].value);													  

		 excluir_id[num_excluidos] = i;		 

		 num_excluidos++;

	   }

	   

	for (i = 0 ; i < num_excluidos ; i++) 

	 destino.options.remove(excluir_id[i]-i);

	 

	if ( num_excluidos > 0 )

      bublesort( origem );



}  



function moveDOTodos(origem, destino)

{

	for (var i = 0 ; i < destino.options.length ; i++) 

	 origem.options[origem.length] = new Option(destino.options[i].text,

  											    destino.options[i].value);

	limpalista( destino );

	

	bublesort( origem );



}  





function troca( lista , i, j)

{

	var aux1 = lista.options[i].value;

	var aux2 = lista.options[i].text;	

	lista.options[i].value = lista.options[j].value;

	lista.options[i].text  = lista.options[j].text;	

	lista.options[j].value = aux1;

	lista.options[j].text  = aux2;	

}

  



function bublesort( lista )

{

  for (var i = 0; i < lista.length; i++){

    for (var j = lista.length - 1; j > i; j--){

      if (lista.options[j].text < lista.options[i].text) 

	    troca( lista , i, j);

    }

  }

}



function isMsie()

{ 

  if ((navigator.userAgent.indexOf("MSIE") != "-1") && (navigator.userAgent.length > 1))

	return true;

  else

	return false;

}



function versionWarning()

{

	var msg = "It has been determined that you don't have Acrobat 5.0 on your machine \n";

	msg += "\n\t Click Ok to visit the Adobe web site for software update, or ";

	msg += "\n\t Cancel if you want to update Acrobat at a later time.";

	if (confirm(msg))

	{

		var url = "http://www.adobe.com/store/products/acrobat.html";

		windowprops = "height=500,width=500,location=yes, scrollbars=yes,menubars=yes,toolbars=yes,resizable=yes";

		window.open(url, "popupWnd", windowprops);

		//Below line opens in the same window

		//location.replace("http://www.adobe.com/store/products/acrobat.html");

	}

}



function getVersions()

{

	alert("Entrou na funcao getVersions");

	var version = 0;

	versionexists = false;		



	if (isMsie())

	{	//GetVersions() gets lists all plug-ins and their versions

		version = pdfObj.GetVersions();

		if (version.indexOf("5.0.0") != -1)

			version = 5.0;

	}

	else

	{   //check that Acrobat Netscape plugin is present

		if (navigator.plugins && navigator.plugins["Adobe Acrobat"].description != "")

		{

			version = navigator.plugins["Adobe Acrobat"].description; 

			var tmp = "Adobe Acrobat Plug-In Version ";

			var tmp2 = " for Netscape";

			var pos = tmp.length;

			var pos2 = version.indexOf(tmp2); 

			version = parseFloat(version.substring(pos, pos2)); 

		}

	}

	if (version < 5.0)

		versionexists =  false;

	else

		versionexists = true;

		

	return versionexists;

}



function virgula(objeto)

{

  objeto.value = objeto.value.replace(',', '.');

}

/*

ex: onKeyPress="aceita_num_letras(this);"

*/

function aceita_num_letras(field)

{

  var existe = 0;



  //Aceitar espaços vazios

  if (event.keyCode == 32)

    existe = 1;

  //Aceitar numeros

 	if ((event.keyCode > 47) && (event.keyCode < 58))

    existe = 1;

  //Aceitar letras maiusculas

 	if ((event.keyCode > 64) && (event.keyCode < 91))

    existe = 1

  //Aceitar letras minusculas

  if ((event.keyCode > 96) && (event.keyCode < 123))

    existe = 1;



  if (existe == 0)

    event.returnValue = false;

}

function aceita_especial(field)

{

	var existe = 0;

  //Aceitar espaços vazios

  if (event.keyCode == 32)

    existe = 1;	

  //Aceitar  

  if ((event.keyCode == 45) || // "-"

			(event.keyCode == 46) || // "."

		  (event.keyCode == 64) || // "@"

			(event.keyCode == 95))   // "_"

    existe = 1;	



  //Aceitar numeros

 	if ((event.keyCode > 47) && (event.keyCode < 58))

    existe = 1;

  //Aceitar letras maiusculas

 	if ((event.keyCode > 64) && (event.keyCode < 91))

    existe = 1

  //Aceitar letras minusculas

  if ((event.keyCode > 96) && (event.keyCode < 123))

    existe = 1;



		

  if (existe == 0)

    event.returnValue = false;	

}

/*

ex: onKeyPress="aceita_num(this);"

*/

function aceita_num(field)

{

  var existe = 0;

	

  //Aceitar numeros

 	if ((event.keyCode > 47) && (event.keyCode < 58))

    existe = 1;



  if (existe == 0)

    event.returnValue = false;		

}

/*

ex: onKeyPress="aceita_letras(this);"

*/

function aceita_letras(field)

{

  var existe = 0;



  //Aceitar espaços vazios

  if (event.keyCode == 32)

    existe = 1;

   //Aceitar letras maiusculas

 	if ((event.keyCode > 64) && (event.keyCode < 91))

    existe = 1

  //Aceitar letras minusculas

  if ((event.keyCode > 96) && (event.keyCode < 123))

    existe = 1;



  if (existe == 0)

    event.returnValue = false;

}



function keypresed()

{

 alert('Teclas desabilitadas');

 document.onkeydown=keypresed;

}



function formatCpfCgc(field)

{

  field.value = SoNumero(field.value);

	if (field.value.length == 11)

	{

	  //Formata o campo como CPF

		field.value = field.value.substr(0,3) + "." +

		              field.value.substr(3,3) + "." +  

									field.value.substr(6,3) + "-" +

									field.value.substr(9,2);		

	}

	else

	{

		if(field.value.length == 14)

		{

			//Formata o campo como CGC

  		field.value = field.value.substr(0,2) + "." +

		                field.value.substr(2,3) + "." +  

						  			field.value.substr(5,3) + "/" +

									  field.value.substr(8,4) + "-" +

										field.value.substr(12,2);					

		}

		else

  		if(field.value.length != 0)

  		{

        alert('Número incorreto!');

        field.focus();

      }

	}

}



function blockNumbers(e)

{

var key;

var keychar;

var reg;



if(window.event) {

  // for IE, e.keyCode or window.event.keyCode can be used

  key = e.keyCode;

}

else if(e.which) {

  // netscape

  key = e.which;

}

else {

  // no event, so pass through

  return true;

}



keychar = String.fromCharCode(key);

reg = /\d/;

// return !reg.test(keychar); ===> para tirar números é necessário tirar o exclamação (!)

        return reg.test(keychar);

}



/**

 * Adiciona método lpad() à classe String.

 * Preenche a String à esquerda com o caractere fornecido,

 * até que ela atinja o tamanho especificado.

 */

String.prototype.lpad = function(pSize, pCharPad)

{

	var str = this;

	var dif = pSize - str.length;

	var ch = String(pCharPad).charAt(0);

	for (; dif>0; dif--) str = ch + str;

	return (str);

} //String.lpad





/**

 * Adiciona método trim() à classe String.

 * Elimina brancos no início e fim da String.

 */

String.prototype.trim = function()

{

	return this.replace(/^\s*/, "").replace(/\s*$/, "");

} //String.trim

function Bloqueia_Caracteres(evt){   

      if (event.keyCode == 13){

	    return event.keyCode = 13;	 	  

	  } else{

        if (event.keyCode < 48 || event.keyCode > 57){   

           return event.keyCode = false;

        }   

	  }

}   

// checkdate sem mensagens
function CheckDateNoMessage(field)
{

  var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  var dateExists = true;
  var day = parseInt(field.value.substring(0,2),10);
  var month = parseInt(field.value.substring(3,5),10);
  var year = parseInt(field.value.substring(6,10),10);

	if (field.value != '')
	{
	  if (!day || !month || !year)
	  {
	    field.value = "";
	    field.focus();
			field.select();
	    return(false);
	  }

		if (year <= 1900)
		{
	    field.value = "";
	    field.focus();
			field.select();
	    return(false);
		}
	  if (year/4 == parseInt(year/4)) monthLength[1] = 29;
	  if (day > monthLength[month-1]) dateExists = false;
	  if (day < 1) dateExists = false;
	  if (month < 1 || month > 12) dateExists = false;

	  if (!dateExists){
        field.value = "";
	    field.focus();
	    field.select();
	    return(false);
	  }
	}
  return(true);
}

// checkdate sem mensagens
function CheckDateNoMessage(field)
{

  var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  var dateExists = true;
  var day = parseInt(field.value.substring(0,2),10);
  var month = parseInt(field.value.substring(3,5),10);
  var year = parseInt(field.value.substring(6,10),10);

	if (field.value != '')
	{
	  if (!day || !month || !year)
	  {
	    field.value = "";
	    field.focus();
			field.select();
	    return(false);
	  }

		if (year <= 1900)
		{
	    field.value = "";
	    field.focus();
			field.select();
	    return(false);
		}
	  if (year/4 == parseInt(year/4)) monthLength[1] = 29;
	  if (day > monthLength[month-1]) dateExists = false;
	  if (day < 1) dateExists = false;
	  if (month < 1 || month > 12) dateExists = false;

	  if (!dateExists){
        field.value = "";
	    field.focus();
	    field.select();
	    return(false);
	  }
	}
  return(true);
}


