var idelement_focused='';


jQuery.fn.delay = function(time,func){
	this.each(function(){ setTimeout(func,time); });
	return this;
};


jQuery.fn.aForm = function(options) {
	options = options || {};

	$(this).bind("submit", function() {
		if(options.in_progress==1) return false;
		forma=this;

		$(this).delay(100, function() {
			post_form(forma);
			return false;
		});
		return false;
	});


	function post_form(forma) {
		options.in_progress=1;
		$(forma).parent().css('opacity',0.4);

		$.ajax({
			url: 'includes/forms.php?SID='+$('#SID').val()+'&form_name='+$(forma).attr('id'),
			data: $(forma).serialize(),
			type: 'post',
			dataType: 'script',
			cache: false,
			error: function(request) { alert('AJAX: Server connection error!'); },
			success: function(response) {
				options.in_progress=0;
				$(forma).parent().css('opacity',1);
			}
		});
	}
}


function show_hide(list) {
	var listElementStyle=document.getElementById(list).style; 
	if (listElementStyle.display=="none") {
		listElementStyle.display="inline";
	} else {
		listElementStyle.display="none";
	} 
}

function show_hide_block(list) {
	var listElementStyle=document.getElementById(list).style; 
	if (listElementStyle.display=="none") {
		listElementStyle.display="block";
	} else {
		listElementStyle.display="none";
	} 
}

function potwierdzenie(link,pytanie,komunikat) {
	var sprawdz = window.confirm(pytanie);
	if(sprawdz==true) {
		window.location=link;
		if(komunikat!="" && komunikat!=" ") alert(komunikat);
		return false;
	}
}

function link_potwierdzenie(link,pytanie) {
	var sprawdz = window.confirm(pytanie);
	if(sprawdz==true) window.location=link;
}


function input_validator(e, regexp) {
	if(navigator.userAgent.indexOf('Gecko') != -1) charCode = e.which; else charCode = e.keyCode;
	if(charCode > 31) {
		znak = String.fromCharCode(charCode);
		return regexp.test(znak);
	}
}