
// Arrays and function for Menu Data

var area1 = new Array();
var area2 = new Array();
var area3 = new Array();
var area4 = new Array();
var area5 = new Array();
var area6 = new Array();


function item(id,name,path){
	this.id = id;
	this.name = name;
	this.path = path;
	
	this.child = new Array();
}

function item_personalization(id,name,path,visibility){
	this.id = id;
	this.name = name;
	this.path = path;
	this.visibility = visibility;

	this.child = new Array();
}

// Counter Variables for Sub Menu 

var index2 = 0;
var index3 = 0;


// Variables and function for Sub Menu Highlighting 

var level1 = "";
var level2 = "";
var level3 = "";

function getLevel(){
    if (level != "default"){
        var pos1 = level.indexOf("-");
        if (pos1 != -1){
            level1 = level.substring(0,pos1);    
            var pos2 = level.indexOf("-", pos1+1);  
            if (pos2 != -1){
                level2 = level.substring(pos1+1,pos2);
                level3 = level.substring(pos2+1,level.length);
            } 
            else{
                level2 = level.substring(pos1+1,level.length);
                level3 = "";
            }
        }
        else{
            level1 = level
            level2 = "";
            level3 = "";
        } 
    }
    else{
        level1 = "default";
        level2 = "default";
        level3 = "default";
    } 
}

// Browser detection

function BrowserCheck()
	{
		var b = navigator.appName;
		if (b=="Netscape") this.b = "ns"
		else if (b=="Microsoft Internet Explorer") this.b = "ie"
		else this.b = b
		
		var p = navigator.platform.toLowerCase();
		if (p=="win32") this.p = "win"
		else if (p=="macppc") this.p = "mac"
		else if (p=="x11") this.p = "x11"
		else this.p = p
		
		this.uA = navigator.userAgent.toLowerCase();
		this.v = parseInt(navigator.appVersion);
		this.ns4 = (this.b=="ns" && this.v==4);
		this.ns6 = (this.b=="ns" && this.v>=5);
		this.ie4 = (this.uA.indexOf('msie 4')>0);
		this.ie5 = ((this.uA.indexOf('msie 5')>0)||(this.uA.indexOf('msie 6')>0));
		this.winns4 = (this.b=="ns" && this.p=="win" && this.v==4);
		this.winns6 = (this.b=="ns" && this.p=="win" && this.v>=5);
		this.winie4 = (this.p=="win" && this.uA.indexOf('msie 4')>0);
		this.winie5 = (this.p=="win" && ((this.uA.indexOf('msie 5')>0)||(this.uA.indexOf('msie 6')>0)));
		this.macns4 = (this.b=="ns" && this.p=="mac" && this.v==4);
		this.macns6 = (this.b=="ns" && this.p=="mac" && this.v>=5);
		this.macie4 = (this.p=="mac" && this.uA.indexOf('msie 4.5')>0);
		this.macie5 = (this.p=="mac" && this.uA.indexOf('msie 5')>0);
		this.other = ((this.p!="mac" && this.p!="win") || (this.b!="ns" && this.b!="ie") || this.uA.indexOf('aol')>0 || this.uA.indexOf('opera')>0);
		
		if (this.ie5) this.v = 5
		this.min = (this.ns4 || this.ie4);
	}

is = new BrowserCheck();

function CSSFileChooser()
	{
		BrowserCheck();
		if (ns4) document.write("<LINK REL='stylesheet' TYPE='text/css' HREF='/general/data/webasto_n4.css'>");
		else document.write("<LINK REL='stylesheet' TYPE='text/css' HREF='/general/data/webasto_ie.css'>");
	}	
	
// Flash detection

var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

if ( plugin ) {
    if (parseInt(plugin.description.substring(plugin.description.indexOf(".")-1)) != 0){
        plugin = parseInt(plugin.description.substring(plugin.description.indexOf(".")-1)) >= 5;
    } else {
        plugin = parseInt(plugin.description.substring(plugin.description.indexOf(".")-2)) >= 5;
    }
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.userAgent.indexOf("Windows 95")>=0 || navigator.userAgent.indexOf("Windows 98")>=0 || navigator.userAgent.indexOf("Windows NT")>=0)) {
    document.write('<SCRIPT LANGUAGE=VBScript\> \n');
    document.write('on error resume next \n');
    document.write('plugin = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5")))\n');
    document.write('</SCRIPT\>\n');
}		

// resize (Netscape)	
	
if(is.ns4) {
    orgWidth = self.innerWidth;
    orgHeight = self.innerHeight;
    self.onresize = reDo;
}

function reDo(){
    if (self.innerWidth==orgWidth && self.innerHeight==orgHeight) return;
    self.location.reload();
}

// Layer Menu (cross browser)

function findObj(n, d) {
	  var p,i,x;  
	  
	  if(!d) d=document; 
	  if((p=n.indexOf("?"))>0&&parent.frames.length) {
	  	d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	  }
	  if(!(x=d[n])&&d.all) 
	  	x=d.all[n]; 
	  else if(!(x=d[n])&&d.getElementById) 
	  	x=d.getElementById(n); 
	  
	  for (i=0;!x&&i<d.forms.length;i++) 
	  	x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
	  	x=findObj(n,d.layers[i].document); 
		
	  return x;
}

function showHideLayers() {
	  var i,p,v,obj,args=showHideLayers.arguments;
	  
	  for (i=0; i<(args.length-2); i+=3) 
	  	if ((obj=findObj(args[i]))!=null) { 
			v=args[i+2];
		    if (obj.style) { 
				obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; 
			}
		    obj.visibility=v; 
		}
} 

// Functions for Layer Menu

function show(id) {
	if (document.layers) {
		document.layers[id].visibility = "show";
	}
	else if (document.all) {
		document.all[id].style.visibility = "visible";
	}
	else {
		document.getElementById(id).style.visibility = "visible";
	}
}

function hide(id) {
	if (document.layers) {
		document.layers[id].visibility = "hide";
	}
	else if (document.all) {
		document.all[id].style.visibility = "hidden";
	}
	else {
		document.getElementById(id).style.visibility = "hidden";
	}
}
	
function showMenu(layer){
	if(document.layers){
		eval('document.layers["'+layer+'"].visibility = "show"');
	}	
	else if(document.all){
		eval('document.all["'+layer+'"].style.visibility="visible"');
	}
	else{
		eval('document.getElementById("'+layer+'").style.visibility = "visible"');
	}		
}

function hideMenu(layer){
	if(document.layers){
		eval('document.layers["'+layer+'"].visibility = "hide"');
	}	
	else if(document.all){
		eval('document.all["'+layer+'"].style.visibility="hidden"');
	}
	else{
		eval('document.getElementById("'+layer+'").style.visibility = "hidden"');
	}		
}

function hideAll(){
	if(document.layers){
		document.layers["area1"].visibility = "hide";
		document.layers["area2"].visibility = "hide";
		document.layers["area3"].visibility = "hide";
		document.layers["area4"].visibility = "hide";
		document.layers["area5"].visibility = "hide";
		document.layers["area6"].visibility = "hide";
	}	
	else if(document.all){
		document.all["area1"].style.visibility="hidden";
		document.all["area2"].style.visibility="hidden";
		document.all["area3"].style.visibility="hidden";
		document.all["area4"].style.visibility="hidden";
		document.all["area5"].style.visibility="hidden";
		document.all["area6"].style.visibility="hidden";
	}
	else{
		document.getElementById("area1").style.visibility = "hidden";
		document.getElementById("area2").style.visibility = "hidden";
		document.getElementById("area3").style.visibility = "hidden";
		document.getElementById("area4").style.visibility = "hidden";
		document.getElementById("area5").style.visibility = "hidden";
		document.getElementById("area6").style.visibility = "hidden";
	}	
}

function show_area1(){
	showHideLayers('area1','','show');
	showHideLayers('area2','','hide');
	showHideLayers('area3','','hide');
	showHideLayers('area4','','hide');
	showHideLayers('area5','','hide');
	showHideLayers('area6','','hide');
}

function hide_area1(){
	showHideLayers('area1','','hide');
}

function show_area2(){
	showHideLayers('area2','','show');
	showHideLayers('area1','','hide');
	showHideLayers('area3','','hide');
	showHideLayers('area4','','hide');
	showHideLayers('area5','','hide');
	showHideLayers('area6','','hide');
}
	
function hide_area2(){
	showHideLayers('area2','','hide');
}

function show_area3(){
	showHideLayers('area3','','show');
	showHideLayers('area1','','hide');
	showHideLayers('area2','','hide');
	showHideLayers('area4','','hide');
	showHideLayers('area5','','hide');
	showHideLayers('area6','','hide');	
}

function hide_area3(){
	showHideLayers('area3','','hide');
}

function show_area4(){
	showHideLayers('area4','','show');
	showHideLayers('area1','','hide');
	showHideLayers('area2','','hide');
	showHideLayers('area3','','hide');
	showHideLayers('area5','','hide');
	showHideLayers('area6','','hide');
}

function hide_area4(){
	showHideLayers('area4','','hide');
}

function show_area5(){
	showHideLayers('area5','','show');
	showHideLayers('area1','','hide');
	showHideLayers('area2','','hide');
	showHideLayers('area3','','hide');
	showHideLayers('area4','','hide');
	showHideLayers('area6','','hide');	
}

function hide_area5(){
	showHideLayers('area5','','hide');
}

function show_area6(){
	showHideLayers('area6','','show');
	showHideLayers('area1','','hide');
	showHideLayers('area2','','hide');
	showHideLayers('area3','','hide');
	showHideLayers('area4','','hide');
	showHideLayers('area5','','hide');	
}

function hide_area6(){
	showHideLayers('area6','','hide');
}

function hide_all(){
	hide_area1();
	hide_area2();
	hide_area3();
	hide_area4();
	hide_area5();
	hide_area6();
}		

// Functions for Image change

function preload(imgObj,imgSrc){
	eval(imgObj+' = new Image()');
	eval(imgObj+'.src = "'+imgSrc+'"');
}

function imageHigh(layer,img){
	if (document.images){
		if(document.layers && layer!=null){
			eval('document.'+layer+'.document.'+img+'.src='+img+'_a'+'.src');
		}	
		else{
			eval('document.'+img+'.src='+img+'_a.src');
		}	
	}
} 	

function imageLow(layer,img){
	if (document.images){
		if(document.layers && layer!=null){
			eval('document.'+layer+'.document.'+img+'.src='+img+'_p'+'.src');
		}	
		else{
			eval('document.'+img+'.src='+img+'_p.src');
		}	
	}
} 	

// Status Line

function fillStatus(txt){
    self.status = txt
}
	
function emptyStatus(){
	self.status = ""
}

// Popup Window

function openDocument(URL) {
	popup = window.open(URL,'','width=564,height=288,scrollbars=yes,location=no,resizable=no,directories=no,status=0,menubar=0,toolbar=no');
}

function openDealerLocator(URL) {
	popup = window.open(URL,'','width=800,height=600,scrollbars=yes,location=no,resizable=no,directories=no,status=0,menubar=0,toolbar=no');
}

// 2006-09-21: Christian Langer (Maximized Window)
function openApplication(URL) {
	var adjustHeight = 37;
	var adjustWidth  = 12;
	var height = screen.availHeight-adjustHeight;
	var width = screen.availWidth-adjustWidth;        
	var winProps = "height="+height+",width="+width+",left=0,top=0,resizable=yes";        
	var winProps = "height="+height+",width="+width+",left=0,top=0,scrollbars=yes,location=no,resizable=yes,directories=no,status=0,menubar=0,toolbar=no"; 
	popup = window.open(URL,'',winProps);
}

function openMicrositeOnLoad(URL) {
	var ablauf = new Date();
	var gueltigbis = ablauf.getTime() + (5000 * 24 * 60 * 60 * 1000);
	ablauf.setTime(gueltigbis);
	 
	if(!document.cookie){
	    document.cookie = ablauf.toGMTString() + "; expires=" + ablauf.toGMTString(); 
	    popup = window.open(URL,'WebastoMicrosite','width=777,height=565,scrollbars=yes,location=no,resizable=no,directories=no,status=0,menubar=0,toolbar=no');	  
	}
}

function openMicrosite(URL) {
	popup = window.open(URL,'WebastoMicrosite','width=777,height=565,scrollbars=yes,location=no,resizable=no,directories=no,status=0,menubar=0,toolbar=no');
}

function openWebastocom(URL) {
	popup = window.open(URL,'WebastoCom','width=770,height=445,scrollbars=yes,location=yes,resizable=yes,directories=yes,status=1,menubar=1,toolbar=yes');
}

function changeLocation(form,element){
	var url,index;
	
	index = eval('document.'+form+'.'+element+'.selectedIndex');
	value = eval('document.'+form+'.'+element+'.options['+index+'].value');
	url = value.substring(0,value.length-4);
	target = value.substring(value.length-3,value.length);
	
	if(value != ""){
		if(target == "ext"){
			popup = window.open(url,'','scrollbars=yes,location=yes,resizable=yes,directories=yes,status=1,menubar=1,toolbar=yes');
		} 
		else if(target == "pop"){
		    popup = window.open(url,'','width=564,height=288,scrollbars=yes,location=no,resizable=no,directories=no,status=0,menubar=0,toolbar=no');
		} 
                else if(target == "app"){
		    openApplication(url);
		}
		else{
			self.location.href = url;
		}
		
	}	
}

function changeLocationExtern(layer,form,element){
	var url,index;
	if(document.layers && layer!=null){
		index = eval('document.'+layer+'.document.'+form+'.'+element+'.selectedIndex');
		url = eval('document.'+layer+'.document.'+form+'.'+element+'.options['+index+'].value');
	}	
	else{
		index = eval('document.'+form+'.'+element+'.selectedIndex');
		url = eval('document.'+form+'.'+element+'.options['+index+'].value');
	}	
	
	if (url != "")
		popup = window.open(url,'','scrollbars=yes,location=yes,resizable=yes,directories=yes,status=1,menubar=1,toolbar=yes');
}

function changeLocationIntern(layer,form,element){
	var url,index;
	if(document.layers && layer!=null){
		index = eval('document.'+layer+'.document.'+form+'.'+element+'.selectedIndex');
		url = eval('document.'+layer+'.document.'+form+'.'+element+'.options['+index+'].value');
	}	
	else{
		index = eval('document.'+form+'.'+element+'.selectedIndex');
		url = eval('document.'+form+'.'+element+'.options['+index+'].value');
	}	
	
	if (url != "")
		self.location.href = url;
}

function changeLocationPopup(layer,form,element){
	var url,index;
	if(document.layers && layer!=null){
		index = eval('document.'+layer+'.document.'+form+'.'+element+'.selectedIndex');
		url = eval('document.'+layer+'.document.'+form+'.'+element+'.options['+index+'].value');
	}	
	else{
		index = eval('document.'+form+'.'+element+'.selectedIndex');
		url = eval('document.'+form+'.'+element+'.options['+index+'].value');
	}	
	
	if (url != "")
		popup = window.open(url,'','width=564,height=288,scrollbars=yes,location=no,resizable=no,directories=no,status=0,menubar=0,toolbar=no');
}

// Press releases: Intern, extern, Print version

function showPressReleaseIntern(urlIntern, urlExtern, urlPrint) {
    if (urlIntern != "")
        self.location.href = urlIntern;
}

function showPressReleaseExtern(urlIntern, urlExtern, urlPrint) {
    if (urlExtern != "")
        popup = window.open(urlExtern,'','scrollbars=yes,location=yes,resizable=yes,directories=yes,status=1,menubar=1,toolbar=yes');
}

function showPressReleasePrint(urlIntern, urlExtern, urlPrint) {
    if (urlPrint != "")
        popup = window.open(urlPrint,'','scrollbars=yes,location=yes,resizable=yes,directories=yes,status=1,menubar=1,toolbar=yes');
}

// Resize and center (onload)

function openIndex(url) {
	xpos = screen.availWidth/2 - 400;
	ypos = screen.availHeight/2 - 300;
	
	if (is.ns4 || is.ns6)
		index = window.open(url,'index','width=770,height=445,scrollbars=no,location=yes,resizable=yes,directories=no,status=1,menubar=1,toolbar=yes');
	else
		index = window.open(url,'index','width=770,height=445,scrollbars=no,location=yes,resizable=yes,directories=no,status=1,menubar=1,toolbar=yes');
	
	index.moveTo(xpos, ypos);
}

// Company History Functions

function showYear(year){
	strText = "txt" + year;
	strImage = "img" + year;
	if (year != actualYear){
		if (actualYear != ''){
			hide(strActualYearText);
			hide(strActualYearImage);
		}	
		show(strText);
		show(strImage);
	}	
}

function hideYear(year, image){
	strText = "txt" + year;
	strImage = "img" + year;
	if (year != actualYear){
		if (actualYear != ''){
			show(strActualYearText);
			show(strActualYearImage);
		}	
		hide(strText);
		hide(strImage);
	}	
}

function setActualYear(year, image){
	actualImage = image;
	actualYear = year;
	strActualYearText = "txt" + year;
	strActualYearImage = "img" + year;
}


// DHTML List Element Functions

function showElement(id){
	if (id != actualId){
		if (actualId != '')
			hide(actualId);
		show(id);
	}	
}

function hideElement(id){
	if (id != actualId){
		hide(id);
		if (actualId != '')
			show(actualId);
	}	
}

function setActualElement(id){
	if (id != actualId){
		showElement(id);
		actualId = id;
	}
}


// CMS Plug In Functions

function openWindowPicture(url){
  var breite=400
  var hoehe=300
  window.open(url,"_blank","width="+breite+",height="+hoehe+",resizable=1,location=0, directories=0,status=0,menubar=0,scrollbars=1,toolbar=0,");
}
 

// Form Functions

function submit_basename(pageUrl, formId){
	var pageName = basename(pageUrl);
	eval('document.form_'+formId+'.action = pageName');
	eval('document.form_'+formId+'.submit()');
}

function basename(pageUrl){
	var pos, pageName;
	pos = pageUrl.lastIndexOf('/');
	if (pos != -1){
		pageName = pageUrl.substring(pos+1, pageUrl.length);
	}
	else{
		pageName = pageUrl;
	}
	
	return pageName;
} 

function getHostname(){
	return window.location.host;
}

// AJAX Functions
function createRequest ()
{
  var ret = null;
  try {
    ret = new ActiveXObject("Msxml2.XMLHTTP");
  } catch(e) {
    try {
      ret = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(ee) {
      ret = null;
    }
  }
  if( !ret && typeof XMLHttpRequest != "undefined" ) {
    ret = new XMLHttpRequest();
  }
  return ret;
}

var rq = null;

function query ( url )
{
  if( rq && rq.readyState != 0 ) {
    rq.abort();
  }
  rq = createRequest();
  if( rq ) {
    rq.open( "GET", url, true );
    rq.onreadystatechange = function ()
      {
        if( rq.readyState == 4 && rq.responseText ) {
          eval(rq.responseText);
        }
      };
    rq.send(null);
  }
} 

function abortRequest ()
{
  if( rq != null ) {
    rq.abort();
    rq = null;
  }
}

var DEBUG = false;

function setSelection (elem, iStart, iLength)
{
  if (elem.createTextRange) {
    var oRange = elem.createTextRange();
    oRange.moveStart("character", iStart);
    oRange.moveEnd("character", iLength - elem.value.length);
    oRange.select();
  } else if (elem.setSelectionRange) {
    elem.setSelectionRange(iStart, iLength);
  }
if(DEBUG) document.all("log").innerHTML += "&nbsp;&nbsp;done<br>";

  elem.focus();
}


function installEmailSuggestionObject ( baseName, textFieldId )
{
  var so = document.getElementById(baseName);
  so.textFieldId = textFieldId;
  so.clearSuggestionTable = function ()
    {
      var table = this.getElementsByTagName("table")[0].getElementsByTagName("tbody")[0];
      while( table.hasChildNodes() ) {
        table.removeChild( table.firstChild );
      }
      this.currentItem = null;
    };
  so.addSuggestion = function ( value )
    {
      var table = this.getElementsByTagName("table")[0].getElementsByTagName("tbody")[0];
      var nuValue = document.createTextNode(value);
      var nuTR = document.createElement("tr");
      var nuTD = document.createElement("td");
      nuTD.appendChild(nuValue);
      nuTR.appendChild(nuTD);
      nuTR.className = "ajax_unselected";
      nuTR.myValue = value;
      nuTR.myIndex = table.childNodes.length;
      nuTR.onmouseover = function ()
        {
          // this.parentNode.firstChild.className = "ajax_unselected";
          // this.className = "ajax_selected";
          this.parentNode.parentNode.parentNode.setCurrentItem(this.myIndex);
        };
      nuTR.onclick = function ()
        {
          document.getElementById(this.parentNode.parentNode.parentNode.textFieldId).value = this.myValue;
          setSelection( document.getElementById(this.parentNode.parentNode.parentNode.textFieldId),
                        this.myValue.length, this.myValue.length );
          this.parentNode.parentNode.parentNode.hide();
        };
      nuTR = table.appendChild( nuTR );
      // nuTR.firstChild.nowrap = "nowrap";
    };
  so.addTextLine = function ( styleCls, text )
    {
      var table = this.getElementsByTagName("table")[0].getElementsByTagName("tbody")[0];
      var nuText = document.createTextNode(text);
      var nuTR = document.createElement("tr");
      var nuTD = document.createElement("td");
      nuTD.appendChild(nuText);
      nuTD.className = styleCls;
      nuTR.appendChild(nuTD);
      nuTR.className = "ajax_unselectible";
      nuTR = table.appendChild( nuTR );
    };
  so.addSeparator = function ( )
    {
      var table = this.getElementsByTagName("table")[0].getElementsByTagName("tbody")[0];
      var nuTR = document.createElement("tr");
      var nuTD = document.createElement("td");
      nuTD.className = "separator";
      nuTR.appendChild(nuTD);
      nuTR.className = "ajax_unselectible";
      nuTR = table.appendChild( nuTR );
    };
  so.setCurrentItem = function ( num )
    {
      var table = this.getElementsByTagName("table")[0].getElementsByTagName("tbody")[0];
      if( this.currentItem != null ) {
        table.childNodes[this.currentItem].className = "ajax_unselected";
      }
      if( num != null && table.childNodes.length > 0 ) {
        table.childNodes[num].className = "ajax_selected";
      }
      this.currentItem = num;

    };
  so.setCurrentItem = function ( num )
    {
      var table = this.getElementsByTagName("table")[0].getElementsByTagName("tbody")[0];
      if( this.currentItem != null ) {
        table.childNodes[this.currentItem].className = "ajax_unselected";
      }
      if( num != null && table.childNodes.length > 0 ) {
        table.childNodes[num].className = "ajax_selected";
      }
      this.currentItem = num;
    };
  so.updateValid = true;
  so.handleKey = function ( keyCode )
    {
      this.updateValid = false;
      abortRequest();
      if(DEBUG) document.all("log").innerHTML += "handleKey "+keyCode+"<br>";
      if(DEBUG) document.all("log").innerHTML += "&nbsp;&nbsp;textBox = "+escape(document.all(this.textFieldId).value)+"<br>";
      var table = this.getElementsByTagName("table")[0].getElementsByTagName("tbody")[0];
      if( keyCode == 38 ) { // up
        if( this.currentItem == null ) {
          // ignore, do nothing!!
        }else if( this.currentItem == 0 ) {
          // re-store the user-input and  currentItem -> null
        }else if( this.currentItem > 0 ) {
          var nuItem = this.currentItem - 1;
          while( nuItem >= 0 && "ajax_unselectible" == table.childNodes[nuItem].className ) {
            --nuItem;
          }
          if( nuItem >= 0 ) this.setCurrentItem(nuItem);
          // change the text of the input field
        }
      }else if( keyCode == 40 ) { // down
        if( this.currentItem == null ) {
          // currentItem -> 0

        }else if( this.currentItem == table.childNodes.length-1 ) {
          // do not advance!
        }else if( this.currentItem >= 0 ) {
          // if == 0: store the user-input and advance
          var nuItem = this.currentItem + 1;
          while( table.childNodes.length-1 >= nuItem && "ajax_unselectible" == table.childNodes[nuItem].className ) {
            ++nuItem;
          }
          if( table.childNodes.length > nuItem ) this.setCurrentItem(nuItem);
          // change the text of the input field
        }
      }else if( keyCode == 13 && this.currentItem != null ) {
        var myValue = table.childNodes[this.currentItem].myValue;
        document.getElementById(this.textFieldId).value = myValue;
        setSelection( document.getElementById(this.textFieldId), myValue.length, myValue.length );
        this.hide();
      }else if( keyCode == 27 ) {
        this.hide();
      }else if( // keyCode ==  8 || // BKSP
                // keyCode == 46 || // DEL
                false
                ) {
        this.hide();
      }else if( keyCode == 36 || // HOME
                keyCode == 35 || // END
                keyCode == 37 || // LEFT
                keyCode == 39    // RIGHT
                ) {
        // do nothing...
      }else{
        this.runQuery();
        this.updateValid = true;
      }
    };
  so.handleBlur = function ()
    {
      this.hide();
    }
  so.hide = function ()
    {
      this.style.visibility = "hidden";
    }
  so.runQuery = function ()
    {

if(DEBUG) document.all("log").innerHTML += "runQuery "+escape(document.all(this.textFieldId).value)+"<br>";
      query( "../../../ajax/intranet-de/de/queryEmail_company_cf_hr_seminaranmeldung.jsp?q="+escape(document.getElementById(this.textFieldId).value)+"&id="+escape(this.id) );
    }
  so.show = function ()
    {
      this.style.visibility = "visible";
    }
  so.setTextBoxContent = function ( text, markerStart, markerEnd )
    {
if(true) return;
if(DEBUG) document.all("log").innerHTML += "setTextBoxContent "+text+"<br>";
      document.getElementById(this.textFieldId).value = text;
      setSelection( document.getElementById(this.textFieldId), markerStart, markerEnd );
    }
  so.checkForUpdate = function ()
    {
      return this.updateValid;
    }
  // XXX: install the onKeyUp- and onBlur-handlers for the textField!
}

function emailSuggestionObjectKeyHandler ( baseName, keyCode )
{
  // window.setTimeout( "timed_emailSuggestionObjectKeyHandler(\""+baseName+"\", "+keyCode+")", 100 );
  timed_emailSuggestionObjectKeyHandler( baseName, keyCode );
}

function timed_emailSuggestionObjectKeyHandler ( baseName, keyCode )
{
  var so = document.getElementById(baseName);
  so.handleKey(keyCode);
}

// Flash Functions

function showFlash(src, width, height, quality, menu, flashvars, allowFullscreen, scale, salign) {
	closeTags = "</" + "embed></" + "object>";
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '" title="" width="100%" height="100%" ><param name="allowFullScreen" value="' + allowFullscreen + '" /><param name="movie" value="' + src + flashvars + '"><param name="quality" value="' + quality + '"><param name=scale value="' + scale + '" /><param name="salign" value="' + salign + '"><param name="menu" value="' + menu + '"><param name="play" value="true"><embed src="' + src + flashvars + '" quality="' + quality + '" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" menu="' + menu + '" play="true" allowFullscreen="' + allowFullscreen + '" scale="' + scale + '" salign="' + salign + '">'+closeTags);
	// alert("showFlash() flashvars="+flashvars + " => " + src);
}

function hideFullscreen() {
    window.close();
}

function getUrlParameter(name){  
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  

    var regexS = "[\\?&]"+name+"=([^&#]*)";  
    var regex = new RegExp( regexS );  
    var results = regex.exec(window.location.href);  

    if( results == null ) 
        return "";  
    else    
        return results[1];
}

function getPath(){
    var url = self.location.href;			
	var urlArray = url.split("/");
	var area = urlArray[urlArray.length-3];
	var language = urlArray[urlArray.length-2];
	var path = '/' + area + '/' + language;
	
	return path;
}

function getStreamName(){
	return streamName;
}

// Extended Form Functions

function getSelectedCheckboxes(){
    var j = 0;
    var strElement = '';
    var strElementHidden = '';
    var strElementId = '';
    var strElementValue = 0;
    
    for (var i = 0; i < selectedValues.length - 1; i++){
        selectedValues.pop();
    }
    
    for (var i = 0; i < document.forms[form].elements.length; i++){
        if((document.forms[form].elements[i].type == 'checkbox') || (document.forms[form].elements[i].type == 'hidden')){
            strElement = document.forms[form].elements[i].id;
            if (strElement.indexOf('page_') != -1){
                strElementValue = document.forms[form].elements[i].value;
                if ((document.forms[form].elements[i].checked == true) || (document.forms[form].elements[i].type == 'hidden')){
                    selectedValues[j] = 'page_' + strElementValue;
                    for (var k = 0; k < document.forms[form].elements.length; k++){
                        strElementId = document.forms[form].elements[k].id;
                        if((strElementId.indexOf(strElementValue) != -1) && (document.forms[form].elements[k].type == 'textarea') && (document.forms[form].elements[k].value == '-')){
                            document.forms[form].elements[k].value = '';
                        }
                    }
                }
                else{
                    selectedValues[j] = null;
                    for (var k = 0; k < document.forms[form].elements.length; k++){
                        strElementHidden = document.forms[form].elements[k].id;
                        if ((strElementHidden.indexOf(strElementValue) != -1) && (strElementHidden.indexOf('page_') == -1)){
                            document.forms[form].elements[k].value = '-';
                        }
                    }
                }
                j++;
            }
        }
    }
}

function nextPage(){
    var nextPage = null;
    var lastPage = null;
    var strId = '';
    var strElementId = '';
    var strPageId = '';
    
    getSelectedCheckboxes();
    lastPage = getLastPage();

    for (var i = 0; i < document.forms[form].elements.length; i++){
        strId = document.forms[form].elements[i].id;
        if((document.forms[form].elements[i].type == 'checkbox') && (strId.indexOf('page_') != -1) && (document.forms[form].elements[i].type != 'hidden')){
            if ((document.forms[form].elements[i].checked == false)){
                strPageId = strId.substr(5, 5);
                for (var j = 0; j < document.forms[form].elements.length; j++){
                    strElementId = document.forms[form].elements[j].id;
                    if (strElementId.indexOf(strPageId) != -1){                                
                        if(!((document.forms[form].elements[j].type == 'checkbox') && (strElementId.indexOf('page_') != -1))){
                            document.forms[form].elements[j].value = '';
                        }
                    }
                }
            }
        }
    }
    
    if ((currentPage != lastPage) && (lastPage != null)){    
        if (currentPage != startPage){            
            for (var i = 0; i < selectedValues.length; i++){
                if (selectedValues[i] == currentPage){
                    for (var j = i+1; j < selectedValues.length; j++){
                        if ((selectedValues[j] != null) && (nextPage == null)){
                            nextPage = selectedValues[j];
                        }
                    }    
                }
            }
        } else {
            for (var i = 0; i < selectedValues.length; i++){
                if ((selectedValues[i] != null) && (nextPage == null)){
                    nextPage = selectedValues[i];
                }
            }
        }   
        hideLink('previous', currentPage);
        hideLink('next', currentPage);
            
        showLink('previous', nextPage);
        if (nextPage != lastPage){
            showLink('next', nextPage);
        } else {
            showLink('submit', nextPage);
        }

        showElement(nextPage);
        if ( currentPage != startPage){
            hideElement(currentPage);
        } else {
            hideStartPage();
        }
        currentPage = nextPage;
        document.forms[form].PageId.value = nextPage.substr(5, nextPage.length-1);
        if (nextPage == lastPage){
            document.forms[form].LastPage.value = true;
        }
        window.scrollTo(0, 0);
    }            
}

function previousPage(){
    var previousPage = null;
    var firstPage = null;
    var lastPage = null;
    
    getSelectedCheckboxes();
    firstPage = getFirstPage();
    lastPage = getLastPage();
        
    if (currentPage != 'formpage_start'){            
        for (var i = 0; i < selectedValues.length; i++){
            if (selectedValues[i] == currentPage){
                if (selectedValues[i] != firstPage){
                    for (var j = i-1; j >= 0; j--){
                        if ((selectedValues[j] != null) && (previousPage == null)){
                            previousPage = selectedValues[j];
                        }
                    }
                } else {
                   previousPage = startPage;
                }    
            }
        }
        hideLink('previous', currentPage);
        hideLink('next', currentPage);
        if (currentPage == lastPage){
            hideLink('submit', currentPage);
        }

        showLink('next', previousPage);
        if (previousPage != startPage){
            showLink('previous', previousPage);
        }                  
        
        if ( previousPage != startPage){
            showElement(previousPage);
        }
        else {
            showStartPage();
        }
        hideElement(currentPage);
        currentPage = previousPage;
        document.forms[form].PageId.value = previousPage.substr(5, previousPage.length-1);
        document.forms[form].LastPage.value = false;
        window.scrollTo(0, 0);
    }               
}

function getLastPage(){
    for (var i = selectedValues.length - 1; i >= 0; i--){
        if (selectedValues[i] != null){
            return selectedValues[i];
        } 
    }            
    return null;
}

function getFirstPage(){
    for (var i = 0; i < selectedValues.length; i++){
        if (selectedValues[i] != null){
            return selectedValues[i];
        } 
    }
    return null;
}

function getUnselectedChecklists(){
    var strElement = '';
    var isChecked = false;

    for (var i = 0; i < checkLists.length; i++){
        for (var j = 0; j < document.forms[form].elements.length; j++){
            if (document.forms[form].elements[j].type == 'checkbox'){
                strElement = document.forms[form].elements[j].id;
                if (strElement.indexOf(checkLists[i]) != -1){
                    if (document.forms[form].elements[j].checked == true){ 
                        isChecked = true;
                    }
                }
            }
        }

        if (isChecked == false){
            unselectedCheckLists[i] = checkLists[i];
        } else {
            unselectedCheckLists[i] = null;
        }
        isChecked = false;
    }           
}

function submitForm(){
    var lastPage = null;
    var error = false;    
    
    getSelectedCheckboxes();
    lastPage = getLastPage();
    

    // Pflichtfeld-Abfrage für Checkbox-Liste
    // Einkommentiert: Mindestens eine Checkbox muß ausgewählt werden.
    /*if (currentPage == startPage){
        getUnselectedChecklists();
        for (var i = 0; i < unselectedCheckLists.length; i++){
            if (unselectedCheckLists[i] != null){
                eval('document.getElementById("checkbox_error_'+ unselectedCheckLists[i] +'").style.display = "block"');
                error = true;
            }
        }
    }*/
    
    if (error == false){
        for (var i = 0; i < checkLists.length; i++){
            eval('document.getElementById("checkbox_error_'+ checkLists[i] +'").style.display = "none"');
        }
    
        if (lastPage != null){
            document.forms[form].submit();
        }
    }    
}

function hideStartPage(){
    hideElement(startPage);
    for (var i = 0; i < checkLists.length; i++){
        eval('document.getElementById("checkbox_list_'+ checkLists[i] +'").style.display = "none"');
        eval('document.getElementById("formpage_end_'+ checkLists[i] +'").style.display = "none"');
    }
}

function showStartPage(){
    showElement(startPage);
    for (var i = 0; i < checkLists.length; i++){
        eval('document.getElementById("checkbox_list_'+ checkLists[i] +'").style.display = "block"');
        eval('document.getElementById("formpage_end_'+ checkLists[i] +'").style.display = "block"');
    }
}

function showChecklists(){
    for (var i = 0; i < checkLists.length; i++){
        eval('document.getElementById("checkbox_list_'+ checkLists[i] +'").style.visibility = "visible"');
        eval('document.getElementById("formpage_end_'+ checkLists[i] +'").style.visibility = "visible"');
    }
}

function showLink(linkType, id){
    eval('document.getElementById("'+ linkType + '_' + id +'").style.display = "block"');
}

function hideLink(linkType, id){ 
    eval('document.getElementById("'+ linkType + '_' + id +'").style.display = "none"');
}

function showElement(id){
    document.getElementById(id).style.display = "block";
}

function hideElement(id){
    document.getElementById(id).style.display  = "none";
} 

function initPage(){ 
    var lastPage = null;
    show(startPage);
    showChecklists();
    hideStartPage();
               
    if((document.forms['MailerPageFlow']) && (document.forms['MailerPageFlow'].PageId.value != "")){
        document.forms[form].PageId.value = document.forms['MailerPageFlow'].PageId.value;
        currentPage = 'page_' + document.forms['MailerPageFlow'].PageId.value;                
        getSelectedCheckboxes();
        lastPage = getLastPage();
        if (currentPage == lastPage){
            document.forms[form].LastPage.value = true;
        }                    
        if (document.forms['MailerPageFlow'].PageError.value == 'false'){
            nextPage();
        } else if (document.forms['MailerPageFlow'].PageError.value == 'true'){                    
            if (currentPage != lastPage){
                showLink('next', currentPage);
            } else {
                showLink('submit', currentPage);
            }    
            if(currentPage != startPage){
                showLink('previous', currentPage);
                showElement(currentPage);
            } else {    
                showStartPage();
            }
        }
    } else {
        showStartPage();
        showLink('next',startPage);
    }
}

function checkDefaultValue(obj, id){
    if (obj.checked == true){
        document.getElementById(id).checked = "";
    } else {
        document.getElementById(id).checked = "checked";
    }
}

function checkDefaultValueRadioButton(obj, id){
    document.getElementById(id).checked = "";
}


// Location Map Functions

var currentZindex = 1000;

function showLocation(id, layer) {
    document.getElementById(id).style.visibility = "visible";
}

function hideLocation(id, layer) {
    if(layer == 'hidden'){
        document.getElementById(id).style.visibility = "hidden";
    }
}

function toggleLocation(id, layer) {
    if(layer == 'visible'){
        document.getElementById(id).style.visibility = "hidden";
        document.getElementById(id).style.zIndex = 10000;
        layer = "hidden";
    } else {
        document.getElementById(id).style.visibility = "visible";
        document.getElementById(id).style.zIndex = currentZindex;
        currentZindex++;
        layer = "visible";
    }

    return layer;
}

function closeLocation(id, layer) {
    document.getElementById(id).style.visibility = "hidden";
    document.getElementById(id).style.zIndex = 10000;
    layer = "hidden";

    return layer;
}

var showPosition = false;

function getDetails(obj){
    if(showPosition == true){ 
        posX = window.event.x-obj.offsetLeft; 
        posY = window.event.y-obj.offsetTop;
        showPosition = false;
        showLocationPosition(posX,posY);
        
        window.setTimeout(function() { showPosition=true; }, 100);
    }
    
}
var locTimer;
function showLocationPosition(positionX, positionY){
    document.body.style.cursor = "crosshair";
    document.getElementById('locationPosition').style.top = (positionY-20) + "px";
    document.getElementById('locationPosition').style.left = (positionX+20) + "px";
    document.getElementById('locationPosition').innerHTML = "<nobr>left:" + positionX + "&nbsp;&nbsp;top:" + positionY + "</nobr>";
    show('locationPosition');
}

function swapCoordinates(){
    if(showPosition == true){
        showPosition = false;
        hide('locationPosition');
        document.body.style.cursor = "default";
        $('#coordinates_background').css('display', 'none');
    }else{
        $('#coordinates_background').css('display', '');
        showPosition = true;
    }
}

function hideCoordinates(){
    showPosition = false;
    hide('locationPosition');
    document.body.style.cursor = "default";
}


// General RedDot Functions

function setIframeStyles(id){
    eval('document.editIframe'+id+'.document.body.style.font="11px arial"');
    
    for(var i=0; i<document.getElementsByTagName('a').length; i++){
        eval('document.editIframe'+id+'.document.getElementsByTagName("a")[i].style.textDecoration="none"');
        eval('document.editIframe'+id+'.document.getElementsByTagName("a")[i].style.color="#333399"');
    }  
}

// Relaunch Functions: jQuery

var mouse_over_navigation = false;
var mouse_over_teaser_overview = false;
var mouse_over_select = false;

$(document).ready(function(){
	if ($("#leftNavigationPortal").length != 0) {
		$('#leftNavigationPortal a.level-1-no-content').click(function () {
	        $("#leftNavigationPortal a.level-1").each(function () {  
	            $('#leftNavigationPortal ul ul').hide();
	            $('#leftNavigationPortal a.level-1').removeClass('level-1-active');
	        });
	        $(this).addClass('level-1-active');
	        $(this).next().show();
	    });
	    $('#leftNavigationPortal a.level-2-no-content').click(function () {
	        $("#leftNavigationPortal a.level-2").each(function () {  
	            $('#leftNavigationPortal ul ul ul').hide();
	            $('#leftNavigationPortal a.level-2').removeClass('level-2-active');
	            $('#leftNavigationPortal a.level-3').removeClass('level-3-active');
	        });
	        $(this).addClass('level-2-active');
	        $(this).next().show();
	    });
	    $('#leftNavigationPortal a.level-3-no-content').click(function () {
	        $("#leftNavigationPortal a.level-2").each(function () {  
	            $('#leftNavigationPortal ul ul ul ul').hide();
	            $('#leftNavigationPortal a.level-3').removeClass('level-3-active');
	        });
	        $(this).addClass('level-3-active');
	        $(this).next().show();                         
	    });
	}
    
    $(".buttonPortal").mouseover(function(){
        $(this).css("background-color","#666");
    })
    $(".buttonPortal").mouseout(function(){
        $(this).css("background-color","#99bde0");
    })  
    $(".button").mouseover(function(){
        $(this).css("background-color","#666");
    })
    $(".button").mouseout(function(){
        $(this).css("background-color","#19539a");
    })  
    $("div[id*='linkText']").hide();
    
    $("body").click(function(){
        if ($("#serviceCountryLinks").length != 0) {
            $("#serviceCountryLinks").hide();
        }       
        if ($("#serviceLanguageLinks").length != 0) {
            $("#serviceLanguageLinks").hide();
        }
        if((!mouse_over_navigation) && (!mouse_over_select)){ 
        	hideAllNavigationLevel();
        	//alert('body');
        }	
        mouse_over_select = false;
    });
    
    $("#mainArea").mouseover(function(){
    	if(! mouse_over_teaser_overview){    		
    		$("div[class='contentExternalLink']").hide();
    	}
    });
    
    $('#topNavigation').hover(function(){  
    	mouse_over_navigation = true;  
    }, function(){  
    	mouse_over_navigation = false;  
    });  
    
    $("div[class='teaserOverview']").hover(function(){  
    	mouse_over_teaser_overview = true;  
    }, function(){  
    	mouse_over_teaser_overview = false;  
    });
    
    $(".searchField").click(function(){
    	$(this).val('');
    });
    
    $("select[id*='countrySelection']").change(function(){
    	mouse_over_select = true;
    });
});


// Relaunch Functions: Navigation

function showNavigationLevel2(id){
    $(".topNavigationLevel4").hide();
    $(".topNavigationLevel3").hide();
    $(".topNavigationLevel2").hide();
    $("#level" + id).show();
    $("a[id*='ancLevel1']").removeClass("selectedLevel1");
    $("a[id*='ancLevel1']").addClass("level1");
    $("a[id*='ancLevel2']").removeClass("selectedLevel2");
    $("a[id*='ancLevel2']").addClass("level2");
    $("#ancLevel1" + id).removeClass("level1");
    $("#ancLevel1" + id).addClass("selectedLevel1");
    $("#portalNavigation").hide();
}

function showNavigationLevel3(id){
    $(".topNavigationLevel4").hide();
    $(".topNavigationLevel3").hide();
    $("#level" + id).show();
    $("a[id*='ancLevel2']").removeClass("selectedLevel2");
    $("a[id*='ancLevel2']").addClass("level2");
    $("a[id*='ancLevel3']").removeClass("selectedLevel3");
    $("a[id*='ancLevel3']").addClass("level3");
    $("#ancLevel2" + id).removeClass("level2");
    $("#ancLevel2" + id).addClass("selectedLevel2");
}

function showNavigationLevel4(id){
    $(".topNavigationLevel4").hide();
    $("#level" + id).show();
    $("a[id*='ancLevel3']").removeClass("selectedLevel3");
    $("a[id*='ancLevel3']").addClass("level3");
    $("#ancLevel3" + id).removeClass("level3");
    $("#ancLevel3" + id).addClass("selectedLevel3");
}

function hideAllNavigationLevel(){
    $(".topNavigationLevel4").hide();
    $(".topNavigationLevel3").hide();
    $(".topNavigationLevel2").hide();
    $("a[id*='ancLevel1']").removeClass("selectedLevel1");
    $("a[id*='ancLevel1']").addClass("level1");
    $("a[id*='ancLevel2']").removeClass("selectedLevel2");
    $("a[id*='ancLevel2']").addClass("level2");
    $("a[id*='ancLevel3']").removeClass("selectedLevel3");
    $("a[id*='ancLevel3']").addClass("level3");
    $("#portalNavigation").show();
}

function openExternalWebsite(id){
	var url = $(id).val();
	
	if (url != "")
		popup = window.open(url,'','scrollbars=yes,location=yes,resizable=yes,directories=yes,status=1,menubar=1,toolbar=yes');
}

function toggleServiceLinks(layer){
    if($(layer).css("display") == "none"){
        $("#serviceCountryLinks").hide();
        $("#serviceLanguageLinks").hide();
        $(layer).show();
    } else {
        $(layer).hide();
    }    
}

// Relaunch Functions: Teaser

function previous(id){
    if(eval('teaserIndex' + id) > 0){
        $('#teaser' + id + eval('teaserIndex' + id)).hide();
        eval('teaserIndex' + id + '= teaserIndex' + id + ' - 1');
        $('#teaser' + id + eval('teaserIndex' + id)).show();
    } else {
        $('#teaser' + id + eval('teaserIndex' + id)).hide();
        eval('teaserIndex' + id + '= teaserIndexMax' + id);
        $('#teaser' + id + eval('teaserIndexMax' + id)).show();
    }
}

function next(id){
    if(eval('teaserIndex' + id) < eval('teaserIndexMax' + id)){
        $('#teaser' + id + eval('teaserIndex' + id)).hide();
        eval('teaserIndex' + id + '= teaserIndex' + id + ' + 1');
        $('#teaser' + id + eval('teaserIndex' + id)).show();
    } else {
        $('#teaser' + id + eval('teaserIndex' + id)).hide();
        eval('teaserIndex' + id + '= 0');
        $('#teaser' + id + '0').show();
    }
    
}

function setHigh(id, type){
    $("#teaserLink" + id).removeClass("teaser" + type + "Low");
    $("#teaserLink" + id).addClass("teaser" + type + "High");
    $("#teaserText" + id).removeClass("teaserLow");
    $("#teaserText" + id).addClass("teaserHigh");
}

function setLow(id, type){
    $("#teaserLink" + id).removeClass("teaser" + type + "High");
    $("#teaserLink" + id).addClass("teaser" + type + "Low");
    $("#teaserText" + id).removeClass("teaserHigh");
    $("#teaserText" + id).addClass("teaserLow");
}

function setHighExternal(id, type, showLayer){
    if (showLayer == false){
        $("#teaserLink" + id).removeClass("teaser" + type + "Low");
        $("#teaserLink" + id).addClass("teaser" + type + "High");
        $("#teaserText" + id).removeClass("teaserLow");
        $("#teaserText" + id).addClass("teaserHigh");
    } else {
        $('#contentExternalLink' + id).show();
    }    
}

function setLowExternal(id, type, showLayer){
    if (showLayer == false){
        $("#teaserLink" + id).removeClass("teaser" + type + "High");
        $("#teaserLink" + id).addClass("teaser" + type + "Low");
        $("#teaserText" + id).removeClass("teaserHigh");
        $("#teaserText" + id).addClass("teaserLow");
    } else {
        $('#contentExternalLink' + id).hide();
    }        
}

function hideAllExternal(){
    $("div[class*='contentExternalLink']").hide();
}

// Relaunch Functions: Direct Market Access

function showVisual(image, id, target, counter, max){
	if(image != ""){
		$("#directAccessImage").attr("src",image);
		$("#directAccessVisual").show();
	}
    if(target == "_blank"){
    	if(counter == max || counter == max-1){
    		$("#linkText" + id).css("left", "-90px");
    	}	
        $("#linkText" + id).show();
    }    
}

function hideVisual(id){
    $("#directAccessVisual").hide();
    $("#linkText" + id).hide();
}


// Relaunch Functions: Ajax

function ajaxRedirect(ajaxPage, projectSecondLanguage, urlSecond){
    var xmlhttp;
    var preferredLanguage;
    if (window.XMLHttpRequest){
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    } else {
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function(){
        if(xmlhttp.readyState==4){
            preferredLanguage = xmlhttp.responseText.substring(0,2);
            if(preferredLanguage.indexOf(projectSecondLanguage) > -1){
                self.location.href = urlSecond;
            }
        }
    }
    xmlhttp.open("GET",ajaxPage,true);
    xmlhttp.send(null);
}


// Relaunch Functions: Utils

function sortMultipleArray(a, b) {
    return a[0] < b[0] ? 1 :
    a[0] > b[0] ? -1 :
    0;
}

function sortDropDown(dropdown, sortorder) {
    var $dd = $(dropdown);
    if ($dd.length > 0) { // make sure we found the select we were looking for

        // save the selected value
        var selectedVal = $dd.val();

        // get the options and loop through them
        var $options = $('option', $dd);
        var arrVals = [];
        $options.each(function(){
            // push each option value and text into an array
            arrVals.push({
                val: $(this).val(),
                text: $(this).text()
            });
        });

        // sort the array by the value (change val to text to sort by text instead)
        arrVals.sort(function(a, b){
            return a.val - b.val;
        });

        // loop through the sorted array and set the text/values to the options
        if (sortorder == 'asc'){
            for (var i = 0, l = arrVals.length; i < l; i++) {
                $($options[i]).val(arrVals[i].val).text(arrVals[i].text);
            }
        } else {
            for (var i = 0, l = arrVals.length; i < l; i++) {
                $($options[i]).val(arrVals[arrVals.length-1-i].val).text(arrVals[arrVals.length-1-i].text);
            }
        }

        // set the selected value back
        $dd.val(selectedVal);
    }
}    

function removeDuplicatesFromDropDown(dropdown){
    var a = new Array(); 
    $(dropdown).children("option").each(function(x){ 
        test = false; 
        b = a[x] = $(this).val(); 
        for (i=0;i<a.length-1;i++){ 
                if (b == a[i]) test =true; 
        } 
        if (test) $(this).remove(); 
    })
}

function countDuplicatesInDropDown(dropdown, entry){
   var counter = 0;
   
   $(dropdown).children("option").each(function(x){ 
        if ($(this).val() == entry){
            counter++;
        }    
        return counter; 
   })
}

function removeDuplicatesFromArray(a){   
   temp = new Array();
 
   for(var i=0;i<a.length;i++){
      if(!contains(temp, a[i])){
          temp.length+=1;
          temp[temp.length-1]=a[i];
      }
   }
   return temp;
}

function countDuplicatesInArray(a, entry, element){   
   var counter = 0;
 
   if(element == 'date'){ 
       for(var i=0;i<a.length;i++){
          if(a[i].substring(a[i].length-4) == entry.substring(entry.length-4)){
               counter++;
          }
       }
   } else {
       for(var i=0;i<a.length;i++){
          if(a[i] == entry){
               counter++;
          }
       }
   }    
   return counter;
}

function contains(a, e) {
   for(j=0;j<a.length;j++)if(a[j]==e)return true;
   return false;
}

function search(url){
	var searchParam = $("#searchField").val();
	
	if(url.indexOf('?') != -1){
		self.location.href = url + "&searchString=" + searchParam;
	} else {
		self.location.href = url + "?searchString=" + searchParam;
	}
}
 
