var img=new Image();
img.src="img/spinner.gif";
var spinnerDimensions = 16;

jQuery.fn.spinner = function() 
{
	h=this.height();
	if (h<spinnerDimensions)
		h=spinnerDimensions;
	w=this.width();
	if (w<spinnerDimensions)
		w=spinnerDimensions;

	this.html('<div style="height: '+(h)+'px; width: '+(w)+'px; background: center no-repeat url('+img.src+')"></div>'); 	
};

jQuery.fn.loads = function(url, msgOk, msgErr) 
{
	$(this).spinner();
	
	if (url.href)
		url=url.href;
	else
		url=base+url;
		
	id=this;
	$.get(url, function(data){
	    if (typeof msgOk == 'undefined') 
	    	$(id).html(data);
	    else
	    {
	    	if (data.substr(0,2)=='ok')
	    		$(id).html(msgOk);
	    	else
	    	{
	    		if (typeof msgErr != 'undefined') 
	    			$(id).html(msgErr);
	    		else
	    			$(id).html(msgOk);
		    }
	    }
	});
};

function l(msg)
{
	if (console!=undefined)
		console.log(msg);
}

function show_promotions(id)
{
	$('#promotion-box').spinner();
	
	url = base + identUser + '/promotions/view/' + id;
    $.get(url, function(data){
        $('#promotion-box').html(data);
		Cufon.refresh('.cw7 h3, .cw7 .buy a');
    });
}

function show_news(id)
{
	$('#news-box').spinner();
	
	url = base + identUser + '/news/view/' + id;
    $.get(url, function(data){
        $('#news-box').html(data);
		Cufon.refresh('.header .h');
    });
}

function show_form1()
{
	$('#over').show();
	url = base + 'pages/user_declaration.php';
	$('#overc').load(url);
}

function show_form2(postData)
{
	$('#overc').spinner();
	url = base + 'users/add';
	$.post(url, postData, function(data){
         $('#overc').html(data);
    });
}

function show_form3()
{
	$('#over').show();
	url = base + 'users/forgot';
	$('#overc').load(url);
}

function show_product_info(id)
{
	$('#over').show();
	url = base + 'products/view/'+id;
	$('#overc').load(url);
}

function hide_over()
{
	$('#over').hide();
}
function send_form1()
{
	declaration = $('#p1').val();
	
	agree = $('#p2:checked').length;

	if(declaration=='')
	{
		alert('Proszę wpisać numer deklaracji.');
		return false;
	}
	
	if(agree=='0')
	{
		alert('Proszę zaznaczyć akceptację regulaminu.');
		return false;
	}
	
	$('#overc').spinner();
	url = base + 'pages/user_declaration.php?declaration=' + declaration;
	$('#overc').load(url);
}

function send_form2()
{
	url = base + 'users/add';
	postData = $('#UserAddForm').serialize();
	
	$('#overc').spinner();
	
	$.post(url, postData, function(data){
		 $('#overc').html(data);
    });
}

function send_form3()
{
	url = base + 'users/forgot';
	postData = $('#UserAddForm').serialize();
	
	$('#overc').spinner();
	
	$.post(url, postData, function(data){
         $('#overc').html(data);
    });
}
