//-----------------------------------------------------------------------
// $Id: javascripts.js,v 1.62 2006/02/02 14:06:21 dbosen Exp $
//-----------------------------------------------------------------------


// image-preloading/ und -highlighting
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function get_url_path(x){
        // this function returns the LAST path element of a url,
        // excluding file-names ...
        if(x){
        help=x.split("/");
         help2=help[help.length-1].match(/\.htm/ig);
        if(help2==null){
                help2=help[help.length-1].match(/\.php/ig);
        }
        if (help2!=null){
                res= help[help.length-2];
        }else{

                if(help[help.length-1]){
                        res= help[help.length-1];
                }else{
                        res=help[help.length-2];
                }
        }
        }
        if(res=="data"){
                res=help[help.length-3];
        }
        return res;
}

function popup(url,breite,hoehe,name,resize){
        if(!breite){
                 breite=320;
        }
        if(!hoehe){
                hoehe=250;
        }
        if(!name){
                name= "tvtotal_fenster";
        }
		if (!resize) {
				resize="yes";
		}
        userfenster=window.open(url,name,"width="+breite+",height="+hoehe+",screenX=0,screenY=0,resizable="+resize+",scrollbars=no");
        userfenster.focus();
}


function nippelboardPopup(){

		breite=800;
		hoehe=330;

		userfenster=window.open('/tvtotal/downloads/nippelboard.html','nippelboardpopup',"width="+breite+",height="+hoehe+",screenX=0,screenY=0,resizable=yes,scrollbars=no");
        userfenster.focus();
}


function pollpopup(wahl) {
        // hier schon mal link auf die neue imperia-popupseite
        var url = '/tvtotal/community/poll/index.html?poll=poll'+wahl;
        //var url = '/tvtotal/community/poll/index.php?poll=poll'+wahl; // <= TODO!
        var pollfenster=window.open(url, 'pollfenster', 'height=300,width=360,screenX=10,screenY=10');
        pollfenster.focus();
}

function videoPopUp(url) {
        var videoPopUpWin=window.open(url, 'Video_Popup', 'width=750,height=600,screenX=10,screenY=10');
        videoPopUpWin.focus();
}

function suggestPopUp(url) {
        var videoPopUpWin=window.open(url, 'Suggest_Popup', 'width=260,height=500,screenX=10,screenY=10');
        videoPopUpWin.focus();
}


function bilderPopUp(url) {
        var bilderPopUp=window.open(url, 'Galerie_Popup', 'width=750,height=520,screenX=10,screenY=10');
        bilderPopUp.focus();
}

// Obsolete. Kept for compatibility until reparsing.
function downloadBilderPopUp (bild) {
	var height = "692";
	var width = "750";
	var url =  '/tvtotal/popups/fotodl_popup.php?uri='+bild;
	var downloadBilderPopup=window.open(url, 'Download_Popup', 'height='+height+',width='+width+',screenX=10,screenY=10');
	downloadBilderPopup.focus();
}

function downloadBilderPopUpGallery (index) {
	var image_uri;
	var max_index;
	var popup = true;
	var height = "692";
	var width = "750";

	if (self.download_bilder_uris) {
		image_uri = download_bilder_uris[index];
		max_index = download_bilder_uris.length - 1;
	}
	else {
		if (window.opener && window.opener.download_bilder_uris) {
			image_uri = window.opener.download_bilder_uris[index];
			max_index = window.opener.download_bilder_uris.length - 1;
			popup = false;
		}
	}

	var previous = index ? index - 1 : max_index;
	var next = index == max_index ? 0 : index + 1;

	var url = '/tvtotal/popups/fotodl_popup.php?uri='+image_uri+'&previous='+previous+'&next='+next;
	if (popup) {
		var downloadBilderPopup=window.open(url, 'Download_Popup2', 'height='+height+',width='+width+',screenX=10,screenY=10');
		downloadBilderPopup.focus();
	} else {
		window.location.href = url;
	}
}

function downloadPopUpGallery (index, file, height, width) {
	var uri;
	var max_index;
	var popup = true;
	var content;

	if (typeof(index) == 'object') {
		content=index;
		index=-1;
	}

	if (self.download_content && index>=0) {
		content = download_content[index];
		max_index = download_content.length - 1;
	}
	else {
		if (window.opener && window.opener.download_content) {
			content = window.opener.download_content[index];
			max_index = window.opener.download_content.length - 1;
			popup = false;
		}
	}

	var navi="";
	if (index>=0) {
		var previous = index ? index - 1 : max_index;
		var next = index == max_index ? 0 : index + 1;
		navi = '&previous='+previous+'&next='+next;
	}

	var temp="";
	for (var key in content) {
		 temp += '&'+key+'='+content[key];
	}

	var url = '/tvtotal/popups/'+file+'?'+navi+temp;

	if (popup) {
		var downloadPopup=window.open(url, 'Download_Popup', 'height='+height+',width='+width+',screenX=10,screenY=10');
		downloadPopup.focus();
	} else {
		window.location.href = url;
	}
}

function downloadNippelPopUpGallery (index, bild) {
	var height = "327";
	var width = "750";
	downloadPopUpGallery (index, 'videodl_popup.php', height, width)
}

function downloadSoundPopUpGallery (index) {
	var height = "327";
	var width = "750";
	downloadPopUpGallery (index, 'spruechedl_popup.php', height, width)
}

function downloadVideoPopUp(uri, bild, headline, teasertext) {
	var height = "327";
	var width = "750";
	var temp = new Array();
	temp = {'url':uri, 'pic':bild, 'headline':headline, 'teasertext':teasertext};
	downloadPopUpGallery (temp, 'videodl_popup.php', height, width);
}

function soundPopUp(url,date,descr) {
	var height = "327";
	var width = "750";
	var temp = new Array();
	temp = {url:url, description:descr, date:date};
	downloadPopUpGallery (temp, 'spruechedl_popup.php', height, width);
}

// Onchange handler for uri selects.
// Used with gallery and videoplayer.
function goToSelectedURI(elem)
{
	var value = elem.options[elem.options.selectedIndex].value;
	if (!value) return void(0);
	window.location = value;
}

function openInOpener(uri)
{
	if (window.opener) {
		window.opener.location = uri;
	}
	else {
		var main = window.open(uri);
		main.focus();
	}
	return void(0);
}

function toggleLayer(layerToHide,layerToShow)
{
	var elem1;
	var elem2;

	if (document.getElementById) {
		elem1 = document.getElementById(layerToHide);
		elem2 = document.getElementById(layerToShow);
	}
	else if (document.all) {
		elem1 = document.all[layerToHide];
		elem1 = document.all[layerToShow];
	}
	if (elem1 && elem2) elem1.style.display = 'none';
	if (elem2) elem2.style.display = 'block';
}

// Skip advert page on missing advert.
function skipAdvertPage(uri)
{
	var regex = /Fallback/i;
	if (regex.test(soi_ad)) {
		document.location = uri;
	}
}

// fuer die Suche - swish-e    -ANFANG
// ===================================
function suchePopUp(url,breite,hoehe,name) {
        if(!breite){
                var breite=575;
        }
        if(!hoehe){
                var hoehe=500;
        }
        if(!name){
                var name= "Suchfenster_TVTOTAL";
        }
        var suchePopUp=window.open(url,name,'top=20,screenx=20,left=20,screeny=20,width='+breite+',height='+hoehe+', scrollbars=yes, resizable=no');
        suchePopUp.focus();
}

function NavigationTo (uParam) {
    top.window.opener.top.location.href = uParam;
}

// URL + ?query-Parameter zusammenbauen
// defines
var locZiel = "";
var locValue ="";
var locEncode = "";
var locURL ="";
var locTaste = 0;
var keyword ="";

function openSuchUrlParam(keyword) {
// locZiel = "/tvtotal/components/parts/suche_popup_ergebnis.html";
 locZiel = "/cgi-bin/swish_tvtotal.cgi";

 if (keyword != "") {
         // Für Suchtipp-Übergabe (optional)
         locValue = keyword;
 }
 else
 {
         // Aus dem Eingabefeld des Suchformular übergeben
         locValue = document.forms['suche'].elements['suchwort'].value;
 }
 // Wegen MAC -IE5.2 durch aeltere Funktion ersetzt
 // locEncode = encodeURI(locValue);
 locEncode = escape(locValue);
 if (locValue != "") {
     locZiel = locZiel + "?query=";
     locZiel = locZiel + locEncode;
     locZiel = locZiel + "&metaname=all&sort=swishrank";
 }
 else
 {
    // Leeres Formular
    locZiel = locZiel + "?";
 }

 return locZiel;
}

// Öffnet das Popupfenster SUCHE + evtl. Query-Parameteruebergabe
function openSuchFenster(keyword, suchtipp) {
        if(!suchtipp){
                var suchtipp="0";
        }
         temp = keyword;
         locURL = openSuchUrlParam(temp);
         suchePopUp(locURL+"&suchtipp="+suchtipp,'705','600','Suchfenster_TVTOTAL');
 //javascript:void(window.open('http://cms03.ext.e-tv.de/tvtotal/show/specials/eurovision2004/teilnehmer/popup/index.html','','top=20,screenx=20,left=20,screeny=20,width=420,height=500, scrollbars=yes, resizable=no'))
}

// Prüfe, ob im Eingabefeld Suche ENTER gedrückt wurde
function openSuchCheckPressed() {
 locTaste = window.event.keyCode;
 if (locTaste==13) {
    locURL = openSuchUrlParam();
    document.forms['suche'].action = "javascript:suchePopUp(locURL,'705','600','Suchfenster_TVTOTAL');";
    document.forms['suche'].submit();
 }
}
// fuer die Suche - swish-e    -ENDE
// ===================================

// Reload a the first (i)frame named 'adframe' (for game-popup)
function reload_adframe() {
	if (document.getElementsByName('adframe')[0]) { // ads-iframe exists?
		if(frames['adframe'].document.body) { // something there?
			frames['adframe'].location.reload();
		}
	}

}

function games_popup(url){
	gamesfenster=window.open(url,"games_popup","width=750,height=700,screenX=0,screenY=0,resizable=yes,scrollbars=no");
	gamesfenster.focus();
}

// ===================================
// Community, Start

function community_autologin_warning() { // warns the user if he activates autologin
	if (document.getElementsByName('autologin')[0].checked) {
		var frage = confirm('Autologin sollte nur verwendet werden, wenn du gerade an keinem öffentlichen Rechner bist. Autologin wirklich verwenden?');
		if (!frage) {
			document.getElementsByName('autologin')[0].checked = false;
			return false;
		} else {
			return true;
		}
	} else {
		return true;
	}
}

// Community, End
// ===================================



// ===================================


// Ads and IVW, End
// ===================================
