// Formata o campo de acordo com a máscara informada.
function formatar(event, src, mask) {
var i = src.value.length;
var saida = mask.substring(i,i+1);
var ascii = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

if (saida == "A") {
    if ((ascii >=97) && (ascii <= 122)) {
		event.keyCode -= 32;
	}else {
		return false;
	}
} else if (saida == "0") {
    if ((ascii >= 48) && (ascii <= 57)) {
		return true;
	}else{
		return false;
	}
} else if (saida == "#") {
        return;
} else {
        src.value += saida;
        i += 1
        saida = mask.substring(i,i+1);

		if (saida == "A") {
            if ((ascii >=97) && (ascii <= 122)) { event.keyCode -= 32; }
        	else { return false; }
        } else if (saida == "0") {
	if ((ascii >= 48) && (ascii <= 57)) { return }
		else { return false;}
	} else { return; }
}
}
	
//conta total de caracteres inseridos	
   function Contador(field,MaxLength) {
      obj = document.getElementById(field);
      if (MaxLength !=0) {
         if (obj.value.length > MaxLength)  {
            obj.value = obj.value.substring(0, MaxLength);
            }
      }
      document.getElementById("contador").value = obj.value.length + '/' + MaxLength;
   }

//Validacão para e-mails
function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){
			return true; 
		}else{
			alert('E-mail inserido é invalido.');
		}
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){
        	return true;
		}else{
			alert('E-mail inserido é invalido.');
		}
    }else{
		alert('E-mail inserido é invalido.');
	return false;
}
}

function isDate(dateStr) {

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?

if (matchArray == null) {
return false;
}

month = matchArray[3]; // p@rse date into variables
day = matchArray[1];
year = matchArray[5];

if (month < 1 || month > 12) { // check month range
return false;
}

if (day < 1 || day > 31) {
return false;
}

if ((month==4 || month==6 || month==9 || month==11) && day==31) {
return false;
}

if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day > 29 || (day==29 && !isleap)) {
return false;
}
}
return true; // date is valid
}


