
var domainURL = 'http://' + document.domain + '/';
var imgDomainURL = '';
var iconWait = '<img src="'+domainURL+'static/im/wait.gif" alt="'+PLEASE_WAIT+'..."/>';

var APP_URL = 'http://'+document.domain+'/';
var ICON_WAIT = 'http://' + document.domain + '/static/im/wait.gif';
var ICON_IMG = '<img src="'+ICON_WAIT+'" alt="'+PLEASE_WAIT+'"/>';

var fhelpers = new Array(70);
var temp_var = '';

function loginForm()
{
	$("#login_button").attr('src',"/static/im/loader.gif");
	$("#err_login_form").html('');
	$.post("/user/login/",
		  $("form[name='login_form']").serialize(),
		  function(data)
		  {
		  	//alert(data.result);
			if (data.result == 1)
			{
				if ($("#backurl").val())
					location.href = baseURL +$("#backurl").val();
				else
					location.reload(true);
			}
			else if (data.result == -1)
			{
				$("#login_button").attr('src',"/static/im/log_btn.png");
				$("#err_login_form").html(ACCOUNT_BLOCKED);
			}					
			else if (data.result == -2)
			{
				$("#login_button").attr('src',"/static/im/log_btn.png");
				$("#err_login_form").html(ACCOUNT_NOT_ACTIVATED+', <a href="#" onclick="javascript:resendActivationEmailForm();return false;">'+CLICK_HERE+'</a>.');
			}					
			else
			{
				$("#login_button").attr('src',"/static/im/log_btn.png");
				$("#err_login_form").html(INCORRECT_LOGIN_DATA);
			}
	
		  },
		  'json');	 
	return false;
}
function resendActivationEmailForm()
{
	$("#login_button").attr('src',"/static/im/loader.gif");
	$("#err_login_form").html('');
	$.post("/registration/resendactivationemail/",
		  $("form[name='login_form']").serialize(),
		  function(data)
		  {
		  	if (data.result == 1)
			{
				$("#login_button").attr('src',"/static/im/log_btn.png");
				$("#err_login_form").html();
			}
			else if (data.result == 2)
			{
				$("#login_button").attr('src',"/static/im/log_btn.png");
				$("#err_login_form").html(INCORRECT_LOGIN_DATA);
			}						
			else
			{
				$("#login_button").attr('src',"/static/im/log_btn.png");
				$("#err_login_form").html(ACTIVATION_EMAIL_ERR);
			}
	
		  },
		  'json');	 
	return false;
}


function url(u,a)
{
	a = a.length == 0?u:a;
	u = (u.substring(0,7) == 'http://' || u.substring(0,8) == 'https://')?u:('http://'+u);
	document.write('<a href="'+u+'" target="_blank">'+a+'</a>');
}

function goto(url)
{
	if (url.substr(0,7) != 'http://' && url.substr(0,8) != 'https://')
		url = 'http://'+url;
	if (url.length > 3)
		document.location.href=url;
}

function burl(u,im,a)
{
	document.write('<a href="'+u+'" target="_blank" title="'+a+'"><img src="'+im+'" alt="'+a+'"/></a>');
}


function searchMenu(url)
{
	var st = $('#searchtextmenu').attr('value');
	if (st == SEARCH_TITLE || st.length == 0)
	{
		$('#searchtextmenu').focus();
		return false;
	}
	st = st.replace('/','-');
	st = st.replace('?','-');
	st = encodeURIComponent(st);
	url += SEARCH_ALL+'/'+st+'/';
	window.location.replace(url);
	return false;
}

function deleteMBPost(uid,id)
{
	if(!confirm(DELETE_NEWS+'?'))return;
	$('#miniblog_'+id).html('czekaj...');
	$.ajax({type:'POST',url:APP_URL+'/profile/deletembmsg/',data:{msg_id:id,uid:uid},
	success:function(txt)
	{
		if (txt == '1')
			$('#miniblog_'+id).html(DELETED_NEWS);
		else
			$('#miniblog_'+id).html(ERROR);
	}});
}

function addMBMsg()
{
	var isValid=true;
	$('#err_mb_msg').html('');
	$('#err_pictures_id').html('');
	
	var msg=$('#mb_msg').attr('value');
	if(!msg || msg.length<2)
	{
		$('#err_mb_msg').html(MIN_LENGTH2);
		isValid=false;
	}
	
	if($('#pictures_id').val().length > 4 && isImageExtension($('#pictures_id').val()) == false)
	{
		$('#err_pictures_id').html(IMG_EXTENSION);
		isValid = false;
	}
	
	return isValid;
}

function editHeadThought()
{
	if ($('#head_thought').css('display') == 'block')
	{
		$('#head_thought').css({display:'none'});
		$('#head_thought_edit').css({display:'block'});
	}
	else
	{
		$('#head_thought').css({display:'block'});
		$('#head_thought_edit').css({display:'none'});
	}
}

function saveHeadThought()
{
	var hdt=$('#ht_text').attr('value');
	$('#ht_text_button').attr('disabled','true');
	$('#err_ht_text').html(ICON_IMG);
	$.ajax({type:'POST',url:APP_URL+'/profile/addhdtxt/',data:{hdt:hdt},
	success:function(txt){
		$('#err_ht_text').html('Zapisano');
		$('#head_thought').html(hdt);
		$('#ht_text_button').attr('disabled','');
		editHeadThought();
	}});
}

function deleteMessage(id, directory)
{
	if (directory == 0)
	{
		if(!confirm(DELETE_NEWS+'?'))return;
		$('#message_'+id).html(ICON_IMG);
		$.ajax({type:'POST',url:APP_URL+'/messages/handler/',data:{id:id,directory:directory},
		success:function(txt){
			$('#message_'+id).html('Usunięto');
		}});
	}
	else
	{
		if(!confirm(MESSAGE_2_TRASH+'?'))return;
		$('#message_'+id).html(ICON_IMG);
		$.ajax({type:'POST',url:APP_URL+'/messages/handler/',data:{id:id,directory:directory},
		success:function(txt){
			$('#message_'+id).html(MOVED_2_TRASH);
		}});
	}
}

function rejectInvitation(uid,id)
{
	$('#friend_request_opt_'+id).html(PLEASE_WAIT);
	$.ajax({type:'POST',url:APP_URL+'/account/friendsrequests/',data:{kind:1,id:id,uid:uid},
	success:function(txt)
	{
		if (txt == null || txt.length == 0)
			$('#friend_request_'+id).html(ERROR);
		else
			$('#friend_request_'+id).html('Zaproszenie odrzucone');
	}});
}

function deleteInvitation(uid,id)
{
	$('#friend_request_opt_'+id).html('czekaj...');
	$.ajax({type:'POST',url:APP_URL+'/account/friendsrequests/',data:{kind:2,id:id,uid:uid},
	success:function(txt)
	{
		if (txt == null || txt.length == 0)
			$('#friend_request_'+id).html('Błąd');
		else
			$('#friend_request_'+id).html('Zaproszenie usunięto');
	}});
}

function acceptInvitation(uid,id)
{
	$('#friend_request_opt_'+id).html('czekaj...');
	$.ajax({type:'POST',url:APP_URL+'/account/friendsrequests/',data:{kind:3,id:id,uid:uid},
	success:function(txt)
	{
		if (txt == null || txt.length == 0)
			$('#friend_request_'+id).html('Błąd');
		else
			$('#friend_request_'+id).html('Jesteście znajomymi!');
	}});
}

function deleteFriendGroup(id)
{
	$('#friend_request_opt_'+id).html('czekaj...');
	$.ajax({type:'POST',url:APP_URL+'/account/friendsrequests/',data:{kind:3,id:id,uid:uid},
	success:function(txt)
	{
		if (txt == null || txt.length == 0)
			$('#friend_request_'+id).html('Błąd');
		else
			$('#friend_request_'+id).html('Jesteście znajomymi!');
	}});
}

function deleteFriendGroup(id)
{
	$('#friend_group_opt_'+id).html('czekaj...');
	$.ajax({type:'POST',url:APP_URL+'/account/friendsrequests/',data:{kind:4,id:id},
	success:function(txt)
	{
		if (txt == null || txt.length == 0)
			$('#friend_group_'+id).html('Błąd');
		else
			$('#friend_group_'+id).html('Grupa została usunięta a jej członkowie przeniesieni do grupy głównej');
	}});
}

function editFriendGroup(id)
{
	$('#friend_group_opt_'+id).html('jeszcze nie ma');
}


function removeFriend(id)
{
	if(!confirm('Czy na pewno usunąć z listy znajomych?'))return;
	$('#friend_opt_'+id).html(ICON_IMG+' czekaj...');
	$.ajax({type:'POST',url:APP_URL+'/account/friendsrequests/',data:{kind:5,id:id},
	success:function(txt)
	{
		if (txt == null || txt.length == 0)
			$('#friend_'+id).html('Błąd');
		else
			$('#friend_'+id).html('Usunięty ze znajomych');
	}});
}

function showBox(open,close)
{
	$('#'+open).slideDown('slow');
	$('#'+close).hide('slow');
}

function showInfo(id)
{
	alert(HELP_ERROR+'...');
}

function mark(o)
{  
	o.focus();  
	o.select();  
} 

function autoKredytowanie()
{
	var isChecked = $('#nowy').attr('checked');
	if(isChecked == true)
	{
		$('#rocznik').attr('value', '');
		$('#rocznik').attr('readonly', 'readonly');
	}
	else
	{
		$('#rocznik').attr('readonly', '');
	}
}

var ie=(document.all)?true:false;
if(!ie){document.addEventListener('mousemove', mpos, false);var pozX,pozY;}

function mpos(e){pozX=e.pageX;pozY=e.pageY;}
function bout(){$('#bubble').css('display','none');}

function bmov()
{
	scrolly=0;
	if(document.documentElement.scrollTop)scrolly=document.documentElement.scrollTop;
	if(document.body.scrollTop)scrolly=document.body.scrollTop;
	var x=(!ie)?pozX:event.x+document.body.scrollLeft;
	var y=(!ie)?pozY:event.y+scrolly;
	$('#bubble').css({left:x+5+'px', top:y+2+'px'});
}

function bover(id)
{
	bmov();
	initBubble(id);
	$('#bubble').css('display','block');
	return true;
}

function bover_info(t)
{
	bmov();
	setBubble('', t);
	$('#bubble').css('display','block');
//	return true;
}

function b_txtover(btxt)
{
	if(btxt.length>0)
	{
		setBubble('',btxt);
		bmov();
		$('#bubble').css('display','block');
	}
	return true;
}

function setBubble(t,info)
{
	$('#bubble_t').text(t);
	$('#bubble_info').html(info);
}

function initBubble(id)
{
	if(id>0)
	{
		if(typeof fhelpers[id] === 'undefined')
		{
			setBubble('Wczytuję...',ICON_IMG);
			$.getJSON(APP_URL+'objasnienie/pobierz/'+id,function(json){
				setBubble(json.name,json.description);
				fhelpers[id] = [json.name,json.description];
			});
		}else setBubble(fhelpers[id][0],fhelpers[id][1]);
	}else setBubble('Wczytuję...',ICON_IMG);
}


function dForum(id,kind)
{
	if(!confirm(R_U_SURE))return;
	$('#moderator_'+id).html(ICON_IMG);
	$.ajax({type:'POST',url:APP_URL+'forum/delete/id/'+id,data:{kind:kind},
	success:function(txt)
	{
		if (txt == '1')
			$('#moderator_'+id).html(DELETED);
		else
			$('#moderator_'+id).html(ERROR);
	}});
}

function dOpinion(id,tn,tid)
{
	if(!confirm(R_U_SURE))return;
	$('#moderator_'+id).html(ICON_IMG);
	$.ajax({type:'POST',url:APP_URL+'opinions/dlt/poid/'+id,data:{tn:tn,tid:tid,id:id},
	success:function(txt)
	{
		if (txt == '1')
			$('#moderator_'+id).html(DELETED);
		else
			$('#moderator_'+id).html(ERROR);
	}});
}

function dArtComment(id)
{
	if(!confirm(R_U_SURE))return;
	$('#moderator_'+id).html(ICON_IMG);
	$.ajax({type:'POST',url:APP_URL+'news/delete/',data:{id:id},
	success:function(txt)
	{
		if (txt == '1')
			$('#moderator_'+id).html(DELETED);
		else
			$('#moderator_'+id).html(ERROR);
	}});
}

function validateSavingAccounts()
{
	var kwota=$('#kwota').attr('value');
	$('#kwota_err').text('');
	if (kwota <= 0)
	{
		$('#kwota_err').text(ENTER_AMOUNT);
		return false;
	}
	return true;
}

function valArtComment(u)
{
	var isValid=true;
	$('#err_comment').html('');
	$('#fac').val('');
	
	if($('#comment').val().length < 3)
	{
		$('#err_comment').html(MIN_LENGTH3_COMMENT);
		isValid=false;
	}

	if (isValid == true)
	{
		$('#fac').val('fac');
		$('#fac_form').attr('action', u);
	}
	return isValid;
}

function valRemindPass()
{
	var isValid=true;
	$('#err_email').html('');
	if($('#email').val().length < 3)
	{
		$('#err_email').html(MIN_LENGTH3);
		isValid=false;
	}
	return isValid;
}


function valOpinion(u)
{
	var isValid=true;
	$('#err_comment').html('');
	$('#err_title').html('');
	$('#fao').val('');
	
	if($('#comment').val().length < 3)
	{
		$('#err_comment').html(MIN_LENGTH3_CONTENT);
		isValid=false;
	}
	if($('#title').val().length < 3)
	{
		$('#err_title').html(MIN_LENGTH3_TITLE);
		isValid=false;
	}
	
	if (isValid == true)
	{
		$('#fao').val('fao');
		$('#fao_form').attr('action', u);
	}
	return isValid;
}

function validateTermDeposits()
{
	var kwota=$('#kwota').attr('value');
	$('#kwota_err').text('');
	if (kwota <= 0)
	{
		$('#kwota_err').text(ENTER_DEPOSIT_AMOUNT);
		return false;
	}
	return true;
}

function validateKredytHipoteczny()
{
	var kwota=$('#kwota').attr('value');
	$('#kwota_err').text('');
	if (kwota <= 0)
	{
		$('#kwota_err').text(ENTER_CREDIT_AMOUNT);
		return false;
	}
	return true;
}

function showAllElems(elemClass, elemID)
{
	$('#'+elemID).hide('slow');
	$('.'+elemClass).slideDown('slow');
}

function valChangeLostPass()
{
var isValid = true;
clearField('err_password');
clearField('err_re_password');
if ($('#password').val().length <= 5)
{
	$('#err_password').text(MIN_LENGTH5);
	isValid = false;
}

if ($('#re_password').val().length <=5 || $('#password').val() != $('#re_password').val())
{
	$('#err_re_password').text(PASSWORDS_DONT_MATCH);
	isValid = false;
}	
return isValid;
}


function valRegistration(isCompetition)
{
var isValid = true;
clearField('err_login');
clearField('err_email');
clearField('err_password');
clearField('err_re_password');
clearField('err_gender');

if ($('#login_reg').val().length <= 2)
{
	$('#err_login').text(MIN_LENGTH3);
	isValid = false;
}

if ($("input[name='gender']:checked").val() == undefined)
{
	$('#err_gender').text(SELECT_GENDER);
	isValid = false;
}

if (isCompetition == 1)
{
clearField('err_first_name');
clearField('err_surname');
clearField('err_provinces_id');
clearField('err_city');
clearField('err_err_phone_no');

if ($('#first_name').val().length <= 3)
{
	$('#err_first_name').text(MIN_LENGTH3);
	isValid = false;
}

if ($('#surname').val().length <= 3)
{
	$('#err_surname').text(MIN_LENGTH3);
	isValid = false;
}

if ($('#city').val().length <= 3)
{
	$('#err_city').text(MIN_LENGTH3);
	isValid = false;
}

if ($('#phone_no').val().length <= 2)
{
	$('#err_phone_no').text(ENTER_PHONE);
	isValid = false;
}

if (!($('#birthday_date_dd').val() > 0 && $('#birthday_date_mm').val() > 0 && $('#birthday_date_yyyy').val() > 0))
{
	$('#err_birthday_date').text(ENTER_DOB);
	isValid = false;
}

if ($('#provinces_id').val() <= 0)
{
	$('#err_provinces_id').text(SELECT_FROM_LIST);
	isValid = false;
}

}
	return isValid;
}

function clearField(id)
{
	/*$('#'+id).hide('slow');*/
	$('#'+id).html('');
}

function deleteUserImage(id)
{
	if(!confirm('Czy na pewno chcesz usunąć to zdjęcie?'))return;
	$('#userImageWait_'+id).html(ICON_IMG+' Usuwanie. Proszę czekać...');
	$.ajax({type:'POST',url:APP_URL+'uzytkownik/deleteuserimage/',data:{f:'fpp',pid:id},
	success:function(txt)
	{
		alert(txt);
		if (txt == '1')
			$('#userImage_'+id).html('Zdjęcie usunięte');
		else
			$('#userImage_'+id).html('Błąd podczas usuwania zdjęcia.');
	}});
}

function setUserAvatar(id)
{
	$('#userAvatarWait_'+id).html(ICON_IMG+PLEASE_WAIT+' ...');
	var imgsrc = $('#userImageSrc_'+id).attr('src');
	imgsrc = imgsrc.replace('_160', '_90');
	$.ajax({type:'POST',url:APP_URL+'uzytkownik/setuseravatar/',data:{f:'fpp',pid:id},
	success:function(txt)
	{
		$('#userAvatarWait_'+id).hide();
		alert(txt);
		if (txt == '1')
		{
			$('#userAvatar').attr('src', imgsrc);
			alert('Avatar zmieniony');
		}
		else
			alert('Błąd podczas ustawiania Avatara');
	}});
}

function showFmbOption(id)
{
	$('#fmb_icon'+id).hide();
	$('#fmb_option'+id).show('slow');
}


/*
var prototype = {};
prototype.string = {};

prototype.string.autolink = function (string, options){
    if(!options) options = {};
    if(!options.limit) options.limit;
    if(!options.tagFill) options.tagFill = '';
    
    var regex = /((http\:\/\/|https\:\/\/|ftp\:\/\/)|(www\.))+(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi;
    
    string = string.replace(regex, function(value){
       // value = value.toLowerCase();
        var m = value.match(/^([a-z]+:\/\/)/);
        var nice;
        var url;
        
        if(m)
        {
            nice = value.replace(m[1],'');
            url = value;
        }
        else
        {
            nice = value;
            url = 'http://' + nice;
        }
        
        return '<a href="' + url + '"' + (options.tagFill != '' ? (' ' + options.tagFill) : '')+ ' ref="nofollow" target="_blank">' + prototype.string.autolinkLabel(nice, options.limit) + '</a> ';
    });
    return string;
};


prototype.string.autolinkLabel = function (text, limit){

    if (!limit){ return text; }

    if (text.length > limit){
        return text.substr(0, limit - 3) + '...';
    }

    return text;
};

$(function(){
	 jQuery.each($('.news_content'), function() {
	$(this).html((prototype.string.autolink($(this).html())));
    });
});
*/

function setAward(tn,tid)
{
	var a=$('#award_ac').val();
	$('#set_award').html(ICON_IMG);
	$.ajax({type:'POST',url:APP_URL+'informacje/setaward/',data:{f:'fsa',a:a,tn:tn,tid:tid},
	success:function(txt)
	{
		if (txt == '1')
			$('#set_award').html(AWARD_SET);
		else $('#set_award').html(ERROR);
	}});
}

function delAvatarSubmit()
{
	return confirm('Na pewno usunąć aktualny Avatar?');
}

function sendContactForm()
{
	var isValid = true;
	$('#err_first_name').text('');
	$('#err_surname').text('');
	$('#err_phone_no').text('');
	$('#err_city').text('');
	$('#err_email').text('');
	$('#err_regulations').text('');
	
	if ($('#first_name').val().length < 3)
	{
		$('#err_first_name').text(ENTER_FIRSTNAME);
		isValid = false;
	}
	
	if ($('#surname').val().length < 3)
	{
		$('#err_surname').text(ENTER_SURNAME);
		isValid = false;
	}
	
	if ($('#phone_no').val().length < 7)
	{
		$('#err_phone_no').text(ENTER_CONTACT_PHONE);
		isValid = false;
	}
	
	/*if ($('#city').val().length < 3)
	{
		$('#err_city').text(ENTER_CITY);
		isValid = false;
	}*/
	
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	if($('#email').val().length > 3 && !emailReg.test($('#email').val()))
	{
		$('#err_email').text(ENTER_EMAIL);
		isValid = false;
	}
	
	var isChecked = $('#regulations').attr('checked');
	if(isChecked == false)
	{
		$('#err_regulations').text(ACCEPT_CONTACT_FORM);
		isValid = false;	
	}
	
	if (isValid == true && $('#submit-motion').attr('tnm').length >= 2)
	{
		$('#sm_tnm').val($('#submit-motion').attr('tnm'));
		$('#sm_tid').val($('#submit-motion').attr('tid'));
	}
	return isValid;
}

function wtxt(t){document.write(t);}

function hideMotionPopup()
{
	$('#motion-popup').hide('slow');
}

function walCenz(s){
t=new Array("kurw","qrw","huj","cipa","pojeb","jeba","przyjeb","dziwk","dzifk","zajeb","pierdol","pierdal","bitch","fuck","shit","gówn","rucha","t e s t i q","bitch","whore","slut","lesbian","bisexual","sexual");
for(i=0;i<t.length;i++)if(s.toLowerCase().indexOf(t[i])>=0)return true;
return false;
}

function addForumThread(u,isl)
{
	var isValid = true; 
	$('#err_subject').html('');
	$('#err_author').html('');
	$('#err_description').html('');
	
	if($('#subject').val().length < 3)
	{
		$('#err_subject').html(THREAD_TITLE_ERR);
		isValid = false;
	}
	else if(walCenz($('#subject').val()))
	{
		$('#err_subject').html(COMMENT_CENSORE);
		isValid = false;
	}
	
	if (isl == '')
	if($('#author').val().length < 3)
	{
		$('#err_author').html(ENTER_THREAD_AUTHOR);
		isValid = false;
	}
	else if(walCenz($('#author').val()))
	{
		$('#err_author').html(AUTHOR_CENSORE);
		isValid = false;
	}
	
	if($('#description').val().length < 3)
	{
		$('#err_description').html(THREAD_CONTENT_LENGTH);
		isValid = false;
	}
	else if(walCenz($('#description').val()))
	{
		$('#err_description').html(CONTENT_CENSORE);
		isValid = false;
	}
	
	
	if (isValid == true)
	{
		$('#fname').val('fat');
		$('#fat_form').attr('action', u);
	}
	return isValid;
}

function addForumPost(u,isl)
{
	var isValid = true; 
	$('#err_author').html('');
	$('#err_description').html('');
	$('#err_pictures_id').html('');
	
	if (isl == '') //not logged
	{
		if($('#author').val().length < 3)
		{
			$('#err_author').html(POST_AUTHOR);
			isValid = false;
		}
		else if(walCenz($('#author').val()))
		{
			$('#err_author').html(POST_AUTHOR_CENSORE);
			isValid = false;
		}
		
	} else {
		if($('#pictures_id').val().length > 4 && isImageExtension($('#pictures_id').val()) == false)
		{
			$('#err_pictures_id').html(IMG_EXTENSION);
			isValid = false;
		}
	}
	
	if($('#description').val().length < 3)
	{
		$('#err_description').html(POST_CONTENT_LENGTH);
		isValid = false;
	}
	else if(walCenz($('#description').val()))
	{
		$('#err_description').html(POST_CONTENT_CENSORE);
		isValid = false;
	}
	
	
	if (isValid == true)
	{
		$('#fname').val('fap');
		$('#fat_form').attr('action', u);
	}
	return isValid;
}

function showAndHide(hide, show)
{
	$('#'+hide).hide('slow');
	$('#'+show).show();
}

function moreCategories()
{
	showAndHide('moreCatTitle','moreCatItems');
	$('.top_section').css({'height':'2250px'});
}

function isImageExtension(name)
{
	var valid_extensions = /(.gif|.jpg|.jpeg|.png)$/i;
	return valid_extensions.test(name);
}

$.fn.scrollingDiv = function()
{
	var scrollingDiv = this;
		
    var w_height = $(window).height();
    var p_height = $(document).height();
    var scrollingDiv_height = $(this).height();
    var tmp_top = w_height - scrollingDiv_height;
    if (p_height <= w_height+scrollingDiv_height)
        return false;


    $(window).scroll(function()
   	{
    	if ($(scrollingDiv).html().length == 0)
    		return false;
    	var w_top = $(window).scrollTop();
        tmp_top = w_height + w_top - scrollingDiv_height;
        if (w_top > 0)
        {
			if ($(scrollingDiv).css('display') == 'none')
				$(scrollingDiv).show('slow').css({'top': tmp_top+'px', 'right':'0px'});
			else
				$(scrollingDiv).animate({'top': tmp_top+'px', 'right':'0px'}, {easing: 'swing', queue: false, duration: 500});
        }
        else if($(scrollingDiv).css('display') == 'block')
        {    
        	$(scrollingDiv).hide('slow');
        }

    });
}

function ajaxCreditWidget(sort)
{
	var url_vars = temp_var;
	if ($('#banks_id').val() > 0)
		url_vars += '&bk[]='+toInt($('#banks_id').val());

	if ($('#currencies_id').val() > 0)
		url_vars += '&cr[]='+toInt($('#currencies_id').val());
	
	if ($('#kwota').val() > 0)
		url_vars += '&kwota='+toInt($('#kwota').val());

	if ($('#wn').val() > 0)
		url_vars += '&wn='+toInt($('#wn').val());

	if ($('#okres_rok').val() > 0)
		url_vars += '&okres_rok='+toInt($('#okres_rok').val());

	if ($('#okres_mc').val() > 0)
		url_vars += '&okres_mc='+toInt($('#okres_mc').val());

	if ($('#dochod').val() > 0)
		url_vars += '&dochod='+toInt($('#dochod').val());

	if ($('#duration').val() > 0)
		url_vars += '&duration='+toInt($('#duration').val());

	if ($("input[name='kd_1']:checked").val() != undefined)
		url_vars += '&kd_1=1';
	
	$.ajax({url:url_vars,
	success:function(txt)
	{
		$('#credits_content').html(txt);
	}});
}

function toInt(v)
{
	return parseInt(v.replace(/[^0-9]/, ''));
}

/*
jQuery.fn.idle = function(time){  
    var i = $(this);  
    i.queue(function(){  
        setTimeout(function(){  
            i.dequeue();  
        }, time);  
    });  
}; 
*/

