function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
function BarraHiRes() {
	var res = screen.availWidth;
	if (res <= 800) {
		if (navigator.appName != 'Netscape') {
			document.all.BarraHiRes.style.display = "none";
		} else
			if (parseInt(navigator.appVersion) >= 5) {
				document.getElementById('BarraHiRes').style.display = "none";
			}
	}
}

function ValidationSummaryOnSubmit() {
    if (typeof(Page_ValidationSummaries) == "undefined") 
        return;
    var summary, sums, s;
    for (sums = 0; sums < Page_ValidationSummaries.length; sums++) {
        summary = Page_ValidationSummaries[sums];
        summary.style.display = "none";
        if (!Page_IsValid) {
            if (summary.showsummary != "False") {
                summary.style.display = "";
                if (typeof(summary.displaymode) != "string") {
                    summary.displaymode = "BulletList";
                }
                switch (summary.displaymode) {
                    case "List":
                        headerSep = "<br>";
                        first = "";
                        pre = "";
                        post = "<br>";
                        final = "";
                        break;
                    case "BulletList":
                    default: 
                        headerSep = "";
                        first = "<ul>";
                        pre = "<li>--";
                        post = "</li>";
                        final = "</ul>";
                        break;
                    case "SingleParagraph":
                        headerSep = " ";
                        first = "";
                        pre = "";
                        post = " ";
                        final = "<br>";
                        break;
                }
                s = "";

                if (typeof(summary.headertext) == "string") {
                    s += summary.headertext + headerSep;
                }
                s += first;
                for (i=0; i<Page_Validators.length; i++) {
                    if (!Page_Validators[i].isvalid && typeof(Page_Validators[i].errormessage) == "string") {
                        s += pre + Page_Validators[i].errormessage + post;
                    }
                }   
                s += final;
                summary.innerHTML = s; 
                window.scrollTo(0,0);
            }
            if (summary.showmessagebox == "True") {
                s = "";
                if (typeof(summary.headertext) == "string") {
                    s += summary.headertext + "<BR>";
                }
                for (i=0; i<Page_Validators.length; i++) {
                    if (!Page_Validators[i].isvalid && typeof(Page_Validators[i].errormessage) == "string") {
                        switch (summary.displaymode) {
                            case "List":
                                s += Page_Validators[i].errormessage + "<BR>";
                                break;
                            case "BulletList":
                            default: 
                                s += "  - " + Page_Validators[i].errormessage + "<BR>";
                                break;
                            case "SingleParagraph":
                                s += Page_Validators[i].errormessage + " ";
                                break;
                        }
                    }
                }
                span = document.createElement("SPAN");
                span.innerHTML = s;
                s = span.innerText;
                alert(s);
            }
        }
    }
}


function IniObjJScript(ParObjeto, ParValor)
// Lógica de apresentação de conteúdo de de BD em tela:
// Lê-se do BD para a Variável ASP e daí para a variável de tela.
// Daí a necessidade de se inicializar os campos de tela individualmente.
{
   ParObjeto.value = ParValor;
}

//Recupera o indice do objeto corrente do formulário
function getIndex(what,which) {
	for (var i=0;i < what.elements.length;i++)
		if (what.elements[i].name == which)
			return i;
	return -1;
}


function FormataData(pForm, pCampo,pTeclaPres) {
	var wTecla = pTeclaPres.keyCode;
	wVr = pForm[pCampo].value;
	wVr = wVr.replace( ".", "" );
	wVr = wVr.replace( "/", "" );
	wVr = wVr.replace( "/", "" );

	wTam = wVr.length + 1;

	if ( wTecla != 9 && wTecla != 8 ){
		if (( wTam > 2 && wTam < 5 ) && (wTecla != 111))
			pForm[pCampo].value = wVr.substr( 0, wTam - 2  ) + '/' + wVr.substr( wTam - 2, wTam );
		if (( wTam >= 5 && wTam <= 10 ) && (wTecla != 111))
			pForm[pCampo].value = wVr.substr( 0, 2 ) + '/' + wVr.substr( 2, 2 ) + '/' + wVr.substr( 4, 4 ); 
	}			
}	

function VerificaData(pForm, pCampo, pDtProibida) {
   var wHoje = new Date();
   var wAUX, wAUX2, wDataValida;
   
   wAUX2 = "";
   wAUX = pForm[pCampo].value;

   if (wAUX == "") {
      return false;
   }	
   if (pDtProibida != "") {
      wAUX2 = pDtProibida;
      var wFrescuraSIAPI = new Date(wAUX2.substr(6, 4), wAUX2.substr(3,2) - 1, wAUX2.substr(0,2))
   }
   if (wAUX == "" || wAUX.length < 10) {
      alert("Tamanho de Data Incorreto. Digite a data no formato DD/MM/AAAA.");
//      pForm[pCampo].value = "";
	  pForm[pCampo].focus();  
      return false;
   }   
   wDataValida = SbrebowsDataSdruxula(wAUX.substr(0,2),wAUX.substr(3,2), wAUX.substr(6, 4));
   if (!wDataValida) {
      alert("Data Inválida.");
//      pForm[pCampo].value = "";
	  pForm[pCampo].focus();  
      return false;
   } else {
	   var wDtRef = new Date(wAUX.substr(6, 4), wAUX.substr(3,2) - 1, wAUX.substr(0,2))
	   if (Date.parse(wDtRef) >= Date.parse(wHoje)) {
	      alert("Data não pode ser maior que a Data Atual. Redigite-a");
//		  pForm[pCampo].value = "";
		  pForm[pCampo].focus();
		  return false;
	   } else {
	       if (wAUX2 != "" && Date.parse(wDtRef) > Date.parse(wFrescuraSIAPI)) {
  	          alert("Data não pode ser maior que " + pDtProibida + ". Redigite-a");
//		      pForm[pCampo].value = "";
		      pForm[pCampo].focus();
		      return false;		   
		   }
	   }
	   return true;
   }
}

function SbrebowsDataSdruxula(pDia, pMes, pAno) {
  var v_dia, v_mes, v_ano;

  v_dia = pDia;
  v_mes = pMes;
  v_ano = pAno;
			
  if (((v_ano < 1900) || (v_ano > 2079)) && (v_ano.length != 0)) {
	return(false);
  }
  if (v_dia > 31) {
	return(false);
  }
  if (v_mes > 12) {
	return(false);
  }
  if (v_dia == "31")  {
	if ((v_mes == "04") || (v_mes == "06") || (v_mes == "09") || (v_mes == "11")) {
       return(false);
	}
  }
  if (v_mes == "02") {
	if (!(v_ano%4))  {
  	  if (v_dia > 29) {
		return(false);
  	  }
	} else if (v_dia > 28) {
  	    return(false);
	}
  }
	
  //o -if- abaixo testa se algum campo foi preenchido e outro deixado em branco deixando a data incompleta

  if (((v_dia != "") || (v_mes != "") || (v_ano != "")) && ((v_dia == "") || (v_mes == "") || (v_ano == ""))) {
 	return(false);
  }
	
  return(true);
}


// Desabilita Objetos JScript de Tela de acordo com o resultado da Expressão Lógica
// passada como parâmetro 
function Desabilita(ParObjeto, ParExprLogica)
{
   ParObjeto.disabled = eval(ParExprLogica);
}

// verifica se campo esta vazio
function TestaCampo( campo, nome )
{
  	if ( campo.value=="" || campo.length==0 )
	{
      alert("É necessário informar o campo '" + nome + "' !");
      campo.focus();
      return(false);
	}
	else
       return(true);
}

//-------------------------------
function ValidaTitulo(Titulo) {
	var  Soma=0;
	var i = 0;
	var j = 0;
	var DV1c = "";
	var DV2c = "";
	var Sequencial = Titulo.substr(0,9);
	var UF = Titulo.substr(9, 2);
	var DV1 = Titulo.charAt(11);
	var DV2 = Titulo.charAt(12);
	var controle = "";
	var ContIni = 2;
	var ContFim = 10;
	for (j = 1; j <= 2; j++)
	{
		Soma = 0;
		for (i = ContIni; i<= ContFim; i++)
		{
			Soma = Soma + (Sequencial.charAt(i-2) * (ContFim + 2 - i));
       }
		Digito = Soma % 11;
		if ((UF == "01") || (UF == "02")) 
		{
			if (Digito == 1) 
				Digito = 0;
			else 	if  (Digito == 0) 
						Digito = 1;
					else
						Digito = 11 - Digito;
		}
		else {
			if ((Digito == 1) || (Digito == 0))
				Digito = 0;
			else
				Digito = 11 - Digito;
		}
		if (j == 1)
			DV1c = Digito;
		else
			DV2c = Digito;

		ContFim = 4;
		controle = controle + Digito;
		Sequencial = UF + controle; 
	} 
	if ((DV1 != DV1c) || (DV2 != DV2c)) 
		return false;
	else
		return true;
}

//-------------------------------
function ValidaCPF(rcpf1,rcpf2,c) {
  d1 = 0;
  for (i=0;i<9;i++) 
    d1 += rcpf1.charAt(i)*(10-i);
  d1 = 11 - (d1 % 11);
  if (d1>9) d1 = 0;
  
  if (rcpf2.charAt(0) != d1) 
    return false;
  
  d1 *= 2;
  for (i=0;i<9;i++) 
    d1 += rcpf1.charAt(i)*(11-i);
  d1 = 11 - (d1 % 11);
  if (d1>9) d1 = 0;
  
  if (rcpf2.charAt(1) != d1) 
    return false;
  return true;
}

//-------------------------------
function isDigit (c){   
   return ((c >= "0") && (c <= "9"))
}  

//-------------------------------
function isInteger (s) {
    var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return false;
     
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    return true;
}

//-------------------------------
function isEmpty(s){
    return ((s == null) || (s.length == 0))
}

//-------------------------------
// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
// 
// isIntegerInRange = true se s &eacute; inteiro dentro dos limites, inclusive
// 
// emptyOK se for opcional deve ser true
function isIntegerInRange (s, a, b){
   if (isEmpty(s)) return false;
    if (!isInteger(s)) return false;
    var num = (s);
    
    return ((num >= a) && (num <= b));
}
//-------------------------------
function isMes (s){
   if (isEmpty(s)) return false;
   return isIntegerInRange (s, 1, 12);
}
//-------------------------------
function isDia (s) {
    if (isEmpty(s)) return false;
    return isIntegerInRange (s, 1, 31);
}
//-------------------------------
function isAno (s) {
    if (isEmpty(s)) return false;
    if (!isInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}
//-------------------------------
function diasInFevereiro (ano){
    return (  ((ano % 4 == 0) && ( (!(ano % 100 == 0)) || (ano % 400 == 0) ) ) ? 29 : 28 );
}

//-------------------------------
function ValidaData (dia, mes, ano, nome, vazia ) {
	
  if (isEmpty(ano.value) && isEmpty(mes.value) && isEmpty(dia.value)){
     if ( vazia ) return true;
     alert("O campo '" + nome + "' deve ser informado.");
     dia.focus();
     return false;
  }
  if (!isAno(ano.value)) 
  { alert("Ano inválido no campo '" + nome + "'."); ano.focus(); return false; }
  if (!isMes(mes.value)) 
  { alert("Mês inválido no campo '" + nome + "'."); mes.focus(); return false; }
  if (!isDia(dia.value)) 
  { alert("Dia inválido no campo '" + nome + "'."); dia.focus(); return false; }
  
  var intAno = parseInt(ano.value);
  var intMes = parseInt(mes.value);
  var intDia = parseInt(dia.value);
  dias = new Array(13);
  dias[1] = 31;
  dias[2] = 29;   // deve ser verificado o caso de anos bissextos
  dias[3] = 31;
  dias[4] = 30;
  dias[5] = 31;
  dias[6] = 30;
  dias[7] = 31;
  dias[8] = 31;
  dias[9] = 30;
  dias[10] = 31;
  dias[11] = 30;
  dias[12] = 31;
  if (intDia > dias[intMes]){ 
     alert("Dia inválido no campo '" + nome + "'"); 
	 dia.focus(); 
	 return false; 
  }
  if ((intMes == 2) && (intDia > diasInFevereiro(intAno))){ 
     alert("Dia inválido no campo '" + nome + "'"); 
	 dia.focus(); 
	 return false; 
  }
  if (intAno < 1000)
  {
     alert("O Ano deve ter 4 digitos: '" + nome + "'"); 
	 ano.focus(); 
	 return false; 
  }	 
  return true;
}

//-------------------------------
function ValidaHora( hora, minutos, nome ){
   if ( hora.value<0 || hora.value>23 ){
     alert("Hora inválida no campo '" + nome + "'"); 
	 hora.focus(); 
	 return false; 
   }
   if ( minutos.value<0 || minutos.value>59 ){
     alert("Minutos inválidos no campo '" + nome + "'"); 
	 minutos.focus(); 
	 return false; 
   }
   return true;
}

//-------------------------------
function ValidaInteiro( n, minimo, maximo, nome ){
    if ( !isInteger(n.value) ){
       alert("Valor inválido no campo '" + nome + "'.");
	   n.focus();
	   return false;
    }
    if ( n.value<minimo || n.value>maximo ){
       alert("O valor do campo '" + nome + "' deve estar entre " + minimo + " e " + maximo + ".");
	   n.focus();
	   return false;
	}
    return true;
}


//-------------------------------
function ValidaSexoMFJ( s, nome ){
  if ( s.value!="M" && s.value!="F" && s.value!="J" )
  {
     alert("Valor incorreto no campo '" + nome + "'. Use M(masculino), F(feminino) ou J(jurídico).");
     s.focus();
	 return false;
  }
  return true;
}

//-------------------------------
function ValidaSexoMF( s, nome ){
  if ( s.value!="M" && s.value!="F" )
  {
     alert("Valor incorreto no campo '" + nome + "'. Use M(masculino) ou F(feminino).");
     s.focus();
	 return false;
  }
  return true;
}

//-------------------------------
function ValidaInt( campo, nome ){
  if ( !isInteger(campo.value) )
  {
     alert("Valor inválido no campo '" + nome + "'. Digite apenas números inteiros.");
     campo.focus();
	 return false;
  }
  return true;
}


//-------------------------------
function ValidaOpcnInteiro ( Campo, Nome, Vazia ){
  if ( isEmpty(Campo.Value) ){
     if ( Vazia ) return true;
	 alert("O campo '" + Nome + "' deve ser informado.");
	 Campo.focus();
	 return false;
  }
  if ( !isInteger(Campo.value) )
  {
     alert("Valor inválido no campo '" + Nome + "'. Digite apenas números inteiros.");
     Campo.focus();
	 return false;
  }
}

//-------------------------------
function ValidaReal( campo, nome ){
var s,m,i,c
s=new String(campo.value);
m=new String("");
for(i=0;i<s.length;i++){
   c=s.charAt(i);
   if ( c=="," ) 
      m=m+".";
   else
   if ( c!="." )
      m=m+c;
}

  if ( isNaN(Number(m)) )
  {
     alert("Valor inválido no campo '" + nome + "'.");
     campo.focus();
	 return false;
  }
  return true;
}

//validar e-mail
function ValidaEmail()
{
	if ( (window.event.keyCode>=65) && (window.event.keyCode<=90) ) //letras maiúsculas
		{
			window.event.keyCode=window.event.keyCode+32;  //tranforma letras maiúsculas em minúsculas
			return(true);
		}
	else
		{
			if ( ((window.event.keyCode>=97) && (window.event.keyCode<=122)) //letras minúsculas
				 || ((window.event.keyCode>=48) && (window.event.keyCode<=57))  //números
				 || (window.event.keyCode==46)   //ponto
				 || (window.event.keyCode==64)   //arroba
				 || (window.event.keyCode==95) ) //underline
				 
				{
					return(true);
				}
			else
				{
					window.event.keyCode=0;
					return(false);				
				}
		}
}


//validar UserID
function ValidaUserID()
{
	if ( (window.event.keyCode>=65) && (window.event.keyCode<=90) ) //letras maiúsculas
		{
			//window.event.keyCode=window.event.keyCode+32;  //tranforma letras maiúsculas em minúsculas
			return(true);
		}
	else
		{
			if ( ((window.event.keyCode>=97) && (window.event.keyCode<=122)) //letras minúsculas
				 || ((window.event.keyCode>=48) && (window.event.keyCode<=57))  //números
				 || (window.event.keyCode==46)   //ponto
				 || (window.event.keyCode==95) ) //underline
				{
					return(true);
				}
			else
				{
					window.event.keyCode=0;
					return(false);				
				}
		}
}


//função: SomNumOuVirgula
//deve ser colocada no evento onkeypress de um objeto "input", para que
//o usuário digite apenas números ou vírgula
function SomNumOuVirgula()
{
  if ( ((window.event.keyCode>=48) && (window.event.keyCode<=57)) || (window.event.keyCode==44) )
     return(true)
  else
  {
     window.event.keyCode=0;
     return(false);
  }
}

//função: SomNum
//usada no evento "onkeypress" de um objeto "input", permite a digitação apenas de números
function SoNumeros()
{
	if ( ((window.event.keyCode>=48) && (window.event.keyCode<=57)) || (window.event.keyCode==13) )
		return(true)
	else
	{
		window.event.keyCode=0;
		return(false);
	}
}

function SemAspas()
{
	//39: aspas simples    34: aspas duplas
	if ( (window.event.keyCode == 34) || (window.event.keyCode == 39) )
	{
		window.event.keyCode=0;
		return(false);
	}
}

function TrataTecla( vetor )
{
	Tam = vetor.length;
	for (i = 0; i <= Tam; i++)
	{
		if (  window.event.keyCode == vetor[i] )
		{
			window.event.keyCode = 0;
			return(false);
		}
	}
	return(true);
}

function ForcaTecla( vetor )
{
	Tam = vetor.length;
	MesmaTecla=false;
	for (i = 0; i < Tam; i++)
	{
		if (  window.event.keyCode == vetor[i] )
		{
		    MesmaTecla=true;
		}
	}
	if ( MesmaTecla==false ) {
    	window.event.keyCode = 0;
		return(false);
	}
	return(true);
}



function TudoIgual(field) {
  var str = field.value, primeiro='';
  for(i = 0; i < str.length; i++)
    if (str.charAt(i)>='0' && str.charAt(i)<='9')
      if (primeiro=='') primeiro = str.charAt(i);
      else if (str.charAt(i) != primeiro) return 0;
  return 1;
}

function CriaArray(n) {
  this.length=n;
  for (var i=1; i<=n; i++) this[i]=0;
  return this;
}

function Str2Int(str) {
  var value=0, i=0, digit=0;
  for(i=0; i < str.length; i++) {
    if (str.charAt(i)=='0') digit=0;
    if (str.charAt(i)=='1') digit=1;
    if (str.charAt(i)=='2') digit=2;
    if (str.charAt(i)=='3') digit=3;
    if (str.charAt(i)=='4') digit=4;
    if (str.charAt(i)=='5') digit=5;
    if (str.charAt(i)=='6') digit=6;
    if (str.charAt(i)=='7') digit=7;
    if (str.charAt(i)=='8') digit=8;
    if (str.charAt(i)=='9') digit=9;
    value=value+digit*Math.pow(10,str.length-i-1);
  }
  return value;
}

function Verifica_CPF_CGC(field) {

  var cpf='', cgc='', digito='', digitoc='', temp='', k=0; i=0, j=0, soma=0, mt=0, dg='';
 if (field.value=='') return; else cpf = field.value;

  if (((cpf.length > 13) && (cpf.length < 19)) && (cpf.substring(3,4) !='.')){
  if (cpf.length == 18) {
     temp = cpf.substring(0,2) + cpf.substring(3,6) + cpf.substring(7,10) + cpf.substring(11,15) + cpf.substring(16,18);
  }
  if (cpf.length == 16) {
     temp = cpf.substring(0,2) + cpf.substring(2,5) + cpf.substring(5,8) + cpf.substring(9,13) + cpf.substring(14,16);
  }
  if (cpf.length == 15 && cpf.substring(12,13) == '-') {
     temp = cpf.substring(0,2) + cpf.substring(2,5) + cpf.substring(5,8) + cpf.substring(8,12) + cpf.substring(13,15);
  }
  if (cpf.length == 15 && cpf.substring(8,9) == '/') {
     temp = cpf.substring(0,2) + cpf.substring(2,5) + cpf.substring(5,8) + cpf.substring(9,13) + cpf.substring(13,15);
  }
  if (cpf.length == 14) {
     temp = cpf.substring(0,2) + cpf.substring(2,5) + cpf.substring(5,8) + cpf.substring(8,12) + cpf.substring(12,14);
  }
	  cgc = temp.substring(0,12);
	  digito = temp.substring(12,14);
   	  mult = '543298765432';
	  for (j = 1; j <= 2; j++) {
	    soma = 0;
	    for (i = 0; i <= 11; i++) {
	      k = i + 1;
	      soma += parseInt((cgc.substring(i,k)) * (mult.substring(i,k)));
	    }

	      if (j == 2){
			soma = soma + (2 * digitoc);
	      }
	      		digitoc = ((soma * 10) % 11);
	      if (digitoc == 10){
			digitoc = 0;
	      }
	     dg +=digitoc;
      	     mult = '654329876543';
	  }
	  //if (dg != digito || TudoIgual(field)) {
	  if (dg != digito) {	  
	    alert('CPF incorreto !');
	    field.value = '';
	    field.focus();
	    return;
	    } 
	  else {
	    field.value=temp.substring(0,2)+'.'+temp.substring(2,5)+'.'+temp.substring(5,8)+'/'+temp.substring(8,12)+'-'+temp.substring(12,14);

	    return true;
	  }

  }
  else {
  if (cpf.length < 11) {
	alert( 'Dados incorretos. Verifique!');
	field.value = '';
	field.focus();
	return false;
  }

  if (cpf.length == 11) {
     temp = cpf.substring(0,3) + cpf.substring(3,6) + cpf.substring(6,9) + cpf.substring(9,11);
  }
  if (cpf.length == 12) {
     temp = cpf.substring(0,3) + cpf.substring(3,6) + cpf.substring(6,9) + cpf.substring(10,12);
  } 
  if (cpf.length == 14) {
     temp = cpf.substring(0,3) + cpf.substring(4,7) + cpf.substring(8,11) + cpf.substring(12,15);
  }
	  cpf = temp.substring(0,9);
	  digito = temp.substring(9,11);
	  for (j = 1; j <= 2; j++) {
	    soma = 0;
	    mt = 2;
	    for (i = 8 + j; i >= 1; i--) {
	      soma += parseInt(cpf.charAt(i-1),10) * mt;
	      mt++;
	    }
	    dg = 11 - (soma % 11);
	    if (dg > 9) {dg = 0};
	    cpf += dg;
	  }

	  //if (digito != cpf.substring(9,11) || TudoIgual(field)) {
	  if (digito != cpf.substring(9,11)) {	  
	    alert('CPF incorreto !');
	    field.value = '';
	    field.focus();
	    return true;
	    } 
	  else {
	    field.value=cpf.substring(0,3)+'.'+cpf.substring(3,6)+'.'+cpf.substring(6,9)+'-'+cpf.substring(9,11);
	    return true;
	  }
  } // fim if (cpf.length < 15)

return true;
}

function ChecaCartao(field) {

	var cartao = field.value;

  	if (cartao.length > 19 ) {
		alert('O Número do Cartão é inválido');
    		field.focus();
		return (false);
        }

	  	sum = 0; mul = 1;
		l = cartao.length;
	for (i = 0; i < l; i++) {
		digit = cartao.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 {
			alert('O Número do Cartão é inválido');
    			field.focus();
			return (false);
		}

}


function Virg2Ponto( campo ){
var s,m,i,c
s=new String(campo);
m=new String("");
for(i=0;i<s.length;i++){
   c=s.charAt(i);
   if ( c=="," ) 
      m=m+".";
   else
   if ( c=="." )
      m=m+",";
   else
      m=m+c;
}
return(m);
}

function Ponto2Virg( campo ){
var s,m,i,c
s=new String(campo);
m=new String("");
//alert("["+s.toUpperCase()+"]");
for(i=0;i<s.length;i++){
   c=s.charAt(i);
   if ( c=="." ) 
      m=m+",";
   else
   if ( c=="," )
      m=m+".";
   else
      m=m+c;
}
m=FormataDecimal(m);
return(m);
}

function FormataDecimal(campo) // Formata campos para duas casas decimais
{
   var StrCampo, StrDecimal, IntTempTam, IntCampoTam, IntPosVirg;
   StrCampo = new String(campo);
   IntCampoTam = StrCampo.length;
   IntPosVirg = StrCampo.indexOf(",");
   if (IntPosVirg > 0)
   {
      StrDecimal = StrCampo.slice(IntPosVirg+1, IntCampoTam);
      IntTempTam = StrDecimal.length;
   }
   else  
      IntTempTam = 0;
	  
   if (IntTempTam == 0)
   {
      StrCampo = StrCampo + ",00";
   }
   if (IntTempTam == 1)
   {
      StrCampo = StrCampo + "0";
   }
   if (IntTempTam > 2)
   {
      StrCampo = StrCampo.slice(0, IntPosVirg+3);
   }
   return(StrCampo);
}

function isReal( campo ){
var s,m,i,c
s=new String(campo.value);
m=new String("");
for(i=0;i<s.length;i++){
   c=s.charAt(i);
   if ( c=="," ) 
      m=m+".";
   else
   if ( c!="." )
      m=m+c;
}

  if ( isNaN(Number(m)) )
  {
     //alert("Valor inválido no campo '" + nome + "'.");
     campo.focus();
	 return false;
  }
  return true;
}

// Compara duas datas e retorna:
// -1 ->  se data1<data2
//  0 ->  se data1=data2
//  1 ->  se data1>data2
function ComparaDatas( dia1, mes1, ano1, dia2, mes2, ano2 ){
  var data1 = new Date(ano1,mes1,dia1)
  var data2 = new Date(ano2,mes2,dia2)
  
  var tm1=data1.valueOf();
  var tm2=data2.valueOf();
  if ( tm1<tm2 )  return(-1);
  if ( tm1==tm2 ) return(0);
  if ( tm1>tm2 )  return(1);
}

// Retira espaços no inicio e fim de uma string
function trim( s ){
   var m = new String( s );
   var i=0;

   while ( m.charCodeAt(0)==32 ) m=m.substr(1,m.length-1);           // retira espacos no inicio
   while ( m.charCodeAt(m.length-1)==32 ) m=m.substr(0,m.length-1);  // retira espacos no fim
   return(m);
}

function SoMaiuscula(campo)
{
	campo.value=campo.value.toUpperCase();
	return(campo);
}

function SoMinuscula(campo)
{
	campo.value=campo.value.toLowerCase();
	return(campo);
}

function FormataCEP(field)
{
	var cep='';
	if (field.value=='') return; else cep = field.value;

	if (cep.length != 8) {	  
		alert('CEP incorreto !');
		field.value = '';
		field.focus();
		return true;
		} 
	else {
		field.value=cep.substring(0,2)+'.'+cep.substring(2,5)+'-'+cep.substring(5,8);
		return true;
	}
}