function init() {
  initNavMainDD();
  initSearchField();
  //if(document.getElementById("documents") && document.getElementById('docItems') && document.getElementById("docViewSpan")) {
  //  document.getElementById('documents').style.display = 'none';
  //  document.getElementById("docViewSpan").onclick = toggleDocuments;
  //}
}

function toggleDocuments() {
  if(document.getElementById('documents').style.display == 'none') { 
    document.getElementById('documents').style.display = 'block'; 
  } else {
    document.getElementById('documents').style.display = 'none';
  }
}

// Initialisierung der Dropdown Navigation für oberes Menü
function initNavMainDD() {
  var navPoints = new Array("navMainPointCompany","navMainPointSupport","navMainPointDownloads","navMainPointNews","navMainPointContact");
  var i = 0;
  while(navPoints[i]) {
    var idTemp = navPoints[i];
    var divTemp = idTemp.replace(/Point/,"Sub");
    if(chkElm(idTemp) && chkElm(divTemp)) {
      getElm(idTemp).onmouseover = new Function("showNavMainDD('"+idTemp+"','"+divTemp+"');");
      getElm(idTemp).onmouseout = new Function("hideNavMainDD('"+idTemp+"','"+divTemp+"');");
      getElm(divTemp).onmouseover = new Function("showNavMainDD('"+idTemp+"','"+divTemp+"');");
      getElm(divTemp).onmouseout = new Function("hideNavMainDD('"+idTemp+"','"+divTemp+"');");
    }
    i++;
  }
}

// Initialisierung des Suchfelds
function initSearchField() {
  if(chkElm("inputSearch")) {
    getElm("inputSearch").onfocus = new Function("clickSearchField();");
    getElm("inputSearch").onblur = new Function("blurSearchField();");
  }
}

function initGlossarySearch() {
  if(chkElm("searchphrase")) {
    getElm("searchphrase").onfocus = new Function("clickSearchPhraseField();");
    getElm("searchphrase").onblur = new Function("blurSearchPhraseField();");
  }
}

$(document).ready(function() {
  $("a[rel='galB']").colorbox({maxWidth:950});
  $("a[rel='galNews']").colorbox({maxWidth:950, html:"<a href='https://www1.gotomeeting.com/register/799234569' target='_blank'><img src='img/digi_webinar_detail_06_10.gif' alt='Digi Webinar: Making Wireless M2M Easy!'/></a>"});
	$("a[rel='gal']").colorbox({maxWidth:950, maxHeight:600});
	$("a[rel='gal2']").colorbox({maxWidth:950, maxHeight:600});
	$("a[rel='galschulung']").colorbox({iframe:true, innerWidth:500, innerHeight:500});
  $("a[rel='galpdf']").colorbox({iframe:true, innerWidth:950, innerHeight:600});
  $("a[rel='galds']").colorbox({iframe:true, innerWidth:950, innerHeight:600});
  $("a[rel='galflv']").colorbox({iframe:true, innerWidth:500, innerHeight:400});
	$("#inputSearch").autocomplete("include/autocomplete.asp",
		{
			delay:5,
			minChars:1,
			matchSubset:1,
			autoFill:true,
			maxItemsToShow:7,
      width: 150,
      onItemSelect: startSearch
		}
	);
});

function startSearch(li) {
    method = "post"; // Set method to post by default, if not specified.
    // The rest of this code assumes you are not using a library.
    // It can be made less wordy if you use one.
    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", "suche.asp");

    var hiddenField = document.createElement("input");
    hiddenField.setAttribute("type", "hidden"); hiddenField.setAttribute("name", "searchphrase"); hiddenField.setAttribute("value", li.selectValue); form.appendChild(hiddenField);
    
    document.body.appendChild(form);    // Not entirely sure if this is necessary
    form.submit();
}


function showNavMainDD(point, id) { getElm(id).style.display='block'; }
function hideNavMainDD(point, id) { getElm(id).style.display='none'; }
function clickSearchField() { if(getElm("inputSearch").value == "Stichwort/Artikel-Nr." || getElm("inputSearch").value == "Keyword/Article no.") getElm("inputSearch").value = ""; }
function blurSearchField() { if(getElm("inputSearch").value == "") getElm("inputSearch").value = "Stichwort/Artikel-Nr."; }
function clickSearchPhraseField() { if(getElm("searchphrase").value == "Fachwort") getElm("searchphrase").value = ""; }
function blurSearchPhraseField() { if(getElm("searchphrase").value == "") getElm("searchphrase").value = "Fachwort"; }
function chkElm(id) { if(getElm(id)) return true; else return false; }
function getElm(id) { return document.getElementById(id); }