function mascara(o,f){
	campo = o;
	funcao = f;
	campo.value = telefone(campo.value);
}
function telefone(v){
	v = v.replace(/\D/g,"");
	v = v.replace(/^(\d\d)(\d)/g,"($1) $2");
	v = v.replace(/(\d{4})(\d)/,"$1-$2");
	return v;
}
function somenteNumeros(input){
   if((event.keyCode < 48)||(event.keyCode > 57))
      event.returnValue = false;
}
function formatar_mascara(src, mascara) {
   if((event.keyCode < 48)||(event.keyCode > 57))
   event.returnValue = false;
	 var campo = src.value.length;
	 var saida = mascara.substring(0,1);
	 var texto = mascara.substring(campo);
	 if(texto.substring(0,1) != saida) {
  		src.value += texto.substring(0,1);
	 }
}
function FormataValor(campo,tammax,pres){
   var tecla = pres.keyCode;
	var value = campo.value;
	if(value.length > 3){
		value = value.replace("R$ ", "");
		value = value.replace("R$ ", "");
	}
	campo.value = value;
   var vr = value;
   vr = vr.replace("/", "");
   vr = vr.replace("/", "");
   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 )
         campo.value = vr;
      tam = tam - 1;
      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);
      if((tam >= 12) && (tam <= 14))
         campo.value = vr.substr(0, tam - 11) + '.' + vr.substr(tam - 11, 3) + '.' + vr.substr(tam - 8, 3) + '.' + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam);
      if((tam >= 15) && (tam <= 17))
         campo.value = vr.substr(0, tam - 14) + '.' + vr.substr(tam - 14, 3) + '.' + vr.substr(tam - 11, 3) + '.' + vr.substr(tam - 8, 3) + '.' + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam);
		campo.value = "R$ " + campo.value;
   }
}
function cadastro_valida(){
   objform = document.getElementById("frm_cadastro");
   if(objform.nome.value=='' || objform.nome.value.length < 4){
      alert('Digite seu nome corretamente');
      objform.nome.focus("");
   }
   else if(objform.email.value=='' || objform.email.value.length < 8){
      alert('Digite seu e-mail corretamente');
      objform.email.focus("");
   }
   else if(objform.email.value!='' && (objform.email.value.split("@").length <=1 || objform.email.value.split(".").length <=1)){
      alert('Email digitado é inválido');
      objform.email.focus("");
   }
   else
      objform.submit("");
}

function pag_valida(){
   objform = document.getElementById("frm_pag2");
   if(objform.nome.value=='' || objform.nome.value.length < 4){
      alert('Digite seu nome corretamente');
      objform.nome.focus("");
   }
   else if(objform.email.value=='' || objform.email.value.length < 8){
      alert('Digite seu e-mail corretamente');
      objform.email.focus("");
   }
   else if(objform.email.value!='' && (objform.email.value.split("@").length <=1 || objform.email.value.split(".").length <=1)){
      alert('Email digitado é inválido');
      objform.email.focus("");
   }
   else
      objform.submit("");
}
function desc_valor(nome){
	n = document.getElementById(nome).value;
	if (n<=0){
		document.getElementById(nome).value = 0;
	} else
		n = n-1;
		document.getElementById(nome).value = parseInt(n);
	somatudo();
	 
}
function asc_valor(nome){
  	n = document.getElementById(nome).value;
  	n = parseInt(n)+1;
	document.getElementById(nome).value = parseInt(n);
	somatudo();
}

function somatudo(){
	var total = 0;
	
	if(document.getElementById("qtde").value > 0)
		total += 42 * document.getElementById("qtde").value;
	
	document.getElementById("preco").innerHTML = "R$ " + total + ",00";
	document.getElementById("total").value = "R$ " + total + ",00";
}
