    var _disabled_submit = false;
    
    function create_combo(pContenerName, pName, pData, pWidth, pSelected, pCut){

	var combo = document.createElement('DIV');
	combo.setAttribute('id',pName);
	combo.className = 'combo';
	if (pWidth){
	  combo.style.width = pWidth;
	}
	
	var text = null;

	if (pCut){
	  text = document.createElement('INPUT');
	  text.setAttribute('id',pName+'Text');
	  text.className='comboTextInput';
	} else {
	  text = document.createElement('DIV');
	  text.setAttribute('id',pName+'Text');
	  text.className = 'comboText';
	}
	combo.appendChild(text);
	
	var button = document.createElement('BUTTON');
	button.setAttribute('type','button');
	button.className = 'comboBtn';
	button.setAttribute('id',pName+'Btn');
	combo.appendChild(button);
	
	var clear = document.createElement('DIV');
	clear.className = 'clear';
	combo.appendChild(clear);
	
	var list = document.createElement('DIV');
	list.setAttribute('id',pName+'List');
	list.className = 'comboList';
	combo.appendChild(list);
	
	var p = document.createElement('P');
	p.setAttribute('value',-1);
	if (pCut){
	  p.innerHTML = '';
	} else {
	  p.innerHTML = '- - -';
	}
	p.className = 'comboItem';
	list.appendChild(p);
	
	for (var i=0; i<pData.length; i++){
	  p = document.createElement('P');
	  p.innerHTML = pData[i]['label'];
	  p.setAttribute('value',pData[i]['id']);
	  if (pSelected == pData[i]['id']){
		p.setAttribute('selected','selected');
	  }
	  p.className = 'comboItem';
	  list.appendChild(p);
	}
	
	//'<input type="hidden" id="'.$name.'Value" name="'.$name.'">'
	var input = document.createElement('INPUT');
	input.setAttribute('id',pName+'Value');
	input.setAttribute('name',pName);
	input.setAttribute('type','hidden');
	
	combo.appendChild(input);
	combo.appendChild(list);
	pContenerName.appendChild(combo);
	
	
  }
  
  function combo_build(pName, pOnChange, pWidth, pDisabled){
    var list = document.getElementById(pName+"List");

	if (pOnChange){
	  list.onchange = pOnChange;
	}
    
    list.setAttribute('dcombo',pName);
    var selectedOption = -1;
    for (var t=0; t<list.childNodes.length; t++){
      
      if (list.childNodes[t].nodeName == "P"){
	list.childNodes[t].onmouseover=( function(n,m){ return function(){combo_mo(n,m);} } )( list, list.childNodes[t] );;
	list.childNodes[t].onclick=( function(n,m){ return function(){combo_select(n,m);} } )( list, list.childNodes[t] );;
	if (selectedOption == -1){
	  selectedOption = t;
	}
	//alert(list.childNodes[t].getAttribute())
	if (list.childNodes[t].getAttribute('selected') != null){
	  selectedOption = t;
	}
      }
    }

    if (selectedOption>-1){
      combo_select(list,list.childNodes[selectedOption], true);
      combo_mo(list,list.childNodes[selectedOption]);
    }

    var btn = document.getElementById(pName+'Btn');
    
    if (!pDisabled){
      jattacheEvent(btn,'click',function(){  combo_open(pName) });
    }
    
    if (list.addEventListener){
      jattacheEvent(list,'mouseup',function(event){  event.stopPropagation() });
    }
    
    jattacheEvent(document.body,'mouseup',function(){  if (window.comboList){combo_close(window.comboList)} });
    


    var combo = $(pName);
    var text = $(pName+'Text');
    var list = $(pName+'List');

    if (text.nodeName == 'INPUT' || text.nodeName == 'input'){
//alert('ddd')
      jattacheEvent(text,'keyup',combo_cutList);
      if (!pDisabled){
	jattacheEvent(text,'focus',combo_cutList);
      }
      jattacheEvent(btn,'keyup',function(event){ if (event.which != 8 && event.which != 46){text.value=String.fromCharCode(event.which).toLowerCase()} else {text.value=''} ; text.focus() });
    }
    
	if (pWidth == 'null') {
	  if (list.offsetWidth > text.offsetWidth){
		//alert(pName)
		combo.style.width = list.offsetWidth +3+ btn.offsetWidth+"px";
		text.style.width = (list.offsetWidth-2) + "px";
	  }
	  
	  if (list.offsetWidth < text.offsetWidth){
		//alert(pName)
		combo.style.width = list.offsetWidth +3+ btn.offsetWidth+"px";
		text.style.width = (list.offsetWidth-2) + "px";
	  }
  
	  if (document.getElementById(pName+'Text').offsetWidth-4-2+btn.offsetWidth > list.offsetWidth){
		list.style.width = document.getElementById(pName+'Text').offsetWidth-4-2+btn.offsetWidth+"px";
	  }
	} else {
		//combo.style.width = pWidth+"px";
		pWidth = combo.offsetWidth;

		combo.style.width = (pWidth+2)+'px';
		pWidth += 2;

		//combo.style.width = pWidth+3+"px";
		text.style.width = (pWidth-btn.offsetWidth-5) + "px";
		if (btn.offsetTop != text.offsetTop){
		  text.style.width = (pWidth-btn.offsetWidth-6) + "px";
		}
		if (list.offsetWidth < pWidth){
		  list.style.width = (pWidth-2-4)+"px";
		}
		
	}
    //280
	if (list.offsetHeight > 280){
	  list.style.width = (list.offsetWidth+15)+'px';
	  list.style.height = '280px';
	  list.style.overflowY = 'auto';
	  list.style.overflowX = 'hidden';
	}
    //alert($(pName));
  }

  function combo_cutList(event){
    var val;
    var cName = null;
    if (event.srcElement){
      val = event.srcElement.value;
      cName = event.srcElement.id.substring(0,event.srcElement.id.length-4);
    } else if (event.target){
      val = event.target.value;
      cName = event.target.id.substring(0,event.target.id.length-4);
    }

    combo_force_open(cName)
    var list = $(cName+'List');
//    alert(list.childNodes.length)
    for (var x=0; x<list.childNodes.length; x++){

      if (list.childNodes[x].innerHTML.toLowerCase().indexOf(val.toLowerCase()) != 0){
	list.childNodes[x].style.display='none';
      } else {
	list.childNodes[x].style.display='';
      }
    }
    $key = null;
    if (event.which){
      $key = event.which;
    }

    if ($key == 40){
      var changed = false;

      for (var x=0; x<list.childNodes.length; x++){

	if (list.childNodes[x].style.display != 'none' && list.childNodes[x].className == 'comboItemMouseOver'){
	  if (x+1 < list.childNodes.length){
	    for (var k=x+1; k<list.childNodes.length; k++){

	      if (list.childNodes[k].style.display != 'none'){


		if (list.childNodes[k].offsetTop+list.childNodes[k].offsetHeight > list.offsetHeight){
		  list.scrollTop  += list.childNodes[k].offsetHeight;
		}

		combo_mo(list, list.childNodes[k])
		changed = true;
		break;
	      }
	    }
	  }
	  break;
	}

      }

      if (!changed){
	  for (var k=0; k<list.childNodes.length; k++){
	    if (list.childNodes[k].style.display != 'none'){
	      combo_mo(list, list.childNodes[k])
	      list.scrollTop = 0;
	      break;
	    }
	  }
      }
      
    }

    if ($key == 38){
      var changed = false;

      for (var x=0; x<list.childNodes.length; x++){

	if (list.childNodes[x].style.display != 'none' && list.childNodes[x].className == 'comboItemMouseOver'){
	  if (x > 0){
	    for (var k=x-1; k>=0; k--){

	      if (list.childNodes[k].style.display != 'none'){
		combo_mo(list, list.childNodes[k])
		changed = true;
//alert(list.maxVPosition)
		if (list.childNodes[k].offsetTop < list.scrollTop){
		  list.scrollTop  -= list.childNodes[k].offsetHeight;
		}
		break;
	      }
	    }
	  }
	  break;
	}


      }

      if (!changed){
	  for (var k=list.childNodes.length-1; k>0; k--){
	    if (list.childNodes[k].style.display != 'none'){
	      combo_mo(list, list.childNodes[k])
	      list.scrollTop = 10000;
	      break;
	    }
	  }
      }

    }

    if ($key == 13){
      for (var x=0; x<list.childNodes.length; x++){
	if (list.childNodes[x].style.display != 'none' && list.childNodes[x].className == 'comboItemMouseOver'){
	  combo_select(list, list.childNodes[x])
	}
      }
      
      if (list.addEventListener){
	event.stopPropagation();
      } else {
	
      }
      return false;
    }

//    alert(event.which);
    //alert(val+" "+cName)
  }

  function jattacheEvent(pElem, pEvent, pFunction){
    if (pElem.addEventListener){
	pElem.addEventListener (pEvent, pFunction, false);
    } else if (pElem.attachEvent) {
	pElem.attachEvent ("on"+pEvent,pFunction);
    } else {
	pElem["on"+pEvent] = pFunction;
    }
  }

  function combo_mo(pList, pItem){

    if (pList.lastMO){
      pList.lastMO.className='comboItem';
    }

    pItem.className='comboItemMouseOver';
    pList.lastMO = pItem;
  }

  function combo_close(pDivId){
    document.getElementById(pDivId+'List').style.visibility='hidden';
    window.comboList = null;
    _disabled_submit = false;
    //document.onclick=null;
  }

  function combo_select(pList, pItem, pInit){
    var cName = pList.getAttribute('dcombo');
    var listText = document.getElementById(cName+'Text');
    var listValue = document.getElementById(cName+'Value');
    if (listText.nodeName == 'INPUT' || listText.nodeName == 'input'){
      var text = pItem.innerHTML.replace('&nbsp;',' ');
      while (text.indexOf('&nbsp;')>-1){
	text = text.replace('&nbsp;',' ');
      }
      listText.value= text;
    } else {
      listText.innerHTML=pItem.innerHTML;
    }
    listValue.value = pItem.getAttribute('value');
    combo_close(cName);
    if (pList.onchange){
      var obj={label:pItem.innerHTML,value:pItem.getAttribute('value'),name:cName};
      pList.onchange(obj, pInit);
    }
  }

  function combo_open(pName){
    if (document.getElementById(pName+'List').style.visibility=='hidden'){
      document.getElementById(pName+'List').style.visibility='visible';
      window.comboList = pName;
    } else {
      combo_close(pName);
    }
    return false;
  }

  function combo_force_open(pName){
    _disabled_submit = true;
    if (document.getElementById(pName+'List').style.visibility=='hidden'){
      document.getElementById(pName+'List').style.visibility='visible';
      window.comboList = pName;
    }

    return false;
  }

  function reloadList(pName, pUrl){

    new Ajax.Request(pUrl,
		     {method:'get',
		      requestHeaders: {Accept: 'application/json'},
		      onSuccess: function (transport){
				  rebuildList(pName, transport.responseText.evalJSON());
		      },
		      onFailure: function() {
				  alert('Something went wrong...');
		      }
		     });

  }
  
  function rebuildList(pName, dataList){
    var list = document.getElementById(pName+"List");
    var listText = document.getElementById(pName+'Text');
    var listValue = document.getElementById(pName+'Value');
    
    listValue.value = -1;    
    listText.innerHTML='';    
    list.innerHTML = '';
    var p;
	var first = null;
	
    for(i=0; i<dataList.length; i++){
      
      p = document.createElement('p');
	  if (!first){
		first = p;
	  }
	  if (dataList[i].value){
		p.setAttribute('value',dataList[i].value);
	  } else if (dataList[i].id){
		p.setAttribute('value',dataList[i].id);
	  }
      p.setAttribute('class','comboItem');
      p.onmouseover=( function(n,m){ return function(){combo_mo(n,m);} } )( list, p );;
      p.onclick=( function(n,m){ return function(){combo_select(n,m);} } )( list, p );;
      p.innerHTML = dataList[i].label;
      list.appendChild(p);
    }
	
	combo_select(list,first);
  }

  
  /**
   *Indicator
   */
  function indicatorCreate(indicatorId, val){
    var div = document.createElement('div');
    div.className='indicator';
    div.id = indicatorId;
    
    var block;

	block = document.createElement('div');
	block.className = 'minus';
    div.appendChild(block);
	
    for (var i=0; i<10; i++){
      block = document.createElement('div');
      block.className = 'block';
      block.setAttribute('level',i+1);
      div.appendChild(block);
    }

	block = document.createElement('div');
	block.className = 'plus';
    div.appendChild(block);

    var input = document.createElement('input');
    input.setAttribute('type','hidden');
    input.setAttribute('name',indicatorId);
    input.setAttribute('id',indicatorId+'Val');
    if (val){
      input.setAttribute('value',val);
    }
    div.appendChild(input);
    
    return div;
  }
  
  function indicatorInit(indicatorId, readonly){
    var pixels = $$('#'+indicatorId+' .block')
	
    var plus = $$('#'+indicatorId+' .plus')
    var minus = $$('#'+indicatorId+' .minus')
	
    
    if (!readonly){
      plus[0].observe('click', plusClick)
      minus[0].observe('click', minusClick)

      for(var t=0; t<pixels.length; t++){
	pixels[t].observe('click', indicatorClick)
	//pixels[t].observe('mouseover', indicatorLevelMouseOver)
	pixels[t].observe('mouseout', indicatorLevelMouseOut)
	pixels[t].choosed = false;
      }
    }

    var defaultVal = $(indicatorId+'Val').getAttribute('value');
    if (indicatorId == 'job_time_52'){
      //alert($(indicatorId+'Val').getAttribute('value'));
      
    }
    //var defaultVal = $$('#'+indicatorId+' #'+indicatorId+'Val');

    if (!defaultVal){
      defaultVal = 1;
    }

    indicatorSelect(indicatorId, defaultVal);
  }

  function indicatorSelect(indicatorId, level){
    var pixels = $$('#'+indicatorId+' .block')

    for(var t=0; t<pixels.length; t++){
      if (parseInt(pixels[t].getAttribute("level")) <= level){
	pixels[t].className = "block block-selected"
	pixels[t].choosed = true;
      } else {
	pixels[t].choosed = false;
	pixels[t].className = "block"
      }
    }
    $(indicatorId+'Val').value = level;
  }

  function indicatorLevelMouseOver(event){
    var pixel = Event.element(event);
    var level = parseInt(pixel.getAttribute("level"));
    var mainNode = pixel.parentNode;
    var pixels = $$('#'+mainNode.id+' .block')
    
    for(var t=0; t<pixels.length; t++){
      if (parseInt(pixels[t].getAttribute("level")) <= level){
	pixels[t].className = "block block-over"
      } else {
	if (!pixels[t].choosed) {
	  pixels[t].className = "block"
	} else {
	  pixels[t].className = "block block-selected"
	}
      }
    }

  }

  function indicatorLevelMouseOut(event){

    var pixel = Event.element(event);
    var mainNode = pixel.parentNode;
    var pixels = $$('#'+mainNode.id+' .block')
    
    for(var t=0; t<pixels.length; t++){
	if (!pixels[t].choosed) {
	  pixels[t].className = "block"
	} else {
	  pixels[t].className = "block block-selected"
	}
    }
  }

  function indicatorClick(event){

    var pixel = Event.element(event);

    indicatorSelect(pixel.parentNode.id, parseInt(pixel.getAttribute("level")));

  }
  
  function plusClick(event){

    var pixel = Event.element(event);
	var curVal = parseInt($(pixel.parentNode.id+'Val').value);
	
	if (curVal < 10){
	  indicatorSelect(pixel.parentNode.id, curVal+1);
	}

  }
  
  function minusClick(event){

    var pixel = Event.element(event);
	var curVal = parseInt($(pixel.parentNode.id+'Val').value);
	
	if (curVal > 1){
	  indicatorSelect(pixel.parentNode.id, curVal-1);
	}

  }
  
  /**********************************
   *
   * splash
   *
   */

      var splashTimer = null;
      var imgCacheL;
      var imgCacheR;

      function splashChange(pJump){
	var imgL = document.getElementById('splashL');
	//var imgR = document.getElementById('splashR');

	if (imgL.lloaded == false /*|| imgR.rloaded == false*/){
	  return;
	}

	if (splashTimer){
	  clearTimeout ( splashTimer );
	}

	var imgNr = parseInt(imgL.src.substring(imgL.src.length-5,imgL.src.length-4));
	var mainLSrc = imgL.src.substring(0,imgL.src.length-5);
	//var mainRSrc = imgR.src.substring(0,imgR.src.length-5);


	if (!pJump){
	  imgNr = (++imgNr%3);
	} else {
	  imgNr = imgNr + pJump;
	  if (imgNr < 0){
	    imgNr = 2;
	  }
	  imgNr = (imgNr%3);
	  if (imgNr == -1){
	    splashTimer = setTimeout(nextSplash, 8000);
	    return;
	  }
	}

	imgL.lloaded = false;
	//imgR.rloaded = false;

	imgL.nextNr = imgNr;
	//imgR.nextNr = imgNr;

	imgL.mainLSrc = mainLSrc;
	//imgR.mainRSrc = mainRSrc;

	if (!imgCacheL){
	  imgCacheL = document.createElement('img');
//	  imgCacheL.onload = function(){imgL.lloaded = true; swapSplash();}
	}
	imgCacheL.src = mainLSrc+imgNr+'.gif';
	imgL.lloaded = true; swapSplash();
	//if (!imgCacheR){
	//  imgCacheR = document.createElement('img');
	//  imgCacheR.onload = function(){imgR.rloaded = true; swapSplash();}
	//}
	//imgCacheR.src = mainRSrc+imgNr;
      }

      function swapSplash(){
	var imgL = document.getElementById('splashL');
	//var imgR = document.getElementById('splashR');

	if (/*imgR.rloaded &&*/ imgL.lloaded){
	  imgL.src = imgL.mainLSrc+imgL.nextNr+".gif";
	  //imgR.src = imgR.mainRSrc+imgR.nextNr+".gif";
	  if (imgL.nextNr == 0){
	    document.getElementById('prevArea').style.cursor='default';
	  } else {
	    document.getElementById('prevArea').style.cursor='pointer';
	  }
	  splashTimer = setTimeout(nextSplash, 8000);
	}
      }

      function nextSplash(){

	splashChange();
      }

      function prevSplash(){
	splashChange(-1);
      }
