/* globale Variablen */
var isWinIE = document.uniqueID ? 1 : 0 ;
var dbgswitch = 0;
var errortxt ="";
function dbg(error){
  if (dbgswitch){
    errortxt += error;
    errortxt += "\n";
    //alert(errortxt);
    window.status=errortxt;  
  }   
}  

// onload-Funktionen hier eintragen: 

function init(){
  searchClick("searchterm","nl-email"); // onclick-Leeren fuer Eingabefelder hinzuf&uuml;gen --
  if (isWinIE){ 
    ieButtonhover();
    inputfocus();
  }
}

// Initfunktion triggern
window.onload=init;

/* weitere (mehrere) onLoad-Funktionen hinzuf�gen:  */
function addOnload(funcname){
  if (window.addEventListener) {
    window.addEventListener( 'load', funcname, false );
  }
  else if (window.attachEvent) { 
    window.attachEvent( 'onload', funcname );
  } 
}

/* Default-Value von Eingabe(Such)Feldern auf Klick l�schen, onblur zur�cksetzen */
function searchClick(){
  for (i=0; i<arguments.length; i++){ 
    var inputRef =  document.getElementById(arguments[i]);
    if(inputRef){
      inputRef.onclick=function(){
        if(this.value==this.defaultValue)this.value='';return false;
      }
      inputRef.onblur=function(){
        if( this.value.replace(/\s/g, '') == '') this.value=this.defaultValue; return false;
      }
    }
    else{
      dbg("Objekt nicht gefunden: " + arguments[i] + " "); 
    } 
  }  
}

// Textnodes aus DOM entfernen
function dropTextNodes(elem){
  for( var i=0; i<elem.childNodes.length; i++ ){
    if ( elem.childNodes[i].nodeType !== 1 ){
      //alert("nodeType: " + elem.childNodes[i].nodeType + "\n\n innerHTML: " + elem.childNodes[i].innerHTML)
      elem.removeChild( elem.childNodes[i] )
    } 
  }
}


// Popup-Basisfunktion
function popup(url, optionen, popupName){
  popupName = window.open(url,popupName,optionen);
  if (popupName){
    if (popupName.focus) popupName.focus();
  }
  return false;
}

// Hier Popups definieren, EIgenschaften zuweisen (auch inline m�glich)


function defaultPopup(url, name) {
  popup(url, 'width=655,height=350,toolbar=0,menubar=0,resizable=1,scrollbars=1,status=1,left=200,top=200', name );
  return false;
}

function fachwortPopup(url, name) {
  popup(url, 'width=655,height=300,toolbar=0,menubar=0,resizable=1,scrollbars=1,status=1,left=200,top=200', name );
}

function groefiPopup(url, name) {
  popup(url, 'width=655,height=580,toolbar=0,menubar=0,resizable=1,scrollbars=1,status=1,left=200,top=200', name );
}

function inviteFriendPopup(url, name) {
  popup(url, 'width=655,height=500,toolbar=0,menubar=0,resizable=1,scrollbars=1,status=0,left=200,top=200', name );
}

function ccvCodePopup(url, name) {
  popup(url, 'width=655,height=370,toolbar=0,menubar=0,resizable=1,scrollbars=1,status=1,left=200,top=200', name );
}

function geburtPopup(url, name) {
  popup(url, 'width=655,height=440,toolbar=0,menubar=0,resizable=0,scrollbars=1,status=1,left=200,top=200', name );
}

function infoiconPopup(url, name, width, height) {
  popup(url, 'width='+width+',height='+height+',toolbar=0,menubar=0,resizable=0,scrollbars=0,status=0,left=200,top=200', name );
}

function freundschaftsPopup(url, name, width, height) {
  popup(url, 'width='+width+',height='+height+',toolbar=0,menubar=0,resizable=0,scrollbars=1,status=0,left=200,top=200', name );
}

function printPopup(url, name, width, height) {
  popup(url, 'width='+width+',height='+height+',toolbar=0,menubar=0,resizable=1,scrollbars=1,status=1,left=100,top=100', name );
}

function videoPopup(url, name, width, height) {
	popup(url, 'width='+width+',height='+height+',toolbar=0,menubar=0,resizable=1,scrollbars=0,status=1,left=200,top=200', name);
	return false;
}

/* Hovereffekt fuer Formularelemente */
function ieButtonhover(){
  for (var i=0; i<document.getElementsByTagName("button").length; i++ ){
    document.getElementsByTagName("button")[i].onmouseover=function(){this.style.cursor='hand';this.className += " btnOver"; }   
    document.getElementsByTagName("button")[i].onmouseout=function(){ this.className = this.className.replace(" btnOver", "");}   
  }

  for (var i=0; i<document.getElementsByTagName("input").length; i++){
    if( document.getElementsByTagName("input")[i].getAttribute("type")=="submit" ){
      document.getElementsByTagName("input")[i].onmouseover=function(){this.style.cursor='hand';  this.className += " btnOver";}   
      document.getElementsByTagName("input")[i].onmouseout=function(){ this.className = this.className.replace(" btnOver", "");}   
    }
    if( document.getElementById("submitpfeil")){
      document.getElementById("submitpfeil").onmouseover=function(){this.style.cursor='hand';  this.className = "submitpfeil_hover";}   
      document.getElementById("submitpfeil").onmouseout=function(){ this.className = this.className.replace("submitpfeil_hover", "submitpfeil");}   
      }
    if( document.getElementById("submittext")){      
      document.getElementById("submittext").onmouseover=function(){this.style.cursor='hand';  this.className = "submittext_hover";}   
      document.getElementById("submittext").onmouseout=function(){ this.className = this.className.replace("submittext_hover", "submittext");}   
      }
  }
}

/* Formular-Fokuseffekte f�r den IE */
function inputfocus() {
  var ta=document.getElementsByTagName("textarea");  
  var inp=document.getElementsByTagName("input");  
  if (ta){
    for (i=0; i<ta.length; i++) {
      if( inp[i].onclick == null ) ta[i].onclick=function() {  this.style.borderColor = '';}
      if( inp[i].onblur == null ) ta[i].onblur=function() {  this.style.borderColor = '';}
    }
  } 

  if (inp){
    for (i=0; i<inp.length; i++) {
      if ( inp[i].getAttribute("type") == "text" ||  inp[i].getAttribute("type") == "password" ){  
        if( inp[i].onblur == null ) inp[i].onblur=function() {  this.style.borderColor = ''; }
        if( inp[i].onfocus == null ) inp[i].onfocus=function() { this.style.borderColor = '';} 
      }
    } 
  }
  
}  

function setLieferland(selElem){
	if (document.getElementById("la-land_txt")){
  		document.getElementById("la-land_txt").innerHTML = selElem.options[selElem.selectedIndex].text;		 
	}
	if (document.getElementById("fw-land_txt")){
  		document.getElementById("fw-land_txt").innerHTML = selElem.options[selElem.selectedIndex].text;		 
	}
}



/* Funktionen "bestellen" und "merken" in artikel.jsp verlegt */


function toggleVis(elemId, _schalter ){
  var schalter = _schalter ? 'visible' : 'hidden'; 
  if ( document.getElementById(elemId) ){
    document.getElementById(elemId).style.visibility = schalter;
  }
}
function toggleDis(elemId, _schalter ){
  var schalter = _schalter ? 'block' : 'none'; 
  if ( document.getElementById(elemId) ){
    document.getElementById(elemId).style.display = schalter;
  }
}


function initPagerHover(hoverImg){ 
  hoverImg.onmouseover = function(){
    hoverImg.src = hoverImg.src.replace(".gif", "_o.gif");  
  }      
  hoverImg.onmouseout = function(){
    hoverImg.src =   hoverImg.src.replace("_o.gif", ".gif")  
  }
  hoverImg.onload = null;      
}

var activeImg;
function detailview(aObj){
  activeImg = aObj.getAttribute("detailsrc");
  var imgSrc = document.getElementById("artikelbild").src;
  var imgPath = imgSrc.substring( 0, imgSrc.lastIndexOf("/")+1 );
  if ( aObj.getAttribute("detailsrc") && aObj.getAttribute("detailsrc")!="null" && aObj.getAttribute("detailsrc").length > 1 ){
    if (document.getElementById("artikelbild")){
      document.getElementById("artikelbild").src = imgPath + aObj.getAttribute("detailsrc") + ".jpg";
      return false;
    }
  }
  else{ return true; }
}

function zoomPopup(url, name) {
  if(activeImg) url = url + "&imgsrc=" + activeImg ;
  popup(url, 'width=372,height=700,toolbar=0,menubar=0,resizable=1,scrollbars=0,status=1,left=200,top=200', name );
  return false;
}

function toggleArticleImage(id, image) {
    document.getElementById(id).src = image;
}

function updateZoomPopupLink(id, image) {
    var url = document.getElementById(id).href;
    if(url.lastIndexOf("articleImage")>0) {
      url = url.substring(0, url.lastIndexOf("articleImage")-1);
    }
    url = url + "&articleImage=" + image ;
    document.getElementById(id).href = url;
}

//-- artikel-detail ------------------------------------------------------------
function showLongDescription(shortDescriptionId, longDescriptionId) {
	$(shortDescriptionId).hide();
	$(longDescriptionId).show();
	//new Effect.SlideUp(shortDescriptionId, { duration: 1.0});
	//new Effect.SlideDown(longDescriptionId, {duration: 1.0});
	//new Effect.Opacity(shortDescriptionId, {from: 1, to: 0, duration: 2});
	// new Effect.SlideUp(shortDescriptionId, { duration: 0.0});
}
//-- artikel-detail-ende -------------------------------------------------------
