var Validator = {
	email : function(str){ 
		var splitted = str.match("^(.+)@(.+)$");
	  	if(splitted == null)
			return false;
		if(splitted[1] != null){
      		var regexp_user=/^\"?[\w-_\.]*\"?$/;
      		if(splitted[1].match(regexp_user) == null) 
      			return false;
    	}
    	if(splitted[2] != null){
      		var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,5}$/;
      		if(splitted[2].match(regexp_domain) == null){
	    		var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    		if(splitted[2].match(regexp_ip) == null)
	    			return false;
      		}
		}
		return true;		
	},
	latinANDnumAnd_ : function(str){
		var illegalChars = /[A-Za-z0-9-_]/; // allow only letters and numbers
    	if (illegalChars.test(str))
      		return true;
    	return false;	 
    },
    latinANDnum : function(str){
		var illegalChars = /^[a-zA-Z0-9-_]*?$/; // allow only letters and numbers
    	if (illegalChars.test(str))
      		return true;
    	return false;	 
    },
    latinANDruANDnum : function(str){
		var illegalChars = /^[a-zA-Zа-яА-Я0-9_\s]*?$/; // allow only letters and numbers
    	if (illegalChars.test(str))
      		return true;
    	return false;	 
    },
    numOnly : function(str){
		var illegalChars = /\d/; // allow only letters and numbers
    	if (illegalChars.test(str))
      		return true;
    	return false;	 
    },
    textString : function(str){
		//alert(str);
		var illegalChars = /[А-Яа-яA-Za-z0-9_-]/; 
    	if (illegalChars.test(str)){
      		return true;
      	}	
    	return false;	 
    },
    testKeylatinANDruANDnum : function(e){
		// Make sure to use event.charCode if available
		var key = (typeof e.charCode == 'undefined' ? e.keyCode : e.charCode);

		// Ignore special keys
  		if (e.ctrlKey || e.altKey || key < 32)
    	return true;

		key = String.fromCharCode(key);
		return /[-А-Яа-яA-Za-z0-9_]/.test(key);
	},
    testKeylatinANDnum : function(e){
		// Make sure to use event.charCode if available
		var key = (typeof e.charCode == 'undefined' ? e.keyCode : e.charCode);

		// Ignore special keys
  		if (e.ctrlKey || e.altKey || key < 32)
    	return true;

		key = String.fromCharCode(key);
		return /[A-Za-z0-9]/.test(key);
	},
    testKeyLoginType : function(e){
		// Make sure to use event.charCode if available
		var key = (typeof e.charCode == 'undefined' ? e.keyCode : e.charCode);

		// Ignore special keys
  		if (e.ctrlKey || e.altKey || key < 32)
    	return true;

		key = String.fromCharCode(key);
		return /[-A-Za-z0-9_]/.test(key);
	},
	testEmailKey : function(e){
		// Make sure to use event.charCode if available
		var key = (typeof e.charCode == 'undefined' ? e.keyCode : e.charCode);

		// Ignore special keys
  		if (e.ctrlKey || e.altKey || key < 32)
    	return true;

		key = String.fromCharCode(key);
		return /[A-Za-z0-9-_\.\@]/.test(key);
	},
	testKeyNumOnly : function(e){
		// Make sure to use event.charCode if available
		var key = (typeof e.charCode == 'undefined' ? e.keyCode : e.charCode);

		// Ignore special keys
  		if (e.ctrlKey || e.altKey || key < 32)
    	return true;

		key = String.fromCharCode(key);
		return /\d/.test(key);
	},
	testTextString : function(e){
		// Make sure to use event.charCode if available
		var key = (typeof e.charCode == 'undefined' ? e.keyCode : e.charCode);

		// Ignore special keys
  		if (e.ctrlKey || e.altKey || key < 32)
    	return true;

		key = String.fromCharCode(key);
		return /[А-Яа-яA-Za-z0-9_\s-]/.test(key);
	},
	testKeyDbTable : function(e){
		// Make sure to use event.charCode if available
		var key = (typeof e.charCode == 'undefined' ? e.keyCode : e.charCode);

		// Ignore special keys
  		if (e.ctrlKey || e.altKey || key < 32)
    	return true;

		key = String.fromCharCode(key);
		console.warn(/\d/.test(key));
		return /\d/.test(key);
		//return /[A-Za-z0-9_]/.test(key);
	}
}


var keyCatcher = {
	capsLock : {
		on : false,
		_catch : function(id,act){
			//if (!e) e = window.event || null;
			alert(id);
			if(!id) obj = document;
			else obj = $("#"+id);
			//alert(obj.id);
			this.act = act;
			//act();
			if (obj.addEventListener){
				//alert('add list to '+obj.id);
				obj.addEventListener("keypress", this.detect, false);
				obj.addEventListener("keydown", this.detect, false);
				
			}
			else if (document.attachEvent){
				obj.attachEvent("onkeypress", this.detect);
				obj.attachEvent("onkeydown", this.detect);
			}
		},
		detect : function(e){
			var n = e.keyCode?e.keyCode:e.charCode;
			if (e.type=="keypress"){
				var c = String.fromCharCode(n);
				var cUC = c.toUpperCase();
				var cLC = c.toLowerCase();
				if (cUC!=cLC) 
					keyCatcher.capsLock.action((e.shiftKey && cLC==c)||(!e.shiftKey && cUC==c));
 			}
 			else if (e.type=="keydown" && n==20) 
 				keyCatcher.capsLock.action(false);
		},
		action : function(pressed){ 
			this.act(pressed);
		}
	}
}

