function postCommentDynamic() {
   var oEditor = FCKeditorAPI.GetInstance('text');
   var text = oEditor.GetHTML();
   var params = "do=add_comment&text=" + escape(text) + "&return_comments=1";
   target = currentFormLocation;
   oEditor.SetHTML("");
   AjaxRequest(postCommentDynamicParse,target,'POST',params);
   return false;
}

function loadCommentDynamic(target) {
   var params = "return_comments=1";
   AjaxRequest(postCommentDynamicParse,target,'POST',params);
   return false;
}

function postCommentDynamicParse(html,xml) {
	$('comments_entries').innerHTML = html;
}


function dynamicLoadLink(element) {
	var target = element.href;
	AjaxRequest(dynamicLoadLinkParse,target,'POST','__getContentOnly=1');
   return false;
}

function dynamicLoad(ele) {
	AjaxRequest(dynamicLoadLinkParse,ele,'POST','__getContentOnly=1');
}

function dynamicLoadLinkParse(html,xml) {
	$('content_left').innerHTML = html;
   if(window.correctPNG) {
  	   correctPNG();
   }
   tt_Init();
   
   loadInlineBanner(adCampaign);   

	var code = $('__jsLoad');
   if(code) {
   	eval(code.innerHTML);
   }

	code = $('__jsLoad2');
   if(code) {
   	eval(code.innerHTML);
   }
}

/************ JAVASCRIPT.JS */

var skyscraperInitial = 412;
var offsetToAd = 191;
var offsetToBottom = 20;
var adHeight = 600;
var lastScroll = 0;
function moveSkyscraper() {
   var scrolledOffset = scrolled();
   if(scrolledOffset != lastScroll) {
   	lastScroll = scrolledOffset;
	   var actualHeight = $('adbanner_topbanner').offsetHeight*1 + skyscraperInitial;
	   var top = 0;
	   if(scrolledOffset > skyscraperInitial) {
	      top = scrolledOffset - skyscraperInitial;
	   }
	   var maxTop = $('content').offsetHeight - adHeight - offsetToBottom - offsetToAd;
	   if(top > maxTop) {
	      top = maxTop;
	   }
      if(top < 0)  {
      	top = 0;
      }
	   $('adbanner_skyscraper').style.top = top + "px";
   }
}

var imagePreload = new Array();
var imageID = 1;
function resizeImage(_image,_width) {
	var id = imageID++;
	imagePreload[id] = new Image();
	imagePreload[id].src = _image;
   document.write('<div id="image_load_' + id + '"></div>');
   resizeImageShow(id,_width);
}

function resizeImageShow(_id,_width) {
	var img = imagePreload[_id];
	if(img.width > 0 || img.height > 0) {
   	var width = img.width;
      var height = img.height;
      if(width > _width) {
      	height = Math.round(height*_width/width);
      	width = _width;
      }
   	document.getElementById('image_load_' + _id).innerHTML = '<img src="'+img.src+'" width="'+width+'" height="'+height+'">';
   	return;
   }
   window.setTimeout('resizeImageShow("'+_id+'",'+_width+')',200);
}


var audioStates = new Array();
function playAudioFlash(_file,_key) {
	audioStates[_key] = false;
	document.getElementById('audio_player_init_' + _key).onclick = function() { initAudioFlash(_key); };
	var so = new SWFObject(dir + 'static/flash/jw_flv_player/mp3player.swf', "6", "320", "70", "7");
	so.addVariable("file", _file);
	so.addVariable("image", "");
	so.addVariable("showeq", "true");
	so.addVariable("overstretch", "true");
	so.addVariable("showdigits", "true");
	so.addVariable("showfsbutton", "true");
	so.addVariable("backcolor", '0x000000');
	so.addVariable("frontcolor", '0xffffff');
	so.addVariable("lightcolor", '0x0099CC');
	so.addVariable("volume", "80");
	so.addVariable("bufferlength", "5");
	so.addVariable("width", "320");
	so.addVariable("height", "70");
	so.addParam("allowfullscreen", "true");
	so.write('audio_player_' + _key);
}

function playVideoFlash(_file,_key,_width,_ap) {
	_width = _width*1;
   if(_width <= 1) {
   	_width = 480;
   }
   _ap = (_ap == "1");
   var _height = _width*3/4;
	audioStates[_key] = false;
	document.getElementById('audio_player_init_' + _key).onclick = function() { initAudioFlash(_key); };
	var so = new SWFObject(dir + 'static/flash/jw_flv_player/flvplayer.swf', "6", _width, _height, "7");
	so.addVariable("file", _file);
	so.addVariable("image", "");
	so.addVariable("showeq", "false");
	so.addVariable("overstretch", "true");
	so.addVariable("showdigits", "true");
	so.addVariable("showfsbutton", "true");
	so.addVariable("backcolor", '0x000000');
	so.addVariable("frontcolor", '0xffffff');
	so.addVariable("lightcolor", '0x0099CC');
	so.addVariable("volume", "80");
	so.addVariable("bufferlength", "5");
	so.addVariable("width", _width);
	so.addVariable("height", _height);
   so.addVariable("autostart", _ap);
	so.addParam("allowfullscreen", "true");
	so.addParam("wmode", "transparent");
	so.write('audio_player_' + _key);
}

function initAudioFlash(_key) {
//   new Effect.Fade(document.getElementById('audio_player_init_' + _key), {duration:0, afterFinish: function() { new Effect.Appear('audio_player_' + _key);  }});
	if(audioStates[_key]) {
      audioStates[_key] = false;
      document.getElementById('audio_player_' + _key).style.display = "none";
   } else {
      audioStates[_key] = true;
      document.getElementById('audio_player_' + _key).style.display = "block";
   }
}


function submitForm(_form) {
	document.getElementById(_form).submit();
}

refreshTimer = null;
function refreshAfter(_secs) {
	refreshTimer = window.setInterval("refreshDo()",_secs*1000);
}

function stopRefresh() {
	if(refreshTimer) {
		window.clearInterval(refreshTimer);
   }
}

function refreshDo() {
	window.clearInterval(popupBackgroundUpdater);
	window.location.href = "./";
}

function writeFlashTo(_id2,_file,_width,_height,_bgcolor,_wmode,_id) {
	window.setTimeout("writeFlashToReal('"+_id2+"','"+_file+"','"+_width+"','"+_height+"','"+_bgcolor+"','"+_wmode+"','"+_id+"')",200);
}

function writeFlashToReal(_id2,_file,_width,_height,_bgcolor,_wmode,_id) {
	var output = "";
	output += '<object data="'+_file+'" type="application/x-shockwave-flash" width="'+_width+'" height="'+_height+'" id="'+(_id?_id:'flashMovie')+'"  align="middle">';
	output += '<param name="movie" value="'+_file+'"/>\n'
	output += '<param name="menu" value="false"/>\n'
	output += '<param name="quality" value="best"/>\n'
	output += '<param name="AllowScriptAccess" value="always"/>\n';
	output += '<param name="align" value="middle"/>\n';
   if(_bgcolor) {
		output += '<param name="bgcolor" value="'+_bgcolor+'"/>\n';
   }
   if(_wmode) {
		output += '<param name="wmode" value="transparent"/>\n';
   }
   output += '<embed src="'+_file+'" menu="false" '+(_wmode?'wmode="'+_wmode+'"':'')+' '+(_bgcolor?'bgcolor="'+_bgcolor+'"':'')+' quality="best" width="'+_width+'" height="'+_height+'" AllowScriptAccess="always" scale="exactfit" type="application/x-shockwave-flash" pluginspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>\n';
   output += '</object>\n';

   document.getElementById(_id2).innerHTML = output;
}

function writeFlash(_file,_width,_height,_bgcolor,_wmode,_id) {
	document.write('<object data="'+_file+'" type="application/x-shockwave-flash" width="'+_width+'" height="'+_height+'" id="'+(_id?_id:'flashMovie')+'"  align="middle">');
	document.write('<param name="movie" value="'+_file+'"/>\n');
	document.write('<param name="menu" value="false"/>\n');
	document.write('<param name="qulality" value="best"/>\n');
	document.write('<param name="AllowScriptAccess" value="always"/>\n');
	document.write('<param name="align" value="middle"/>\n');
   if(_bgcolor) {
		document.write('<param name="bgcolor" value="'+_bgcolor+'"/>\n');
   }
   if(_wmode) {
		document.write('<param name="wmode" value="transparent"/>\n');
   }
   document.write('<embed src="'+_file+'" menu="false" '+(_wmode?'wmode="'+_wmode+'"':'')+' '+(_bgcolor?'bgcolor="'+_bgcolor+'"':'')+' quality="best" width="'+_width+'" height="'+_height+'" AllowScriptAccess="always" scale="exactfit" type="application/x-shockwave-flash" pluginspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>\n');
   document.write('</object>\n');
}

function startMover() {
	document.getElementById('ticker').setAttribute('scrollamount',"3");
	document.getElementById('ticker').setAttribute('scrolldelay',"5");
}

function stopMover() {
	document.getElementById('ticker').setAttribute('scrollamount',"0");
}

function replaceLinks() {
	for (var i = 0; i < document.links.length; ++i) {
   	link = "" + document.links[i].href;
   	if(link.substr(0,dir.length) != dir && !link.match(/gamecity\.ch/) && link.substr(0,10) != 'javascript' && link != "" && document.links[i].className != 'no_external') {
         save = document.links[i].innerHTML;
         document.links[i].href = dir + "link/external/?link=" + escape(link);
         document.links[i].innerHTML = save;
      }
   }
}

/* RANDOM BOX */
randomBoxItems = new Array();
randomBoxElement = null;
randomBoxCurrent = 0;
randomBoxCount = 0;
randomBoxID = 0;
randomBoxAdDuration = 10000;

function adSpotBoxHover() {
   showPopupBackground();
   AjaxRequest(adSpotBoxHoverParse,dir + 'dynamic/ad/adspotboxbig/'+randomBoxID+'/','GET',false);
}

function adSpotBoxHoverParse(html,xml) {
	popupContentElement.innerHTML = html;
   centerize('popup_content');
   if(window.correctPNG) {
  	   correctPNG();
   }
}

function addRandomBox(_title,_length) {
	data = new Array();
   data['title']  = _title;
   data['length'] = _length
	randomBoxItems.push(data);
}
function initRandomBox() {
//	randomBoxCurrent = Math.floor(Math.random()*randomBoxItems.length);
	randomBoxElement = document.getElementById('random_box');
   loadRandomBox();
}

function parseRandomBox(html,xml) {
   randomBoxElement.innerHTML = html;
   if(window.correctPNG) {
  	   correctPNG();
   }
}

function parseRandomBoxAd(html,xml) {
	if(html.length > 0) {
	   randomBoxElement.innerHTML = html;
      field = document.getElementById('adspotbox_playtime');
      id = document.getElementById('adspotbox_id');
      if(field && field.value) {
      	playtime = field.value*1;
         if(playtime == 0) {
         	playtime = 10;
         }
      } else {
      	playtime = 10;
      }
      if(id && id.value) {
      	randomBoxID = id.value*1;
      }
	   window.setTimeout("loadRandomBox()",playtime*1000);
   } else {
		AjaxRequest(parseRandomBox,dir + 'dynamic/random_box/'+randomBoxItems[randomBoxCurrent]['title']+'/','GET',false);
      _save = randomBoxCurrent;
	   randomBoxCurrent = (randomBoxCurrent + 1) % randomBoxItems.length;
	   window.setTimeout("loadRandomBox()",randomBoxItems[_save]['length']*1000);
   }
}

function getDownloadPopup(_from) {
	return document.getElementById(_from).innerHTML;
}
function loadRandomBox() {
/*   randomBoxCount++;
	if(randomBoxCount % 100000 == 0) {
		AjaxRequest(parseRandomBoxAd,dir + 'dynamic/ad/banner/adspotbox/'+adCampaign+'/?system='+adSystem,'GET',false);
   } else {*/
		AjaxRequest(parseRandomBox,dir + 'dynamic/random_box/'+randomBoxItems[randomBoxCurrent]['title']+'/','GET',false);
      _save = randomBoxCurrent;
//	   randomBoxCurrent = (randomBoxCurrent + 1) % randomBoxItems.length;
//	   window.setTimeout("loadRandomBox()",randomBoxItems[_save]['length']*1000);
//   }
}

var changeToActive = new Array();
var changeToMax = new Array();
function changeTo(_item,_nr) {
	var d;
	var img;
	changeToActive[_item] = _nr;
	for(i = 1;i <= changeToMax[_item];i++) {
		d = document.getElementById(_item + '_' + i);
      img = document.getElementById(_item + '_image_' + i);
      if(d) {
         if(i == _nr) {
            d.style.display = "block";
            img.src = layout + 'icon_switch2_active.gif';
         } else {
            d.style.display = "none";
            img.src = layout + 'icon_switch2.gif';
         }
      }
   }
}
function initAutoChange(_item,_max) {
	changeToMax[_item] = 5;
	for(i = 1;i <= changeToMax[_item];i++) {
		d = document.getElementById(_item + '_' + i);
      if(!d) {
      	changeToMax[_item] = i - 1;
         break;
      }
   }
   window.setTimeout('autoChange("'+_item+'",1)',0);
}
function autoChange(_item,_nr) {
	changeTo(_item,_nr);
	next = (_nr == changeToMax[_item] ? 1 : _nr + 1);
	window.setTimeout('autoChange("'+_item+'",'+next+')',10000);
}

function callCheck(text) {
	if(text == undefined) {
   	text = "Wirklich löschen?";
   }
   return confirm(text);
}

function initAGB() {
	showPopupBackground();
	AjaxRequest(parseInitAGB,'?show=agb','GET',false);
}
function parseInitAGB(html,xml) {
	popupContentElement.innerHTML = html;
   centerize('popup_content');
   if(window.correctPNG) {
  	   correctPNG();
   }
}

/* SEND-OPTIONS */
var sendUrl = "";
var sendUrlTop = false;
function initSend(_url,_color) {
	sendUrlTop = false;
	sendUrl = _url;
	showPopupBackground();
	AjaxRequest(parseInitSend,dir + 'content/send/'+_color+'/','GET',false);
}
function initSendTop(_url,_color) {
	sendUrlTop = true;
	sendUrl = _url;
	showPopupBackground(sendUrlTop);
	AjaxRequest(parseInitSend,dir + 'content/send/'+_color+'/','GET',false);
}

function parseInitSend(html,xml) {
	popupContentElement.innerHTML = html;
   centerize('popup_content');
   if(window.correctPNG) {
  	   correctPNG();
   }
   if(sendUrlTop) {
   	document.getElementById('popup_content').style.top = "150px";
   }
}
var sendEmail = "";
function doSend(_url) {
	if(_url) {
   	sendUrl = _url;
   }
	postData = '?';
	fromName = document.getElementById('send_name').value;
   fromEmail = document.getElementById('send_email').value;
   toName = document.getElementById('to_name').value;
   toEmail = document.getElementById('to_email').value;
   sendEmail = toEmail;
   text = document.getElementById('send_text').value;
   url = escape(sendUrl);
   postData = 'from_name='+fromName+'&from_email='+fromEmail+'&to_name='+toName+'&to_email='+toEmail+'&text='+text+'&url='+url;
   document.getElementById('send_form_result').innerHTML = " - Prüfe..";
   AjaxRequest(parseDoSend,dir + 'content/send/?submit=1','POST',postData);
}

function parseDoSend(html,xml) {
	if(html == 'false') {
   	msg = ' - Fülle biite alle Felder aus.';
   } else {
   	msg = ' - <b>Deine Empfehlung wurde an '+sendEmail+' erfolgreich versandt.</b>';
      document.getElementById('form_send').reset();
   }
   document.getElementById('send_form_result').innerHTML = msg;
}


/* SMILEYS */
smileysLoaded = false;
function openSmileys() {
	popupReload = false;
	if(!smileysLoaded) {
		showPopupBackground();
      AjaxRequest(parseOpenSmileys,dir + 'dynamic/smileys/','GET',false);
      smileysLoaded = true;
   } else {
		showPopupBackground();
   }
}
function parseOpenSmileys(html,xml) {
	popupContentElement.innerHTML = html;
   centerize('popup_content');
   if(window.correctPNG) {
  	   correctPNG();
   }
}

/* REGISTER */
function checkRegisterNick() {
	document.getElementById('info_nick').innerHTML = 'Überprüfe...';
	nick = document.getElementById('input_nick').value;
   AjaxRequest(parseCheckRegisterNick,dir + 'register/check_nick/','POST','nick='+escape(nick));
   return true;
}
function parseCheckRegisterNick(html,xml) {
	document.getElementById('info_nick').innerHTML = html;
}
function checkRegisterPassword(element) {
	d = document.getElementById('pw_security');
	value = element.value;

   factor = 0;
   len = value.length;

   if(value.match(/^[a-z]*$/)) {
   	level = 0.1;
   } else if(value.match(/^[a-zA-Z]*$/)) {
   	level = 0.3;
   } else if(value.match(/^[a-zA-Z0-9]*$/)) {
   	level = 0.8;
   } else {
   	level = 1;
   }


   if(len < 6) {
   	factor = 0;
   } else {
   	factor = (len-2) / 7;
      if(factor > 1) {
      	factor = 1;
      }
   }
   d.style.width = Math.round(factor*level*100) + "%";
}

/* POPUP BACKGROUND & PLAYER */
var popupBackgroundElement = null;
var popupContentElement = null;
var popupBackgroundUpdater = null;
var popupBackgroundBody = null;
var popupCloseFunction = null;
var popupReload = true;

function getElement(element) {
	return document.getElementById(element);
}
function hideBanner() {
//	d = null;
//   if(d = getElement('td_flash')) {
//   	d.setAttribute('wmode','transparent');
//      params = document.getElementsByTagName(	);
//      for(i = 0; i < params.length) {

//      }
//   }

	getElement('header_ad').style.visibility = 'hidden';
	getElement('element_skyscraper').style.visibility = 'hidden';
}
function showBanner() {
	getElement('element_skyscraper').style.visibility = 'visible';
	getElement('header_ad').style.visibility = 'visible';
}

function showPopupBackground(_stay) {
	if(_stay == undefined) {
   	_stay = false;
	}
	popupBackgroundElement = document.getElementById('popup_background');
	popupContentElement = document.getElementById('popup_content');
   popupBackgroundBody = document.getElementsByTagName('body')[0];
   popupBackgroundElement.style.display = 'block';
   popupContentElement.style.display = 'block';
   updatePopupBackground();
   if(_stay) {
	   popupBackgroundUpdater = window.setInterval("updatePopupBackground2()",500);
   } else {
		popupBackgroundUpdater = window.setInterval("updatePopupBackground()",500);
   }
   hideBanner();
	hideSelects();
   if(popupReload) {
	   popupContentElement.innerHTML = "Lade...";
   }
   centerize('popup_content');
}
function updatePopupBackground() {
	width = popupBackgroundBody.offsetWidth;
	height = popupBackgroundBody.offsetHeight+scrolled();
	popupBackgroundElement.style.width = width + "px";
	popupBackgroundElement.style.height = height + "px";
   centerize('popup_content');
}

function updatePopupBackground2() {
	width = popupBackgroundBody.offsetWidth;
	height = popupBackgroundBody.offsetHeight+scrolled();
	popupBackgroundElement.style.width = width + "px";
	popupBackgroundElement.style.height = height + "px";
}

function closePopupBackground() {
   if(popupCloseFunction != null) {
	   popupCloseFunction();
      popupCloseFunction = null;
   }
	window.clearInterval(popupBackgroundUpdater);
	popupBackgroundElement.style.display = "none";
	popupContentElement.style.display = "none";
   if(popupReload) {
	   popupContentElement.innerHTML = "";
	}
	showSelects();
   showBanner();
}

function scrolled() {
   if (self.pageYOffset) {
      return self.pageYOffset;
   }
   else if (document.documentElement && document.documentElement.scrollTop) {
      return document.documentElement.scrollTop;
   }
   else if (document.body) {
      return document.body.scrollTop;
   }
}

/* REWORKED GALLERY */
var popupGalleryStart = 0;
var popupGalleryLast  = false;
var popupGalleryCount = 0;
var popupGalleryDiaShow = null;
var popupGalleryShowTags = true;
var popupGalleryHasTag = false;

function popupGalleryToogleTags(_swapper) {
	if(popupGalleryShowTags) {
   	document.getElementById('popup_gallery_tags').style.display = "none";
      _swapper.innerHTML = "Tags anzeigen";
      popupGalleryShowTags = false;
   } else {
   	document.getElementById('popup_gallery_tags').style.display = "block";
      _swapper.innerHTML = "Tags ausblenden";
      popupGalleryShowTags = true;
   }
}

function popupGalleryStartDia() {
	popupCloseFunction = popupGalleryStopDia;
	popupGalleryShowDia();
	popupGalleryDiaShow = window.setInterval("popupGalleryShowDia()",5000);
   document.getElementById('gallery_diashow_start').style.display = "none";
   document.getElementById('gallery_diashow_stop').style.display = "inline";
}

function popupGalleryStopDia() {
	if(popupGalleryDiaShow) {
		window.clearInterval(popupGalleryDiaShow);
	   popupGalleryDiaShow = null;
	}
   if(document.getElementById('gallery_diashow_start')) {
   	document.getElementById('gallery_diashow_start').style.display = "inline";
	   document.getElementById('gallery_diashow_stop').style.display = "none";
   }
}

function popupGalleryClearTags() {
	document.getElementById('popup_gallery_tags').innerHTML = "";
}

function deleteTag(id) {
	if(confirm('Möchtest du dein Tag löschen?')) {
	   AjaxRequest(deleteTagParse,dir +  '/content/popup_gallery/delete_tag/?tag='+id,'GET',false);
   }
}
function deleteTagParse(html,xml) {
	popupGalleryLoadTags();
}

function popupGalleryLoadTags() {
	popupGalleryHasTag = false;
	id = document.getElementById('popup_gallery_id').value;
	type = document.getElementById('popup_gallery_type').value;
   AjaxRequest(poppGalleryLoadTagsParse,dir +  '/content/popup_gallery/'+type+'/'+id+'/?tags=1','GET',false);
}

function poppGalleryLoadTagsParse(html,xml) {
	document.getElementById('popup_gallery_tags').innerHTML = html;
   check = document.getElementById('popup_gallery_set');
   if(check) {
   	popupGalleryHasTag = true;
   }
}

function popupGalleryShowDia() {
	popupGalleryNext();
}

function popupGalleryInit(_link,_image) {
	showPopupBackground();
   AjaxRequest(popupGalleryInitParse,dir +  '/content/popup_gallery/' + _link,'GET',false);
}

function popupGalleryInitParse(html,xml) {
	popupContentElement.innerHTML = html;
   centerize('popup_content');
   if(window.correctPNG) {
  	   correctPNG();
   }
   var nr = document.getElementById('popupgallery_nr').value;
   if(nr > 0) {
  	   popupGalleryStart = nr;
	   popupGalleryLast = document.getElementById('popupgallery_image_' + nr);
   	popupGalleryLast.firstChild.style.border = "1px solid white";
   }
  	initSlider('popupgallery_slider');
   var left = document.getElementById('popupgallery_offset').value * 1;
   popupGalleryGoto(left);

   popupGalleryLoadTags();
}

function popupGalleryGoto(_left)  {
   sliderMax   = sliderElement.offsetWidth;
   sliderWidth = sliderElement.parentNode.parentNode.offsetWidth;
   left = (sliderWidth/2) - (140/2) - _left*1;
   if(left > 0 || sliderMax < sliderWidth) {
      left = 0;
   } else if(sliderMax+left < sliderWidth) {
      left = -1*(sliderMax-sliderWidth);
   }
	sliderElement.parentNode.style.left = left + "px";

	popupGalleryLoadTags();
}

function popupGalleryShow(_image,_width,_height,_this,_nr,_left,_id) {

	popupGalleryClearTags();
	document.getElementById('popup_gallery_id').value = _id;
   popupGalleryCount++;
	popupGalleryStart = _nr;

	if(popupGalleryLast && popupGalleryLast.firstChild) {
		popupGalleryLast.firstChild.style.border = "1px solid #4c4c4c";
   }
   popupGalleryLast = _this;
	_this.firstChild.style.border = "1px solid white";

   document.getElementById('popup_gallery_screenshot').src = _image;
   document.getElementById('popup_gallery_screenshot').width = _width;
   document.getElementById('popup_gallery_screenshot').height = _height;

   document.getElementById('popup_gallery_screenshot').style.width = _width + "px";
   document.getElementById('popup_gallery_screenshot').style.height = _height + "px";

   document.getElementById('popup_gallery_screenshot').style.display = 'inline';
   document.getElementById('popup_gallery_ad').style.display = 'none';

   if(popupGalleryShowTags && document.getElementById('popup_gallery_tags').style.display == "none") {
     	document.getElementById('popup_gallery_tags').style.display = "block";
   }

   popupGalleryAdCheck();
   centerize('popup_content');
   popupGalleryGoto(_left);
}

function popupGalleryAdCheck() {
	if(popupGalleryCount % 4 == 0) {
   	document.getElementById('popup_gallery_tags').style.display = "none";
//   	document.getElementById('popup_gallery_screenshot').style.display = 'none';
//   	document.getElementById('popup_gallery_ad').style.display = 'block';
      loadAdGalleryPopup();
   }
}

function popupGalleryHideAd() {
  	document.getElementById('popup_gallery_tags').style.display = "block";
   document.getElementById('popup_gallery_screenshot').style.display = 'inline';
   document.getElementById('popup_gallery_ad').style.display = 'none';
}

function popupGalleryNext() {
 	popupGalleryStart++;
   next = document.getElementById('popupgallery_image_' + popupGalleryStart);
   if(next) {
      next.onclick();
   } else {
      popupGalleryStart = 0;
      popupGalleryNext();
   }
}
function popupGalleryPrev(_start) {
  	popupGalleryStart--;
   prev = document.getElementById('popupgallery_image_' + popupGalleryStart);
   if(prev) {
      prev.onclick();
   } else {
	  	popupGalleryStart++;
   }
}
function popupGalleryUpdate(_image) {

   var copy = new Image();
   copy.src = _image.src;

   width = copy.width;
   height = copy.height;

   if(width > 800) width = 800;
   height = width/copy.width*height;
   if(height > 600) height = 600;
   width = height/copy.height*copy.width;

   document.getElementById('popup_gallery_screenshot').onload = null;
   document.getElementById('popup_gallery_screenshot').src = _image.src;
   document.getElementById('popup_gallery_screenshot').width = width;
   document.getElementById('popup_gallery_screenshot').height = height;
   centerize('popup_content');
}


/* GALLERY POPUP FRONTEND */
function initGallery(game,screenshot,base) {
	if(base == null) {
   	base = dir + 'game/'+ game+ '/screenshots/';
   }
	showPopupBackground();
   AjaxRequest(parseGalleryData,base + screenshot + '/','GET',false);
   return true;
}
function parseGalleryData(html,xml) {
	popupContentElement.innerHTML = html;
   centerize('popup_content');
   initSlider('screenshots2_slider');
   popupCloseFunction = closeGallery;
   if(window.correctPNG) {
  	   correctPNG();
   }
}
function updateGallery(game,screenshot,base) {
	if(base == null) {
   	base = dir + 'game/'+ game+ '/screenshots/';
   }
   AjaxRequest(parseGalleryUpdateData,base + screenshot + '/update/','GET',false);
}
function parseGalleryUpdateData(html,xml) {
	document.getElementById('popup_gallery_screenshot').innerHTML = html;
   centerize('popup_content');
}
function closeGallery() {
	initSlider('screenshots_slider');
}

/* FLASH PLAYER FRONTEND */
function initPlayer(game,file) {
	if(adCampaign != null) {
      game = 1*game;
      showPopupBackground();
      if(game > 0) {
         AjaxRequest(parsePlayerData,dir + 'game/'+game+'/files/'+file+'/player/?system='+adSystem+'&campaign=' + adCampaign,'GET',false);
      } else {
         AjaxRequest(parsePlayerData,dir + 'content/download/'+file+'/player/?system='+adSystem+'&campaign=' + adCampaign,'GET',false);
      }
   } else {
   	window.setTimeout('initPlayer("'+game+'","'+file+'")',1000);
   }
}
function updatePlayer(game,file) {
   AjaxRequest(parsePlayerUpdateData,dir + 'game/'+game+'/files/'+file+'/playeronly/','GET',false);
}
function parsePlayerData(html,xml) {
	popupContentElement.innerHTML = html;
   centerize('popup_content');
   if(window.correctPNG) {
  	   correctPNG();
   }
}
function parsePlayerUpdateData(html,xml) {
	document.getElementById('flashplayer_video').innerHTML = html;
}

/* SWAP PAGE*/
function swapPage(element,link) {
	var value = element.value;
   window.location.href = link  + value +  "/";
}

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
var isIE_PNG = (navigator.appName == "Microsoft Internet Explorer" && navigator.userAgent.indexOf('Opera') == -1);

function pngImage(imgSource) {
  if(isIE_PNG) document.write('<img src="'+layout+'/trans.gif" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+imgSource+');">');
  else document.write('<img src="'+imgSource+'">');
}

/* POP UP*/
var POPUP_OPEN = 0;
var POPUP_CLOSABLE = 1;

var popupTimer = 250;
var popupStates = new Array();
var popupIDs = new Array();
var popupBack = new Array();

function openPopup(element,popup) {
	if(document.getElementById(popup + "_menu")) {
	   document.getElementById(popup + "_menu").style.display = 'block';
   	popupStates[popup] = POPUP_OPEN;
	   popupIDs[popup] = element;
   	element.style.backgroundImage = "url('"+layout+"nav_back_hover_"+popup+".jpg')";
   }
}

function hoverPopup(popup) {
   popupIDs[popup].style.backgroundImage = "url('"+layout+"nav_back_hover_"+popup+".jpg')";
   popupStates[popup] = POPUP_OPEN;
}

function unhoverPopup(popup) {
	popupStates[popup] = POPUP_CLOSABLE;
   window.setTimeout("closePopup('"+popup+"')",popupTimer);
}

function closePopup(popup) {
	if(popupStates[popup] == POPUP_CLOSABLE && document.getElementById(popup + "_menu")) {
   	if(popup != menuActive) {
	      popupIDs[popup].style.backgroundImage = "url('"+layout+"nav_back.jpg')";
      }
      document.getElementById(popup + "_menu").style.display = 'none';
   }
}

/* Tipps RATING SLIDER */
var ratingSliderTipsTop = 30;
var ratingSliderTipsLeft = -23;
var ratingSliderTipsElement = null
var ratingSliderTipsMax = 214;
var ratingSliderTipsOffset = 0;
var ratingSliderTipsMode = null;

function initRatingSliderTips(_percent,_mode) {
	ratingSliderTipsMode = _mode;
	if(!_percent || _percent == "") {
   	_percent = 5;
   }
   if(_mode == "points") {
   	_percent *= 10;
   }
	if(document.getElementById('rating_slider')) {
      ratingSliderTipsOffset = Math.round(_percent/100*ratingSliderTipsMax);

      ratingSliderTipsElement = document.getElementById('rating_slider');
      ratingSliderTipsElement.style.top = ratingSliderTipsTop + "px";
      ratingSliderTipsElement.style.left = ratingSliderTipsLeft + ratingSliderTipsOffset + "px";

      SET_DHTML("rating_slider"+MAXOFFLEFT+(0+ratingSliderTipsOffset)+MAXOFFRIGHT+(ratingSliderTipsMax-ratingSliderTipsOffset)+HORIZONTAL);
      dd.elements["rating_slider"].setDragFunc(updateRatingSlider);

      updateRatingSlider();
   }
}

/* RATING SLIDER */
var ratingSliderTop = 6;
var ratingSliderLeft = 114;
var ratingSliderElement = null
var ratingSliderMax = 118;
var ratingSliderOffset = 0;
var ratingSliderMode = null;
function initRatingSlider(_percent,_mode) {
	ratingSliderMode = _mode;
	if(!_percent || _percent == "") {
   	_percent = 5;
   }
   if(_mode == "points") {
   	_percent *= 10;
   }
	if(document.getElementById('rating_slider')) {
      ratingSliderOffset = Math.round(_percent/100*ratingSliderMax);

      ratingSliderElement = document.getElementById('rating_slider');
      ratingSliderElement.style.top = ratingSliderTop + "px";
      ratingSliderElement.style.left = ratingSliderLeft + ratingSliderOffset + "px";

      SET_DHTML("rating_slider"+MAXOFFLEFT+(0+ratingSliderOffset)+MAXOFFRIGHT+(ratingSliderMax-ratingSliderOffset)+HORIZONTAL);
      dd.elements["rating_slider"].setDragFunc(updateRatingSlider);

      updateRatingSlider();
   }
}
function updateRatingSlider() {

   var offset = dd.elements["rating_slider"].x-dd.elements["rating_slider"].defx + ratingSliderOffset;
   var percent = Math.round(offset/ratingSliderMax*100);
   percent = !percent ? 1 : percent;
   if(ratingSliderMode == 'points') {
	   document.getElementById('rating_slider_percent').innerHTML = Math.ceil(percent/10) + " P.";
   } else {
	   //document.getElementById('rating_slider_percent').innerHTML = percent + "%";
   }
	if(document.getElementById('user_rating')) {
	   if(ratingSliderMode == 'points') {
	      document.getElementById('user_rating').value = Math.ceil(percent/10);
      } else {
	      document.getElementById('user_rating').value = percent;

         if(document.getElementById('rating_preview')) {
	         document.getElementById('rating_preview').innerHTML = percent;
         }
      }
   }
}
function sendRating(user) {
	if(!user) {
   	alert('Du musst registriert und eingeloggt sein, um eine Bewertung abgeben zu können.');
   } else {
      if(confirm('Bewertung abschicken?')) {
         document.getElementById('user_rating_form').submit();
      }
	}
}

/* FUNCTIONS */
resetState = new Array();

function resetInput(element,name) {
	if(!resetState[name]) {
   	resetState[name] = true;
      element.value = "";
   }
}

function hoverNav(element,name) {
	element.style.backgroundImage = "url('"+layout+"header_nav_hovered.gif')";
}

function unhoverNav(element) {
	element.style.background = "none";
}

var isIE_PNG = (navigator.appName == "Microsoft Internet Explorer" && navigator.userAgent.indexOf('Opera') == -1);

function Popup(path,name,width,height,scrolling,resizable) {
	window.open(path,name,"width="+width+",height="+height+",scrollbars="+scrolling+",resizable="+resizable);
}

/* LIST SLIDER */
var listSliderIsMoving = false;
var listSliderElement = null;
var listSliderRefreshRate = 30;
var listSliderSpace = 3;
var listSliderMax = 0;
var listSliderHeight = 0;

function setSliderSpace(_space) {
	listSliderSpace = _space;
}

function clickListSlider(_element,_direction,_height,_offset) {
	listSliderElement = document.getElementById(_element);
   listSliderMax     = listSliderElement.offsetHeight;
   listSliderHeight  = listSliderElement.parentNode.offsetHeight;
   if(_height == undefined || _height == null) {
   	_height = listSliderHeight;
   }

   if(_offset != undefined) {
   	_height += _offset;
   }

   var left = listSliderElement.style.top;
   left = left.substring(0,left.length-2)*1;
   if(_direction == "up") {
      left += _height;
   } else {
      left -= _height;
   }
   if(left > 0) {
      left = 0;
   }
   if(left+listSliderMax < listSliderHeight) {
      left = listSliderHeight-listSliderMax;
   }
   listSliderElement.style.top = left + "px";
}

function startListSlider(_element,_direction) {
	listSliderElement = document.getElementById(_element);
   listSliderMax = listSliderElement.offsetHeight;
   listSliderHeight = listSliderElement.parentNode.offsetHeight;
	listSliderIsMoving = _direction;
	window.setTimeout("moveListSlider('"+_direction+"')",listSliderRefreshRate);
}

function stopListSlider() {
	listSliderIsMoving = false;
}

function bottomListSlider(_element) {
	listSliderElement = document.getElementById(_element);
   listSliderMax = listSliderElement.offsetHeight;
   listSliderHeight = listSliderElement.parentNode.offsetHeight;

   if(listSliderMax > listSliderHeight) {
   	offset = listSliderMax-listSliderHeight;
      listSliderElement.style.top = "-"+offset+"px";
   }
}

function moveListSlider(direction) {
	if(listSliderMax > listSliderHeight && listSliderIsMoving == direction) {

      var left = listSliderElement.style.top;
		left = left.substring(0,left.length-2)*1;

      if(direction == "up") {
			left += listSliderSpace;
		} else {
			left -= listSliderSpace;
		}

      if(left > 0) {
      	left = 0;
      }

      if(left+listSliderMax < listSliderHeight) {
      	left = listSliderHeight-listSliderMax;
      }

		listSliderElement.style.top = left + "px";

		window.setTimeout("moveListSlider('"+direction+"')",listSliderRefreshRate);
	}
}

/* SLIDER HORI */
var sliderIsMoving = false;
var sliderElement = null;
var refreshRate = 20;
var space = 5;
var sliderMax = 0;
var sliderWidth = 0;

function initSlider(_element) {
	sliderElement = document.getElementById(_element);
}

function moveSliderPage(_dir,_element,_space,_offset) {
	if(_element) {
		initSlider(_element);
   }
   sliderMax   = sliderElement.offsetWidth;
   sliderWidth = sliderElement.parentNode.parentNode.offsetWidth;

   if(_offset != undefined) {
   	sliderWidth += _offset;
   }

   _space = _space * 1;

   var left = sliderElement.parentNode.style.left;
   left = left.substring(0,left.length-2)*1;

   if(_dir == "left") {
      left += _space ? _space : sliderWidth;
   } else {
      left -= _space ? _space : sliderWidth;
   }

   if(left > 0) {
      left = 0;
   } else if(sliderMax-(left*-1) < sliderWidth) {
      left = -1*(sliderMax-sliderWidth);
   }

	sliderElement.parentNode.style.left = left + "px";
}

function moveSlider(direction,element) {

	if(element) {
   	sliderElement = document.getElementById(element);
   }

   sliderMax   = sliderElement.offsetWidth;
   sliderWidth = sliderElement.parentNode.parentNode.offsetWidth;


   if(sliderMax <= sliderWidth) {
   	return;
   }

	sliderIsMoving = direction;


	window.setTimeout("move('"+direction+"')",refreshRate);
}

function stopMove() {
	sliderIsMoving = false;
}

function move(direction) {

	if(sliderIsMoving == direction) {

      var left = sliderElement.parentNode.style.left;
		left = left.substring(0,left.length-2)*1;

      if(direction == "left") {
			left += space;
		} else {
			left -= space;
		}

      if(left > 0) {
      	left = 0;
      } else if(sliderMax-(left*-1) < sliderWidth) {
      	left = -1*(sliderMax-sliderWidth);
      }

//      document.write(left);

		sliderElement.parentNode.style.left = left + "px";
		window.setTimeout("move('"+direction+"')",refreshRate);
	}
}



/* Centerized Tooltip */

function getImageTooltip(image,imgInt,img) {
   var copy = new Image();
   copy.src = image.src;

   width = copy.width;
   height = copy.height;
   if(width > 640) width = 640;
   height = width/copy.width*height;

   if(height > 480) height = 480;
   width = height/copy.height*copy.width;

   extra = "";
   if(imgInt != null && imgInt != "undefined") {
   	extra = "onClick=\"addCode('"+imgInt+"','"+img+"')\"";
   }

   basic = "<img "+extra+" width=\'"+width+"\' src=\'"+image.src+"\'>";
   return basic;
}

var updateInterval; // Intervall, in which the frame is recentered
var hideInterval; // Interval after which tooltip is closed, if its not reset
var closeable = false;
var tooltip = false;

function getImage(image,width) {
	width = width ? "width=" + width : "";
	return '<img '+width+' src="'+image+'">';
}

function getResizedTooltip(image,maxWidth,maxHeight,loading) {
   var copy = new Image();
   copy.src = image;
   width    = copy.width;
   height   = copy.height;

   if(maxWidth && width > maxWidth) {
   	width = maxWidth;
   	height = width/copy.width*height;
   }
   if(maxHeight && height > maxHeight) {
   	height = maxHeight;
   	width = height/copy.height*copy.width;
   }

   if(height == 0 || width == 0) {
   	window.setTimeout('getResizedTooltip("'+image+'",'+maxWidth+','+maxHeight+',"yes")',200)
      return '<span id="tooltip_preloader">Lade Bild..</span>';
   } else {
   	if(loading == 'yes') {
	     	document.getElementById('tooltip_preloader').innerHTML = "<img width=\""+width+"\" height=\""+height+"\" src=\""+image+"\">";
         return;
      }
	   return "<img width=\""+width+"\" height=\""+height+"\" src=\""+image+"\">";
   }
}

function getResizedTooltipThis(image,maxWidth,maxHeight) {
   var copy = new Image();
   copy.src = image.src;
   width    = copy.width;
   height   = copy.height;
   if(width == 0) {
   	width = 300;
	}
   if(maxWidth && width > maxWidth) {
   	width = maxWidth;
   	height = width/copy.width*height;
   }
   if(maxHeight && height > maxHeight && height) {
   	height = maxHeight;
   	width = height/copy.height*copy.width;
   }
   height = height ? "height=\""+height+"\"" : '';
   code = "<img width=\""+width+"\" "+height+" src=\""+image.src+"\">";
   return code;
}

function customTooltip(which,tooltip_name) {
	tooltip = tooltip_name;
   closeable = false;

   which.onmouseout = wantHideTooltip;

	window.clearInterval(updateInterval);
	d = document.getElementById(tooltip);
   d.style.display = "inline";
   centerize(tooltip);
   updateInterval = window.setInterval("centerize('tooltip')",250);
}

function showTooltip(which,content) {
	tooltip = 'tooltip';
   closeable = false;

   which.onmouseout = wantHideTooltip;

	window.clearInterval(updateInterval);
	d = document.getElementById(tooltip);
	d.innerHTML = content;
   d.style.display = "inline";
   centerize(tooltip);
   updateInterval = window.setInterval("centerize('tooltip')",250);
}

function hideTooltip(override) {
	if(closeable || override) {
		// clear intervals
		window.clearInterval(updateInterval);
		window.clearInterval(hideInterval);
   	// hide tooltip
	 	document.getElementById(tooltip).style.display = 'none';
	}
}

function wantHideTooltip() {
	closeable = true;
	hideInterval = window.setInterval("hideTooltip()",200);
}

function clearHideTooltip() {
	closeable = false;
	window.clearInterval(hideInterval);
}

function getScreenshotTooltip(image) {
	return '<img src="'+image+'"><br /><img src="'+layout+'ipopup_click.jpg">';
}

function centerize(field) {
	d = document.getElementById(field);
   if(d) {
		d.style.position = "absolute";
		dWidth = d.offsetWidth;
      dHeight = d.offsetHeight;
      wWidth = getWindowWidth();
      wHeight = getWindowHeight();
      x = (wWidth-dWidth)/2;
      y = (wHeight-dHeight)/2;
      offsetY = getWindowOffsetY();
      offsetX = getWindowOffsetX();
      x += offsetX;
      y += offsetY;
      d.style.left = x + "px";
      d.style.top = y + "px";
   }
}

function getWindowOffsetY() {
   if (self.pageYOffset) {
	   return self.pageYOffset;
   } else if (document.documentElement && document.documentElement.scrollTop) {
   	return document.documentElement.scrollTop;
   } else if (document.body) {
   	return document.body.scrollTop;
   }
}

function getWindowOffsetX() {
   if (self.pagecOffset) {
	   return self.pageXOffset;
   } else if (document.documentElement && document.documentElement.scrollLeft) {
   	return document.documentElement.scrollLeft;
   } else if (document.body) {
   	return document.body.scrollLeft;
   }
}

function getWindowWidth() {
   if (self.innerWidth) {
      return self.innerWidth;
   } else if (document.documentElement && document.documentElement.clientHeight) {
      return document.documentElement.clientWidth;
   } else if (document.body) {
      return document.body.clientWidth;
   }
}

function getWindowHeight() {
   if (self.innerHeight) {
      return self.innerHeight;
   } else if (document.documentElement && document.documentElement.clientHeight) {
      return document.documentElement.clientHeight;
   } else if (document.body) {
      return document.body.clientHeight;
   }
}

function swapShowHide(_element,_changer) {
	element = document.getElementById(_element);
   if(element.style.display == "none") {
   	element.style.display = "block";
      if(_changer) {
      	_changer.firstChild.src = layout + "arrow_left.gif";
      }
   } else {

   	element.style.display = "none";
      if(_changer) {
      	_changer.firstChild.src = layout + "arrow_down.gif";
      }
   }
}

/************ AJAX.JS */

function AjaxRequest(func,page,mode,data) {
	var xmlHttp;
   if(typeof(XMLHttpRequest) != 'undefined') {
      xmlHttp = new XMLHttpRequest();
   }
   if (!xmlHttp) {
      try {
         xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
      } catch(e) {
         try {
            xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
         } catch(e) {
            xmlHttp  = false;
         }
      }
   }
   if(xmlHttp) {
   	xmlHttp.onreadystatechange = function() {
         if(xmlHttp.readyState == 4 && func) {
           	func(xmlHttp.responseText,xmlHttp.responseXML);
         }
      }
		xmlHttp.open(mode,page, true);
      xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      if(mode == 'POST') {
      	xmlHttp.send(data);
      } else {
      	xmlHttp.send('');
      }
   }
   return true;
}

var states = new Array();
var i = 0;

function hideSelects() {
	selects = document.getElementsByTagName("select");
   for(i = 0; i < selects.length;i++) {
		selects[i].style.visibility = "hidden";
   }
}

function showSelects() {
	selects = document.getElementsByTagName("select");
   for(i = 0; i < selects.length;i++) {
		selects[i].style.visibility = "visible";
   }
}

function showTransBackground() {
	offsetY = getWindowOffsetY();
  	transLayer = document.getElementById('trans_layer');
   transLayer.style.top = offsetY + "px";
 	transLayer.style.display = 'block';
}

function hideTransBackground() {
  	transLayer = document.getElementById('trans_layer');
 	transLayer.style.display = 'none';
}

/************ AJAX_CONTENT.JS */

/* Tested for: Input-Text Input-Checkbox */
function form2param(_form) {
	query = "";
	formElement = document.getElementById(_form);
   formElements = formElement.elements.length;
   for(i = 0;i < formElements;i++) {
      add = true;
      if(formElement.elements[i].type == "checkbox" && !formElement.elements[i].checked) {
      	add = false;
      }
      if(add) {
			query += formElement.elements[i].name + "=" + escape(formElement.elements[i].value) + "&";
      }
	}
   return query;
}


// AD-System

function loadAdHomeBanner(_campaign) {
	if(document.getElementById('banner_home_start')) {
		AjaxRequest(loadAdHomeBannerParse,dir +  'dynamic/ad/banner/homebanner/'+_campaign+'/?system=' + adSystem+'&systems='+__adSystems,'GET');
}

}
function loadAdHomeBannerParse(html,xml) {
	if(html.length > 0) {
		document.getElementById('banner_home_start').innerHTML = html;
		document.getElementById('banner_home_start').style.display = 'block';
         }

}

adSystem = 0;
adCampaign = null;
function clickAd(_banner) {
	AjaxRequest(null,dir +  'dynamic/ad/click/'+_banner+'/','GET');
}
function initAds(_system) {
	adSystem = _system;
	loadAds();
}
function loadAds() {
	AjaxRequest(parseLoadAds,dir +  'dynamic/ad/init/?system=' + adSystem + '&systems='+__adSystems,'GET');
}
function parseLoadAds(html,xml) {
  //	document.getElementById('debug').innerHTML = html;
	adCampaign = html;
	loadAdSkyscraper(html);
	loadAdFullbanner(html);
	loadAdTopBanner(html);
	loadBackgroundBanner(html);
	loadAdHomeBanner(html);
    loadInlineBanner(html);
	window.setTimeout('loadAds()',60000);
}

function loadInlineBanner(_campaign) {
	var element = $('ad_inline_container');
   if(element) {

		AjaxRequest(parseLoadInlineBanner,dir +  'dynamic/ad/banner/inline/'+_campaign+'/?type=' + element.innerHTML + '&system=' + adSystem+'&systems='+__adSystems,'GET');
   }
}
function parseLoadInlineBanner(html,xml) {
	if(html) {
	   var innerHTML = '<div style="text-align:left;padding:0px 0px 5px 10px;"><img style="display:block" src="'+layout+'headline_small_ad.png">'+html+'</div>';
	   $('ad_inline_container').innerHTML = innerHTML;
	   $('ad_inline_container').show();
   }
}

function loadAdSkyscraper(_campaign) {
//	document.getElementById('debug_skyscraper').innerHTML = dir +  'dynamic/ad/banner/skyscraper/'+_campaign+'/';
	AjaxRequest(parseLoadAdSkyscraper,dir +  'dynamic/ad/banner/skyscraper/'+_campaign+'/?system=' + adSystem+'&systems='+__adSystems,'GET');
}
function parseLoadAdSkyscraper(html,xml) {
	document.getElementById('adbanner_skyscraper').innerHTML = html;
}

function loadBackgroundBanner(_campaign) {
	AjaxRequest(parseLoadBackgroundBanner,dir +  'dynamic/ad/banner/background/'+_campaign+'/?system=' + adSystem+'&systems='+__adSystems,'GET');
}
function parseLoadBackgroundBanner(html,xml) {
	var id = html;
	if(id > 0) {
	   	$('ad_background_left').style.width = '250px';
	   	$('ad_background_right').style.width = '250px';
	   	$('body_size').style.width = '1500px';
	   	$('ad_background_right').show();
	   	$('ad_background_left').show();
		AjaxRequest(parseLoadBackgroundBannerLeft,dir +  'dynamic/ad/ibanner/'+html+'/?side=left&pre=1','GET');
		AjaxRequest(parseLoadBackgroundBannerRight,dir +  'dynamic/ad/ibanner/'+html+'/?side=right&pre=1','GET');
	}
}
function parseLoadBackgroundBannerLeft(html,xml) {
	document.getElementById('ad_background_left').innerHTML = html;
}
function parseLoadBackgroundBannerRight(html,xml) {
	document.getElementById('ad_background_right').innerHTML = html;
}



function loadAdGalleryPopup() {
   AjaxRequest(loadLoadAdGalleryPopup,dir +  'dynamic/ad/banner/gallery/'+adCampaign+'/?system=' + adSystem+'&systems='+__adSystems,'GET');
}
function loadLoadAdGalleryPopup(html,xml) {
	if(html.length > 0) {
   	document.getElementById('popup_gallery_screenshot').style.display = 'none';
   	document.getElementById('popup_gallery_ad').style.display = 'block';
	   document.getElementById('adbanner_gallery_popup').innerHTML = html;
   } else  {
   	popupGalleryHideAd();
   }
}

function loadAdGallery() {
	if(adCampaign == null) {
   	window.setTimeout('loadAdGallery()',500);
   } else {
		AjaxRequest(parseLoadAdGallery,dir +  'dynamic/ad/banner/gallery/'+adCampaign+'/?system=' + adSystem+'&systems='+__adSystems,'GET');
   }
}
function parseLoadAdGallery(html,xml) {
	document.getElementById('adbanner_gallery').innerHTML = html;
}


function loadAdFullbanner(_campaign) {
	AjaxRequest(parseLoadAdFullbanner,dir +  'dynamic/ad/banner/fullbanner/'+_campaign+'/?system=' + adSystem+'&systems='+__adSystems,'GET');
}
function parseLoadAdFullbanner(html,xml) {
	if(html.length > 0) {
		document.getElementById(adElement).style.backgroundImage = "url('" + layout + adElement + '.jpg' + "')";
		document.getElementById('adbanner_fullbanner').innerHTML = html;
   }
}

function loadAdTopBanner(_campaign) {
//	document.getElementById('debug_topbanner').innerHTML = dir +  'dynamic/ad/banner/topbanner/'+_campaign+'/';
	AjaxRequest(parseLoadAdTopBanner,dir +  'dynamic/ad/banner/topbanner/'+_campaign+'/?system=' + adSystem+'&systems='+__adSystems,'GET');
}
function parseLoadAdTopBanner(html,xml) {
	if(html.length > 0) {
   	document.getElementById('adbanner_topbanner').style.display = 'block';
		document.getElementById('adbanner_topbanner').innerHTML = html;
   } else {
   }
}

/************ BBCODE.JS */

function selectColor(field,into) {
	if(field.value != 0) {
   	insertText('[color=#'+field.value+']','[/color]',into);
      field.value = 0;
   }
}

  var bbcode = new Array("","[b]","[/b]","[i]","[/i]","[u]","[/u]","[left]","[/left]",
                         "[center]","[/center]","[right]","[/right]","[link=http://]","[/link]",
                         "[email]","[/email]","[img=","]","[irc=#","]","[quote]","[/quote]");

  var clientPC = navigator.userAgent.toLowerCase();
  var clientVer = parseInt(navigator.appVersion);

  var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
  var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
                && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
  var is_moz = 0;

  var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
  var is_mac = (clientPC.indexOf("mac")!=-1);

  switch_minus = new Image();
  switch_minus.src = layout + "minus.jpg";

  switch_plus = new Image();
  switch_plus.src = layout + "plus.jpg";

  function switch_status(field,link)
   {
     if (document.getElementById(field).style.display == 'none')
      {
        document.getElementById(field).style.display = "";
        document.getElementById(link).src = switch_minus.src;
      }
     else
      {
        document.getElementById(field).style.display = "none";
        document.getElementById(link).src = switch_plus.src;
      }
   }

function mozWrap(txtarea, open, close) {
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2)
		selEnd = selLength;

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
   return;
}

function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

function insertText(before,after,field) {
	var txtarea = document.getElementById(field);
   var theSelection = false;

	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text; // Get text selection
		if(theSelection) {
			document.selection.createRange().text = before+theSelection+after;
			txtarea.focus();
			return;
		} else {
		  txtarea.value = txtarea.value + before + after;
		  txtarea.focus();
			return;
		}
	} else {
		if(txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0)) {
			mozWrap(txtarea, before, after);
			return;
		} else {
			txtarea.value = txtarea.value + before + after;
			txtarea.focus();
			return;
		}
	}
	storeCaret(txtarea);
}

function addbbcode(codenr,field) {

	before = bbcode[codenr];
   after  = bbcode[codenr*1+1];

   insertText(before,after,field);
}

  function addQuote(qtext)
   {
    var quote = document.getElementById(qtext).innerHTML;
    document.getElementById('text').value += '[quote]' + quote + '[/quote]';
    document.getElementById('text').focus();
   }

  function Popup(path,name,width,height,scrolling,resizable)
   {
     window.open(path,name,"width="+width+",height="+height+",scrollbars="+scrolling+",resizable="+resizable);
   }

  function addcolor(color,feld)
   {
     if(color)
      {
        var old = document.getElementById(feld).value;
        var neu = old+"[color="+color+"][/color]";
        document.getElementById(feld).value = neu;
      }
   }

  function addsize(size,feld)
   {
     if(size)
      {
        var old = document.getElementById(feld).value;
        var neu = old+"[size="+size+"][/size]";
        document.getElementById(feld).value = neu;
      }
   }

  function addfont(font,feld)
   {
     if(font)
      {
        var old = document.getElementById(feld).value;
        var neu = old+"[font="+font+"][/font]";
        document.getElementById(feld).value = neu;
      }
   }

  function addtext(feld,text)
   {
     var old = document.getElementById(feld).value;
     var neu = old+text;
     document.getElementById(feld).value = neu;
   }

/************ CHAT.JS */

/* CHAT FUNCTIONS */

var chatSexData = new Array();
chatSexData['m'] = 'm&auml;nnlich';
chatSexData['w'] = 'weiblich';

var chatBox = false;
var chatBoxID = false;
var chatChannel = 1;
var chatMessageQueue = new Array();
var chatActive = false;
var chatUser = false;
var chatBig = false;
var chatIter = 1;
var chatSpeed = 500;
var chatMinimized = false;
var chatJoinSilent = false;

function chatSound(name){
	output = '<embed src="'+layout+'chat_'+name+'.wav" width="20" height="0" autostart="true" loop="false">';
	document.getElementById('chat_sound').innerHTML = output;
}

function initMinimizedChats() {
	chatJoinSilent = true;
   chatMinimized = true;
   initPopupChat();
   document.getElementById('chat_indicator').style.display = 'block';
}

function minimizeChat() {
	popupCloseFunction = null;
   popupReload = false;
   closePopupBackground();
   popupReload = true;
   chatMinimized = true;
   document.getElementById('chat_indicator').style.display = 'block';
   AjaxRequest(false,dir + 'community/chat/?s=chat&m=minimize&chat='+chatChannel,'GET',false);
//   popupContentElement.style.display = "block";
//   popupContentElement.innerHTML = "test";

}

function initPopupChat(field,box,_chatUser) {
	popupCloseFunction = closeBigChat;
   if(chatMinimized) {
   	if(chatJoinSilent) {
      	popupContentElement = document.getElementById('popup_content');
			AjaxRequest(parseInitPopupChat,dir + 'community/chat_big/','GET',false);
      } else {
		   document.getElementById('chat_indicator').style.display = 'none';
		   chatMinimized = false;
	      AjaxRequest(false,dir + 'community/chat/?s=chat&m=maximize&chat='+chatChannel,'GET',false);
	      popupReload = false;
	      showPopupBackground();
	      popupReload = true;
      }
   } else {
		showPopupBackground();
	   AjaxRequest(parseInitPopupChat,dir + 'community/chat_big/','GET',false);
   }

}
function parseInitPopupChat(html,xml) {
	popupContentElement.innerHTML = html;
   centerize('popup_content');
   if(window.correctPNG) {
  	   correctPNG();
   }
	chatBoxID = "list_slider_chat2"
   chatBox = document.getElementById(chatBoxID);
//   chatBox.innerHTML = 'Lade Chat..';
   chatUser   = true;
   chatBig    = true;
 	chatActive = true;
   sendJoin();
}

function initChat(field,box,_chatUser) {
	chatUser = _chatUser;
	if(!chatActive) {
	  	chatActive = true;
	 	//field.value = 'Chat verlassen';
		chatBox = document.getElementById(box);
      chatBoxID = box;
      chatBox.innerHTML = 'Lade Chat..';
      chatBig = false;
	   sendJoin();
   } else {
   	chatActive = false;
  	//	field.value = 'Chat beitreten';
      sendPart();
      resetChatUser();
   }
}

function closeBigChat() {
	chatBox = document.getElementById("chat_frame");
	chatBoxID = "chat_frame";
   chatBig = false;
 	chatActive = true;
   chatUser   = false;
//   getMessages();
   sendPart();
}

function sendJoin() {
	if(chatJoinSilent) {
	   chatJoinSilent = false;
		AjaxRequest(parseSendJoin,dir + 'community/chat/?s=chat&m=join_silent&chat='+chatChannel,'GET',false);
   } else {
		AjaxRequest(parseSendJoin,dir + 'community/chat/?s=chat&m=join&chat='+chatChannel,'GET',false);
   }
}
function parseSendJoin(html,xml) {
   if(html == "OK") {
   	window.setTimeout('getMessages()',500);
      getChatUser();
   }
}

function sendPart() {
	AjaxRequest(parsePartJoin,dir + 'community/chat/?s=chat&m=part&chat='+chatChannel,'GET',false);
}

function parsePartJoin(html,xml) {
	return;
}

function addChatUser(nick,id,sex,pic) {
	// list
  	d = document.getElementById(chatBoxID + "_user");

   // create entry
	div = document.createElement('div');
	div.setAttribute('id','chat_user_' + id);

   pic = (pic > 0 ? dir + 'static/images/user/'+id+'.jpg' : dir + 'static/images/layout/user_small_pic.jpg' );

	addText  = '<div class="chat_user"><img style="float:left;margin-right:6px;" src="'+dir+'dynamic/user/'+id+'/chat/"">';
	addText += '<span style="font-weight:bold;font-size:11px;color:white">'+nick+'</span><br />';
	addText += '<img class="chat_user_sex" src="'+layout+'icon_'+sex+'.gif"> <span style="color:#878787">'+chatSexData[sex]+'</span><br /><br />';
	addText += '<a target="_blank" href="'+dir+'profile/'+id+'/"><img src="'+layout+'button_red_visit_profile.jpg"></a><br clear:left/></div>';
   div.innerHTML = addText;

   // search position
   if(d.hasChildNodes()) {

   	element = d.firstChild;
      do {
         _id = element.getAttribute('id');
         if("chat_user_" + id == _id) {
            return;
         } else if(_id < id) {
            d.insertBefore(div,element);
            return;
         }
      } while(element = element.nextSibling);
      d.appendChild(div);
   } else {
   	d.appendChild(div);
   }
   return;
}
function removeChatUser(nick,id,sex,pic) {
	// list
  	d = document.getElementById(chatBoxID + "_user");
   // search position
   if(d.hasChildNodes()) {
   	element = d.firstChild;
      do {
         _id = element.getAttribute("id");
         if(_id == "chat_user_" + id) {
            d.removeChild(element);
            return;
         }
      } while(element = element.nextSibling);
   }
   return;
}
function resetChatUser() {
  	d = document.getElementById(chatBoxID + "_user");
   d.innerHTML = "";
}
function getChatUser() {
	if(chatUser) {
		AjaxRequest(parseGetChatUser,dir + 'community/chat/?s=chat&m=list&chat='+chatChannel,'GET',false);
   }
}
function parseGetChatUser(html,xml) {

   list = xml.getElementsByTagName('users').item(0);

   for(i = 0; i < list.childNodes.length;i++) {
   	d = document.getElementById(chatBoxID + "_user");
   	nick = list.childNodes[i].getAttribute('nick');
   	sex = list.childNodes[i].getAttribute('sex');
   	pic = list.childNodes[i].getAttribute('pic');
   	id = list.childNodes[i].getAttribute('id');
		addChatUser(nick,id,sex,pic);
   }
}


function chatMessage(field) {
	chatMsgInput = document.getElementById(field);
   text = escape(chatMsgInput.value);

   chatMsgInput.value = '';
   chatMsgInput.focus();
   if(chatActive) {
		AjaxRequest(parseChatMessage,dir + 'community/chat/?s=chat&m=message&chat='+chatChannel,'POST','message='+text);
	}
  return;
}
function parseChatMessage(html,xml) {
	return;
}

function getMessages() {
	if(chatActive) {
		AjaxRequest(parseGetMessages,dir + 'community/chat/?s=chat&m=get_messages&chat='+chatChannel,'GET');
   }
}
function parseGetMessages(html,xml) {
   list = xml.getElementsByTagName('messages').item(0);

   if(chatMinimized && list.childNodes.length > 0) {
	   chatSound('new');
   }

   for(i = 0; i < list.childNodes.length;i++) {

   	type = list.childNodes[i].getAttribute('type');
   	id = list.childNodes[i].getAttribute('id');
   	nick = list.childNodes[i].getAttribute('nick');
   	sex = list.childNodes[i].getAttribute('sex');
   	pic = list.childNodes[i].getAttribute('pic');
   	timer = list.childNodes[i].getAttribute('timer');
      msg = list.childNodes[i].firstChild.data;

      sex_text = (sex == 'w' ? 'female' : 'male');

      newMsg = "";

      chatIter++;
      swap = (chatIter % 2 ? '_swap' : '')

      if(type == 'msg') {
         if(chatBig) {

newMsg = '<div class="chat_line">';
newMsg += '<div class="chat_line_time">'+timer+'</div>';
newMsg += '<div class="chat_line_nick"><a class="'+sex_text+'" target="_blank" href="'+dir+'profile/'+id+'/"><b>'+nick+':</b></a></div>';
if(msg.length > 100) {
	newMsg += '<br style="clear:both"/>';
}
newMsg += '<div class="chat_line_text">'+unescape(msg)+'</div>';
newMsg += '</div>';

//   	   	newMsg  = '<div class="chat_line"><div class="chat_line_nick"><a class="'+sex_text+'" target="_blank" href="'+dir+'profile/'+id+'/"><b>'+nick+'</b></a></div>'
//	         newMsg += '<div class="chat_line_text'+swap+'">'+unescape(msg)+'</div><br style="clear:both"/></div>';
         } else {
         	newMsg = '<div style="float:right">'+timer+'</div><div><a target="_blank" class="red" href="'+dir+'profile/'+id+'/">'+nick+'</a> schreibt:<br />'+unescape(msg)+'<br /></div>';
         }
      } else if(type == 'join') {
      	if(chatBig) {
   	   	newMsg  = '<div class="chat_line"><div class="chat_line_nick"><a class="'+sex_text+'" target="_blank" href="'+dir+'profile/'+id+'/"><b>'+nick+'</b></a></div>'
            newMsg += '<div class="chat_line_time">'+timer+'</div>';
	         newMsg += '<div class="chat_line_text">hat den Chat betreten.</div></div>';
         } else {
         	newMsg = '<div><a target="_blank" class="red" href="'+dir+'profile/'+id+'/">'+nick+'</a> hat den Chat betreten.</div>';
         }
         if(chatUser) {
         	addChatUser(nick,id,sex,pic);
         }
      } else if(type== 'part') {
      	if(chatBig) {
	      	newMsg  = '<div class="chat_line"><div class="chat_line_nick"><a class="'+sex_text+'" target="_blank" href="'+dir+'profile/'+id+'/"><b>'+nick+'</b></a></div>';
            newMsg += '<div class="chat_line_time">'+timer+'</div>';
   	      newMsg += '<div class="chat_line_text">hat den Chat verlassen.</div><br style="clear:both"/></div>';
         } else {
         	newMsg = '<div><a target="_blank" class="red" href="'+dir+'profile/'+id+'/">'+nick+'</a> hat den Chat verlassen.</div>';
         }

         if(chatUser) {
         	removeChatUser(nick,id,sex,pic);
         }
      } else if(type == 'part_timeout') {
      	if(chatBig) {
   	   	newMsg  = '<div class="chat_line"><div class="chat_line_nick"><a class="'+sex_text+'" target="_blank" href="'+dir+'profile/'+id+'/"><b>'+nick+'</b></a></div>'
				newMsg += '<div class="chat_line_time">'+timer+'</div>';
	         newMsg += '<div class="chat_line_text">hat den Chat verlassen.</div></div>';
         } else {
         	newMsg = '<div><a target="_blank" class="red" href="'+dir+'profile/'+id+'/">'+nick+'</a> hat den Chat verlassen.</div>';
         }

         if(chatUser) {
         	removeChatUser(nick,id,sex,pic);
         }
      }

      chatBox.innerHTML = chatBox.innerHTML + newMsg ;

      if(chatBig){
	      bottomListSlider('list_slider_chat2');
      } else {
	      bottomListSlider('list_slider_chat');
      }


/*	   loadOption = document.createElement("option");
      loadOption.setAttribute('value',list.childNodes[i].getAttribute('id'));
   	loadOptionText = document.createTextNode(list.childNodes[i].getAttribute('name'));
	   loadOption.appendChild(loadOptionText);
      d.appendChild(loadOption);*/

   }

   window.setTimeout('getMessages()',chatSpeed);
}

function outputMessage() {

}

/************ ESPORT_CHART.JS */

function openChartAdmin(_chart) {
   showTransBackground();
   hideSelects();
	AjaxRequest(openChartAdminParse,dir + 'esport/chart/'+_chart+'/admin/','GET',false);
}

function openChart(_chart) {
	showPopupBackground();
   AjaxRequest(openChartParse,dir + 'esport/chart/'+_chart+'/','GET');
}

function openChartParse(html,xml) {
	popupContentElement.innerHTML = html;
   centerize('popup_content');
   if(window.correctPNG) {
  	   correctPNG();
   }
}

function openChartAdminParse(html,xml) {
	document.getElementById('trans_content').innerHTML = html;
	document.getElementById('trans_content').style.display = "";
   centerize('trans_content');
}

/************ ESPORT_CHART.JS */

var tickerElement = null;
var tickerMoving = false;
var tickerRate = 50;
var tickerMax = 0;
var tickerWidth = 0;
var tickerSpace = 2;

function initTicker(_element) {
 	tickerElement = document.getElementById(_element);
   tickerMax     = tickerElement.offsetWidth;
   tickerWidth   = tickerElement.parentNode.parentNode.offsetWidth;
   tickerElement.parentNode.style.left = tickerWidth + "px";
   startTicker();
}

function startTicker() {
	tickerMoving = 'right';
	window.setTimeout("moveTicker('"+tickerMoving+"')",tickerRate);
}

function stopTicker() {
	tickerMoving = false;
}

function moveTicker() {

	direction = 'right';

	if(tickerMoving == direction) {

      var left = tickerElement.parentNode.style.left;
		left = left.substring(0,left.length-2)*1;

		left -= tickerSpace;

      if(left < -1*tickerMax) {
      	left = tickerWidth;
      }

		tickerElement.parentNode.style.left = left + "px";
		window.setTimeout("moveTicker('"+direction+"')",tickerRate);
	}
}