

/**
 * jQuery brTip plugin
 * This jQuery plugin was inspired and based on various other plugins of tooltip, but this is better =)
 * @name jquery-brtip-1.1.js
 * @author Gabriel Sobrinho - gabriel.sobrinho@gmail.com
 * @version 1.1
 * @date March 04, 2008
 * @category jQuery plugin, User Interface
 * @copyright (c) 2008 Gabriel Sobrinho (gabriel.sobrinho@gmail.com)
 * @license CC Attribution 3.0 Unported - http://creativecommons.org/licenses/by/3.0/deed.en_US
 * @example Visit http://plugins.jquery.com/project/brTip for more informations about this jQuery plugin
 */

eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(3($){$.S.7=3(c){c=$.R({m:\'\',o:\'\',C:y,w:Q,j:0.8,g:-1,d:W,6:\'V\',4:h,i:h,l:h,9:\'\'},c);3 u(){H(c.i);H(c.l)}3 v(){u();G(!c.4){c.4=$(\'<5 p="7-4"><5 p="7-6">&F;</5><5 p="7-E">&F;</5></5>\').Y(\'X\');c.4.B(\'j\',c.j)}c.4.A(\'5.7-6\').D(c.6);c.4.A(\'5.7-E\').D(c.9);c.i=n(3(){c.4.m(c.m)},c.C)}3 z(){c.l=n(3(){c.4.o(c.o)},c.w)}3 f(a,b){G(c.4){c.4.B({g:a+c.g,d:b+c.d})}U{n(3(){f(a,b)},y)}}T q.P(3(){t b=$(q);b.s(3(){c.9=b.k(\'6\');b.k(\'6\',\'\');v()}).r(3(){b.k(\'6\',c.9);c.9=\'\';z()}).O(3(e){f(e.N,e.M)}).L(3(){b.x(\'s\');t a=b.K();f(a.g+(b.J()/2),a.d+(b.I()/2))}).Z(3(){b.x(\'r\')})})}}(10));',62,63,'|||function|box|div|title|brTip||txt||||left||_setPos|top|null|delayToShow|opacity|attr|delayToHide|fadeIn|setTimeout|fadeOut|class|this|mouseout|mouseover|var|_clearTimes|_create|toHide|trigger|100|_hide|find|css|toShow|html|content|nbsp|if|clearTimeout|height|width|offset|focus|pageX|pageY|mousemove|each|500|extend|fn|return|else|Help|15|body|appendTo|blur|jQuery'.split('|'),0,{}));

function validateForm(form, rules) {
	//clear out any old errors
	$("#messages").html("");
	$("#messagesOuter").slideUp();
	$(".error-message").hide();
  
	//loop through the validation rules and check for errors
	$.each(rules, function(field) {
//		var val = $.trim($("#" + field).val());
		var val = $.trim($("#" + field).val()).replace(/\n/g, ' '); //removes \n for textarea controls
		$("#" + field).parent().removeClass("error");

		$.each(this, function() {
//			console.log(this['rule']);
	      
			//check if the input exists
			if ($("#" + field).attr("id") != undefined) {
				var valid = true;
				if (this['allowEmpty'] && val == '') {
					//do nothing
				} else if (this['rule'].match(/^range/)) {
					var range = this['rule'].split('|');
					if (val < parseInt(range[1])) {
						valid = false;
					}
					if (val > parseInt(range[2])) {
						valid = false;
					}
				} else if (this['negate']) {
					if (val.match(eval(this['rule']))) {
						valid = false;
					}
				} else if (!val.match(eval(this['rule']))) {
					valid = false;
				}
				 
				if (!valid) {
					//add the error message
					$("#messages").append("<p>" + this['message'] + "</p>");
					   
					//highlight the label
					//$("label[for='" + field + "']").addClass("error");
					$("#" + field).parent().addClass("error");
				}
			}
		});
	});
  
	if($("#messages").html() != "") {
		$("#messages").wrapInner("<div class='errors'></div>");
		$("#messagesOuter").slideDown();
		return false;
	}
	return true;
}