
function loadXMLDoc( docname ) 
{
 try //Internet Explorer
 {
  xmlDoc = new ActiveXObject( "Microsoft.XMLDOM" );
 }
 catch(e)
 {
  try //Firefox, Mozilla, Opera, etc.
  {
   xmlDoc = document.implementation.createDocument( "","",null );
  }
  catch( e ) 
  {
   alert( e.message )
  }
 }
 
 try 
 {
  xmlDoc.async = false;
  xmlDoc.load( docname );
  return( xmlDoc );
 }
 catch( e ) 
 {
  alert( e.message )
 }

 return( null );
}

function loadXMLString( txt ) 
{
 try //Internet Explorer
 {
  xmlDoc = new ActiveXObject( "Microsoft.XMLDOM" );
  xmlDoc.async = "false";
  xmlDoc.loadXML( txt );
  return( xmlDoc ); 
 }
 catch( e )
 {
  try //Firefox, Mozilla, Opera, etc.
  {
   parser = new DOMParser();
   xmlDoc = parser.parseFromString( txt,"text/xml" );
   return( xmlDoc );
  }
  catch( e ) 
  {
   alert( e.message )
  }
 }
 
 return( null );
}

////////////////////////////////////////////////////////////////

// CLASS AjaxFeedback variations

function AjaxFeedback_Text( str )
{
 this.busy          = str; 

 // member functions for handling feedback
 this.onChangeBusy  = onChangeBusy;
 this.onLoading     = onLoading;
 this.onLoaded      = onLoaded;
 this.onInteractive = onInteractive;
}

function onChangeBusy( id )
{
 this.busy += ".";
}

function onLoading( id )
{
 this.onChangeBusy( id );
 SetElementTextById( id, "<span>" + this.busy + "</span>" );
}

function onLoaded( id )
{
 this.onChangeBusy( id );
 SetElementTextById( id, "<span>" + this.busy + "</span>" );
}

function onInteractive( id )
{
 this.onChangeBusy( id );
 SetElementTextById( id, "<span>" + this.busy + "</span>" );
}

////////////////////////////////////////////////////////////////

function ProduceWorldSummary()
{
 CallAjax( "/ajax_stats_produce.php", "action=sum&target=0", "sum_0", new AjaxFeedback_Text( "Creating " ) );
}

function ProduceWorldReceiving()
{
 CallAjax( "/ajax_stats_produce.php", "action=rec&target=0", "rec_0", new AjaxFeedback_Text( "Creating " ) );
}

function ProduceWorldOrigin()
{
 CallAjax( "/ajax_stats_produce.php", "action=ori&target=0", "ori_0", new AjaxFeedback_Text( "Creating " ) );
}

function ProduceAustraliaSummary()
{
 CallAjax( "/ajax_stats_produce.php", "action=sum&target=251", "sum_251", new AjaxFeedback_Text( "Creating " ) );
}

function ProduceAustraliaReceiving()
{
 CallAjax( "/ajax_stats_produce.php", "action=rec&target=251", "rec_251", new AjaxFeedback_Text( "Creating " ) );
}

function ProduceAustraliaOrigin()
{
 CallAjax( "/ajax_stats_produce.php", "action=ori&target=251", "ori_251", new AjaxFeedback_Text( "Creating " ) );
}

function CheckForAjax( val )
{
 CallAjax( "/ajaxcando.php", "val=" + val, null, null );
}

function DisplayImages()
{
 CallAjax( "/ajaxkids.php", null, "abclearn", new AjaxFeedback_Text( "Loading " ) );
}

function ChangeKidImage( key )
{
 CallAjax( "/ajaxkid.php", "key=" + key, "kid_" + key, new AjaxFeedback_Text( "Loading " ) );
}

function ChangeNewsLatestLink()
{
 CallAjax( "/ajaxnews.php", "mode=linklatest", "newslink", null );
}

function ChangeNewsAllLink()
{
 CallAjax( "/ajaxnews.php", "mode=linkall", "newslink", null );
}

function DisplayAllNews( filter )
{
 CallSjax( "/ajaxnews.php", "mode=allnews&filter=" + filter, "indexnews", null );
}

function DisplayLatestNews( filter )
{
 CallSjax( "/ajaxnews.php", "mode=latestnews&filter=" + filter, "indexnews", null );
}

function DisplayFooter()
{
 CallAjax( "/ajaxfooter.php", null, "footer" );
}

//////////////////////////////////////////////////////////////////

function AddRow( id, rowNum, count, period )
{
 var request = new AjaxRequest( "/ajax_stats_addrow.php", "row=" + rowNum + "&" + "count=" + count + "&" + "period=" + period, id );
 if ( request != null )
 {
  request.SetMimeType( 'text/xml' );
  request.onCompleted = onCompletedAddStats;
  request.onError = null;
  request.onFeedback = null; 
  request.Perform();
 }
}

function StatsLoad( id, region, period )
{
 var request = new AjaxRequest( "/ajax_stats_load.php", "region=" + region + "&" + "period=" + period, id );
 if ( request != null )
 {
  request.SetMimeType( 'text/xml' );
  request.onCompleted = onCompletedAddStats;
  request.onError = null;
  request.onFeedback = null; 
  request.Perform();
 }
}

////////////////////////////////////////////////////////////////

function InsertStats( id, statTo, period, region, number, code )
{
 //var str = "";
 //str += "To: "     + statTo + "\n";
 //str += "Period: " + period + "\n";
 //str += "Region: " + region + "\n";
 //str += "Count: "  + number + "\n";
 //str += "Code: "   + code + "\n";
 //str += "Result=<" + id + ">\n";
 //alert( str );

 var request = new AjaxRequest( "/ajax_stats_save.php", 
                                "statTo=" + statTo + "&" + 
                                "period=" + period + "&" + 
                                "region=" + region + "&" + 
                                "number=" + number + "&" + 
                                "code=" + code, 
                                id );
 if ( request != null )
 {
  request.onFeedback = null; 
  request.Perform();
 }
}

////////////////////////////////////////////////////////////////

