// remove spaces
function removeSpaces( string )
{
   var tstring = "";
   string = '' + string;
   splitstring = string.split(" ");
   for( i = 0; i < splitstring.length; i++ )
      tstring += splitstring[i];
   return tstring;
}

// Returns an XMLHttpRequestObject
function GetXmlHttpObject()
{
   var xmlHttp = null;
   try
   {
     // Firefox, Opera 8.0+, Safari
     xmlHttp = new XMLHttpRequest();
   }
   catch( e )
   {
     // Internet Explorer
     try
     {
        xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP" );
     }
     catch( e )
     {
        xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );
     }
   }
   return xmlHttp;
}

// updates html content of element
// method                   - GET or 'POST'
// url                      - url of resource
// xmlHttp                  - XMLHttpRequest()/ActiveXObject() object
// readyStateChangeFunction - onreadystatechange function
function setUpdateFunction( method, url, xmlHttp, readyStateChangeFunction )
{
   xmlHttp.open( method, url, true );
   xmlHttp.onreadystatechange = readyStateChangeFunction;
   xmlHttp.send( null );
}

// Changes the value of innerHTML for an element
// id      - for document.getElementById( id )
// xmlHttp - XMLHttpRequest()/ActiveXObject() object
function updateFunction( id, xmlHttp )
{
   if( xmlHttp.readyState == 4 )
   {
      if( xmlHttp.status == 200 )
      {
         if( document.getElementById( id ) )
         {
            document.getElementById( id ).innerHTML = xmlHttp.responseText;
         }
      }
   }
}

// Check or unckeck all checkboxes in a form
function setAllCheckBoxes( formName, fieldName, checkValue )
{
   if( !document.forms[formName] )
      return;

   for( var i=0 ; i < document.forms[0].length ; i++ )
   {
      if( document.forms[formName].elements[i].type == 'checkbox' &&
          document.forms[formName].elements[i].name == fieldName
       )
      {
         document.forms[formName].elements[i].checked = checkValue;
      }
   }
}

// File input tag for multiple file upload form
function getFileInputTag( name )
{
   global_file_number++;
   var return_value = 
   "<div>File " + global_file_number + ":<input type='file' size='75' name='" + name + "' /><br/><br/></div>";
   return return_value;
}

var global_file_number = 0;
