﻿/*
	File: fbdeFunctions.js
	Purpose: JavaScript codes common to all fussball.de pages
*/

// ------------------------------------------------------------------------------------------------------------------------------------------------
// Globals
var variablen = new Array();
	variablen['select'] = '';
var saison0 = 2008;
var saison1 = 2009;
var communityRef = new Array();
var edSaison; var edMandantId; var edWettbewerbId;
if(window.location.search != "")
{
	QUERYSTRING = window.location.search
	QUERYSTRING = QUERYSTRING.replace(/\?/,"");
	var teilstrings = QUERYSTRING.split("&");
	for(i=0; i<teilstrings.length; i++)
	{
		vararr = teilstrings[i].split("=");
		variablen[vararr[0]] = vararr[1];
	}

	if(variablen['next'])
	{
		var work = variablen['next'].split("%2F");
		if(work[1] && work[1].length == 4)
		{
			saison0 = '20' + work[1].substring(0,2);
			saison1 = '20' + work[1].substring(2,4);
			edSaison = work[1];
			edWettbewerbId = work[5];
		}
		else
		{
			work = variablen['next'].split("\/");
			if(work[1] && work[1].length == 4)
			{
				saison0 = '20' + work[1].substring(0,2);
				saison1 = '20' + work[1].substring(2,4);
				edSaison = work[1];
				edWettbewerbId = work[5];
			}
		}
	}
}
// legacy...
var Basispfad=variablen['next'];

function printpage()
{
	var myURL = window.location.href;
	var myNewURL = myURL.replace(/#.*/, '');

	if(variablen['next'] == undefined)
	{
		window.open(myNewURL+'?print=true','Druckansicht','width=800,height=700,resizeable=yes,scrollbars=yes,toolbar=yes');
	}
	else
	{
		window.open(myNewURL+'&print=true','Druckansicht','width=800,height=700,resizeable=yes,scrollbars=yes,toolbar=yes');
	}
}

function showhide(ref)
{
	var e = document.getElementById(ref);
	var visi = (e.style.display == 'block') ? 'none' : 'block';
	e.style.display = visi;
}

// Funktionen fuer Redakteure in CM
function openWindowGeneric(theURI, theName, theAttributes)
{
	theWindow = window.open(theURI, theName, theAttributes);
}

// ------------------------------------------------------------------------------------------------------------------------------------------------
// IVW Zaehlung

var ivwNumCat = "";
var ivwTypeView = "";
var ivwTopNav = "";
var ivwSubNav = "";
var ivwSaison = "";
var ivwMart = "";
var ivwSklasse = "";
var ivwGebiet = "";
var ivWStaffelId = "";
var ivwTypeEdView = "";
var ivwTypeEdSubView = "";


function cleanIVW(string)
{
	string = string.replace(/Ä/g, 'Ae');
	string = string.replace(/ä/g, 'ae');
	string = string.replace(/Ö/g, 'Oe');
	string = string.replace(/ö/g, 'oe');
	string = string.replace(/Ü/g, 'Ue');
	string = string.replace(/ü/g, 'ue');
	string = string.replace(/ß/g, 'ss');
	return string.replace(/\W/g, '');
}


// ------------------------------------------------------------------------------------------------------------------------------------------------
// LiveTicker
function liveTickerOpenWindow(url)
{
	window.open(url,
              "Fussball",
              "width=660,height=500,status=no,toolbar=no,menubar=no,resizable=yes,scrollbars=no");
			return true;
}

var ScrollerGo = 0;
var ScrollerTop = 36;
var ScrollerTopCur = 36;

function TscrollDown()
{
	if(ScrollerGo == 1)
	{
		var ScrollerMax = ScrollerTop - document.getElementById('TickerContent').offsetHeight + 108;
		ScrollerTopCur -= 4;
		if(ScrollerTopCur > ScrollerMax)
		{
			document.getElementById('TickerContent').style.top = ScrollerTopCur+'px';
			window.setTimeout("TscrollDown()",100);
		}
		else
		{
			ScrollerTopCur = ScrollerMax;
		}
	}
}

function TscrollUp()
{
	if(ScrollerGo == 1)
	{
		var ScrollerMax = ScrollerTop - document.getElementById('TickerContent').offsetHeight + 108;
		ScrollerTopCur += 4;
		if(ScrollerTopCur <= ScrollerTop)
		{
			document.getElementById('TickerContent').style.top = ScrollerTopCur+'px';
			window.setTimeout("TscrollUp()",100);
		}
		else
		{
			ScrollerTopCur = ScrollerTop;
		}
	}
}

function TscrollStop()
{
	ScrollerGo = 0;
}
function TscrollStartDown()
{
	ScrollerGo = 1;
	TscrollDown();
}
function TscrollStartUp()
{
	ScrollerGo = 1;
	TscrollUp()
}


// ------------------------------------------------------------------------------------------------------------------------------------------------
// Seite empfehlen
var currentReferrer = document.referrer;
if(!currentReferrer.match(/fussball/g)) { currentReferrer = 'http://www.fussball.de/'; }
function DieseSeiteEmpfehlen()
{
	var error = 0;

	new Ajax.Updater('Seite_weiterempfehlen_info','/fussball/php/seiteEmpfehlen.php',
		{
			'evalScripts': true,
			'asynchronous': true,
			'method': 'post',
			'parameters': {'senderURL':currentReferrer, 'senderName':$F('senderName'), 'senderEmail':$F('senderEmail'), 'recipientName':$F('recipientName'), 'recipientEmail':$F('recipientEmail'), 'message':$F('message')}
		}
	);

	return false;
}

function fbdeKontakt()
{
	var error = 0;

	new Ajax.Updater('fbdeKontakt_info','/fussball/php/fbdeKontakt.php',
		{
			'evalScripts': true,
			'asynchronous': true,
			'method': 'post',
			'parameters': Form.serialize('fbdeKontakt_form')
		}
	);

	return false;
}




// ------------------------------------------------------------------------------------------------------------------------------------------------
function fbdeSuche()
{
	if(fbdeSuchLogger())
	{
		if(document.getElementById('s-g').checked)
		{
			window.open('http://suche.t-online.de/fast-cgi/tsc?mandant=toi&portallanguage=de&userlanguage=de&device=html&context=internet-tab&tpc=internet&ptl=std&dia=fussball_de&classification=internet-tab_internet_std&src=&lang=any&q='+$F('q'));
		}
		else
		{
			document.location.href=$F('communitySuchurl')+$F('q');
		}
	}
}

function fbdeSucheFussball()
{
	document.getElementById('search-form').action = document.getElementById('communitySuchurl').value;
	document.getElementById('search-form').setAttribute("target","_self");
}

function fbdeSucheGoogle()
{
	document.getElementById('search-form').action = "http://suche.t-online.de/fast-cgi/tsc?mandant=toi&amp;portallanguage=de&amp;userlanguage=de&amp;device=html&amp;context=internet-tab&amp;tpc=internet&amp;ptl=std&amp;dia=fussball_de&amp;classification=internet-tab_internet_std&amp;src=&amp;lang=any";
	document.getElementById('search-form').setAttribute("target","_blank");
}

function fbdeSuchLogger()
{
	var maschine = 'fussball';
	if(document.getElementById('s-g').checked)
	{
		maschine = 'google';
	}

	new Ajax.Request('/fussball/php/fbdeSuchLogger.php',
		{
			'asynchronous': false,
			'method': 'post',
			'parameters': {'website':'fbde','maschine':maschine,'query':$F('q')}
		}
	);

	return true;
}

// ------------------------------------------------------------------------------------------------------------------------------------------------
// Formularelemente
function readoutSelect(theSelect, theInput, theArray)	{
	document.getElementById(theInput).value = theArray[document.getElementById(theSelect).selectedIndex + 1][1];
}

function populateSelect(theSelect, theArray) {
for(var i = 1; i < theArray.length; i++)
	{
	newEntry = new Option(theArray[i][0],theArray[i][1],false,true);
 	document.getElementById(theSelect).options[document.getElementById(theSelect).length] = newEntry;
	}
	document.getElementById(theSelect).options[0].selected = true;	
}


// ------------------------------------------------------------------------------------------------------------------------------------------------
// Config Kontakt-Topics
var contactTopics = new Array();
contactTopics[1] = new Array();
contactTopics[1][0] = "Spiel- oder Mannschaftsdaten nicht korrekt";
contactTopics[1][1] = "spieldaten@fussball.de";
contactTopics[2] = new Array();
contactTopics[2][0] = "Anmerkungen/Wünsche/Feedback";
contactTopics[2][1] = "feedback@fussball.de";
contactTopics[3] = new Array();
contactTopics[3][0] = "Inhaltliche Fragen zur Fußball-Community";
contactTopics[3][1] = "community@fussball.de";
contactTopics[4] = new Array();
contactTopics[4][0] = "Technische Fragen";
contactTopics[4][1] = "technik@fussball.de";
contactTopics[5] = new Array();
contactTopics[5][0] = "Games";
contactTopics[5][1] = "games@fussball.de";
contactTopics[6] = new Array();
contactTopics[6][0] = "Mobile Welt";
contactTopics[6][1] = "mobil@fussball.de";
contactTopics[7] = new Array();
contactTopics[7][0] = "Shop";
contactTopics[7][1] = "shop@fussball.de";
contactTopics[8] = new Array();
contactTopics[8][0] = "Datenschutz";
contactTopics[8][1] = "datenschutz@fussball.de";
contactTopics[9] = new Array();
contactTopics[9][0] = "Sonstiges";
contactTopics[9][1] = "sonstiges@fussball.de";


// ------------------------------------------------------------------------------------------------------------------------------------------------
// Community-Benutzer
var fbdeUserName = '';
var fbdeUserId = '';
var fbdeUserSession = '';
function getCookieVal (offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
        return getCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
    }
    return null;
}


function getCommunityUserInfo()
{
	fbdeUserName = GetCookie("FBCOM_Username");
	fbdeUserId = GetCookie("FBCOM_UserId");
	fbdeUserSession = GetCookie("FBCOM_SessionId");
}
