jQuery.fn.invalid = function() {
	$(this).addClass('error');
};
jQuery.fn.resetform = function(clear) {
	$('#' + this.attr('id') + ' *').removeClass('error');	
	if (clear) {
		$('#' + this.attr('id') + ' input[type=text]').val('');
		$('#' + this.attr('id') + ' select').attr('selectedIndex', 0);
		$('#' + this.attr('id') + ' input[type=checkbox]:checked').attr('checked', false);
		$('#' + this.attr('id') + ' textarea').val('');
	}
};
jQuery.fn.validateCheckBox = function(div) {
	if (!$(this).attr('checked')) {
		if (div != null) div.invalid();
		$(this).invalid();
	}
};
jQuery.fn.validateEmail = function(required, div) {
	var regex = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	
	if (!((!required && $(this).val().length == 0) || regex.test($(this).val()))) {
		if (div != null) div.invalid();
		$(this).invalid();
		
		return false;
	}
	return true;
};
jQuery.fn.validateIndex = function(div) {
	if ($(this).attr('selectedIndex') == 0) {
		if (div != null) div.invalid();
		$(this).invalid();
		$(this).parent().invalid();
	}
}
jQuery.fn.validateNumeric = function(required, div) {
	var regex = /^-{0,1}\d*\.{0,1}\d+$/;
	
	if (!((!required && $(this).val().length == 0) || regex.test($(this).val()))) {
		div.invalid();
		$(this).invalid();
	}
}
jQuery.fn.validatePhoneNumber = function(required, div) {
	var us = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
	var intl = /^\+(?:[0-9] ?){6,14}[0-9]$/;
	
	if (!((!required && $(this).val().length == 0) || (us.test($(this).val()) || intl.test($(this).val())))) {
		div.invalid();
		$(this).invalid();		
	}
};
jQuery.fn.validateString = function(required, div) {
	if ($(this).val().length == 0) {
		if (div != null)
			div.invalid();
		$(this).invalid();
	}
};

