
function trim(str){
    while (str.charAt(0) == " ")
    str = str.substr(1,str.length -1);

    while (str.charAt(str.length-1) == " ")
    str = str.substr(0,str.length-1);

    return str;
}

function limpa_string(s){
    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_CPF(s)
{

    var i;
    s = limpa_string(s);
    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 (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 < 9; i++)
    {
        d1 += c.charAt(i)*(11-i);
    }
    d1 = 11 - (d1 % 11);
    if (d1 > 9) d1 = 0;
    if (dv.charAt(1) != d1)
    {
        return(false);
    }

    if(s=='11111111111' ||  s=='22222222222' || s=='33333333333' || s=='44444444444' || s=='55555555555' || s=='66666666666' || s=='77777777777' || s=='88888888888' || s=='99999999999' || s=='00000000000')
        return(false);
    else
        return(true);
}

function valida_CNPJ(s)
{
    var i;
    s = limpa_string(s);
    var c = s.substr(0,12);
    var dv = s.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 validaNews(obj, vnome,vemail, page, w, h){
if(vnome != "")
{
  if(vemail != "")
  {
    if(validaEmail(vemail) == true)
    {
      //NewWindow(page,myname,w,h,scroll);
      toPopup(obj, h, w, page);
    }
    else
    {
      alert('Você deve informar um endereço de e-mail válido');
      document.f_news.email.value = "";
      document.f_news.email.focus();
    }
  }
  else
  {
    alert('Por favor, informe seu "E-mail".');
    document.f_news.email.focus();
  }
}
else
{
  alert('Por favor, informe seu "Nome".');
  document.f_news.nome.focus();
}
  return(false);
}

//VALIDAÇÕES DE FORMULARIOS E POST AJAX
$(document).ready(function() {
    
    //FALE CONOSCO
    $("#contato").submit( function() {
         
         if (trim($("#nome_contato").val()) == '') {
            alert("Por favor, informe o Seu Nome");
            $("#nome_contato").focus();
            return false;
         }
         
         if (trim($("#telefone").val()) == '') {
            alert("Por favor, informe o Telefone");
            $("#telefone").focus();
            return false;
         }
         
		 if (trim($("#email").val()) == ''){
            alert("Por favor, informe o email");
            $("#email").focus();
            return false;
         }
         else{
			  var regmail = /^[\w!#$%&amp;'*+\/=?^`{|}~-]+(\.[\w!#$%&amp;'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
			  if (!regmail.test($("#email").val())) {
				   alert("E-mail inválido");
                   $("#email").focus();
				   return false;
			  }
		 }
         
         if (trim($("#mensagem").val()) == '') {
            alert("Por favor, informe a Mensagem");
            $("#mensagem").focus();
            return false;
         }
         
         $("#msg").html('Enviando!...');
         $("#msg").fadeIn("slow");
        //$('#contato').css('opacity', .60);
        
        $("#msg").ajaxStart(function(){
            //$(this).fadeIn("slow");
        });
        
        $("#msg").ajaxStop(function(){
            //$(this).fadeOut("slow");
            //$(".alvo").show();
        });

        $.post("includes/ajax/faleconosco_enviar.php", {empresa: escape( encodeURI( $('#empresa').val() ) ), 
                                                        nome_contato: escape( encodeURI( $('#nome_contato').val() ) ),
                                                        telefone: escape( encodeURI( $('#telefone').val() ) ),
                                                        ramal: escape( encodeURI( $('#ramal').val() ) ),
                                                        email: escape( encodeURI( $('#email').val() ) ),
                                                        mensagem: escape( encodeURI( $('#mensagem').val() ) )
                                                        },
        function(data) {
            //Retorna 1 caso sucesso senao mensgens de erro
            if(data == '1'){
                $('#contato').hide();
                $('#contato_obrigado').fadeIn("slow");
            }
            else{
                $("#msg").html('');
                alert(data);
            }
        });
        
        //conteudoAjax.load('TESTE.php');
        return false;
    
	});
    
    
    
    
    
    //SALA DE IMPRENSA
    $("#sala_imprensa").submit( function() {
    
         if ($("#nome").val() == '') {
            alert("Por favor, informe Seu Nome");
            $("#nome").focus();
            return false;
         }
         
         if (!$("#cnpj").val() == '') {
            if (valida_CNPJ($("#cnpj").val()) == false) {
				   alert("CNPJ inválido");
                   $("#cnpj").focus();
				   return false;
			}
         }
         
         if (trim($("#cpf").val()) == '') {
            alert("Por favor, informe o CPF");
            $("#cpf").focus();
            return false;
         }
         else{
            if (!valida_CPF($("#cpf").val())) {
				   alert("CPF inválido");
                   $("#cpf").focus();
				   return false;
			}
         }
         
         if ($("#telefone").val() == '') {
            alert("Por favor, informe o Telefone");
            $("#telefone").focus();
            return false;
         }
         
		 if ($("#email").val() == ''){
            alert("Por favor, informe o E-mail");
            $("#email").focus();
            return false;
         }
         else{
			  var regmail = /^[\w!#$%&amp;'*+\/=?^`{|}~-]+(\.[\w!#$%&amp;'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
			  if (!regmail.test($("#email").val())) {
				   alert("E-mail inválido");
                   $("#email").focus();
				   return false;
			  }
		 }
         
         if ($("#login").val() == ''){
            alert("Por favor, informe o E-mail para Login");
            $("#login").focus();
            return false;
         }
         else{
			  var regmail = /^[\w!#$%&amp;'*+\/=?^`{|}~-]+(\.[\w!#$%&amp;'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
			  if (!regmail.test($("#login").val())) {
				   alert("O login deve ser um e-mail válido");
                   $("#login").focus();
				   return false;
			  }
		 }
         
         if ($("#senha").val() == '') {
            alert("Por favor, informe a Senha");
            $("#senha").focus();
            return false;
         }
         
         if ($("#confirma_senha").val() == '') {
            alert("Por favor, confirme a senha");
            $("#confirma_senha").focus();
            return false;
         }
         
         if (!(($("#senha").val()) == ($("#confirma_senha").val()))) {
            alert("As senhas não conferem");
            $("#confirma_senha").focus();
            return false;
         }
         
         $('#submit').attr("disabled", true);
         
         $("#msg").html('Enviando!...');
         $("#msg").fadeIn("slow");
        
        $("#msg").ajaxStart(function(){
            //$(this).fadeIn("slow");
        });
        
        $("#msg").ajaxStop(function(){
            //$(this).fadeOut("slow");
            //$(".alvo").show();
        });

        $.post("includes/ajax/salaimprensa_enviar.php", {nome: escape( encodeURI( $('#nome').val() ) ), 
                                                        empresa: escape( encodeURI( $('#empresa').val() ) ),
                                                        cnpj: escape( encodeURI( $('#cnpj').val() ) ),
                                                        cpf: escape( encodeURI( $('#cpf').val() ) ),
                                                        telefone: escape( encodeURI( $('#telefone').val() ) ),
                                                        ramal: escape( encodeURI( $('#ramal').val() ) ),
                                                        email: escape( encodeURI( $('#email').val() ) ),
                                                        site: escape( encodeURI( $('#site').val() ) ),
                                                        login: escape( encodeURI( $('#login').val() ) ),
                                                        senha: escape( encodeURI( $('#senha').val() ) )
                                                        },
        function(data) {
            //Retorna 1 caso sucesso senao mensgens de erro
            if(data == '1'){
                $('#sala_imprensa').hide();
                $('#sala_imprensa_obrigado').fadeIn("slow");
            }
            else{
                $("#msg").html('');
                alert(data);
            }
        });
        
        $('#submit').removeAttr("disabled");
        
        //conteudoAjax.load('TESTE.php');
        return false;
    
	});
    
    
    
    
    
    //PROPOSTA FIREWALL
    $("#firewall").submit( function() {
    
         if (trim($("#nome_contato").val()) == '') {
            alert("Por favor, informe o Seu Nome");
            $("#nome_contato").focus();
            return false;
         }
         
         if (trim($("#telefone").val()) == '') {
            alert("Por favor, informe o Telefone");
            $("#telefone").focus();
            return false;
         }
         
		 if (trim($("#email").val()) == ''){
            alert("Por favor, informe o email");
            $("#email").focus();
            return false;
         }
         else{
			  var regmail = /^[\w!#$%&amp;'*+\/=?^`{|}~-]+(\.[\w!#$%&amp;'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
			  if (!regmail.test($("#email").val())) {
				   alert("E-mail inválido");
                   $("#email").focus();
				   return false;
			  }
		 }
         
         if (trim($("#usuarios").val()) == '') {
            alert("Por favor, informe os Usuários a se conectar");
            $("#usuarios").focus();
            return false;
         }
         
         if (trim($("#conexao").val()) == '') {
            alert("Por favor, informe o Link de conexão");
            $("#conexao").focus();
            return false;
         }
         
         $('#submit').attr("disabled", true);
         
         $("#msg").html('Enviando!...');
         $("#msg").fadeIn("slow");
        
        $("#msg").ajaxStart(function(){
            //$(this).fadeIn("slow");
        });
        
        $("#msg").ajaxStop(function(){
            //$(this).fadeOut("slow");
            //$(".alvo").show();
        });

        $.post("includes/ajax/firewallproposta_enviar.php", {empresa: escape( encodeURI( $('#nome').val() ) ), 
                                                             nome_contato: escape( encodeURI( $('#empresa').val() ) ),
                                                             telefone: escape( encodeURI( $('#telefone').val() ) ),
                                                             ramal: escape( encodeURI( $('#ramal').val() ) ),
                                                             email: escape( encodeURI( $('#email').val() ) ),
                                                             cep: escape( encodeURI( $('#cep').val() ) ),
                                                             usuarios: escape( encodeURI( $('#usuarios').val() ) ),
                                                             conexao: escape( encodeURI( $('#conexao').val() ) ),
                                                             mensagem: escape( encodeURI( $('#mensagem').val() ) )
                                                            },
        function(data) {
            //Retorna 1 caso sucesso senao mensgens de erro
            if(data == '1'){
                $('#firewall').hide();
                $('#firewall_proposta_obrigado').fadeIn("slow");
            }
            else{
                $("#msg").html('');
                alert(data);
            }
        });
        
        $('#submit').removeAttr("disabled");
        
        //conteudoAjax.load('TESTE.php');
        return false;
    
	});
    
    
    //PROPOSTA ANTIVIRUS
    $("#antivirus").submit( function() {
    
         if ($("#nome_contato").val() == '') {
            alert("Por favor, informe o Seu Nome");
            $("#nome_contato").focus();
            return false;
         }
         
         if ($("#telefone").val() == '') {
            alert("Por favor, informe o Telefone");
            $("#telefone").focus();
            return false;
         }
         
		 if ($("#email").val() == ''){
            alert("Por favor, informe o email");
            $("#email").focus();
            return false;
         }
         else{
			  var regmail = /^[\w!#$%&amp;'*+\/=?^`{|}~-]+(\.[\w!#$%&amp;'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
			  if (!regmail.test($("#email").val())) {
				   alert("E-mail inválido");
                   $("#email").focus();
				   return false;
			  }
		 }
         
         if (!$("#trial").is(':checked')) {
            alert("Por favor, selecione Obter versão de avaliação");
            $("#trial").focus();
            return false;
         }
         
         if (!$("#orcar").is(':checked')) {
            alert("Por favor, selecione solicitar orçamento");
            $("#orcar").focus();
            return false;
         }
         
         var valores = "";
         //VALIDA OPÇÕES SOLUÇÕES
         var n = $(".iradio:checked").length;
         if(n == 0){
              alert("Por favor, selecione uma ou mais Soluções.");
              $('op1').focus();
              return(false);
         }else{
             for(i=1; i<=16; i++){
                if(document.getElementById('op'+i).checked == true)
                    valores +=  document.getElementById('op'+i).value+"<br />";
             }
         }
         
         $('#submit').attr("disabled", true);
         
         $("#msg").html('Enviando!...');
         $("#msg").fadeIn("slow");
        
        $("#msg").ajaxStart(function(){
            //$(this).fadeIn("slow");
        });
        
        $("#msg").ajaxStop(function(){
            //$(this).fadeOut("slow");
            //$(".alvo").show();
        });

        $.post("includes/ajax/antivirusproposta_enviar.php", {empresa: escape( encodeURI( $('#empresa').val() ) ), 
                                                             nome_contato: escape( encodeURI( $('#nome_contato').val() ) ),
                                                             telefone: escape( encodeURI( $('#telefone').val() ) ),
                                                             ramal: escape( encodeURI( $('#ramal').val() ) ),
                                                             email: escape( encodeURI( $('#email').val() ) ),
                                                             cep: escape( encodeURI( $('#cep').val() ) ),
                                                             trial: escape( encodeURI( $('#trial').val() ) ),
                                                             orcar: escape( encodeURI( $('#orcar').val() ) ),
                                                             solucoes: escape( encodeURI( valores ) )
                                                            },
        function(data) {
            //Retorna 1 caso sucesso senao mensgens de erro
            if(data == '1'){
                $('#antivirus').hide();
                $('#antivirus_proposta_obrigado').fadeIn("slow");
            }
            else{
                $("#msg").html('');
                alert(data);
            }
        });
        
        $('#submit').removeAttr("disabled");
        
        //conteudoAjax.load('TESTE.php');
        return false;
    
	});
    
    //PARCEIROS
    $("#parceria").submit( function() {
         
         if ($("#nome_contato").val() == '') {
            alert("Por favor, informe o Seu Nome");
            $("#nome_contato").focus();
            return false;
         }
         
         if ($("#telefone").val() == '') {
            alert("Por favor, informe o Telefone");
            $("#telefone").focus();
            return false;
         }
         
		 if ($("#email").val() == ''){
            alert("Por favor, informe o E-mail");
            $("#email").focus();
            return false;
         }
         else{
			  var regmail = /^[\w!#$%&amp;'*+\/=?^`{|}~-]+(\.[\w!#$%&amp;'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
			  if (!regmail.test($("#email").val())) {
				   alert("E-mail inválido");
                   $("#email").focus();
				   return false;
			  }
		 }
         
         $('#submit').attr("disabled", true);
         
         $("#msg").html('Enviando!...');
         $("#msg").fadeIn("slow");
        
        $("#msg").ajaxStart(function(){
            //$(this).fadeIn("slow");
        });
        
        $("#msg").ajaxStop(function(){
            //$(this).fadeOut("slow");
            //$(".alvo").show();
        });

        $.post("includes/ajax/parceiros_enviar.php", {empresa: escape( encodeURI( $('#empresa').val() ) ), 
                                                        nome_contato: escape( encodeURI( $('#nome_contato').val() ) ),
                                                        telefone: escape( encodeURI( $('#telefone').val() ) ),
                                                        ramal: escape( encodeURI( $('#ramal').val() ) ),
                                                        fax: escape( encodeURI( $('#fax').val() ) ),
                                                        email: escape( encodeURI( $('#email').val() ) ),
                                                        uf: escape( encodeURI( $('#uf').val() ) ),
                                                        cidade: escape( encodeURI( $('#cidade').val() ) ),
                                                        endereco: escape( encodeURI( $('#endereco').val() ) ),
                                                        obs: escape( encodeURI( $('#obs').val() ) )
                                                        },
        function(data) {
            //Retorna 1 caso sucesso senao mensgens de erro
            if(data == '1'){
                $('#parceria').hide();
                $('#parceria_obrigado').fadeIn("slow");
            }
            else{
                $("#msg").html('');
                alert(data);
            }
        });
        
        $('#submit').removeAttr("disabled");
        
        //conteudoAjax.load('TESTE.php');
        return false;
    
	});
    
    
    
    //CADASTRO NEWSLETTER
    $("#form_newsletter").submit( function() {
    
         if ($("#nome").val() == '') {
            alert("Por favor, informe seu Nome");
            $("#nome").focus();
            return false;
         }
         
		 if ($("#email").val() == ''){
            alert("Por favor, informe o E-mail");
            $("#email").focus();
            return false;
         }
         else{
			  var regmail = /^[\w!#$%&amp;'*+\/=?^`{|}~-]+(\.[\w!#$%&amp;'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
			  if (!regmail.test($("#email").val())) {
				   alert("E-mail inválido");
                   $("#email").focus();
				   return false;
			  }
		 }
         
         $('#submit').attr("disabled", true);
         
         $("#box_newsletter_obrigado_txt").html('Enviando!...');
         $("#box_newsletter").hide();
         $("#box_newsletter_obrigado").fadeIn('slow');
         //$("#box_newsletter_obrigado_txt").fadeIn('slow');
         
        $("#box_newsletter_obrigado_txt").ajaxStart(function(){
            //$(this).fadeIn('slow');
        });
        
        $("#box_newsletter_obrigado_txt").ajaxStop(function(){
            //$(this).hide();
        });

        $.post("includes/ajax/newsletter_enviar.php", {nome:  escape( encodeURI( $('#nome').val() ) ), 
                                                       email:  escape( encodeURI( $('#email').val() ) )
                                                      },
        function(data) {
            if(data == '1'){
                $("#box_newsletter_obrigado_txt").html('Seu cadastro foi efetuado com sucesso.<br /><br />Obrigado.');
            }
            else{
                $("#box_newsletter_obrigado").hide(); 
                $("#box_newsletter").show();
                $("#box_newsletter_obrigado_txt").html('');
                alert(data);
            }
        });
        
        $('#submit').removeAttr("disabled");
        
        //conteudoAjax.load('TESTE.php');
        return false;
    
	});
    
    
    
    
    
    //PODEMOS AJUDAR
    $("#ajuda").submit( function() {
    
         if (trim($("#nome_contato").val()) == '') {
            alert("Por favor, informe o Seu Nome");
            $("#nome_contato").focus();
            return false;
         }
         
		 if ($("#mail").val() == ''){
            alert("Por favor, informe o E-mail");
            $("#mail").focus();
            return false;
         }
         else{
			  var regmail = /^[\w!#$%&amp;'*+\/=?^`{|}~-]+(\.[\w!#$%&amp;'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
			  if (!regmail.test($("#mail").val())) {
				   alert("E-mail inválido");
                   $("#mail").focus();
				   return false;
			  }
		 }
         
         if ($("#telefone").val() == '') {
            alert("Por favor, informe o Telefone");
            $("#telefone").focus();
            return false;
         }
         
         $('#submit').attr("disabled", true);
         
         $("#msg").html('Enviando!...');
         $("#msg").fadeIn("slow");
        
        $("#msg").ajaxStart(function(){
            //$(this).fadeIn("slow");
        });
        
        $("#msg").ajaxStop(function(){
            //$(this).fadeOut("slow");
            //$(".alvo").show();
        });

        $.post("includes/ajax/podemosajudar_enviar.php", {empresa: escape( encodeURI( $('#empresa').val() ) ), 
                                                        nome_contato: escape( encodeURI( $('#nome_contato').val() ) ),
                                                        telefone: escape( encodeURI( $('#telefone').val() ) ),
                                                        ramal: escape( encodeURI( $('#ramal').val() ) ),
                                                        email: escape( encodeURI( $('#mail').val() ) ),
                                                        mensagem: escape( encodeURI( $('#mensagem').val() ) )
                                                        },
        function(data) {
            //Retorna 1 caso sucesso senao mensgens de erro
            if(data == '1'){
                $('#podemos-ajudar').hide();
                $('#podemos-ajudar-obrigado').fadeIn("slow");
            }
            else{
                $("#msg").html('');
                alert(data);
            }
        });
        
        $('#submit').removeAttr("disabled");
        
        //conteudoAjax.load('TESTE.php');
        return false;
    
	});
    
    
    //OPORTUNIDADES SUBMIT FILE UPLOAD
    $('#oportunidades').ajaxForm({
        url: 'includes/ajax/oportunidade_enviar.php',
        dataType: 'html',
        beforeSubmit: validaOportunidades,
        success: function(data) {
            var $out = $('#msg');                    
            if (typeof data == 'object' && data.nodeType)
                data = elementToString(data.documentElement, true);
            else if (typeof data == 'object')
                data = objToString(data);
            if(data == '1'){
                $('#oportunidades').hide();
                $('#oportunidades_obrigado').fadeIn("slow");                
            }
            else
            {
                $out.html('');
                $('#curriculo_loading').hide();
                $('#curriculo').fadeIn("slow");
                alert(data);
            }
        },
        error: function(data) {
                $('#curriculo_loading').hide();
                $('#curriculo').fadeIn("slow");
                alert(data);
        }
    });
    
});


function validaOportunidades(){
         
         if (trim($("#curriculo").val()) == '') {
            alert("Por favor, informe o Currículo");
            $("#curriculo").focus();
            return false;
         }
         
         $('#msg').html('Enviando!...');
         $('#msg').fadeIn("slow");
         
         $('#curriculo').hide();
         $('#curriculo_loading').fadeIn("slow");
         
         return true;
         
}



