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.zaznaczone = function(p,k){

    	if(!p.checked)
			throw new Error(k);
	};


    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.datetime = function(input){
		var x = /^([0-9]{4})(\/|-)([0-9]{1,2})(\/|-)([0-9]{1,2})([\ ]{1,}([0-9]{1,2})\:([0-9]{1,2})(\:([0-9]{1,2}))?)?$/;
		var a = input.match(x);
		if (a == null)
			throw new Error("Wprowadz date w formacie YYYY/MM/DD HH:II lub YYYY-MM-DD HH:II.");


		var r = a[1];
		var m = a[3];
		var d = a[5];
		var h = a[7];
		var i = a[8];

		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");
		}
		if(h!=undefined && (h<0 || h>24))
			throw new Error("Wprowadz poprawny czas");
		if(i!=undefined && (i<0 || i>60))
			throw new Error("Wprowadz poprawny czas");


		return(true);
	};



	this.daty = function(d1,d2){


		d1=d1.replace(/\-/gi,'');
		d2=d2.replace(/\-/gi,'');
		var d1Int=parseInt(d1);
		var d2Int=parseInt(d2);
		//alert(d1Int+':'+d2Int);
		if(d1Int>d2Int)
			throw new Error("Data początku  nie może być większa od daty końca !");
	};

	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.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;
	};

	this.konwertujUrl = function(url)
	{
		url=url.toLowerCase();
		var u=Array(/ą/g,/ź/g,/ś/g,/ę/g,/ó/g,/ł/g,/ż/g,/ć/g,/ń/g,/ /g);
	    var c=Array("a","z","s", "e","o","l", "z", "c", "n", "_");
	   	for(i=0;i<u.length; i++)
			url=url.replace(u[i],c[i]);
		url=url.replace(/[^a-z0-9_\/\-]/g,'');
		return url;
	};

	this.image = function(i,k){
    	i=this.trim(i);
    	var x = /^(.)+\.(png|gif|jpg|jpeg)$/i
		if(!(x.test(i)))
			throw new Error(k);
		return true;
    };

    this.doc = function(i,k){
    	i=this.trim(i);
    	var x = /^(.)+\.(rtf|doc|docx|pdf|odt)$/i
		if(!(x.test(i)))
			throw new Error(k);
		return true;
    };
}

var _currentElement=null;
	function showTooltip(s)
	{
		if(_currentElement)
			_currentElement.style.display='none';

		//alert("czy MSIE? "+jQuery.browser.msie+"\n"+"czy wersja 6? "+(parseInt(jQuery.browser.version)==6)+"\n\n"+jQuery.browser.version);
		if(jQuery && jQuery.browser.msie && parseInt(jQuery.browser.version)==6) {
      $('select').css('visibility', 'hidden');
    }

		var p=s.parentNode;
		if(p){
			var nodes=p.childNodes;
			if(nodes)
				for(i=0;i<nodes.length;i++){
					var element=nodes[i];
					if(element.nodeName.toLowerCase()=='div'){
						element.style.display='block';
						_currentElement=element;
					}
			}
		}
	}
	function hideTooltip(obj)
	{
		obj.style.display='none';

		if(jQuery && jQuery.browser.msie && parseInt(jQuery.browser.version)==6) {
      $('select').css('visibility', 'visible');
    }
	}

	function changeLang(f)
	{
		if(f){
			var host=window.location.hostname;
			var uri=window.location.pathname;
			uri=uri.replace('/en/','/');
			uri=uri.replace('/pl/','/');
			uri=uri.replace('/ru/','/');
			var lang=document.getElementById('langSelect').value;
			if(lang!='pl')
				f.action='/'+lang+uri;
			else
				f.action=uri;
		}

	}
