/********************************************
*
* 	FORM CHECK
*
*********************************************/
/*
	CLASS
*/

var InputValidate = new Class ({	
	Implements: [Events, Options],
	options: {
		errorMsg: 'This field is required.'
	
	},
	initialize: function(options) {
		this.setOptions(options);
	},
	test: function(element){
		
		if (element.type == 'select-one' || element.type == 'select')
			return !(element.selectedIndex >= 0 && element.options[element.selectedIndex].value != '');
		else
			return ((element.get('value') == null) || (element.get('value').length == 0));
	},
	isEmpty: function(input){
		return this.test(input);
	},
	getMsg: function(){
		return this.options.errorMsg;
	},
	marked: function(input){
		if(input.getStyle('border-width').toInt() != 4){
			input.setStyle('width', (input.getStyle('width')).toInt() - 8);
			input.tween('border', '4px solid #ff0000');
			input.focus();
		}
	},
	unmarked: function(input){
		if(input.getStyle('border-width').toInt() == 4){
			input.setStyle('border-width', '1px');
			input.setStyle('width', (input.getStyle('width')).toInt() + 8);
			input.setStyle('border-color', '#b5bfc4');
		}
	}
});

/*
	Function
*/
	var isEmpty = new InputValidate({
		errorMsg: 'This field is required.'
	});
	
function checkForm(form){
	

	var inputs = $(form).getElements('input');
	var c = inputs.length;
	
	for(i=0; i<c; i++){
		var input = inputs[i];
		if(input.hasClass('required')){
			if(isEmpty.test(input)) {
				
				isEmpty.marked(input);
				
				return false;
			}
			else{
				isEmpty.unmarked(input);

			}
		}
	}

	return true;
}
/*
	The end of FormCheck
*/
