/*TV total js main*/

function changeNextGuestImg(new_img){
	document.getElementById('nextGuestImg').src = new_img;
}
function domElem(id){
	return document.getElementById(id);
}

function showNippel(el){
	var nippel_id = el.id;
	nippel_id = nippel_id.replace(/_link/, '');
	var nippel_list = '';
	var childs = document.getElementById('mr_nippel').childNodes;
	for(var i=0;i < childs.length;i++){
		var obj = childs[i];
		if(typeof obj !== 'undefined'){
			if(obj.nodeName == 'A' && typeof(obj.id) != 'undefined' && obj.id != ''){
				nippel_list = obj.id.replace(/_link/, '');
				if(nippel_id == nippel_list){
					showElem(nippel_id);
					obj.className = 'mr_nippel_link mr_nippel_active';
				}else{
					hideElem(nippel_list);
					obj.className = 'mr_nippel_link';
				}
			}
		}
	}
}



function registerNewsletter(mail, newsletterId){
   var link = "http://newsletter.e-tv.de/?p=subscribe&id=" + newsletterId + "&email=" + mail;
   newsletterWindow = window.open(link, "TV total Newsletter", "width=680,height=443,status=yes, scrollbars=no, resizable=no");
   newsletterWindow.focus();
}



function showPreview(el){
	var daylist = document.getElementById('preview_days').childNodes;
	var act_id = 'vorschau_'+el.id;
	
	for(var i=0;i < daylist.length;i++){
		var obj = daylist[i];
		if(typeof obj !== 'undefined'){
			if(obj.nodeName == 'A' && typeof(obj.id) != 'undefined' && obj.id != ''){
				if(obj.id == el.id){
					showElem(act_id);
					document.getElementById(act_id).className = 'active_day';
					document.getElementById(obj.id).className = 'active_headline';
				}else{
					hideElem('vorschau_'+obj.id);
					document.getElementById('vorschau_'+obj.id).className = '';
					document.getElementById(obj.id).className = 'headline';
				}
			}
		}
	}
}

function showElem(id){
	document.getElementById(id).style.display = 'block';
}
function hideElem(id){
	document.getElementById(id).style.display = 'none';
}

function mainnavi(obj){
	var orig_img = obj.firstChild.src;
	
	if(orig_img.indexOf('_active.jpg') == -1){
		var new_img = orig_img.replace(/.jpg/, '_active.jpg');
	}else{
		var new_img = orig_img.replace(/_active.jpg/, '.jpg');
	}
	obj.firstChild.src = new_img;
	return;
}

/*Flash Voting*/
function load_vote_stars(type, id, current_vote){
	var so = new SWFObject("/tvtotal/media/flash/voting_stars.swf?"+Math.random(), "voting", "100", "20", "8");
	so.useExpressInstall("/tvtotal/media/flash/expressinstall.swf");
	so.addParam("menu","true");
	so.addParam("wmode","transparent");
	so.addParam("quality","high");
	so.addParam("swLiveConnect","true");
	so.addParam("allowScriptAccess","sameDomain");
	so.addVariable("type",type);
	so.addVariable("id",id);
	so.addVariable("current_vote",current_vote);
	so.write("voting");
}

function showVoting(id, current_vote){
	var so = new SWFObject("/tvtotal/media/flash/show_voting.swf", "voting"+id, "60", "20", "8");
	so.useExpressInstall("/tvtotal/media/flash/expressinstall.swf");
	so.addParam("menu","true");
	so.addParam("wmode","transparent");
	so.addParam("quality","high");
	so.addParam("swLiveConnect","true");
	so.addParam("allowScriptAccess","sameDomain");
	so.addVariable("current_vote",current_vote);
	so.write("voting"+id);
}


/*Menu Right Videoplayer*/
function initializePlayerMenuRight(videoid){
	var so = new SWFObject("/tvtotal/media/flash/flashvideoplayer.swf", "mr_player", "100%", "100%", "8","#000000");
	so.useExpressInstall("/tvtotal/media/flash/expressinstall.swf");
	so.addParam("menu","true");
	so.addParam("wmode","transparent");
	so.addParam("quality","high");
	so.addParam("allowScriptAccess","sameDomain");
	so.addVariable("theme", "/tvtotal/media/flash/TVTotalMini_Skin.swf");
	so.addParam("allowFullScreen","true");
	so.addVariable("videoid",videoid);
	so.addVariable("asf",videoid);
	so.addVariable("adText","Werbung dauert noch XX Sek.");
	so.write("mr_player");
}


function startFlashGame(swfname, target, gamename, width, height, xmlpath){
	var so = new SWFObject("/tvtotal/media/flash/spielothek/"+swfname+"?"+Math.random(), gamename, width, height, "8");
	so.useExpressInstall("/tvtotal/media/flash/expressinstall.swf");
	so.addParam("menu","true");
	so.addParam("wmode","transparent");
	so.addParam("quality","high");
	/*so.addParam("allowScriptAccess","sameDomain");*/
	so.addParam("allowScriptAccess","always");
	so.addParam("swLiveConnect","true");
	if(xmlpath){
		so.addVariable("XMLpath", xmlpath);
	}
	so.write(target);
}	


function loadFlashObject(swfpath, target, flashobjname, width, height){
	var so = new SWFObject(swfpath + "?" + Math.random(), flashobjname, width, height, "8");
	so.useExpressInstall("/tvtotal/media/flash/expressinstall.swf");
	so.addParam("menu","true");
	so.addParam("wmode","transparent");
	so.addParam("quality","high");
	so.addParam("allowScriptAccess","always");
	so.addParam("swLiveConnect","true");
	so.write(target);
}


function suggestPopUp(url) {
        var videoPopUpWin=window.open(url, 'Suggest_Popup', 'width=260,height=500,screenX=10,screenY=10');
        videoPopUpWin.focus();
}


function openAsPopup(url, width, height) {
	if(!width){width = 640;}
	if(!height){height = 480;}
    var newPop = window.open(url, 'Suggest_Popup', 'width=' + width + ',height=' + height + ',screenX=10,screenY=10');
    newPop.focus();
}


function initFlexUploader(uploadedFilename, target, width, height){
	//alert(uploadedFilename);
	var so = new SWFObject("/tvtotal/media/flash/FlexUploader/FLEXUploader.swf" + "?" + Math.random(), "TV total Uploader", width, height, "9");
	so.useExpressInstall("/tvtotal/media/flash/expressinstall.swf");
	so.addParam("menu","false");
	so.addParam("wmode","transparent");
	so.addParam("quality","high");
	so.addParam("allowScriptAccess","always");
	so.addVariable("uploadedFilename", uploadedFilename);
	so.write(target);
}





/*Community Advanced Search*/
function switchSearch(){
	if(document.getElementById('search_advanced').style.display == 'block'){
		document.getElementById('search_advanced').style.display = 'none';
		document.getElementById('search_switch_text').innerHTML = 'erweiterte Suche';
	}
	else{
		document.getElementById('search_advanced').style.display = 'block';
		document.getElementById('search_switch_text').innerHTML = 'erweiterte Suche ausblenden';
	}
}
function popup(url) {
	pop = window.open(url, "popuuuup", "width=750,height=605,screenX=80,screenY=50,status=no,scrollbars=no,resizable=no");
	pop.focus();
}

function resetSearch(){
	if(document.getElementById('suchfeld').value == 'Suchbegriff...'){
		document.getElementById('suchfeld').value = '';
		//alert(document.getElementById('suchfeld').value);
	}
}

function redirect(url, timeOut){
	window.setTimeout("location.href='"+url+"';", timeOut*1000);
}







/***************************
Google Adsense
****************************/

/*
	(1) The function 'google_ad_request_done' is executed in
	http://pagead2.googlesyndication.com/pagead/show_ads.js
*/
function google_ad_request_done(google_ads) {
	if (!google_ads || google_ads.length == 0) return;
	
	var type = ETV_GOOGLE_ADTYPE;

	if (type == 'rectangle2') {
		if (checkRectangle('rectangle2')) return;
		if (checkRectangle('rectangle1')) return; // ovolgmann
		write_google_ads(google_ads, type);
	}
	else if (type == 'skyscraper') {
		// No depency on ordinary adtags
		write_google_ads(google_ads, type);
	}
	else if (type.match(/^fullbanner2/)) {
		if (existsRectangle('fullbanner2')) return;
		write_google_ads_popup(google_ads, type);
	}
	else if (type == 'suchergebnisse') {
		write_google_suchergebnisse(google_ads);
		// No incrementing of google_skip
		return;
	}
	else {
		return;
	}

	if (google_ads[0].bidtype == "CPC" && google_ads[0].type != 'image') {
		ETV_GOOGLE_COUNT += google_ads.length;
	}

	return;
}

function write_google_ads(google_ads, type) {
	if (!google_ads || google_ads.length == 0) return;
	
	var s = '';

	if (type == 'rectangle2') {
		var i = 0;
		s += '<div class="google-rectangle2">'
			+ '<p class="anzeige">Google-Anzeige<\/p>'
			+ '<p class="title"><a href="' + google_ads[i].url + '" target="_blank" onmouseover="window.status=\'' + google_ads[i].visible_url + '\';return true" onmouseout="window.status=\'\'">' + unescape(google_ads[i].line1) + '<\/a><\/p>'
			+ '<p><a href="' + google_ads[i].url + '" target="_blank" onmouseover="window.status=\'' + google_ads[i].visible_url + '\';return true" onmouseout="window.status=\'\'" class="linkstyle">' + unescape(google_ads[i].line2) + ' ' + unescape(google_ads[i].line3) + '<\/a><\/p>'
			+ '<p><a href="' + google_ads[i].url + '" target="_blank" onmouseover="window.status=\'' + google_ads[i].visible_url + '\';return true" onmouseout="window.status=\'\'">' + google_ads[i].visible_url + '<\/a><\/p>'
			+ '<\/div>';

	}
	else if (type == 'skyscraper') {
	
		var num_ads;
		
		num_ads = google_ads.length;

		var title = num_ads == 1 ?
			  'Google-Anzeige'
			: 'Google-Anzeigen';

		s += '<div class="tipps">'
			+ '<div class="tipps-inner">'
			+ '<div align="center"><span class="tipps-head-google">' + title + '</span></div><br />'

	for (var i = 0; i < num_ads; ++i) {

		visible_url = format_overlong(google_ads[i].visible_url, 24)

		s += '<div class="tipps-single-entry">'
				+ '<span class="tipps-head"><a href="' + google_ads[i].url + '" target="_blank" onmouseover="window.status=\'' + google_ads[i].visible_url + '\';return true" onmouseout="window.status=\'\'">' + unescape(google_ads[i].line1) + '<\/a><\/span>'
				+ '<p><a class="tipps-desc" href="' + google_ads[i].url + '" target="_blank" onmouseover="window.status=\'' + google_ads[i].visible_url + '\';return true" onmouseout="window.status=\'\'">' + unescape(google_ads[i].line2) + ' ' + unescape(google_ads[i].line3) + '<\/a><\/p>'
				+ '<p><a class="tipps-link" href="' + google_ads[i].url + '" target="_blank" onmouseover="window.status=\'' + google_ads[i].visible_url + '\';return true" onmouseout="window.status=\'\'">' + visible_url + '<\/a><\/p>'
				+ '</div>';
		}
		
		s += '<\/div>'
			+ '<div class="tipps-bottom"><\/div>'
			+ '<\/div>';

	}
	
	document.write(s);
}

// Valid types are fullbanner2-GAL|fullbanner2-VID
// Currently type is not needed.
function write_google_ads_popup(google_ads, type) {
	if (!google_ads || google_ads.length == 0) return;
	var title = google_ads.length == 1 ?
		  'Google- Anzeige'
		: 'Google- Anzeigen';

	var s = '';
	
	s += '<div class="tipps" style="background-color: #FFFFFF; width: 750px; height: 90px">'
		+ '<table cellpadding="0" cellspacing="0"><tr><td><p class="tipps-head-google" style="text-align: left; vertical-align: top;">' + title + '<\/p></td>'

	for (var i = 0; i < google_ads.length; ++i) {
	
		visible_url = format_overlong(google_ads[i].visible_url, 24)
		
		s += '<td style="vertical-align: top; width:180px; padding-right: 10px;"><div class="tipps-single-entry">'
			+ '<span class="tipps-head"><a href="' + google_ads[i].url + '" target="_blank" onmouseover="window.status=\'' + google_ads[i].visible_url + '\';return true" onmouseout="window.status=\'\'">' + unescape(google_ads[i].line1) + '<\/a><\/span><br /><br />'
			+ '<a class="tipps-desc" href="' + google_ads[i].url + '" target="_blank" onmouseover="window.status=\'' + google_ads[i].visible_url + '\';return true" onmouseout="window.status=\'\'">' + unescape(google_ads[i].line2) + ' ' + unescape(google_ads[i].line3) + '<\/a><br />'
			+ '<img src="/tvtotal/media/images/pfeil_doppelrot.gif" border="0"><a class="tipps-link" href="' + google_ads[i].url + '" target="_blank" onmouseover="window.status=\'' + google_ads[i].visible_url + '\';return true" onmouseout="window.status=\'\'"> ' + visible_url + '<\/a>'
			+ '</div></td>';
	}
	
	s += '</tr></table>'
		+ '<\/div>';
	
	document.write(s);
}

function write_google_suchergebnisse(google_ads) {
	if (!google_ads || google_ads.length == 0) return;

	var style_aktuell;
	var style1 = "result_entry1";
	var	style2 = "result_entry2";

	var s = '	<!-- TablePerLinks Start -->'
		+ '		<table cellpadding="0" cellspacing="0" width="312">';

	for (var i = 0; i < google_ads.length; ++i) {
	
		// Stylewechsel in der Ergebnisliste
	    if (style_aktuell == style1 ) {
			style_aktuell = style2;
	    } else {
			style_aktuell = style1;
		}
		
		s += '			<tr>'
			+ '				<td class="' + style_aktuell + '">'
			+ '					<table cellpadding="0" cellspacing="0" border="0">'
			+ '						<tr>'
			+ '							<td rowspan="4"><img src="\/tvtotal\/media\/images\/pix.gif" width="5" height="1"><\/td>'
			+ '							<td width="262" class="hit_headline"><a class="linkstyle" href="'+ google_ads[i].url +'" target="_blank" onmouseover="window.status=\'' + google_ads[i].url + '\';return true" onmouseout="window.status=\'\'">' + google_ads[i].line1 + '<\/a><\/td>'
			+ '							<td rowspan="4"><img src="\/tvtotal\/media\/images\/pix.gif" width="5" height="1"><\/td>'
			+ '						<\/tr>'
			+ '						<tr>'
			+ '							<td colspan="2"><img src="\/tvtotal\/media\/images\/pix.gif" width="1" height="5"><\/td>'
			+ '						<\/tr>'
			+ '						<tr>'
			+ '							<td colspan="2" class="searchform">' + google_ads[i].line2 + ' ' + google_ads[i].line3 + '<\/td>'
			+ '						<\/tr>'
			+ '						<tr>'
			+ '							<td colspan="2" class="searchform">' + '<p><a class="linkstyle" href="'+ google_ads[i].url +'" target="_blank" onmouseover="window.status=\'' + google_ads[i].visible_url + '\';return true" onmouseout="window.status=\'\'">' + google_ads[i].visible_url + '<\/td>'
			+ '						<\/tr>'
			+ '					<\/table>'
			+ '				<\/td>'
			+ '			<\/tr>'
			+ '			<tr>'
			+ '				<td bgcolor="#FDA704"><img src="\/tvtotal\/media\/images\/pix.gif" height="1" width="1"><\/td>'
			+ '			<\/tr>';	
	}
	s += '		<\/table>'
		+ '		<!-- TablePerLinks Ende -->';

	document.write(s);
}

// added by ovolgmann@brainpool.de
function format_overlong(str, num) {
	if (str.length > num) {
		new_str = str.substring(0, num) + '...';
	} else {
		new_str = str; }
	return new_str;
}

function biggerInput(){
	var el = document.getElementById('CommentBox');
	//alert(el.offsetHeight);
	if(el.offsetHeight == '' || typeof el.offsetHeight == 'undefined'){
		el.style.height = '152px';
	}else
		el.style.height = el.offsetHeight + 50 + 'px';
	return false;

}



function checkTextareaLength(target, length){
	var x = document.getElementById(target).value;
	if (x.length > length) {
		x = x.substring(0, length)
		alert("Du kannst maximal " + length + " Zeichen angeben.");
	};
	document.getElementById(target).value = x;
	
}






/* home preview teaser data */
var days = new Array();

/* home preview teaser function */
function refreshPreviewData(id) {
	document.getElementById('nextGuestImg').innerHTML = days[id][1];
	document.getElementById('nextGuestText').innerHTML = days[id][4];	
	document.getElementById('nextGuestsFirst').innerHTML = days[id][2];	
	if (days[id][3])
		document.getElementById('nextGuestsOthers').innerHTML = days[id][3];
	else
		document.getElementById('nextGuestsOthers').innerHTML = "&nbsp;";
}
HTTP_GET_VARS=new Array();
strGET=document.location.search.substr(1,document.location.search.length);
if(strGET!=''){
	gArr=strGET.split('&');
	for(i=0;i<gArr.length;++i){
		v='';vArr=gArr[i].split('=');
		if(vArr.length>1){v=vArr[1];}
		HTTP_GET_VARS[unescape(vArr[0])]=unescape(v);
	}
}

function GET(v){
	if(!HTTP_GET_VARS[v]){return 'undefined';}
	return HTTP_GET_VARS[v];
}

/* ajax Suche */
/*
 * @author René Welbers <rwelbers@brainpool.de>
 * @return none
 * @function Starts the Search via YUI Ajax function
 */
function ajaxSearch()
{
	/*
	 * Check the Get Parameter for Searchtype, and if its 'article'
	 * then start the Swish-E Search via Ajax, 
	 * else start the Database Search
	 */
	if(GET('searchtype') == 'articles')
		ajax('GET','/cgi-bin/swish_tvtotal.cgi?query='+document.getElementById('query').value+'&metaname=all&sort=swishrank&start='+GET('start'),'','swish-e_search_container');
	else
		ajax('','ajax.php','search','swish-e_search_container','ajaxSearch');
	
}

