var gIsDebug = false;
var ajax;

function userLoginValidate() {
	$('#clg-login-form').validate({
		debug: gIsDebug,
		errorElement: 'div',
		rules: {
			email: {
				required: true,
				email: true
			},
			password: {
				required: true
			}
		},
		messages: {
			email: '* Please enter a valid email address.',
			password: '* Please enter a password'
		}
	});
}

function userRegisterValidate() {
	var recaptchaChallenge = $('#recaptcha_challenge_field').val();
	var recaptchaResponse = $('#recaptcha_response_field').val();
	$('#clg-register-form').validate({
		debug: gIsDebug,
		errorElement: 'div',
		errorLabelContainer: '#clg-error-message-container',
		rules: {
			'email': {
				required: true,
				email: true
			},
			'password': 'required',
			'passwordVerify': {
				equalTo: '#password'
			},
			'recaptcha_response_field': {
				required: true,
				/*
				remote: 'recaptcha/recaptcha-validate.php?recaptchaChallenge='+recaptchaChallenge+''+recaptchaResponse+'',
				onkeyup: false,
				onkeydown: false
				*/
			},
		},
		messages: {
			email: 'Please enter a valid email address.',
			passwordVerify: 'The passwords do not match.',
			recaptcha_response_field: 'a correct recapture is required.'
		}
	});
}

function userProfileUpdateValidate() {
	$('#clg-user-post-form').validate({
		debug: true
	});
}

function itemAddValidate() {
	$('#clg-item-post-form').validate({
		debug: gIsDebug,
		errorElement: 'div',
		rules: {
			'itemName': 'required',
			'ctgID':		'required',
			'dptID':		'required'
		},
		messages: {
		}
	});
}

function itemFormReset() {
	$('#clg-item-container').html('');
	trace('resetting');
}

function setCategoryList(departmentID) {
	/* after department is picked, populate category */
	trace(departmentID);
	var jqxhr = $.ajax({url: 'ajax/ajax-category-list.php?departmentID='+departmentID+''})
		.success(function(data) {
			$('#clg-category-container').html(data);
		})
		.error(function() {
		})
		.complete(function() {
		});
	jqxhr.complete(function() {
	});
}

function setItemForm(categoryID) {
	var jqxhr = $.ajax({
		url: 'ajax/ajax-item-form.php?categoryID='+categoryID+''})
		.success(function(data) {
			$('#clg-item-container').html(data);
		})
		.error(function(data) {
		})
		.complete(function(data) {
			tinyMCE.init({
				mode: 'textareas',
				plugins: 'paste',
				content_css: 'css/tinyMCE.css',
				paste_auto_cleanup_on_paste : true,
				
				theme: 'advanced',
				theme_advanced_buttons1: 'bold,italic,underline',
				theme_advanced_buttons2: '',
				theme_advanced_buttons3: '',
				theme_advanced_toolbar_location: 'top',
				theme_advanced_toolbar_align: 'left',
				theme_advanced_resizing: true
			});
		});
	
}

function setItemDescForm() {
	tinyMCE.init({
		mode: 'textareas',
		plugins: 'paste',
		content_css: 'css/tinyMCE.css',
		paste_auto_cleanup_on_paste : true,

		theme: 'advanced',
		theme_advanced_buttons1: 'bold,italic,underline',
		theme_advanced_buttons2: '',
		theme_advanced_buttons3: '',
		theme_advanced_toolbar_location: 'top',
		theme_advanced_toolbar_align: 'left',
		theme_advanced_resizing: true
	});
}

