$(document).ready(function() {
	$("#registerForm").validate({
		submitHandler: function(form) {
			jQuery(form).ajaxSubmit({
				success: function (response, type, form) {
					var obj = eval("(" + response + ')') ;
					
					if(obj.success) {
						valid_dialog(LANG.register_send_confirmation, function () {
							window.location.href = './' ;
						}) ;
					}
					else {
						alert_dialog(obj.errors.reason) ;
					}
				}
			}) ;
		}
	}) ;
	
	function getSubcategories () {
		var category = $('#sitecat').attr('value') ;
		
		if(category != 'nothing') {
			$.post('register.php', { action: 'get-subcategories', category: category }, function(response){
				if(response.success) {
					document.getElementById('sitesubcat').innerHTML = response.html ;
				}
			}, 'json');
		}
	}
	
	$('#sitecat').change(function () { getSubcategories() ; }) ;
	$('#sitecat').keyup(function () { getSubcategories() ; }) ;
});