// oninputkeyup="mascaraData(this)"
function mascaraData(campoData){
    var data = campoData.value;
    
    if(data.length > 10) {
    	campoData.value = data.substring(0, 10);
    	return false;
    }
    if (data.length == 2){
        data = data + '/';
        campoData.value = data;
        return true;              
    }
    if (data.length == 5){
        data = data + '/';
        campoData.value = data;
        return true;
    }
    return false;
}

//oninputkeypress="return onlyNumber2(event)"
function onlyNumber( evt) {
	
	 var charCode = (evt.which) ? evt.which : event.keyCode
	         if (charCode > 31 && (charCode < 48 || charCode > 57))
	        	 if (charCode != 44 )
	            return false;

	         return true;
}

function maxLenght(evt, len, obj) {
	var ascii = (evt.which) ? evt.which : evt.keyCode;
	if(ascii == 8 || ascii == 46 || ascii == 37|| ascii == 39 || ascii == 38 || ascii == 40) {
		return true;
	}
	//alert(ascii);
	if(obj.value.length >= len) {
		alert("Excedeu o limite de "+len+" caractéres.");
		obj.value = obj.value.substring(0,3999);
		return false;
	}
	return true;
}

function doHotSite(url, width, height) {
	var x_tam = width;
	var y_tam= height;
		x_tam = x_tam + 20;
		y_tam = y_tam + 60;
		x_pos = (screen.availWidth-x_tam)/2;
		y_pos = (screen.availHeight-y_tam)/2;
	window.open(url , "HotSite" , "status , scrollbars=no ,width="+width+", height="+height+" , top="+y_pos+" , left="+x_pos); 
}

//Função que formata com uma máscara o texto digitado em um INPUT TYPE="TEXT"
//Recebe:
//- src = objeto com a referência para o INPUT que está sendo formatado
//- mask = string contendo a máscara de formatação. Ex.: "00/00/0000"
//Obs.: deve ser utilizada no evento onkeypress do campo
function formatar(evt, src, mask) {
	
var i = src.value.length;
var saida = mask.substring(i,i+1);
var ascii = (evt.which) ? evt.which : evt.keyCode;
if(ascii == 8 || ascii == 46  || ascii == 9) {
	return true;
}

if(i >= mask.length) {
	return false;
}

	if (saida == "A") {
	   if ((ascii >=97) && (ascii <= 122)) { ascii -= 32; }
	   else if(!(ascii >=65) && (ascii <= 90))
	   { return  false; }
	} else if (saida == "0") {
	   if ((ascii >= 48) && (ascii <= 57)) { return true; }
	   else { return false; }
	} else if (saida == "#") {
	   return true ;
	} else {
	   src.value += saida;
	   i += 1;
	   saida = mask.substring(i,i+1);
	   if (saida == "A") {
	       if ((ascii >=97) && (ascii <= 122)) { ascii -= 32; }
	       else { return false; }
	   } else if (saida == "0") {
	       if ((ascii >= 48) && (ascii <= 57)) { return true ; }
	       else { return false; }
	   } else { evt.returnValue=false; }
	}
	return true;
}

function validaCTPS() {
	var ctps = document.getElementById('form1:ctps').value;
	var ctps_serie = document.getElementById('form1:ctps_serie').value;
	if(ctps.length > 0 ) {
			if(ctps_serie.length <= 0) {
					alert("O Número de Série da Carteira de Trabalho é obrigatório, quando preenchido o Número da Carteira de Trabalho.");
					document.getElementById('form1:ctps_serie').focus();
			}
	}
	
}