
	
	function validate(elm,retest)
	{
		if (elm.hasClassName('noValidation')) {
			return;
		}
		//	case 'OK':
		var OK = 'background:#EAFFDF; color:#127B00; border:2px solid #127B00;';
		//	case 'BAD':
		var BAD = 'background:#FBE7E7; color:#9F0404; border:2px solid #9F0404;';
		//	case 'PART':
		var PART = 'background:#FFF0DF; color:#AF5E00; border:2px solid #AF5E00;';
		var valType = elm.readAttribute('rel');
		var varResult = 'OK';
		if (valType) {
			var valParts = valType.split('-');
			var ref = null;
			var comp = '==';
			if (valParts.length > 1) {
				type = valParts[0];
				ref = valParts[1];
				if (valParts[2]) {
					comp = valParts[2];
				}
			}else{
				type = valType;
			}
		}

		if (elm.present === false) {
			elm.morph(BAD,{duration: 0.4});
			elm.removeClassName('OK');
			elm.removeClassName('PART');
			elm.addClassName('BAD');
		}

		switch(type) {
			case 'alpha':
				if (/[\w\s]/i.match(elm.getValue())) {
					if (ref == null || eval('elm.getValue() '+comp+' $(ref).getValue()')) {
						varResult = 'OK';
					}else{
						varResult = 'PART';
					}
				}else{
						varResult = 'BAD';
				}
				if (retest != true && $(ref)) {
					validate($(ref),true);
				}
				break;
			case 'number':
				if (/\d/i.match(elm.getValue())) {
					if (ref == null || eval('parseInt(elm.getValue()) '+comp+' parseInt($(ref).getValue())')) {
						varResult = 'OK';
					}else{
						varResult = 'PART';
					}
				}else{
						varResult = 'BAD';
				}
				if (retest != true && $(ref)) {
					validate($(ref),true);
				}
				break;
			case 'email':
				if (/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i.match(elm.getValue())) {
					if (ref == null || eval('elm.getValue() '+comp+' $(ref).getValue()')) {
						varResult = 'OK';
					}else{
						varResult = 'PART';
					}
				}else{
						varResult = 'BAD';
				}
				if (retest != true && $(ref)) {
					validate($(ref),true);
				}
				break;
		}
		
		switch(varResult) {
			case 'OK':
				elm.morph(OK,{duration: 0.4});
						elm.addClassName('OK');
						elm.removeClassName('PART');
						elm.removeClassName('BAD');
						if ($(elm.id+'-bad') && $(elm.id+'-bad').visible()) {
							$(elm.id+'-bad').fade();
						}
						if ($(elm.id+'-part') && $(elm.id+'-part').visible()) {
							$(elm.id+'-part').fade();
						}
				break;
			case 'PART':
					elm.removeClassName('OK');
					elm.addClassName('PART');
					elm.removeClassName('BAD');
					elm.morph(PART,{duration: 0.4});
					if ($(elm.id+'-bad') && $(elm.id+'-bad').visible()) {
						$(elm.id+'-bad').fade();
					}
					if ($(elm.id+'-part')) {
						$(elm.id+'-part').appear();
						$(elm.id+'-part').morph(PART,{duration: 0.4});
					}
				break;
			case 'BAD':
				elm.removeClassName('OK');
				elm.removeClassName('PART');
				elm.addClassName('BAD');
				elm.morph(BAD,{duration: 0.4});
				if ($(elm.id+'-part')) {
					$(elm.id+'-part').fade();
					$(elm.id+'-part').morph(PART,{duration: 0.4});
				}
				if ($(elm.id+'-bad')) {
					$(elm.id+'-bad').appear();
					$(elm.id+'-bad').morph(BAD,{duration: 0.4});
				}
				break;
		}
		
	}