///////////////////////////////////////////////////////////////////////
// Globale Variablen

// Browsercheck
// OS
isMac  = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
isPC   = (navigator.appVersion.indexOf("Windows")!=-1) ? true : false;
isUnix = (navigator.appVersion.indexOf("Unix")!=-1) ? true : false;

// Browser
var ie4=document.all
var ie5=document.getElementById&&document.all
var ie6=document.getElementById&&document.all&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)
var ie7=document.getElementById&&document.all&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)
var ns4=document.layers
var ns6=document.getElementById&&!document.all
var ff3=document.getElementById&&!document.all

// Tools
function check4Att(id,attr){
	var element = $(id) ? $(id) : id;
  return !!element.getAttribute(attr);
}

///////////////////////////////////////////////////////////////////////
// Keyboard-Tracking
document.onkeyup = function (e) {
	if(!e){
		e=window.event;
	}
	el=e.target?e.target:e.srcElement;
	if (el.tagName == "INPUT"){
		if (el.type == "text" && el.id == "getAffiliateDataInput"){
		
    	if(e.keyCode == 13){
				searchEntries(el.id, el.name);
			}
		
    }else if(el.type == "text" && el.id == "topMenueSearchInput"){
			
      if (e.keyCode == 13){
					sendSearch($('topMenueSearchInput').value);
			} else if($('topMenueSearchInput').value.length <= 1){
				$('searchQueryPopup').style.display = 'none';
			}
			
		}else if (el.type == "password" && el.id == "login_password"){
		
    	if(e.keyCode == 13){
			  document.loginForm.submit(); 
			}
		
    }
	}
}; 


///////////////////////////////////////////////////////////////////////
// Mouse-Tracking
document.onclick = function (e) {
	if(!e){
		e=window.event;
	}
	el=e.target?e.target:e.srcElement;
	
	// checken ob ein Parent Element ein Popup ist
  var found=false;
  var end = false;
  var temp = el;
  
  while (end==false){
    if ((temp.parentNode.id)){
      temp = temp.parentNode;
    } else {
      end = true;
    }
    if (temp.getAttribute('isPopup')=='yes' || temp.getAttribute('ispopup') == 'yes' ){
      found = true;
      end = true;
    } 
  }
  if (!el.getAttribute('isFunction')&&!el.getAttribute('isfunction')&&el.className!='fragezeichen'&&!temp.getAttribute('isPopup')&&!temp.getAttribute('ispopup')){
	 closePopups();
	}
}



var x = 0; 
var y = 0; 
var mouseX = 0; // Horizontal position of the mouse on the screen
var mouseY = 0; // Vertical position of the mouse on the screen
var screenX = 0; // Width of the page
var screenY = 0; // Height of the page
var topLeftX = 0;
var topLeftY = 0;

function captureMousePosition(e) {
  if (document.layers) {
      mouseX = e.pageX;
      mouseY = e.pageY;
      screenX = window.innerWidth+window.pageXOffset;
      screenY = window.innerHeight+window.pageYOffset;
  		topLeftX = window.pageXOffset;
  		topLeftY = window.pageYOffset;
  } else if (document.all) {
      mouseX = event.clientX+document.documentElement.scrollLeft;
      mouseY = event.clientY+document.documentElement.scrollTop;
  		topLeftX = document.body.scrollLeft;
  		topLeftY = document.body.scrollTop;
      screenX = document.body.clientWidth+document.body.scrollLeft;
      screenY = document.body.clientHeight+document.body.scrollTop;
  } else if (document.getElementById) {
      mouseX = e.pageX;
      mouseY = e.pageY;
      screenX = window.innerWidth+window.pageXOffset;
      screenY = window.innerHeight+window.pageYOffset;
  		topLeftX = window.pageXOffset;
  		topLeftY = window.pageYOffset;
  }
}



///////////////////////////////////////////////////////////////////////
// login

function login(){
	var url = AJAX_DIR + 'login.php';
	
  var pars = 	"action=login&email=" + $('login_email').value;
  pars += "&password=" + MD5($('login_password').value);
	
	
	if ($('persistentCheckbox').className == 'loginCheckboxSelected') {
		pars = pars + "&persistent=1";
	} else {
		pars = pars + "&persistent=0";
  }
	
	$('loginStatus').innerHTML = LOADING_GIF_CENTER;	
	
	new Ajax.Updater('loginStatus',url,{
		method: 'post',
		parameters: pars,
		onComplete: function() {
       if(  $('login_status').getAttribute('status')=='confirm' ){
			  if ( ($('goto').value!="") &&  ($('goto').value!="/")){
          window.location.href = $('goto').value;
        } else {
  			  window.location.href = '/start/'+MD5(Math.random());	      
          //window.location.reload();					
        }
       }
		}
	});
}

function toggleLoginCheckbox(){
	if ($('persistentCheckbox').className == 'loginCheckbox') {
    $('persistentCheckbox').className = 'loginCheckboxSelected';
  } else {
    $('persistentCheckbox').className = 'loginCheckbox';
  }
}

function logOut(){
	url = AJAX_DIR + 'login.php';
	pars = 	"action=logout";
	$('loginStatus').style.display = 'block';
	$('loginStatus').innerHTML = LOADING_GIF_CENTER;	
	new Ajax.Updater('loginStatus',url,{
		method: 'post',
		parameters: pars,
		onComplete: 
			function() {
  			window.location.href = '/logout/'+MD5(Math.random());	      
			}
	});
}

function toggleUserStatus(){
  var url=AJAX_DIR + "viewsettingsRightSidebar.php";
  var pars = 'action=toggleUserStatus';
  
  if ($('rightUserStatus').style.display != 'none'){
    $('rightUserStatus').style.display = 'none';
    $('sidebarCollapse').className = 'sidebarRightUserBoxHeaderExpand';
    pars += "&mode=0";
  } else {
    $('rightUserStatus').style.display = 'block';
    $('sidebarCollapse').className = 'sidebarRightUserBoxHeaderCollapse';
    pars += "&mode=1";
  }
	new Ajax.Request( url, 
	{
		method:'post', parameters: pars,
    onComplete: function(transport){
    } 
	});
}

///////////////////////////////////////////////////////////////////////
// Ablagen/Funktionen-Dropdown

function toggleAblegenDropdown(){
  if ($('ablegenDropdown').style.display == 'block'){
    closeTopMenu();
    $('ablegenDropdown').style.display = 'none';
    $('topAblegenLink').className = 'selectionMenueFunctionHeader';
  } else {
    closeTopMenu();
    $('ablegenDropdown').style.display = 'block';  
    $('topAblegenLink').className = 'selectionMenueFunctionHeaderActive';
  }
}

function toggleFunktionenDropdown(){
  if ($('funktionenDropdown').style.display == 'block'){
    closeTopMenu();
    $('funktionenDropdown').style.display = 'none';  
    $('topFunktionenLink').className = 'selectionMenueFunctionHeader';
  } else {
    closeTopMenu();
    $('funktionenDropdown').style.display = 'block';  
    $('topFunktionenLink').className = 'selectionMenueFunctionHeaderActive';
  }
}

function toggleResortDropdown(){
  if ($('resortDropdown').style.display == 'block'){
    closeTopMenu();
    $('resortDropdown').style.display = 'none';  
    $('topResortLink').className = 'selectionMenueFunctionHeader';
  } else {
    closeTopMenu();
    $('resortDropdown').style.display = 'block';  
    $('topResortLink').className = 'selectionMenueFunctionHeaderActive';
  }
}

function toggleStatusDropdown(){
  if ($('statusDropdown').style.display == 'block'){
    closeTopMenu();
    $('statusDropdown').style.display = 'none';  
    $('topStatusLink').className = 'selectionMenueFunctionHeader';
  } else {
    closeTopMenu();
    $('statusDropdown').style.display = 'block';  
    $('topStatusLink').className = 'selectionMenueFunctionHeaderActive';
  }
}

function closeTopMenu(){
  if ($('ablegenDropdown')){
    $('ablegenDropdown').style.display = 'none';  
    $('topAblegenLink').className ='selectionMenueFunctionHeader'; 
  } 
  if ($('funktionenDropdown')){
    $('funktionenDropdown').style.display = 'none';  
    $('topFunktionenLink').className ='selectionMenueFunctionHeader'; 
  } 
  if ($('statusDropdown')){
    $('statusDropdown').style.display = 'none';  
    $('topStatusLink').className ='selectionMenueFunctionHeader'; 
  } 
  if ($('resortDropdown')){
    $('resortDropdown').style.display = 'none';  
    $('topResortLink').className ='selectionMenueFunctionHeader'; 
  } 
}

///////////////////////////////////////////////////////////////////////
// Aktivität

var confirmMessageDiv = document.createElement('div');
confirmMessageDiv.id = 'confirmMessageDiv';

var confirmMessageText = document.createElement('div');
confirmMessageText.id = 'confirmMessageText';

var actionMessageWait = 3000;
var actionMessageRemain = 3000;
var actionMessageSpeed = 6;
var actionMessageTextStep = 0.002;
var actionMessageDivStep = 0.0017;

var actionMessageTextInitialTransp = 0.99;
var actionMessageTextCurrentTransp = 0.99;
var actionMessageDivInitialTransp = 0.7;
var actionMessageDivCurrentTransp = 0.7;

function setConfirmMessage(text){
 if (!document.getElementById('confirmMessageDiv')) {
  document.body.appendChild(confirmMessageDiv);
  document.body.appendChild(confirmMessageText);
 }
 $('confirmMessageText').innerHTML = text;
 $('confirmMessageDiv').innerHTML = text;
}
	
function showConfirmMessage(){
 if (!document.getElementById('confirmMessageDiv')) {
  document.body.appendChild(confirmMessageDiv);
  document.body.appendChild(confirmMessageText);
 }

 confirmMessageDiv.className = 'confirmMessageDiv';
 confirmMessageText.className = 'confirmMessageText';
 
 $('confirmMessageDiv').innerHTML = $('confirmMessageText').innerHTML;

  if (document.layers) {
      scrollY = window.pageYOffset;
  } else if (document.all) {
      var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
      scrollY = iebody.scrollTop;
  } else if (document.getElementById) {
      scrollY = window.pageYOffset;
  }  

  if (scrollY<55) scrollY = 50;  
  y = scrollY + 5;
  
  $('confirmMessageDiv').style.top = y + 'px';    
  $('confirmMessageDiv').style.opacity = actionMessageDivInitialTransp;
	$('confirmMessageDiv').style.filter = 'alpha(opacity='+actionMessageDivInitialTransp*100+')';

  $('confirmMessageText').style.top = y + 'px';    
  $('confirmMessageText').style.opacity = actionMessageTextInitialTransp;
	$('confirmMessageText').style.filter = 'alpha(opacity='+actionMessageTextInitialTransp*100+')';

  actionMessageDivCurrentTransp = actionMessageDivInitialTransp;
	actionMessageTextCurrentTransp = actionMessageTextInitialTransp;
  actionMessageRemain = actionMessageWait;
  fadeActionMessage();
}

function fadeActionMessage(){
  // Checken ob wartezeit schon abgelaufen ist
  if (actionMessageRemain>0){
    actionMessageRemain -= actionMessageSpeed;
    setTimeout("fadeActionMessage()", actionMessageSpeed);
  } else {
    // Transparenz setzen  
    if (actionMessageDivCurrentTransp>0){
      $('confirmMessageDiv').style.opacity = actionMessageDivCurrentTransp;
  	  $('confirmMessageDiv').style.filter = 'alpha(opacity='+actionMessageDivCurrentTransp*100+')';
    }
    if (actionMessageTextCurrentTransp>0){
      $('confirmMessageText').style.opacity = actionMessageTextCurrentTransp;
  	  $('confirmMessageText').style.filter = 'alpha(opacity='+actionMessageTextCurrentTransp*100+')';
    }
    actionMessageDivCurrentTransp -= actionMessageDivStep;
    actionMessageTextCurrentTransp -= actionMessageTextStep;
    
    if ((actionMessageTextCurrentTransp>0)||(actionMessageDivCurrentTransp>0)){
      setTimeout("fadeActionMessage()", actionMessageSpeed);
    } else {
     	if ($('confirmMessageDiv')) document.body.removeChild(confirmMessageDiv);
     	if ($('confirmMessageText')) document.body.removeChild(confirmMessageText);
    }
  }  

}

function findPos(obj) {
	var curleft = curtop = 0;
  if (obj.offsetParent) {
      do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
      } while (obj = obj.offsetParent);
  }
  return [curleft,curtop];
}

function insertLoadingGif(id,fade,xoffset,yoffset,index,showImg){
  var fadeDiv = document.createElement('div');
  var loadingGif = document.createElement('img');
  
  showImg = (showImg)? showImg: 'yes';
  index = (index)? index: 1;
  xoffset = (xoffset)? xoffset: 0;
  yoffset = (yoffset)? yoffset: 0;

  var divPos = findPos($(id));
  
  fadeDiv.style.position = 'absolute';
  fadeDiv.style.zIndex = 200;
  fadeDiv.style.width = $(id).scrollWidth + 'px';
  fadeDiv.style.height = $(id).scrollHeight + 'px';
  fadeDiv.style.top = '0px';
  fadeDiv.style.left = '0px';
  fadeDiv.style.marginLeft = divPos[0] + 'px';
  fadeDiv.style.marginTop = divPos[1] + 'px';
  fadeDiv.style.position = 'absolute';
  fadeDiv.style.background = '#FFF';
  fadeDiv.id = 'fadeDiv' + index;
	fadeDiv.innerHTML = '';
	if (fade==true){
    fadeDiv.style.opacity = '0.5';
	  fadeDiv.style.filter = 'alpha(opacity=50)';	
  } else {
  	fadeDiv.style.opacity = 1;
  	fadeDiv.style.filter = 'alpha(opacity=100)';  
  }

  if (document.body.hasChildNodes()){
      first = document.body.firstChild;
      document.body.insertBefore(fadeDiv,first);
  } else {
      document.body.appendChild(fadeDiv);
  }   

  if (showImg=='yes') {
    loadingGif.src = LOADING_GIF;
    loadingGif.id = 'loadingOverlayGif' + index;
    loadingGif.style.zIndex = 300;
    loadingGif.style.position = 'absolute';
    loadingGif.style.top = '0px';
    loadingGif.style.left = '0px';
    var imgMarginLeft = divPos[0] + $(id).scrollWidth/2 - 26 + xoffset + 'px';
    var imgMarginTop = divPos[1] + $(id).scrollHeight/2 - 19 + yoffset + 'px';
    loadingGif.style.marginLeft = imgMarginLeft;
    loadingGif.style.marginTop = imgMarginTop;

    if (document.body.hasChildNodes()){
        first = document.body.firstChild;
        document.body.insertBefore(loadingGif,first);
    } else {
        document.body.appendChild(loadingGif);
    } 
  }
} 

function removeLoading(id,index){
  index = (index)? index: 1;
  document.body.removeChild($('loadingOverlayGif'+index));		 
  document.body.removeChild($('fadeDiv' + index));
}

//////////////////////////////////////////////
// POPUPS

// schliesst alle isPopup='yes' Divs und resettet die Top-Menü Dropdowns
function closePopups(){
  var divs = document.getElementsByTagName('div');
  for(var i = 0; i < divs.length; i++){
  		if(divs[i].getAttribute('isPopup')||divs[i].getAttribute('ispopup')){
  				divs[i].style.display = 'none';
  		}  		  
  } 
  
  var links = document.getElementsByTagName('a');
  for(var i = 0; i < links.length; i++){
    		if (links[i].className=='selectionMenueFunctionHeaderActive'){
        links[i].className='selectionMenueFunctionHeader';
      }
  }
}

//////////////////////////////////////////////////////777
// Popup mit Fade 

var klappboxEditDiv = document.createElement('div');

function centerEditDiv(){
    if (document.layers) {
        scrollY = window.pageYOffset;
        screenY = window.innerHeight;
        screenX= window.innerWidth;
        //alert('a');
    } else if (document.all) {
        var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
        scrollY = iebody.scrollTop;
        screenY = iebody.clientHeight;
        screenX = iebody.clientWidth;
        //alert('b');
    } else if (document.getElementById) {
        scrollY = window.pageYOffset;
        screenY = window.innerHeight;
        screenX = window.innerWidth;
        //alert('c');
    } 
    y = scrollY + (screenY/2) - ($('editDivWrapper').getHeight()/2);
    x = (screenX/2) - ($('editDivWrapper').getWidth()/2);
  	klappboxEditDiv.style.top = y + 'px';    
  	klappboxEditDiv.style.left = x + 'px';   
}

function createEditDiv(cssClassName,mode){
  var html = '<table id="popuptable" cellpadding=0 cellspacing=0 bordercollapse=collapse>';
  html += '<tr>';
  html += '<td id="popupcontent"><div id="klappboxEditDiv">'+ LOADING_GIF_CENTER + '</div></td>';
  html += '<td id="popupright" style="overflow:hidden;width:8px;background: url(/img/schattenRight.png);background-repeat:no-repeat;"></td>';
  html += '</tr>';
  html += '<tr>';
  html += '<td id="popupbottom" style="heigth:8px;background: url(/img/schattenBottom.png);background-repeat:no-repeat;">';
  html += '&nbsp;</td>';
  html += '<td id="popupbottomright" style="heigth:8px;background: url(/img/schattenBottomRight.png);background-repeat:no-repeat;">';
  html += '&nbsp;</td>';
  html += '</tr>';
  html += '</table>';
  
  klappboxEditDiv.style.top = '0px';
  klappboxEditDiv.style.left = '0px';
  klappboxEditDiv.style.zIndex = '500';
  klappboxEditDiv.style.width = '';
  klappboxEditDiv.style.height = '';
  klappboxEditDiv.id = 'editDivWrapper';
	klappboxEditDiv.innerHTML = html;
  klappboxEditDiv.style.position = 'absolute';
	klappboxEditDiv.style.opacity = 0;
	klappboxEditDiv.style.filter = 'alpha(opacity=0)';
	document.body.appendChild(klappboxEditDiv);

  $('klappboxEditDiv').innerHTML = '';
  $('klappboxEditDiv').style.top = '0px';
  $('klappboxEditDiv').style.left = '0px';
	$('klappboxEditDiv').className = cssClassName;
	$('klappboxEditDiv').style.position = 'static';
	$('klappboxEditDiv').style.background = '#FFFFFF';
	$('klappboxEditDiv').style.opacity = 1;
	$('klappboxEditDiv').style.filter = 'alpha(opacity=100)';

  if (mode != 'center'){
    x = mouseX - 120;
    y = mouseY - 20;
  	$('editDivWrapper').style.left = x + 'px';
  	$('editDivWrapper').style.top = y + 'px';  
  } 
	
  if (mode == 'center'){
    if (document.layers) {
        scrollY = window.pageYOffset;
        screenY = window.innerHeight;
        screenX= window.innerWidth;
      $('popupright').style.backgroundImage = "url(/img/schattenRight.gif)";
      $('popupbottom').style.backgroundImage = "url(/img/schattenBottom.gif)";
      $('popupbottomright').style.background = "url(/img/schattenBottomRight.gif)";
        //alert('a');
    } else if (document.all) {
        var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
        scrollY = iebody.scrollTop;
        screenY = iebody.clientHeight;
        screenX = iebody.clientWidth;
      $('popupright').style.backgroundImage = "url(/img/schattenRight.gif)";
      $('popupbottom').style.backgroundImage = "url(/img/schattenBottom.gif)";
      $('popupbottomright').style.background = "url(/img/schattenBottomRight.gif)";
        //alert('b');
    } else if (document.getElementById) {
        scrollY = window.pageYOffset;
        screenY = window.innerHeight;
        screenX = window.innerWidth;
        //alert('c');
    } 
    
    y = scrollY + (screenY/2) - ($('editDivWrapper').getHeight()/2);
    x = (screenX/2) - ($('editDivWrapper').getWidth()/2);
  	klappboxEditDiv.style.top = y + 'px';    
  	klappboxEditDiv.style.left = x + 'px';   
  }
  fadeIn(klappboxEditDiv.id);
}

function removeEditDiv(){
	fadeOut(klappboxEditDiv.id);
}

// Zentriertes Popup

var popupDivWrapper = document.createElement('div');

function createPopupDiv(cssClassName){

  var html = '<table id="popuptable" cellpadding=0 cellspacing=0 bordercollapse=collapse>';
  html += '<tr>';
  html += '<td id="popupcontent"><div id="popupDiv">'+ LOADING_GIF_CENTER + '</div></td>';
  html += '<td id="popupright" style="overflow:hidden;width:8px;background: url(/img/schattenRight.png);background-repeat:no-repeat;"></td>';
  html += '</tr>';
  html += '<tr>';
  html += '<td id="popupbottom" style="heigth:8px;background: url(/img/schattenBottom.png);background-repeat:no-repeat;">';
  html += '&nbsp;</td>';
  html += '<td id="popupbottomright" style="heigth:8px;background: url(/img/schattenBottomRight.png);background-repeat:no-repeat;">';
  html += '&nbsp;</td>';
  html += '</tr>';
  html += '</table>';
  
  popupDivWrapper.style.top = '0px';
  popupDivWrapper.style.left = '0px';
  popupDivWrapper.style.zIndex = '500';
  popupDivWrapper.style.width = '';
  popupDivWrapper.style.height = '';
  popupDivWrapper.id = 'popupDivWrapper';
	popupDivWrapper.innerHTML = html;
  popupDivWrapper.style.position = 'absolute';
	popupDivWrapper.style.opacity = 0;
	popupDivWrapper.style.filter = 'alpha(opacity=0)';
	document.body.appendChild(popupDivWrapper);

  $('popupDiv').innerHTML = '';
  $('popupDiv').style.top = '0px';
  $('popupDiv').style.left = '0px';
	$('popupDiv').className = cssClassName;
	$('popupDiv').style.position = 'static';
	$('popupDiv').style.background = '#FFFFFF';
	$('popupDiv').style.opacity = 1;
	$('popupDiv').style.filter = 'alpha(opacity=100)';
	
  if (document.layers) {
      scrollY = window.pageYOffset;
      screenY = window.innerHeight;
      screenX= window.innerWidth;
      $('popupright').style.backgroundImage = "url(/img/schattenRight.gif)";
      $('popupbottom').style.backgroundImage = "url(/img/schattenBottom.gif)";
      $('popupbottomright').style.background = "url(/img/schattenBottomRight.gif)";
  } else if (document.all) {
      var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
      scrollY = iebody.scrollTop;
      screenY = iebody.clientHeight;
      screenX = iebody.clientWidth;
      $('popupright').style.backgroundImage = "url(/img/schattenRight.gif)";
      $('popupbottom').style.backgroundImage = "url(/img/schattenBottom.gif)";
      $('popupbottomright').style.background = "url(/img/schattenBottomRight.gif)";
  } else if (document.getElementById) {
      scrollY = window.pageYOffset;
      screenY = window.innerHeight;
      screenX = window.innerWidth;
  } 
  y = scrollY + (screenY/2) - ($('popupDivWrapper').getHeight()/2);
  x = (screenX/2) - ($('popupDivWrapper').getWidth()/2);
	popupDivWrapper.style.top = y + 'px';    
	popupDivWrapper.style.left = x + 'px';
	
	fadeIn(popupDivWrapper.id);
}

function centerPopupDiv(){
    if (document.layers) {
        scrollY = window.pageYOffset;
        screenY = window.innerHeight;
        screenX= window.innerWidth;
        //alert('a');
    } else if (document.all) {
        var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
        scrollY = iebody.scrollTop;
        screenY = iebody.clientHeight;
        screenX = iebody.clientWidth;
        //alert('b');
    } else if (document.getElementById) {
        scrollY = window.pageYOffset;
        screenY = window.innerHeight;
        screenX = window.innerWidth;
        //alert('c');
    } 
    y = scrollY + (screenY/2) - ($('popupDivWrapper').getHeight()/2);
    x = (screenX/2) - ($('popupDivWrapper').getWidth()/2);
  	popupDivWrapper.style.top = y + 'px';    
  	popupDivWrapper.style.left = x + 'px';   
}

function removePopupDiv(){
	fadeOut(popupDivWrapper.id);
}

function highlightPopupClose(){
	var img = $('popupClose').src;
	var tmp = img.split('_');
	var imgloc =  "/img/popupCloseHover_"+tmp[1];
	$('popupClose').src = imgloc;
}

function resetPopupClose(){
	var img = $('popupClose').src;
	var tmp = img.split('_');
	var imgloc = "/img/popupClose_"+tmp[1];
	$('popupClose').src = imgloc;
}

var trans =  document.createElement('div');

function fadeIn(id, count, popup){

	var popup = (popup) ? false : true;

	count = (count) ? count : 0;

	if(count == 0 && popup){
		trans.style.width = document.body.scrollWidth+'px';
		trans.style.height= document.body.scrollHeight+'px';

		trans.style.top = '0px';
		trans.style.left = '0px';
		trans.style.position = 'absolute';
		trans.style.backgroundColor = document.body.getAttribute('overlaycolor');
		trans.style.display = 'block';
		trans.style.zIndex = '100';
		trans.style.opacity = 0;
		trans.style.filter = 'alpha(opacity=0)';		
		document.body.appendChild(trans);
	}
	var div = $(id);
	div.style.zIndex = 120;
	var i = count;
	var tmp = i/10;
	div.style.opacity = tmp;
	div.style.filter = 'alpha(opacity='+i*10+')';
	div.style.display = '';
	if(i <= 5 && popup){
		var tmpi = i*6;
		var tmpi2 = tmpi/100;
		trans.style.opacity = tmpi2;
		trans.style.filter = 'alpha(opacity='+tmpi+')';
	}
	i++;
	if(i <= 10){
		setTimeout("fadeIn('"+div.id+"','"+i+"')", 50);
	}
}

function fadeOut(id, count, popup){
	var remove = (popup) ? false : true;
	count = (count) ? count : 10;
	var div = $(id);
	var i = count;
	var tmp = i/10;
	div.style.opacity = tmp;
	div.style.filter = 'alpha(opacity='+i*10+')';
	div.style.display = '';
	i--;
	
	if(i > 0){
		if(i <= 5){
			var tmpi = i*6;
			var tmpi2 = tmpi/100;
			trans.style.opacity = tmpi2;
			trans.style.filter = 'alpha(opacity='+tmpi+')';
		}

		setTimeout("fadeOut('"+div.id+"','"+i+"')", 50);
	}else{
		div.style.display = 'none';
		div.style.opacity = 1;
		div.style.filter = 'alpha(opacity=100)';
		if(remove){
			document.body.removeChild(trans);
		}
		div.innerHTML = '';
    document.body.removeChild(div);
	}
}

///////////////////////////////////////////////////////////////////////
// Divs allgemein

function toggleDiv(div){
	if ($(div).style.display != 'block'){
		$(div).style.display = 'block';
	} else {
		$(div).style.display = 'none';		
	}
}

function hideDivNow(div){
	$(div).style.display = 'none';
}


////////////////////////////////////////////////////////////////////////////
// Formulare

// Allgemein
function hasFocus(id){
    $(id).style.display = '';
		$(id).style.borderColor = '#666';
		$(id).style.color = '#333';
		if ($(id).tagName=='SELECT'){
      $(id).style.background = '#F7F7F7';
		}
}

function lostFocus(id){
		$(id).style.backgroundColor = '';
		$(id).style.borderColor = '';
		$(id).style.color = '';
    $(id).style.background = '';
}

function prepareSanitize(string){
		string = string.replace(/:/g,'[::DOTTDOTT::]');

		string = string.replace(/&/g,'[::UND::]');
		string = string.replace(/\?/g,'[::SAYWHAT::]');
		string = string.replace(/=/g,'[::IS::]');
		string = string.replace(/#/g,'[::RAUTE::]');
		string = string.replace(/%/g,'[::PROZ::]');
		string = string.replace(/;/g,'[::SEMIC::]');

		return string;
}

function checkField(fieldtype,fieldvalue,updateDiv,additional){
  pars="field="+ fieldtype + 
        "&value=" + prepareSanitize(fieldvalue) +
        "&additional=" + additional + 
        "&action=checkField";
  url = AJAX_DIR + "checkFields.php";
	var divLeft = updateDiv + 'Left';
	var divLabel = updateDiv + 'Label';
	var divRight = updateDiv + 'Right';
  new Ajax.Request(url,{
		method: 'post',
		parameters: pars,
		onComplete: function(transport) {
		  
		   var status = transport.responseText;
       if (status==0){
        // OK
        $(divLeft).style.backgroundImage = 'url(/img/starGreen.gif)';
        $(divLabel).style.fontWeight = 'normal';
        $(divLabel).style.color = '#333';
        $(divRight).innerHTML = '';        
       } else 
       if (status==1){
        // ungültige Zeichen
        $(divLeft).style.backgroundImage = 'url(/img/starRed.gif)';
        $(divLabel).style.fontWeight = 'bold';
        $(divLabel).style.color = '#CC0000';
        $(divRight).innerHTML = 'Ung&uuml;ltig';
       } else 
       if (status==2) {
        // zu kurz
        $(divLeft).style.backgroundImage = 'url(/img/starRed.gif)';
        $(divLabel).style.fontWeight = 'bold';
        $(divLabel).style.color = '#CC0000';
        $(divRight).innerHTML = '5 Zeichen';
       } else
       if (status==3) {
        // email ungültig
        $(divLeft).style.backgroundImage = 'url(/img/starRed.gif)';
        $(divLabel).style.fontWeight = 'bold';
        $(divLabel).style.color = '#CC0000';
        $(divRight).innerHTML = 'Ung&uuml;ltig';
       } else 
       if (status==4) {
        // Keine übereinstimmung
        $(divLeft).style.backgroundImage = 'url(/img/starRed.gif)';
        $(divLabel).style.fontWeight = 'bold';
        $(divLabel).style.color = '#CC0000';
        $(divRight).innerHTML = 'Ung&uuml;ltig';
       } else 
       if (status==5) {
        // bereits vergeben
        $(divLeft).style.backgroundImage = 'url(/img/starRed.gif)';
        $(divLabel).style.fontWeight = 'bold';
        $(divLabel).style.color = '#CC0000';
        $(divRight).innerHTML = 'bereits<br>vergeben';
       } else 
       if (status==6) {
        // bereits verwendet
        $(divLeft).style.backgroundImage = 'url(/img/starRed.gif)';
        $(divLabel).style.fontWeight = 'bold';
        $(divLabel).style.color = '#CC0000';
        $(divRight).innerHTML = 'bereits<br>verwendet';
       } else 
       if (status==7) {
        // code nicht gültig
        $(divLeft).style.backgroundImage = 'url(/img/starRed.gif)';
        $(divLabel).style.fontWeight = 'bold';
        $(divLabel).style.color = '#CC0000';
        $(divRight).innerHTML = 'Ung&uuml;ltig';
       } else 
       if (status==8) {
        // code nicht freigeschaltet
        $(divLeft).style.backgroundImage = 'url(/img/starRed.gif)';
        $(divLabel).style.fontWeight = 'bold';
        $(divLabel).style.color = '#CC0000';
        $(divRight).innerHTML = 'Ung&uuml;ltig';
       } else 
       if (status==9) {
        // eigene email
        $(divLeft).style.backgroundImage = 'url(/img/starRed.gif)';
        $(divLabel).style.fontWeight = 'bold';
        $(divLabel).style.color = '#CC0000';
        $(divRight).innerHTML = 'Das ist ihre aktuelle Adresse.';
       } else 
       if (status==10) {
        // eigene email
        $(divLeft).style.backgroundImage = 'url(/img/starRed.gif)';
        $(divLabel).style.fontWeight = 'bold';
        $(divLabel).style.color = '#CC0000';
        $(divRight).innerHTML = 'Erforderlich';
       } else 
       if (status==11) {
        // PLZ ungültig
        $(divLeft).style.backgroundImage = 'url(/img/starRed.gif)';
        $(divLabel).style.fontWeight = 'bold';
        $(divLabel).style.color = '#CC0000';
        $(divRight).innerHTML = 'PLZ ung&uuml;ltig';
       } else 
       if (status==12) {
        // zu kurz
        $(divLeft).style.backgroundImage = 'url(/img/starRed.gif)';
        $(divLabel).style.fontWeight = 'bold';
        $(divLabel).style.color = '#CC0000';
        $(divRight).innerHTML = '3 Zeichen';
       }       
      }
	});	
}

function checkFields(fieldtype,fieldvalue1,fieldvalue2,updateDiv){

  if (fieldvalue1.length > 4){
    fieldvalue1 = MD5(fieldvalue1);
  }
  if (fieldvalue2.length > 4){
    fieldvalue2 = MD5(fieldvalue2);
  }
  
	pars="field="+ fieldtype + "&value=" + fieldvalue1 + "&value2=" + fieldvalue2 + "&action=checkField";
	url = AJAX_DIR + "checkFields.php";
	var divLeft = updateDiv + 'Left';
	var divLabel = updateDiv + 'Label';
	var divRight = updateDiv + 'Right';
	
	new Ajax.Request(url,{
		method: 'post',
		parameters: pars,
		onComplete: function(transport) {
		   var status = transport.responseText;
       if (status==0){
        // OK
        $(divLeft).style.backgroundImage = 'url(/img/starGreen.gif)';
        $(divLabel).style.fontWeight = 'normal';
        $(divLabel).style.color = '#333';
        $(divRight).innerHTML = '';        
       } else 
       if (status==4) {
        // Keine übereinstimmung
        $(divLeft).style.backgroundImage = 'url(/img/starRed.gif)';
        $(divLabel).style.fontWeight = 'bold';
        $(divLabel).style.color = '#CC0000';
        $(divRight).innerHTML = 'Ung&uuml;ltig';
       } else 
       if (status==11) {
        // Keine übereinstimmung
        $(divLeft).style.backgroundImage = 'url(/img/starRed.gif)';
        $(divLabel).style.fontWeight = 'bold';
        $(divLabel).style.color = '#CC0000';
        $(divRight).innerHTML = 'Ung&uuml;ltig';
       }		
      }		
	});	
}

///////////////////////////////////////////////////////////////////////
// RADIO ELEMENTE

function $radioGroup(el, radioGroup) {
    if($(el).type && $(el).type.toLowerCase() == 'radio') {
        var radioGroup = $(el).name;
        var el = $(el).form;
    } else if ($(el).tagName.toLowerCase() != 'form') {
        return false;
    }
 
    var checked = $(el).getInputs('radio', radioGroup).find(
        function(re) {return re.checked;}
    );
    return (checked) ? $F(checked) : null;
}

function getRadioValue(idOrName) {
    var value = null;
    var element = document.getElementById(idOrName);
    var radioGroupName = null;  
    
    // if null, then the id must be the radio group name
    if (element == null) {
            radioGroupName = idOrName;
    } else {
            radioGroupName = element.name;     
    }
    if (radioGroupName == null) {
            return null;
    }
    var radios = document.getElementsByTagName('input');
    for (var i=0; i<radios.length; i++) {
            var input = radios[ i ];    
            if (input.type == 'radio' && input.name == radioGroupName && input.checked) {
                    value = input.value;
                    break;
            }
    }
    return value;
}



function allInOut(aktStatus, table, id, where){
	var newStatus = aktStatus == 0 ? 1 : 0;
  var pars = 'javascript:allInOut(\''+newStatus+'\', \''+table+'\', \''+id+'\', \''+where+'\')';
	$(id).setAttribute('href',pars);

	var allElements = $(table).getElementsByTagName('div');
  for (var i=0; i<allElements.length; i++) {
    
		if(check4Att(allElements[i],'viewstatus')){
      if(newStatus == 1){
				if(allElements[i].getAttribute('viewstatus') == 1){
					allElements[i].style.display = 'block';
				}else{
					allElements[i].style.display = 'none';
				}
			}else{
				if(allElements[i].getAttribute('viewstatus') == 0){
					allElements[i].style.display = 'block';
				}else{
					allElements[i].style.display = 'none';
				}
			}
			
		}
	}
	
  $(id+'-Img').src = newStatus == 1 ? '/img/toggleAllMinus.gif' :'/img/toggleAllPlus.gif';
	adjustSideLine();
	
	pars = "action=setToggleStatus&where=" + where + "&status=" + newStatus;
	new Ajax.Request(AJAX_DIR+'viewsettingsToggleAll.php', {
		method: 'post',
		parameters: pars,
		onComplete: function(transport) {
		}
	});
}

///////////////////////////////////////////////////////////////////////
// Checkboxen

// Für alle Items

function toggleItemCheckbox(id){

  if ($('item_'+id)){
    var div = 'item_' + id;
  }
  if ($('itemHeadWrapperDiv')){
    var div = 'itemHeadWrapperDiv';
  }
  if ($('object_' + id)){
    var div = 'object_' + id;
	}
  if ($('wunschlisteContent_' + id)){
    var div = 'wunschlisteContent_' + id;
  }
  if ($('wunschlisteContent_' + id)){
    var div = 'wunschlisteContent_' + id;
  }
	
  if ($('itemCheckbox_' + id).className == 'listItemSelectionDiv'){
		$('itemCheckbox_' + id).className = 'listItemSelectionCheckedDiv';
    $('itemCheckbox_' + id).style.backgroundImage = 'url(/img/itemCheckboxChecked.jpg)';
	  // drunterliegende Angebote auch markieren
	  selectAllShopCheckboxes(div);
  } else {
		$('itemCheckbox_' + id).className = 'listItemSelectionDiv';
    $('itemCheckbox_' + id).style.backgroundImage = 'url(/img/itemCheckbox.jpg)';
	  // drunterliegende Angebote auch markieren
	  unselectAllShopCheckboxes(div);
	  
  }
}

function mouseoverItemCheckbox(id){
	if ($('itemCheckbox_' + id).className == 'listItemSelectionDiv'){
	 $('itemCheckbox_' + id).style.backgroundImage = 'url(/img/itemCheckboxMouseOver.jpg)';
  }
}

function mouseoutItemCheckbox(id){
	if ($('itemCheckbox_' + id).className == 'listItemSelectionDiv'){
    $('itemCheckbox_' + id).style.backgroundImage = 'url(/img/itemCheckbox.jpg)';
	} else {
    $('itemCheckbox_' + id).style.backgroundImage = 'url(/img/itemCheckboxChecked.jpg)';
	}
}

function selectAllItemCheckboxes(){
	var checkboxes = document.getElementsByTagName('div');
	for(var i = 0; i < checkboxes.length; i++){
			if((checkboxes[i].getAttribute('name') == 'itemCheckbox')&&
         (checkboxes[i].style.display != 'none')){
				checkboxes[i].className = 'listItemSelectionCheckedDiv';
        checkboxes[i].style.backgroundImage = 'url(/img/itemCheckboxChecked.jpg)';
			}
	}
}

function unselectAllItemCheckboxes(){
	var checkboxes = document.getElementsByTagName('div');
	for(var i = 0; i < checkboxes.length; i++){
			if((checkboxes[i].getAttribute('name') == 'itemCheckbox')&&(checkboxes[i].style.display != 'none')){
				checkboxes[i].className = 'listItemSelectionDiv';
        checkboxes[i].style.backgroundImage = 'url(/img/itemCheckbox.jpg)';
			}
	}
}

// F�r alle Produkte

function toggleShopCheckbox(id){
	if ($('shopCheckbox_' + id).className == 'listShopSelectionDiv'){
		$('shopCheckbox_' + id).className = 'listShopSelectionCheckedDiv';
    $('shopCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckboxChecked.jpg)';
	} else {
		$('shopCheckbox_' + id).className = 'listShopSelectionDiv';
    $('shopCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckbox.jpg)';
	}
}

function mouseoverShopCheckbox(id){
	if ($('shopCheckbox_' + id).className == 'listShopSelectionDiv'){
	 $('shopCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckboxMouseOver.jpg)';
  }
}

function mouseoutShopCheckbox(id){
	if ($('shopCheckbox_' + id).className == 'listShopSelectionDiv'){
    $('shopCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckbox.jpg)';
	} else {
    $('shopCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckboxChecked.jpg)';
	}
}

function selectAllShopCheckboxes(div){
  if (!div){
    var checkboxes = document.getElementsByTagName('div');
  } else {
    var checkboxes = $(div).getElementsByTagName('div');
  }
	for(var i = 0; i < checkboxes.length; i++){
		if((checkboxes[i].getAttribute('name') == 'shopCheckbox')&&(checkboxes[i].style.display != 'none')){
      checkboxes[i].className = 'listShopSelectionCheckedDiv';
      checkboxes[i].style.backgroundImage = 'url(/img/productCheckboxChecked.jpg)';
		}
	}
}

function unselectAllShopCheckboxes(div){
  if (!div){
    var checkboxes = document.getElementsByTagName('div');
  } else {
    var checkboxes = $(div).getElementsByTagName('div');
  }
	for(var i = 0; i < checkboxes.length; i++){
		if(checkboxes[i].getAttribute('name') == 'shopCheckbox'){
      checkboxes[i].className = 'listShopSelectionDiv';
      checkboxes[i].style.backgroundImage = 'url(/img/productCheckbox.jpg)';
		}
	}
}

// Für alle Rezensionen

function toggleReviewCheckbox(id){
	if ($('reviewCheckbox_' + id).className == 'listReviewSelectionDiv'){
		$('reviewCheckbox_' + id).className = 'listReviewSelectionCheckedDiv';
    $('reviewCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckboxChecked.jpg)';
	} else {
		$('reviewCheckbox_' + id).className = 'listReviewSelectionDiv';
    $('reviewCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckbox.jpg)';
	}
}

function mouseoverReviewCheckbox(id){
  if ($('reviewCheckbox_' + id).className == 'listReviewSelectionDiv'){
   $('reviewCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckboxMouseOver.jpg)';
  }
}

function mouseoutReviewCheckbox(id){
	if ($('reviewCheckbox_' + id).className == 'listReviewSelectionDiv'){
    $('reviewCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckbox.jpg)';
	} else {
    $('reviewCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckboxChecked.jpg)';
	}
}

function selectAllReviewCheckboxes(){
  if ($('klappboxReviewsContent')) {
    if ($('klappboxReviewsContent').style.display == 'block') var check = true;
  } else {
    var  check = true;
  }

  if (check == true){
	  var checkboxes = document.getElementsByTagName('div');
		for(var i = 0; i < checkboxes.length; i++){
			if(checkboxes[i].getAttribute('name') == 'reviewCheckbox'){
				checkboxes[i].className = 'listReviewSelectionCheckedDiv';
        checkboxes[i].style.backgroundImage = 'url(/img/productCheckboxChecked.jpg)';
			}
		}
  }
}

function unselectAllReviewCheckboxes(){
		var checkboxes = document.getElementsByTagName('div');
		for(var i = 0; i < checkboxes.length; i++){
			if(checkboxes[i].getAttribute('name') == 'reviewCheckbox'){
				checkboxes[i].className = 'listReviewSelectionDiv';
        checkboxes[i].style.backgroundImage = 'url(/img/productCheckbox.jpg)';
			}
		}
}

// Für alle Quellen

function toggleQuellenCheckbox(id){
	if ($('quellenCheckbox_' + id).className == 'listQuellenSelectionDiv'){
		$('quellenCheckbox_' + id).className = 'listQuellenSelectionCheckedDiv';
    $('quellenCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckboxChecked.jpg)';
	} else {
		$('quellenCheckbox_' + id).className = 'listQuellenSelectionDiv';
    $('quellenCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckbox.jpg)';
	}
}

function mouseoverQuellenCheckbox(id){
	if ($('quellenCheckbox_' + id).className == 'listQuellenSelectionDiv'){
	 $('quellenCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckboxMouseOver.jpg)';
  }
}

function mouseoutQuellenCheckbox(id){
	if ($('quellenCheckbox_' + id).className == 'listQuellenSelectionDiv'){
    $('quellenCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckbox.jpg)';
	} else {
    $('quellenCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckboxChecked.jpg)';
	}
}

function selectAllQuellenCheckboxes(){
  if ($('klappboxLinksContentWrapper')) {
    if ($('klappboxLinksContentWrapper').style.display == 'block') var check = true;
  } else {
    var  check = true;
  }

  if (check == true){
    var checkboxes = document.getElementsByTagName('div');
		for(var i = 0; i < checkboxes.length; i++){
			if(checkboxes[i].getAttribute('name') == 'quellenCheckbox'){
				checkboxes[i].className = 'listQuellenSelectionCheckedDiv';
        checkboxes[i].style.backgroundImage = 'url(/img/productCheckboxChecked.jpg)';
			}
		}
  }
}

function unselectAllQuellenCheckboxes(){
		var checkboxes = document.getElementsByTagName('div');
		for(var i = 0; i < checkboxes.length; i++){
			if(checkboxes[i].getAttribute('name') == 'quellenCheckbox'){
				checkboxes[i].className = 'listQuellenSelectionDiv';
        checkboxes[i].style.backgroundImage = 'url(/img/productCheckbox.jpg)';
			}
		}
}

// Für alle Meinungen

function toggleOpinionsCheckbox(id){
	if ($('opinionsCheckbox_' + id).className == 'listOpinionsSelectionDiv'){
		$('opinionsCheckbox_' + id).className = 'listOpinionsSelectionCheckedDiv';
    $('opinionsCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckboxChecked.jpg)';
	} else {
		$('opinionsCheckbox_' + id).className = 'listOpinionsSelectionDiv';
    $('opinionsCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckbox.jpg)';
	}
}

function mouseoverOpinionsCheckbox(id){
	if ($('opinionsCheckbox_' + id).className == 'listOpinionsSelectionDiv'){
	 $('opinionsCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckboxMouseOver.jpg)';
  }
}

function mouseoutOpinionsCheckbox(id){
	if ($('opinionsCheckbox_' + id).className == 'listOpinionsSelectionDiv'){
    $('opinionsCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckbox.jpg)';
	} else {
    $('opinionsCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckboxChecked.jpg)';
	}
}

function selectAllOpinionsCheckboxes(){
  if ($('klappboxOpinionsContent')) {
    if ($('klappboxOpinionsContent').style.display == 'block') var check = true;
  } else {
    var  check = true;
  }

  if (check == true){
    var checkboxes = document.getElementsByTagName('div');
		for(var i = 0; i < checkboxes.length; i++){
			if(checkboxes[i].getAttribute('name') == 'opinionsCheckbox'){
				checkboxes[i].className = 'listOpinionsSelectionCheckedDiv';
        checkboxes[i].style.backgroundImage = 'url(/img/productCheckboxChecked.jpg)';
			}
		}
  }
}

function unselectAllOpinionsCheckboxes(){
		var checkboxes = document.getElementsByTagName('div');
		for(var i = 0; i < checkboxes.length; i++){
			if(checkboxes[i].getAttribute('name') == 'opinionsCheckbox'){
				checkboxes[i].className = 'listOpinionsSelectionDiv';
        checkboxes[i].style.backgroundImage = 'url(/img/productCheckbox.jpg)';
			}
		}
}

// Für alle Werke


function toggleWerkeCheckbox(id){
	if ($('werkeCheckbox_' + id).className == 'werkeSelectionDiv'){
		$('werkeCheckbox_' + id).className = 'werkeSelectionCheckedDiv';
    $('werkeCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckboxChecked.jpg)';
	} else {
		$('werkeCheckbox_' + id).className = 'werkeSelectionDiv';
    $('werkeCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckbox.jpg)';
	}
}

function mouseoverWerkeCheckbox(id){
	if ($('werkeCheckbox_' + id).className == 'werkeSelectionDiv'){
	 $('werkeCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckboxMouseOver.jpg)';
  }
}

function mouseoutWerkeCheckbox(id){
	if ($('werkeCheckbox_' + id).className == 'werkeSelectionDiv'){
    $('werkeCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckbox.jpg)';
	} else {
    $('werkeCheckbox_' + id).style.backgroundImage = 'url(/img/productCheckboxChecked.jpg)';
	}
}

function selectAllWerkeCheckboxes(){
  var check = false;
  if ($('klappboxWorksContentWrapper')) {
    if ($('klappboxWorksContentWrapper').style.display == 'block') check = true;
  } else {
    check = true;
  }

  if (check == true){
    var checkboxes = document.getElementsByTagName('div');
		for(var i = 0; i < checkboxes.length; i++){
			if(checkboxes[i].getAttribute('name') == 'werkeCheckbox'){
				checkboxes[i].className = 'werkeSelectionCheckedDiv';
        checkboxes[i].style.backgroundImage = 'url(/img/productCheckboxChecked.jpg)';
			}
		}
  }
}

function unselectAllWerkeCheckboxes(){
		var checkboxes = document.getElementsByTagName('div');
		for(var i = 0; i < checkboxes.length; i++){
			if(checkboxes[i].getAttribute('name') == 'werkeCheckbox'){
				checkboxes[i].className = 'werkeSelectionDiv';
        checkboxes[i].style.backgroundImage = 'url(/img/productCheckbox.jpg)';
			}
		}
}


///////////////////////////////////////////////////////////////
// Ablagen

// Sidebar anzeige
function updateAblagen(){
  var pars = "action=udpateAblagen";
  new Ajax.Request(AJAX_DIR+'ablagenGetTotals.php', {
		method: 'post',
		parameters: pars,
		onComplete: function(transport) {
				if(transport.responseText){
          fillRightSidebar(transport.responseText);
				}
		}
	});  
}

function fillRightSidebar(counts){
	var totalCount = counts.split('_');
  if( totalCount[0] > 0){
		$('notizenCountSidebarRight').innerHTML = totalCount[0];
		$('notizenCountSidebarRightDiv').style.display = '';
		$('ablagenOverviewDiv').style.display = 'block';
	}else{
		$('notizenCountSidebarRightDiv').style.display = 'none';
	}
	if( totalCount[1] > 0){
		$('kalenderCountSidebarRight').innerHTML = totalCount[1];
		$('kalenderCountSidebarRightDiv').style.display = '';
		$('ablagenOverviewDiv').style.display = 'block';
	}else{
		$('kalenderCountSidebarRightDiv').style.display = 'none';
	}
	if( totalCount[2] > 0){
		$('wishlistCountSidebarRight').innerHTML = totalCount[2];
		$('wishlistCountSidebarRightDiv').style.display = '';
		$('ablagenOverviewDiv').style.display = 'block';
	}else{
		$('wishlistCountSidebarRightDiv').style.display = 'none';
	}		
	if( totalCount[3] > 0){
		$('warenkorbCountSidebarRightDiv').style.display = '';
		$('warenkorbCountSidebarRight').innerHTML = totalCount[3];
		$('warenkorbAmountSidebarRight').innerHTML = totalCount[4];
	  if ($('warenkorbWert')){
      $('warenkorbWert').innerHTML = totalCount[4];
    }  
		$('ablagenOverviewDiv').style.display = 'block';
  }else{
		$('warenkorbCountSidebarRightDiv').style.display = 'none';
	}
	
	if ((totalCount[0]<1)&&(totalCount[1]<1)&&(totalCount[2]<1)&&(totalCount[3]<1)){
		$('ablagenOverviewDiv').style.display = 'none';
  }
}

// Notizbuch

function addSelectedToNotizbuch(from,id){
  //createPopupDiv('ablagenPopupDiv');
  setConfirmMessage("Markierte Inhalte werden ins Notizbuch &uuml;bernommen...");
  showConfirmMessage();
  closePopups();  
  
  var angebote_ids = '';
  var werke_ids = '';
	var item_ids = '';
	var review_ids = '';
	var quellen_ids = '';
	var opinion_ids = '';
	var user_ids = '';
	var mail_ids = '';
	
	if (!id){
    var items = document.getElementsByTagName('div');
    for(var i = 0; i < items.length; i++){
    	if(  (items[i].getAttribute('name') == 'shopCheckbox')&&
           (items[i].className == 'listShopSelectionCheckedDiv')){
           angebote_ids += items[i].id.replace('shopCheckbox_','') + '_';
    	}
    	if(  (items[i].getAttribute('name') == 'werkeCheckbox')&&
           (items[i].className == 'werkeSelectionCheckedDiv')){
           werke_ids += items[i].id.replace('werkeCheckbox_','') + '_';
    	}
    	if(  (items[i].getAttribute('name') == 'itemCheckbox')&&
           (items[i].className == 'listItemSelectionCheckedDiv')){
           if (check4Att(items[i],'userid')){
             user_ids += items[i].getAttribute("userid") + '_';         
           } else if (check4Att(items[i],'mailid')){
             mail_ids += items[i].getAttribute("mailid") + '_';         
           } else {
             item_ids += items[i].id.replace('itemCheckbox_','') + '_';
           }
    	}
    	if(  (items[i].getAttribute('name') == 'reviewCheckbox')&&
           (items[i].className == 'listReviewSelectionCheckedDiv')){
           review_ids += items[i].id.replace('reviewCheckbox_','') + '_';
    	}
    	if(  (items[i].getAttribute('name') == 'opinionsCheckbox')&&
           (items[i].className == 'listOpinionsSelectionCheckedDiv')){
           opinion_ids += items[i].id.replace('opinionsCheckbox_','') + '_';
    	}
    	if(  (items[i].getAttribute('name') == 'quellenCheckbox')&&
           (items[i].className == 'listQuellenSelectionCheckedDiv')){
           quellen_ids += items[i].id.replace('quellenCheckbox_','') + '_';
    	}
    }
  } else {
    if (from=='kontakte') user_ids = id + '_';
    if (from=='mail') mail_ids = id + '_';
  }
	//alert('angebote: ' + angebote_ids +'\nItems: ' + item_ids + '\nRezensionen: '+ review_ids + '\nQuellen: ' + quellen_ids);
  
  var pars = "action=addToNotizbuch&items=" + item_ids + "&angebote=" + angebote_ids +
            "&reviews=" + review_ids + "&quellen=" + quellen_ids + "&opinions=" + opinion_ids + "&werke=" + werke_ids
            + "&profile=" + user_ids + "&mails=" + mail_ids;

  pars += "&from=" + from; 
  var url = AJAX_DIR + "ablagenNotizbuch.php";
  new Ajax.Updater('confirmMessageText',url,
  {
  method: 'post',
  parameters: pars,
  onComplete: function () {
    showConfirmMessage();
    unselectAllItemCheckboxes();
    unselectAllWerkeCheckboxes();
    unselectAllShopCheckboxes();
    unselectAllReviewCheckboxes();
    unselectAllOpinionsCheckboxes();
    unselectAllQuellenCheckboxes();
    updateAblagen();
  }
  });         
  
}

// Wunschliste

function addSelectedToWunschliste(from){
    setConfirmMessage("Markierte Inhalte werden in die Wunschliste &uuml;bernommen...");
    showConfirmMessage();
    closePopups();  
    
    var angebote_ids = '';
		var werke_ids = '';
		var item_ids = '';
		var review_ids = '';
		var quellen_ids = '';
		var object_ids = '';
		
		var items = document.getElementsByTagName('div');
  	for(var i = 0; i < items.length; i++){
  		if(  (items[i].getAttribute('name') == 'shopCheckbox')&&
           (items[i].className == 'listShopSelectionCheckedDiv')){
           angebote_ids += items[i].id.replace('shopCheckbox_','') + '_';
  		}
  		if(  (items[i].getAttribute('name') == 'werkeCheckbox')&&
           (items[i].className == 'werkeSelectionCheckedDiv')){
           werke_ids += items[i].id.replace('werkeCheckbox_','') + '_';
  		}
  		if(  (items[i].getAttribute('name') == 'itemCheckbox')&&
           (items[i].className == 'listItemSelectionCheckedDiv')){
           item_ids += items[i].id.replace('itemCheckbox_','') + '_';
  		}
  		if(  (items[i].getAttribute('name') == 'reviewCheckbox')&&
           (items[i].className == 'listReviewSelectionCheckedDiv')){
           review_ids += items[i].id.replace('reviewCheckbox_','') + '_';
  		}
  		if(  (items[i].getAttribute('name') == 'quellenCheckbox')&&
           (items[i].className == 'listQuellenSelectionCheckedDiv')){
           quellen_ids += items[i].id.replace('quellenCheckbox_','') + '_';
  		}
    	if(  (items[i].getAttribute('name') == 'opinionsCheckbox')&&
           (items[i].className == 'listOpinionsSelectionCheckedDiv')){
           opinion_ids += items[i].id.replace('opinionsCheckbox_','') + '_';
    	}  		
  	}
		
		//alert('angebote: ' + angebote_ids +'\nItems: ' + item_ids + '\nRezensionen: '+ review_ids + '\nQuellen: ' + quellen_ids);
    //createPopupDiv('ablagenPopupDiv');
    
    var pars = "action=addToWunschliste&items=" + item_ids + "&angebote=" + angebote_ids +
              "&reviews=" + review_ids + "&quellen=" + quellen_ids + "&opinions=" + opinion_ids  + "&werke=" + werke_ids;
    pars += '&from=' + from;
    var url = AJAX_DIR + "ablagenWunschliste.php";
    
    new Ajax.Updater('confirmMessageText',url,
    {
    method: 'post',
    parameters: pars,
    onComplete: function () {
      showConfirmMessage();
      unselectAllItemCheckboxes();
      unselectAllWerkeCheckboxes();
      unselectAllShopCheckboxes();
      unselectAllReviewCheckboxes();
      unselectAllOpinionsCheckboxes();
      unselectAllQuellenCheckboxes();
      updateAblagen();
    }
    });         
}

function updateAmount(id){
    var amount = $('objectAmount_'+id).value;
		var pars = "action=updateWarenkorbAmount&objectId=" + id + "&amount=" + amount;
    var url = AJAX_DIR + "ablagenWarenkorb.php";
    new Ajax.Request(url,
    {
      method: 'post',
      parameters: pars,
      onComplete: function(){
        updateAblagen();
      } 
    }); 
}

///////////////////////////////////////////////////////////////
// Melden

function prepareAbuse(id,type){
  var url = AJAX_DIR + "abuse.php";
  var pars = "id=" + id + "&type=" + type;
  createPopupDiv('abuseDiv');
  new Ajax.Updater('popupDiv',url,{
    method: 'post',
    parameters: pars
  });  
}

function saveAbuse(){
  var url = AJAX_DIR + "abuse.php";
  var pars = "action=saveAbuse&id=" + $('objectId').value + "&type=" + $('objectType').value;
  pars += "&reasonType=" + $('abuseReasonType').value + "&reasonText=" + 
  prepareSanitize($('abuseReasonText').value);
  insertLoadingGif('popupInner',true);
  new Ajax.Request(url,{
    method: 'post',
    parameters: pars,
    onComplete: function() {
      removeLoading('popupInner');
      removePopupDiv();
      setConfirmMessage("Meldung an Redaktion erfolgreich versendet.");
      showConfirmMessage();
    }
  });  
}

///////////////////////////////////////////////////////////////
// Suche

function searchGoogle(string){
	string = string.replace(/ /g,'+');
	window.open('http://www.google.de/search?q='+string);
}

function searchSpiegel(string){
	string = string.replace(/ /g,'+');
	window.open('http://wissen.spiegel.de/wissen/resultset.html?suchbegriff='+string);
}

function urldecode( str ) {    
    var ret = str;
    ret = ret.replace(/\+/g, '%20');
    ret = decodeURIComponent(ret);
    ret = ret.toString();
    return ret;
}

function query2Url(string,index){
		return(escape(string));
		var anArray = new Array(2);
		anArray[0] =  new Array(" " , "," , "\\\." , "�" , "�", "�" , "�" , "�" , "�" , "�", "Ö" , "ö", "Ä" , "ä" , "U" , "ü" , "ß");
		anArray[1] = new Array("+" , "+" , "+" , "Oe","oe", "Ae","ae" , "Ue", "ue", "sz" , "Oe","oe", "Ae","ae" , "Ue", "ue", "sz");
		for (var i=0; i<anArray[index].length; i++){
				myRegExp = new RegExp(anArray[index][i],"g");
				string = string.replace(myRegExp, anArray[(index==0?1:0)][i]);
		}
		return string
}

function sendSearch(string){
  if (string=='Titel, Name oder ISBN, EAN') string='';
  
  string1 = sanitizeURL(query2Url(string,0));
  string1 = string1 == '' ? ' ':string1;
  window.location.href = "/suche/werke/"+string1+'/';
}

function searchGetPage(whichDiv, page, typeId){
		var start = page;
		start = start-0;
		var end =  10;
		$(whichDiv+'-Wrapper').style.height = $(whichDiv+'-Wrapper').scrollHeight+'px';
		$(whichDiv+'-Results').style.height = $(whichDiv+'-Results').scrollHeight+'px';
		
		var pars = 'start='+start+'&end='+end+'&which='+typeId;
		pars += '&query='+$('topMenueSearchInput').value;
		$(whichDiv+'-Results').innerHTML = '<center><b>hole Daten...</b></center><br>'+LOADING_GIF_CENTER;
		new Ajax.Updater(whichDiv+'-Results',AJAX_DIR+'searchGetPage.php', {method:"POST", parameters: pars, onComplete:function(){adjustDivHeight(whichDiv);}});	
		$('start').value = start;
}

function adjustDivHeight(whichDiv){
	var tmpDiv =
	$(whichDiv+'-Wrapper').getElementsByTagName('div')[0];
	tmpDiv.style.height = $(whichDiv+'-Wrapper').getElementsByTagName('div')[0].scrollHeight+'px';
}

function sanitizeURL(string){
		string = string.replace(/\+/g,' ');
		string = string.replace(/\//g,'');
		string = string.replace(/\(/g,'');
		string = string.replace(/\)/g,'');
		string = string.replace(/'/g,'');
		string = string.replace(/`/g,'');
		string = string.replace(/´/g,'');
		string = string.replace(/&/g,'');
		string = string.replace(/\?/g,'');
		string = string.replace(/=/g,'');
		string = string.replace(/#/g,'');
		string = string.replace(/;/g,'');
		string = string.replace(/ +/g,'+');
		string = string.replace(/\*/g,'');
		return string;
}


///////////////////////////////////////////////////////////////
// Artikel vorschlagen
 
function openVorschlagenDiv(){
	var pars = 'action=openSuggestionDiv';
	createPopupDiv('vorschlagenDiv');
	new Ajax.Updater('popupDiv',AJAX_DIR+'vorschlagenCreateDiv.php', {
    method:"POST", 
    parameters: pars, 
    onComplete:function(){	
		}
	});
}

function suggestClearTa(id){
	if($(id).getAttribute('initmessage') == 'true'){
		$(id).style.color = '#333333';
		$(id).setAttribute('initmessage','');
		if(id == 'suggestionKat'){
			return true;
		}
		$(id).value = '';	

		$(id).style.fontSize = '11px';
	}
}

function suggestCheck4Value(id){
  suggestCheckInputs(id);
	if($(id).getAttribute('initmessage') == '' && $(id).value == ''){
		$(id).style.color = '#999';
		$(id).setAttribute('initmessage','true');
		$(id).value = $(id+'-Hidden').value;
		$(id).style.fontSize = '11px';
	}else if($(id).value != ''){
		$(id).style.fontSize = '11px';
		$(id+'-B').style.color = '#060';
		$(id+'-Div').style.color = '#060';	
	}
}

function suggestCheckInputs(id){
	var inputValue = $(id).value;
	if(!inputValue || ( inputValue && $(id).getAttribute('initmessage') == 'true')){
		$(id+'-Div').style.color = '#CC0000';
		$(id+'-B').style.color = '#CC0000';
		$(id+'-Img').src = '/img/starRed.gif';
		return false;
	}else{
		$(id+'-Img').src = '/img/starGreen.gif';
		inputValue = prepareSanitize(inputValue);
		return inputValue;
	}
}

function sendSuggestion(){
	var suggkat = suggestCheckInputs('suggestionKat');
	var suggtitle = suggestCheckInputs('suggestionTitle');
	var suggcomment = suggestCheckInputs('suggestionComment');
	var sugglink = $('suggestionLink').getAttribute('initmessage') == 'true' ? '' : $('suggestionLink').value;

	if(suggkat && suggtitle && suggcomment){
		$('errorMsg').style.display = 'none';
		var pars = 'kat='+suggkat+'&title='+suggtitle+'&comment='+suggcomment+'&link='+sugglink;
		new Ajax.Request(AJAX_DIR+'vorschlagenSendSuggestion.php', {method:"POST", parameters: pars, onComplete:function(transport){
				removePopupDiv();
				setConfirmMessage('Ihr Vorschlag wurde erfolgreich versendet.');
				showConfirmMessage();
			}
		});
	}else{
		$('errorMsg').innerHTML = 'Bitte f&uuml;llen Sie alle mit <img src="/img/starRed.gif" style="margin-top:-3px;"> gekennzeichneten Felder aus!';
		$('errorMsg').style.display = '';
	}
}


///////////////////////////////////////////////////////////////////////////
// Personen einladen

var invSubjects = [];
invSubjects[0] = "Hier den Betreff eingeben.";
invSubjects[1] = "Einladung zu kulturempfehlungen.de";
invSubjects[2] = "Einladung zu kulturempfehlungen.de";
invSubjects[3] = "Einladung zu kulturempfehlungen.de";
invSubjects[4] = "Einladung zu kulturempfehlungen.de";

var invTexts = [];
invTexts[0] = "Hier Ihre pers"+unescape("%F6")+"nliche Einladungsnachricht eingeben.";
invTexts[1] = "Hallo,\n\nich w"+unescape("%FC")+"rde Sie gerne zu kulturempfehlungen.de einladen. Hier halte ich mich seit einiger Zeit auf dem Laufenden, was das Empfehlenswerteste und Kontroverseste aus Musik, Literatur und Film angeht. Auch die eigene Meinung kann man hier kundtun und sich in einer kulturinteressierten Community austauschen.\n\nViel Spa"+unescape("%DF")+" dabei w"+unescape("%FC")+"nscht\n\n";
invTexts[2] = "Sehr geehrte ...,\n\nmit kulturempfehlungen.de bin ich auf eine Seite gesto"+unescape("%DF")+"en, die auch Sie interessieren k"+unescape("%F6")+"nnte. Ich m"+unescape("%F6")+"chte Sie einladen, sich ebenfalls dort anzumelden und sich einmal umzusehen. Das in allen wichtigen deutschsprachigen Feuilletons besprochene aus den Bereichen Musik, Literatur und Film ist dort fast tagesaktuell zu finden und auch Ihre Meinung ist gefragt.  Vielleicht lesen wir uns ja demn"+unescape("%E4")+"chst in der Community?\n\nBeste Gr"+unescape("%FC")+""+unescape("%DF")+"e,\n\n";
invTexts[3] = "Hallo,\n\nda ich wei"+unescape("%DF")+", dass auch Du Dich f"+unescape("%FC")+"r Kultur interessierst, w"+unescape("%FC")+"rde ich Dich gerne einladen, Mitglied bei kulturempfehlungen.de zu werden. Hier findest Du ein interessantes Bewertungssystem zu Highlights aus Musik, Literatur und Film. Als Mitglied ist au"+unescape("%DF")+"erdem auch Deine Meinung gefragt, sowohl bei der Bewertung einzelner Werke, als auch in der Community. Vielleicht hast Du ja auch Freude daran, wie ich?\n\nViele Gr"+unescape("%FC")+""+unescape("%DF")+"e,\n\n";
invTexts[4] = "Hi,\n\nDu gibst doch auch gern "+unescape("%FC")+"berall Deine Meinung ab :-) Dann habe ich mit kulturempfehlungen.de genau das richtige f"+unescape("%FC")+"r Dich! Neben den umfangreichen Empfehlungen aus den Bereichen Musik, Literatur und Film kannst Du Dich dort in der Community richtig tummeln! Melde Dich mal, wie Du es findest!\n\nGru"+unescape("%DF")+",\n\n";


function toggleInviteFriends(){
  var url = AJAX_DIR + "inviteFriends.php";
  var pars = "action=showInviteFriends";
  createPopupDiv('popupDivInvite');
  new Ajax.Updater('popupDiv',url,{
    method: 'post',
    parameters: pars,
    onComplete: function(){
      
      if ($('inviteContent').getAttribute('maximum') == 'yes'){
        $('popupDiv').className='popupDivInviteConfirm';
        centerPopupDiv();    
      }
    }
  });  
}

function getInvitationText(){
  var mode = $('invitationChoose').value;
  $('invitationSubject').value = invSubjects[mode];
  var text =  invTexts[mode];
  if (mode>0) text = text + $('senderName').value;
  $('inviteText').value = text;

  if (mode==0){
    $('invitationSubject').style.color = '#999';
    $('inviteText').style.color = '#999';
  } else {
    $('invitationSubject').style.color = '#333';
    $('inviteText').style.color = '#333';
  }
}

function sendInvitationMails(){
  var textArray = $('inviteReceivers').value.split('');
  var counter = 0;
  for (i=0;i<textArray.length;i++)
  {
    if (textArray[i] == '@')
    {
    counter++;
    }
  }
  if (counter>0){
    insertLoadingGif('inviteContent',true);
    var url = AJAX_DIR + "inviteFriends.php";
    var subject = prepareSanitize($('invitationSubject').value);
    var text = prepareSanitize($('inviteText').value);
    if (subject == invSubjects[0]) subject = invSubjects[2];
    if (text == invTexts[0]) text = '';
    var pars = "action=sendInvitations";
    pars += "&mode=" + prepareSanitize($('invitationMethod').value);
    pars += "&receivers=" + prepareSanitize($('inviteReceivers').value);
    pars += "&subject=" + subject;
    pars += "&text=" + text;
    new Ajax.Updater('popupDiv',url,{
      method: 'post',
      parameters: pars,
      onComplete: function(){
        removeLoading('inviteContent');
        $('popupDiv').className='popupDivInviteConfirm';
        centerPopupDiv();
      }
    });   
  } else {
    $('noReceiver').style.display = 'block';
  }
}

function inviteMoreFriends(){
  insertLoadingGif('inviteContent',true);
  var url = AJAX_DIR + "inviteFriends.php";
  var pars = "action=showInviteFriends";
  new Ajax.Updater('popupDiv',url,{
    method: 'post',
    parameters: pars,
    onComplete: function(){
      $('popupDiv').className='popupDivInvite';
      centerPopupDiv();
    }
  });  
}

function orderNewCodes(){
  insertLoadingGif('inviteContent',true);
  var url = AJAX_DIR + "inviteFriends.php";
  var pars = "action=generateNewCodes";
  new Ajax.Updater('popupDiv',url,{
    method: 'post',
    parameters: pars,
    onComplete: function(){
      removeLoading('inviteContent');
      $('popupDiv').className='popupDivInvite';
      centerPopupDiv();
    }
  });  
}

function toggleInvitationMode(){
  var value= $('invitationMethod').value;
  
  if (value == '0'){
    $('sendTextDiv').style.display = 'block';
    $('personalText').style.display = 'block';
    $('anonymeText').style.display = 'none';
    $('generateCodeDiv').style.display = 'none';
    $('popupDiv').className = 'popupDivInvite';
    $('invitationCounterDiv').style.display = 'block';
    $('invCloseButton2').style.display = 'none';
  }
  if (value == '1'){
    $('sendTextDiv').style.display = 'block';
    $('personalText').style.display = 'none';
    $('anonymeText').style.display = 'block';
    $('generateCodeDiv').style.display = 'none';
    $('popupDiv').className = 'popupDivInvite';
    $('invitationCounterDiv').style.display = 'block';
    $('invCloseButton2').style.display = 'none';
  }
  if (value == '2'){
    $('sendTextDiv').style.display = 'none';
    $('personalText').style.display = 'block';
    $('anonymeText').style.display = 'none';
    $('generateCodeDiv').style.display = 'block';
    $('popupDiv').className = 'popupDivInviteConfirm';
    $('invitationCounterDiv').style.display = 'block';
    $('invCloseButton2').style.display = 'none';
  }
}

function countRemainingInvitations(){
  var beforeInput = parseInt($('invitationsTotalHidden').innerHTML);
  var maximum = parseInt($('invitationsMaximumHidden').innerHTML);
  
  $('noReceiver').style.display = 'none';

  // Count the @ symbols
  var textArray = $('inviteReceivers').value.split('');
  var counter = 0;
  for (i=0;i<textArray.length;i++)
  {
    if (textArray[i] == '@')
    {
    counter++;
    }
  }
  
  var total = beforeInput + counter;
  
  if (total > maximum){
      $('invitationsTotal').innerHTML = maximum;
      $('invitationCounterDiv').style.color = "#CC0000";
  } else {
      $('invitationsTotal').innerHTML = total;
      $('invitationCounterDiv').style.color = "#333";
  }
}

function increaseSentInvitations(){
  var beforeInput = parseInt($('invitationsTotal').innerHTML);
  var maximum = parseInt($('invitationsMaximumHidden').innerHTML);
  current = beforeInput + 1;
  $('invitationsTotal').innerHTML = current;
  $('invitationsTotalHidden').innerHTML = current;
  if (current > maximum){
      $('invitationCounterDiv').style.color = "#CC0000";
  } else {
      $('invitationCounterDiv').style.color = "#333";
  }  
}

function generateInvLink(){
  insertLoadingGif('generateCodeDiv',true);
  var url = AJAX_DIR + "inviteFriends.php";
  var pars = "action=generateCode";
  new Ajax.Updater('generateCodeDiv',url,{
    method: 'post',
    parameters: pars,
    onComplete: function(){
      removeLoading('generateCodeDiv');
      increaseSentInvitations();
      $('invLinkInput').select();
      $('invCloseButton2').style.display = 'block';
    }
  });    
}

////////////////////////////////////////////////////////////////////////
// Hilfe-Popups

var helpLink = '';
var helpDiv = document.createElement('div');
helpDiv.style.display = 'none';
helpDiv.setAttribute('ispopup','yes');

function getHelpText(which, pos){

  if (helpDiv.style.display != 'block'){
  
  pos = (pos && pos.match(/[TB][LR]/) )? pos: 'BL';
  
	helpId = which;
	helpLink = $(which);
  // get position of "?"
  var xy = findPos(helpLink);
  var divX = xy[0];  	
  var divY = xy[1];  	
  // set position
  if (pos == 'BL'){
    divX = (divX - 275);
  }
  if (pos == 'TL'){
    divY = (divY - 120);
    divX = (divX - 275);
  }
  if (pos == 'BR'){
    divX = (divX + 10);
  }
  if (pos == 'TR'){
    divY = (divY - 120);
    divX = (divX + 10);
  }
  // check for collision with scroll height
  if (document.layers) {
  		topLeftX = window.pageXOffset;
  		topLeftY = window.pageYOffset;
  } else if (document.all) {
  		topLeftX = document.body.scrollLeft;
  		topLeftY = document.body.scrollTop;
  } else if (document.getElementById) {
  		topLeftX = window.pageXOffset;
  		topLeftY = window.pageYOffset;
  }
  if (topLeftY>divY) divY = topLeftY + 5;

  // Setup surrounding shade
  var html = '<table id="popuptable" cellpadding=0 cellspacing=0 bordercollapse=collapse>';
  html += '<tr>';
  html += '<td id="popupcontent"><div id="helpDivInner"><br><br><center>Hilfe wird geladen..</center><br>'+ LOADING_GIF_CENTER + '</div></td>';
  html += '<td id="popupright" style="overflow:hidden;width:8px;background: url(/img/schattenRight.png);background-repeat:no-repeat;"></td>';
  html += '</tr>';
  html += '<tr>';
  html += '<td id="popupbottom" style="heigth:8px;background: url(/img/schattenBottom.png);background-repeat:no-repeat;">';
  html += '&nbsp;</td>';
  html += '<td id="popupbottomright" style="heigth:8px;background: url(/img/schattenBottomRight.png);background-repeat:no-repeat;">';
  html += '&nbsp;</td>';
  html += '</tr>';
  html += '</table>';
  
  helpDiv.style.top = '0px';
  helpDiv.style.left = '0px';
  helpDiv.style.display = 'block';
  helpDiv.style.zIndex = '500';
  helpDiv.style.width = '';
  helpDiv.style.height = '';
  helpDiv.id = 'popupDivWrapper';
	helpDiv.innerHTML = html;
  helpDiv.style.position = 'absolute';
	document.body.appendChild(helpDiv);

  $('helpDivInner').innerHTML = '';
  $('helpDivInner').style.top = '0px';
  $('helpDivInner').style.left = '0px';
	$('helpDivInner').className = 'helpDivWrapper';
	$('helpDivInner').style.position = 'static';
	helpDiv.style.top = divY + 'px';    
	helpDiv.style.left = divX + 'px';

	var pars = 'helpId='+helpId+"&action=help";
	new Ajax.Updater("helpDivInner", AJAX_DIR+'helpGetText.php', {method:'post', parameters: pars,
  onComplete:function(){}});
  
  } else {
   helpDiv.style.display = 'none';
  }
  
}

function hideHelpText(which){
	document.body.removeChild(helpDiv);
}

//////////////////////////////////////////////////////////////////////////////
// Footer

function highlightFooter(id){
  $(id+'Headline').style.color="#333";
  var links = $(id).getElementsByTagName('a');
  for (var i=0; i<links.length; i++) {
    links[i].style.color = '#333';
  }
}

function resetFooter(id){
  $(id+'Headline').style.color="#999";
  var links = $(id).getElementsByTagName('a');
  for (var i=0; i<links.length; i++) {
    links[i].style.color = '#999';
  }
}


function gotoNews(lang){

	window.location = lang == 'de' ? '/content/news' : '/content/en/news';

}
