//var $j = jQuery.noConflict();

function dateMask(inputData, e){
if(document.all) // Internet Explorer
var tecla = event.keyCode;
else //Outros Browsers
var tecla = e.which;

if(tecla >= 47 && tecla < 58){ // numeros de 0 a 9 e "/"
var data = inputData.value;
if (data.length == 2 || data.length == 5){
data += '/';
inputData.value = data;
}
}else if(tecla == 8 || tecla == 0) // Backspace, Delete e setas direcionais(para mover o cursor, apenas para FF)
return true;
else
return false;
}


 $(document).ready(function(){

							
			$("#topo h1 a").append('<img src="/emagrecimento/images/logo.jpg">');





           $("#numero").keyup(function(){
 var v =$(this).val();
v=v.replace(/\D/g,"");
$(this).val(v);


});

$("#cep").livequery("keyup",function(){
var a =$(this).val();
a=a.replace(/\D/g,"")                //Remove tudo o que não é dígito
a=a.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações

$(this).val(a);
});


$("#telefone").livequery("keyup",function(){
  var v =$(this).val();
  v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
  v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
  v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
   $(this).val(v);
});

function validar_email(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;
       }
}
 

$("#cadastra_usuario").livequery("click",function(e) {
 e.preventDefault();
 var campo="";
//r nome=$("#nome").val();
//ert(nome);
$('.borda').each(function () {

 // if (this.title!='') {
  if (this.value=='') {
  alert('O campo  ' + this.name + '  esta vazio');
  $(this).css({ backgroundColor:"#ffffcc"}).focus();
   campo=1;
  return false;
}
if(this.name=="email") {

var email=$("#email").val();
 if (!validar_email(email)) {
    alert("Email inválido");
    campo=1;
     $("#email").css({ backgroundColor:"#ffffcc"});
         // $("#email").focus();

     return false;
    }


}



$(this).css({ backgroundColor:"#efefef"});



})

if(campo!=1) {
var str = jQuery('#form_assinatura').serialize();

  $.ajax({
   type: "POST",
   url: "ver2.php",
   data: str,
   success: function(msg){

   if(msg==1) {
    alert("Já Existe um usuario cadastrado com esse email");
   }
   else {
   
    alert("Cadastro Efetuado com Sucesso");
    $("#remove_form").hide();
    $("#aviso").fadeIn(1500);
    
    
   }
//  if(msg==1) {
 //  alert("Cadastro efetuado com sucesso");
//   $("#form_contato").hide();
  //  $("#sucesso").fadeIn(1500);
  // var artigo ="1500";
   // setTimeout(location.href='mostranoticia.php?id='+artigo,2000);

//   }


   }
 });




}

 campo="";





})






/* cadastra new do form*/
$("#cadastra_futuro").livequery("click",function(e) {
 e.preventDefault();

//r nome=$("#nome").val();
//ert(nome);
$('.borda_futuro').each(function () {

 // if (this.title!='') {
  if (this.value=='') {
  alert('O campo  ' + this.name + '  esta vazio');
  $(this).css({ backgroundColor:"#ffffcc"}).focus();
   campo=1;
  return false;
}
if(this.name=="email") {

var email=$("#email_futuro").val();
 if (!validar_email(email)) {
    alert("Email inválido");
    campo=1;
     $("#email_futuro").css({ backgroundColor:"#ffffcc"});
         // $("#email").focus();

     return false;
    }


}



$(this).css({ backgroundColor:"#efefef"});



})

if(porta!=1) {
var str = jQuery('#form_futuro').serialize();

  $.ajax({
   type: "POST",
   url: "achar_email.php",
   data: str,
   success: function(msg){

   if(msg==1) {
    alert("Já Existe um usuario cadastrado com esse email");
   }
   else {

    alert("Cadastro Efetuado com Sucesso");
    $("#remove_form").hide();
 //   $("#aviso").fadeIn(1500);


   }

   }
 });




}

 porta="";





})




/* final do new*/

 /// form de contato//
 
 $("#enviar_email").livequery("click",function(e) {
 e.preventDefault();
 var campo="";
//r nome=$("#nome").val();
//ert(nome);
$('.borda_enviar').each(function () {

 // if (this.title!='') {
  if (this.value=='') {
  alert('O campo  ' + this.name + '  esta vazio');
  $(this).css({ backgroundColor:"#ffffcc"}).focus();
   campo=1;
  return false;
}
if(this.name=="email") {

var email=$("#email_enviar").val();
 if (!validar_email(email)) {
    alert("Email inválido");
    campo=1;
     $("#email_enviar").css({ backgroundColor:"#ffffcc"});
         // $("#email").focus();

     return false;
    }


}



$(this).css({ backgroundColor:"#efefef"});



})

if(campo!=1) {
var str = jQuery('#mandar_email').serialize();

  $.ajax({
   type: "POST",
   url: "mandar_msg.php",
   data: str,
   success: function(msg){

   if(msg) {
    alert("Mensagem enviada com Sucesso");
    location.href='contato';


   }

//  if(msg==1) {
 //  alert("Cadastro efetuado com sucesso");
//   $("#form_contato").hide();
  //  $("#sucesso").fadeIn(1500);
  // var artigo ="1500";
   // setTimeout(location.href='mostranoticia.php?id='+artigo,2000);

//   }


   }
 });




}

 campo="";





})
 // final do form de contato






 
 });
