/**
 * Wrapper functionality for AJAX request using prototype
 *
 * This file is part of Batavi Open E-Commerce Solution.
 *
 * Batavi Open E-Commerce Solution is free software: you can redistribute 
 * it and/or modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 * 
 * @copyright 2007-2008 ICEshop Copyright 
 * 
 * @category   javascript
 * @package    javascript
 * @author     Arjan Gelderblom <arjan@iceshop.nl>
 * @license    GNU General Public License v3
 * 
 * @link       http://www.gnu.org/licenses/
 * @link       http://www.gnu.org/licenses/gpl-faq.html
 */
var startedRequest = false;

function AsyncRequest(form, ajaxID, box, instanceKey) {
  
  document.getElementById('ajaxOverlay').className = 'ajaxOverlay';

  postParameters = "box=" + box + "&instance=" + instanceKey;
  for(i = 0; i < document.getElementById('create').length; i++) {
    var element = document.getElementById('create').elements[i];
    if (!(element.type == 'checkbox' && !element.checked)) {
      postParameters += "&" + element.name + "=" + element.value;
    }
  }
  
  startedRequest = true;
  
  new Ajax.Updater(ajaxID, 'async.php',
  {
    method:'post',
    evalScripts: true,
    parameters: postParameters,
    onSuccess: function(transport){
      document.getElementById('ajaxOverlay').className = '';
      startedRequest = false;
    },
    onFailure: function(){ 
      alert('Something went wrong...');
      startedRequest = false;
    }
  });
  
  /** 
   * Function still in comments for easy debugging
   */
  //new Ajax.Request('async.php',
  //{
  //  method:'post',
  //  parameters: postParameters,
  //  onSuccess: function(transport){
  //    document.getElementById('ajaxOverlay').className = '';
  //    
  //    alert(transport.responseText); 		
  //  },
  //  onFailure: function(){ alert('Something went wrong...') }
  //});

}
