function Validacja(){
     	  
    this.trim = function(i){
    	return i.replace(/^\s+|\s+$/g,"");
    };
    
     this.liczba = function(i,k){ 
    	i=this.trim(i);    			
		//if(isNaN(s))
		var x = /^[0-9]+$/
		if(!(x.test(i)))
			throw new Error(k);
		return true;
    }; 
        
    this.email = function(i,k){ 
    	i=this.trim(i);     	
    	var x = /^([a-z0-9_\.\-])+\@(([a-z0-9_\-])+\.)+[a-z0-9]{2,4}$/i
		if(!(x.test(i)))
			throw new Error(k);
		return true;
    }; 

    this.empty = function(i){
		i=this.trim(i);			
		if(i!="")			
			return(false);		
		return(true);
	}   
	
    this.emptyEx = function(i,k){
		i=this.trim(i);			
		if(i=="")			
			throw new Error(k);
	}  	
	
	this.password = function(i1, i2){
		i1=this.trim(i1);			
		i2=this.trim(i2);
		var x = /^([0-9a-z]{7,})$/i
		if(!(x.test(i1)))
			throw new Error("Popraw haslo");							
		if(!(x.test(i2)))
			throw new Error("Popraw haslo 2");									
		if(i1!=i2)
			throw new Error("Podales dwa rozne hasla");				
		return(true);		
	}
	
	this.data = function(i){				
		var x = /^([0-9]{4})(\/|-)([0-9]{1,2})(\/|-)([0-9]{1,2})$/;
		var a = i.match(x); 				
		if (a == null)
			throw new Error("Wprowadz date w formacie YYYY/MM/DD lub YYYY-MM-DD.");					
			
		var r = a[1];
		var m = a[3]; 
		var d = a[5];
		
		if (m < 1 || m > 12)
			throw new Error("Wprowadz poprawny miesiac");					
		if (d < 1 || d > 31)
			throw new Error("Wprowadz poprawny dzien");					
		if ((m==4 || m==6 || m==9 || m==11) && d==31)		
			throw new Error("Miesiac: "+m+" nie ma 31 dni");									
		if (m == 2){
			var p = (r % 4 == 0 && (r % 100 != 0 || r % 400 == 0));
			if(d > 29 || (d==29 && !p))
				throw new Error("W roku " + r + " luty nie posiada " + d + " dni");							
		}				
		return(true);		
	}
		
	this.rok = function(i){		
		i=this.trim(i); 
    	var x=/^([0-9]{4})$/   	
		if(!(x.test(i)))
			throw new Error("Wprowadz date w formacie: YYYY");		
		return(true);		
	}
	

	this.daty = function(d1,d2){
				
		d1=d1.replace(/\//gi,'');
		d2=d2.replace(/\//gi,'');
		var d1Int=parseInt(d1);
		var d2Int=parseInt(d2);		
		if(d1Int>d2Int) 
			throw new Error("Wrong end date !");		
	};	
	
	
	this.getIds = function(form, key)
	{
		if(key=='')
			key='id[]';
					
		var f=document.getElementById(form);			
		var tab=f[key];
		
		if(!tab)	
			throw new Error("Nie ma elemntu: "+key);		
		
		var ok=false;
		var len=tab.length;			
		var ids='';
		var index=0;
		
		if(len!=null){						
			for(i=0;i<len;i++){
				var _obj=f[key][i];
					if(_obj.checked){
					if(index==0)
						ids+=_obj.value;
					else
						ids=ids+','+_obj.value;
					index++;
					}
			}
		}else{
			if(tab.checked)
				ids=tab.value;					
		}
		return ids;
	}
		
}
