/* jquery form drop changer */

$(document).ready(function(){
	$('#campus_code').change( changeProgram );

	if ($('#BestTimeCall')) {
		$('#BestTimeCall').click(function() {
			if ($(this).val() == 'HH:MM') {
				$(this).val('');
			}
		});

		$('#BestTimeCall').blur(function() {
			if ($(this).val() == '') {
				$(this).val('HH:MM');
			}
		});
	}
});

function changeProgram() {
	var locValue = $("#campus_code option:selected").attr('sid');
	if (locValue) {
		$('#program_code').load('programdropdown/'+locValue, function() {
			$('#program_code').removeAttr('disabled');
		});
	} else {
	 if ($('#program_code')) {
		 $('#program_code').length = 1;
		 $('#program_code').attr('disabled', 'true');
	 }
	}
}

/* form processing */
DocumentUtil.onReady(function() {
	FormUtil.setupForm(config);
});

function showError() {
	$("#validation-message").show();
}

function hideError() {
	$("#validation-message").hide();
}

function showInputError(obj) {
	obj.className += ' error';

	var newObj = document.getElementById(obj.name + '_text');
	if (newObj) {
		newObj.className += ' error';
	}
}

function hideInputError(obj) {
	var classes = obj.className.split(" ");

	for (var i = 0; i < classes.length; i++) {
		if (classes[i] == 'error') {
			ArrayUtil.remove({array:classes, from:i});
			i--;
		}
	}

	obj.className = classes.join(" ");

	var newObj = document.getElementById(obj.name + '_text');
	if (newObj) {
		classes = newObj.className.split(" ");

		for (i = 0; i < classes.length; i++) {
			if (classes[i] == 'error') {
				ArrayUtil.remove({array:classes, from:i});
				i--;
			}
		}

		newObj.className = classes.join(" ");
	}
}
