/**
 * @author Programmer
 */
var mail_exist;

$(document).ready(function(){


	$(".centered").center({
		horizontal: false
	});
	
//	$("#actie-right-form .submit").click(function() {$("#actie-right-form").submit(); return false;});
	$("#probe-form .submit").click(function() {
		check_form2('probe-form');
		return false;
		});	
	$("#actie-right-form .submit").click(function() {
		check_form2('actie-right-form');
		return false;
		});		

});

function check_form2( idk )
{
	var and_what = 0;
	var and_pass = 0;
 
	jQuery("#" + idk + " input.check").each(function ( loop ) {
 
		if( jQuery(this).val() == '' || ( jQuery(this).hasClass("email") && !IsEmailCorrect2( jQuery(this).val() ) ) || jQuery(this).val() == jQuery(this).attr("rel") )
		{
			jQuery(this).addClass("error");
			and_what = 1;
		}
		else if (jQuery(this).hasClass("password") && (jQuery(this).val().length<6 || jQuery(this).val()!=jQuery("#" + idk + " .password_retype").val()))
		{
			jQuery(this).addClass("error");
			jQuery("#" + idk + " .password_retype").addClass("error");
			and_pass = 1;
		}
		else
		{
			if (and_pass!=1 || !jQuery(this).hasClass('password_retype')) jQuery(this).removeClass("error");
		}
 
	});
 	//alert(and_what);
	if(and_what == 1)
	{
		alert("Vul de verplichte velden.");
		 if (and_pass == 1)
			{
				alert("Password must have minimum 5 chars, and will the same in password field and retype password fild.");
			}
		return false;
	}
	else
	{
	
		jQuery("#" + idk + " input").each(function () {
		
			if( jQuery(this).val() == jQuery(this).attr("rel") )
				jQuery(this).val('');
				
		
		});
		
		jQuery( "#"+idk ).submit();
		return true;
	}
 
}

function IsEmailCorrect2(email) { 
  if (email.match(/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,3})$/)!=null) 
  	{
		jQuery.post("/ajax.php", { "option": "check_mail", "mail": email},
		function(data){
			if (data==1)
				{
				mail_exist=1;
				}
				else
				mail_exist=0;

	   });					
		if (mail_exist==1) 
			{
				alert('Your email is in our database'); 
				return false;
			}
			else 
			return true;
	}
	else
	return false;
 
}
