// JavaScript Document
function check_form(){
	var form       = document.getElementById('signup_form') ;
	
	var validate_code = document.getElementById('validate_code');
	var username   = document.getElementById('signup_username');
	var password   = document.getElementById('signup_password');
	var pwd_again  = document.getElementById('password');
	var first      = document.getElementById('signup_first');
	var last       = document.getElementById('signup_last');
	var number     = document.getElementById('signup_number');
	var country    = document.getElementById('signup_country');
	var postcode   = document.getElementById('signup_postcode');
	var email      = document.getElementById('signup_email');
	var date_birth = document.getElementById('signup_data');
	var gender     = document.getElementById('signup_gender');
	var conditions = document.getElementById('signup_conditions');
	
	/*form.action = 'v_reg.php' ;
	form.submit() ;*/
	if(is_empty(username.value)){
		alert(LANG.empty_username);
		username.focus();
		return false;
	}else if(username.value.length > 16){
		alert(LANG.large_username);
		username.select();
		return false;
	}else if(!is_username(username.value)){
		alert(LANG.error_username);
		username.select();
		return false;
	}else if(is_empty(password.value)){
		alert(LANG.empty_password);
		password.focus();
		return false;
	}else if(password.value.indexOf(" ") != -1){
		alert(LANG.spaces_error);
		password.select();
		return false;
	}else if(password.value.length < 6 || password.value.length > 16){
		alert(LANG.length_error);
		password.select();
		return false;
	}else if(is_empty(pwd_again.value)){
		alert(LANG.empty_pwd_again);
		pwd_again.focus();
		return false;
	}else if(pwd_again.value.indexOf(" ") != -1){
		alert(LANG.pwd_again_spaces_error);
		pwd_again.select();
		return false;
	}else if(pwd_again.value != password.value){
		alert(LANG.pwd_differ);
		password.select();
		return false;
	}else if(is_empty(first.value)){
		alert(LANG.empty_first);
		first.focus();
		return false;
	}else if(is_empty(last.value)){
		alert(LANG.empty_last);
		last.focus();
		return false;
	}else if(isNaN(number.value)){
		alert(LANG.not_number);
		number.select();
		return false;
	}else if(is_empty(country.value)){
		alert(LANG.empty_country);
		country.focus();
		return false;
	}else if(isNaN(postcode.value)){
		alert(LANG.not_post);
		postcode.select();
		return false;
	}else if(is_empty(email.value)){
		alert(LANG.empty_email);
		email.focus();
		return false;
	}else if(!is_email(email.value)){
		alert(LANG.email_error);
		email.select();
		return false;
	}else if(is_empty(date_birth.value)){
		alert(LANG.empty_date);
		date_birth.focus();
		return false;
	}else if(is_empty(validate_code.value)){
		alert(LANG.empty_validation);
		validate_code.focus();
		return false;
	}else if(!conditions.checked){
		alert(LANG.not_conditions);
		conditions.focus();
		return false;
	}
	form.action = 'v_reg.php' ;
}
function validate_name(user){
	$.ajax({
		   type: "GET",
		   url: "v_validate_username.php?v_username="+user,
		   success: function(msgs){
			   if(msgs == 'null'){
					$('#validate_result').html("<span style='color:#F00; font-size:12px; font-weight:bold;'><strong>" + LANG.empty_username + "</strong></span>");  
			   }else if(msgs == 'SPACE'){
			   		$("#validate_result").html("<span style='color:#F00; font-size:12px; font-weight:bold;'><strong>" + LANG.error_username + "</strong></span>");
			   		$('#signup_username').select() ;
			   }else if(msgs == 'ERROR'){
			   		$("#validate_result").html("<span style='color:#F00; font-size:12px; font-weight:bold;'><strong>" + LANG.used_username + "</strong></span>");
			   		$('#signup_username').select() ;
			   }else{
				   $("#validate_result").html("");
			   }
		   }
	});
}

function validate_email(mail){
	$.ajax({
		   type:"GET",
		   url: "v_validate_email.php?v_email="+mail,
		   success: function(msgm){
			   if(msgm == 'nulls'){
					$('#validate_email').html("<span style='color:#F00; font-size:12px; font-weight:bold;'><strong>" + LANG.empty_email + "</strong></span>");
				}else if(msgm == 'email'){
					$('#validate_email').html("<span style='color:#F00; font-size:12px; font-weight:bold;'><strong>" + LANG.email_error + "</strong></span>");
					$('#signup_email').select();
				}else{
		   			$('#validate_email').html("");
				}
		   }
	})
}

function validate_validate_code(validate){
	$.ajax({
		 type:"GET",
		 url :"validate_validate_code.php?v_validate="+validate,
		 success: function(msg){
			if(msg == 'null'){
				$("#validate_validate").html("<span style='color:#F00; font-size:12px; font-weight:bold;'><strong>" + LANG.empty_validation + "</strong></span>");
			}else if(msg == 'ERROR'){
				$("#validate_validate").html("<span style='color:#F00; font-size:12px; font-weight:bold;'><strong>" + LANG.validation_error + "</strong></span>");	
				$("#validate_code").select();
			}else{
				$("#validate_validate").html('');	
			}
		}
	})
}
