
function wfb_try(code)
{
	try
	{
		eval(code);
	}
	catch (e)
	{
//		setTimeout(code, 1000);
//		alert('loading page. please wait.');
	}
}

$(document).ready(function()
{
	// +$time() ???
	var wfb_ugc_url = '/rpc/ugc.php?';  // user generated
	var wfb_sgc_url = '/rpc/sgc.php?'; // site generated
	var tmp;

	wfb_rzCC = function(s)
	{
		for(var exp=/-([a-z])/;
			exp.test(s);
			s=s.replace(exp,RegExp.$1.toUpperCase()));
		return s;
	};

	wfb_setStyle = function(element, declaration)
	{
		if (declaration.charAt(declaration.length-1)==';')
		{
			declaration = declaration.slice(0, -1);
		}
		var k, v;
		var splitted = declaration.split(';');
		for (var i=0, len=splitted.length; i<len; i++)
		{
			k = wfb_rzCC(splitted[i].split(':')[0]);
			v = splitted[i].split(':')[1];
			eval("element.style."+k+"='"+v+"'");
		}
	};

	wfb_showTooltip = function(id, txt, parent_tag, new_id, offset_x, offset_y)
	{
		var obj;
		var tag = $('#'+parent_tag);
		var x;
		var y;
		if (tag)
		{
			obj = document.createElement("div");
			if (obj)
			{
				obj.setAttribute('id', new_id);
				var tmp;
				tmp = $('#'+id);
				x = tmp.offset().left;
				y = tmp.offset().top;
				x += offset_x;
				y = y - offset_y;
				wfb_setStyle(obj, 'left: '+x+'px; top: '+y+'px;');
				var code = '<div id="'+new_id+'" style="left: '+x+'px; top: '+y+'px;"><div id="'+new_id+'2"><div id="'+new_id+'3"><div id="'+new_id+'4">'+txt+'</div></div></div></div>';
				$('body').append(code);
			}
		}
	};

	wfb_hideTooltip = function(ex_id)
	{
		$('#'+ex_id).remove();
	};

	wfb_showLoader = function(parent_id, offset_x, offset_y, in_body)
	{
		var obj, x, y;
		x = 0;
		y = 0;

		var tag;
		tag = $('#'+parent_id);
		var pos = 'relative';
		if (in_body == 1)
		{
			x = tag.offset().left;
			y = tag.offset().top;;
			tag = $('body');
			pos = 'absoulte';
		}
		if (tag)
		{
			var new_id = "loader-pic-"+parent_id;
			var ex_pic = $('#'+new_id);
			if (ex_pic)
			{
				ex_pic.remove();
			}
			x += offset_x;
			y += offset_y;
			if (in_body != 1)
			{
				tag.empty();
			}
			tag.append('<img src="/bilder/shared/ajax_waiting.gif" class="loader-pic" alt="load" id="'+new_id+'" style="position: '+pos+'; left: '+x+'px; top: '+y+'px;" />');
		}
	};

	wfb_hideLoader = function(id)
	{
		$("#loader-pic-"+id).remove();
	};

	wfb_chPrivacy = function(id, name, old_val)
	{
		$('#'+id).empty();
		wfb_showLoader(id, 0, 0);
		var url;
		url = wfb_ugc_url+'&action=privacy_change_form&attribute='+name+'&value='+old_val;
		$('#'+id).load(url);
	};

	wfb_chMail = function(id, name, old_val)
	{
		$('#'+id).empty();
		wfb_showLoader(id, 0, 0);
		var url;
		url = wfb_ugc_url+'&action=mail_change_form&attribute='+name+'&value='+old_val;
		$('#'+id).load(url);
	};

	wfb_chCountry = function(id)
	{
		wfb_showLoader(id, 0, 0);
		var url;
		url = wfb_sgc_url+'&action=country_form';
		$('#'+id).load(url);
		$('#load-country').bind('keyup',
			function(e)
			{
				var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
				if (key == 27)
				{
					$('#country-list-inside').remove();
				}
				else
				{
					$('#country-list-inside').scrollTo($('#lnk-'+key));
				}
			});
	};

	wfb_chLang = function(id)
	{
		wfb_showLoader(id, 0, 0);
		var url;
		url = wfb_sgc_url+'&action=language_form';
		$('#'+id).load(url);
		$('#load-lang').bind( 'keyup',
			function(e)
			{
				var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
				if (key == 27)
				{
					$('#lang-list-inside').remove();
				}
			});
	};

	var wfb_old_content = Array();

	wfb_setOldContent = function(id)
	{
		try
		{
			if (typeof wfb_old_content[id] == 'undefined')
			{
				wfb_old_content[id] = $('#'+id).html();
			}
		}
		catch (e)
		{

		}
	};

	wfb_getOldContent = function(id)
	{
		try
		{
			$('#'+id).html(wfb_old_content[id]);
			delete wfb_old_content[id];
			wfb_recall();
		}
		catch (e)
		{

		}
	};

	wfb_emptyOldContent = function(id)
	{
		try
		{
			delete wfb_old_content[id];
		}
		catch (e)
		{

		}
	};

	wfb_chUserCfg = function(id, name, old_val)
	{
		wfb_setOldContent(id);
		$('#'+id).empty();
		wfb_showLoader(id, 0, 0);
		var url;
		url = wfb_ugc_url+'&action=user_cfg&attribute='+name+'&value='+old_val;
		if (name == 'country')
		{
			url = wfb_sgc_url+'&action=user_cfg_country&attribute='+name+'&value='+old_val;
		}
		$('#'+id).load(url);
	};

	wfb_contact = function(action, user_id, user_name)
	{
		$('#msgbox').remove();
		$('.portfolio').prepend('<div id="msgbox"></div>');
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(600);
		var url;
		url = wfb_ugc_url+'&action=user_contact&attribute='+action+'&to_id='+user_id+'&to_name='+user_name;
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });
	};


	var last_friend_count = -1;
	var last_msg_count = -1;

	wfb_getTime = function()
	{
		var now = new Date();
		return Math.round(now.getTime()/1000);
	};


	var last_friend_call = wfb_getTime();
	var last_msg_call = wfb_getTime();

	wfb_chkNewMsg = function()
	{
		var now_call = wfb_getTime();
		var bla = (now_call - last_friend_call);
		var url;
		var tmp;
		var tmp2;

		if (bla > 10)
		{
			url = wfb_ugc_url+'&action=user_chk&attribute=new_friend';
			wfb_showLoader('new-friend-count', 0, 0);
			$('#new-friend-count').load(url);
			last_friend_call = wfb_getTime();
		}
		else
		{
			var tmp1 = $('#new-friend-count').html();
			wfb_showLoader('new-friend-count', 0, 0);
			$('#new-friend-count').fadeOut(400, function() {$('#new-friend-count').html(tmp1); $('#new-friend-count').fadeIn(20);});
		}

		bla = (now_call - last_msg_call);
		if (bla > 10)
		{
			wfb_showLoader('new-msg-count', 0, 0);
			url = wfb_ugc_url+'&action=user_chk&attribute=new_msg';
			$('#new-msg-count').load(url);
			last_msg_call = wfb_getTime();
		}
		else
		{
			var tmp2 = $('#new-msg-count').html();
			wfb_showLoader('new-msg-count', 0, 0);
			$('#new-msg-count').fadeOut(400, function() {$('#new-msg-count').html(tmp2); $('#new-msg-count').fadeIn(20);});
		}

	};

	wfb_delMsg = function(msg_id, dir)
	{
		var url;
		url = wfb_ugc_url+'&exec=1&action=user_contact&attribute=delmsg&msg_id='+msg_id+'&dir='+dir;
//		alert(url);
		wfb_showLoader('msg-tr-'+msg_id, 0, 0);
		$.get(url, {}, function(data) { $('#'+'msg-tr-'+msg_id).remove(); });
	};

	wfb_delDetailMsg = function(msg_id, dir)
	{
		wfb_delMsg(msg_id, dir);
		$('#msgbox').fadeOut(600);
	};

	wfb_readMsg = function(user_id, user_name, msg_id, dir, read)
	{
		$('#msgbox').remove();
		$('.portfolio').prepend('<div id="msgbox"></div>');
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(600);
		var url;
		var exec_val = 0;
		if (read == 0 && dir == '')
		{
			exec_val = 1;
		}
		url = wfb_ugc_url+'&action=user_contact&attribute=readmsg&to_id='+user_id+'&to_name='+user_name+'&msg_id='+msg_id+'&dir='+dir+'&read='+read+'&exec='+exec_val;
		$('#msgbox').load(url);
		if (dir == '')
		{
			$('#msg-lnk-'+msg_id).removeClass('msg-unread');
			$('#msg-lnk-'+msg_id).addClass('msg-read');
		}
		$.scrollTo({ top:0, left:0 });
	};

	wfb_writeMsg = function(user_id, user_name, msg_id)
	{
		$('#msgbox').remove();
		$('.portfolio').prepend('<div id="msgbox"></div>');
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(600);
		var url;
		url = wfb_ugc_url+'&action=user_contact&attribute=writemsg&to_id='+user_id+'&to_name='+user_name+'&msg_id='+msg_id;
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });
	};

	wfb_showUpload = function(attrib, exec, value)
	{
		$('#msgbox').remove();
		$('.portfolio').prepend('<div id="msgbox"></div>');
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(600);
		var url;
		url = wfb_ugc_url+'&action=user_upload&attribute='+attrib+'&exec='+exec+'&value='+value;
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });
	};

	wfb_addContent = function(kind, value_type, value, title)
	{
		$('#msgbox').remove();
		if ($('.portfolio').length < 1)
		{
			$('.content').prepend('<div id="msgbox"></div>');
		}
		else
		{
			$('.portfolio').prepend('<div id="msgbox"></div>');
		}
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(1200);
		var url;
		url = wfb_sgc_url+'&action=add_content&attribute='+kind+'&value_type='+value_type+'&value='+value+'&title='+title;
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });

		if ($('#ticker-refresh-time').length > 0)
		{
			$('#ticker-refresh-time').html('disabled');
			$('#ticker-refresh-text').html('Auto-Refresh');
			delete wfb_tickerReload; // see liveticker include!
		}
	};

	wfb_delContent = function(value, value_type, do_it)
	{
		$('#msgbox').remove();
		$('.portfolio').prepend('<div id="msgbox"></div>');
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(1200);
		var url;
		if (do_it == '0')
		{
			url = wfb_sgc_url+'&action=del_content&attribute=delete&value='+value+'&value_type='+value_type;
		}
		else
		{
			url = wfb_ugc_url+'&action=del_content&attribute=delete&value='+value+'&value_type='+value_type+'&exec=1';

		}
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });
	};

	wfb_editContent = function(value, value_type, do_it)
	{
		$('#msgbox').remove();
		if ($('.portfolio').length < 1)
		{
			$('.content').prepend('<div id="msgbox"></div>');
		}
		else
		{
			$('.portfolio').prepend('<div id="msgbox"></div>');
		}
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(1200);
		var url;
		if (do_it == '0')
		{
			url = wfb_sgc_url+'&action=edit_content&attribute=edit&value='+value+'&value_type='+value_type;
		}
		else
		{
			url = wfb_ugc_url+'&action=edit_content&attribute=edit&value='+value+'&value_type='+value_type+'&exec=1';

		}
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });
	};

	wfb_alertMsg = function(kind, value_type, value)
	{
		$('#msgbox').remove();
		if ($('.portfolio').length < 1)
		{
			$('.content').prepend('<div id="msgbox"></div>');
		}
		else
		{
			$('.portfolio').prepend('<div id="msgbox"></div>');
		}
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(1200);
		var url;
		url = wfb_sgc_url+'&action=alert&attribute='+kind+'&value_type='+value_type+'&value='+value;
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });
	};

	wfb_loadSearch = function(q, kind)
	{
		$('#sidebar-searchbox').remove();
		$('.sidebar').prepend('<div id="sidebar-searchbox"></div>');
		wfb_showLoader('sidebar-searchbox', 0, 0);
		$('#sidebar-searchbox').fadeIn(1200);
		var url;
		url = wfb_sgc_url+'&action=sidebar_searchbox&q='+q+'&kind='+kind;
		$('#sidebar-searchbox').load(url);
		$.scrollTo({ top:0, left:0 });
	};

	wfb_loadForumSearch = function(q, kind)
	{
		$('#msgbox').remove();
		if ($('.portfolio').length < 1)
		{
			$('.content').prepend('<div id="msgbox"></div>');
		}
		else
		{
			$('.portfolio').prepend('<div id="msgbox"></div>');
		}
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(1200);
		var url;
		url = wfb_sgc_url+'&action=forum_searchbox&q='+q+'&kind='+kind;
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });
	};


	wfb_track = function()
	{
		try
		{
			// google analytics
			if (typeof pageTracker != 'undefined')
			{
				pageTracker._trackPageview();
			}
			
			
			if (typeof wfb_ivw_host != 'undefined' && wfb_ivw_host != ''
				&& typeof wfb_ivw_subdomain != 'undefined' && wfb_ivw_subdomain != ''
				&& typeof wfb_ivw_code != 'undefined' && wfb_ivw_code != '')
			{
				// ivw I
				var IVW="http://"+wfb_ivw_host+"/cgi-bin/ivw/CP/"+wfb_ivw_code;
				$('#wfb-track-code').append("<img src=\""+IVW+"?r="+escape(document.referrer)+"&d="+(Math.random()*100000)+"\" width=\"1\" height=\"1\" alt=\"szmtag\" />");


				if (typeof wfb_ivw_with_szm_frabo != 'undefined' && wfb_ivw_with_szm_frabo == '1')
				{
					// ivw II
					var szmvars=wfb_ivw_subdomain+"//CP//"+wfb_ivw_code;
					var szmvar_c=0;
					var szmvar_cook = document.cookie.split(";");
					for(szmvar_i=0;szmvar_i<szmvar_cook.length;szmvar_i++)
					{
						if(szmvar_cook[szmvar_i].match("POPUPCHECK=.*"))
						{
							var szmvar_check=new Date();
							var szmvar_now=szmvar_check.getTime();
							szmvar_check.setTime(szmvar_cook[szmvar_i].split("=")[1]);
							if(szmvar_check.getTime() >= (szmvar_now))
								szmvar_c=1;
							break;
						}
					}
					if(szmvar_c==0)
					{
						$('#wfb-track-code').append('<script src="http://qs.ivwbox.de/?'+szmvars+'"></'+'script>');
					}
				}
			}
			else if (wfb_ivw_code == 'focus')
			{
				getomni('tippspiel','');
			}
			else if (wfb_ivw_code == 'sport1')
			{
				sp1CallPi();
			}
		}
		catch (e)
		{
		}
	};

	wfb_pushAds = function()
	{
		try
		{
			var src = getAdManager(1); // load ad-manager
			src = src.replace(/&amp;/g, "&");
			$.getScript(src);
		}
		catch (e)
		{
		}
	};

	wfb_recall = function()
	{
		// overwrite document.write !!!
		try
		{
			document.write = function(html_code)
			{
				$('#wfb-ad-code').append(html_code);
			};
		}
		catch (e)
		{
		}

		// TODO: find reload-solution for new ad-management
//		wfb_pushAds();
		wfb_track();
	};

	wfb_close = function(tag_id, kind)
	{
		var tag;
		tag = $('#'+tag_id);

		if (kind == 1)
		{
			$(tag).fadeOut(600);
		}
		else
		{
			$(tag).remove();
		}
		// wfb_recall();
	};

	wfb_checkLocation = function(country_code, click_count)
	{
		// country_code: two-digit code, NOT three-digit!
		var new_host = window.location.hostname;
		var new_host2 = window.location.hostname;
		if (typeof wfb_allCc[country_code] == 'string')
		{
			if (wfb_allCc[country_code] != '')
			{
				if (country_code == 'AT')
				{
					new_host = 'www.weltfussball.at';
					new_host2 = 'aut.wf.endstand.de';
				}
				else if (country_code == 'DE')
				{
					new_host = 'www.weltfussball.de';
					new_host2 = 'ger.wf.endstand.de';
				}
				else if (country_code == 'GB')
				{
					new_host = 'www.worldfootball.net';
					new_host2 = 'www.wf.endstand.de'; 
				}
				else if (country_code == 'CH')
				{
					new_host = 'www.weltfussball.com';
					new_host2 = 'sui.wf.endstand.de'; 
				}
				else
				{
					new_host = wfb_allCc[country_code]+'.worldfootball.net';
					new_host2 = wfb_allCc[country_code]+'.wf.endstand.de';
				}
			}
		}
		
		var actual_path = window.location.pathname;
		if (click_count == 1 
			&& window.location.hostname != new_host 
			//&& document.referrer
			&& window.location.hostname != new_host2
			&& actual_path.search('/wetten/') == -1)
		{
			var referer = document.referrer;
			if (referer.search(/^https?:\/\/[a-z]+\.(weltfussball|worldfootball|wf\.endstand)\./) == -1)
			{
				window.location.hash = '#redirect';
				window.location.hostname = new_host;
//				$('#msgbox').remove();
//				if ($('.portfolio').length < 1)
//				{
//					$('.content').prepend('<div id="msgbox"></div>');
//				}
//				else
//				{
//					$('.portfolio').prepend('<div id="msgbox"></div>');
//				}
//				wfb_showLoader('msgbox', 0, 0);
//				$('#msgbox').fadeIn(1200);
//				var url;
//				url = wfb_sgc_url+'&action=change_location&country_code='+country_code;
//				$('#msgbox').load(url);
//				$.scrollTo({ top:0, left:0 });
			}
		}
		else if (window.location.hostname != new_host
			&& window.location.hostname != new_host2)
		{
			$('#sidebar-correct-country').remove();
			if ($('.sidebar').length < 1)
			{
				$('.portfolio').prepend('<div id="sidebar-correct-country"></div>');
			}
			else
			{
				$('.sidebar').prepend('<div id="sidebar-correct-country"></div>');
			}
			$('#sidebar-correct-country').fadeIn(1200);
			var url;
			url = wfb_sgc_url+'&action=sidebar_correct_country&country_code='+country_code;
			$('#sidebar-correct-country').load(url);
		}
		else if (window.location.hostname == new_host
				|| window.location.hostname == new_host2)
		{
			if (window.location.hash == '#redirect')
			{
				$('#sidebar-correct-country').remove();
				if ($('.sidebar').length < 1)
				{
					$('.portfolio').prepend('<div id="sidebar-after-redirect"></div>');
				}
				else
				{
					$('.sidebar').prepend('<div id="sidebar-after-redirect"></div>');
				}
				$('#sidebar-after-redirect').fadeIn(1200);
				var url;
				url = wfb_sgc_url+'&action=sidebar_after_redirect';
				$('#sidebar-after-redirect').load(url);
			}
		}
	};

	wfb_assignEntryToData = function(id, ds_art, ds_id, nr, kind)
	{
		if (ds_art == '')
		{
			$('#'+id).empty();
		}
		else
		{
			if (nr < 10)
			{
				for (i = nr; i < 10; i++)
				{
					$('#test-'+i).remove();
				}
			}
			$('#'+id).append('<div id="test-'+nr+'"></div>');
			id = 'test-'+nr;
		}
		wfb_showLoader(id, 0, 0);
		var url;
		url = wfb_sgc_url+'&action=assign_entry_to_data&ds_art='+ds_art+'&ds_id='+ds_id+'&nr='+nr+'&kind='+kind+'';
		$('#'+id).load(url);
	};


	wfb_doAssign = function(ds_art, ds_id, txt)
	{
		$('#ds_art2').attr("value", ds_art);
		$('#ds_id2').attr("value", ds_id);
		$('#assign-to').empty();
		if ($('#no-assign').length > 0)
		{
			$('#no-assign').fadeOut(600);
		}
		$('#second-assign a').html(txt);
	};

	wfb_assignEntryToDataNg = function(prefix, ds_art, ds_id, nr, kind)
	{
		var id;
		id = prefix+'-assign-to';
		if (ds_art == '')
		{
			$('#'+prefix+'-assign-to').empty();
			$('#'+prefix+'-assign-to').addClass('assigner-space');
		}
		else
		{

			if (nr < 10)
			{
				for (i = nr; i < 10; i++)
				{
					$('#test-'+i).remove();
				}
			}
			$('#'+prefix+'-assign-to').append('<div id="test-'+nr+'"></div>');
			id = 'test-'+nr;
//			alert(id);
		}
		wfb_showLoader(id, 0, 0);
		var url;
		url = wfb_sgc_url+'&action=assign_entry_to_data_ng&ds_art='+ds_art+'&ds_id='+ds_id+'&nr='+nr+'&kind='+kind+'&prefix='+prefix;
		$('#'+id).load(url);
	};


	wfb_doAssignNg = function(ds_art, ds_id, prefix, txt)
	{
		$('#'+prefix+'_ds_art').attr("value", ds_art);
		$('#'+prefix+'_ds_id').attr("value", ds_id);
		$('#'+prefix+'-assign-to').empty();
		$('#'+prefix+'-assign-to').removeClass('assigner-space');
		if ($('#no-assign').length > 0)
		{
			$('#no-assign').fadeOut(600);
		}
		$('#'+prefix+'-assign a').html(txt);
	};

	wfb_undoAssignNg = function(prefix, do_txt, undo_txt)
	{
		$('#'+prefix+'-close').html(' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="javascript:;" onclick="$(\'#'+prefix+'-assign-to\').empty(); $(\'#'+prefix+'-assign-to\').removeClass(\'assigner-space\'); $(\'#'+prefix+'_ds_id\').attr(\'value\', 0); $(\'#'+prefix+'_ds_art\').attr(\'value\', \'\'); $(\'#'+prefix+'-close\').empty(); $(\'#'+prefix+'-assign a\').html(\''+do_txt+'\');">'+undo_txt+'</a>');
	};


	wfb_quickLink = function(id)
	{
		wfb_assignEntryToData(id, '', 0, 0, 'link');
	};

	wfb_forumLink = function(id)
	{
		wfb_assignEntryToData(id, '', 0, 0, 'forum_link');
	};

	wfb_addGang = function(kind, value_type, value)
	{
		$('#msgbox').remove();
		if ($('.portfolio').length < 1)
		{
			$('.content').prepend('<div id="msgbox"></div>');
		}
		else
		{
			$('.portfolio').prepend('<div id="msgbox"></div>');
		}
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(1200);
		var url;
		url = wfb_sgc_url+'&action=add_gang&attribute='+kind+'&value_type='+value_type+'&value='+value;
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });

		if ($('#ticker-refresh-time').length > 0)
		{
			$('#ticker-refresh-time').html('disabled');
			$('#ticker-refresh-text').html('Auto-Refresh');
			delete wfb_tickerReload; // see liveticker include!
		}
	};

	wfb_editGang = function(value, value_type, do_it)
	{
		$('#msgbox').remove();
		if ($('.portfolio').length < 1)
		{
			$('.content').prepend('<div id="msgbox"></div>');
		}
		else
		{
			$('.portfolio').prepend('<div id="msgbox"></div>');
		}
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(1200);
		var url;
		if (do_it == '0')
		{
			url = wfb_sgc_url+'&action=edit_gang&attribute=edit&value='+value+'&value_type='+value_type;
		}
		else
		{
			url = wfb_ugc_url+'&action=edit_gang&attribute=edit&value='+value+'&value_type='+value_type+'&exec=1';
		}
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });
	};

	wfb_login = function()
	{
		$('#msgbox').remove();
		if ($('.portfolio').length < 1)
		{
			$('.content').prepend('<div id="msgbox"></div>');
		}
		else
		{
			$('.portfolio').prepend('<div id="msgbox"></div>');
		}
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(1200);
		var url;
		url = wfb_sgc_url+'&action=login';
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });

		if ($('#ticker-refresh-time').length > 0)
		{
			$('#ticker-refresh-time').html('disabled');
			$('#ticker-refresh-text').html('Auto-Refresh');
			delete wfb_tickerReload; // see liveticker include!
		}
	};

	wfb_chGangCfg = function(id, gang_id, name, old_val)
	{
		wfb_setOldContent(id);
		$('#'+id).empty();
		wfb_showLoader(id, 0, 0);
		var url;
		url = wfb_ugc_url+'&action=gang_cfg&attribute='+name+'&gang_id='+gang_id+'&value='+old_val;
		$('#'+id).load(url);
	};

	wfb_delGangMod = function(id, gang_id, old_val)
	{
		wfb_setOldContent(id);
		$('#'+id).empty();
		$('#edit-main-content-inline-2').empty();
		wfb_showLoader(id, 0, 0);
		var url;
		url = wfb_ugc_url+'&action=gang_cfg&attribute=del-mod-2&gang_id='+gang_id+'&exec=1&value='+old_val;
		$('#'+id).load(url);
	};

	wfb_gangContact = function(action, gang_id, user_id, user_name)
	{
		$('#msgbox').remove();
		$('.portfolio').prepend('<div id="msgbox"></div>');
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(600);
		var url;
		url = wfb_ugc_url+'&action=gang_contact&attribute='+action+'&to_id='+gang_id+'&value='+user_id+'&to_name='+user_name;
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });
	};

	wfb_betGameContact = function(action, gang_id)
	{
		$('#msgbox').remove();
		$('.portfolio').prepend('<div id="msgbox"></div>');
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(600);
		var url;
		url = wfb_ugc_url+'&action=bet_game_contact&attribute='+action+'&to_id='+gang_id;
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });
	};

	wfb_addForumContent = function(kind, value_type, value, cite_id)
	{
		$('#msgbox').remove();
		if ($('.portfolio').length < 1)
		{
			$('.content').prepend('<div id="msgbox"></div>');
		}
		else
		{
			$('.portfolio').prepend('<div id="msgbox"></div>');
		}
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(1200);
		var url;
		url = wfb_sgc_url+'&action=add_forum_content&attribute='+kind+'&value_type='+value_type+'&value='+value+'&cite_id='+cite_id;
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });

		if ($('#ticker-refresh-time').length > 0)
		{
			$('#ticker-refresh-time').html('disabled');
			$('#ticker-refresh-text').html('Auto-Refresh');
			delete wfb_tickerReload; // see liveticker include!
		}
	};

	wfb_delForumContent = function(value, value_type, do_it)
	{
		$('#msgbox').remove();
		$('.portfolio').prepend('<div id="msgbox"></div>');
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(1200);
		var url;
		if (do_it == '0')
		{
			url = wfb_sgc_url+'&action=del_forum_content&attribute=delete&value='+value+'&value_type='+value_type;
		}
		else
		{
			url = wfb_ugc_url+'&action=del_forum_content&attribute=delete&value='+value+'&value_type='+value_type+'&exec=1';

		}
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });
	};

	wfb_editForumContent = function(value, value_type, do_it)
	{
		$('#msgbox').remove();
		if ($('.portfolio').length < 1)
		{
			$('.content').prepend('<div id="msgbox"></div>');
		}
		else
		{
			$('.portfolio').prepend('<div id="msgbox"></div>');
		}
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(1200);
		var url;
		if (do_it == '0')
		{
			url = wfb_sgc_url+'&action=edit_forum_content&attribute=edit&value='+value+'&value_type='+value_type;
		}
		else
		{
			url = wfb_ugc_url+'&action=edit_forum_content&attribute=edit&value='+value+'&value_type='+value_type+'&exec=1';

		}
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });
	};

	wfb_mozWrap = function(txtarea, open, close)
	{
		var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		var scrollTop = txtarea.scrollTop;

		if (selEnd == 1 || selEnd == 2)
		{
			selEnd = selLength;
		}

		var s1 = (txtarea.value).substring(0,selStart);
		var s2 = (txtarea.value).substring(selStart, selEnd)
		var s3 = (txtarea.value).substring(selEnd, selLength);

		txtarea.value = s1 + open + s2 + close + s3;
		txtarea.selectionStart = selEnd + open.length + close.length;
		txtarea.selectionEnd = txtarea.selectionStart;
		txtarea.focus();
		txtarea.scrollTop = scrollTop;

		return;
	};


	wfb_insertText = function(text, elem_id)
	{
		//textarea = $('#'+elem_id);
		var textarea;
		textarea = document.getElementById(elem_id);
		if (!isNaN(textarea.selectionStart))
		{
			var sel_start = textarea.selectionStart;
			var sel_end = textarea.selectionEnd;

			wfb_mozWrap(textarea, text, '')
			textarea.selectionStart = sel_start + text.length;
			textarea.selectionEnd = sel_end + text.length;
		}
		else if (textarea.createTextRange && textarea.caretPos)
		{
			if (baseHeight != textarea.caretPos.boundingHeight)
			{
				textarea.focus();
				storeCaret(textarea);
			}

			var caret_pos = textarea.caretPos;
			caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) == ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text;
		}
		else
		{
			textarea.value = textarea.value + text;
		}
		textarea.focus();

	};

	wfb_storeCaret = function(textEl)
	{
		if (textEl.createTextRange)
		{
			textEl.caretPos = document.selection.createRange().duplicate();
		}
	};


	wfb_bbStyle = function (bbnumber, elem_id)
	{
		var bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[list]','[/list]','[list=]','[/list]','[img]','[/img]','[url]','[/url]','[flash=]', '[/flash]','[size=]','[/size]');
		var bbopen = bbtags[bbnumber];
		var bbclose = bbtags[bbnumber+1];

		var imageTag = false;
		var theSelection = false;
		//var textarea = document.forms[form_name].elements[text_name];
		var textarea = document.getElementById(elem_id);
		//var text_name = 'message';
		textarea.focus();

		var clientPC = navigator.userAgent.toLowerCase(); // Get client info
		var clientVer = parseInt(navigator.appVersion); // Get browser version
		var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1));
		var is_win = ((clientPC.indexOf('win') != -1) || (clientPC.indexOf('16bit') != -1));

		if ((clientVer >= 4) && is_ie && is_win)
		{
			// Get text selection
			theSelection = document.selection.createRange().text;

			if (theSelection)
			{
				// Add tags around selection
				document.selection.createRange().text = bbopen + theSelection + bbclose;
				textarea.focus();
				theSelection = '';
				return;
			}
		}
		else if (textarea.selectionEnd && (textarea.selectionEnd - textarea.selectionStart > 0))
		{
			wfb_mozWrap(textarea, bbopen, bbclose);
			textarea.focus();
			theSelection = '';
			return;
		}

		//The new position for the cursor after adding the bbcode
		var caret_pos = getCaretPosition(textarea).start;
		var new_pos = caret_pos + bbopen.length;

		// Open tag
		wfb_insertText(bbopen + bbclose, elem_id);

		// Center the cursor when we don't have a selection
		// Gecko and proper browsers
		if (!isNaN(textarea.selectionStart))
		{
			textarea.selectionStart = new_pos;
			textarea.selectionEnd = new_pos;
		}
		// IE
		else if (document.selection)
		{
			var range = textarea.createTextRange();
			range.move("character", new_pos);
			range.select();
			wfb_storeCaret(textarea);
		}

		textarea.focus();
		return;
	};


	wfb_changeBetGame = function(gang_id, id, do_it)
	{
		$.scrollTo({ top:0, left:0 });
		$('#msgbox').remove();
		if ($('.portfolio').length < 1)
		{
			$('.content').prepend('<div id="msgbox"></div>');
		}
		else
		{
			$('.portfolio').prepend('<div id="msgbox"></div>');
		}
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(1200);
		var url;
		url = wfb_ugc_url+'&action=change_bet_game&attribute=edit&gang_id='+gang_id+'&bet_game_id='+id;
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });

	};

	wfb_loadBetGameTeams = function(tag_id, bet_game_id, season_id, team_id)
	{
		var url = wfb_sgc_url+'&action=load_bet_game_teams&bet_game_id='+bet_game_id+'&season_id='+season_id+'&team_id='+team_id+'&tag_id='+tag_id;
		$('#'+tag_id).load(url);
	};
	
	wfb_loadNewsList = function(id, value_type, value, limit, base_folder)
	{
		$('#'+id).fadeTo("normal", 0.30);
		var url;
		url = wfb_sgc_url+'&action=presseschau_list&value_type='+value_type+'&value='+value+'&limit='+limit+'&base_folder='+base_folder;
		$('#'+id).load(url, '', function()
		{
			$('#'+id).fadeTo("normal", 1.0);
		});
	};

	wfb_loadNewsListStart = function(id, value_type, limit)
	{
		$('#'+id).fadeTo("normal", 0.30);
		var url;
		url = wfb_sgc_url+'&action=presseschau_list_start&value_type='+value_type+'&limit='+limit;
		$('#'+id).load(url, '', function()
		{
			$('#'+id).fadeTo("normal", 1.0);
		});
	};
	
	wfb_loadBetGameFanTeams = function(ds_id)
	{
		wfb_showLoader("fan-team-target", 0, 0);
		url = wfb_sgc_url+'&action=bet_game_select_team&ds_id='+ds_id;
		$('#fan-team-target').load(url);
	};
	
	wfb_betGameLogin = function()
	{
		$('#msgbox').remove();
		if ($('.portfolio').length < 1)
		{
			$('.content').prepend('<div id="msgbox"></div>');
		}
		else
		{
			$('.portfolio').prepend('<div id="msgbox"></div>');
		}
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(1200);
		var url;
		url = wfb_sgc_url+'&action=bet_game_login';
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });
	};

	wfb_recommendGang = function(gang_id)
	{
		$('#msgbox').remove();
		if ($('.portfolio').length < 1)
		{
			$('.content').prepend('<div id="msgbox"></div>');
		}
		else
		{
			$('.portfolio').prepend('<div id="msgbox"></div>');
		}
		wfb_showLoader('msgbox', 0, 0);
		$('#msgbox').fadeIn(1200);
		var url;
		url = wfb_ugc_url+'&action=recommend_gang&attribute=recommend&gang_id='+gang_id;
		$('#msgbox').load(url);
		$.scrollTo({ top:0, left:0 });
		
	};
	
	wfb_showLastBets = function(user_id)
	{
		$('#sidebar-user-bets').remove();
		$('.sidebar').prepend('<div id="sidebar-user-bets"></div>');
		wfb_showLoader('sidebar-user-bets', 0, 0);
		$('#sidebar-user-bets').fadeIn(1200);
		var url;
		url = wfb_sgc_url+'&action=sidebar_user_bets&user_id='+user_id;
		$('#sidebar-user-bets').load(url);
		$.scrollTo({ top:0, left:0 });
	};

});
