function is_numeric( mixed_var ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: David
    // *     example 1: is_numeric(186.31);
    // *     returns 1: true
    // *     example 2: is_numeric('Kevin van Zonneveld');
    // *     returns 2: false
    // *     example 3: is_numeric('+186.31e2');
    // *     returns 3: true
 
    return !isNaN( mixed_var );
}


$(document).ready(function()
{
	// foto
	$('#profileImage').click(function()
		{
			$('#upload').show();
		}
	);
	
	
	function ajaxFileUpload()
	{
		//starting setting some animation when the ajax starts and completes
		$("#loading")
		.ajaxStart(function(){
			$("#imageForm").hide();
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
			$("#upload").hide();
			$("#imageForm").show();
		});
		
		$.ajaxFileUpload
		(
			{
				url:'../php/ajax_profileImage.php', 
				secureuri:false,
				fileElementId:'uploadImage_field',
				dataType: 'json',
				success: function (data, status)
				{
					if(data.msg != '') {
						$('div#profileImage div#image').css("background-image", "url("+path+"upload/temp/profiles/"+data.msg+".jpg)"); 
						$('input#inputImage').val(data.msg);
					}
				},
				error: function (data, status, e)
				{
					//alert(e);
				}
			}
		)
		
		return false;
	}
	
	// 
	$("#imageForm").submit(function()
	{
		ajaxFileUpload();
		return false;
	});
	
	
	// formulier submitten
	$('#registrateForm div.submit').click(function()
		{
			$("#registrateForm").submit();
		}
	);
	
	
	// formulier valideren
	$("#registrateForm").validate({
		errorPlacement:	function(error, element) {	
		},
		rules: {
			reg_username: {
				required: true,
				minlength: 2
			},
			reg_password: {
				required: true,
				minlength: 2
			},
			reg_conf_password: {
				equalTo: "#reg_password"
			},
			reg_email: {
				required: true,
				email: true
			},
			reg_naam: {
				required: true,
				minlength: 2
			},
			reg_voornaam: {
				required: true,
				minlength: 2
			},
			reg_geboortedatum: {
				required: true,
				dateISO: true
			}
		},
		messages: {

		},
		submitHandler: function()
		{
			var myData = $("#registrateForm").serialize();
			$.post("../php/ajax_registrate.php", myData, function(data)
			{
				if(data == 'succes') {
					var regName = $("#registrateForm #reg_username").attr('value');
					var regMail = $("#registrateForm #reg_email").attr('value');
					$("#regName").html(regName);
					$("#regMail").html(regMail);
					$("#imageForm").hide();
					$("#registrateForm").hide();
					$("#success").show();
				}
				
			});
		}
	});
	
	
	// formulier submitten
	$('#editProfileForm div.submit').click(function()
		{
			$("#editProfileForm").submit();
		}
	);
	
	// formulier valideren
	$("#editProfileForm").validate({
		errorPlacement:	function(error, element) {	
		},
		rules: {
			reg_password: {
				required: false,
				minlength: 2
			},
			reg_conf_password: {
				equalTo: "#reg_password"
			},
			reg_email: {
				required: true,
				email: true
			},
			reg_naam: {
				required: true,
				minlength: 2
			},
			reg_voornaam: {
				required: true,
				minlength: 2
			},
			reg_geboortedatum: {
				required: true,
				dateISO: true
			}
		},
		messages: {

		},
		submitHandler: function()
		{
			var myData = $("#editProfileForm").serialize();
			$.post(path+"php/ajax_editprofile.php", myData, function(data)
			{
				window.location.href=path+'members/detail/'+data;			
			});
		}
	});
	
	
	
	// lostpassForm
	$('div#lostpassSubmit').click(function()
	{
		$('#lostpassForm').submit();
	});
	
	$('#lostpassForm').validate({
		errorPlacement:	function(error, element){},
		rules: {
			lost_username: {
				required: {
					depends: function(element) {
						if($("#lost_email").val()!='') {
							return false;
						} else {
							return true;
						}
					}
				},
				minlength: 2
			},
			lost_email: {
				required: {
					depends: function(element) {
						if($("#lost_username").val()!='') {
							return false;
						} else {
							return true;
						}
					}
				},
				email: true
			}
		},
		messages: {},
		submitHandler: function()
		{
			var myData = $("#lostpassForm").serialize();
			$.post(path+"php/ajax_lostpass.php", myData, function(data)
			{
				if(data=='error') {
					$('#lost_username').addClass('error');
					$('#lost_email').addClass('error');
				} else {
					$('#lostpassFormDiv').hide();
					$('#lostpassSend').show();
				}	
			});
		}
	});
	

});
