/*******************************************************************************
  Classe per l'oggetto AJAX Cross-Browser
  
  Testato su:
    - Firefox 3.0
    - Internet Explorer 7
    
  Problemi con ajax e browser:
  
    - Ajax e cache:
        IE ha problemi di cache e quindi la pagina caricata con ajax potrebbe
        essere non aggiornata. Per ovviare a questo problema prima di qls 
        output le pagine php richiamate dovranno spedire gli header opportuni
        per escludere la cache:
        
        header("Cache-Control: no-cache, must-revalidate");   // HTTP/1.1
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");     // Date in the past
        
        soluzione di aggiungere una stringa casuale
        
        soluzione di aggiungere delle request per escludere la cache
        
    - Ajax, php e codifica utf8 - latin
      Tutti i dati sia GET che POST che invio devono essere trattati con la funzione:
        encodeURIComponent
      che oltre a trattare i caratteri speciali, converte tutto in UTF-8.
      Ajax e JS funzionano in Utf-8 (unicode) quindi il passaggio di dati deve
      essere fatto in utf8.
      La pagina php che elaborerà la richiesta dovrà quindi essere in grado di leggere
      i dati in utf8 e rimandare dati in codifica utf8. Se la pagina è cmq in utf8
      problemi non ci sono, se la pagina è codificata in ANSI o ISO LATIN i dati
      ricevuti devono essere trattati con utf8_decode() poi si può lavorare con
      tranquillità. Tutto ciò che deve essere rimandato in ouput deve essere 
      ricodificato con utf8_encode() in modo da mantenere il canale di comunicazione
      in utf8.
    - Per ovviare al problema della responseXML, il documento restituito da php
      deve avere questo header:
        header('Content-Type: text/xml');
      Per ovviare ulteriormente al problema della cache dovranno essere inserite le
      seguenti righe di header:
        header("Cache-Control: no-cache, must-revalidate");
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    - POSSIBILE MIGLIORAMENTO: nello sblocco dello stato possiamo prendere la response
      copiarla e poi sbloccare lo stato e fare l'operazione. Oppure eseguire l'operazione
      e poi sbloccare lo stato.
  
*******************************************************************************/

JAjax = function ()
{ 
  // ---------------------------------------------------------------------------
  // Definizione di proprietà
  // ---------------------------------------------------------------------------
  
  this.state        = true;       // Indica se l'oggetto è inizializzato
  this.message      = "";         // Mantiene il messaggio di errore
  this.XHR          = null;       // Oggetto xmlhttprequest
  this.ttl          = 0;          // Indica il ttl della chiamata
  this.data         = "";         // Mantiene i dati da inviare
  this.link         = null;       // Indica la pagina di riferimento
  this.method       = null;       // Indica il metodo da usare ( get/post )
  this.operation    = null;       // Mantiene l'operazione da eseguire sui dati restituiti
  this.errOperation = null;       // Mantiene l'operazione da eseguire in caso di errori
  this.manErrorOp   = null;       // Mantiene l'operazione da eseguire in caso di controllo errori via XML
  this.manageError  = false;      // Indica se eseguire il controllo degli errori in caso di responseXML
  this.cacheControl = true;       // Indica se è necessario eliminare la cache
  this.xmlResponse  = true;       // Indica il tipo response ( text/xml )
  this.localState   = false;      // Indica il semaforo locale 
  this.global       = true;       // Indica se i controlli per l'oggetto sono eseguiti globalmente o localmente

  // --------------------------------------------------------------------------- 
  // Definizione del metodo costruttore
  // ---------------------------------------------------------------------------
  
  this.JAjax = function()
  {
    this.initialize();  
        
    this.link         = null;
    this.cacheControl = true;
    this.xmlResponse  = true;  
    this.ttl          = 30000;
    this.method       = "post";
    
    this.errOperation = function (str){
                          alert(str);
                        }
    this.operation    = function (str){
                          alert(str);
                        }
                        
    this.manErrorOp   = function (xmlDocument, operation, errOperation){
                          // prima di tutto devo controllare che sia veramente un documento xml.
                          if ( xmlDocument )
                          {
                            // Ottengo la radice del documento
                            var response = xmlDocument.documentElement;
                            // Controllo il risultato
                            var result = response.getElementsByTagName("result")[0].childNodes[0].nodeValue;
                            
                            if (result == "False")
                            {
                              var error = response.getElementsByTagName("error");
                              
                              for (var i=0; i< error.length; i++)
                              {
                                err_element_id    = error[i].getElementsByTagName("type")[0].childNodes[0].nodeValue;
                                err_element_value = error[i].getElementsByTagName("value")[0].childNodes[0].nodeValue;
                                
                                // Inserisco gli errori
                                if ( err_element_id.toUpperCase() == "GENERIC" )
                                {
                                  errOperation("Errore interno al server. Riprovare più tardi");
                                }
                                else
                                
                                {
                                  document.getElementById(err_element_id).innerHTML = "<p>"+err_element_value+"</p>";
                                }
                              }
                              
                            }
                            else
                            {
                              // Eseguo la corretta operazione(passandogli true che è il risultato corretto)
                              operation("True");
                            }
                          }
                          else
                          {
                            // Mandiamo la notifica
                            errOperation("Errore interno al server. Riprovare più tardi");
                          }    
                        }
  };
  
  // ---------------------------------------------------------------------------
  // Definizione dei metodi
  // ---------------------------------------------------------------------------
  
  // Metodo per l'inizializzazione di una chiamata
  this.initialize = function()
  {
    this.XHR          = this.createRequest();
    this.message      = "";
    this.state        = true;
    this.data         = "";    
  }

  // Metodo per la creazione dell'oggetto request
  this.createRequest = function() 
  {
    var xmlHttp;
    try
    {
      // Oggetto per Firefox, Opera 8.0+, Safari
      xmlHttp = new XMLHttpRequest();
    }
    catch (e)
    {
      try
      {
        // ActiveX per Internet Explorer
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e)
      {
        try
        {
          // ActiveX per Internet Explorer < 6.0
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e)
        {
          this.state = false;
          this.message = e.message;
          return null;
        }
      }
    }
    this.state = true;
    return xmlHttp;
  }
  
  // Metodo per l'invio dei dati
  this.sendData = function()
  { 
    // Inizio la chiamata ajax solo se ho semaforo verde
    if ( ( !this.checkState() ) && ( this.state ) ) 
    {
      // Qui devo bloccare lo stato o Locale o globale.
      this.lockState(this);
      
      var checkTime;                      // Oggetto per il controllo del tempo
      var firstCheck    = true;           // Semaforo per il controllo del tempo
      
      // Devo costruire il corretto passaggio di dati per GET/POST
      var link      = ( this.method == "post" )? this.link : this.link+"?"+this.data ;
      var qstring   = ( this.method == "post" )? this.data : "" ;
      
      // Sistema di protezione da cache
      if ( (this.method == "get") && (this.cacheControl) )
      {
        var data = new Date();        
        link += "&tstamp=" + encodeURIComponent(data.getHours() + data.getMinutes() + data.getSeconds() );
      }
      
      // Memorizzo l'istante della chiamata ajax
      var dateCall  = new Date();
      var startCall = dateCall.getTime();
      
      // Imposto gli header per la chiamata
      this.XHR.open(this.method, link, true);
      
      // Per le chiamte POST devo aggiungere l'intestazione corretta
      if (this.method == "post")
      {
        this.XHR.setRequestHeader("content-type", "application/x-www-form-urlencoded");
      }
      
      // Per le response XML aggiungo questa ulteriore header
      if ( this.isXMLresponse() )
      {
        this.XHR.setRequestHeader("content-type", "text/xml");
      }
      
      // Questa intestazione va aggiunta per ciascuna connessione
      this.XHR.setRequestHeader("connection", "close");
      
      // Con questa closure realizzo l'oggetto parent per onreadystatechange
      _parent = this;
      
      // Imposto la funzione di controllo dello stato della chiamata ajax
      this.XHR.onreadystatechange = function(){
                                  
                                  if(this.readyState === readyState.COMPLETATO) 
                                  { 
                                    // Blocco il check sul tempo associandogli una funzione vuota.
                                    checkTime = function(){};
                                    
                                    if(statusText[this.status] === "OK") 
                                    {
                                      if ( _parent.isXMLresponse() )
                                      {
                                        // XHR.responseXML.documentElement --> è la radice del documento xml

                                        _parent.unlockState(_parent);                                        
                                        
                                        if (_parent.manageError)
                                        {
                                          _parent.manErrorOp(this.responseXML,_parent.operation,_parent.errOperation);
                                        }
                                        else
                                        {
                                          _parent.operation (this.responseXML);
                                        }                                       
                                      }
                                      else
                                      { 
                                        _parent.unlockState(_parent);
                                        _parent.operation (this.responseText);
                                      }
                                    }
                                    else
                                    {
                                      _parent.unlockState(_parent);    
                                      _parent.errOperation (statusText[this.status]);
                                    }
                                  }
                                  else if(firstCheck)
                                  {
                                    // Dopo il primo check non devo più eseguire questa funzione
                                    firstCheck = false;
                                    
                                    // Definisco la funzione per il check dei tempi
                                    checkTime = function(){
                                                  // Memorizzo l'istante attuale
                                                  dateCurrent  = new Date();
                                                  currentCall = dateCurrent.getTime();
                                                  
                                                  // Controllo il tempo trascorso dalla chiamata
                                                  if ( (currentCall - startCall) > _parent.ttl ) 
                                                  {
                                                    // Blocco i controlli sullo stato della chiamata
                                                    this.onreadystatechange = function(){return false;};
                                                    
                                                    // Lancio il segnale di blocco chiamata
                                                    _parent.XHR.abort(); 
                                                    
                                                    _parent.unlockState(_parent);
                                                  }
                                                  else
                                                  {
                                                    // Se il tempo non è scaduto, re-imposto la chiamata
                                                    setTimeout(checkTime, 100);
                                                  }
                                                  
                                                };
                                    // Chiamo la funzione di check
                                    checkTime();
                                  }
                                };
      
      // Effettuo la chiamata ajax
      this.XHR.send(qstring);
      
    }
    else
    {
      // Devo impostare la restituzioni di un valore es. false
      return false;
    }
  }
  
  //----------------------------------------------------------------------------
  // Definizione di metodi per le proprietà
  //----------------------------------------------------------------------------
  
  // Metodo per controllare lo stato
  this.getState = function()
  {
    return this.state;
  }
  
  // Metodo per controllare il link
  this.getLink = function()
  {
    return this.link;
  }
  
  // Metodo per impostare i link
  this.setLink = function(link)
  {
    this.link = link;
  }
  
  // Metodo per controllare il ttl
  this.getTTL = function()
  {
    return this.ttl;
  }
  
  // Metodo per impostare il ttl
  this.setTTL = function(time)
  {
    this.ttl = time;
  }
  
  // Metodo per controllare l'operazione da eseguire in caso di successo
  this.getOperation = function()
  {
    return this.operation;
  }
  
  // Metodo per impostare l'operazione da eseguire in caso di successo
  this.setOperation = function(op)
  {
    this.operation = op;
  }
  
  // Metodo per controllare l'operazione da eseguire in caso di errore
  this.getErrOperation = function()
  {
    return this.errOperation;
  }
  
  // Metodo per impostare l'operazione da eseguire in caso di errore
  this.setErrOperation = function(op)
  {
    this.errOperation = op;
  }
  
  // Metodo per controllare il method
  this.getMethod = function()
  {
    return this.method;
  }
  
  // Metodo per impostare il method POST
  this.setPost = function() 
  {
    this.method = "post"; 
  }

  // Metodo per impostare il method GET
  this.setGet = function() 
  {
    this.method = "get"; 
  }
  
  // Metodo per aggiungere le coppie chiavi/valori da inviare
  this.addQueryString = function (key,value)
  {
    if (this.data != "")
    {
      this.data += "&";
    }
    // EncodeUri oltre che a proteggere l'invio dei dati in get/post da caratteri
    // particolare, converte il tutto in utf8 per l'invio corretto.
    this.data += key + "=" + encodeURIComponent(value);
  }
  
  // Metodo per l'abilitazione della cache
  this.enableCache = function ()
  {
    this.cacheControl = false;
  }
  
  // Metodo per la disabilitazione della cache
  this.disableCache = function ()
  {
    this.cacheControl = true;
  }
  
  // Metodo per il controllo dell'abilitazione della cache
  this.isCacheEnable = function ()
  {
    return this.cacheControl;
  }
  
  // Metodo per controllare il tipo di response 
  this.isXMLresponse = function ()
  {
    return this.xmlResponse;
  }
  
  // Metodo per impostare la response XML
  this.setXmlResponse = function ()
  {
    this.xmlResponse = true;
  }
  
  // Metodo per impostare la reponse TEXT
  this.setTextResponse = function ()
  {
    this.xmlResponse = false;
  }
  
  // Metodo per impostare il semaforo locale
  this.setLocal = function ()
  {
    this.global = false;
  }
  
  // Metodo per impostare il semaforo globale
  this.setGlobal = function ()
  {
    this.global = true;
  }
  
  // Metodo per controllare il tipo di semaforo
  this.isGlobal = function ()
  {
    return this.global;
  }
  
  // Metodo privato per bloccare il semaforo impostato
  this.lockState = function ( object )
  {
    if (object.isGlobal)
    {
      JAjax.globalState = true;
    }
    else
    {
      object.localState = true;
    }
  }
  
  // Metodo privato per sbloccare il semaforo impostato
  this.unlockState = function ( object )
  {
    if (object.isGlobal)
    {
      JAjax.globalState = false;
    }
    else
    {
      object.localState = false;
    }
  }
  
  // Metodo per controllare il semaforo impostato
  this.checkState = function ()
  {
    return (this.isGlobal)? JAjax.globalState : this.localState;
  } 
  
  // Richiamo il costruttore  
  this.JAjax();
  
}

/*******************************************************************************
 *  METODI/PROPRIETA' DI CLASSE                                                *
*******************************************************************************/

JAjax.globalState = false;  // Variabile semaforo per gestire diverse chiamate ajax.

/*******************************************************************************
 *  COSTANTI UTILIZZATE DALL'OGGETTO                                           *
*******************************************************************************/


// Oggetto per la verifica dello stato
var readyState = {
  INATTIVO:	0,
	INIZIALIZZATO:	1,
	RICHIESTA:	2,
	RISPOSTA:	3,
	COMPLETATO:	4
}

// Array descrittivo dei codici restituiti dal server
var statusText = new Array();
statusText[0]   = "Richiesta Fallita. Riprovare più tardi"; // Aggiunta per Abort
statusText[100] = "Continue";
statusText[101] = "Switching Protocols";
statusText[200] = "OK";
statusText[201] = "Created";
statusText[202] = "Accepted";
statusText[203] = "Non-Authoritative Information";
statusText[204] = "No Content";
statusText[205] = "Reset Content";
statusText[206] = "Partial Content";
statusText[300] = "Multiple Choices";
statusText[301] = "Moved Permanently";
statusText[302] = "Found";
statusText[303] = "See Other";
statusText[304] = "Not Modified";
statusText[305] = "Use Proxy";
statusText[306] = "(unused, but reserved)";
statusText[307] = "Temporary Redirect";
statusText[400] = "Bad Request";
statusText[401] = "Unauthorized";
statusText[402] = "Payment Required";
statusText[403] = "Forbidden";
statusText[404] = "Not Found";
statusText[405] = "Method Not Allowed";
statusText[406] = "Not Acceptable";
statusText[407] = "Proxy Authentication Required";
statusText[408] = "Request Timeout";
statusText[409] = "Conflict";
statusText[410] = "Gone";
statusText[411] = "Length Required";
statusText[412] = "Precondition Failed";
statusText[413] = "Request Entity Too Large";
statusText[414] = "Request-URI Too Long";
statusText[415] = "Unsupported Media Type";
statusText[416] = "Requested Range Not Satisfiable";
statusText[417] = "Expectation Failed";
statusText[500] = "Internal Server Error";
statusText[501] = "Not Implemented";
statusText[502] = "Bad Gateway";
statusText[503] = "Service Unavailable";
statusText[504] = "Gateway Timeout";
statusText[505] = "HTTP Version Not Supported";
statusText[509] = "Bandwidth Limit Exceeded";


/*******************************************************************************
*  FUNZIONI GENERICHE TEMPORANEE (Da sistemare)                                *
*******************************************************************************/

/* Crossing function gerElementsByName (ie suck) */
function getElementsByName_cross(name,tag) 
{
     tag = tag || '*';
     
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) 
     {
          att = elem[i].getAttribute("name");
          if(att == name) 
          {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}

/* display2 */
function display2 ( obj_id, value, closeall )
{ 
  if(!document.getElementById) return;
  obj = document.getElementById(obj_id);
  
  value    = ( value === false ) ? ( false ) : ( true );
  closeall = ( closeall === true ) ? ( true ) : ( false );
  
  if( value )
  { 
    if ( closeall )
    {
      /* var box_el = document.getElementsByName("box_el"); ..w3c.. */ 
      var box_el = getElementsByName_cross("box_el","div"); // MALEDETTO IE!!!!
      
      for(i=0;i<box_el.length;i++)
      {
        
        if( box_el[i].id != obj_id ) 
        { 
          box_el[i].className  = 'div_hidden'; 
          getElement('img_'+box_el[i].id).src = (getElement('img_'+box_el[i].id).src).replace("link_r.gif","link.gif");
        }
      }
    }
    
    if( obj.className == 'div_hidden')
    {
      getElement('img_'+obj_id).src = (getElement('img_'+obj_id).src).replace("link.gif","link_r.gif");
      obj.className = 'div_show';
      
      return true;
    }
    else
    {
      getElement('img_'+obj_id).src = (getElement('img_'+obj_id).src).replace("link_r.gif","link.gif");
      obj.className = 'div_hidden';
      
      return false;
    }
    
  }
  else
  {
    obj.className  = 'div_hidden';
    return false;
  }
}

/* getElement (in old file ajax.js) */
function getElement(id_elemento) 
{
  // elemento da restituire
  var elemento;
 
  // se esiste il metodo getElementById
  // questo if sarà diverso da false, null o undefined
  // e sarà quindi considerato valido, come un true
  if(document.getElementById)
  {
    elemento = document.getElementById(id_elemento);
  } 
  else
  {
    // altrimenti è necessario usare un vecchio sistema
    elemento = document.all[id_elemento];
  }
 // restituzione elemento
 return elemento;
}

/*******************************************************************************
*  FUNZIONI TOOLS                                                              *
*******************************************************************************/

/* Send invito (Tools invia ad amico, old invito.js) */
function send_invito(link,elem)
{

  /* data controls */
  
  var err = false;
  
  
  /* resetto gli errori */
  
  var err_el = getElementsByName_cross("err_desc");
  for(i=0;i<err_el.length;i++)
  {
    err_el[i].innerHTML = "";
  }
   
  // Eseguo i controlli sull'indirizzo mail    
  if ( trim(document.forms['form_invito'].mail.value) == "" )
  {
    // visualizzo e setto l'errore
    getElement('err_mail').innerHTML = "<i>mail non inserita</i>";
    err = true;
  }
  else
  {   
    if ( !( is_valid_mail(document.forms['form_invito'].mail.value) ) )
    {
      getElement('err_mail').innerHTML = "<i>mail non valida</i>";
      err = true;
    }
  }
    
  // Eseguo i controlli sul campo controlcode
  if ( trim(document.forms['form_invito'].controlcode.value) == "" )
  {
    getElement('err_controlcode').innerHTML = "<i>codice non inserito</i>";
    err = true;
  }
    
   // Eseguo i controlli sul campo link
  if ( trim(document.forms['form_invito'].link.value) == "" )
  {
    //getElement('err_link').innerHTML = "<i>link non valido</i>";
    err = true;
  }
  
  /* se i controlli sui dati sono passati con successo eseguo la chiamata */
  if(!err)
  {
    var Aobj = new JAjax();
    Aobj.setPost();
    Aobj.setTextResponse();
    Aobj.setLocal();
    Aobj.setLink( link );
      
    Aobj.setOperation( function (str){
                        document.getElementById(elem).innerHTML = str;
                     });
      
    var fm = document.forms['form_invito'];
    
    Aobj.addQueryString("link",fm.link.value);
    Aobj.addQueryString("mail",fm.mail.value);
    Aobj.addQueryString("commento",fm.commento.value);
    Aobj.addQueryString("controlcode",fm.controlcode.value);
    Aobj.addQueryString("cryptcode",fm.cryptcode.value);
    
    Aobj.sendData(); 
  }
}

/* Send Request (Tools richiesta informazioni/preventivo, old aj_info_e_prenotazioni.js) */
function send_request(link,elem)
{

  /* data controls */
  
  var err = false;
  
  
  /* resetto gli errori */
  
  var err_el = getElementsByName_cross("err_desc");
  for(i=0;i<err_el.length;i++)
  {
    err_el[i].innerHTML = "";
  }

  // Controllo ragionesociale
  var ragionesociale = trim(document.forms['form_request'].ragionesociale.value);
  if ( ragionesociale == "" )
  {
    getElement("err_ragionesociale").innerHTML = "<i>Ragione Sociale mancante</i>";
    err = true;
  }
  else
  {
    if ( ( ragionesociale.length < 3 ) )
    {
      getElement("err_ragionesociale").innerHTML = "<i>Lunghezza non consentita</i>";
      err = true;
    }
  }
  
  // Controllo la mail
  var mail    = trim(document.forms['form_request'].mail.value);
  if ( mail == "" )
  {
    getElement("err_mail").innerHTML = "<i>E-mail mancante</i>";
    err = true;
  }
  else
  {
    if (!(is_valid_mail(mail)))
    {
      getElement("err_mail").innerHTML = "<i>E-mail non é nel formato corretto</i>";
      err = true;
    }
  }
  
  // Eseguo i controlli sul campo controlcode
  if ( trim(document.forms['form_request'].richiesta.value) == "" )
  {
    getElement('err_richiesta').innerHTML = "<i>richiesta non valorizzata</i>";
    err = true;
  }
    
  // Eseguo i controlli sul campo controlcode
  if ( trim(document.forms['form_request'].controlcode.value) == "" )
  {
    getElement('err_controlcode').innerHTML = "<i>codice non inserito</i>";
    err = true;
  }
    
  // Eseguo i controlli sul campo link
  if ( trim(document.forms['form_request'].link.value) == "" )
  {
    //getElement('err_link').innerHTML = "<i>link non valido</i>";
    err = true;
  }
  
  // Eseguo i controlli sul campo id_locale
  if ( trim(document.forms['form_request'].id_locale.value) == "" )
  {
    //getElement('err_id_elm').innerHTML = "<i>id_locale non valido</i>";
    err = true;
  }
  
  /* se i controlli sui dati sono passati con successo eseguo la chiamata */
  if(!err)
  {
    /* costruzione post request */
    
    var ragione;
    for (i=0;i<document.forms['form_request'].ragione.length;i++){
      if ( document.forms['form_request'].ragione[i].checked )
      {
        ragione = document.forms['form_request'].ragione[i].value;
      } 
    }
        
    var Aobj = new JAjax();
    Aobj.setPost();
    Aobj.setTextResponse();
    Aobj.setLocal();
    Aobj.setLink( link );
      
    Aobj.setOperation( function (str){
                        document.getElementById(elem).innerHTML = str;
                     });
      
    var fm = document.forms['form_request'];
    
    Aobj.addQueryString("ragionesociale",fm.ragionesociale.value);
    Aobj.addQueryString("telefono",fm.telefono.value);
    Aobj.addQueryString("mail",fm.mail.value);
    Aobj.addQueryString("ragione",ragione);
    Aobj.addQueryString("link",fm.link.value);
    Aobj.addQueryString("op",fm.op.value);
    Aobj.addQueryString("id_locale",fm.id_locale.value);
    Aobj.addQueryString("richiesta",fm.richiesta.value);
    Aobj.addQueryString("controlcode",fm.controlcode.value);
    Aobj.addQueryString("cryptcode",fm.cryptcode.value);
    
    Aobj.sendData();
  }
}

/* call_aj_calendar ( chiamata ajax calendario ) */
function call_aj_calendar(link,elem)
{
    var Aobj = new JAjax();
    Aobj.setGet();
    Aobj.disableCache();
    Aobj.setTextResponse();
    Aobj.setLocal();
    Aobj.setLink( link );
      
    Aobj.setOperation( function (str){
                        document.getElementById(elem).innerHTML = str;
                     });

    Aobj.sendData();
}    