 maxbucket = 16; 


function urldecode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urldecode('Kevin+van+Zonneveld%21');
    // *     returns 1: 'Kevin van Zonneveld!'
    // *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
    // *     returns 2: 'http://kevin.vanzonneveld.net/'
    // *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
    // *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
    
    var histogram = {}, histogram_r = {}, code = 0, str_tmp = [];
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urlencode.
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    
    for (replace in histogram) {
        search = histogram[replace]; // Switch order when decoding
        ret = replacer(search, replace, ret) // Custom replace. No regexing   
    }
    
    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);
 
    return ret;
}


function addbucket(val) {

	var bucket = Array();
	var b = val.split("***");
	var its = "";
	
	for ( i=1; i < maxbucket; i++ ) {

		bucket[''+i+''] = GetCookie('bucket['+i+']');
		var a = bucket[''+i+''].split("***");
		
		if ( a[3] == b[3] ) {
			its = "bucket["+i+"]";
		}
		
	}
	if ( its == "" ) {

		for ( i=1; i < maxbucket; i++ ) {

			if ( bucket[''+i+''] == "" ) {

				SetCookie('bucket['+i+']',''+val+'','1000','/','goin.pl');
				fastreadbucket();
				readbucket();

			}
		}
	}
	if ( its != "" ) {

			bucket = GetCookie(''+its+'');
			var c = bucket.split("***");
	
			delbucket(''+its+'',''+c[3]+'');
			$(''+c[3]+'').src = '/images/kubelek_add.gif';
			$(''+c[3]+'').alt = 'Do kubełka';
			$(''+c[3]+'').title = 'Do kubełka';
			fastreadbucket();
			readbucket();

	}
	
	return true;
	

}

function countbucket() {
	
	var bucket = Array();
	var count = 0;

	for ( i=1; i < maxbucket; i++ ) {
		bucket[''+i+''] = GetCookie('bucket['+i+']');
		var a = bucket[''+i+''].split("***");
		if ( a[0] != "" ) {	count = count+1; }
	}
	if ( $("countbucket") ) {
		$("countbucket").innerHTML = "<b>"+count+" z 15</b>";
	}
	
}


function readbucket() {
	
	var bucket = Array();
	var html = " ";

	for ( i=1; i < maxbucket; i++ ) {

		bucket[''+i+''] = GetCookie('bucket['+i+']');

		var a = bucket[''+i+''].split("***");

		if ( a[0] != "" ) {


			b = "<a href=\"\" onClick=\"delbucket('bucket["+i+"]','"+a[3]+"'); return false;\"><img src=\"/images/kubelek_del.gif\" border=\"0\" alt=\"Z kubełka\" title=\"Z kubełka\" ></a> &nbsp; <a href='http://www.goin.pl/message_send.php?"+a[3]+"&link="+a[0]+"' target='_blank'><img src='/images/koperta.gif' alt='Wyślij link znajomemu' title='Wyślij link znajomemu' border='0'></a> &nbsp; "+a[2]+" &nbsp; <a href='http://www.goin.pl/redirect.php?id="+a[3]+"&link="+a[0]+"' target='_blank'>"+a[1]+"</a><br><br>";
			
			html = html.concat(b);

			if ( $(''+a[3]+'') ) {

				$(''+a[3]+'').src = '/images/kubelek_del.gif';
				$(''+a[3]+'').alt = 'Z kubełka';
				$(''+a[3]+'').title = 'Z kubełka';
	
			}
			
		}
	}

	html = html+" ";
	countbucket();
	fastreadbucket();
	
	if ( $("bucket") ) {
		$("bucket").innerHTML=""+html+"";
	}
	
}
		 
function fastswitch() {

	var f = GetCookie('fast');

	if ( f == "1" ) {
		SetCookie('fast','','1000','/','goin.pl');
	}
	if ( f == ""  ) {
		SetCookie('fast','1','1000','/','goin.pl');
	}


}		 
		 
function fastreadbucket() {
	
	var bucket = Array();
	var html = "";
	var k = 0;
	var f = GetCookie('fast');

	if ( f == "1" ) {
	
		for ( i=1; i < maxbucket; i++ ) {

			bucket[''+i+''] = GetCookie('bucket['+i+']');

			var a = bucket[''+i+''].split("***");

			if ( a[0] != "" ) {
			
				k = k+1;
				b = ""+k+". <a id='fast' href='http://www.goin.pl/redirect.php?id="+a[3]+"&link="+a[0]+"' target='_blank'>"+a[1].substr(0,30)+"...</a><br>";
			
				html = html.concat(b);
			
			}
		}
		if ( $("shortc") ) {
			$("shortc").innerHTML=""+html+"";
		}
	} 
	
	if ( f == "" ) {
		if ( $("shortc") ) {
			$("shortc").innerHTML="&nbsp;";
		}

	}
	
}


		 
		 
function delbucket(bucket,id) {

	var buckets = Array();
	
	if ( bucket == "" ) {
		for ( i=1; i < maxbucket; i++ ) {
			
			buckets[''+i+''] = GetCookie('bucket['+i+']');
			var a = buckets[''+i+''].split("***");

			if ( $(''+a[3]+'') ) {
			
				$(''+a[3]+'').alt = 'Do kubełka';
				$(''+a[3]+'').title = 'Do kubełka';			
				$(''+a[3]+'').src = '/images/kubelek_add.gif';
				
			}

			SetCookie('bucket['+i+']','','0','/','goin.pl');
		}
		
		readbucket();
		fastreadbucket();
		
		
	}else{
	
		SetCookie(''+bucket+'','','0','/','goin.pl');
		
		if ( $(''+bucket+'') ) {
		
			$(''+bucket+'').alt = 'Do kubełka';
			$(''+bucket+'').title = 'Do kubełka';			
			$(''+bucket+'').src = '/images/kubelek_add.gif';
			
		}
		
		readbucket();
		fastreadbucket();
		
	}
	
		

}




function font_sizek(size) {

		SetCookie("font_size",size,"1000","/","goin.pl");
		if( document.getElementById("bucket") ) {
			document.getElementById("bucket").style.fontSize = size;
		}

}



function test_font_sizek() {

     var fonts = GetCookie("font_size");
     
     font_sizek(fonts); 

}





