var bw=new cm_bwcheck()

var m1=0;
var m2=0;

function cm_bwcheck()
{
  this.ver=navigator.appVersion;

  this.agent=navigator.userAgent.toLowerCase();

  this.dom=document.getElementById?1:0;

  this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1) && window.opera;

  this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1) && window.opera;

  this.op9=(this.agent.indexOf("opera/9")>-1) && window.opera;

  this.op=(this.agent.indexOf("opera")>-1) && window.opera;

  this.ie5 = (this.agent.indexOf("msie 5")>-1 && !this.op5 && !this.op6);

  this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1);

  this.ie6 = (this.agent.indexOf("msie 6")>-1 && !this.op5 && !this.op6);
  this.ie6 = (this.agent.indexOf("msie 6")>-1 && !this.op5 && !this.op6);
  this.ie7 = (this.agent.indexOf("msie 7")>-1 && !this.op5 && !this.op6);

  this.ie4=(this.agent.indexOf("msie")>-1 && document.all && !this.op5 &&!this.op6 &&!this.ie5&&!this.ie6);

  this.ie = (this.ie4 || this.ie5 || this.ie6);

  this.mac=(this.agent.indexOf("mac")>-1);

  this.ns6=(this.agent.indexOf("netscape/6")>-1);
  this.ns7=(this.agent.indexOf("netscape/7")>-1);
  this.ns8=(this.agent.indexOf("netscape/8")>-1);

  this.ns4=(!this.dom && document.layers)?1:0;

  this.ff1=(this.agent.indexOf("firefox/1")>-1);
  this.ff2=(this.agent.indexOf("firefox/2")>-1);

  this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6);

  this.usedom= this.ns6;//Use dom creation

  this.reuse = this.ie||this.usedom; //Reuse layers

  this.px=this.dom&&!this.op5?"px":"";

  return this;
}

function OnChangeRange()
{
  var pr1 = document.getElementById("price_range1");
  var prs1 = document.getElementById("price_range_s1");
  prs1.innerHTML = pr1.value;

  var pr2 = document.getElementById("price_range2");
  var prs2 = document.getElementById("price_range_s2");
  prs2.innerHTML = pr2.value;

  var pr1 = document.getElementById("perc_range1");
  var prs1 = document.getElementById("perc_range_s1");
  prs1.innerHTML = pr1.value;

  var pr2 = document.getElementById("perc_range2");
  var prs2 = document.getElementById("perc_range_s2");
  prs2.innerHTML = pr2.value;
}

function SetDefaultEmail()
{
  var e = document.getElementById("e_description");
  e.value = "";
  var e = document.getElementById("e_subject");
  e.value = "";
  var e = document.getElementById("e_email");
  e.value = "";
  var e = document.getElementById("e_name");
  e.value = "";
}

function SetPopupMenuPosition()
{
  var e = document.getElementById("gmenu");
  if (e)
  {
	  e.style.top="122";
	  e.style.left="602";
	  if (!bw.ie)
	  {
		e.style.left="603";
		e.style.width="143";
	  }
  }
}

function ShowMenu1()
{
	m1=1;
	ShowTag('gmenu');
}
function ShowMenu2()
{
	m2=1;
	ShowTag('gmenu');
}
function HideMenu()
{
	if (m1==0 && m2==0)
	  HideTag('gmenu');
}
function HideMenu1()
{
	if (m1==1)
	{
		m1=0;
		return;
	}
}
function HideMenu2()
{
	m2=0;
}

function ShowTag(id)
{
    var e = document.getElementById(id);
	e.style.visibility = "visible";
}

function HideTag(id)
{
    var e = document.getElementById(id);
	if (e)
		e.style.visibility = "hidden";
}

function SB(el, color)
{
    el.style.backgroundColor=color;
}

function SetVisibility(id, style)
{
  var e = document.getElementById(id);
  if (e)
    e.style.visibility=style;
}

function SetSortVisibility(style)
{
  SetVisibility("sort_field", style);
  SetVisibility("sl1", style);
  SetVisibility("sl2", style);
  SetVisibility("sl3", style);
  SetVisibility("sl4", style);
}

function SetColor(id, color)
{
  var e = document.getElementById(id);
  if (e)
    e.style.color=color;
}

function SetBGColor(id, color)
{
  var e = document.getElementById(id);
  if (e)
    e.style.background=color;
}

function SetPrBG(id, c1, c2, c3)
{
  SetBGColor("dl1"+id, c1);
  SetBGColor("d121"+id, c1);
  SetBGColor("d122"+id, c1);
  SetBGColor("dl3"+id, c1);
  SetBGColor("dl4"+id, c1);
//  SetBGColor("d151"+id, c1);
//  SetBGColor("d152"+id, c1);
  SetBGColor("dl6"+id, c1);
  SetBGColor("dl7"+id, c1);

  SetColor("d151"+id, c2);
  SetColor("d152"+id, c3)
}

function OnMainResize()
{
  var e = document.getElementById("nultysloupec");
  if (e)
    e.height=MainTableHeight();
}

function MainTableHeight() {
 if( typeof( window.innerWidth ) == 'number' ) {
   //Non-IE
   myWidth = window.innerWidth;
   myHeight = window.innerHeight;
 } else if( document.documentElement &&
     ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
   //IE 6+ in 'standards compliant mode'
   myWidth = document.documentElement.clientWidth;
   myHeight = document.documentElement.clientHeight;
 } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
   //IE 4 compatible
   myWidth = document.body.clientWidth;
   myHeight = document.body.clientHeight;
 }
// topmenu.width = myWidth;
 if (!bw.ie && myWidth<1000) myHeight=myHeight-15;
 return myHeight - 150;
}

function NewUserInText(node, text)
{
    while (node.hasChildNodes()) {
        node.removeChild(node.firstChild);
    }
    node.appendChild(document.createTextNode(text));
}

function NewUserChType()
{
  switch (document.forms["newuser"].type.selectedIndex)
  {
  case 0:
  case 1:
    NewUserInText(document.getElementById("_first"), "*");
    NewUserInText(document.getElementById("_last"), "*");
    NewUserInText(document.getElementById("_firm"), " ");
    break;
  case 2:
    NewUserInText(document.getElementById("_first"), "*");
    NewUserInText(document.getElementById("_last"), "*");
    NewUserInText(document.getElementById("_firm"), "*");
    break;
  }
}

function NewUserAGBDisableButton () {
  button=document.newuser_agb.Weiter;
  if (document.all || document.getElementById)
    button.disabled = true;
  else if (button) {
    button.oldOnClick = button.onclick;
    button.onclick = null;
    button.oldValue = button.value;
    button.value = 'DISABLED';
  }
}

function OnBillAdd() {
	var e1 = document.getElementById("samebilladd");
	var s1 = document.getElementById("s1");
	var s2 = document.getElementById("s_name_or_company");
	var s3 = document.getElementById("s_comment");
	var s4 = document.getElementById("s_street_and_number");
	var s5 = document.getElementById("s_zip");
	var s6 = document.getElementById("s_city");
	var s7 = document.getElementById("s_country");

	if (e1 && !e1.checked)
		vis = "visible";
	else
		vis = "hidden";

	if(s1) s1.style.visibility = vis;
	if(s2) s2.style.visibility = vis;
	if(s3) s3.style.visibility = vis;
	if(s4) s4.style.visibility = vis;
	if(s5) s5.style.visibility = vis;
	if(s6) s6.style.visibility = vis;
	if(s7) s7.style.visibility = vis;
}


function NameCompany(varName, companyNameId, firstNameId, lastNameId, deliveryNameCompanyId, billingNameCompanyId)
{
	this.name = varName;
	window[varName] = this;

	var isCheckingNameCompanyS = false;
	var isCheckingNameCompanyF = false;

	this.dnc = document.getElementById(deliveryNameCompanyId);
	this.bnc = document.getElementById(billingNameCompanyId);
	this.comp = document.getElementById(companyNameId);
	this.fn = document.getElementById(firstNameId);
	this.ln = document.getElementById(lastNameId);

	this.check = check;
	this.update = update;

	check();

	function check()
	{
		isCheckingNameCompanyS = (dnc.value == createNameCompanyStr(fn.value, ln.value, comp.value));
		isCheckingNameCompanyF = (bnc.value == createNameCompanyStr(fn.value, ln.value, comp.value));
	}

	function update(ev)
	{
		nctr = createNameCompanyStr(fn.value, ln.value, comp.value);

		if(dnc.value == nctr)
			isCheckingNameCompanyS = true;
		if(bnc.value == nctr)
			isCheckingNameCompanyF = true;

		if(isCheckingNameCompanyS)
			dnc.value = createNameCompanyStr(fn.value, ln.value, comp.value);
		if(isCheckingNameCompanyF)
			bnc.value = createNameCompanyStr(fn.value, ln.value, comp.value);
	}


	function createNameCompanyStr(first, last, company)
	{
		first = trim(first);
		last = trim(last);
		company = trim(company);

		str = "";
		if(company.length > 0)
		{
		  str += company;

		  if(first.length > 0 || last.length > 0)
		    str += " / ";
		}

		if(first.length > 0)
		{
		  str += first;

		  if(last.length > 0)
		    str += " ";
		}

		str += last;

		return str;
	}

	function trim(str)
	{
		return str.replace(/^\s+|\s+$/g,"");
	}

}



function SelectAddress(varName, arrAddressTexts, formName, optionId, textId, actionId, linkId)
{
	this.name = varName;
	window[varName] = this;

	this.texts = arrAddressTexts;
	this.formName = formName;
	this.optonId = optionId;
	this.textId = textId;
	this.actionId = actionId;
	this.linkId = linkId;

	this.updateAddr = updateAddr;
	this.sf = sf;

	updateLink();
	updateAddr();

	function updateLink()
	{
	    document.getElementById(this.linkId).innerHTML =
        	"<a href=\"javascript: " + this.name + ".sf();\">Neue lieferadresse<\/a> \n";
	}

    function updateAddr()
	{
	    i = document.getElementById(optionId).selectedIndex;
	    document.getElementById(textId).innerHTML = address_texts[i];
	}

	function sf()
	{
	    document.getElementById(actionId).value = "newaddress";
	    document.forms[formName].submit();
	}
}


function NewUserAGBEnableButton () {
  button=document.newuser_agb.Weiter;
  if (document.all || document.getElementById)
    button.disabled = false;
  else if (button) {
    button.onclick = button.oldOnClick;
    button.value = button.oldValue;
  }
}

var MDs = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var MNs = new Array('Jan','Feb','Mär','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez');
function GetDayCount(Year, Month) {
   if (Month==-1) return 31;
   var iDay = ((Year!="") && (Month == 2) && ((Year % 400 == 0) || ((Year % 4 == 0) && (Year % 100 != 0)))) ? 29 : MDs[Month-1];
   return iDay;
}

function FixDayList(DayList, NewDays) {
   var DayPick = DayList.selectedIndex + 1;
   if (NewDays+1 != DayList.length) {
      var OldSize = DayList.options.length;
	  for (var k=Math.min(NewDays+1,OldSize);k<Math.max(NewDays+1,OldSize);k++) {
         (k > NewDays) ?  DayList.options[NewDays+1] = null : DayList.options[k] = new Option(k,k);
      }
      DayPick = Math.min(DayPick-1, NewDays);
      DayList.options[DayPick].selected = true;
   }
   return DayPick;
}

function changeMonth(MonthList)
{
  var DayList = document.getElementById("_Day");
  var Year = document.getElementById("_Year");
  var YearValue = Year.value;
  if (MonthList.options[MonthList.selectedIndex].value == -1) {
      DayList.selectedIndex = 0;
   }
   else {
      var DayPick = FixDayList(DayList, GetDayCount(YearValue, MonthList.options[MonthList.selectedIndex].value));
   }
}

function changeYear()
{
  var MonthList = document.getElementById("_Month");
  changeMonth(MonthList);

  return true;
}

function WriteCalendar(day, month, year, bg)
{
  document.writeln('<select name="_Day" style="width:50px; '+bg+'">');
  var Selected = (day == -1) ? ' selected' : '';
  document.writeln('<option value="-1" '+Selected+'></option>');
  var iDay = GetDayCount(year, month);
  for (var j=1;j<=iDay;j++) {
	Selected = (day==j) ? ' selected' : '';
	document.writeln('<option' + Selected + '>' + j + '</option>');
  }
  document.writeln('</select>' + String.fromCharCode(13) + String.fromCharCode(13));
  document.writeln('<select name="_Month" onChange="changeMonth(this)" style="width:50px; '+bg+'">');
  Selected = (month == -1) ? ' selected' : '';
  document.writeln('<option value="-1" '+Selected+'></option>');
  for (var i=1;i<=12;i++) {
	Selected = (month==i) ? ' selected' : '';
	document.writeln('<option value="' + i + '"' + Selected + '>' + MNs[i-1].substr(0,3) + '</option>');
  }
  document.writeln('</select>' + String.fromCharCode(13));
  var value = year;
  document.writeln('<input class="input" type="text" style="width:60px; '+bg+'" name="_Year" id="_Year" size="3" maxlength="4" title="Year" value="'+value+'" onKeyUp="return changeYear();">');
}

function RemoveTags(text)
{
	i1 = text.search("<");
	while(i1>=0)
	{
		i2 = text.search(">");
		t = text.substring(0, i1)+text.substring(i2+1, text.length);
		text = t;
		i1 = text.search("<");
	}
	return text;
}

function CheckSellValue()
{
  var e = document.getElementById("limit_s");
  if (e.value<0)
  {
	  window.alert("Die Eingabe der ist fehlerhaft.");
	  return false;
  }

  return true;
}

function CheckBuyValue()
{
  var e = document.getElementById("limit_b");
  if (e.value<0)
  {
	  window.alert("Die Eingabe der ist fehlerhaft.");
	  return false;
  }

  return true;
}

function setFocus(field)
{
  document.getElementById( field ).focus();
}

function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
		while(1) {
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;

	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
		while(1) {
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;

	return curtop;
}

function swap_content( ul ) {
	displayType = ( document.getElementById( ul ).style.display == 'block' ) ? 'none' : 'block';
	document.getElementById( ul ).style.display = displayType;
}

function change_abled( input ) {
	state = ( document.getElementById( input ).disabled == false ) ? true : false;
	document.getElementById( input ).disabled = state;
}

function hilfe( foo ) {
    displayType = ( document.getElementById( foo ).style.display == 'block' ) ? 'none' : 'block';
    document.getElementById( foo ).style.display = displayType;
}

function extend() {
	if (document.getElementById('extend1'))
      document.getElementById('extend1').style.display = 'none';
      if (document.getElementById('extend2'))
	  document.getElementById('extend2').style.display = 'inline';
}

function tab(old, _new) {
	document.getElementById( old ).style.display = 'none';
	document.getElementById( _new ).style.display = 'block';

	HideCalendars();
}

function active_tab(_new) {
	if (document.getElementById( 'beschreibung' ))
		document.getElementById( 'beschreibung' ).style.display = 'none';
	if (document.getElementById( 'aehnliche' ))
		document.getElementById( 'aehnliche' ).style.display = 'none';
	if (document.getElementById( 'geboteangebote' ))
		document.getElementById( 'geboteangebote' ).style.display = 'none';
	if (document.getElementById( 'preisverlauf' ))
		document.getElementById( 'preisverlauf' ).style.display = 'none';
	if (document.getElementById( 'andereshops' ))
		document.getElementById( 'andereshops' ).style.display = 'none';
	if (document.getElementById( 'meinungen' ))
		document.getElementById( 'meinungen' ).style.display = 'none';
    if (document.getElementById( 'testberichte' ))
		document.getElementById( 'testberichte' ).style.display = 'none';

	document.getElementById( _new ).style.display = 'block';

	HideCalendars();
}

function str_replace(search, replace, subject) {
    return subject.split(search).join(replace);
}

function currencyFormat(n, currencySign, currencySignPosition, decimalDivider, thousandsDivider, notForField) {
   if (!isNaN(n)) {
		if (!currencySign) {currencySign = false;}
		if (!currencySignPosition) {currencySignPosition = false;}
		if (!decimalDivider) {decimalDivider = ".";}
		if (!thousandsDivider) {thousandsDivider = "";}
		if (!notForField) {notForField = false;}

      n = Math.round(n*100)/100;
      n = n.toString();

		nPart = n.split(".");

		var x = nPart[0].substr(0, nPart[0].length%3);
		for (var i = 0; i < Math.floor(nPart[0].length/3); i++) {
			if ((nPart[0].length%3 != 0) || (i > 0)) {
				x += thousandsDivider;
			}
			x += nPart[0].substr((nPart[0].length%3) + (i*3), 3);
		}

		if (!nPart[1]) {nPart[1] = "00";}
		if (nPart[1].length == 1) {nPart[1] += "0";}

      n = x + decimalDivider + nPart[1];
		if (currencySign) {
			n = (currencySignPosition) ? currencySign + " " + n : n + " " + currencySign;
		}
		if (notForField) {
			while (n.indexOf(" ") != -1) {
				n = n.replace(" ", "&nbsp;");
			}
		}
   }
   return n;
}

function standardPriceFormat_Intern(price) {
	price = price.replace(".", "");  // thousands separator
	price = price.replace(",", ".");

	return price;
}

function standardPriceFormat_Show(price) {
	price = currencyFormat(price, "", "", ",", ".", "");

	return price;
}

function preis_down(start) {

	start = standardPriceFormat_Intern(start);
	if (start == 0)
	       start = 500.00;

	var oldpreis = document.getElementById('limit_b').value;
	oldpreis = standardPriceFormat_Intern(oldpreis);
	var preis = (oldpreis-(start/100)).toFixed(2).toString();

	if (parseFloat(preis) < 0)
		preis = 0;

	check_preis(start, preis);
	preis = standardPriceFormat_Show(preis);
	document.getElementById('limit_b').value = preis;
}

function preis_up(start) {

	start = standardPriceFormat_Intern(start);

	if (start == 0)
		start = 500.00;

	var oldpreis = document.getElementById('limit_b').value;
	oldpreis = standardPriceFormat_Intern(oldpreis);
	var preis = (Number(oldpreis)+(start/100)).toFixed(2).toString();

	check_preis(start, preis);
	preis = standardPriceFormat_Show(preis);
	document.getElementById('limit_b').value = preis;
}

function check_preis(start, preis) {

	if (preis == standardPriceFormat_Show(preis))
		preis = standardPriceFormat_Intern(preis);
	if (start == standardPriceFormat_Show(start))
		start = standardPriceFormat_Intern(start);
	if (preis > 0 && start != preis)
	{
		document.getElementById('gebot_abgeben').style.display = 'inline';
		document.getElementById('gebot_abgeben_g').style.display = 'none';
	}
	else
	{
		document.getElementById('gebot_abgeben').style.display = 'none';
		document.getElementById('gebot_abgeben_g').style.display = 'inline';
	}

	if(preis != start) {
		if(document.getElementById('plus_inaktiv').style.display != 'none') {
			document.getElementById('plus_inaktiv').style.display = 'none';
			document.getElementById('plus_aktiv').style.display = 'block';
		}
	} else {
		if(document.getElementById('plus_inaktiv').style.display == 'none') {
			document.getElementById('plus_inaktiv').style.display = 'block';
			document.getElementById('plus_aktiv').style.display = 'none';
		}
	}
}

/**
 *	Estimates, if the entered bid on a product page has a good chance to be
 *	handled or not and displays the corresponding block.
 *
 *	@param: float start - initial value of the price
 *	@param: float price - bid price
 */
function estimateBid(start, price)
{
	if (document.getElementById('estimation') == null)
		return;

	start = standardPriceFormat_Intern(start);
	price = standardPriceFormat_Intern(price);
	var percent = 0;
	if (start != 0)
		percent = Math.round(100 * (1 - price / start));

	if (percent > 10)
	{
		document.getElementById('estimation_orange').style.display = 'block';
		document.getElementById('estimation_yellow').style.display = 'none';
		document.getElementById('estimation_green').style.display = 'none';
	}
	else if (percent > 3)
	{
		document.getElementById('estimation_orange').style.display = 'none';
		document.getElementById('estimation_yellow').style.display = 'block';
		document.getElementById('estimation_green').style.display = 'none';
	}
	else
	{
		document.getElementById('estimation_orange').style.display = 'none';
		document.getElementById('estimation_yellow').style.display = 'none';
		document.getElementById('estimation_green').style.display = 'block';
	}

	if (start == price || start == 0)
		document.getElementById('estimation').style.display = 'none';
	else
		document.getElementById('estimation').style.display = 'block';
}

function enable_trade_buttons() {
	if (!document.getElementById('sofort_kaufen'))
		document.getElementById('gebot_abgeben_tab').style.display = 'inline';
}

function adresse1() {
 	var anzahl = document.getElementById('address1').length;
 	for (var i = 0; i < anzahl; i++) {
 		if(i == document.getElementById('address1').selectedIndex)
 			document.getElementById('adr1' + (i+1)).style.display = 'inline';
 		else
 			document.getElementById('adr1' + (i+1)).style.display = 'none';
 	}
}

function adresse2() {
 	var anzahl = document.getElementById('address2').length;
 	for (var i = 0; i < anzahl; i++) {
 		if(i == document.getElementById('address2').selectedIndex)
 			document.getElementById('adr2' + (i+1)).style.display = 'inline';
 		else
 			document.getElementById('adr2' + (i+1)).style.display = 'none';
 	}
}

function navilink(_neu)
{
	var elements = new Array('mitmachen', 'buttons', 'teilnehmer');

	for (var i = 0; i < elements.length; i++)
	{
		document.getElementById('navi_' + elements[i]).style.background = 'transparent';
		document.getElementById('navi_' + elements[i]).style.color = '';
		document.getElementById('navi_' + elements[i]).style.textDecoration = '';
		document.getElementById(elements[i]).style.display = 'none';
	}

	document.getElementById('navi_' + _neu).style.background = '#fff';
	document.getElementById('navi_' + _neu).style.color = '#000';
	document.getElementById('navi_' + _neu).style.textDecoration = 'none';

	document.getElementById(_neu).style.display = 'block';

	if(_neu == 'mitmachen')
	{
		document.getElementById('wwf').style.display = 'block';
		document.getElementById('panda').style.display = 'block';
		document.getElementById('stern').style.display = 'block';
		document.getElementById('formular').style.display = 'none';
	}
	else
	{
		document.getElementById('wwf').style.display = 'none';
		document.getElementById('panda').style.display = 'none';
		document.getElementById('stern').style.display = 'none';
		document.getElementById('formular').style.display = 'block';
	}
}

function stripHtml(text)
{
	// remove simple HTML-tags out of text
	return text.replace(/<\/?[^>]+>/gi, '');
}

function FFSuggest() {

	var pRequest;
	var pLayer;
	var pDebug					= false;
	var pSearchURL				= "";
	var pQueryParamName			= "";
	var pForm 					= null
		var pLayerName				= "";
	var pAnchor;
	var pTemplate;
	var pQueryInput;
	var pSuggest				= new Array();
	var pLastQuery;
	var pCurrentSelection		= 0;
	var submitted				= false;

	this.init = function(searchURL, formid, queryParamName, queryFieldId, divLayername, debugMode) {
		pSearchURL		= searchURL;
		pForm			= document.getElementById(formid);
		pQueryParamName	= queryParamName;
		pLayerName		= divLayername;
		pDebug			= debugMode;

		if (pSearchURL == "") {
			if (pDebug) alert("no searchurl defined");
			return null;
		} else if (pForm == null) {
			if (pDebug) alert("no form found");
			return null;
		} else if (pQueryParamName == "") {
			if (pDebug) alert("no queryparamname defined");
			return null;
		} else if (pLayerName == "") {
			if (pDebug) alert("need a layer for output");
		}

		pQueryInput = document.getElementById(queryFieldId);
		pQueryInput.onkeyup	= handleKeyPress;
		pQueryInput.onblur	= hideLayer;

		pTemplate = document.getElementById("suggestRow");
		pAnchor = document.getElementById("suggestAnchor");
		pAnchor.removeChild(pTemplate);

		pForm.onsubmit = handleSubmit;
	}

	function handleSubmit() {
		submitted = true;
		if (pSuggest[pCurrentSelection] != undefined) {
			if (pSuggest[pCurrentSelection].split('###')[1] != "Kategorie") {
				pQueryInput.value = pSuggest[pCurrentSelection].split('###')[0];
			}
		}
	}

	this.handleClick = function() {
		if (pSuggest[pCurrentSelection] != undefined) {
			if (pSuggest[pCurrentSelection].split('###')[1] == "Kategorie") {
				pForm.elements["filterkategorie"].value = "__" + pSuggest[pCurrentSelection].split('###')[0] + "__";
				pQueryInput.value = "";
				pForm.submit();
			}
			else {
				pQueryInput.value = pSuggest[pCurrentSelection].split('###')[0];
				pForm.submit();
			}
		}
	}

	this.handleMouseOver = function(elem) {
		highlightSuggest(elem);
		pCurrentSelection = elem.getAttribute("id").split('_')[1];
	}

	this.handleMouseOut = function(elem) {
		unmarkSuggest(elem);
		pCurrentSelection = -1;
	}

	function handleKeyPress(evt) {
		evt = (evt) ? evt : ((event) ? event : null);
		var keyCode = evt.keyCode;
		if (keyCode == 38) {
			moveSelection("up")
		} else if (keyCode == 40) {
			moveSelection("down");
		} else {
			if (pQueryInput.value == "") {
				hideLayer();
				return null;
			}
			if (pLastQuery != pQueryInput.value) startAjax();
			pLastQuery = pQueryInput.value;
		}
	}

	function moveSelection(direction) {
		var pos = pCurrentSelection;
		if (direction == "up")	pos--;
		else 					pos += 1;

		if (pos < 0) {
			unmarkAll();
			pQueryInput.focus();
			pCurrentSelection	= -1;
		} else {
			var tblCell = getTableCell(pos);
			if (tblCell != null) {
				unmarkAll();
				highlightSuggest(tblCell);
				pCurrentSelection = pos;
			}
		}

		var query = pQueryInput.value;
		pQueryInput.value = "";
		pQueryInput.focus();
		pQueryInput.value = query;
	}

	function startAjax() {
		var query = pQueryInput.value;
		var requestURL = pSearchURL + "?" + pQueryParamName + "=" + escape(query);

		try {
			if( window.XMLHttpRequest ) {
				pRequest = new XMLHttpRequest();
			} else if( window.ActiveXObject ) {
				pRequest = new ActiveXObject( "Microsoft.XMLHTTP" );
			} else {
				if (pDebug) alert( "" );
			}

			pLayer = document.getElementById(pLayerName);
			if (pLayer != null) {
				if (query != "") {

					pRequest.open( "GET", requestURL, true );
					pRequest.onreadystatechange = callbackAjax;
					pRequest.send( null );
				} else {
					hideLayer();
				}
			} else {
				if (pDebug) alert( "no layer for output found" );
			}
		} catch( ex ) {
			hideLayer();
			if (ex == undefined) {
				if (pDebug) alert( "Error: " + ex.getmessage );
			} else {
				if (pDebug) alert( "Error: " + ex );
			}
		}
	}

	function hideLayer() {
		if (pLayer != null) {
			pLayer.style.display = "none";
		}
	}


	function showLayer() {
		if (pLayer != null && pSuggest != null && pSuggest.length >= 1) {
			pLayer.style.display	= "block";
		}
	}

	// Make public
	this.hideLayer = hideLayer;
	this.showLayer = showLayer;

	function callbackAjax() {
		if (submitted == false) {
			if (pRequest.readyState == 4) {
				if (pRequest.status != 200) {
					hideLayer();
					if (pDebug) alert( "Error (" + pRequest.status + "): " + pRequest.statusText );
				} else {
					handleResponse(pRequest.responseText);
				}
			}
		}
	}

	function handleResponse(text) {
		pCurrentSelection = -1;
		pSuggest = new Array();
		pSuggest = text.split("\n");

		var pNewSuggest = new Array();
		for (var i in pSuggest) {
			var firstChar = pSuggest[i].charCodeAt(0);
			if (firstChar != 13 && firstChar != 10 && pSuggest[i].length >= 1) {
				pNewSuggest.push(pSuggest[i]);
			}
		}
		pSuggest = pNewSuggest;

		var query = pQueryInput.value;

		while (node = pAnchor.childNodes[0])
		{
			node = pAnchor.removeChild(node);
			delete node;
		}

		for (var i in pSuggest) {
			pSuggestParts = new Array();
			pSuggestParts = pSuggest[i].split("###");

			var newNode = pTemplate.cloneNode(true);
			newNode.setAttribute("id", "suggestRow_" + i);
			newNode.onmouseover = function() { suggest.handleMouseOver(this); }
			newNode.onmouseout = function() { suggest.handleMouseOut(this); }

			for (var i = 0; i < newNode.childNodes.length; i++) {
				var node = newNode.childNodes[i];
				if (!node.firstChild)
					continue;

				if (node.firstChild.data == "Text")
					node.firstChild.data = pSuggestParts[0];
				else if(node.firstChild.data == "Typ")
					node.firstChild.data = pSuggestParts[2];
				else if(node.firstChild.data == "Anzahl")
					node.firstChild.data = pSuggestParts[1];
			}

			pAnchor.appendChild(newNode);
		}

		if (pSuggest.length >= 1)
			showLayer();
		else
			hideLayer();
	}

	function highlightSuggest(tblCell) {
		tblCell.className = "highlight";
	}

	function unmarkSuggest(tblCell) {
		tblCell.className = "";
	}

	function unmarkAll() {
		for (var i = 0; i < pAnchor.childNodes.length; i++)
			unmarkSuggest(pAnchor.childNodes[i]);
	}

	function getTableCell(pos) {
		return document.getElementById("suggestRow_" + pos);
	}
}

function ExorbyteSuggest()
{
	var pRequest;
	var pLayer;
	var pDebug					= false;
	var pSearchURL				= "";
	var pQueryParamName			= "";
	var pForm 					= null
	var pLayerName				= "";
	var pAnchor;
	var pTemplate;
	var pQueryInput;
	var pSuggest				= new Array();
	var pLastQuery;
	var pCurrentSelection		= 0;
	var submitted				= false;

	this.init = function(searchURL, formid, queryParamName, queryFieldId, divLayername, debugMode) {
		pSearchURL		= searchURL;
		pForm			= document.getElementById(formid);
		pQueryParamName	= queryParamName;
		pLayerName		= divLayername;
		pDebug			= debugMode;

		if (pSearchURL == "") {
			if (pDebug) alert("no searchurl defined");
			return null;
		} else if (pForm == null) {
			if (pDebug) alert("no form found");
			return null;
		} else if (pQueryParamName == "") {
			if (pDebug) alert("no queryparamname defined");
			return null;
		} else if (pLayerName == "") {
			if (pDebug) alert("need a layer for output");
		}

		pQueryInput = document.getElementById(queryFieldId);
		pQueryInput.onkeyup	= handleKeyPress;
		pQueryInput.onblur	= hideLayer;

		pTemplate = document.getElementById("suggestRow");
		pAnchor = document.getElementById("suggestAnchor");
		pAnchor.removeChild(pTemplate);

		pForm.onsubmit = handleSubmit;
	}

	function handleSubmit() {
		submitted = true;
		if (pSuggest[pCurrentSelection] != undefined)
			pQueryInput.value = pSuggest[pCurrentSelection].text;
	}

	this.handleClick = function() {
		if (pSuggest[pCurrentSelection] != undefined) {
			pQueryInput.value = pSuggest[pCurrentSelection].text;
			pForm.submit();
		}
	}

	this.handleMouseOver = function(elem) {
		highlightSuggest(elem);
		pCurrentSelection = elem.getAttribute("id").split('_')[1];
	}

	this.handleMouseOut = function(elem) {
		unmarkSuggest(elem);
		pCurrentSelection = -1;
	}

	function handleKeyPress(evt) {
		evt = (evt) ? evt : ((event) ? event : null);
		var keyCode = evt.keyCode;
		if (keyCode == 38) {
			moveSelection("up")
		} else if (keyCode == 40) {
			moveSelection("down");
		} else {
			if (pQueryInput.value == "") {
				hideLayer();
				return null;
			}
			if (pLastQuery != pQueryInput.value) startAjax();
			pLastQuery = pQueryInput.value;
		}
	}

	function moveSelection(direction) {
		var pos = pCurrentSelection;
		if (direction == "up")	pos--;
		else 					pos += 1;

		if (pos < 0) {
			unmarkAll();
			pQueryInput.focus();
			pCurrentSelection	= -1;
		} else {
			var tblCell = getTableCell(pos);
			if (tblCell != null) {
				unmarkAll();
				highlightSuggest(tblCell);
				pCurrentSelection = pos;
			}
		}

		var query = pQueryInput.value;
		pQueryInput.value = "";
		pQueryInput.focus();
		pQueryInput.value = query;
	}

	function startAjax() {
		var query = pQueryInput.value;
		var requestURL = pSearchURL + "?" + pQueryParamName + "=" + escape(query);

		try {
			if( window.XMLHttpRequest ) {
				pRequest = new XMLHttpRequest();
			} else if( window.ActiveXObject ) {
				pRequest = new ActiveXObject( "Microsoft.XMLHTTP" );
			} else {
				if (pDebug) alert( "" );
			}

			pLayer = document.getElementById(pLayerName);
			if (pLayer != null) {
				if (query != "") {

					pRequest.open( "GET", requestURL, true );
					pRequest.onreadystatechange = callbackAjax;
					pRequest.send( null );
				} else {
					hideLayer();
				}
			} else {
				if (pDebug) alert( "no layer for output found" );
			}
		} catch( ex ) {
			hideLayer();
			if (ex == undefined) {
				if (pDebug) alert( "Error: " + ex.getmessage );
			} else {
				if (pDebug) alert( "Error: " + ex );
			}
		}
	}

	function hideLayer() {
		if (pLayer != null) {
			pLayer.style.display = "none";
		}
	}


	function showLayer() {
		if (pLayer != null && pSuggest != null && pSuggest.length >= 1) {
			pLayer.style.display	= "block";
		}
	}

	// Make public
	this.hideLayer = hideLayer;
	this.showLayer = showLayer;

	function callbackAjax() {
		if (submitted == false) {
			if (pRequest.readyState == 4) {
				if (pRequest.status != 200) {
					hideLayer();
					if (pDebug) alert( "Error (" + pRequest.status + "): " + pRequest.statusText );
				} else {
					handleResponse(pRequest.responseText);
				}
			}
		}
	}

	function handleResponse(text)
	{
		pCurrentSelection = -1;
		text = eval('(' + text + ')');
		pSuggest = new Array();

		for (var k in text)
			pSuggest.push(text[k]);

		while (node = pAnchor.childNodes[0])
		{
			node = pAnchor.removeChild(node);
			delete node;
		}

		for (var i in pSuggest)
		{
			pSuggestParts = new Array();
			pSuggestParts[0] = pSuggest[i].text.substr(0, 50);

			if (pSuggestParts[0] < pSuggest[i].text)
				pSuggestParts[0] += '...';

			if (pSuggest[i].data.Type == 'article')
				pSuggestParts[1] = '';
			else
			{
				if (pSuggest[i].data.AID < 1)
					pSuggestParts[1] = '';
				else if (pSuggest[i].data.AID == 1)
					pSuggestParts[1] = pSuggest[i].data.AID + ' Produkt';
				else
					pSuggestParts[1] = pSuggest[i].data.AID + ' Produkte';
			}

			switch (pSuggest[i].data.Type)
			{
				case 'article':
					pSuggestParts[2] = 'Produkt';
					break;

				case 'brand':
					pSuggestParts[2] = 'Hersteller';
					break;

				case 'category':
					pSuggestParts[2] = 'Kategorie';
					break;

				case 'suggestion':
					pSuggestParts[2] = 'Suchbegriff';
					break;

				default:
					pSuggestParts[2] = '';
			}

			var newNode = pTemplate.cloneNode(true);
			newNode.setAttribute("id", "suggestRow_" + i);
			newNode.onmouseover = function() { suggest.handleMouseOver(this); }
			newNode.onmouseout = function() { suggest.handleMouseOut(this); }

			for (var i = 0; i < newNode.childNodes.length; i++)
			{
				var node = newNode.childNodes[i];
				if (!node.firstChild)
					continue;

				if (node.firstChild.data == "Text")
					node.firstChild.data = pSuggestParts[0];
				else if(node.firstChild.data == "Typ")
					node.firstChild.data = pSuggestParts[2];
				else if(node.firstChild.data == "Anzahl")
					node.firstChild.data = pSuggestParts[1];
			}

			pAnchor.appendChild(newNode);
		}

		if (pSuggest.length >= 1)
			showLayer();
		else
			hideLayer();
	}

	function highlightSuggest(tblCell) {
		tblCell.className = "highlight";
	}

	function unmarkSuggest(tblCell) {
		tblCell.className = "";
	}

	function unmarkAll() {
		for (var i = 0; i < pAnchor.childNodes.length; i++)
			unmarkSuggest(pAnchor.childNodes[i]);
	}

	function getTableCell(pos) {
		return document.getElementById("suggestRow_" + pos);
	}
}

function show_kategorie() {
	document.getElementById('show_all').style.display = 'none';
	document.getElementById('kategorien_scroll').style.border = 'none';
	document.getElementById('kategorien_scroll').style.overflow = 'visible';
	document.getElementById('kategorien_scroll').style.height = 'auto';
	document.getElementById('kategorien_scroll').style.padding = '0';
}

var cDate=new Date();
cDate.setTime(cDate.getTime()+86400000);
cDate.setDate(1);
var MNs = new Array('Jan','Feb','Mär','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez');
var Calendar = new Array();
var cal = new Object();
cal.cYear=cDate.getFullYear();
cal.cMonth=cDate.getMonth();
cal.cDay=cDate.getDate();
Calendar[0]=cal;

function setCalendar(dt, c) {
  Calendar[c].cYear=dt.getFullYear();
  Calendar[c].cMonth=dt.getMonth();
  Calendar[c].cDay=dt.getDate();
  firstDay = dt.getDay();
  for(i = 0; i < 42; i++){
    var e = document.getElementById(c+"B"+i);
	if (!e) continue;
	e.innerHTML = "";
  }
  if ((firstDay-2)<-1)
    firstDay +=7;
  dayspermonth = getDaysPerMonth(c);
  aD=new Date();
  for(i = 1; i < dayspermonth+1; i++){
    i1=i;
	var e = document.getElementById(c+"B"+(i+firstDay-2));
	if (!e) continue;
	D=new Date(Calendar[c].cYear, Calendar[c].cMonth, i1);
	if (D<=aD)
		e.innerHTML = "<div class=gray>"+i1+"</div>";
    else
	  e.innerHTML = "<a class=button href=\"javascript:ShowDate('"+c+"B"+(i+firstDay-2)+"', "+c+");\">"+i1+"</a>";
  }
  var e = document.getElementById(c+"month");
  if (e)
    e.innerHTML = MNs[Calendar[c].cMonth]+" "+Calendar[c].cYear;
}

function nextM(c){
  Calendar[c].cMonth++;
  if (Calendar[c].cMonth>11) {Calendar[c].cMonth = 0;Calendar[c].cYear++;}
  setCalendar(new Date(Calendar[c].cYear,Calendar[c].cMonth,1), c);
}

function preM(c){
  Calendar[c].cMonth--;
  if (Calendar[c].cMonth<0) {Calendar[c].cMonth = 11;Calendar[c].cYear--;}
  setCalendar(new Date(Calendar[c].cYear,Calendar[c].cMonth,1), c);
}

function getDaysPerMonth(c){
  daysArray=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  days=daysArray[Calendar[c].cMonth];
  if (Calendar[c].cMonth==1){
    if((Calendar[c].cYear% 4) == 0) {
      if(((Calendar[c].cYear% 100) == 0) && (Calendar[c].cYear% 400) != 0)
        days = 28;
      else
        days = 29;
    }
  }
  return days;
}

function ShowDate(temp, c){
  var e = document.getElementById(Calendar[c].field);
  var e1 = document.getElementById(temp);
  temp = e1.innerHTML;
  Calendar[c].cDay=RemoveTags(temp);
  d = Calendar[c].cDay;
  if (d<10) d = "0" + d;
  m = Calendar[c].cMonth+1;
  if (m<10) m = "0" + m;
  if (Calendar[c].format==1)
    strA=d + "." + m + "." + Calendar[c].cYear;
  else if (Calendar[c].format==2)
    strA=Calendar[c].cYear + "-" + m + "-" + d;
  e.value = strA;
  HideCalendar(c);
}

function ShowCalendar(temp, top, left)
{
  var e = document.getElementById("calendar"+temp);
  if (!e) return;
  e.style.display = "inline";
  e.style.top = top;
  e.style.left = left;
}

function HideCalendar(temp)
{
  var e = document.getElementById("calendar"+temp);
  if (!e) return;
  e.style.display = "None";
}

function HideCalendars()
{
  for(i=1;i<Calendar.length;i++)
	HideCalendar(i);
}

function OnChangeEnd(combo, edit, first)
{
  var c = document.getElementById(combo);
  var e = document.getElementById(edit);
  if (!c || !e) return;

  if (first && e.value!="") return;

  days = Number(c.value);

  Calendar[0].cYear=cDate.getFullYear();
  Calendar[0].cMonth=cDate.getMonth();
  Calendar[0].cDay=cDate.getDate();

  d = Number(Calendar[0].cDay + days);
  while(d > getDaysPerMonth(0))
  {
	d -= getDaysPerMonth(0);
    Calendar[0].cDay = 1;
	Calendar[0].cMonth++;
	if (Calendar[0].cMonth>12) {Calendar[0].cMonth = 1; Calendar[0].cYear++;}
  }
  Calendar[0].cDay = d;
  strA=Calendar[0].cDay + "." + (Calendar[0].cMonth+1) + "." + Calendar[0].cYear;
  e.value = strA;
}

function addCalendar(c, f, format, http)
{
var cal = new Object();
cal.cYear=cDate.getFullYear();
cal.cMonth=cDate.getMonth();
cal.cDay=cDate.getDate();
cal.field = f;
cal.format = format;

Calendar[c]=cal;

if (http) http = "http";
else http = "https";

document.write("<div id=\"calendar"+c+"\" class=\"calendar\">\r\n");
document.write("<table width=\"100%\" border=\"0\" cellpadding=1 cellspacing=0 bordercolor=\"#000000\">\r\n");
document.write("<tr class=top bgcolor=\"#707070\" style=\"background-color:#707070\">\r\n");
document.write("<td class=top><a href=\"javascript:preM("+c+");\"><img border=\"0\" src=\""+http+"://www.gimahhot.de/images/layout/backward.gif\"></a></td>\r\n");
document.write("<td class=top colspan=\"5\" align=\"center\"><div id=\""+c+"month\" style=\"display:inline;color:white;font-weight:bold;\">a</div></td>\r\n");
document.write("<td class=top align=\"right\"><a href=\"javascript:nextM("+c+");\"><img border=\"0\" src=\""+http+"://www.gimahhot.de/images/layout/forward.gif\"></a></td>\r\n");
document.write("</tr>\r\n");
document.write("<tr>\r\n");
document.write("<td class=\"month\">M</td>\r\n");
document.write("<td class=\"month\">D</td>\r\n");
document.write("<td class=\"month\">M</td>\r\n");
document.write("<td class=\"month\">D</td>\r\n");
document.write("<td class=\"month\">F</td>\r\n");
document.write("<td class=\"month\"><font color=\"red\">S</font></td>\r\n");
document.write("<td class=\"month\"><font color=\"red\">S</font></td>\r\n");
document.write("</tr>\r\n");
document.write("<tr>\r\n");
document.write("<td><div id=\""+c+"B0\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B1\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B2\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B3\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B4\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B5\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B6\">-</div></td>\r\n");
document.write("</tr>\r\n");
document.write("<tr>\r\n");
document.write("<td><div id=\""+c+"B7\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B8\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B9\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B10\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B11\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B12\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B13\">-</div></td>\r\n");
document.write("</tr>\r\n");
document.write("<tr>\r\n");
document.write("<td><div id=\""+c+"B14\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B15\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B16\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B17\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B18\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B19\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B20\">-</div></td>\r\n");
document.write("</tr>\r\n");
document.write("<tr>\r\n");
document.write("<td><div id=\""+c+"B21\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B22\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B23\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B24\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B25\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B26\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B27\">-</div></td>\r\n");
document.write("</tr>\r\n");
document.write("<tr>\r\n");
document.write("<td><div id=\""+c+"B28\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B29\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B30\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B31\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B32\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B33\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B34\">-</div></td>\r\n");
document.write("</tr>\r\n");
document.write("<tr>\r\n");
document.write("<td><div id=\""+c+"B35\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B36\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B37\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B38\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B39\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B40\">-</div></td>\r\n");
document.write("<td><div id=\""+c+"B41\">-</div></td>\r\n");
document.write("</tr>\r\n");
document.write("<tr>\r\n");
document.write("<td colspan=7 align=center><a href='javascript:HideCalendar("+c+");'>Schließen</a></td>\r\n");
document.write("</tr>\r\n");
document.write("</table>\r\n");
document.write("</div>\r\n");
}

function scrollPageToTop()
{
	var y = 0;

	if (window.pageYOffset)
		y = window.pageYOffset;
	else if (document.documentElement.scrollTop)
		y = document.documentElement.scrollTop;
	else if (document.body.scrollTop)
		y = document.body.scrollTop;
	else
		window.scrollTo(0, 0);

	if (y > 0)
	{
		window.scrollBy(0, -20);
		setTimeout("scrollPageToTop()", 5);
	}
}

function scrollToElement(element)
{
	var y = element.offsetTop;
	var parentElement = element.offsetParent;

	while (parentElement)
	{
		y += parentElement.offsetTop;
		parentElement = parentElement.offsetParent;
	}

	window.scrollTo(0, y);
}

/*
 * Display and hide block elements (div containers)
 * The elements will be added dynamically, after they've been choosen
 */
function Rollercoaster()
{
	// private
	var in_progress = false;
	var elements = new Array();

	/*
	 * Just display or hide the container
	 */
	this.flap = function(element, close_active)
	{
		in_progress = true;

		var e = document.getElementById(element);

		// the content will be displayed -> close the container or not
		if (e.style.display == 'block' && !close_active)
		{
			in_progress = false;
			return;
		}

		var element_found = false;
		for (var i = 0; i < elements.length; i++)
		{
			if (elements[i] == element)
			{
				element_found = true;
				break;
			}
		}

		if (!element_found)
			elements.push(element);

		for (x in elements)
		{
			if (document.getElementById(elements[x]).style.display == 'block')
				document.getElementById(elements[x]).style.display = 'none';
			else if (elements[x] == element && e.style.display == 'none')
				document.getElementById(elements[x]).style.display = 'block';
		}

		in_progress = false;
	}
}

