function MascaraMoeda(campo, separador_milhar, separador_decimal, tecla){//onKeyPress="return(MascaraMoeda(this,'.',',',event))"
    var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? tecla.which : tecla.keyCode;

	if (whichCode == 13) return true; // Tecla Enter
	if (whichCode == 8) return true; // Tecla Delete
	key = String.fromCharCode(whichCode); // Pegando o valor digitado
	if (strCheck.indexOf(key) == -1) return false; // Valor inválido (não inteiro)
	len = campo.value.length;
	for(i = 0; i < len; i++)
	if ((campo.value.charAt(i) != '0') && (campo.value.charAt(i) != separador_decimal)) break;
	aux = '';
	for(; i < len; i++)
	if (strCheck.indexOf(campo.value.charAt(i))!=-1) aux += campo.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) campo.value = '';
	if (len == 1) campo.value = '0'+ separador_decimal + '0' + aux;
	if (len == 2) campo.value = '0'+ separador_decimal + aux;

	if (len > 2) {
		aux2 = '';

		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += separador_milhar;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}

		campo.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		campo.value += aux2.charAt(i);
		campo.value += separador_decimal + aux.substr(len - 2, len);
	}

	return false;

}
function mascaraEntrada(objeto, sMask, evtKeyPress) // onkeypress="javascript:return mascaraEntrada(this,'99999-999',event);"
{
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

if (document.all) { nTecla = evtKeyPress.keyCode; }
else if (document.layers) { nTecla = evtKeyPress.which; }
else { nTecla = evtKeyPress.which; if (nTecla == 8) { return true; } }

sValue = objeto.value;

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)
{
if (sMask.charAt(i-1) == "9")
{
return ((nTecla > 47) && (nTecla < 58));
}
else { return true; }
}
else { return true; }
} 


function verificarEmail(email){
   
      er = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2}/;
      
      if(er.exec(email.value))
        {
          return true;
        } else {
          alert('Email não é válido');
		  email.focus();
		  return false;
        }
}
function checknewsletter(){
nw = document.getElementById('form_news');
if(nw.new_nome.value == 'Digite seu Nome'){
	alert('Digite Seu Nome!');
	nw.new_nome.focus();
	return false;
}
if(nw.new_email.value == 'Digite seu Email'){
	alert('Digite Seu Email!');
	nw.new_email.focus();
	return false;
}
if(!checkMail(nw.new_email)){
	alert('Email Não e Válido');
	nw.new_email.focus();
	return false;
}
return true;

}
function vercpf (cpf) 
{if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
return false;
add = 0;
for (i=0; i < 9; i ++)
add += parseInt(cpf.charAt(i)) * (10 - i);
rev = 11 - (add % 11);
if (rev == 10 || rev == 11)
rev = 0;
if (rev != parseInt(cpf.charAt(9)))
return false;
add = 0;
for (i = 0; i < 10; i ++)
add += parseInt(cpf.charAt(i)) * (11 - i);
rev = 11 - (add % 11);
if (rev == 10 || rev == 11)
rev = 0;
if (rev != parseInt(cpf.charAt(10))){
	alert('O CPF INFORMADO NAO É VÁLIDO.');
	return false;
}else{
	
	return true;
}
}
function Numero(e)
{
  navegador = /msie/i.test(navigator.userAgent);
  if (navegador)
   var tecla = event.keyCode;
  else
   var tecla = e.which;
  
  if(tecla > 47 && tecla < 58) // numeros de 0 a 9
    return true;
  else
    {
      if (tecla != 8) // backspace
        return false;
      else
        return true;
    }
}
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 if(typeof(mail) == "object"){
            if(er.test(mail.value)){ 
            return true; 
            }
        }else{
            return false;
		}
}
function VerificarEnter(e) {
        var evento = window.event || e;
        var tecla = evento.keyCode || evento.witch;
        if (tecla == 13) {
			return false;
		}
}
function ValidaPeso(val,len)
{
	n='__0123456789';
	d=val.value;
	l=d.length;
	s='';
	a=2;
	for (i=0; i<l; i++)
	{
		c=d.charAt(i);
		if (n.indexOf(c) > a)
		{
			a=1;
			s+=c;
		};
	};
	l=s.length;
	t=len-1;
	if (l > t)
	{
		l=t;
		s=s.substr(0,t);
	};
	r='';
	if (l > 3)
	{
		r=s.substr(0,l-3)+','+s.substr(l-3,3);
	}
	else
	{
		if (l == 3)
		{
			r='0,'+s;
		}
		else
		{
			if (l == 2)
			{
				r='0,0'+s;
			}
			else
			{
				if(l == 1)
				{
					r='0,00'+s;
				};
			};
		};
	};
	if (r == '')
	{
		r='0,000';
	};
	val.value=r;
	return 'ok';
};
function exibir_pedido(id){
	var div = document.getElementById('exibi_pedido');
    div.innerHTML = "<center><img src='carregando.gif'></center>";
    var ajax = new Ajax();
    ajax.set_receive_handler(
       function(c) {
          div.innerHTML = c;
       }
    );
    ajax.send('area_cliente/exibi_pedido.php?id='+id);
}

function CheckDate(pObj) {
  var expReg = /^((0[1-9]|[12]\d)\/(0[1-9]|1[0-2])|30\/(0[13-9]|1[0-2])|31\/(0[13578]|1[02]))\/(19|20)?\d{2}$/;
  var aRet = true;
  if ((pObj) && (pObj.value.match(expReg)) && (pObj.value != '')) {
        var dia = pObj.value.substring(0,2);
        var mes = pObj.value.substring(3,5);
        var ano = pObj.value.substring(6,10);
        if ((mes == 4 || mes == 6 || mes == 9 || mes == 11 ) && dia > 30) 
          aRet = false;
        else 
          if ((ano % 4) != 0 && mes == 2 && dia > 28) 
                aRet = false;
          else
                if ((ano%4) == 0 && mes == 2 && dia > 29)
                  aRet = false;
  }  else 
        aRet = false;  
  return aRet;
}
function ValidaData(obj){
	if(!CheckDate(obj)){
		alert('Data '+obj.value+'não é válida!');
		obj.focus();
		return false;	
	}else{
		return true;
	}
	
}
function gera_estoque(id){
	var div = document.getElementById('produtos_estoque');
    div.innerHTML = "<center><img src='carregando.gif'></center>";
    var ajax = new Ajax();
    ajax.set_receive_handler(
       function(c) {
          div.innerHTML = c;
       }
    );
    ajax.send('gera_estoque.php?pro='+id);
	
}
function enviar_ped(obj){
if(document.getElementById('estoque_opcao').length != 0){	
	if(typeof(document.getElementById('estoque_opcao').opcao.length) != "undefined"){	
		for (i=0;i<document.getElementById('estoque_opcao').opcao.length;i++){
			if(document.getElementById('estoque_opcao').opcao[i].checked){
			break;	
			}
		} 
		obj.href = obj.href+'&op='+document.getElementById('estoque_opcao').opcao[i].value; 
		return true;	
			
	}else{
		obj.href = obj.href+'&op='+document.getElementById('estoque_opcao').opcao.value; 	
		return true;
	}
}else{
	return true;
}
}
function cadastro_cliente(){
	obj = document.getElementById('produto_valores');
	obj.innerHTML="<div id='texto_cadastro'>Para ter acesso ao nossos preços<br> você precisa estar cadastrado e logado no site</div> <a href='?p=Y2xpZW50ZV9sb2dpbg=='><img src='imagens/btn_cadastro2.png' border='0' style='margin:25px'></a>";
	
}
