// ajax_register.js v1.1
// copyright 2008
// Easy2play BV

$(document).ready(function() {

	switch($("#reglng").val()) {
		case "nl":
		  var msg1 = " De gebruikersnaam is niet ingevuld.";
		  var msg2 = " Het wachtwoord is niet ingevuld.";
		  var msg3 = " Het email adres is niet ingevuld.";
		  var msg4 = " Je dient akkoord te gaan met de spelregels en condities door het vinkje aan te vinken.";
		  var msg6 = " Dit e-mailadres is al geregistreerd.";
		  var msg7 = " E-mail adres is niet correct.";
		  break;   
		default: // default and english
		  var msg1 = " You did not fill in a user name.";
		  var msg2 = " You did not fill in a password.";
		  var msg3 = " You did not fill in an e-mailaddress.";
		  var msg4 = " Please agree with our terms and conditions.";
		  var msg6 = " This emailaddress is allready registered with us.";
		  var msg7 = " Incorrect email address.";
	} 
	
	// Validate input register form
	$("#register_form").submit(function() {

		if ($("#reg_user").val() == '') {
			alert(msg1);
			$("#reg_user").focus();
			return false;
		}
		
		if ($("#reg_pw").val() == '') {
			alert(msg2);
			$("#reg_pw").focus();
			return false;
		}
		
		if ($("#reg_email").val() == '') {
			alert(msg3);
			$("#reg_email").focus();
			return false;
		}
		
		if ($('#reg_ok:checked').val() != 'yes') {
			alert(msg4);
			$("#reg_ok").focus();
			return false;	
		}
	});
	
	// Check if email is allready registered
	$("#reg_email").blur(function() {		
		if ($("#reg_email").val() != '') {
				$("#reg_emailcheck").removeClass().addClass('ajaxok').html('<img src="img/loading_red_small.gif" width="15" height="15"> Checking...').fadeIn("fast");
				$.post("inc/functions/ajax_checkemail.php",{ email:$(this).val() 
			} 
			,function(data) {
		  	if(data=='no') {
		  		$("#reg_emailcheck").fadeTo(200,0.1,
		  			function() {
			  			$(this).removeClass().addClass('ajaxerror').html('<img src="img/error.gif" width="15" height="15"> '+msg6).fadeTo(900,1,
				  			function(){ 
				  				if(jQuery.browser.msie) this.style.removeAttribute('filter');
				  			});	
			  			$("#reg_email").val('');
			  			$("#reg_email").focus();
						});		
				} else if(data=='yes') {
					$("#reg_emailcheck").fadeTo(200,0.1,
						function() {
			  			$(this).removeClass().addClass('ajaxok').html('<img src="img/ok.gif" width="15" height="15"> OK.').fadeTo(900,1,
				  			function(){ 
				  				if(jQuery.browser.msie) this.style.removeAttribute('filter');
				  			});	
						});
				} else {
					$("#reg_emailcheck").fadeTo(200,0.1,
		  			function() {
			  			$(this).removeClass().addClass('ajaxerror').html('<img src="img/error.gif" width="15" height="15"> '+msg7).fadeTo(900,1,
				  			function(){ 
				  				if(jQuery.browser.msie) this.style.removeAttribute('filter');
				  			});	
			  			$("#reg_email").val('');
			  			$("#reg_email").focus();
						});	
		  	}
			});
		} // end val !=''
	});
	
});