// JavaScript Document
<!--

function validaCampoObrigatorio(form){
            var erro=0;
            var legenda;
            var obrigatorio;          
            for (i=0;i<form.length;i++){
                        obrigatorio = form[i].lang;
                        if (obrigatorio==1){
                                   if (form[i].value == ""){
                                               var nome = form[i].name;
                                               mudarCorCampo(form[i], '#66CCFF');
                                               legenda=document.getElementById(nome);
                                               legenda.style.color="#003366";
                                               erro++;
                                   }
                        }
            }
            if(erro>=1){
                        alert("Existe(m) " + erro + " campo(s) obrigatório(s) vazio(s)! ")
                        return false;
            } else
                        return true;
}
function mudarCorCampo(elemento, cor){
            elemento.style.backgroundColor=cor;
}

function Mascara(tipo, campo, teclaPress) {
        if (window.event)
        {
                var tecla = teclaPress.keyCode;
        } else {
                tecla = teclaPress.which;
        }
 
        var s = new String(campo.value);
        // Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
        s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');
 
        tam = s.length + 1;
 
        if ( tecla != 9 && tecla != 8 ) {
                switch (tipo)
                {
                case 'CPF' :
                        if (tam > 3 && tam < 7)
                                campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
                        if (tam >= 7 && tam < 10)
                                campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
                        if (tam >= 10 && tam < 12)
                                campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
                break;
				
				case 'RG' :
                        if (tam > 2 && tam < 6)
                                campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
                        if (tam >= 6 && tam < 9)
                                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
                        if (tam >= 9 && tam < 11)
                                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '-' + s.substr(8,tam-8);
                break;
 
                case 'CNPJ' :
 
                        if (tam > 2 && tam < 6)
                                campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
                        if (tam >= 6 && tam < 9)
                                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
                        if (tam >= 9 && tam < 13)
                                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,tam-8);
                        if (tam >= 13 && tam < 15)
                                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,4)+ '-' + s.substr(12,tam-12);
                break;
 
                case 'TEL' :
                        if (tam > 2 && tam < 4)
                                campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
                        if (tam >= 7 && tam < 11)
                                campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
                break;
 
                case 'DATA' :
                        if (tam > 2 && tam < 4)
                                campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
                        if (tam > 4 && tam < 11)
                                campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
                break;
                
                case 'CEP' :
                        if (tam > 5 && tam < 7)
                                campo.value = s.substr(0,5) + '-' + s.substr(5, tam);
                break;
                }
        }
}


function digitos(event){
        if (window.event) {
                // IE
                key = event.keyCode;
        } else if ( event.which ) {
                // netscape
                key = event.which;
        }
        if ( key != 8 || key != 13 || key < 48 || key > 57 )
                return ( ( ( key > 47 ) && ( key < 58 ) ) || ( key == 8 ) || ( key == 13 ) );
        return true;
}

function checkLength()
 {
  maxnum = 300; // The maximum number of characters.
  yrTxt = form.conheceu;
  charleft = form.charsLeft;
  charleft.value = maxnum - yrTxt.value.length;
  if (charleft.value <= 0)
   {
    charleft.value = "max";
   }
  if (yrTxt.value.length > maxnum)
   {
    yrTxt.value = yrTxt.value.substring(0,maxnum-1);
   }
 }
 
 function checkLength2()
 {
  maxnum = 200; // The maximum number of characters.
  yrTxt = form.animais_quais;
  charleft2 = form.charsLeft2;
  charleft2.value = maxnum - yrTxt.value.length;
  if (charleft2.value <= 0)
   {
    charleft2.value = "max";
   }
  if (yrTxt.value.length > maxnum)
   {
    yrTxt.value = yrTxt.value.substring(0,maxnum-1);
   }
 }
 
 function checkLength3()
 {
  maxnum = 200; // The maximum number of characters.
  yrTxt = form.disponibilidade;
  charleft3 = form.charsLeft3;
  charleft3.value = maxnum - yrTxt.value.length;
  if (charleft3.value <= 0)
   {
    charleft3.value = "max";
   }
  if (yrTxt.value.length > maxnum)
   {
    yrTxt.value = yrTxt.value.substring(0,maxnum-1);
   }
 }
 
 function checkLength4()
 {
  maxnum = 300; // The maximum number of characters.
  yrTxt = form.programas;
  charleft4 = form.charsLeft4;
  charleft4.value = maxnum - yrTxt.value.length;
  if (charleft4.value <= 0)
   {
    charleft4.value = "max";
   }
  if (yrTxt.value.length > maxnum)
   {
    yrTxt.value = yrTxt.value.substring(0,maxnum-1);
   }
 }

 function checkLength5()
 {
  maxnum = 300; // The maximum number of characters.
  yrTxt = form.motivo;
  charleft5 = form.charsLeft5;
  charleft5.value = maxnum - yrTxt.value.length;
  if (charleft5.value <= 0)
   {
    charleft5.value = "max";
   }
  if (yrTxt.value.length > maxnum)
   {
    yrTxt.value = yrTxt.value.substring(0,maxnum-1);
   }
 }
 
  function checkLength6()
 {
  maxnum = 300; // The maximum number of characters.
  yrTxt = form.forma;
  charleft6 = form.charsLeft6;
  charleft6.value = maxnum - yrTxt.value.length;
  if (charleft6.value <= 0)
   {
    charleft6.value = "max";
   }
  if (yrTxt.value.length > maxnum)
   {
    yrTxt.value = yrTxt.value.substring(0,maxnum-1);
   }
 }


function Limpar(valor, validos) {
// retira caracteres invalidos da string
var result = "";
var aux;
for (var i=0; i < valor.length; i++) {
aux = validos.indexOf(valor.substring(i, i+1));
if (aux>=0) {
result += aux;
}
}
return result;
}


function Formata(campo,tammax,teclapres,decimal) {
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,"0123456789");
tam = vr.length;
dec=decimal

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 <= dec )
{ campo.value = vr ; }

if ( (tam > dec) && (tam <= 5) ){
campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 6) && (tam <= 8) ){
campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
} 

}

function abreJanela(url,nome,pars) { //v2.0
  window.open(url,nome,pars);
}

function abre_janela(width, height, nome, scrollbar) {
var top; var left;
top = ( (screen.height/2) - (height/2) )
left = ( (screen.width/2) - (width/2) )
window.open('',nome,'width='+width+',height='+height+',scrollbars='+scrollbar+',toolbar=no,location=no,status=no,menubar=no,resizable=no,left='+left+',top='+top);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function fechar(){
	window.close();
}

function pulaCasa(vl,qtd,prox){
	var tamanho=vl.length;
	var limite=qtd;
	//alert(tamanho+'#'+qtd+'#'+prox);
		if(tamanho==limite){
			$(prox).focus();
		}
}

function resizeWindow(largura,altura){
	resizeTo(largura,altura);
	window.moveTo(250,250); 
}


function somenteNumero(e,id_element){
	var key
	if(window.event) {
		key = e.keyCode; 
		if (( key < 47 )||( key > 58 )) {
				window.event.returnValue = null; 
				return;
		}		
	}
	else if (e.which) {
			key = e.which;
			if (( key < 47 )||( key > 58 )) {
					e.preventDefault();
					return ; 
			}		
	}

}
var boolClicado = false;
-->
