 /* Copyright (C) 2006-2009 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 scratch()

  {
    
     //alert('scratch'+document.getElementById('xmlIsland'))
    n = document.getElementById('xmlIsland').childNodes
  
    //alert(document.getElementById('xmlIsland').XMLDocument)
     return createTable(document.getElementById('xmlIsland').getElementsByTagName("transaction")[0])
  }
  
function incoming(data)

  {
  
  //alert(data);
  
    
     if (ignoreResponse == true)
      {
        ignoreResponse  = false;
             document.forms[0].nextButton.disabled=false
             document.forms[0].clearButton.disabled=false
             return;
      }
     
     n = data.childNodes
     /*
    for (var i = 0; i<n.length&& i<10; i++)
       alert(i+n[i].nodeName)

     alert(data.getElementsByTagName("TRANSACTION")[0])       
    
     */
     
     var trn = data.getElementsByTagName("errorText")[0];
     if (trn != null)
       {
          alert(trn.childNodes[0].nodeValue);
          document.forms[0].nextButton.disabled=false
          return;
       }
     
     var trn = data.getElementsByTagName("TRANSACTION")[0];
     sg= createTable(trn)
     
     
     //alert(sg.display)
     
     docmnt=sg.display()
     
     //alert(docmnt);
     
     disply=document.getElementById("displayspace");
     
     disply.innerHTML=docmnt;
     document.forms[0].nextButton.disabled=false
     
      if (nextState == '???') {
             document.forms[0].nextButton.disabled=true
             document.forms[0].clearButton.disabled=true
             }

   }


function createTable(node)
{

    /*node=document.getElementById("TRANSACTION")
     alert(node); 
     alert('create table for node ' + node.nodeName);
     */
    var attr = node.attributes;
    
       for (var i = 0; i < attr.length; i++) {
          if (attr[i].name == 'action')
             theActionToTake = attr[i].value
          if (attr[i].name == 'timestamp') {
             setTimeStamp(attr[i].value)
             }
          if (attr[i].name == 'nextState')
             nextState = attr[i].value
          if (attr[i].name == 'ssi')
             session = attr[i].value
          if (attr[i].name == 'useCount') {
             usecnt = attr[i].value
             document.getElementById('useCount').innerHTML = usecnt
            } 
          }
          

	
	setAction(theActionToTake)
	//alert("tatt="+theActionToTake)
	
	
	
	theTableAndSegs = "not defined"
	
	
	
var sgs=node.getElementsByTagName("segments");

//alert(node.nodeName+" "+sgs.length+' length')

 return new SegmentGroup(sgs.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)
}



