if (typeof QQ === "undefined") {
  var QQ = {};
} 
QQ.Validator = function(){
		
  return {
  	emailRegExp: /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/,
		// returns element, id might be element itself or id of the element
    validateInput: function (settings){
			
			var value = settings.value; 
			var errorFunction = settings.errorFunction;
			var successFunction = settings.successFunction;
			var path = settings.path; // if value should additionally be validated on server
			var regExp = settings.regExp;
			
			// check syntax
			if (regExp !== undefined){
			  if (value.search(regExp) == -1){
		      if (errorFunction !== undefined) errorFunction();
		      return false;
		    }
			}
			
			// validate on server if necessary
			if (path !== undefined){
				function serverValidationCheck(req){
					if (req.responseText == 1){
						if (successFunction !== undefined) successFunction();
	   				return true;
					}else {
						if (errorFunction !== undefined) errorFunction();
	     		  return false;
					}
				}
				QQ.Ajax.request(path,{data:"value="+value,method:"post",responseFunction:serverValidationCheck});
			}else{
				if (successFunction !== undefined) successFunction();
	      return true;				
			}
		}    
  };
}();
