﻿function ToggleDiv(name)
{
	if (document.getElementById(name).style.display == "block")
		{ 
		document.getElementById(name).style.display='none';
		}
	else
		{ 
		document.getElementById(name).style.display='block';
		} 
}

function SwitchCover(div,pos)
{
	document.getElementById('Magazin'+pos).style.display = 'none';
	document.getElementById('DVD'+pos).style.display = 'none';
	document.getElementById(div+pos).style.display = 'block';
}

function switch_and_count(tagname,filename)
{
	document.getElementById(tagname).src=filename;
	
	var get_rand = "d=" + (Math.random()*100000);
	var get_referer = "r=" + escape(document.referrer);
	var countSwitch = new Image();
	countSwitch.src = "http://pcgameha.ivwbox.de/cgi-bin/ivw/CP/RC_BilderG;?" + get_referer + "&" + get_rand;
	
	if (typeof(pageTracker) == 'object') {
		pageTracker._trackPageview();
	}
}

function download( file, type, id ){
	var url = 'http://download.pcgameshardware.de/download.cfm?f=' + file + '&t=' + type + '&article_id=' + id;
	open( url,'Download',"resizable=0,scrollbars=0,alwaysRaised=yes,width="+750+",height="+490+",menubar=no,statusbar=no" );
}

function toggle_spoiler(id,linkid)
{
	if (document.getElementById(id).style.display == 'block')
	{
	document.getElementById(id).style.display = 'none';
	document.getElementById(linkid).innerHTML = 'anzeigen';
	}
	else
	{
	document.getElementById(id).style.display = 'block';
	document.getElementById(linkid).innerHTML = 'verbergen';
	}
}

//       var suchenBlock = 12; // <-- hier Anzahl der suchenBlock angeben
//       var suchenInterval = null;

function show_suchen_block( id )
		 {
			  var div_show = 'div_show_suchen_block_' + id;
			  var div_hide = 'div_hide_suchen_block_' + id;

			  document.getElementById(div_show).style.display = 'block';
			  document.getElementById(div_hide).style.display = 'none';

		 }

function hide_suchen_block( id )
		 {
			  var div_show = 'div_show_suchen_block_' + id;
			  var div_hide = 'div_hide_suchen_block_' + id;

			  document.getElementById(div_show).style.display = 'none';
			  document.getElementById(div_hide).style.display = 'block';

		 }

function searchkey_len()
		{
			if(document.SearchForm.searchkey.value.length >=3)
				{
					document.SearchForm.submit();
				}
			else
				{
					alert('Suchbegriffe m\u00fcssen mindestens drei Zeichen enthalten!');
				}
		}

function search_highlight_on( limit,id   )
	{
		 var td_1 = 'content_kasten_search_' + limit + '_' + id + '_1';
		 var td_2 = 'content_kasten_search_' + limit + '_' + id + '_2';
		 var td_3 = 'content_kasten_search_' + limit + '_' + id + '_3';
		 var td_4 = 'content_kasten_search_' + limit + '_' + id + '_4';
		 var td_5 = 'content_kasten_search_' + limit + '_' + id + '_5';

		 if ( ( id % 2 ) == 0 )
			{
			  document.getElementById(td_1).className = 'content_kasten_suche_thema_1_even_on';
			  document.getElementById(td_2).className = 'content_kasten_suche_thema_2_even_on';
			  document.getElementById(td_3).className = 'content_kasten_suche_thema_1_even_on';
			  document.getElementById(td_4).className = 'content_kasten_suche_thema_1_even_on';
			  document.getElementById(td_5).className = 'content_kasten_suche_thema_3_even_on';
			 }
		 else
			 {
			  document.getElementById(td_1).className = 'content_kasten_suche_thema_1_odd_on';
			  document.getElementById(td_2).className = 'content_kasten_suche_thema_2_odd_on';
			  document.getElementById(td_3).className = 'content_kasten_suche_thema_1_odd_on';
			  document.getElementById(td_4).className = 'content_kasten_suche_thema_1_odd_on';
			  document.getElementById(td_5).className = 'content_kasten_suche_thema_3_odd_on';
			 }
	}

function search_highlight_off( limit,id )

	{
		 var td_1 = 'content_kasten_search_' + limit + '_'+ id + '_1';
		 var td_2 = 'content_kasten_search_' + limit + '_'+ id + '_2';
		 var td_3 = 'content_kasten_search_' + limit + '_'+ id + '_3';
		 var td_4 = 'content_kasten_search_' + limit + '_'+ id + '_4';
		 var td_5 = 'content_kasten_search_' + limit + '_'+ id + '_5';


		 if ( ( id % 2 ) == 0 )
			 {
			  document.getElementById(td_1).className = 'content_kasten_suche_thema_1_even_off';
			  document.getElementById(td_2).className = 'content_kasten_suche_thema_2_even_off';
			  document.getElementById(td_3).className = 'content_kasten_suche_thema_1_even_off';
			  document.getElementById(td_4).className = 'content_kasten_suche_thema_1_even_off';
			  document.getElementById(td_5).className = 'content_kasten_suche_thema_3_even_off';
			 }
		 else
			 {
			  document.getElementById(td_1).className = 'content_kasten_suche_thema_1_odd_off';
			  document.getElementById(td_2).className = 'content_kasten_suche_thema_2_odd_off';
			  document.getElementById(td_3).className = 'content_kasten_suche_thema_1_odd_off';
			  document.getElementById(td_4).className = 'content_kasten_suche_thema_1_odd_off';
			  document.getElementById(td_5).className = 'content_kasten_suche_thema_3_odd_off';
			 }
	}


function image_highlight_on( limit,id   )
	{
		 var td_image = 'content_kasten_search_' + limit + '_' + id ;
		 document.getElementById(td_image).className = 'content_kasten_suche_thema_image_on';
	}

	function image_highlight_off( limit,id )
	{
		var td_image = 'content_kasten_search_' + limit + '_' + id ;
		document.getElementById(td_image).className = 'content_kasten_suche_thema_image_off';

	}

function WebCode()
{
	if(document.searchbox.strSearch.value.length==4){
		document.searchbox.action='/external/ads/forward/search.cfm';
		document.searchbox.target='_blank';
		document.searchbox.submit();
		document.searchbox.action='/service/suche/';
		document.searchbox.target='_self';
	}else{
		alert('Bonuscodes müssen vier Stellen haben!');
	}
}
function Search()
{
	document.searchbox.action='/service/suche/';
	document.searchbox.target='_self';
	document.searchbox.submit();
}
function SearchPreis()
{
	if (escape(document.searchbox.strSearch.value) == '')
		{
		document.location.href='/preisvergleich/';
		}
	else
		{
		document.location.href='/preisvergleich/?fs=' + escape(encodeURIComponent(document.searchbox.strSearch.value));
		}
}

function switchWidth(width)
{
	document.getElementById('frmSetWidth').setMaxWidth.value = width;
	document.frmSetWidth.submit();
}
function switchStyle(style)
{
	document.getElementById('frmSetStyle').setStyleset.value = style;
	document.frmSetStyle.submit();
}

function register_switcher(feed)
	{
		$('.feedListCl').css('display', 'none');
		$('#'+feed).css('display', 'block');
	}

function removeSmartphoneHint() {
	$('#smartphoneHint').remove();
	document.cookie = "smartphonehint=false;"
}

voteQuickpoll = function(id, box){
	var insertVotes = $('#submitVote_'+id).serialize();
	
	$.ajax({
		url: "/external/cf/remoteFunctions.cfc?method=savePollForm",
		type: "POST",
		dataType: "text",
		data: insertVotes,
		cache: false,
		success: function(html){
			$('#quickpoll_'+id+'_'+box).html(html);
		}
	});
}

// Betakeys Module, TH 26.10.2011
function showBetakey(product_id) {	
	window.open('/common/betakeys/index.cfm?lk_product_id=' + product_id, 'Beta-Key ' + product_id, 'height=750,width=537,resizable=no,scrollbars=no');			
}

// 2011/11/15 AA - fxmbgclick extends click area of wallpapers
// triggered by fxm only
function fxmbgclick(sUrl) {
	$('#content_main').prepend('<div class="fixed_layer" style="position:fixed;top:0;left:0;width:100%;height:1500px;z-index:0;"></div>');
	$('#header').css('position','relative');
	$('#site_content').css('position','relative');
	$('#footer').css('position','relative');
	$('.fixed_layer').bind('click', function () {window.open(sUrl)}); 
	$('.fixed_layer').css('cursor','pointer');
	$('#column_right').css('width','auto');
	
	return true;
}

function fxmskyheight(iHeight) {
/*	$('#adBox11').css('height',iHeight + 'px');
	$('#additionalSky').attr('style','position:relative; z-index:5; width:0px;margin-top:15px;');*/
	return true;
}



// 2011/11/25 AA - teaser-slider - start
// ****************************************
var oTsrSlider = new Object();

initTsrSldr = function (iCurAId) {
	oTsrSlider.bRefGoogle = false;
	oTsrSlider.bSliderOn = false;

	// if cookie ffOredilsResaet is set, don't display teaser
	if (!(document.cookie && document.cookie.indexOf('ffOredilsResaet=') >= 0)) {
		// display teaser only with google referrer 
		if (document.cookie && document.cookie.indexOf('google_ref=') >= 0) {
			oTsrSlider.bRefGoogle = true;
		}
		else if (document.referrer.search(/^(?:[a-zA-Z]+:\/\/)?[^\/]*google/i) >= 0) {
			oTsrSlider.bRefGoogle = true;
			document.cookie = 'google_ref=x; path=/;'
		}
	}
	
	if (oTsrSlider.bRefGoogle && $('#teaserSlider').length > 0 && $('.readOnBox').length > 0 && !(document.cookie && document.cookie.indexOf('ffOredilsResaet=') >= 0)) {
		oTsrSlider.bSliderOn = true;
		loadTsrSldr(iCurAId);
	}

	return true;
}

$(document).ready( function () {
	if (!((typeof bIsMobileDevice != "undefined" && bIsMobileDevice) || (typeof bIsIpad != "undefined" && bIsIpad))) {
		$('.readOnBox').css('display','block');
	}
} );

loadTsrSldr = function (iCurAId) {
	if (typeof oTsrSlider != "undefined" &&  typeof oTsrSlider.arrItems != "undefined" && (!(typeof bIsMobileDevice != "undefined" && bIsMobileDevice) && !(typeof bIsIpad != "undefined" && bIsIpad))) {
		var iNumItems = oTsrSlider.arrItems.length;
		var arrAIds = new Array(iNumItems);
		var arrAIdsNotUsed = new Array(0);
		var iRandIdx = -1;
		var iCookieAId = -1;
		var ii = -1;
		var sCookie = '';
		var sCookieVal = '';
	
		for (i=0; i < iNumItems; i++) {
			arrAIds[i] = oTsrSlider.arrItems[i].IARTICLEID*1;
		}
		
		if (iNumItems > 0) {
			if (document.cookie && document.cookie.indexOf('TSR_SLIDER=') >= 0) { 
				sCookieVal = GetCookie('TSR_SLIDER');
			}
			else {
				// cookie was not set yet, so we use current article's article-id just to simplify later parsing and appending of artcile-teaser-article-ids
				sCookieVal = iCurAId + '|' + iCurAId;
			}

			var arrMatch = sCookieVal.match(/^\d+/);

			if (arrMatch != null && arrMatch.length > 0) {
				iCookieAId = arrMatch[0]*1;
			}

			for (i=0; i < iNumItems; i++) {
				sRegExp = '/' + oTsrSlider.arrItems[i].IARTICLEID + '/';

				if (sCookieVal.search(eval(sRegExp)) == -1) {
					ii++;
					arrAIdsNotUsed[ii] = oTsrSlider.arrItems[i].IARTICLEID*1;
				}
			}

			// get random value out of count of array items
			iRandIdx = Math.floor(Math.random() * arrAIdsNotUsed.length);

			// user has reloaded current article
			if (iCookieAId == iCurAId && iCookieAId > 0) {
				if (arrAIdsNotUsed.length > 0) { 
					iRandIdx = arrAIds.indexOf(arrAIdsNotUsed[iRandIdx]*1)*1;
					sCookie = 'TSR_SLIDER=' + sCookieVal + ',' + oTsrSlider.arrItems[iRandIdx].IARTICLEID + '; path=/';
				}
				else {
					// all available articles already displayed. 
					var arrMatch = sCookieVal.match(/^\d+\|(\d+).*/);

					if (arrMatch != null && arrMatch.length >= 1) {
						iRandIdx = arrAIds.indexOf(arrMatch[1]*1)*1;

						console.log(arrMatch);
						console.log(arrAIds);
						console.log(oTsrSlider.arrItems);
						console.log(oTsrSlider);
						console.log(iRandIdx);

						// fallback; if item not found use first item
						if (iRandIdx == -1) {
							iRandIdx = 0;
						}
						
						sCookie = 'TSR_SLIDER=' + iCurAId + '|' + oTsrSlider.arrItems[iRandIdx].IARTICLEID + '; path=/';
					}
				}
			}
			// first article request
			else {
				iRandIdx = 0;
				// check whether first teaser points to previous article
				if (iCookieAId == arrAIds[0] && arrAIds.length > 1) {
					iRandIdx = 1;
				}

				sCookie = 'TSR_SLIDER=' + iCurAId + '|' + oTsrSlider.arrItems[iRandIdx].IARTICLEID + '; path=/';
			}
			/*}
			else {
				sCookie = 'TSR_SLIDER=' + iCurAId + '|' + oTsrSlider.arrItems[0].IARTICLEID + '; path=/';
			}*/
			
			document.cookie = sCookie;
	
			if (iRandIdx >= 0) {
				$('.readOnBox_image a').attr('title',oTsrSlider.arrItems[iRandIdx].STITLEALTTEXT);
				$('.readOnBox_image a').attr('href',oTsrSlider.arrItems[iRandIdx].SURLTARGET);
				$('.readOnBox_image a img').attr('src',oTsrSlider.sPath + oTsrSlider.arrItems[iRandIdx].SIMAGEURL);
				$('.readOnBox_image a').attr('alt',oTsrSlider.arrItems[iRandIdx].STITLEALTTEXT);
				
				$('#headline_link').attr('title',oTsrSlider.arrItems[iRandIdx].STITLEALTTEXT);
				$('#headline_link').attr('href',oTsrSlider.arrItems[iRandIdx].SURLTARGET);
				$('#headline_link').text(oTsrSlider.arrItems[iRandIdx].SHEADLINE);
			}
		}
	}
	
	return true;
}

$(function() {
	var distanceTop = '';

	// set cookie which remembers which article was already
	$(window).scroll(function() {
		if (oTsrSlider.bSliderOn == true) {
			// when reaching the element with id "last" we want to show the slidebox. Let's get the distance from the top to the element
			distanceTop = $('#teaserSlider').offset().top - $(window).height();
			
			if (distanceTop < 0) {
				distanceTop = 0;
			}

			//if  ($(window).scrollTop() > (distanceTop-100)*1 && $(window).scrollTop() < (distanceTop + 600)*1) {
			if  ($(window).scrollTop() > distanceTop) {
				$('.readOnBox').animate({'right':'0px'},300);
			}
			else {
				$('.readOnBox').stop(true).animate({'right':'-460px'},100);	
			}
		}
	});
			
	// remove the slidebox when clicking the cross
	$('.readOnBox .close').bind('click',function() {
		$(this).parent().parent().remove();

		// set cookie
		// slider mustn't be displayed until new session
		document.cookie = "ffOredilsResaet=off; path=/";
	});
});

// teaser-slider - end
// ********************

//Videocontrolle ab16 bzw. ab18
jQuery(document).ready(function() {
 var zeitJetzt  = new Date();
 var Std   = zeitJetzt.getHours();
 var endZeit  = '6';
 var startZeit18 = '23'; 
 var startZeit16 = '22'; 
 if (!((Std >= startZeit18 && Std < 24) || (Std >= 0 && Std < endZeit)))
 { jQuery('.ab_18').each(function(){
   jQuery(this).html('<img src="/common/gfx/images/sendepause18.png" alt="Dieser Inhalt ist nur in der Zeit zwischen '+startZeit18+':00-6:00 Uhr verfügbar." />');
  });
 }
 jQuery('.ab_18').css("display","block");
 
 if (!((Std >= startZeit16 && Std < 24) || (Std >= 0 && Std < endZeit)))
 { jQuery('.ab_16').each(function(){
   jQuery(this).html('<img src="/common/gfx/images/sendepause16.png" alt="Dieser Inhalt ist nur in der Zeit zwischen '+startZeit16+':00-6:00 Uhr verfügbar." />');
  });
 }
 jQuery('.ab_16').css("display","block");
});

