/**
 * Get form's data from the form with id "formName"
 * 
 * @author Alessandro Coscia
 * @see www.programmatorephp.it
 * 
 * @param formID
 * @return Array
 */
function getFormData_Array(formID) {
  var form = document.getElementById(formID);
  var formsValues = new Array();

  for (i=0; i < form.length; i++) {
    formsValues[form[i].name] = form[i].value;
  }
  
  return formsValues;
}


/**
 * Get form's data from the form with id "formName"
 * 
 * @author Alessandro Coscia
 * @see www.programmatorephp.it
 * 
 * @param formName
 * @return Object
 */
function getFormData_Object(formName) {
  // Find form
  var form = document.getElementById(formName);
  // Init
  var formsValues = new Object();

  // For each form's field
  for (i=0; i < form.length; i++) {
    formsValues[form[i].name] = new Object();
    formsValues[form[i].name] = form[i].value;
  }
  
  return formsValues;
}


/**
 * Returns an Object with same structure and content of a given array
 * Useful for Array to Object convertion required for JSON stringify()
 *
 * @author Alessandro Coscia
 * @see www.programmatorephp.it
 * 
 * @param Array array
 * @return Object
 */
function array2obj(array) {
  var obj = new Object();
  
  for (var label in array) {
    obj[label] = new Object();
    
    // Recursion if needed
    if (typeof array[label] == "object") {
      obj[label] = array2obj(array[label]);
    }
    // Simple vars
    else
      obj[label] = array[label];
  }
  
  return obj;
}
