//
// add the values of the inputs to the value of the list
// 
function addElementsByFormId( _id, _elements) {
   var tmp = eval(_elements);
   var formElements = getElementsByFormId(_id);
   for(property in formElements){
       tmp[property] = formElements[property];
   }
   return tmp;
}


// take a block of javascript that generates a map
// take function that returns an Object() with more properties
// join the two and return the result

function join(_elements, _function){
   var decodedElements = decodeURIComponent(_elements);
   var tmp = eval(decodedElements);
   var functionName = _function+"()";
   var functionResult = eval(functionName);

   for(property in functionResult){
       tmp[property] = functionResult[property];
   }

   return tmp;
}

// 
// harvest a property array from the elements of the form
//
function getElementsByFormId(_id){
   var result = new Object();
   var _form = document.forms[_id];
   if(_form){
       var _elements = _form.elements;
       if(_elements){
           for(var i = 0; i < _elements.length ; i++){
               var index = _elements[i].name;
               if(!index){
                  index = "element_"+i;
               }
               if('checkbox' == _elements[i].type){
                  result[index] = _elements[i].checked;
               }else{
                  result[index] = _elements[i].value;
               }
           }
       }
   }
   return result;
}

// function to be call when unpacking a return 
function unpack(_function, _list){
    // set the start of a function call
    var _call = _function+"(";
    var passed = false;
    for(var i = 0; i < _list.length; i++){
       if(passed){
          _call = _call + ", ";
       }else{
          passed = true;
       }
       eval("var x"+i+"=_list["+i+"]");
       _call = _call + "x"+i;   
    }
    _call = _call + ")";
    eval(_call);
}

// just a ignore function to circumpass some unwanted behavior
function donttouch(_data){
   return _data;
}