<!--
// Bloqueia todas as teclas exceto as numéricas
function sonum(e) {
	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode;
	} else if(e.which) {
		// netscape
		key = e.which;
	} else {
		// no event, so pass through
		return true;
	}
	if ((key > 47 && key < 58) || (key == 8 || key == 9 || key == 127)){
	}else{
		return false;
	}
}

function BuscaCep() {
	var cep1 = document.getElementById("num_cep").value;
	var cep2 = document.getElementById("num_cep2").value;
	
	var num_cep = cep1 +'-'+ cep2;
	var ind_cep = document.getElementById("ind_cep").value;
	
	if (num_cep.length == 9 && num_cep != ind_cep) {
		document.getElementById("ind_cep").value = num_cep; // atualiza o valor do campo hidden
		
		// chama a função de busca de cep
		document.getElementById('msg').innerText = "Pesquisando endereço...";
		frames["funcoes"].document.location.href = "include/get.asp?tipo=busca_cep&num_cep="+ num_cep;
		//window.open("include/get.asp?tipo=busca_cep&num_cep="+ num_cep,'');
	}
}

function BuscaEsedex() {
	var cep1 = document.getElementById("num_cep").value;
	var cep2 = document.getElementById("num_cep2").value;

	var num_cep = cep1 +'-'+ cep2;
	var ind_cep = document.getElementById("ind_cep").value;
	if (num_cep.length == 9 && num_cep != ind_cep) {
		document.getElementById("ind_cep").value = num_cep; // atualiza o valor do campo hidden
		//Exibe a mensagem em sua respectiva linha		
		aguarde.innerText = "   Aguarde. Buscando dados para e-sedex...";
		// chama a função de busca de cep		
		frames["funcoes"].document.location.href = "include/get.asp?tipo=busca_esedex&num_cep="+ num_cep;
	}
}
function BuscaEndereco() {
	var num_cep = document.getElementById("num_cep_entrega").value
	var ind_cep = document.getElementById("ind_cep").value;	
	
	if (num_cep.length == 8 && num_cep != ind_cep) {		
		document.getElementById("ind_cep").value = num_cep; // atualiza o valor do campo hidden						
		// chama a função de busca de cep
		aguarde.innerText = "   Aguarde.\rBuscando dados para e-sedex...";
		frames["funcoes"].document.location.href = "include/get.asp?tipo=busca_endereco&num_cep="+ num_cep;
	}
}

function FormataFone(campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form1[campo].value;
	vr = vr.replace( " ", "" );
	vr = vr.replace( "(", "" );
	vr = vr.replace( ")", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length + 1;
	if (tecla != 9 && tecla != 8){
		if ( tam <= 10){
			if ( tam == 1)
				document.form1[campo].value = '(' + vr.substr( 0, 2 );
			if ( tam == 3)
				document.form1[campo].value = '(' + vr.substr( 0, 2 ) + ') ';
			if ( tam == 6)
				document.form1[campo].value = '(' + vr.substr( 0, 2 ) + ') ' + vr.substr( 2, 4 ) + '-';
			if ( tam == 10)
				document.form1[campo].value = '(' + vr.substr( 0, 2 ) + ') ' + vr.substr( 2, 4 ) + '-' + vr.substr( 6, 4 );
		}else{
			event.returnValue = false;
		}
	}
}

function TestaCPF(campo) {
	if (campo.value.length > 0 && campo.value.length < 14) {
		alert("CPF Inválido!");
		campo.focus();
	}
}

function FormataCPF(tammax,teclapres) {
	if(window.event) {
		vr = teclapres.srcElement.value;
		campo = teclapres.srcElement;
		tecla = teclapres.keyCode;
	} else if(teclapres.which) {
		vr = teclapres.target.value;
		campo = teclapres.target;
		tecla = teclapres.which;
	}

	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;
	
	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 <= 2 ){ event.srcElement.value = vr ; }
		if ( (tam > 2) && (tam <= 5)){
			campo.value = vr.substr(0, tam - 2) + '-' + vr.substr(tam - 2, tam) ; }
			if ( (tam >= 6) && (tam <= 8)){
			campo.value = vr.substr(0, tam - 5) + '.' + vr.substr(tam - 5, 3) + '-' + vr.substr(tam - 2, tam) ; }
			if ( (tam >= 9) && (tam <= 11) ){
			campo.value = vr.substr(0, tam - 8) + '.' + vr.substr(tam - 8, 3) + '.' + vr.substr(tam - 5, 3) + '-' + vr.substr(tam - 2, tam) ; }
	}
}

function FormataCnpj(campo) {
	if (campo.value.length == 2){ 
		campo.value = campo.value + '.'; 
	} 
	else if (campo.value.length == 6){ 
		campo.value = campo.value + '.'; 
	} 
	else if (campo.value.length == 10){ 
		campo.value = campo.value + '/'; 
	} 
	else if (campo.value.length == 15){ 
		campo.value = campo.value + '-'; 
	}
}


function valida_CPF(campo) {
	var i;
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";
	for (var i=0; i<campo.value.length; i++){
	  digito = campo.value.charAt(i);
	  if (Digitos.indexOf(digito)>=0) { temp += digito }
	}
	s = temp;

	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(10-i);
	}
	if (s == "00000000000" || s == "11111111111" || s == "22222222222" || s == "33333333333" || s == "44444444444" || s == "55555555555" || s == "66666666666" || s == "77777777777" || s == "88888888888" || s == "99999999999"){
			campo.focus();
			return false;
   }
        if (d1 == 0) {
			campo.focus();
			return false;
		}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1)
	{
			campo.focus();
			return false;
	}

	d1 *= 2;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(11-i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1)
	{
			campo.focus();
			return false;
	}
	return true;
}

function currencyFormat(fld, milSep, decSep, e) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;

	if (whichCode == 13 || whichCode == 0) {		//Enter
		return true;  
	}
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) {
		return false;  // Not a valid key
	}
	len = fld.value.length;
	for(i = 0; i < len; i++) {
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) {
			break;
		}
	}
	aux = '';
	for(; i < len; i++) {
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) {
			aux += fld.value.charAt(i);
		}
	}
	aux += key;
			
	len = aux.length;
	if (len == 0) {
		fld.value = '';
	} else if (len == 1) {
		fld.value = '0'+ decSep + '0' + aux;
	} else if (len == 2) {
		fld.value = '0'+ decSep + aux;
	} else if (len > 2) {
		aux2 = '';

		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--) {
			fld.value += aux2.charAt(i);
		}
		fld.value += decSep + aux.substr(len - 2, len);
	}	
return false;
}

function limpa_string(S){
// Deixa so' os digitos no numero
var Digitos = "0123456789";
var temp = "";
var digito = "";
    for (var i=0; i<S.length; i++){
      digito = S.charAt(i);
      if (Digitos.indexOf(digito)>=0){temp=temp+digito}
    }
    return temp
}

function valida_CGC(campo) {
	var i;
	campo = limpa_string(campo.value);
	var c = campo.substr(0,12);
	var dv = campo.substr(12,2);
	var d1 = 0;
	for (i = 0; i < 12; i++) {
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
	if (d1 == 0) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1) {
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 12; i++) {
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1)	{
		return false;
	}
		return true;
}


function checkemail(email){
 var str=email.value;
 var erro = "";
 var filter=/^.+@.+\..{2,3}$/
 if (str.length > 0) {
	 if (filter.test(str) && str.indexOf('@')>0 && str.indexOf(' ')<0 && str.indexOf('#')<0)
		{	for(var I =1;I < 100;I++){
				if(I==30) { I=80; }
				if(str.indexOf(unescape("%"+I))> -1 || str.indexOf(",")> -1 || str.indexOf(":")> -1 || str.indexOf("/")> -1 || str.indexOf(";")> -1 || str.indexOf("www.")> -1 || str.indexOf("WWW.")> -1 || str.indexOf("+")> -1 || str.indexOf("*")> -1 || str.indexOf("~")> -1 || str.indexOf("^")> -1 || str.indexOf("=")> -1 || str.indexOf("\\")> -1 || str.indexOf("ª")> -1 || str.indexOf("º")> -1 || str.indexOf("°")> -1 || str.indexOf("|")> -1 || str.indexOf("¹")> -1 || str.indexOf("²")> -1 || str.indexOf("£")> -1 || str.indexOf("¢")> -1 || str.indexOf("¬")> -1 || str.indexOf("§")> -1 || str.indexOf("@.")> -1)
				{
					return false;
					I=100;
					email.focus();
				}
			}
			return true;
		}
	 else {
		return false;
		email.focus();
	}
	return true;
 }
}

// vai para o proximo campo, utilizado quando tem um campo para ddd e outro para fone (apenas um exemplo).
function GoToNext(size, fld, next) {
	if (fld.value.length == size) {
		if (document.getElementById(next))
			document.getElementById(next).focus();
	}
}


function formatar_moeda(valor) {	
	var decimal, preco = '0';
			
	if (valor.lastIndexOf('.') > 0) {
		decimal = valor.substr(valor.lastIndexOf('.') + 1, valor.lastIndexOf('.') + 2);
	} else {
		decimal = '00';
	}
	if (decimal.length == 0) decimal = '00';
	if (decimal.length == 1) decimal = decimal + '0';

	if (valor.lastIndexOf('.') > 0) {
		preco = valor.substr(0, valor.indexOf('.'));
	} else {
		preco = valor;
	}

	amount = parseFloat(preco);
	var samount = new String(amount);

	if (samount.length < 3) { return preco +','+ decimal; }  

	for (var i = 0; i < Math.floor((samount.length-(1+i))/3); i++)
	{
		samount = samount.substring(0,samount.length-(4*i+3)) + '.' + samount.substring(samount.length-(4*i+3));
	}

	return samount +','+ decimal
}
function formatar_data(e) {
	
	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		tecla = e.keyCode;
	} else if(e.which) {
		// netscape
		tecla = e.which;
	} else {
		// no event, so pass through
		return true;
	}
	if ((tecla > 47 && tecla < 58) || (tecla == 8 || tecla == 9 || tecla == 127)){
		vr = e.srcElement.value;
		vr = vr.replace("/", "");
		tam = vr.length + 1;
		if (tecla != 9 && tecla != 8){
			if ( tam < 10){
				if ( tam == 3)
					e.srcElement.value = vr.substr( 0, 2 ) + '/';
				if ( tam == 5)
					e.srcElement.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/';
			}else{
				event.returnValue = false;
			}
		}
	}else{
		return false;
	}
	
	
}	


/******************************************
/* Mascara para os campos
/*****************************************/

// Adiciona um evento a uma função/campo
addEvent = function(o, e, f, s){
    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
    r[r.length] = [f, s || o], o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
        return e = null, !!d;
    }
};

// Remove um evento de uma função/campo
removeEvent = function(o, e, f, s){
    for(var i = (e = o["_on" + e] || []).length; i;)
        if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
            return delete e[i];
    return false;
};

// Função que cria a maskara
MaskInput = function(f, m){ //v1.0
    function mask(e){
        var patterns = {"1": "/[A-Z]/i", "2": "/[0-9]/", "4": "/[À-ÿ]/i", "8": "/./" };
        var rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
        function accept(c, rule){
            for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
                if(r & i && eval(patterns[i]).test(c))
                    break;
                return i <= r || c == rule;
        }
        var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
        (!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
            r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
            : (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
            r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
    }
    for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
        addEvent(f, i, mask);
};


// Formata uma data
var DATA = "99/99/9999";
// Formata um Cpf
var CPF  = "999.999.999-99";
// Formata um CNPJ
var CNPJ = "99.999.999/9999-99";
// Formata uma HORA
var HORA = "99:99";
// Formata um TELEFONE
var FONE = "(99) 9999-9999";
// Formata um CEP
var CEP  = "99999-999";
// Formata Seguro
var SEGURO = "a^";

// Formata um VALOR
FormataValor = function(o, n, dig, dec) {
  o.c = !isNaN(n) ? Math.abs(n) : 2;
  o.dec = dec || ",", o.dig = dig || ".";
  addEvent(o, "keypress", function(e){
      if(e.key > 47 && e.key < 58){
          var o, s = ((o = this).value.replace(/^0+/g, "") + String.fromCharCode(e.key)).replace(/\D/g, ""), l, n;
          (l = s.length) <= (n = o.c) && (s = new Array(n - l + 2).join("0") + s);
          for(var i = (l = (s = s.split("")).length) - n; (i -= 3) > 0; s[i - 1] += o.dig);
          n && n < l && (s[l - ++n] += o.dec);
          o.value = s.join("");
      }
      e.key > 30 && e.preventDefault();
  });
};
// Auto tabulação
autoTab = function(){
    var c = 0, lastKey = function(e){c = e.key;}, next = function(e){
        var i, j, f = (e = e.target).form.elements, l = e.value.length, m = e.maxLength;
        if(c && m > -1 && l >= m){
            for(i = l = f.length; f[--i] != e;);
            for(j = i; (j = (j + 1) % l) != i && (!f[j].type || f[j].disabled || f[j].readOnly || f[j].type.toLowerCase() == "hidden" || f[j].style.display == "none"););
            try {j != i && f[j].focus();}catch(e){ /*nada*/ }
        }
    };
    for(var f, i = (f = document.forms).length; i; addEvent(f[--i], "keyup", next), addEvent(f[i], "keypress", lastKey));
};


//-->