
//<!-- Begin
var initialsubj	= "Hallo, hier eine interessante Seite bei rttb.ch";
var initialmsg	= "Schau Dir mal diese Seite an: "+window.location;

var good;

function get_article_liveid() {
	var id 		= 0;
	try {
		var url 	= window.location.href;
		var temp_array 	= url.split('/');
		var temp_array2 = temp_array[temp_array.length-1].split('.');
		id 		= temp_array2[0];
	}
	catch(e) {
		alert( e.toString() );
	}
	return id;
}

var article_liveid  = get_article_liveid();

function checkEmailAddress(field) {
	var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\.sex)|(\.biz)|(\.aero)|(\.coop)|(\.museum)|(\.name)|(\.pro)|(\..{2,2}))$)\b/gi);
	if (goodEmail) {
		good = true;
	}
	else {
		alert('Bitte eine Email Adresse eingeben');
		field.focus();
		field.select();
		good = false;
   }
}

function check_email(email_value) {
    try {
        var error = false;
        if(email_value == "") {
            error = true;
        }
        else {
            var goodEmail = email_value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\.sex)|(\.biz)|(\.aero)|(\.coop)|(\.museum)|(\.name)|(\.pro)|(\..{2,2}))$)\b/gi);
            error         = (goodEmail) ? false : true;
        }
        return error;
    }
    catch(e) {
        alert_error(e);
    }
}
/** Newsletter-Anmeldung */
function checkFormNewsletter(language) {
    try {
        var err     = 0;
        var error_message = '';
        var email   = document.getElementById("email");
        var form    = document.newsletterform;
        var errresp = document.getElementById("err_resp");
        
        err = check_email(email.value) == false ? 0 : 1;
    
        if(err > 0) {
            switch(language) {
                case "de": 
                    error_message =  "Bitte füllen Sie alle Felder korrekt aus ! !";
                break;
                case "en": 
                    error_message =  "Please fill in all fields correctly! !";
                break;
                default: 
                    error_message =  "Bitte füllen Sie alle Felder korrekt aus !";
            }
            errresp.innerHTML       = error_message;
            errresp.style.display   = "block";
            return false;
        }
        else {
            form.submit();
        }
    }
    catch(e) {
        alert_error(e);
    }
}
/** ********************* */

u = window.location;
function mailThisUrl() {
	good = false;
	checkEmailAddress(document.eMailer.email);
	if (good) {
		//window.location = "mailto:"+document.eMailer.email.value+"?subject="+initialsubj+"&body="+document.title+" "+u;
		window.location = "mailto:"+document.eMailer.email.value+"?subject="+initialsubj+"&body="+initialmsg;
   }
}
//  End -->

//ecards
function open_ecard(id) {
	//http://www.sportal.de
	ecardsWindow = window.open("/sportal/service/ecards/ecard.php?" + id, "ECards", "width=660, height=640, top=50,left=50,scrollbars=no,resizable=no");
}
	
//<!-- Tell a friend -->
function win_tellafriend1() {    
	var url=window.location;
	//http://www.sportal.de
	tellafriendWindow=window.open("/scripts/tellafriend/tellafriend.php?url="+url, "win_tellafriend","height=400,width=450,left=350,top=155,scrollbars=no,resizable=no");    
}    



/** MC - POPUP Start **/
function popup(url) {
	// NEU: Neuen Fensternamen für jedes MC!
	var omc_wname = Math.floor(Math.random()*1000000000000);
	var default_window_height = 450;
	var default_window_width = 600;
	var default_scrollbars = "no";
	
	var screen_height = screen.height;
	if (isNaN(screen_height)) {
		screen_height = 700;		
	}
	var max_window_height = Math.floor(screen_height-50);
		
	// Default
	var window_height = 450;
	var window_width = default_window_width;

	if (window_height > max_window_height) {
		window_height = max_window_height;
		default_scrollbars = "yes";
		window_width = Math.floor(window_width+20);
	}
	window.open(url, omc_wname, "width=" +(window_width)+ ",height=" +(window_height)+ ",top=50,left=50,scrollbars=" +(default_scrollbars)+ ",resizable=no");
}
/** MC - POPUP End**/
//-->


//<!-- Textgroesse anfang -->
var faktor = 0.15; 			
var start_groesse = 0.75; 		
var anz = 0; 					
function fontsizer(inc, reset) {
	if ((anz + inc >= 0) && (anz + inc <= 2)) {
		anz += inc;
		neue_groesse = anz * faktor + start_groesse;
		artikel_text = document.getElementById('content_artikel');
		artikel_text.style.fontSize = neue_groesse + "em";
	}
	switch (anz) {
		case 0:
			document.getElementById("fsminus").src = "/sportch/images/icons/schrift_minus_inaktiv.gif";
			break;
		case 2:
			document.getElementById("fsplus").src = "/sportch/images/icons/schrift_plus_inaktiv.gif";
			break;
		default:	
			document.getElementById("fsplus").src = "/sportch/images/icons/schrift_plus.gif";
			document.getElementById("fsminus").src = "/sportch/images/icons/schrift_minus.gif";
			break;					
	}
}
//<!-- Textgroesse ende -->

//<!-- Kontaktformular anfang -->
function open_kontakt() {
	kontaktWindow = window.open("/de/sportch/service/kontakt/kontakt.php?", "poppage", "width=440,height=590,top=155,left=350,scrollbars=no,resizable=no");
}
//<!-- Kontaktformular ende -->

//<!-- Kontaktformular anfang -->
function open_kontakt_sc() {
	kontaktWindow = window.open("/de/spenglercup/service/kontakt/kontakt.php?", "poppage", "width=460,height=590,top=155,left=350,scrollbars=yes,resizable=no");
}
//<!-- Kontaktformular ende -->

//<!-- Kontaktformular english anfang -->
function open_kontakt_sc_en() {
	kontaktWindow = window.open("/de/spenglercup/service/kontakt/kontakt_en.php?", "poppage_en", "width=460,height=590,top=155,left=350,scrollbars=yes,resizable=no");
}
//<!-- Kontaktformular english ende -->

function openNewWindow2(url, name, x, y) {
	window.open(url, name, "height="+x+", width="+y+", toolbar=no, scrollbars=no");
}

/** i.P. allgemeine Funktionen */
/** Bildergalerie start */ 
function trim_text(text, strlimit, wordlimit) { 
	if(text.length > strlimit) {
		textA		= text.split(" ");
		text_short	= "";
		for(w=0; w<wordlimit; w++) {
			text_short 	+= textA[w] + " "; 
		}
		text_short 	+= " ...";
	}
	else text_short = text;
	return text_short;
}

function change_div(div_id, content) {
	try {
       	if(document.getElementById && document.getElementById(div_id)) {
			document.getElementById(div_id).innerHTML = content;
		} 
		else if(document.all && document.all[div_id]) {
			document.all[div_id].innerHTML = content;
		}
	}
	catch (e) {
        alert_error("change_div: "+e);
	}
}

function in_array(value, array_name) {
	found = false;
	for(n=0; n<array_name.length; n++) {
		if(array_name[n] == value) {
			found = true;
			break;
		}
	}
	return found;
}

function change_class(divname, class_name) {
	try {
		if(document.getElementById(divname)) {
			document.getElementById(divname).className = class_name;
		}
	}
	catch(e) {
	   alert_error("change_class: "+e);
	}
}

function dummy() {
	//return;
}
/** Bildergalerie end */ 


/** MC - POPUP Start **/
function open_mc(url) {
	// NEU: Neuen Fensternamen für jedes MC!
	var omc_wname = Math.floor(Math.random()*1000000000000);
	var default_window_height = 790;
	var default_window_width = 840;
	var default_scrollbars = "no";
	
	var screen_height = screen.height;
	if (isNaN(screen_height)) {
		screen_height = 768;		
	}
	var max_window_height = Math.floor(screen_height-50);
	
	if ((url.indexOf("tennis") > 0) || (url.indexOf("radsport") > 0)) {
		var window_height = 735;
		var window_width = default_window_width;
	} else {
		if ((url.indexOf("fussball") > 0) && (url.indexOf("bundesliga") > 0)) {
			// Bundesliga: Wallpaper: Größeres Fenster
			var window_height = 810;
			var window_width = 980;
		} else if ((url.indexOf("eishockey") > 0) && (url.indexOf("nla") > 0)) {
			// Eishockey NLA: Größeres Fenster
			var window_height = 830;
			var window_width = 1000;
		} else {
			// Default
			var window_height = 790;
			var window_width = default_window_width;
		}
	}
	if (window_height > max_window_height) {
		window_height = max_window_height;
		default_scrollbars = "yes";
		window_width = Math.floor(window_width+20);
	}
	window.open(url, omc_wname, "width=" +(window_width)+ ",height=" +(window_height)+ ",top=50,left=50,scrollbars=" +(default_scrollbars)+ ",resizable=no");
}
/** MC - POPUP End**/

function chgBgCol(col) {
    var cookiewert = CookieLesen();
    
    if(cookiewert != "") {
        if(cookiewert == "black" || cookiewert == "white") {
            col = cookiewert;
        }
    }
    
    if(col == "black") {
        document.body.style.backgroundImage = 'url(/rttb/images/bg_black.jpg)';
        document.body.style.backgroundColor = '#000000';
        document.getElementById("navBgTitle").className = "nav_bg_black";
        
        setTheCookie("rttb_bgcolor", "black", "1");
        
        if(isNaN(document.getElementById("logo"))) {
           document.getElementById("logo").src = "/rttb/images/logo_black.png";
        }
        
        if(isNaN(document.getElementById("datum"))) {
           document.getElementById("datum").src = "/rttb/images/datum_black.png";
        }
        
        if(isNaN(document.getElementById("datum_en"))) {
           document.getElementById("datum_en").src = "/rttb/images/datum_black_en.png";
        }
        
        if(isNaN(document.getElementById("sportch"))) {
           document.getElementById("sportch").src = "/rttb/images/sportch_logo_black.png";
        }
        
        if(isNaN(document.getElementById("sportalmedia"))) {
           document.getElementById("sportalmedia").src = "/rttb/images/sportalmedia_black.gif";
        }
        
        if(isNaN(document.getElementById("trainingspartner"))) {
           document.getElementById("trainingspartner").src = "/rttb/images/sponsoren/trainingspartner_s.png";
        }
    }
    else {
        document.body.style.backgroundImage = 'url(/rttb/images/bg_white.jpg)';
        document.body.style.backgroundColor = '#ffffff';
        document.getElementById("navBgTitle").className = "nav_bg_white";
        
        setTheCookie("rttb_bgcolor", "white", "1");
        
        if(isNaN(document.getElementById("logo"))) {
           document.getElementById("logo").src = "/rttb/images/logo_white.png";
        }
        
        if(isNaN(document.getElementById("datum"))) {
           document.getElementById("datum").src = "/rttb/images/datum_white.png";
        }
        
        if(isNaN(document.getElementById("datum_en"))) {
           document.getElementById("datum_en").src = "/rttb/images/datum_white_en.png";
        }
        
        if(isNaN(document.getElementById("sportch"))) {
           document.getElementById("sportch").src = "/rttb/images/sportch_logo_white.png";
        }
        
        if(isNaN(document.getElementById("sportalmedia"))) {
           document.getElementById("sportalmedia").src = "/rttb/images/sportalmedia_white.gif";
        }
        
        if(isNaN(document.getElementById("trainingspartner"))) {
           document.getElementById("trainingspartner").src = "/rttb/images/sponsoren/trainingspartner_w.png";
        }
    }
}

function chgBgColClick(col) {
    if(col == "black") {
        document.body.style.backgroundImage = 'url(/rttb/images/bg_black.jpg)';
        document.body.style.backgroundColor = '#000000';
        document.getElementById("navBgTitle").className = "nav_bg_black";
        
        setTheCookie("rttb_bgcolor", "black", "1");
        
        if(isNaN(document.getElementById("sponsorboard"))) {
           document.getElementById("sponsorboard").src = "/rttb/images/sponsoren/board_black.jpg";
        }
        
        if(isNaN(document.getElementById("logo"))) {
           document.getElementById("logo").src = "/rttb/images/logo_black.png";
        }
        
        if(isNaN(document.getElementById("datum"))) {
           document.getElementById("datum").src = "/rttb/images/datum_black.png";
        }
        if(isNaN(document.getElementById("datum_en"))) {
           document.getElementById("datum_en").src = "/rttb/images/datum_black_en.png";
        }
/*        
        if(isNaN(document.getElementById("sportch"))) {
           document.getElementById("sportch").src = "/rttb/images/sportch_logo_black.png";
        }
*/        
        if(isNaN(document.getElementById("sportalmedia"))) {
           document.getElementById("sportalmedia").src = "/rttb/images/sportalmedia_black.gif";
        }
        
        if(isNaN(document.getElementById("trainingspartner"))) {
           document.getElementById("trainingspartner").src = "/rttb/images/sponsoren/trainingspartner_s.png";
        }
    }
    else {
        document.body.style.backgroundImage = 'url(/rttb/images/bg_white.jpg)';
        document.body.style.backgroundColor = '#ffffff';
        document.getElementById("navBgTitle").className = "nav_bg_white";
        
        setTheCookie("rttb_bgcolor", "white", "1");
        
        if(isNaN(document.getElementById("sponsorboard"))) {
           document.getElementById("sponsorboard").src = "/rttb/images/sponsoren/board.jpg";
        }
        
        if(isNaN(document.getElementById("logo"))) {
           document.getElementById("logo").src = "/rttb/images/logo_white.png";
        }
        
        if(isNaN(document.getElementById("datum"))) {
           document.getElementById("datum").src = "/rttb/images/datum_white.png";
        }
        if(isNaN(document.getElementById("datum_en"))) {
           document.getElementById("datum_en").src = "/rttb/images/datum_white_en.png";
        }
/*        
        if(isNaN(document.getElementById("sportch"))) {
           document.getElementById("sportch").src = "/rttb/images/sportch_logo_white.png";
        }
*/        
        if(isNaN(document.getElementById("sportalmedia"))) {
           document.getElementById("sportalmedia").src = "/rttb/images/sportalmedia_white.gif";
        }
        
        if(isNaN(document.getElementById("trainingspartner"))) {
           document.getElementById("trainingspartner").src = "/rttb/images/sponsoren/trainingspartner_w.png";
        }
    }
}

function setTheCookie(Bezeichner, Wert, Dauer) {
    jetzt   = new Date();
    Auszeit = new Date(jetzt.getTime()+Dauer*86400000);
    document.cookie = Bezeichner+"="+Wert+";expires="+Auszeit.toGMTString()+"; path=/rttb/;";
}

function CookieLesen() {
    Wert = "";
      
    if(document.cookie) {
        Wertstart = document.cookie.indexOf("=") + 1;
        Wertende = document.cookie.indexOf(";");
          
        if(Wertende == -1) Wertende = document.cookie.length;
      
        Wert = document.cookie.substring(Wertstart,Wertende);
    }
      
    return Wert;
}


/** Scripte aus navigation */
function display_submenu(id) {
    if(main_menu_selected == id) { 
        return; //aktives Menue nicht ausklappen
    }
    clear_timer(timer_sub);
    document.getElementById(id).style.display = "block";  
    mark_mainmenu(id);
    if(id != main_menu_selected_temp) {
        hide_submenu(main_menu_selected_temp);                                                  //voriges Submenue deaktivieren
    }
    main_menu_selected_temp = id;
}

function hide_submenu(id) {
	if(id != main_menu_selected) {
       document.getElementById("main_menu_"+id).className = "";
       document.getElementById("main_menu_"+id+"_left").className = "";
       document.getElementById("main_menu_"+id+"_right").className = "";
   }
   document.getElementById(id).style.display = "none"; /* Subnavi verbergen (immer beimouseout)*/
}

function hide_submenu_all(id) {
    try {
        if(typeof(main_array) != "Array") {
            return;
        }
        for(n=0; n<main_array.length; n++) {
            if(main_array[n] != id) {
                hide_submenu(main_array[n]);
            }
        }
    }
    catch(e) {} 
}

function mark_mainmenu(id) {
//  var class_add = (id == "home") ? "_round" : "";
    var class_add = "_round"; 
    document.getElementById("main_menu_"+id).className = "bg_main_menu";
    document.getElementById("main_menu_"+id+"_left").className  = "bg_main_menu_left"+class_add;
    document.getElementById("main_menu_"+id+"_right").className = "bg_main_menu_right";
}

function clear_timer(timer) {
    if(typeof(timer) == "number") {
        clearTimeout(timer);
    }
}

function waitTime(id) {
	timer_sub = window.setTimeout("hide_submenu('"+id+"')",1000);
}

/* mouseover über die Klappmenuepunkte */
function highlite_subrow(id) {
    clear_timer(timer_sub);
    var class_name = (id == 'home_newsarchiv') ? 'submenu_div_sub_active submenu_first' : 'submenu_div_sub_active';
    document.getElementById(id).className = class_name;
    var main_id = id.substring(0, id.indexOf("_"));
}
function delite_subrow(id) {
    var class_name = (id == 'home_newsarchiv') ? 'submenu_div_sub submenu_first' : 'submenu_div_sub';
    document.getElementById(id).className = class_name;
    var main_id = id.substring(0, id.indexOf("_"));
}

/* die horizontale Subnavileiste einfärben: dunkel bei mouseover über das Klappmenue */
function subnaviSelected() {
    document.getElementById("subnavi_main").className = "subnavi_main_divActive";
}
function subnaviNonSelected() {
    document.getElementById("subnavi_main").className = "subnavi_main_div";
}

/** **** Buttons Topstories ***** */
function change(idx) {
    try {
        fadeIt(idx-1);//0..3
        hi_button(idx);
        if(typeof(id_temp) == "undefined") {
            id_temp = (start_id+1);
        }
        if(idx != id_temp) {
            if(document.images["button"+id_temp]) {
                document.images["button"+id_temp].src = "/rttb/images/topstory/"+id_temp+".png";
            }
        }
        id_temp     = idx; 
        aktuell_id  = idx; //global
    }
    catch(e) {
        alert_error("change: "+e);
    }
}

function hi_button(id) {
    try {
        if(document.images["button"+id]) {
            document.images["button"+id].src = "/rttb/images/topstory/"+id+"_a.png";
        }
    }
    catch(e) {
        alert_error("hi_button: "+e);
    }
}
function low_button(id) {
    try {
        if(document.images["button"+id]) {
            if(id != aktuell_id) {
                document.images["button"+id].src = "/rttb/images/topstory/"+id+".png";
            }
        }
    }
    catch(e) {
        alert_error("low_button: "+e);
    }
}

function change_by_click(idx) {
    try {
        change(idx);
        if(typeof(timer) != "undefined") {
            window.clearTimeout(timer);
        }
        intervall_play = false;
    }
    catch(e) {
        alert_error("change_by_click: "+e);
    }
}

function fadeIt(idx) {
    try {
        // Topstory umschalten / anzeigen:
        document.getElementById("mainImageOutline").className = 'topstory_'+(idx+1)+'_bg';
        document.getElementById("tss_headline").innerHTML     = topstories_headline_array[idx];
        document.getElementById("tss_text").innerHTML         = topstories_text_array[idx];
    }
    catch(e) {
        alert_error("fadeIt: "+e);
    }
}


function intervallFadeIt(akt_id, st_id, e_id, t_out) {
    try {
        if(intervall_play == true) {
            akt_id = akt_id>=e_id ? st_id+1 : akt_id+1; //nächstes oder erstes Bild
            change(akt_id);
            timer = window.setTimeout("intervallFadeIt("+akt_id+", "+st_id+", "+e_id+","+t_out+");", t_out);
        }
    }
    catch(e) {
        alert_error(e);
    }
    
}

function init_topstoryswitch() {
    // Automatisch starten:
    try {
        fadeIt(start_id);
        var timer = window.setTimeout("intervallFadeIt("+aktuell_id+","+start_id+","+end_id+","+timeout+")", timeout); 
    }
    catch(e) {
       alert_error("init_topstoryswitch: "+e);
    }
}
/** ******************************* */

function getX(el) {
   x = el.offsetLeft;
   if (!el.offsetParent) return x;
   else return (x+getX(el.offsetParent));
}

function getY(el) {
   y = el.offsetTop;
   if (!el.offsetParent) return y;
   else return (y+getY(el.offsetParent));
}
/** */

function alert_error(e) {
    if(location.href.indexOf(".hamsta") != -1) {
        alert(e);   //DEBUG
    }
}

/** FOTOSTRECKE */
function load_fotostrecke(fotostrecke_array, fotostrecke_big_array, start_value, fotostrecke_text) {
    try {
        if(typeof(fotostrecke_array) == "object" && fotostrecke_array.length > 0) {
            var max_teaser = 4;
            if(fotostrecke_array.length-1 < max_teaser) {   // Array zählt 0-te Element mit, daher -1
                max_teaser = fotostrecke_array.length-1;    // Array ist kleiner als max->max = Arrayanzahl (-1, s.o.)
            }
            load_fotostrecke_navi(fotostrecke_text, fotostrecke_array, start_value, max_teaser);
        }
    }
    catch(e) {
        alert_error("load_fotostrecke: "+e);
    }
}

function load_fotostrecke_fotos(foto_array, foto_array_big, start_teaser, max_teaser) {
    var text = "";
    var link = "";
    try {
      //überblätterte Anfangsbilder unsichtbar setzen
      if(start_teaser>1) {
         for(var n=1; n<start_teaser; n++) {
             link     = '<div style="display:none;"><a rel="lightbox[foo]" href="'+foto_array_big[n]+'">';
             link_end = '</a></div>';
             text    += link+'<img src="'+foto_array[n]+'" border="0" class="fotostrecke_teaser">'+link_end;
         }
      }
      //diese sichtbar setzen
      for(var n=0; n<max_teaser; n++) {
           link     = '<a rel="lightbox[foo]" href="'+foto_array_big[start_teaser+n]+'">';
           link_end = '</a>';
           text    += link+'<img src="'+foto_array[start_teaser+n]+'" border="0" class="fotostrecke_teaser">'+link_end;
      }
      //Bilder am Ende unsichtbar setzen
      if(start_teaser+3<foto_array_big.length-1) {
          for(var n=start_teaser+4; n<foto_array_big.length; n++) {
              link = '<div style="display:none;"><a rel="lightbox[foo]" href="'+foto_array_big[n]+'">';
              link_end = '</a></div>';
              text += link+'<img src="'+foto_array[n]+'" border="0" class="fotostrecke_teaser">'+link_end;
          }
      }
      change_div('fotostrecke_fotos', text);
    }
    catch(e) {
        alert_error("load_fotostrecke_fotos: "+e);
    }
}

function load_fotostrecke_navi(fotostrecke_text, fotostrecke_array, start_value, end_value) {
    var text = "";
    try {
        var link_back       = "";
        var link_forward    = "";
        var link_end        = '</a>';
        var array_length    = fotostrecke_array.length;
        var hotfix          = end_value-1;
        if( (start_value-1) >= 1) {
    	    link_back 	= '<a href="javascript:load_fotostrecke_navi(fotostrecke_text,fotostrecke_array,'+(start_value-1)+','+end_value+');">';
            button_back = '<div id="button_back">'+link_back+'<img src="/rttb/images/fotonav_left.png" border="0" class="backlink">'+link_end+'</div>';
        }
        else {
            button_back     = '<div id="button_back">&nbsp;</div>';
        }
        if( (start_value+1) < array_length-hotfix) {
    		link_forward	= '<a href="javascript:load_fotostrecke_navi(fotostrecke_text,fotostrecke_array,'+(start_value+1)+','+end_value+');">';
    	    button_forward  = '<div id="button_forward">'+link_forward+'<img src="/rttb/images/fotonav_right.png" border="0" class="forwardlink">'+link_end+'</div>';
        }
        else {
            button_forward  = '<div id="button_forward">&nbsp;</div>';
        }
         
        text  =  button_back+'<div id="fotostrecke_text">'+start_value+' von '+(array_length-1)+'<br>'+fotostrecke_text+'</div>'+button_forward;
  
        load_fotostrecke_fotos(fotostrecke_array, fotostrecke_big_array, start_value, end_value);
        
        change_div('fotostrecke_navi', text);
        
    }
    catch(e) {
        alert_error("load_fotostrecke_navi: "+e);
    }
}
/** */
