$(document).ready(
	function() {
		$(".clear-form").click(
			function() {
				var check = confirm('Are you sure you want to clear this form?');
				if(check) {
					var form = $("#" + $(this).attr('name'));
					form.clearForm();
				}
			}
		);
	}
);

$.fn.clearForm = function() {
	return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
			return $(':input',this).clearForm();
		if (type == 'text' || type == 'password' || tag == 'textarea')
			this.value = '';
		else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
		else if (tag == 'select')
			this.selectedIndex = -1;
	});
};

var resetInvalidFields = function(form) {
	$("*", form).removeClass('error-field');
};

var setInvalidField = function(field) {
	$(field).addClass('error-field');
};

var setFormSubmitted = function(form, message) {
	$(".error").hide();
	$(".success", form).html(message);
};

//client get user id
var getUserID = function() {
	var userID = null;
	
	$.ajax({
		url: 'ajax.php',
		type: 'post',
		data: ({
			action: 'get-user-id'
		}),
		async: false,
		success: function(data) {
			userID = data;
		}
	});
	return userID;
};
