/**
 * content.simple.form.js - insert headline here
 *
 * COPYRIGHT: All  title   and  proprietary  rights,  including  trade
 * secrets,   in   the   Software   and   any   copies thereof and the
 * accompanying  written   materials,   are  owned  by   schukai  GmbH
 * and  are  protected  by  German  copyright  laws,  other applicable
 * copyright   laws  and  international  treaty  provisions.
 *
 * @package    alvine
 * @author     schukai GmbH <info@schukai.de>
 * @copyright  Copyright (C) 2002, 2003, 2004, 2005, 2006 schukai GmbH
 * @license    http://www.alvine.de/license/
 * @version    20061114
 * @link       http://www.alvine.de/
 */
 
function content_frontend_plugin_content_simple_form_init(){

}


function content_frontend_plugin_content_simple_form_undoSpecialInit(obj) {
  obj = element_isObject(obj);
  if(!obj) return false;
  
  effects_fade(obj, 100, 'now', 20, 12);

  return true;
}


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

  if(typeof obj.id == 'undefined') return false;
  
  var parentObj = obj.parentNode;
  var newNode = obj.cloneNode(true);
  
  var objID = obj.id;
  var counterObj = element_isObject(objID+'_copiescount');  
  var maxObj     = element_isObject(objID+'_copiesmax');  
  var currentCount = parseInt(counterObj.value);

  objID = objID.split('__');
  var objKey   = objID[0];
  var objIndex = objID[1];
  
  //Letztes GruppenMitglied ermitteln;
  var insertBeforeObj = element_isObject(objKey+'__'+currentCount);

  //NächstenKnoten anwählen
  if(insertBeforeObj) insertBeforeObj = insertBeforeObj.nextSibling;
  
  search = '__'+objIndex;
  
  
  if(currentCount>maxObj.value) {
    alert('too many Fields copied, max is '+maxObj.value);
    return false;
  }
  
  currentCount++;
  var newID = objKey+'__'+currentCount;
  
  replace = '__'+currentCount;
  
  //Daten anpassen
  newNode.id = newID;
  
  for(var i in newNode.childNodes){   
    var tmpItem = newNode.childNodes[i];
    
    if(tmpItem.nodeName != 'DIV') continue;
    
    for(var j in tmpItem.childNodes){    //rows
      var tmpSubItem = tmpItem.childNodes[j];
      
      if(tmpSubItem.nodeName != 'DIV') continue;

      for(var k in tmpSubItem.childNodes){  //columns (label/field)
        var child = tmpSubItem.childNodes[k];  

        if(typeof child.value != 'undefined') child.value = '';
        
        if(typeof child.checked != 'undefined') child.checked = null;
        if(typeof child.selected != 'undefined') child.selected = null;
        
        if(typeof child.attributes != 'undefined' && child.attributes != null && typeof child.attributes.length != 'undefined') {
          for(var l in child.attributes){  //attributes
            var attribute = child.attributes[l];

            if(attribute == null) continue;            
            if(typeof attribute.nodeValue != 'string') continue;
            if(attribute.nodeValue == '') continue;            
            
            child.attributes[l].nodeValue = str_replace(search, replace, child.attributes[l].nodeValue);
          }
        };
        
        for(var kk in child.childNodes){  //columns (label/field)
          var child2 = child.childNodes[kk];  
          
          if(typeof child2.value != 'undefined') child2.value = '';
          if(typeof child2.checked != 'undefined') child2.checked = null;
          if(typeof child2.selected != 'undefined') child2.selected = null;
          
          
          if(typeof child2.attributes == 'undefined') continue;
          if(child2.attributes == null) continue;
          if(typeof child2.attributes.length == 'undefined') continue;
          if(child2.attributes.length == 0) continue;
          
          for(var ll in child2.attributes){  //attributes
            var attribute = child2.attributes[ll];
            if(attribute == null) continue;            
            if(typeof attribute.nodeValue != 'string') continue;
            if(attribute.nodeValue == '') continue;
            
            child2.attributes[ll].nodeValue = str_replace(search, replace, child2.attributes[ll].nodeValue);
            
          }
        }
        
      }
      
    }
    
  }
  
  if(typeof insertBeforeObj == 'object'){
    parentObj.insertBefore(newNode, insertBeforeObj);
  } else {
    parentObj.appendChild(newNode);
  }
  
  counterObj.value = currentCount;
  
  return true;
}

//control select assignment

if(typeof content_frontend_plugin_content_simple_form_controlSelectAssignmentData == 'undefined') var 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();
  for(var x in listSelected.options){
    var item = listSelected.options[x];
    if(typeof item.value == 'undefined') 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);
    //event_add(imageButton, 'mousedown', content_frontend_plugin_content_simple_form_imageselect_setActive);
    //event_add(imageButton, 'mouseup', content_frontend_plugin_content_simple_form_imageselect_setActive);
    //event_add(imageButton, 'change', content_frontend_plugin_content_simple_form_imageselect_setStatus);
  
  }

  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, -20, -20);
  
  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');
      
    }
  }  
}

