//eval(function(p,a,c,k,e,d){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--)d[e(c)]=k[c]||e(c);k=[function(e){return d[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;}('b U=H 1d({f:{1N:"2f",1L:"U-c",1e:{"1g-n":"#2g","1u-n":"#2h"},1O:{"1g-n":"#2e","1u-n":"#2b"},1S:{"1g-n":"#2c","1u-n":"#2d"},10:{7:"10",e:/[^.*]/,c:"1i 1l 2i 10."},1P:{7:"1P",e:/^[a-z.N-]+$/i,c:"1i 1l 1X 2n 1y 1B."},22:{7:"22",e:/^[a-x-9.N-]+$/i,c:"1i 1l 1X 2o 1y 1B."},1a:{7:"1a",e:/^[-+]?\\d+$/,c:"u q a t 1a."},1H:{7:"1H",e:/^[-+]?\\d*\\.?\\d+$/,c:"u q a t 2p."},1x:{7:"1x",e:/^((((0[1D])|([1D])|(1[1G]))[\\/](([1-9])|([0-2][0-9])|(3[2m])))|(((0[1F])|([1F])|(11))[\\/](([1-9])|([0-2][0-9])|(30)))|((2|1G)[\\/](([1-9])|([0-2][0-9]))))[\\/]\\d{4}$|^\\d{4}$/,c:"u q a t 1x (2j/2k/2l)."},1o:{7:"1o",e:/^[a-x-9.N%-]+@[a-x-9.-]+\\.[a-z]{2,4}$/i,c:"u q a t 1o."},1r:{7:"1r",e:/^[\\d\\s().-]+$/,c:"u q a t 1r."},1c:{7:"1c",e:/^(2a|28|27)\\:\\/\\/[a-x-9\\-\\.]+\\.[a-z]{2,3}(:[a-x-9]*)?\\/?([a-x-9\\-\\.N\\?\\,\\\'\\/\\\\\\+&29;%\\$#\\=~])*$/i,c:"u q a t 1c."},V:{7:"V",c:"2X 1M 2Q 2T 1p 2S 1M."},1R:1d.1K,26:1d.1K},2R:8(1E,1z){5.T=$(1E);5.2U(1z);5.1C=5.T.2O("*[1w^=1v]");5.K=[];5.1C.M(8(j){6(!5.L(j)){j.1Q(5.f.1e)}j.v=0;b 1I=j.o("1w").2N(" ");1I.M(8(1n){6(1n.1p(/^1v(\\[.+\\])$/)){b r=2P(1n.1p(/^1v(\\[.+\\])$/)[1]);21(b i=0;i<r.1Z;i++){6(5.f[r[i]]){5.1m(j,5.f[r[i]])}6(r[i].2Z(0)=="="){5.1m(j,$31(5.f.V,{25:r[i].2W(1)}))}}}}.k(5))}.k(5));5.T.2V({"2Y":5.24.k(5),"2x":5.1U.k(5)})},1m:8(w,1j){w=$(w);5.K.2w([w,1j]);w.2y("2A",8(){5.1h(w,1j)}.k(5))},L:8(D){b 1f=D.7.2z();6((1f=="2v")||(1f=="2r")){1q S}1q F},1h:8(l,g){2q(g.7){2s"V":6($(g.25).Z()==l.Z()){5.G(l,g)}I{5.R(l,g)}1W;2u:6(g.e.1Y(l.Z())){5.G(l,g)}I{5.R(l,g)}}},1J:8(Y,E){b W=5.T[Y.o("2t")];b 1b=0;b X=S;21(b i=0;i<W.1Z;i++){6(W[i].2B){1b++;6(!E.e.1Y(W[i].Z())){X=F;1W}}}6(1b==0&&E.7=="10"){X=F}6(X){5.G(Y,E)}I{5.R(Y,E)}},R:8(m,C){6(!$(m.o("B")+C.7+"P")){b 2J=H 2I(5.f.1N,{"B":m.o("B")+C.7+"P","1w":5.f.1L}).2K(C.c).2M("1t",0).2L(m).1T("1t",{14:13,12:15.16.17}).18(0,1);m.v++;5.1s(m,C)}},G:8(A,19,O){O=O||F;6($(A.o("B")+19.7+"P")){b D=$(A.o("B")+19.7+"P");D.1T("1t",{14:13,12:15.16.17,2H:8(){D.2D()}}).18(1,0);6(!O){A.v--;5.1s(A,19)}}},1s:8(p,1k){6(p.v==0){p.1V({14:13,12:15.16.17}).18(5.f.1S);5.23("1R",[p,1k],20)}I{p.1V({14:13,12:15.16.17}).18(5.f.1O);5.23("26",[p,1k],20)}},24:8(Q){Q=H 2C(Q);b J=S;5.K.M(8(h){6(5.L(h[0])){5.1J(h[0],h[1])}I{5.1h(h[0],h[1])}6(h[0].v>0){J=F}}.k(5));6(!J){Q.2E()}1q J},1U:8(){5.K.M(8(y){6(!5.L(y[0])){y[0].1Q(5.f.1e)}y[0].v=0;5.G(y[0],y[1],S)}.k(5))}});U.1A(H 2G);U.1A(H 2F);',62,188,'|||||this|if|type|function|||var|msg||re|options|_d|_1f||_3|bind|_c|_14|color|getProperty|_1b|enter|_6||valid|Please|cbErr|_8|z0|_20||_17|id|_15|el|_f|false|_msgRemove|new|else|_1e|validations|_isChildType|each|_|_19|_msg|_1d|_msgInject|true|form|fValidator|confirm|_10|_12|_e|getValue|required||transition|500|duration|Fx|Transitions|linear|start|_18|integer|_11|url|Class|styleNeutral|_b|background|_validate|This|_9|_1c|field|register|_5|email|match|return|phone|_chkStatus|opacity|border|fValidate|class|date|characters|_2|implement|only|fields|13578|_1|469|02|real|_4|_validateChild|empty|msgClass|Password|msgContainerTag|styleInvalid|alpha|setStyles|onValid|styleValid|effect|_onReset|effects|break|accepts|test|length|50|for|alphanum|fireEvent|_onSubmit|idField|onInvalid|ftp|https|amp|http|c00|cfc|0c0|fcc|div|ffc|cc0|is|mm|dd|yyyy|01|alphabetic|alphanumeric|number|switch|checkbox|case|name|default|radio|push|reset|addEvent|toLowerCase|blur|checked|Event|remove|stop|Options|Events|onComplete|Element|_16|setHTML|injectAfter|setStyle|split|getElements|eval|does|initialize|original|not|setOptions|addEvents|substr|Confirm|submit|charAt||extend'.split('|'),0,{}))

/* ************************************************************************************* *\
 * The MIT License
 * Copyright (c) 2007 Fabio Zendhi Nagao - http://zend.lojcomm.com.br
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this
 * software and associated documentation files (the "Software"), to deal in the Software
 * without restriction, including without limitation the rights to use, copy, modify,
 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies
 * or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
\* ************************************************************************************* */

var fValidator = new Class({
	options: {
		msgContainerTag: "div",
		msgClass: "fValidator-msg",

		styleNeutral: {"background-color": "#ffc", "border-color": "#cc0"},
		styleInvalid: {"background-color": "#fcc", "border-color": "#c00"},
		styleValid: {"background-color": "#cfc", "border-color": "#0c0"},

		required: {type: "required", re: /[^.*]/, msg: "This field is required."},
		alpha: {type: "alpha", re: /^[a-z ._-]+$/i, msg: "This field accepts alphabetic characters only."},
		alphanum: {type: "alphanum", re: /^[a-z0-9 ._-]+$/i, msg: "This field accepts alphanumeric characters only."},
		integer: {type: "integer", re: /^[-+]?\d+$/, msg: "Please enter a valid integer."},
		real: {type: "real", re: /^[-+]?\d*\.?\d+$/, msg: "Please enter a valid number."},
		date: {type: "date", re: /^((((0[13578])|([13578])|(1[02]))[\/](([1-9])|([0-2][0-9])|(3[01])))|(((0[469])|([469])|(11))[\/](([1-9])|([0-2][0-9])|(30)))|((2|02)[\/](([1-9])|([0-2][0-9]))))[\/]\d{4}$|^\d{4}$/, msg: "Please enter a valid date (mm/dd/yyyy)."},
		email: {type: "email", re: /^[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}$/i, msg: "Please enter a valid email."},
		phone: {type: "phone", re: /^[\d\s ().-]+$/, msg: "Please enter a valid phone."},
		url: {type: "url", re: /^(http|https|ftp)\:\/\/[a-z0-9\-\.]+\.[a-z]{2,3}(:[a-z0-9]*)?\/?([a-z0-9\-\._\?\,\'\/\\\+&amp;%\$#\=~])*$/i, msg: "Please enter a valid url."},
		confirm: {type: "confirm", msg: "Confirm Password does not match original Password."},

		onValid: Class.empty,
		onInvalid: Class.empty
	},

	initialize: function(form, options) {
		this.form = $(form);
		this.setOptions(options);

		this.fields = this.form.getElements("*[class^=fValidate]");
		this.validations = [];

		this.fields.each(function(element) {
			if(!this._isChildType(element)) element.setStyles(this.options.styleNeutral);
			element.cbErr = 0;
			var classes = element.getProperty("class").split(' ');
			classes.each(function(klass) {
				if(klass.match(/^fValidate(\[.+\])$/)) {
					var aFilters = eval(klass.match(/^fValidate(\[.+\])$/)[1]);
					for(var i = 0; i < aFilters.length; i++) {
						if(this.options[aFilters[i]]) this.register(element, this.options[aFilters[i]]);
						if(aFilters[i].charAt(0) == '=') this.register(element, $extend(this.options.confirm, {idField: aFilters[i].substr(1)}));
					}
				}
			}.bind(this));
		}.bind(this));

		this.form.addEvents({
			"submit": this._onSubmit.bind(this),
			"reset": this._onReset.bind(this)
		});
	},

	register: function(field, options) {
		field = $(field);
		this.validations.push([field, options]);
		field.addEvent("blur", function() {
			this._validate(field, options);
		}.bind(this));
	},

	_isChildType: function(el) {
		var elType = el.type.toLowerCase();
		if((elType == "radio") || (elType == "checkbox")) return true;
		return false;
	},

	_validate: function(field, options) {
		switch(options.type) {
			case "confirm":
				if($(options.idField).getValue() == field.getValue()) this._msgRemove(field, options);
				else this._msgInject(field, options);
				break;
			default:
				if(options.re.test(field.getValue())) this._msgRemove(field, options);
				else this._msgInject(field, options);
		}
	},

	_validateChild: function(child, options) {
		var nlButtonGroup = this.form[child.getProperty("name")];
		var cbCheckeds = 0;
		var isValid = true;
 		for(var i = 0; i < nlButtonGroup.length; i++) {
			if(nlButtonGroup[i].checked) {
				cbCheckeds++;
				if(!options.re.test(nlButtonGroup[i].getValue())) {
					isValid = false;
					break;
				}
			}
		}
		if(cbCheckeds == 0 && options.type == "required") isValid = false;
		if(isValid) this._msgRemove(child, options);
		else this._msgInject(child, options);
	},

	_msgInject: function(owner, options) {
		if(!$(owner.getProperty("id") + options.type +"_msg")) {
			var msgContainer = new Element(this.options.msgContainerTag, {"id": owner.getProperty("id") + options.type +"_msg", "class": this.options.msgClass})
				.setHTML(options.msg)
				.setStyle("opacity", 0)
				.injectAfter(owner)
				.effect("opacity", {
					duration: 500,
					transition: Fx.Transitions.linear
				}).start(0, 1);
			owner.cbErr++;
			this._chkStatus(owner, options);
		}
	},

	_msgRemove: function(owner, options, isReset) {
		isReset = isReset || false;
		if($(owner.getProperty("id") + options.type +"_msg")) {
			var el = $(owner.getProperty("id") + options.type +"_msg");
			el.effect("opacity", {
				duration: 500,
				transition: Fx.Transitions.linear,
				onComplete: function() {el.remove()}
			}).start(1, 0);
			if(!isReset) {
				owner.cbErr--;
				this._chkStatus(owner, options);
			}
		}
	},

	_chkStatus: function(field, options) {
		if(field.cbErr == 0) {
			field.effects({duration: 500, transition: Fx.Transitions.linear}).start(this.options.styleValid);
			this.fireEvent("onValid", [field, options], 50);
		} else {
			field.effects({duration: 500, transition: Fx.Transitions.linear}).start(this.options.styleInvalid);
			this.fireEvent("onInvalid", [field, options], 50);
		}
	},

	_onSubmit: function(event) {
		event = new Event(event);
		var isValid = true;

		this.validations.each(function(array) {
			if(this._isChildType(array[0])) this._validateChild(array[0], array[1]);
			else this._validate(array[0], array[1]);
			if(array[0].cbErr > 0) isValid = false;
		}.bind(this));

		if(!isValid) event.stop();

		if(!isValid) {
			$('submit_msg').innerHTML='You have one or more errors on your form, please re-check for errors on the red fields.';
			$('submit_msg').className='fValidator-msg';
		}
		return isValid;
	},

	_onReset: function() {
		this.validations.each(function(array) {
			if(!this._isChildType(array[0])) array[0].setStyles(this.options.styleNeutral);
			array[0].cbErr = 0;
			this._msgRemove(array[0], array[1], true);
		}.bind(this));
	}
});
fValidator.implement(new Events); // Implements addEvent(type, fn), fireEvent(type, [args], delay) and removeEvent(type, fn)
fValidator.implement(new Options);// Implements setOptions(defaults, options)
