// JavaScript Document


	function clearForm(form) {
	  // iterate over all of the inputs for the form
	  // element that was passed in
	  
	  /// elimino anche tutti gli errori
	  $('input.error').removeClass("error");
	  $('span.error').remove();
	  $('label.error').remove();
	  
	  
	  
	  $(':input', form).each(function() {
	 var type = this.type;
	 var tag = this.tagName.toLowerCase(); // normalize case
	 // it's ok to reset the value attr of text inputs,
	 // password inputs, and textareas
	 if (type == 'text' || type == 'password' || tag == 'textarea')
	   this.value = "";
	 // checkboxes and radios need to have their checked state cleared
	 // but should *not* have their 'value' changed
	 else if (type == 'checkbox' || type == 'radio')
	   this.checked = false;
	 // select elements need to have their 'selectedIndex' property set to -1
	 // (this works for both single and multiple select elements)
	 else if (tag == 'select')
	   this.selectedIndex = -1;
	  });
	};


       
	  function BackToForm(){
			 
			 $("#result_form").html("");
			 $("#loading_form").hide();
			 $("#result_form").hide();
	         $("#FormContact").fadeIn();
			 
	  } 
	  
	  
	  
	  
	function OpenBoxLoginUtente(){
	        var div = document.getElementById("BoxLoginUtente");
			var form = div.getElementsByTagName("FORM")[0];
            
			clearForm(form);
			
			if(div.style.display=="none"){
				div.style.display="";
			}else{
				div.style.display="none";
			}
   }




$(document).ready(function() {
						   
						   
    $('#tab_software form').attr("id","loginForm2");			   				   
						   
						   
						   
	$("#loginForm").validate({
		submitHandler: function(form) { 


              //$(form).css('background-color', 'red');


               var parent = $(form).parent();
			   $(".loading_form", parent).fadeIn();
			   $(form).hide();

               var sendtojquery = "";
			   var f_username = $("#email", form).val();
			   var f_password = $("#password", form).val();
			   var f_action = $("#action", form).val();
			   var f_page = $("#page", form).val();
			   

			   clearForm(form);
			   

			   $.post("register2.php", { username: f_username, password: f_password, action:f_action, page:f_page, sendtojquery:"yes"},                function(data){
				       
					   $(".loading_form", parent).fadeOut();
					   $(".result_form", parent).fadeIn();
					   $(".result_form", parent).html(data);
					   
					   $("#button_form_back", parent).removeAttr("onclick");
					   $("#button_form_back", parent).click(function(){

							 $("#result_form, .result_form").html("");
							 $("#loading_form, .loading_form").hide();
							 $("#result_form, .result_form").hide();
							 $(form).show();

						});
					   
					   
				 });

			
		},			
		rules: {
			
			email: {
				required: true,
				email: true
			},
			
			password: {
				required: true,
				minlength: 5,
				maxlength: 8
			}
		},
		messages: {
		   email: {
				required: "Inserisci un indirizzo Email.",
				email: "Inserisci un indirizzo Email valido."
			},
			    password: {
				required: "Inserisci la Password",
				minLength: "La Password deve essere composta da 5 lettere minimo.",
				maxLength: "La Password deve essere composta da 8 lettere massimo."
			}
		}
		

		
	});

	


	$("#loginForm2").validate({
		submitHandler: function(form) { 


              //$(form).css('background-color', 'red');


               var parent = $(form).parent();
			   $(".loading_form", parent).fadeIn();
			   $(form).hide();

               var sendtojquery = "";
			   var f_username = $("#email", form).val();
			   var f_password = $("#password", form).val();
			   var f_action = $("#action", form).val();
			   var f_page = $("#page", form).val();
			   
			   clearForm(form);
			   

			   $.post("register2.php", { username: f_username, password: f_password, action:f_action, page:f_page, sendtojquery:"yes"},                       function(data){
				       
					   $(".loading_form", parent).fadeOut();
					   $(".result_form", parent).fadeIn();
					   $(".result_form", parent).html(data);
					   
					   $("#button_form_back", parent).removeAttr("onclick");
					   $("#button_form_back", parent).click(function(){

							 $("#result_form, .result_form").html("");
							 $("#loading_form, .loading_form").hide();
							 $("#result_form, .result_form").hide();
							 $(form).show();

						});
					   
					   
				 });

			
		},			
		rules: {
			
			email: {
				required: true,
				email: true
			},
			
			password: {
				required: true,
				minlength: 5,
				maxlength: 8
			}
		},
		messages: {
		   email: {
				required: "Inserisci un indirizzo Email.",
				email: "Inserisci un indirizzo Email valido."
			},
			    password: {
				required: "Inserisci la Password",
				minLength: "La Password deve essere composta da 5 lettere minimo.",
				maxLength: "La Password deve essere composta da 8 lettere massimo."
			}
		}
		

		
	});
						   
						   
						   




});
