/**
 * 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 = element_cloneNode(obj, 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;
}


