// JavaScript Document

//onClick="return verifica_campos(this.Form)"
function verifica_campos()
{
if ((document.Form.Nome_produto.value == ""))
	{
		alert("Selecione o nome do produto."); 
		document.Form.Nome_produto.focus();
		return false;
	}	
if ((document.Form.Numero_lote.value == ""))

	{
		alert("Informe o número do lote."); 
		document.Form.Numero_lote.focus();
		return false;
	}
if ((document.Form.Certificado_pdf.value == ""))
	{
		alert("Selecione o arquivo (pdf) do certificado."); 
		document.Form.Certificado_pdf.focus();
		return false;
	}
	return true;
}
//Impede a inserção de acentuação, pontuação e caracteres especiais.
//Comando = onKeyPress="return Verifica_caracteres(event);"
function Verifica_caracteres(caracter) {
if(window.event) { // Internet Explorer
  	var tecla = event.keyCode;
 	}
else { // Firefox
  	var tecla = caracter.which;
 	}
 	//if((tecla > 33) && (tecla < 62)) { Um intervalo entre os caracteres ASCII
 	if((tecla == 33) || (tecla == 34) || (tecla == 35) || (tecla == 36) || (tecla == 37) || (tecla == 38) || (tecla == 39) || (tecla == 40) || (tecla == 41) || (tecla == 42) || (tecla == 43) || (tecla == 44) || (tecla == 45) || (tecla == 46) || (tecla == 47) || (tecla == 48) || (tecla == 49) || (tecla == 50) || (tecla == 51) || (tecla == 52) || (tecla == 53) || (tecla == 54) || (tecla == 55) || (tecla == 56) || (tecla == 57) || (tecla == 58) || (tecla == 59) || (tecla == 60) || (tecla == 61) || (tecla == 62) || (tecla == 63) || (tecla == 64) || (tecla == 94) || (tecla == 95) || (tecla == 96) || (tecla == 180) || (tecla == 123) || (tecla == 125)|| (tecla == 91)|| (tecla == 92)|| (tecla == 93) || (tecla == 124) || (tecla == 126) || (tecla == 170) || (tecla == 186)) { 
  	alert("Este campo aceita apenas caracteres alpha. Acentuação, pontuação, numéricos e caracteres especiais não são aceitos.");
return false;
 	}
else 
 	{ 
return true; 
 	}
}


//Pula para o próximo campo no form após quantidade determinada de caractéres serem digitados ***********
//Comando = onFocus="this.value='';" onKeyDown="proximoCampo(this,10);"
function proximoCampo(field, letras){
for (i = 0; i < field.form.elements.length; i++){
if (field == field.form.elements[i]){
if (field.form.elements[i].value.length == letras){
i = (i + 1) % field.form.elements.length;
field.form.elements[i].focus();
return false;
}
}
}
return true;
}

//Limpa campo do form ao receber o fóco**********************************************
//Comando = onfocus="Esvazia(this)" onblur="Padrao(this)"
//Limpa o campo 
function Esvazia(valor_campo){
if (valor_campo.value == valor_campo.defaultValue)
	valor_campo.value='';
}
//Se nada foi alterado recupera o valor padrão
function Padrao(valor_campo){

if (valor_campo.value == '')
	valor_campo.value=valor_campo.defaultValue;
}

// INÍCIO Máscara para campos de formulário *****************************************
// Comando onkeypress="return Mascara_do_campo(this, '99/99/9999', event);"
// Não esquecer de configurar o maxlength=xx
function Mascara_do_campo(objeto, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

if(document.all) { // Internet Explorer
    nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
    nTecla = evtKeyPress.which;
} else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8) {
        return true;
    }
}

    sValue = objeto.value;

    // Limpa todos os caracteres de formatação que
    // já estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

      if (bolMask) {
        sCod += sMask.charAt(i);
        mskLen++; }
      else {
        sCod += sValue.charAt(nCount);
        nCount++;
      }

      i++;
    }

    objeto.value = sCod;

    if (nTecla != 8) { // backspace
      if (sMask.charAt(i-1) == "9") { // apenas números...
        return ((nTecla > 47) && (nTecla < 58)); } 
      else { // qualquer caracter...
        return true;
      } 
    }
    else {
      return true;
    }
  }
// FIM Máscara para campos de formulário
