 /* Copyright (C) 2006-2007 by Joseph McVerry - American Coders, Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


function trim(input)
{
  if (input.length == 0) return '';

  if (input.length == 1 && input == '\n') return '';
  
  var s;
  var i;
  for (s=0; s<input.length; s++)
    {
      if (input.charAt(s) != " ")
       {
        break;
        }
    }
  for (i=input.length-1; i>-1; i--)
    {
      if (input.charAt(i) != " ")
       {
        break;
        }
    }

  work = ""

  for (j = s; j <= i; j++)
     work += input.charAt(j);

  return work

}


  
function incoming(data)

  {
  
     //alert("incoming function with "+data);
    
     if (ignoreResponse == true)
      {
        ignoreResponse  = false;
        document.forms[0].nextButton.disabled=false
        document.forms[0].prevButton.disabled=false
        document.forms[0].clearButton.disabled=false
        return;
      }
     
     var trn = data.getElementsByTagName("errorText")[0];
     if (trn != null)
       {
          alert(trn.childNodes[0].nodeValue);
          document.forms[0].nextButton.disabled=false
          document.forms[0].prevButton.disabled=false
          document.forms[0].clearButton.disabled=false
          return;
       }
     
     var trn = data.getElementsByTagName("TRANSACTION")[0];
     var attr=trn.attributes
       
     
       for (var i = 0; i < attr.length; i++) {
                   
               if (attr[i].name == 'name') {
                  document.getElementById("title").innerHTML = attr[i].value
                  document.getElementById("secondtitle").innerHTML = attr[i].value
                  }
         }
     

     pg = createPage(trn)
     
     var dsplySpace = document.getElementById("displayspace")
     while (dsplySpace.firstChild != null)
     	dsplySpace.removeChild(dsplySpace.firstChild);// there's only one child
     
     var dat = trn.getElementsByTagName("data")
     dataNodes = new Array();
     dataNodes[0] = undefined;
     
     if (dat.length > 0)
     {
       var dataNodes = dat[0].childNodes;
     }  
     
     pg.display(dsplySpace, dataNodes[0])
     
     
     document.forms[0].nextButton.disabled=false
     document.forms[0].prevButton.disabled=false
     
  
   }


function createPage(node)
{

    /*node=document.getElementById("TRANSACTION")
    alert(node); 
     alert('create page for node ' + node.nodeName);
     */
    var attr = node.attributes;
    
       for (var i = 0; i < attr.length; i++) {
          if (attr[i].name == 'nextState')
             nextState = attr[i].value
             

          }
          
	
   var sections=node.getElementsByTagName("page");
   //alert(node.nodeName+" "+sections.length+' length')

    return new Page(sections.item(0));
   
   

  }

function nextNode(node) {
if (!node) return null;
if (node.firstChild) return node.firstChild
else return nextWide(node)
}

function nextWide(node) {
  if (!node) return null
  if (node.nextSibling) return node.nextSibling
  return nextWide(node.parentNode)
}



