function wlpPasswordValidator(_params){this.params=new wlpPropertyList(_params);this.styleContainer='3px inset';this.parentId=this.params.get('controlParentName');this.ID=this.parentId+'_'+this.params.get('controlName');}wlpPasswordValidator.prototype=new wlpValidator;wlpPasswordValidator.prototype.validate=function(value){var _pv=$('password_validator');return this.compareReType(this.ID);};wlpPasswordValidator.prototype.compareType=function(id){var _reType=$(id+'_retype');var _pv=$('password_validator');_reType.value='';_reType.style.border=this.styleContainer;_pv.value=0;};wlpPasswordValidator.prototype.compareReType=function(id){var _type=$(id);var _reType=$(id+'_retype');var _pv=$('password_validator');if(_type.value!=_reType.value){this.styleContainer='3px inset ';_reType.style.border='2px inset red';_pv.value=0;return false;}else{_reType.style.border=this.styleContainer;_pv.value=1;}return true;}

function wlpDateValidator(_params){this.params=new wlpPropertyList(_params);}wlpDateValidator.prototype=new wlpValidator;wlpDateValidator.prototype._parseMask=function(_mask){var maskRegexp=/#(.)/i;var match=maskRegexp.exec(_mask);var strRegexp=new String();var pos=-1;while(match!=null&&match.length>1){pos=_mask.indexOf(match[0]);if(pos!=-1){strRegexp+=_mask.substr(0,pos);_mask=_mask.substr(pos+match[0].length,_mask.length-pos-match[0].length);}switch(match[1]){case'd':strRegexp+="(0?[1-9]|[12][0-9]|3[01])";break;case'm':strRegexp+="(0?[1-9]|1[012])";break;case'y':strRegexp+="[0-9]{2}";break;case'Y':strRegexp+="(19|20){1}[0-9]{2}";break;}match=maskRegexp.exec(_mask);}return strRegexp;};wlpDateValidator.prototype.validate=function(value){var mask=this.params.get('mask');var strValue=new String(value);if(strValue.length!=0){if(mask!==false){var strMask=new String(mask);strRegexp=this._parseMask(strMask);if(strRegexp.length!=0){strRegexp="\\b"+strRegexp+"\\b";var regexpInstance=new RegExp(strRegexp);var match=regexpInstance.exec(strValue);if(match==null||match.indexOf(strValue)==-1){return false;}}}}return true;}

function wlpEmailValidator(_params){this.params=new wlpPropertyList(_params);}wlpEmailValidator.prototype=new wlpValidator;wlpEmailValidator.prototype.validate=function(value){var strValue=new String(value);if(strValue.length!=0){var regexpInstance=new RegExp(/^[\w-\.]+\@[\w\.-]+\.[a-zA-Z]{2,4}$/);var match=regexpInstance.test(strValue);if(!match)return false;}return true;}

function wlpFileExtValidator(_params){this.params=new wlpPropertyList(_params);}wlpFileExtValidator.prototype=new wlpValidator;wlpFileExtValidator.prototype.validate=function(value){var strValue=new String(value);if(strValue.length!=0){var _p=this.params.get('ext');if(_p!==false){var strExt=new String(_p);var strRegexp="(.*)\.("+strExt+")$";var regexpInstance=new RegExp(strRegexp,"i");var match=regexpInstance.exec(strValue);if(match==null)return false;}}return true;}

function wlpLoginValidator(_params){this.params=new wlpPropertyList(_params);}wlpLoginValidator.prototype=new wlpValidator;wlpLoginValidator.prototype.validate=function(value){var strValue=new String(value);if(strValue.length!=0){var regexpInstance=new RegExp(/^[a-z-A-Z0-9_-]{3,10}$/);var match=regexpInstance.test(strValue);if(!match)return false;}else{return false;}return true;}

/**
 * @author Kalapuc Roman (rkalapuc@gmail.com)
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

function wlpNotEmptyValidator(_params){
	this.params = new wlpPropertyList(_params);	
}

wlpNotEmptyValidator.prototype = new wlpValidator;

wlpNotEmptyValidator.prototype.validate = function(value){
	var strValue = new String(value);
	
	if (strValue.length==0) return false;
		
	return true;
}

/**
 * @author Kalapuc Roman (rkalapuc@gmail.com)
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

function wlpNotLessValidator(_params){
	this.params = new wlpPropertyList(_params);	
}

wlpNotLessValidator.prototype = new wlpValidator;

wlpNotLessValidator.prototype.validate = function(value){
	
	var strValue = new String(value);
	
	if (strValue.length!=0){
		strValue =strValue.replace(/,/g, ".");

		var _numValue = new Number(strValue);
		var _field = this.params.get('field');	
		
		if (_field!==false){
			var _fieldValue = new Number($(_field).value);
			var _mindif = this.params.get('mindif');
			
			if (_mindif!==false){
				_mindif = new Number(_mindif);
				
				if ((_numValue-_fieldValue)<_mindif) {
					return false;
				}
			}
			
			var _maxdif = this.params.get('maxdif');

			if (_maxdif!==false){
				_maxdif = new Number(_maxdif);
				
				if ((_numValue-_fieldValue)>_maxdif) {
					return false;
				}
			}						
		}
	}
	
	return true;
}

function wlpDefaultValidator(_params){this.params=new wlpPropertyList(_params);}wlpDefaultValidator.prototype=new wlpValidator;wlpDefaultValidator.prototype.validate=function(value){return true;}

/**
 * @author Izzet Mustafayev <webdizz@gmail.com>
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

function wlpPhoneValidator(_params){
	this.params = new wlpPropertyList(_params);
}

wlpPhoneValidator.prototype = new wlpValidator;

wlpPhoneValidator.prototype.validate = function(value){
	var strValue = new String(value);
	if (strValue.length!=0){
		var regexpInstance = new RegExp(/^[\+\d{1,1}\(\d\)]+[\d\.\s\-]+$/);
		var match = regexpInstance.test(strValue);
		if (!match) return false;
	}else{
		return false;
	}
	return true;
}

function wlpIntValidator(_params){this.params=new wlpPropertyList(_params);}wlpIntValidator.prototype=new wlpValidator;wlpIntValidator.prototype.validate=function(value){var strValue=new String(value);if(strValue.length!=0){var regexpInstance=/[-+]?\b\d+\b/;var match=regexpInstance.exec(strValue);if(match!=null&&match.indexOf(strValue)!=-1){var _nValue=new Number(strValue);var _p=this.params.get('max');if(_p!==false){var _nMax=new Number(_p);if(_nValue>_nMax)return false;}_p=this.params.get('min');if(_p!==false){var _nMin=new Number(_p);if(_nValue<_nMin)return false;}return true;}else{return false;}}return true;}

/**
 * @author Kalapuc Roman (rkalapuc@gmail.com)
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

var wlpValidatorFactory;

if (!wlp_def("wlpValidatorFactoty")){
	wlpValidatorFactory = {
		getInstance: function(_type,_params){
			switch(_type){
				case wlpConst.WLP_JSVALIDATOR_NOTEMPTY: return new wlpNotEmptyValidator(_params);
				case wlpConst.WLP_JSVALIDATOR_STRING: return new wlpStringValidator(_params);
				case wlpConst.WLP_JSVALIDATOR_INT: return new wlpIntValidator(_params);
				case wlpConst.WLP_JSVALIDATOR_DATE: return new wlpDateValidator(_params);
				case wlpConst.WLP_JSVALIDATOR_FLOAT: return new wlpFloatValidator(_params);
				case wlpConst.WLP_JSVALIDATOR_FILEEXT: return new wlpFileExtValidator(_params);
				case wlpConst.WLP_JSVALIDATOR_NOTLESS: return new wlpNotLessValidator(_params);
				case wlpConst.WLP_JSVALIDATOR_EMAIL: return new wlpEmailValidator(_params);
				case wlpConst.WLP_JSVALIDATOR_LOGIN: return new wlpLoginValidator(_params);
				case wlpConst.WLP_JSVALIDATOR_PHONE: return new wlpPhoneValidator(_params);
				case wlpConst.WLP_JSVALIDATOR_PASSWORD: return new wlpPasswordValidator(_params);					
				default: return new wlpDefaultValidator(_params);
			}
		}
	}
}

function wlpRegexpValidator(_params){this.params=new wlpPropertyList(_params);}wlpRegexpValidator.prototype=new wlpValidator;wlpRegexpValidator.prototype.validate=function(value){return true;}

function wlpFloatValidator(_params){this.params=new wlpPropertyList(_params);}wlpFloatValidator.prototype=new wlpValidator;wlpFloatValidator.prototype.validate=function(value){var strValue=new String(value);if(strValue.length!=0){strValue=strValue.replace(/,/g,".");var regexpInstance=/[-+]?\b(?:[0-9]*[\.])?[0-9]+\b/;var match=regexpInstance.exec(strValue);if(match!=null&&match.indexOf(strValue)!=-1){var _nValue=new Number(strValue);var _p=this.params.get('max');if(_p!==false){var _nMax=new Number(_p);if(_nValue>_nMax){return false;}}_p=this.params.get('min');if(_p!==false){var _nMin=new Number(_p);if(_nValue<_nMin){return false;}}return true;}else{return false;}}return true;}

/**
 * @author Kalapuc Roman (rkalapuc@gmail.com)
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

function wlpDateValidator(_params){
	this.params = new wlpPropertyList(_params);	
}

wlpDateValidator.prototype = new wlpValidator;

wlpDateValidator.prototype._parseMask = function(_mask){
	var maskRegexp = /#(.)/i;
	var match = maskRegexp.exec(_mask);
	var strRegexp = new String();
	var pos = -1;
	while (match!=null && match.length>1){
		pos = _mask.indexOf(match[0]);
		if (pos!=-1){
			strRegexp+=_mask.substr(0,pos);			
			_mask = _mask.substr(pos+match[0].length,_mask.length-pos-match[0].length);
		}
		
		switch(match[1]){
			case 'd': 
				strRegexp+="(0?[1-9]|[12][0-9]|3[01])";
				break;
			case 'm':
				strRegexp+="(0?[1-9]|1[012])"; 
				break;
			case 'y':
				strRegexp+="[0-9]{2}";							
				break;
			case 'Y': 
				strRegexp+="(19|20){1}[0-9]{2}";
			break;			
		}
		match = maskRegexp.exec(_mask);
	}
	
	return strRegexp;
}

wlpDateValidator.prototype.validate = function(value){
	var mask = this.params.get('mask');
	var strValue = new String(value);
	
	if (strValue.length!=0){
		if (mask!==false){
			var strMask = new String(mask);
			strRegexp = this._parseMask(strMask);
			if (strRegexp.length!=0){
				strRegexp = "\\b"+strRegexp+"\\b";				
				var regexpInstance = new RegExp(strRegexp);
				var match = regexpInstance.exec(strValue);
				if (match==null || match.indexOf(strValue)==-1){
					return false;
				}
			}			
		}
	}

	return true;
}

/**
 * @author Kalapuc Roman (rkalapuc@gmail.com)
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

function wlpEmailValidator(_params){
	this.params = new wlpPropertyList(_params);
}

wlpEmailValidator.prototype = new wlpValidator;

wlpEmailValidator.prototype.validate = function(value){
	var strValue = new String(value);
	
	if (strValue.length!=0){
		var regexpInstance = new RegExp(/^[\w-\.]+\@[\w\.-]+\.[a-zA-Z]{2,4}$/);
		var match = regexpInstance.test(strValue);
		if (!match) return false;
	}/* to enable check not required email fields 
	else{
		return false;
	}*/
	return true;
}

/**
 * @author Kalapuc Roman (rkalapuc@gmail.com)
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

function wlpDefaultValidator(_params){
	this.params = new wlpPropertyList(_params);
}

wlpDefaultValidator.prototype = new wlpValidator;

wlpDefaultValidator.prototype.validate = function(value){
	return true;
}

/**
 * @author Izzet Mustafayev <webdizz@gmail.com>
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

function wlpPasswordValidator(_params){
	this.params = new wlpPropertyList(_params);
	this.styleContainer = '3px inset';
	
	this.parentId = this.params.get('controlParentName');
	this.ID = this.parentId +'_'+this.params.get('controlName');
}

wlpPasswordValidator.prototype = new wlpValidator;

wlpPasswordValidator.prototype.validate = function(value){
	var _pv = $('password_validator');
	return this.compareReType(this.ID);
}

wlpPasswordValidator.prototype.compareType = function(id){
	var _reType = $(id + '_retype');
	var _pv = $('password_validator');
	_reType.value = '';
	_reType.style.border = this.styleContainer;
	_pv.value = 0;
}

wlpPasswordValidator.prototype.compareReType = function(id){
	var _type = $(id);
	var _reType = $(id + '_retype');
	var _pv = $('password_validator');
	if(_type.value != _reType.value){
		this.styleContainer = '3px inset ';//_reType.style.border;
		_reType.style.border = '2px inset red';
		_pv.value = 0;
		return false;
	}else{
		_reType.style.border = this.styleContainer;
		_pv.value = 1;
	}
	return true;
}

function wlpStringValidator(_params){this.params=new wlpPropertyList(_params);}wlpStringValidator.prototype=new wlpValidator;wlpStringValidator.prototype.validate=function(value){var strValue=new String(value);if(strValue.length!=0){var _p=this.params.get("maxlen");if(_p!==false){var _nMax=new Number(_p);if(strValue.length>_p)return false;}_p=this.params.get('minlen');if(_p!==false){var _nMin=new Number(_p);if(strValue.length<_p)return false;}}return true;}

function wlpPhoneValidator(_params){this.params=new wlpPropertyList(_params);}wlpPhoneValidator.prototype=new wlpValidator;wlpPhoneValidator.prototype.validate=function(value){var strValue=new String(value);if(strValue.length!=0){var regexpInstance=new RegExp(/^[\+\d{1,1}\(\d\)]+[\d\.\s\-]+$/);var match=regexpInstance.test(strValue);if(!match)return false;}else{return false;}return true;}

var wlpValidatorFactory;if(!wlp_def("wlpValidatorFactoty")){wlpValidatorFactory={getInstance:function(_type,_params){switch(_type){case wlpConst.WLP_JSVALIDATOR_NOTEMPTY:return new wlpNotEmptyValidator(_params);case wlpConst.WLP_JSVALIDATOR_STRING:return new wlpStringValidator(_params);case wlpConst.WLP_JSVALIDATOR_INT:return new wlpIntValidator(_params);case wlpConst.WLP_JSVALIDATOR_DATE:return new wlpDateValidator(_params);case wlpConst.WLP_JSVALIDATOR_FLOAT:return new wlpFloatValidator(_params);case wlpConst.WLP_JSVALIDATOR_FILEEXT:return new wlpFileExtValidator(_params);case wlpConst.WLP_JSVALIDATOR_NOTLESS:return new wlpNotLessValidator(_params);case wlpConst.WLP_JSVALIDATOR_EMAIL:return new wlpEmailValidator(_params);case wlpConst.WLP_JSVALIDATOR_LOGIN:return new wlpLoginValidator(_params);case wlpConst.WLP_JSVALIDATOR_PHONE:return new wlpPhoneValidator(_params);case wlpConst.WLP_JSVALIDATOR_PASSWORD:return new wlpPasswordValidator(_params);default:return new wlpDefaultValidator(_params);}}}}

function wlpNotLessValidator(_params){this.params=new wlpPropertyList(_params);}wlpNotLessValidator.prototype=new wlpValidator;wlpNotLessValidator.prototype.validate=function(value){var strValue=new String(value);if(strValue.length!=0){strValue=strValue.replace(/,/g,".");var _numValue=new Number(strValue);var _field=this.params.get('field');if(_field!==false){var _fieldValue=new Number($(_field).value);var _mindif=this.params.get('mindif');if(_mindif!==false){_mindif=new Number(_mindif);if((_numValue-_fieldValue)<_mindif){return false;}}var _maxdif=this.params.get('maxdif');if(_maxdif!==false){_maxdif=new Number(_maxdif);if((_numValue-_fieldValue)>_maxdif){return false;}}}}return true;}

function wlpNotEmptyValidator(_params){this.params=new wlpPropertyList(_params);}wlpNotEmptyValidator.prototype=new wlpValidator;wlpNotEmptyValidator.prototype.validate=function(value){var strValue=new String(value);if(strValue.length==0)return false;return true;}

/**
 * @author Kalapuc Roman (rkalapuc@gmail.com)
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

function wlpFloatValidator(_params){
	this.params = new wlpPropertyList(_params);	
}

wlpFloatValidator.prototype = new wlpValidator;

wlpFloatValidator.prototype.validate = function(value){
	
	var strValue = new String(value);
	
	if (strValue.length!=0){	
		
		strValue =strValue.replace(/,/g, ".");
		var regexpInstance = /[-+]?\b(?:[0-9]*[\.])?[0-9]+\b/;
		var match = regexpInstance.exec(strValue);
		
		if (match != null && match.indexOf(strValue)!=-1){
			var _nValue = new Number(strValue);
			var _p = this.params.get('max');
			
			if (_p!==false){
				var _nMax = new Number(_p);
				if (_nValue>_nMax) {
					return false;
				}
				
			}
			
			_p = this.params.get('min');
			if (_p!==false){
				var _nMin = new Number(_p);
				if (_nValue<_nMin) {
					return false;	
				}
			}						
			
			return true;	
		} else {
			return false;
		}	
	}
	
	return true;
}

/**
 * @author Kalapuc Roman (rkalapuc@gmail.com)
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

function wlpIntValidator(_params){
	this.params = new wlpPropertyList(_params);		
}

wlpIntValidator.prototype = new wlpValidator;

wlpIntValidator.prototype.validate = function(value){
	var strValue = new String(value);
	
	if (strValue.length!=0){
		var regexpInstance = /[-+]?\b\d+\b/;
		var match = regexpInstance.exec(strValue);
		
		if (match != null && match.indexOf(strValue)!=-1){
			var _nValue = new Number(strValue);						
			var _p = this.params.get('max');			
			
			if (_p!==false){
				var _nMax = new Number(_p);
				if (_nValue>_nMax) return false;
			}
			
			_p = this.params.get('min');
			if (_p!==false){
				var _nMin = new Number(_p);
				if (_nValue<_nMin) return false;
			}						
			
			return true;	
		} else {
			return false;
		}	
	}
	
	return true;
}

function wlpValidator(_params){this.params=new wlpPropertyList(_params);}wlpValidator.prototype.validate=function(value){return true;}

/**
 * @author Izzet Mustafayev <webdizz@gmail.com>
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

function wlpLoginValidator(_params){
	this.params = new wlpPropertyList(_params);
}

wlpLoginValidator.prototype = new wlpValidator;

wlpLoginValidator.prototype.validate = function(value){
	var strValue = new String(value);
	if (strValue.length!=0){
		var regexpInstance = new RegExp(/^[a-z-A-Z0-9_-]{3,10}$/);
		var match = regexpInstance.test(strValue);
		if (!match) return false;
	}else{
		return false;
	}
	return true;
}

/**
 * @author Kalapuc Roman (rkalapuc@gmail.com)
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

function wlpRegexpValidator(_params){
	this.params = new wlpPropertyList(_params);	
}

wlpRegexpValidator.prototype = new wlpValidator;

wlpRegexpValidator.prototype.validate = function(value){
	return true;
}

/**
 * @author Kalapuc Roman (rkalapuc@gmail.com)
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

function wlpStringValidator(_params){
	this.params = new wlpPropertyList(_params);	
}

wlpStringValidator.prototype = new wlpValidator;

wlpStringValidator.prototype.validate = function(value){
	var strValue = new String(value);
	
	if (strValue.length!=0){
		var _p = this.params.get("maxlen");
		
		if (_p!==false){
			var _nMax = new Number(_p);
			if (strValue.length>_p) return false;
		}
			
		_p = this.params.get('minlen');
		if (_p!==false){
			var _nMin = new Number(_p);
			if (strValue.length<_p) return false;
		}
	}
	
	return true;
}

/**
 * @author Kalapuc Roman (rkalapuc@gmail.com)
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

function wlpFileExtValidator(_params){
	this.params = new wlpPropertyList(_params);		
}

wlpFileExtValidator.prototype = new wlpValidator;

wlpFileExtValidator.prototype.validate = function(value){

	var strValue = new String(value);
	
	if (strValue.length!=0){
		
		var _p = this.params.get('ext');
	
		if (_p!==false){
			var strExt = new String(_p);			
			var strRegexp = "(.*)\.("+strExt+")$";

			var regexpInstance = new RegExp(strRegexp,"i");
			var match = regexpInstance.exec(strValue);
			
			if (match==null) return false;
		}	
	}
	
	return true;
}

