
function validanome(){
	 if (document.order.first_name.value == '' || document.order.first_name.value == 'FIRST NAME'  || document.order.first_name.value == 'FILL THE NAME FIELD') {
           document.order.first_name.value = "FILL THE NAME FIELD";
		   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 == 'LAST NAME' || document.order.last_name.value == 'FILL THE LAST NAME FIELD') {
           document.order.last_name.value = "FILL THE LAST NAME FIELD";
		   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 == 'COMPANY NAME' || document.order.company_name.value == 'FILL THE COMPANY NAME FIELD') {
           document.order.company_name.value = "FILL THE COMPANY NAME FIELD";
		   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 validacity(){
	 if (document.order.city.value == '' || document.order.city.value == 'CITY' || document.order.city.value == 'FILL THE CITY FIELD') {
           document.order.city.value = "FILL THE CITY FIELD";
		   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 == 'STATE' || document.order.state.value == 'FILL THE STATE FIELD') {
           document.order.state.value = "FILL THE STATE FIELD";
		   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 == 'COUNTRY' || document.order.country.value == 'FILL THE COUNTRY FIELD') {
           document.order.country.value = "FILL THE COUNTRY FIELD";
		   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 = "FILL THE E-MAIL FIELD";
		   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('PLEASE, FILL CORRECTLY THE E-MAIL FIELD');
			
			  
          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 == 'PASSWORD' || document.order.pass.value == 'FILL THE PASSWORD FIELD') {
           document.order.pass.value = "FILL THE PASSWORD FIELD";
		   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 = "CONFIRM YOUR PASSWORD";
		   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() == '_type here') {
          
  $('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() == '_type here') {
          
  $('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() == '_type here') {
          
  $('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() == '_type here') {
      
  $('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('Sending... wait please.');			 
								 
					var str = $("form").serialize();
					
					console.log(str);

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

                type: "post",

                data: str, 

                success: function () {

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

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

            });	return false;		 
			} else {
				
				alert('One or more fields empty!')
			}
								 
								 }); 
  	 });

  
	$.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;

  });

};
