alvine_object_createObjectPath(alvine, 'forms');

alvine.forms.mouseOverControl = false;

function forms_initControl(obj, extendControl){

  var isCompatible = forms_checkExtendedControlsBrowserCompability();

  if(!isCompatible) return false;
  obj = element_isObject(obj);

  if(!obj) return false;
  if(typeof obj.tagName == 'undefined') return false;

  extendControl = (extendControl===true)?true:false;
  
  //über init gesetzt
  extendControl = (typeof obj.alvine_extendControl != 'undefined')?obj.alvine_extendControl:extendControl;
  

  /** place general atrributes/functions here **/

  //check for proxyObject (custom controls)
  if(extendControl){
    forms_renderExtendedControl(obj);

    var proxyObj = element_isObject(obj.id+'_proxy');
    obj.alvine_proxyObj = proxyObj;

  }

  
  if(typeof obj.alvine_renderProxyObject != 'function'){
    obj.alvine_renderProxyObject = function(){
      proxyObj = this.alvine_proxyObj; //schon ermittelt?
      if(!this.alvine_proxyObj){
        proxyObj = element_isObject(this.id+'_proxy'); //versuchen zu ermitteln

        if(!proxyObj) return true;
        //festlegen, wenn gefunden
        this.alvine_proxyObj = proxyObj;
      }

      if(typeof proxyObj.alvine_renderObject != 'function') return true;

      proxyObj.alvine_renderObject();

      return true;
    };
  }

  var controlType = forms_getControlType(obj);

  /** type specific attributes/functions **/
  switch(controlType){
    case 'select_select-one':
    case 'select':

      //functions
      if(typeof obj.alvine_addOption == 'function') {
        obj.alvine_renderProxyObject();

        if(!extendControl) break;
        event_add(obj, 'change', 'this.alvine_renderProxyObject()', true);
        break;
      }
      
      obj.alvine_addOptions = function(objects){

        if(typeof objects == 'undefined') return false;

        var tmpValue;
        var newOptions = new Object();
        if(typeof objects == 'object'){  //objects given
          if(object_count(objects)==0) return true;
          
          for(var i in objects){
            if(typeof objects[i].tagName == 'undefined') continue;
            //options
            if(objects[i].tagName.toString().toLowerCase()=='option') {
              newOptions[objects[i].value] = objects[i];
              continue;
            }

            //alvine gfx options

            var attValue = objects[i].getAttribute('alvine:value');
            if(attValue==null || attValue=='') continue;

            var attSelected = objects[i].getAttribute('alvine:selected');
            objects[i].alvine_selected = (attSelected!=null && attSelected!='')?true:false;
            tmpValue = attValue.valueOf();
            newOptions[tmpValue] = objects[i];
          }

        } else { //objects is string value
          newOptions[objects] = objects;
        }

        for(var j in newOptions){
          var newOption = document.createElement('OPTION');

          var idx = this.options.length;
          newOption.id                = this.id+'_'+idx;
          newOption.value             = j;
          newOption.selected          = (typeof newOptions[j].alvine_selected != 'undefined')?newOptions[j].alvine_selected:newOptions[j].selected;
          newOption.text              = newOptions[j].textContent;
          newOption.className         = newOptions[j].className;
          newOption.alvine_initObject = newOptions[j];

          var num = (document.all)?idx:null;
          this.add(newOption, num);
        }

        if(this.selectedIndex<0){
          this.options[0].selected = true;
        }

        this.alvine_renderProxyObject();

        return true;
      };

      obj.alvine_removeOption = function(index){

        this.remove(index);
        
        this.alvine_renderProxyObject();
      };

      obj.alvine_clearOptions = function(avoidProxyRendering){
        avoidProxyRendering = (avoidProxyRendering===true)?true:false;

        //Liste zurücksetzen
        this.options.length = 0;

        if(avoidProxyRendering) return true;
        this.alvine_renderProxyObject();

        return true;
      };

      obj.alvine_setValue = function(index){

        //Liste zurücksetzen
        this.selectedIndex = index;

        
        this.alvine_renderProxyObject();

        return true;
      };
      //Logic


      //lets see, if there is a optioncontainer
      var optionContainerObj = element_isObject(obj.id+'_optioncontainer');
      if(optionContainerObj){
        var optConOptionList = optionContainerObj.getElementsByTagName('DIV');
        if(optConOptionList.length>0) {
          obj.alvine_clearOptions(true);
          obj.alvine_addOptions(optConOptionList);
        }
      }

      obj.alvine_renderProxyObject();

      if(!extendControl) break;
      event_add(obj, 'change', 'this.alvine_renderProxyObject()', true);
     
      break;

    case 'select_select-multiple':
    case 'select_multiple':
    case 'select_select-multiple_true':
    case 'select_list':

      break;
    case 'textarea':
    case 'textarea_textarea':
    case 'input_text':
    case 'input_password':

      break;
    case 'input_checkbox':
    case 'input_radio':

      obj.alvine_renderProxyObject();

      //if(!extendControl) break;
      
      event_add(obj, 'change', forms_clickbox_handleChange, true);
      if(_ALVINE_IE) event_add(obj, 'focus', forms_checkbox_handleFocus, true);
      
      break;
    default:
      break;

  }

  return true;
}

function forms_clickbox_handleChange(ev){
  if(!ev) ev = window.event;

  var obj = this;

  obj.alvine_renderProxyObject();


  if(_ALVINE_IE6) return;
  return object_preventDefaultEventBehaviour(ev);
}

function forms_checkbox_handleFocus(ev){
  if(!ev) ev = window.event;

  this.alvine_proxyObject.focus();
 
  return object_preventDefaultEventBehaviour(ev);
}

function forms_init_textinput(obj, clear, restore, select){
  obj = element_isObject(obj);
  if(!obj) return false;

  clear = (typeof clear != 'undefined' && clear===false)?false:true;
  select = (typeof select != 'undefined' && select===false)?false:true;
  restore = (typeof restore != 'undefined' && restore===false)?false:true;

  obj.alvine_defaultValue = obj.value;

  if(clear) event_add(obj, 'focus', forms_textinput_clearValue);
  if(select) event_add(obj, 'focus', forms_textinput_selectValue);

  if(restore) event_add(obj, 'blur', forms_textinput_restoreDefaultValue);

  return true;
}

function forms_textinput_clearValue(ev){
  if(!ev) ev = window.event;

  if(this.value == '') return;
  if(typeof this.alvine_defaultValue == 'undefined') this.alvine_defaultValue = this.value;
  if(this.value != this.alvine_defaultValue) return;

  this.value = '';
}

function forms_textinput_restoreDefaultValue(ev){
  if(!ev) ev = window.event;

  if(this.value != '') return;
  if(typeof this.alvine_defaultValue == 'undefined') return;

  this.value = this.alvine_defaultValue;
}

function forms_textinput_selectValue(ev){
  if(!ev) ev = window.event;

  if(this.value == '') return;

  this.select();
}

function forms_setInputValue(targetControl, value){ 
  targetControl = element_isObject(targetControl);

  targetControl.value = value;
  
  return true;
}

function forms_initImageSelectFields(parentID){
  var parentObj = element_isObject(parentID);
  var obj = null;
    
  for(var i in parentObj.childNodes){   
    for(var j in parentObj.childNodes[i].childNodes){
      obj = parentObj.childNodes[i].childNodes[j].id;
      if(obj == null) continue;
      if(typeof obj == 'undefined') continue;            
      if(obj.substr(0,parentID.length)!=parentID) continue;

      var nameParts = obj.split('_label__');
      if(nameParts[0]!=parentID) continue;

      event_add(obj, 'mouseover', forms_setHover);
      event_add(obj, 'mouseout', forms_setHover);
      event_add(obj, 'mousedown', forms_imageSelectSetStatus);
      event_add(obj, 'mousedown', forms_setActive);
      event_add(obj, 'mouseup', forms_setActive);      
    }
  }
}
function forms_checkExtendedControlsBrowserCompability(){
  // set only tested browsers to true
  if(_ALVINE_IE6) return true;
  if(_ALVINE_IE7) return true;
  if(_ALVINE_IE8) return true;
  //if(_ALVINE_SAFARI2) return true;
  //if(_ALVINE_SAFARI3) return true;
  if(_ALVINE_FIREFOX2) return true;
  if(_ALVINE_FIREFOX3) return true;

  return false;
}

function forms_initExtendedControls(ev){
  if(!ev) ev = window.event;  
  alvine_object_createObjectPath(alvine, 'forms');

  alvine.forms.browserIsCompatible = forms_checkExtendedControlsBrowserCompability();
  if(typeof alvine.forms.controls == 'undefined') alvine.forms.controls = new Object();

  return object_preventDefaultEventBehaviour(ev);
}

function forms_registerControl(obj, extendControl){  
  var isCompatible = forms_checkExtendedControlsBrowserCompability();
  if(!isCompatible) return false; //Browser is not compatible
  obj = element_isObject(obj);
  if(!obj) return false;

  if(typeof alvine.forms.controls == 'undefined') alvine.forms.controls = new Object();
   
  obj.alvine_extendControl = (extendControl===true)?true:false;
  alvine.forms.controls[obj.id] = obj;

  return true;
}

function forms_processExtendedControls(ev){
  if(!ev) ev = window.event;

  if(typeof alvine == 'undefined') return false;
  if(typeof alvine.forms == 'undefined') return false;
  if(typeof alvine.forms.controls == 'undefined') return false;

  for(var i in alvine.forms.controls){
    var controlSrcObj = alvine.forms.controls[i];

    var extend = (controlSrcObj.alvine_extendControl===true)?true:false;
    forms_initControl(controlSrcObj, extend);
  }

  return true;
}

function forms_getControlType(obj){
  obj = element_isObject(obj);

  if(!obj) return false;

  var controlType = obj.nodeName.toString().toLowerCase();
  controlType+= ((typeof obj.type != 'undefined' && obj.type!=null) && obj.type.toString().toLowerCase()!=controlType)?'_'+obj.type.toString().toLowerCase():'';
  controlType+= (typeof obj.multiple != 'undefined' && obj.multiple===true)?'_'+obj.multiple.toString().toLowerCase():'';

  return controlType;
}

function forms_renderExtendedControl(obj){
  var isCompatible = forms_checkExtendedControlsBrowserCompability();
  if(!isCompatible) return false; //Browser is not compatible

  obj = element_isObject(obj);
  if(!obj) return false;

  //event gefore finishing extension
  if(typeof obj.alvine_beforeExtension == 'function'){
    obj.alvine_beforeExtension();
  }

  if(typeof obj.nodeName == 'undefined' || obj.nodeName == null) return false;

  var controlType = forms_getControlType(obj);

  if(controlType=='hidden') return true;

  var proxyObj;
  var contentObj;

  var gfxBorderObjTop    = document.createElement('DIV');
  gfxBorderObjTop.className = 'top_panel';
  var gfxBorderObjBottom = document.createElement('DIV');
  gfxBorderObjBottom.className = 'bottom_panel';
  var fillBorderTypes = new Object();
  fillBorderTypes.left   = '&nbsp;';
  fillBorderTypes.right  = '&nbsp;';
  fillBorderTypes.middle = '&nbsp;';
  

  //topBorder/BottomBorder
  for(var i in fillBorderTypes){
    var newElement = document.createElement('DIV');
    newElement.className = i;
    newElement.innerHTML = fillBorderTypes[i];
    gfxBorderObjTop.appendChild(newElement.cloneNode(true));
    gfxBorderObjBottom.appendChild(newElement.cloneNode(true));
  }
  contentObj = document.createElement('DIV');
  contentObj.className = 'content_panel';
  var contentRightObj =  document.createElement('DIV');
  contentRightObj.className = 'right';
  var contentContentObj =  document.createElement('DIV');
  contentContentObj.className = 'content';

  if(controlType == 'select_select-one' && (parseInt(obj.size)>0 || parseInt(obj.rows)>0 || parseInt(obj.style.height)>0)){
    controlType = 'select_list';
  }
  
  switch (controlType) {
    case 'select_select-one':
    case 'select':

      //dropdown
      var dropdownObj = document.createElement('DIV');
      dropdownObj.alvine_originalObj = obj;
      dropdownObj.id                 = obj.id+'_proxy';
      dropdownObj.className          = 'gfx_dropdown';
      dropdownObj.className         += ' '+str_replace('hidden','',obj.className);
      if(obj.disabled) dropdownValueObj.className += ' disabled';
      //hide original
      element_setVisibility(obj, 'hidden');
      element_move(obj, -9999, 0);
      

      dropdownObj.alvine_options     = new Array();
      
      event_add(dropdownObj, 'mouseover', custom_input_activateMouseoverControl, true);
      event_add(dropdownObj, 'mouseout',  custom_input_deactivateMouseoverControl, true);
      
      //dropdown button
      var dropdownButtonObj       = document.createElement('DIV');
      dropdownButtonObj.className = 'button_selector down';
      dropdownButtonObj.id        = dropdownObj.id+'_buttonselector';
      dropdownButtonObj.alvine_parentObject = dropdownObj;

      //dropdown value
      var dropdownValueObj        = document.createElement('DIV');
      dropdownValueObj.className  = 'value islink';
      dropdownValueObj.id         = dropdownObj.id+'_value';
      dropdownValueObj.alvine_parentObject = dropdownObj;

      //copy events
      if(typeof obj.alvine_eventListeners != 'undefined'){
        for(var i in obj.alvine_eventListeners) {
          var t = obj.alvine_eventListeners[i];
          for(var j in t){
            var ev = t[j];
            event_add(dropdownValueObj, ev.type, ev.fn, ev.useCapture);

          }
        }
      }

      dropdownObj.appendChild(dropdownButtonObj);
      dropdownObj.appendChild(dropdownValueObj);
      contentContentObj.appendChild(dropdownObj);

      //dropdown list
      var dropdownListID  = dropdownObj.id+'_list';
      var dropdownListObj = element_isObject(dropdownListID);
      if(!dropdownListObj){
        dropdownListObj = document.createElement('DIV');
        dropdownListObj.id = dropdownListID;
        document.body.insertBefore(dropdownListObj, document.body.childNodes[0]);
      }
      dropdownListObj.className = 'dropdown_list';
      element_setVisibility(dropdownListObj, 'hidden');
      element_setLeft(dropdownListObj, -9999);
      dropdownListObj.alvine_visible = false;
      dropdownListObj.alvine_dropdownObj = dropdownObj;

      event_add(dropdownListObj, 'mouseover', custom_input_activateMouseoverControl, true);
      event_add(dropdownListObj, 'mouseout',  custom_input_deactivateMouseoverControl, true);


      /////////////
      dropdownObj.alvine_buttonSelectorObj = dropdownButtonObj;
      dropdownObj.alvine_valueObj          = dropdownValueObj;
      dropdownObj.alvine_listObj           = dropdownListObj;

      //list
      dropdownListObj.alvine_selectOption = function(obj){
        obj = element_isObject(obj);
        if(!obj) return true;

        var dropdownObj = this.alvine_dropdownObj;
        
        for(var i in dropdownObj.alvine_options){
          element_removeClassName(dropdownObj.alvine_options[i], ' selected');

          if(dropdownObj.alvine_options[i].id!=obj.id) continue;
          element_addClassName(dropdownObj.alvine_options[i], ' selected');
        }

        return true;
      };
      
      dropdownListObj.alvine_renderObject = function(){

        var dropdownObj = this.alvine_dropdownObj;
        var originalObj = dropdownObj.alvine_originalObj;

        //remove all options
        writeHTML(this, '');

        //dropdown list options
        var optionList = originalObj.getElementsByTagName('OPTION');

        
        for(var i in optionList){

          if(typeof optionList[i].tagName == 'undefined') continue;

          var contentObj = optionList[i];
          var initObj    = (typeof optionList[i].alvine_initObject == 'object')?optionList[i].alvine_initObject:contentObj;

          var optionRowObj = document.createElement('DIV');
          var alvine_type = document.createAttribute('alvine:type');
          alvine_type.nodeValue = 'option';
          optionRowObj.setAttributeNode(alvine_type);
          optionRowObj.alvine_originalOption = optionList[i];

          optionRowObj.className = 'option islink';

          //Class/Style
          optionRowObj.className+= ' '+str_replace('hidden', '', contentObj.className);

          var selected = contentObj.selected;
          if(selected) optionRowObj.className+= ' selected'; 

          //Event übernahme
          var eventMap = new Object();
          eventMap.onclick     = {
            trgObj:optionRowObj
          };
          eventMap.onmousedown = {
            trgObj:optionRowObj
          };
          eventMap.onmouseup   = {
            trgObj:optionRowObj
          };
          eventMap.onmousemove = {
            trgObj:optionRowObj
          };


          for(var eventKey in eventMap){
            var tmpEvent = initObj[eventKey];
            if(typeof tmpEvent != 'function'){
              var alv_event = initObj.getAttribute('alvine:'+eventKey);
              if(alv_event != null && alv_event!='') tmpEvent = alv_event;
            }
            if(typeof tmpEvent != 'function' || tmpEvent == null || tmpEvent == '') continue;
            event_add(eventMap[eventKey].trgObj, eventKey, tmpEvent, true);
          }


          optionRowObj.innerHTML   = initObj.innerHTML;
          optionRowObj.alvine_valueObj = dropdownObj.alvine_valueObj;
          optionRowObj.alvine_parentObject = dropdownObj;
          
          if(selected){
            custom_dropdown_setOptionValue(optionRowObj);
          }
          event_add(optionRowObj, 'mousedown', custom_dropdown_setOptionValueHandler, true);
          event_add(optionRowObj, 'mousedown', custom_dropdown_handleToggleListEvent, true);

          this.appendChild(optionRowObj);
          dropdownObj.alvine_options.push(optionRowObj);

          //highlighting
          optionRowObj.onmouseover = function(){
            var classNameParts = this.className.split(' ');
            var found = false;
            for(var i in classNameParts){
              if(classNameParts[i] != 'highlight') continue;
              found = true;
              break;
            }
            if(!found) classNameParts.push('highlight');
            this.className = classNameParts.join(' ');
          };

          optionRowObj.onmouseout = function(){
            var classNameParts = this.className.split(' ');
            for(var i in classNameParts){
              if(classNameParts[i] != 'highlight') continue;
              delete(classNameParts[i]);
              break;
            }
            this.className = classNameParts.join(' ');
          };

        }
        
        dropdownObj.alvine_setSwitchcolors();

        return true;
      }

      //dropdown
      dropdownObj.alvine_renderObject = function(){

        //var originalObj = this.alvine_originalObj;
        this.alvine_clear();
        this.alvine_listObj.alvine_renderObject();
        
        return true;
      }

      dropdownObj.alvine_clear = function(){
        if(this.alvine_options.length == 0) return true;

        for(var i in this.alvine_listObj.childNodes){
          var obj = element_isObject(this.alvine_listObj.childNodes[i]);
          if(!obj) continue;
          var checkAttr = obj.getAttribute('alvine:type');
          if(checkAttr==null || checkAttr=='') continue;

          this.alvine_listObj.removeChild(obj);
        }
        this.alvine_options.length = 0;

        return true;
      }

      dropdownObj.alvine_setSwitchcolors = function(){
        if(this.alvine_options.length==0) return true;

        for(var i in this.alvine_options){
          var sColorIndex = (i%2==0)?2:1;
          if(this.alvine_options[i].className.substring(0, 10) == 'switchcolor'){
            this.alvine_options[i].className = this.alvine_options[i].className.substring(12);
          }
          element_removeClassName(this.alvine_options[i], '  ');
          this.alvine_options[i].className = 'switchcolor0'+sColorIndex.toString()+' '+this.alvine_options[i].className;
        }

        return true;
      };

      //functions

      event_add(dropdownButtonObj, 'mousedown', custom_dropdown_handleToggleListEvent, true);
      event_add(dropdownValueObj,  'mousedown', custom_dropdown_handleToggleListEvent, true);
      if(typeof document.alvine_dropdownFields == 'undefined') document.alvine_dropdownFields = new Object();
      if(typeof document.alvine_dropdownFields[dropdownObj.id] == 'undefined') document.alvine_dropdownFields[dropdownObj.id] = dropdownObj;

      if(typeof document.alvine_closeRegisteredDropDowns=='undefined'){
        document.alvine_closeRegisteredDropDowns = function(ev){
          
          if(!ev) ev = window.event;
          for(var i in document.alvine_dropdownFields){
            var tmpListObj = document.alvine_dropdownFields[i].alvine_listObj;
            if(alvine.forms.mouseOverControl && tmpListObj.id == alvine.forms.mouseOverControl) continue;
            tmpListObj = element_isObject(tmpListObj);
            if(!tmpListObj) continue;
            if(!tmpListObj.alvine_visible) continue;
            custom_dropdown_toggleList(i);
          }

          return true;
        };
      }

      if(_countChildren(document.alvine_dropdownFields)==1){
        event_add(document, 'mousedown', document.alvine_closeRegisteredDropDowns);
      }

      dropdownButtonObj.onmouseover = function(){
        var classNameParts = this.className.split(' ');        
        if(!strstr(this.className, 'highlight')) classNameParts.push('highlight');
        this.className = classNameParts.join(' ');
        return false;
      };

      dropdownButtonObj.onmouseout = function(){
        element_replaceClassName(this, ' highlight', '');
        return false;
      };

      proxyObj = document.createElement('DIV');
      proxyObj.className = 'custom_control_panel';

      proxyObj.className+= ' '+str_replace('hidden', '', obj.className);
      proxyObj.appendChild(gfxBorderObjTop);

      contentRightObj.appendChild(contentContentObj);
      contentObj.appendChild(contentRightObj);
      proxyObj.appendChild(contentObj);

      proxyObj.appendChild(gfxBorderObjBottom);

      obj.parentNode.insertBefore(proxyObj, obj);

      break;
    case 'select_select-multiple':
    case 'select_multiple':
    case 'select_select-multiple_true':
    case 'select_list':

      //dropdown
      var multiListObj = document.createElement('DIV');
      multiListObj.id              = obj.id+'_proxy';
      multiListObj.className       = 'gfx_multilist';
      multiListObj.className      += ' '+str_replace('hidden', '', obj.className);

      multiListObj.alvine_options           = new Array();

      contentContentObj.appendChild(multiListObj);

      //multilist options
      var optionList = obj.getElementsByTagName('OPTION');
      //lets see, if there is a optioncontainer
      var optionContainerObj = element_isObject(obj.id+'_optioncontainer');
      var optionContainerObjIsset = false;
      if(optionContainerObj){
        var optConOptionList = optionContainerObj.getElementsByTagName('DIV');
        if(optConOptionList.length>0) {
          optionList = optConOptionList;
        }
      }

      ////////
      multiListObj.alvine_addOption = function(parentObj, contentObj, index){
        parentObj  = element_isObject(parentObj);
        contentObj = element_isObject(contentObj);

        var newIndex = (typeof index != 'number')?this.alvine_options.length:index;

        var optionRowObj = document.createElement('DIV');
        var alvine_type = document.createAttribute('alvine:type');
        alvine_type.nodeValue = 'option';
        optionRowObj.setAttributeNode(alvine_type);

        optionRowObj.className = 'option islink';

        var optionInputObj       = document.createElement('INPUT');
        var inputObjID           = this.id+'_'+newIndex;
        optionInputObj.id        = inputObjID;
        optionInputObj.className = 'hidden';
        optionInputObj.type      = 'checkbox';
        optionInputObj.checked   = false;

        //Class/Style
        optionRowObj.className+= ' '+str_replace('hidden', '', contentObj.className);

        var value;
        var selected;
        if(contentObj.tagName.toLowerCase()=='option'){
          value = optionList[i].value;
          selected = contentObj.selected;
        } else {
          var attValue = contentObj.getAttribute('alvine:value');

          if(attValue==null || attValue=='') return false;

          //Event übernahme
          var eventMap = new Object();
          eventMap.onchange    = {
            trgObj:optionInputObj
          };
          eventMap.onclick     = {
            trgObj:optionRowObj
          };
          eventMap.onmousedown = {
            trgObj:optionRowObj
          };
          eventMap.onmouseup   = {
            trgObj:optionRowObj
          };
          eventMap.onmousemove = {
            trgObj:optionRowObj
          };

          for(var eventKey in eventMap){
            var tmpEvent = optionList[i].getAttribute('alvine:'+eventKey);
            if(tmpEvent == null || tmpEvent == '') continue;
            event_add(eventMap[eventKey].trgObj, eventKey, tmpEvent, true);
          }

          value = attValue.valueOf();

          var attSelected = contentObj.getAttribute('alvine:selected');
          selected = (attSelected!=null && attSelected!='')?attSelected.valueOf():false;
        }

        optionInputObj.value     = value;
        optionInputObj.name      = parentObj.name;
        if(selected){
          optionInputObj.checked   = selected;
          element_addClassName(optionRowObj, 'checked');
        }
        optionInputObj.alvine_multilistObject = multiListObj;

        parentObj.parentNode.insertBefore(optionInputObj, parentObj);

        optionRowObj.innerHTML = contentObj.innerHTML;
        optionRowObj.alvine_inputObj = optionInputObj;

        event_add(optionRowObj, 'mousedown', custom_multilist_setOptionValue, true);

        this.appendChild(optionRowObj);
        this.alvine_options[parseInt(newIndex)] = optionRowObj;

        return newIndex;
      };

      multiListObj.alvine_removeOption = function(index){
        var removeRowObj      = this.alvine_options[index];
        var removeInputObj = removeRowObj.alvine_inputObj;

        if(typeof removeRowObj != 'object') return false;

        removeInputObj.parentNode.removeChild(removeInputObj);
        removeRowObj.parentNode.removeChild(removeRowObj);
        this.alvine_options.splice(index, 1);

        this.alvine_setSwitchcolors();

        return true;
      };

      multiListObj.alvine_clearOptions = function(){
        if(this.alvine_options.length==0) return true;

        for(var i in this.alvine_options){
          this.alvine_removeOption(i);
        }

        return true;
      };

      multiListObj.alvine_setSwitchcolors = function(){
        if(this.alvine_options.length==0) return true;

        for(var i in this.alvine_options){
          var sColorIndex = (i%2==0)?2:1;
          element_removeClassName(this.alvine_options[i], 'switchcolor01');
          element_removeClassName(this.alvine_options[i], 'switchcolor02');
          element_removeClassName(this.alvine_options[i], '  ');
          this.alvine_options[i].className = 'switchcolor0'+sColorIndex.toString()+' '+this.alvine_options[i].className;
        }

        return true;
      };

      for(var i in optionList){

        if(typeof optionList[i].tagName == 'undefined') continue;
        
        multiListObj.alvine_addOption(obj, optionList[i]);
      }
      contentContentObj.appendChild(multiListObj);

      //////////////////functions
      
      multiListObj.alvine_setSwitchcolors();

      for(var i in multiListObj.alvine_options){

        if(typeof multiListObj.alvine_options[i] != 'object') continue;

        var checkAttribute = multiListObj.alvine_options[i].getAttribute('alvine:type');
        if(checkAttribute == null || checkAttribute == '') continue;

        multiListObj.alvine_options[i].onmouseover = function(){
          var classNameParts = this.className.split(' ');
          var found = false;
          for(var i in classNameParts){
            if(classNameParts[i] != 'highlight') continue;
            found = true;
            break;
          }
          if(!found) classNameParts.push('highlight');
          this.className = classNameParts.join(' ');
        };

        multiListObj.alvine_options[i].onmouseout = function(){
          var classNameParts = this.className.split(' ');
          for(var i in classNameParts){
            if(classNameParts[i] != 'highlight') continue;
            delete(classNameParts[i]);
            break;
          }
          this.className = classNameParts.join(' ');
        };
      }

      proxyObj = document.createElement('DIV');
      proxyObj.className = 'custom_control_panel';
      proxyObj.className+= ' '+str_replace('hidden', '', obj.className);
      proxyObj.appendChild(gfxBorderObjTop);

      contentRightObj.appendChild(contentContentObj);
      contentObj.appendChild(contentRightObj);
      proxyObj.appendChild(contentObj);

      proxyObj.appendChild(gfxBorderObjBottom);

      obj.parentNode.replaceChild(proxyObj, obj);

      break;
    case 'textarea':
    case 'textarea_textarea':
    case 'input_text':
    case 'input_password':
      //contentContentObj
      obj.className = str_replace('hidden', '', obj.className);
      var copyobj = obj.cloneNode(true);
      
      //copy events
      if(typeof obj.alvine_eventListeners != 'undefined'){
        for(var i in obj.alvine_eventListeners) {
          var t = obj.alvine_eventListeners[i];
          for(var j in t){
            var ev = t[j];
            event_add(copyobj, ev.type, ev.fn, ev.useCapture);
          
          }
        }
      }

      contentContentObj.appendChild(copyobj);

      proxyObj = document.createElement('DIV');
      
      proxyObj.className = 'custom_control_panel';
      //proxyObj.className+= ' '+str_replace('hidden', '', obj.className);
      proxyObj.id = obj.id+'_proxy'
      proxyObj.appendChild(gfxBorderObjTop);

      contentRightObj.appendChild(contentContentObj);
      contentObj.appendChild(contentRightObj);
      proxyObj.appendChild(contentObj);

      proxyObj.appendChild(gfxBorderObjBottom);

      obj.parentNode.replaceChild(proxyObj, obj);

      break;
    case 'input_checkbox':
    case 'input_radio':

      if(controlType == 'input_radio') {
        alvine_object_createObjectPath(alvine.forms, 'lists.radio');
        if(typeof alvine.forms.lists.radio[obj.name] == 'undefined') alvine.forms.lists.radio[obj.name] = new Array();
        alvine.forms.lists.radio[obj.name].push(obj);
      }

      obj.className+= ' hidden';
      obj.alvine_controlType = controlType;

      proxyObj = document.createElement('DIV');
      proxyObj.id = obj.id+'_proxy'
      proxyObj.className = 'custom_small_control_panel';

      var sensitiveObj = document.createElement('LABEL');
      sensitiveObj.htmlFor = obj.id;
      sensitiveObj.alvine_inputObj = obj;  //reference
      

      inputObj = document.createElement('DIV');
      inputObj.className = 'custom_'+controlType;      
      obj.alvine_proxyObject = inputObj;  //back reference

      proxyObj.alvine_sensitiveObj = sensitiveObj;

      sensitiveObj.appendChild(inputObj);
      proxyObj.appendChild(sensitiveObj);

      proxyObj.alvine_renderObject = function(){
        var inputObj = this.alvine_sensitiveObj.alvine_inputObj;

        if(inputObj.alvine_controlType == 'input_checkbox'){ //checkbox

          if(inputObj.checked){
            if(!strstr(inputObj.className, 'checked')){
              element_addClassName(inputObj.alvine_proxyObject, 'checked');
            }
          } else {
            element_removeClassName(inputObj.alvine_proxyObject, ' checked');
          }

        } else { //radio

          for(var i in alvine.forms.lists.radio[inputObj.name]){
            var obj = alvine.forms.lists.radio[inputObj.name][i];

            element_removeClassName(obj.alvine_proxyObject, ' checked');

            if(!obj.checked) continue;
            element_addClassName(obj.alvine_proxyObject, 'checked');
            
          }

        }
        
        return true;
      }

      obj.parentNode.insertBefore(proxyObj, obj);
      break;
    default:
      break;
  }

  //event after finishing extension  
  if(typeof obj.alvine_finishExtension == 'function'){
    proxyObj.alvine_finishExtension = obj.alvine_finishExtension;
    proxyObj.alvine_finishExtension();
  }
  return;
}

function forms_setHover(ev){ 
  if(!ev) ev = window.event;
  
  if(ev.type=='mouseover'){
    element_addClassName(this,'hover');          
  } else {
    element_removeClassName(this,'hover');
  }
  return object_preventDefaultEventBehaviour(ev);
}

function forms_setActive(ev){
  element_removeClassName(this,'active');  
  element_addClassName(this,'active',' ');

  return object_preventDefaultEventBehaviour(ev);
}


function forms_imageSelectSetStatus(ev){ 
  var objID = this.id;  
  var nameParts = objID.split('_label__');
  var parentID = nameParts[0];
  
  var parentObj = element_isObject(parentID);
  for(var i in parentObj.childNodes){   
    for(var j in parentObj.childNodes[i].childNodes){
      obj = parentObj.childNodes[i].childNodes[j].id;
      if(obj == null) continue;
      if(typeof obj == 'undefined') continue;            
      if(obj == objID) continue;
      if(obj.substr(0,parentID.length)!=parentID) continue;
      
      var tmpNameParts = obj.split('_label__');
      if(tmpNameParts[0]!=parentID) continue;

      element_removeClassName(obj,'active');             
    }
  }

  return object_preventDefaultEventBehaviour(ev);
}

function forms_imageSelectDoEffect(ev){
  //__debug(this);
  var rowObj = this.parentNode;  
  var nameParts = rowObj.id.split('_');  
  var rowid = nameParts[(nameParts.length-1)];
    
  var currentPanelSize = element_getSize('form_panel_id');
  
  var nextRowid = parseInt(rowid)+1;
  if(typeof sfxFormData[nextRowid]=='undefined') return null;
  /*
  if(currentPanelSize.height>=sfxFormData[nextRowid].size.height){
    nextRowid = rowid;
  } 
  */
  
  var preloadImage = image_preload_get('form_panel_id',nextRowid);
  var img = element_isObject('stepimage');
  /*                       
  var imageFadeOut = new JAVASCRIPT_SFX_FADE(img,'0',65,1,true);
  var imageFadeIn = new JAVASCRIPT_SFX_FADE(img,'100',65,1,true);
  
  imageFadeOut.registerFollowingObject(imageFadeIn);
  imageFadeOut.start();
  */
  img.src = preloadImage.src;
  
  if(nextRowid>=sfxFormData.length && nextRowid==rowid) return null;

  var followOptions = new Object();
  followOptions['unlock_sizing'] = false;
  var effect = new JAVASCRIPT_SFX_ROLLOUT("form_panel_id","size","100%",sfxFormData[nextRowid].size.height+"px",65,1,1,true,followOptions);
  effect.start();
  
  return object_preventDefaultEventBehaviour(ev);
}


function forms_initFieldEvents(parentID){
  var parentObj = element_isObject(parentID);
  var obj = null;
  
  for(var i in parentObj.childNodes){ 
    for(var j in parentObj.childNodes[i].childNodes){
      row = parentObj.childNodes[i].childNodes[j]; //rows

      for(var k in row.childNodes){
        obj = row.childNodes[k];
        
        if(obj.nodeName!='SELECT' && !strstr(obj.className,'image_select_panel')) continue;

        if(obj.nodeName=='SELECT'){ //items flat
          event_add(obj, 'change', forms_imageSelectDoEffect);
        } else if(strstr(obj.className,'image_select_panel')){                        
          event_add(obj, 'mouseup', forms_imageSelectDoEffect);
        } 
      }
    }
  }
}

function forms_initCommandSelectAllCheckboxes(checkboxObj, formObj){
  checkboxObj = element_isObject(checkboxObj);
  formObj     = element_isObject(formObj);

  var checkboxList = formObj.getElementsByTagName('INPUT');
  checkboxObj.alvine_checkboxList = new Array();

  for(var i=0;i<checkboxList.length;i++){
    var item = checkboxList[i];
    if(item.type!='checkbox') continue;

    checkboxObj.alvine_checkboxList.push(item);
  }

  event_add(checkboxObj, 'click', forms_toggleCommandSelectAllCheckboxes);

  return true;
}

function forms_toggleCommandSelectAllCheckboxes(ev){
  if(!ev) ev = window.event;
  
  for(var i in this.alvine_checkboxList){
    this.alvine_checkboxList[i].checked = this.checked;
    if(typeof this.alvine_checkboxList[i].alvine_renderProxyObject == 'function') this.alvine_checkboxList[i].alvine_renderProxyObject();
  }

  return true;
}

function markFocus(obj) {
  var found = strstr(obj.className, 'inputfocus');
  if(!found){
    element_addClassName(obj, 'inputfocus');
    if(typeof obj.select == 'function') obj.select();
  }else{
    element_removeClassName(obj, ' inputfocus');
  }
  return true;
}

/** custom inputs functions **/
function custom_input_activateMouseoverControl(ev){
  if(!ev) ev = window.event;

  alvine.forms.mouseOverControl = (typeof this.alvine_listObj != 'undefined')?this.alvine_listObj.id:this.id;

  return true;
}
function custom_input_deactivateMouseoverControl(ev){
  if(!ev) ev = window.event;

  alvine.forms.mouseOverControl = false;

  return true;
}
function custom_dropdown_setOptionValueHandler(ev){

  if(!ev) ev = window.event;

  custom_dropdown_setOptionValue(this);
  var originalObj = this.alvine_originalOption;
  if(typeof originalObj.parentNode.onchange != 'undefined' && originalObj.parentNode.onchange != null){
    originalObj.parentNode.onchange(ev);
  }
 
  return object_preventDefaultEventBehaviour(ev);
}

function custom_dropdown_setOptionValue(rowObj){

  rowObj = element_isObject(rowObj);

  var valueObj    = rowObj.alvine_valueObj;
  var originalObj = rowObj.alvine_originalOption;
  var content     = (typeof originalObj.alvine_initObject == 'object')?originalObj.alvine_initObject.innerHTML:originalObj.innerHTML;
  valueObj.innerHTML = content;

  var index = originalObj.index;
  originalObj.parentNode.selectedIndex = index;
 
  originalObj.parentNode.alvine_proxyObj.alvine_listObj.alvine_selectOption(rowObj);
 
  return false;
}

function custom_multilist_setOptionValue(ev){

  if(!ev) ev = window.event;

  var inputObj = this.alvine_inputObj;
  inputObj.checked = (inputObj.checked)?false:true;
  if(inputObj.checked){
    element_addClassName(this, 'checked');
  } else {
    element_removeClassName(this, ' checked');
  }

  return object_preventDefaultEventBehaviour(ev);
}

function custom_dropdown_handleToggleListEvent(ev){
  if(!ev) ev = window.event;

  if(typeof this.alvine_parentObject != 'object') return;

  custom_dropdown_toggleList(this.alvine_parentObject.id);

  return object_preventDefaultEventBehaviour(ev);
}

function custom_dropdown_toggleList(parentID){

  var parentObj = document.getElementById(parentID);
  if(!parentObj) return true;
  buttonSelectorObj = parentObj.alvine_buttonSelectorObj;
  listObj           = parentObj.alvine_listObj;

  var classNameParts = buttonSelectorObj.className.split(' ');

  if(typeof listObj.alvine_visible == 'undefined' || !listObj.alvine_visible){
    var viewPort          = alvine_getViewport();
    var scrollPosition    = element_getScrollPosition();
    var viewPortMaxHeight = (viewPort.height-15);
    var parentPosition    = element_getPosition(parentObj, true);
    var parentSize        = element_getSize(parentObj);
    
    var minListHeight  = 120;
    var listHeight     = element_getHeight(listObj);
    var minTop         = 15;
    var maxTop         = (scrollPosition.y+viewPortMaxHeight);

    if(_ALVINE_IE) {
    //maxTop       = viewPortMaxHeight;
    }

    //default Position bottom of parentObj
    var newLeft = parentPosition.x;
    var newTop  = (parentPosition.y + parentSize.height);
    
    var checkHeight = (newTop+listHeight);

    if(checkHeight > maxTop){
      var newListHeight = viewPortMaxHeight-newTop;
      if(newListHeight < minListHeight){
        newListHeight = listHeight;
        newTop = parentPosition.y - listHeight;
        
        //check if list is too large for showing above
        var scrollCleanedTop       = (newTop-scrollPosition.y);
        var scrollCleanedParentTop = (parentPosition.y-scrollPosition.y);

        if(scrollCleanedTop<minTop){
          newTop = scrollPosition.y + minTop;
          newListHeight = scrollCleanedParentTop - minTop;
        }
      }

      element_setHeight(listObj, newListHeight);
      listObj.style.overflow = 'auto';
    }
    
    element_move(listObj, newLeft, newTop);
    
    element_setVisibility(listObj, 'visible');

    for(var i in classNameParts){
      if(classNameParts[i] != 'down') continue;
      classNameParts[i] = 'up';
    }
    listObj.alvine_visible = true;
  } else {
    element_setVisibility(listObj, 'hidden');
    element_setLeft(listObj, -9999);
    element_setTop(listObj, -9999);

    //reset
    listObj.style.overflow = 'visible';
    element_resetHeight(listObj);

    for(var i in classNameParts){
      if(classNameParts[i] != 'up') continue;
      classNameParts[i] = 'down';
    }    
    listObj.alvine_visible = false;
  }

  buttonSelectorObj.className = classNameParts.join(' ');

  return false;
}

function _countChildren(obj){
  var ret = 0;
  for(var i in obj) ret++;
  return ret;
}

/** assignment list **/
//control select assignment

if(typeof content_frontend_plugin_content_simple_form_controlSelectAssignmentData == 'undefined') content_frontend_plugin_content_simple_form_controlSelectAssignmentData = new Object();

function content_frontend_plugin_content_simple_form_select_assignment_init(boxID){


  if(typeof content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID] == 'undefined') content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID] = new Object();
  if(typeof content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists'] == 'undefined') content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists'] = new Array();
  if(typeof content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['all'] == 'undefined') content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['all'] = new Array();
  if(typeof content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['selected'] == 'undefined') content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['selected'] = new Array();
  if(typeof content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['menu'] == 'undefined') content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['menu'] = new Array();
  if(typeof content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['menu']['buttons'] == 'undefined') content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['menu']['buttons'] = new Array();

  var listAllID      = 'control_select_list_all';
  var listSelectedID = 'control_select_list_selected';
  var menuID         = 'control_select_assignment_menu';

  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['all']['object']      = element_isObject(listAllID+'_'+boxID);
  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['selected']['object'] = element_isObject(listSelectedID+'_'+boxID);

  //Init/Reset Daten merken
  var listAll      = content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['all']['object'];
  var listSelected = content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['selected']['object'];

  var selectedValueList = new Object();
  if(listSelected.options.length>0){
    for(var x in listSelected.options){
      var item = listSelected.options[x];
      if(typeof item != 'object') continue;
      selectedValueList[item.value] = true;
    }
  }
  selectedEntries = content_frontend_plugin_content_simple_form_select_assignment_getInternListSelection(listAll, 'value', selectedValueList);
  if(selectedEntries.length>0){
    content_frontend_plugin_content_simple_form_select_assignment_removeListEntry(listAll, selectedEntries);
    content_frontend_plugin_content_simple_form_select_assignment_clearList(listSelected);
    content_frontend_plugin_content_simple_form_select_assignment_addListEntry(listSelected, selectedEntries);
  }
  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['all']['reset']      = content_frontend_plugin_content_simple_form_select_assignment_getInternListSelection(listAll, 'all');
  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['selected']['reset'] = content_frontend_plugin_content_simple_form_select_assignment_getInternListSelection(listSelected, 'all');

  //Buttons / Events

  //Menu
  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['menu']['buttons']['selected_move_right'] = element_isObject(menuID+'_cmd_selected_move_right'+'_'+boxID);
  event_add(content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID].menu.buttons.selected_move_right, 'click', content_frontend_plugin_content_simple_form_select_assignment_listMenuCmdWrapper);

  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['menu']['buttons']['selected_move_left'] = element_isObject(menuID+'_cmd_selected_move_left'+'_'+boxID);
  event_add(content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID].menu.buttons.selected_move_left, 'click', content_frontend_plugin_content_simple_form_select_assignment_listMenuCmdWrapper);

  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['menu']['buttons']['all_move_right'] = element_isObject(menuID+'_cmd_all_move_right'+'_'+boxID);
  event_add(content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID].menu.buttons.all_move_right, 'click', content_frontend_plugin_content_simple_form_select_assignment_listMenuCmdWrapper);

  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['menu']['buttons']['all_move_left'] = element_isObject(menuID+'_cmd_all_move_left'+'_'+boxID);
  event_add(content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID].menu.buttons.all_move_left, 'click', content_frontend_plugin_content_simple_form_select_assignment_listMenuCmdWrapper);

  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['menu']['buttons']['reset'] = element_isObject(menuID+'_cmd_reset'+'_'+boxID);
  event_add(content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID].menu.buttons.reset, 'click', content_frontend_plugin_content_simple_form_select_assignment_listMenuCmdWrapper);

  //control_select_list_all
  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['all']['move_up']   = element_isObject(listAllID+'_cmd_up'+'_'+boxID);
  event_add(content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID].lists.all.move_up, 'click', content_frontend_plugin_content_simple_form_select_assignment_listInternMoveSelection);

  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['all']['move_down'] = element_isObject(listAllID+'_cmd_down'+'_'+boxID);
  event_add(content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID].lists.all.move_down, 'click', content_frontend_plugin_content_simple_form_select_assignment_listInternMoveSelection);


  //control_select_list_selected
  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['selected']['move_up']   = element_isObject(listSelectedID+'_cmd_up'+'_'+boxID);
  event_add(content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID].lists.selected.move_up, 'click', content_frontend_plugin_content_simple_form_select_assignment_listInternMoveSelection);

  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['selected']['move_down'] = element_isObject(listSelectedID+'_cmd_down'+'_'+boxID);
  event_add(content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID].lists.selected.move_down, 'click', content_frontend_plugin_content_simple_form_select_assignment_listInternMoveSelection);

}

function content_frontend_plugin_content_simple_form_select_assignment_getData(boxID){
  return content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID];
}


function content_frontend_plugin_content_simple_form_select_assignment_listMenuCmdWrapper(ev){
  if(!ev) ev = window.event;

  var idParts = this.id.split('_cmd_');

  var listID = idParts[0];
  var tmpData = idParts[1].split('_');

  var boxID = tmpData.pop();
  var cmd   = tmpData.join('_');

  var data = content_frontend_plugin_content_simple_form_select_assignment_getData(boxID);

  var listLeft  = data.lists.all.object;
  var listRight = data.lists.selected.object;
  var selectedEntries;

  switch(cmd){
    default:
      break;

    case 'selected_move_right':
      selectedEntries = content_frontend_plugin_content_simple_form_select_assignment_getInternListSelection(listLeft);
      content_frontend_plugin_content_simple_form_select_assignment_addListEntry(listRight, selectedEntries);
      content_frontend_plugin_content_simple_form_select_assignment_removeListEntry(listLeft, selectedEntries);
      break;

    case 'selected_move_left':
      selectedEntries = content_frontend_plugin_content_simple_form_select_assignment_getInternListSelection(listRight);
      content_frontend_plugin_content_simple_form_select_assignment_addListEntry(listLeft, selectedEntries);
      content_frontend_plugin_content_simple_form_select_assignment_removeListEntry(listRight, selectedEntries);
      break;

    case 'all_move_right':
      selectedEntries = content_frontend_plugin_content_simple_form_select_assignment_getInternListSelection(listLeft, 'all');
      content_frontend_plugin_content_simple_form_select_assignment_addListEntry(listRight, selectedEntries);
      content_frontend_plugin_content_simple_form_select_assignment_clearList(listLeft);
      break;

    case 'all_move_left':
      selectedEntries = content_frontend_plugin_content_simple_form_select_assignment_getInternListSelection(listRight, 'all');
      content_frontend_plugin_content_simple_form_select_assignment_addListEntry(listLeft, selectedEntries);
      content_frontend_plugin_content_simple_form_select_assignment_clearList(listRight);
      break;

    case 'reset':
      content_frontend_plugin_content_simple_form_select_assignment_clearList(listLeft);
      content_frontend_plugin_content_simple_form_select_assignment_addListEntry(listLeft, data.lists.all.reset);
      content_frontend_plugin_content_simple_form_select_assignment_clearList(listRight);
      content_frontend_plugin_content_simple_form_select_assignment_addListEntry(listRight, data.lists.selected.reset);
      break;
  }

}


function content_frontend_plugin_content_simple_form_select_assignment_listInternMoveSelection(ev){
  if(!ev) ev = window.event;

  var idParts = this.id.split('_cmd_');

  var listID = idParts[0];
  var tmpData = idParts[1].split('_');

  var boxID = tmpData.pop();
  var cmd   = tmpData.pop();

  listID+= '_'+boxID;
  var listObj = element_isObject(listID);

  if(listObj.selectedIndex<0) return true; //nichts ausgewühlt

  var currentEntries  = listObj.options;
  var selectedEntries = content_frontend_plugin_content_simple_form_select_assignment_getInternListSelection(listObj);

  var oldPos = listObj.selectedIndex;
  var newPos = null;
  if(cmd=='up'){
    newPos = ((oldPos-1)>=0)?(oldPos-1):0;
  } else {
    newPos = ((oldPos+1)<listObj.options.length)?(oldPos+1):(listObj.options.length-1);
  }

  var newEntries = new Array();
  var cnt = 0;
  for(var i=0;i<currentEntries.length;i++){
    var item = currentEntries[i];

    //nicht gewühlte Eintrüge ermitteln
    if(typeof selectedEntries[item.index] == 'undefined'){
      newEntries.push(item);
    }
  }

  //Liste zurücksetzen
  content_frontend_plugin_content_simple_form_select_assignment_clearList(listObj);

  //Selected Entries einfügen
  cnt = newPos;
  for(var j in selectedEntries){
    newEntries.splice(cnt, 0, selectedEntries[j]);
    cnt++;
  }

  //Liste füllen
  content_frontend_plugin_content_simple_form_select_assignment_addListEntry(listObj, newEntries)

}

function content_frontend_plugin_content_simple_form_select_assignment_addListEntry(listObj, options){
  listObj   = element_isObject(listObj);

  if(typeof options.length == 'number' || object_count(options)!=null){ //ist ein Array/Objekt
    for(var j in options){

      var newOption = document.createElement('option');
      newOption.value = options[j].value;
      newOption.text  = options[j].text;
      newOption.selected  = options[j].selected;

      listObj.appendChild(newOption);
    }
  } else { //ist ein Object
    var optionObj = element_isObject(options);

    var newOption = document.createElement('option');
    newOption.value = optionObj.value;
    newOption.text  = optionObj.text;
    newOption.selected  = optionObj.selected;

    listObj.appendChild(newOption);
  }
}

function content_frontend_plugin_content_simple_form_select_assignment_removeListEntry(listObj, options){
  listObj   = element_isObject(listObj);

  if(typeof options.length == 'number' || object_count(options)!=null){ //ist ein Array/Objekt
    for(var j in options){

      listObj.removeChild(options[j]);
    }
  } else { //ist ein Object
    var optionObj = element_isObject(options);
    listObj.removeChild(optionObj);
  }
}

function content_frontend_plugin_content_simple_form_select_assignment_clearList(listObj){
  listObj   = element_isObject(listObj);

  //Liste zurücksetzen
  listObj.options.length = 0;
}

function content_frontend_plugin_content_simple_form_select_assignment_getInternListSelection(listID, getEntries, valueList){

  getEntries = (typeof getEntries == 'undefined')?'selected':getEntries;
  var listObj = element_isObject(listID);

  var selectedEntries = new Object();
  for(var i=0;i<listObj.options.length;i++){
    var item = listObj.options[i];
    var cont = false;
    switch(getEntries){
      default:
        break;

      case 'selected':
        if(!item.selected) cont = true;
        break;

      case 'value':
        if(typeof valueList == 'undefined') cont = true;
        if(object_count(valueList)>0 && (typeof valueList[item.value] == 'undefined')) cont = true;
        break;
    }

    if(cont) continue;

    if(typeof selectedEntries[item.index] == 'undefined') selectedEntries[item.index] = new Object();

    selectedEntries[item.index] = item;
  }

  return selectedEntries;
}

//Image select


function content_frontend_plugin_content_simple_form_imageselect_initFields(objID){
  var parentObj = element_isObject(objID);
  var obj = null;

  if(typeof parentObj['alvine_imageButtonLabels'] == 'undefined') parentObj['alvine_imageButtonLabels'] = new Array();

  for(var i in parentObj.alvine_imageButtonLabels){
    var imageButton =  parentObj.alvine_imageButtonLabels[i];

    if(typeof imageButton != 'object') continue;
    event_add(imageButton, 'mouseover', content_frontend_plugin_content_simple_form_imageselect_setHover);
    event_add(imageButton, 'mousedown', content_frontend_plugin_content_simple_form_imageselect_setStatus);

    event_add(imageButton, 'mouseout', content_frontend_plugin_content_simple_form_imageselect_resetHover);


  }

  parentObj['alvine_setStatus'] = function(activeID){


    for(var i in this.alvine_imageButtonLabels){

      buttonObj = this.alvine_imageButtonLabels[i];

      if(buttonObj.id!=activeID){
        element_removeClassName(buttonObj, 'active', ' ');
      } else {
        element_removeClassName(buttonObj, 'active', ' ');
        element_addClassName(buttonObj, 'active');
      }
    }

    return true;
  }

  parentObj['alvine_resetHover'] = function(){


    for(var i in this.alvine_imageButtonLabels){

      buttonObj = this.alvine_imageButtonLabels[i];

      element_removeClassName(buttonObj, 'hover', ' ');

    }

    return true;
  }

  parentObj['alvine_setHover'] = function(activeID){

    for(var i in this.alvine_imageButtonLabels){

      buttonObj = this.alvine_imageButtonLabels[i];

      if(buttonObj.id!=activeID){
        element_removeClassName(buttonObj, 'hover', ' ');
      } else {
        element_removeClassName(buttonObj, 'hover', ' ');
        element_addClassName(buttonObj, 'hover');
      }
    }

    return true;
  }

  parentObj['alvine_getChildPanel'] = function(value, index){
    for(var i in this.alvine_imageButtonPanels){
      var tmpInput = this.alvine_imageButtonPanels[i];

      if(tmpInput.value != value && i != index) continue;

      return tmpInput;
    }

    return false;
  };

  parentObj['alvine_getChildButton'] = function(value, index){
    for(var i in this.alvine_imageButtonInputs){
      var tmpInput = this.alvine_imageButtonInputs[i];

      if(tmpInput.value != value && i != index) continue;

      return tmpInput;
    }

    return false;
  };

  parentObj['alvine_setChildPanelDisplay'] = function(value, status){

    var imgPanel  = this.alvine_getChildPanel(value);
    var imgButton = this.alvine_getChildButton(value);

    if(!imgPanel)  return false;
    if(!imgButton) return false;

    //status = (typeof status == 'undefined')?true:false;

    if(!status) {
      element_setDisplay(imgPanel.object, 'none');
      imgButton.checked = '';
    } else {
      element_setDisplay(imgPanel.object, 'block');
    }

    return true;
  };

  parentObj['alvine_setChildrenDisplay'] = function(data, srcObj){
    if(data=='' && typeof this.alvine_initValueList == 'undefined'){
      return true;
    }

    if(data==''){
      data = this.alvine_initValueList;
    }

    var values = new Array();
    if(typeof data != 'object') {
      if(strstr(data, ',')){
        data = data.split(',');
        for(var i in data){
          values.push(data[i]);
        }
      } else {
        values.push(data);
      }
    } else {
      values = data;
    }

    if(typeof this.alvine_configurator_settings != 'undefined' && typeof this.alvine_configurator_settings.values != 'undefined'){
      if(values != null){
        if(typeof this.alvine_configurator_settings.values[values[0]] != 'undefined'){
          values = this.alvine_configurator_settings.values[values[0]];

          if(typeof values != 'object' && strstr(values, ',')) values = values.split(',');
        }
      } else {
        values = this.alvine_initValueList;
      }
    }

    var ret = null;
    for(var i in this.alvine_imageButtonPanels){
      var tmp = this.alvine_imageButtonPanels[i];
      var buttonObj = tmp.object;
      var value = tmp.value;
      var found = false;

      for(var j in values){

        if(value != values[j]) continue;
        found = true;
        ret = (ret==null)?value:ret;
        break;
      }

      if(!found) {
        element_setDisplay(buttonObj, 'none');
      } else {
        element_setDisplay(buttonObj, 'block');
      }
    }

    return ret;
  }


  return true;
}

function content_frontend_plugin_content_simple_form_imageselect_addImageButton(parentID, buttonLabelID, buttonID, panelID, imageID, imageSrc){
  var parentObj = element_isObject(parentID);
  if(!parentObj) return false;

  var buttonLabelObj = element_isObject(buttonLabelID);
  if(!buttonLabelObj) return false;

  var buttonPanelObj = element_isObject(panelID);
  if(!buttonPanelObj) return false;

  if(typeof parentObj['alvine_imageButtonLabels'] == 'undefined') parentObj['alvine_imageButtonLabels'] = new Array();
  if(typeof parentObj['alvine_imageButtonInputs'] == 'undefined') parentObj['alvine_imageButtonInputs'] = new Array();
  if(typeof parentObj['alvine_imageButtonPanels'] == 'undefined') parentObj['alvine_imageButtonPanels'] = new Array();
  if(typeof parentObj['alvine_imageButtonSrc']    == 'undefined') parentObj['alvine_imageButtonSrc']    = new Object();
  if(typeof parentObj['alvine_initValueList']     == 'undefined') parentObj['alvine_initValueList']     = new Array();

  var buttonObj = element_isObject(buttonID);

  parentObj.alvine_imageButtonLabels.push(buttonLabelObj);
  parentObj.alvine_imageButtonInputs.push(buttonObj);
  parentObj.alvine_imageButtonSrc[buttonObj.value] = imageSrc;
  parentObj.alvine_initValueList.push(buttonObj.value);

  var newEntry = new Object();
  newEntry['object'] = buttonPanelObj;
  newEntry['value']  = buttonObj.value;
  parentObj.alvine_imageButtonPanels.push(newEntry);

  element_move(buttonObj, -999, -999);

  return true;
}

function content_frontend_plugin_content_simple_form_imageselect_triggerInputField(ev){
  if(!ev) ev = window.event;

  if(typeof this.alvine_triggerInput == 'undefined') return false;

  this.alvine_triggerInput(ev);

  return true;
}


function content_frontend_plugin_content_simple_form_imageselect_resetHover(ev){

  if(!ev) ev = window.event;

  var objID = this.id;

  var nameParts = objID.split('_label__');
  var parentID = nameParts[0];

  var parentObj = element_isObject(parentID);

  if(!parentObj) return false;

  parentObj.alvine_resetHover(objID);

  return true;
}

function content_frontend_plugin_content_simple_form_imageselect_setHover(ev){

  if(!ev) ev = window.event;

  var objID = this.id;

  var nameParts = objID.split('_label__');
  var parentID = nameParts[0];

  var parentObj = element_isObject(parentID);

  if(!parentObj) return false;

  parentObj.alvine_setHover(objID);

  return true;
}



function content_frontend_plugin_content_simple_form_imageselect_setStatus(ev){

  if(!ev) ev = window.event;

  var objID = this.id;

  var nameParts = objID.split('_label__');
  var parentID = nameParts[0];

  var parentObj = element_isObject(parentID);

  if(!parentObj) return false;

  parentObj.alvine_setStatus(objID);

  return true;
}


//Multi
var registeredItems = new Object();

function forms_initImageSelectMultiFields(parentID, selectionMaxItems){
  var parentObj = element_isObject(parentID);
  var obj = null;

  if(typeof registeredItems[parentID] == 'undefined') registeredItems[parentID] = new Object();

  registeredItems[parentID]['selectionMaxItems'] = (typeof selectionMaxItems != 'undefined')?selectionMaxItems:null;

  for(var i in parentObj.childNodes){
    for(var j in parentObj.childNodes[i].childNodes){
      obj = parentObj.childNodes[i].childNodes[j].id;
      if(obj == null) continue;
      if(typeof obj == 'undefined') continue;
      if(obj.substr(0,parentID.length)!=parentID) continue;

      var nameParts = obj.split('_label__');
      if(nameParts[0]!=parentID) continue;

      var itemObj = element_isObject(nameParts[0]+'_item__'+nameParts[1]);

      event_add(obj, 'mouseover', forms_setHover);
      event_add(obj, 'mouseout', forms_setHover);
      event_add(itemObj, 'change', forms_setMultiStatus);
    }
  }

}

function forms_setMultiStatus(e){
  var objID = this.id;
  var nameParts = objID.split('_item__');
  var parentID = nameParts[0];

  var parentObj = element_isObject(parentID);
  var currentLabelObj = element_isObject(nameParts[0]+'_label__'+nameParts[1]);

  selectionCount = 1;
  for(var i in parentObj.childNodes){
    for(var j in parentObj.childNodes[i].childNodes){
      obj = parentObj.childNodes[i].childNodes[j].id;
      if(obj == null) continue;
      if(typeof obj == 'undefined') continue;
      if(obj == objID) continue;
      if(obj.substr(0,parentID.length)!=parentID) continue;

      var nameParts = obj.split('_label__');
      if(nameParts[0]!=parentID) continue;

      var itemObj = element_isObject(nameParts[0]+'_item__'+nameParts[1]);
      var labelObj = element_isObject(nameParts[0]+'_label__'+nameParts[1]);

      if(itemObj.checked == true){
        if(registeredItems[parentID].selectionMaxItems!=null
          && selectionCount > registeredItems[parentID].selectionMaxItems){
          alert(' Es stehen nur '+registeredItems[parentID].selectionMaxItems+' Müglichkeiten zur Auswahl.');
          this.checked = false;
          element_removeClassName(currentLabelObj,'active');
          selectionCount--;
          return false;
        }
        element_removeClassName(labelObj,'active');
        element_addClassName(labelObj,'active',' ');
        selectionCount++;
      } else {
        element_removeClassName(labelObj,'active');
      }
    }
  }
}

function forms_resetMultiStatus(parentID){

  var nameParts = new Array();
  nameParts.push(parentID);

  var parentObj = element_isObject(parentID);

  for(var i in parentObj.childNodes){
    for(var j in parentObj.childNodes[i].childNodes){
      obj = parentObj.childNodes[i].childNodes[j].id;
      if(obj == null) continue;
      if(typeof obj == 'undefined') continue;

      if(obj.substr(0,parentID.length)!=parentID) continue;

      var nameParts = obj.split('_label__');
      if(nameParts[0]!=parentID) continue;

      var itemObj = element_isObject(nameParts[0]+'_item__'+nameParts[1]);
      var labelObj = element_isObject(nameParts[0]+'_label__'+nameParts[1]);

      itemObj.checked = false;
      element_removeClassName(labelObj,'active');

    }
  }
}

/**  **/
page_onLoad(forms_processExtendedControls);
page_onLoad(forms_initExtendedControls);


