/******************************************************************************
 *
 *                   INDIGEN SOLUTIONS CODE PROPERTY
 *       The present javascript code is property of Indigen Solutions. This 
 *     code can only be used inside Internet/Intranet web sites located on 
 *  *web servers*, as the outcome of a licensed Indigen Solutions application 
 *  only. Any unauthorized use, reverse-engineering, alteration, transmission, 
 * transformation, facsimile, or copying of any means (electronic or not) is 
 *     strictly prohibited and will be prosecuted. Removal of the present 
 *              copyright notice is strictly prohibited
 *         Copyright (c) 2004 Indigen Solutions. All Rights Reserved.
 *
 * RCS Id                       $Id: sender.js,v 1.6 2005/02/28 09:53:35 indigen Exp $
 * RCS Revision                 $Revision: 1.6 $
 * RCS Check in date            $Date: 2005/02/28 09:53:35 $
 * 
 ******************************************************************************/
 
/*
  Be carefull ...
  
  The request in the iframe (action  param) must be with the same server as the global request 
  to avoid an invalid permission error.

*/

/* Classes. */

function Sender(action, func) {
  // Attributes.
  this.action = action;
  this.nbParams = 0;
  this.params = new Array();
  this.func = func;  
  // Methods.
  this.addParam  = Sender_addParam;
  this.send      = Sender_send;
}

function Sender_addParam (name, value) {
  this.params[this.nbParams++] = new Array(name, value);
}

function Sender_send(form) {
  if (form == null) {
    form = document.createElement("form");
    document.body.appendChild(form);
  }
  // Manage result
  if ( this.func != null ) {
    var iframe = document.createElement("<iframe name=\"iframe\" id=\"iframe\" width=\"0\" src=\""+BLANK_URL+"\" height=\"0\" style=\"display:none\">");
    var thisRef = this;
    document.body.appendChild(iframe);	
    iframe.onload = function() {
      thisRef.func(iframe.contentWindow.document.body.innerHTML);
    };
    form.target = "iframe";
  }    
  form.id     = "form";
  form.action = this.action;
  form.method = "post";
  form.encoding = "multipart/form-data";
  for (var i = 0; i < this.nbParams; i++) {
    var input   = document.createElement("input");
    input.name  = this.params[i][0];
    input.value = this.params[i][1];
    input.type  = "hidden";
    form.appendChild(input);
  }
  form.submit();
}
