
var winID = 0;
var popUp = new Array();

function fensterAuf(inhalt, breite, hoehe, winname) {
  var xOff = null,yOff = null;
  var cv4 = (parseInt(navigator.appVersion)>=4);
  var fArgs = fensterAuf.arguments,wp = new Array(0,0,0,0,0,0);
  
  if (fArgs.length > 4) {
    for (a=4;a<fArgs.length;a++) {
      if (fArgs[a].length == 6) {
        for (i=0;i<6;i++) {wp[i] = fArgs[a].substr(i,1);}
      } else {
        if (xOff != null) yOff = fArgs[a]; else xOff = fArgs[a];
      }
    }
  }

  if (xOff == null) {
    if (cv4) xOff = (screen.width-breite)/2; else xOff = 10;
  }
  if (yOff == null) {
    if (cv4) {
      yOff = (screen.height-(hoehe))/2;
      yOff -= 20;
    } else {
      yOff = 10;
    }
  }
  popUp[winID] = window.open(inhalt,winname, "toolbar="+wp[0]+",status="+wp[1]+",location="+wp[2]+",menubar="+wp[3]+",resizable="+wp[4]+",scrollbars="+wp[5]+",width="+breite+",height="+hoehe+",left="+xOff+",top="+yOff);
  winID++;
}

function showTooltipp(name) {
  $('tooltipp_'+name).style.visibility = 'visible';
}

function hideTooltipp(name) {
  $('tooltipp_'+name).style.visibility = 'hidden';
}
function toggleDisplay(id) {
  var element = $(id);
  if(element.style.display == "none") {
    element.style.display = "block";
  }
  else if(element.style.display == "block") {
    element.style.display = "none";
  }
}

/**
 * Handls klick in Form Field which contains description initially.
 * Removes value onfocus
 * last char is a blank (' ')
 */
Form.defValFieldFocus = function(element) {
  if ($F(element).lastIndexOf(' ') + 1 == $F(element).length) {
    $(element).value = '';
  }
}

/**
 * Returns default form-field value if its empty
 */
Form.defValFieldBlur  = function(element) {
  if ($F(element) == '') {
    $(element).value = $(element).defaultValue;
  }
}

function doProduktSchnellsuche(form) {
   if(!form.sprache.value) {
      alert('Bitte w�hlen Sie eine Sprache aus!');
      return false;
   }
   
   form.action = form.sprache.value + 'produktSchnellsuche.do';
   form.submit();
   
   return false;
}

function ajaxUpdateSchnellSuche(form) {
  ajaxUpdateSchnellSucheBox(form, form.medium.value, form.verwendung.value);
}

function ajaxUpdateSchnellSucheBox(form, mediumValue, verwendungValue) {
  var actionUrl = '/home/suchteaserDropdownListe.do';

  // do ajax request for json response
  new Ajax.Request(actionUrl, {
      method: 'post',
      parameters: 'sprache=' + form.sprache.value + '&medium=' + mediumValue + '&verwendung=' + verwendungValue,
      onSuccess: function(res, json) {
        // bef�lle medium select box
        if(json[0].length > 0) populateSelectBox($('mediumContainer'), json[0]);
        else $('mediumContainer').disabled = true;
        // bef�lle verwendung select box
        if(json[1].length > 0) populateSelectBox($('verwendungContainer'), json[1]);
        else $('verwendungContainer').disabled = true;
      }
  });
}

function populateSelectBox(selectField, json) {
  if(json.length == 0) selectField.disabled = true;
  else selectField.disabled = false;
  
  for(var i=0; i < json.length; i++) {
    var optKey = i+1;
    selectField.options[optKey] = new Option(json[i].name, json[i].key);
    if(json[i].highlight) selectField.selectedIndex = optKey;
  }
}


var TeaserSuche =  {
  displayTab: function(tabNo) {
	  if (tabNo == 1) {
		  Element.show('teaser_produktsuche'); Element.hide('teaser_volltextsuche');
			Element.classNames('teaser_suche_header').set('dualTabHeader1');
		}
		else {
		  Element.show('teaser_volltextsuche'); Element.hide('teaser_produktsuche');
			Element.classNames('teaser_suche_header').set('dualTabHeader2');
		}
  }
}

/**
 * AGB Popup Fenster �ffnen
 */
function openAGB(anchor) {
  var width = 600;
  var height = 480;
  var winProp = '000001';
  var url = 'agb.html' + ((anchor) ? anchor : "");
  var winName = 'pons_agb'
  fensterAuf(url, width, height,winName, winProp);
  return false;
}

/**
 * Datenschutz Popup Fenster �ffnen
 */
function openDatenschutz(anchor) {
  var width = 600;
  var height = 480;
  var winProp = '000001';
  var url = 'datenschutz.html' + ((anchor) ? anchor : "");
  var winName = 'pons_datenschutz'
  fensterAuf(url, width, height,winName, winProp);
  return false;
}

/**
 *  Hinweis Popup Fenster �ffnen
 */
function openHinweis() {
  var width = 600;
  var height = 480;
  var winProp = '000001';
  var url = 'best_hinweis.html';
  var winName = 'pons_hinweis'
  fensterAuf(url, width, height,winName, winProp );
}

/**
 *  Auslandskunden Info Popup fenster �ffnen
 */
function openAuslandskundenInfo() {
  var width = 600;
  var height = 480;
  var winProp = '000001';
  var url = 'auslandskunden_info.html';
  var winName = 'pons_auslandskunde_info'
  fensterAuf(url, width, height,winName, winProp );  
}

/*
 * PONS-LINE SUCH-TESAER
 */
function ponslineSuche(){
  var Begriff = escape(document.getElementById('Begriff').value);
  var Richtung = document.getElementById('Richtung').value;
  document.location.href = "http://www.ponsline.de/cgi-bin/wb/w.pl?von=pons.de&Richtung="+Richtung+"&Begriff="+Begriff,"WB","width=810,height=750,scrollbars=yes,resizable=yes";
}
function FeldLeeren(text){
  if (text == '') text = "Bitte Wort eingeben";
  if(document.getElementById('Begriff').value == text){
	  document.getElementById('Begriff').value = "";
  }
}

/*
 * E-Mail Link Generator
 */
function makeLink(name, domain, tld, linktext) {
  if(linktext.length == 0) linktext = name + '@' + domain + '.' + tld;
  var display_this = '<a href="mailto:' + name + '@' + domain + '.' + tld + '">' + linktext + '</a>';
  document.write(display_this);
}

/*
 * Top Navigation
 */
var naviTimeout = null;
var naviLangSelected = null;

function clearNaviTimeout() {
  if (naviTimeout) {
    clearTimeout(naviTimeout);
  }
  naviTimeout = null;
}

function showNaviLang(id) {
  var naviWorkspace = document.getElementById('naviWorkspace');
  naviWorkspace.innerHTML = document.getElementById("div"+id).innerHTML;
  naviWorkspace.style.visibility = "visible";
  
  document.getElementById("tdHauptnaviLang"+id+"Left").style.backgroundImage = "url(/img/bg_hauptnavi_gr_left.png)";
  document.getElementById("tdHauptnaviLang"+id).style.backgroundImage = "url(/img/bg_hauptnavi_gr_mid.png)";
  document.getElementById("tdHauptnaviLang"+id+"Right").style.backgroundImage = "url(/img/bg_hauptnavi_gr_right.png)";
}
function clearNaviLang() {
  for(var i = 1; i <= 5; i++) { 
    if (naviLangSelected && (i == naviLangSelected)) {
      document.getElementById("tdHauptnaviLang"+i+"Left").style.backgroundImage = "url(/img/bg_hauptnavi_gr_nmo_left.png)";
      document.getElementById("tdHauptnaviLang"+i).style.backgroundImage = "url(/img/bg_hauptnavi_gr_nmo_mid.png)";
      document.getElementById("tdHauptnaviLang"+i+"Right").style.backgroundImage = "url(/img/bg_hauptnavi_gr_nmo_right.png)";
      continue;
    }
    document.getElementById("tdHauptnaviLang"+i+"Left").style.backgroundImage = "url(/img/bg_hauptnavi_bl_left.png)";
    document.getElementById("tdHauptnaviLang"+i).style.backgroundImage = "url(/img/bg_hauptnavi_bl_mid.png)";
    document.getElementById("tdHauptnaviLang"+i+"Right").style.backgroundImage = "url(/img/bg_hauptnavi_bl_right.png)";
  }
  document.getElementById("naviWorkspace").style.visibility = "hidden";
}

function naviLangIn(id, tout) {
  if (tout) {
    clearNaviLang();
    showNaviLang(id);
    clearNaviTimeout();
    return true;
  }
  clearNaviTimeout();
  naviTimeout = setTimeout("naviLangIn("+id+", true)", 100);
  return true;
}
function naviLangOut(tout) {
  if (tout) {
    clearNaviLang();
    clearNaviTimeout();
    return true;
  }
  clearNaviTimeout();
  naviTimeout = setTimeout("naviLangOut(true)", 150);
  return true;
}

function naviWorkspaceIn(tout) {
  if (tout) {
    clearNaviTimeout();
    return true;
  }
  clearNaviTimeout();
  naviTimeout = setTimeout("naviWorkspaceIn(true)", 50);
  return true;
}
function naviWorkspaceOut() {
  return naviLangOut();
}
