var globale = {adres:'',gdzie:''};
var last = '#przes';
function usun_ozs2(id){
	$('#del'+id).attr('value',id);
}
function usun_ozs(id){
	$('#add'+id).attr('value',0);
}
function wzs(page,serialized){
	bc('Proszę czekać');
	$.post(page,serialized,function(data){
		$('#fotos').html($('#fotos').html()+data);
		$.unblockUI();
	});
}
function makeTip(war,con){
	$(war).wTooltip({ 
		content: con, 
		style: {
			border: "1px solid black", 
			background: "#CCCCCC", 
			color: "black", 
			fontWeight: "bold" 
		} 
	});
}
function makeSort(a,b,c,d){
	if($(a).css('display')=='none'){
		$(a).toggle('slow');
		$(last).SortableDestroy();
		admin_makeMoveable('admin.php?module='+d+'&mode=cat&m=move',a,c,b);
		if(last!=a && last!='#przes')
			$(last).toggle('slow');
		last = a;
	}else{
		$(a).toggle('slow');
		$(last).SortableDestroy();
		admin_makeMoveable('admin.php?module='+d+'&mode=cat&m=move','#przes','przesable','przes');
		last = '#przes';
	}
}

function admin_makeMoveable(page,where,what,ons){
	$(where).Sortable({
		accept: what,
		opacity: 0.5,
		onStop: function(){
			bc('Zapisywanie');
			serial = $.SortSerialize(ons);
			$.post(page,serial.hash,function(data){
				$.unblockUI();
			});
		}});
}

function reloadOverlay(page){
	bc('Proszę czekać');
	$.get(page,function(data){
		$('#innerBox').html(data);
		$.unblockUI();
	});
}
function sendNewsletter(page,serialized){
	bc('Zapisywanie');
	$.post(page,serialized,function(data){
		$('#content').html(data);
		$.unblockUI();
	});
}
function sendForm(page,serialized,loadAfter,where,close){
	bc('Zapisywanie');
	$.post(page,serialized,function(data){
		$.get(loadAfter,function(data){
			$(where).html(data);
			if(globale.adres!=''){
				$.get(globale.adres,function(data){
					$(globale.gdzie).html(data);
					$.unblockUI();
					if(close==1)
						hideBox();
				});
			}else{
				$.unblockUI();
			}
		});
	});
}
function sendAjax(page){
	bc();
	$.get(page,function(data){
		if(globale.adres!=''){
			$.get(globale.adres,function(data){
				$(globale.gdzie).html(data);
				$.unblockUI();
				if(close==1)
					hideBox();
			});
		}else{
			$.unblockUI();
		}
	});
}
function bc(mess){
	if(mess=='undefined' || !mess)
		mess = 'Proszę czekać';
	$.blockUI({message: '<h1>'+mess+'</h1>', css: { 
            border: 'none', 
            padding: '15px',
            
            backgroundColor: '#CCCCCC', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px',
            opacity: .7, 
            color: '#878181' 
        }});
}
function admin_content(page){
	bc();
	$.get(page,function(data){
		$('#content').html(data);
		$.unblockUI();
	});
}
function wid(){
    if(jQuery.browser.msie){
        return {
            w:document.documentElement.offsetWidth,
            h:document.documentElement.offsetHeight
        }
    }
    else
        return {w:window.innerWidth, h:window.innerHeight}
}
function getW(){
	winHeight = $('#bodyC').css('height');
	all = wid();
	if(all.h>parseInt(winHeight))
		return all.h;
	else
		return winHeight;
}
function loadOverlay(page){
	bc();
	$.get(page,function(data){
		$.unblockUI();
		$('#innerBox').html(data);
		$('#cos').css('display','block');
		showBox();
	});
}
function showBox(){
	$('#overlay').show();
	$('#box').center();
	$('#overlay').animate({'opacity': 0.9},500);
	$('#box').toggle(600);
	e = getW();
	if(parseInt($('#innerBox').css('height'))>e)
		a = parseInt($('#innerBox').css('height'))+50;
	else
		a = e;
	$('#overlay').css('height',a+'px');
	if(parseInt($('#box').css('top'))<20)
		$('#box').css('top',20);
    return false;
}
function hideBox(){
	$('#overlay').animate({'opacity': 0},500);
    $('#box').toggle(600);
	$('#overlay').hide(500);
	$('#cos').css('display','none');
	globale.adres = '';
	globale.gdzie = '';
    return false;
}
