
function validanome(){
	 if (document.order.first_name.value == '' || document.order.first_name.value == 'PRIMEIRO NOME'  || document.order.first_name.value == 'PREENCHA O CAMPO NOME') {
           document.order.first_name.value = "PREENCHA O CAMPO NOME";
		   document.order.first_name.style.background="url(images/bg_order_false.png)";
		  document.order.first_name.style.color="#c00";

		 return false;
		 
		}else{
     document.order.first_name.style.background="url(images/bg_order_true.png)";
 document.order.first_name.style.color="#7eb5c8";

   return true;
		}
 }
 function validalast(){
	 if (document.order.last_name.value == '' || document.order.last_name.value == 'SOBRENOME' || document.order.last_name.value == 'PREENCHA O CAMPO SOBRENOME') {
           document.order.last_name.value = "PREENCHA O CAMPO SOBRENOME";
		   document.order.last_name.style.background="url(images/bg_order_false.png)";
		  document.order.last_name.style.color="#c00";

		 return false;
		 
		}else{
     document.order.last_name.style.background="url(images/bg_order_true.png)";
 document.order.last_name.style.color="#7eb5c8";
  return true;

		}
 }	
 
  function validacompany_name(){
	 if (document.order.company_name.value == '' || document.order.company_name.value == 'NOME DA EMPRESA' || document.order.company_name.value == 'PREENCHA O CAMPO NOME DA EMPRESA') {
           document.order.company_name.value = "PREENCHA O CAMPO NOME DA EMPRESA";
		   document.order.company_name.style.background="url(images/bg_order_false.png)";
		  document.order.company_name.style.color="#c00";

		 return false;
		 
		}else{
     document.order.company_name.style.background="url(images/bg_order_true.png)";
 document.order.company_name.style.color="#7eb5c8";
   return true;

		}
 }	
 
  function validaendereco(){
	 if (document.order.endereco.value == '' || document.order.endereco.value == 'ENDEREÇO' || document.order.endereco.value == 'PREENCHA O CAMPO ENDEREÇO') {
           document.order.endereco.value = "PREENCHA O CAMPO ENDEREÇO";
		   document.order.endereco.style.background="url(images/bg_order_false.png)";
		  document.order.endereco.style.color="#c00";

		 return false;
		 
		}else{
     document.order.endereco.style.background="url(images/bg_order_true.png)";
 document.order.endereco.style.color="#7eb5c8";
   return true;

		}
 }	
 
 function validacity(){
	 if (document.order.city.value == '' || document.order.city.value == 'CIDADE' || document.order.city.value == 'PREENCHA O CAMPO CIDADE') {
           document.order.city.value = "PREENCHA O CAMPO CIDADE";
		   document.order.city.style.background="url(images/bg_order_false.png)";
		  document.order.city.style.color="#c00";

		 return false;
		 
		}else{
     document.order.city.style.background="url(images/bg_order_true.png)";
 document.order.city.style.color="#7eb5c8";
   return true;
		}
 }	
 
 function validastate(){
	 if (document.order.state.value == '' || document.order.state.value == 'ESTADO' || document.order.state.value == 'PREENCHA O CAMPO ESTADO') {
           document.order.state.value = "PREENCHA O CAMPO ESTADO";
		   document.order.state.style.background="url(images/bg_order_false.png)";
		  document.order.state.style.color="#c00";

		 return false;
		 
		}else{
     document.order.state.style.background="url(images/bg_order_true.png)";
 document.order.state.style.color="#7eb5c8";
   return true;
		}
 }	
 
  function validacountry(){
	 if (document.order.country.value == '' || document.order.country.value == 'PAÍS' || document.order.country.value == 'PREENCHA O CAMPO PAÍS') {
           document.order.country.value = "PREENCHA O CAMPO PAÍS";
		   document.order.country.style.background="url(images/bg_order_false.png)";
		  document.order.country.style.color="#c00";

		 return false;
		 
		}else{
     document.order.country.style.background="url(images/bg_order_true.png)";
 document.order.country.style.color="#7eb5c8";
   return true;
		}
 }	
 
 function validaemail(email)
    {
		 if (document.order.email.value == '') {
			document.order.email.value = "PREENCHA O CAMPO E-MAIL";
		   document.order.email.style.background="url(images/bg_order_false.png)";
		    document.order.email.style.color="#c00";   
		 return false;
		 
		
		}
     
      
  if (document.order.email.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) {
       
			
			  document.order.email.style.background="url(images/bg_order_false.png)";
			  $("#alert_email").css("display","block");
			 $('#alert_email').html('DIGITE UM E-MAIL VÁLIDO');
			
			  
          return false; 	
 
        } else {
			document.order.email.style.background="url(images/bg_order_true.png)";
 document.order.email.style.color="#000";
    $("#alert_email").css("display","none");
  $('#alert_email').html('');
  return true;
        }
    }
 


 
     function validapass(){
	 if (document.order.pass.value == '' || document.order.pass.value == 'SENHA' || document.order.pass.value == 'PREENCHA O CAMPO SENHA') {
           document.order.pass.value = "PREENCHA O CAMPO SENHA";
		   document.order.pass.style.background="url(images/bg_order_false.png)";
		  document.order.pass.style.color="#c00";
	 document.order.pass.type="text";
		 return false;
		 
		} if (document.order.pass.value != '') {
     document.order.pass.style.background="url(images/bg_order_true.png)";
	   return true;

		}
 }	
 
  function validapass_confirm(){
	 if (document.order.confirm_pass.value != $('#pass').val()) {
           document.order.confirm_pass.value = "CONFIRME A SENHA";
		   document.order.confirm_pass.style.background="url(images/bg_order_false.png)";
		  document.order.confirm_pass.style.color="#c00";
	 document.order.confirm_pass.type="text";
		 return false;
		 
		} if (document.order.confirm_pass.value != '') {
     document.order.confirm_pass.style.background="url(images/bg_order_true.png)";
	   return true;

		}
 }	 
 
 

 
   function validacompany(){
	 if ($('textarea[name=company]').val() == '_digite aqui') {
          
  $('p#company_p').css("color","#c00");
    $('p#company_p').css("font-size","15px");
		 return false;
		 
		}else{
    

  $('p#company_p').css("color","#21556E");
    $('p#company_p').css("font-size","13px");
   return true;
		}
 }	
 
     function validaabout(){
	 if ($('textarea[name=about]').val() == '_digite aqui') {
          
  $('p#about_p').css("color","#c00")
    $('p#about_p').css("font-size","15px")
		 return false;
		 
		}else{
    

  $('p#about_p').css("color","#21556E");
    $('p#about_p').css("font-size","13px");
   return true;
		}
 }	
 
      function validawords_relationed(){
	 if ($('textarea[name=words_relationed]').val() == '_digite aqui') {
          
  $('p#words_relationed_p').css("color","#c00");
    $('p#words_relationed_p').css("font-size","15px");
		 return false;
		 
		}else{
    

  $('p#words_relationed_p').css("color","#21556E")
    $('p#words_relationed_p').css("font-size","13px")
   return true;
		}
 }	
 

       function validacolors(){
	 if ($('textarea[name=colors]').val() == '_digite aqui') {
      
  $('p#colors_p').css("color","#c00");
    $('p#colors_p').css("font-size","15px");
	 console.log()
		 return false;
		 
		}else{
   

  $('p#colors_p').css("color","#21556E");
    $('p#colors_p').css("font-size","13px");
   return true;
		}
 }	
 
 

 function validaradio(){
	
	 if (!document.order.escolhe1.checked && !document.order.escolhe2.checked) {
      console.log($('input[name=escolhe]').val());
  $('p#options_p').css("color","#c00");
    $('p#options_p').css("font-size","15px");
	
		 return false;
		 
		}else{
    

  $('p#options_p').css("color","#21556E");
    $('p#options_p').css("font-size","13px");
 return true;

		}
 }	
	 
  								 
  
  $(document).ready(function() {  
							 
							 $("#order").keypress(function(e) {
  if (e.which == 13) {
    return false;
  }
});
							 
							 
  $("img.SendOrder").click(function() { //if click

//validate data one more time
			if(validanome()==1 && validalast()==1 && validacompany_name()==1 && validacity()==1 && validastate()==1 && validacountry()==1 && validaemail()==1 && validapass()==1 && validapass_confirm()==1 && validacompany()==1 && validaabout()==1 && validawords_relationed()==1 && validacolors()==1 && validaradio()==1){
				
				
					$('#results').html('Enviando pedido... um momento.');			 
								 
					var str = $("form").serialize();
					
					console.log(str);

            $.ajax ({
					
                url: "send_data.php",

                type: "post",

                data: str, 

                success: function () {

					  
					setTimeout("window.location='enviado.php'", 2000);
	
				
						

					
$(':input').clearForm();
             
                }
				
				
		   

            });	return false;		 
			} else {
				
				alert('Preencha corretamente o formulário!')
			}
								 
								 }); 
  	 });

  
	$.fn.clearForm = function() {

  return this.each(function() {

	var type = this.type, tag = this.tagName.toLowerCase();

	if (tag == 'form')

	  return $(':input',this).clearForm();

	if (type == 'text' || type == 'password' || tag == 'textarea')

	  this.value = '';

	else if (type == 'checkbox' || type == 'radio')

	  this.checked = false;

	else if (tag == 'select')

	  this.selectedIndex = -1;

  });

};
