
  var myAjax_cyclic;
  var cyclic_running=0;

function init ()
{
  var tabs = document.getElementsByClassName('tabs');

  for (var i=0; i<tabs.length; i++)
  {
    $(tabs[i].id).onclick = function () { getTabData(this.id); } ;
  }

}

function getTabData(id)
{
  var tabs = document.getElementsByClassName('tabs');
  for (var i = 0; i < tabs.length; i++)
  {
     $(tabs[i].id).style.backgroundColor = "#AAAAAA";//"white";
     $(tabs[i].id).style.zIndex = 1;
  }

  document.getElementById(id).style.backgroundColor = "#DDDDDD";          // OK
  document.getElementById(id).style.zIndex = 4;

  $('content').innerHTML = 'Loading...';

  // store sub-id for all tabs
  if(main_id =='can_frm_2.htm')
    id_can_bus =  id;

  if(main_id =='com1_frm_2.htm')
    id_com1 = id;

  if(main_id =='ip_frm_2.htm')
    id_connection = id;

  if(main_id =='strm_frm_2.htm')
    id_datastream = id;

  if(main_id =='othr_frm_2.htm')
    id_options = id;

  if(main_id =='help_frm_2.htm')
    id_help = id;


  // check for cyclic loading of pages

  if(cyclic_running == 1)
  {
    myAjax_cyclic.stop();
    cyclic_running =0;
  }
  
  if(id=='ajaxcandriverc.cgi')
  {
    cyclic_running = 1;
    myAjax_cyclic = new PeriodicalExecuter(load_cyclic_1, 20);
    id='ajaxcandriver.cgi';
  }

  if(id=='ajaxipstatec.cgi')
  {
    cyclic_running = 1;
    myAjax_cyclic = new PeriodicalExecuter(load_cyclic_2, 20);
    id='ajaxipstate.cgi';
  }

  // for test only
  if(id=='ajaxbar2c.cgi')
  {
    cyclic_running = 1;
    myAjax_cyclic = new PeriodicalExecuter(load_cyclic_3, 2);
    id='ajaxbar2.cgi';
  }

  if(id=='can_rcv')
  {
    id='http://192.168.1.199:3333/'; // this port will not work (Sicherheitsfehler)
  }


  var myAjax = new Ajax.Request(id, { method: 'get', onLoading: showLoad, onComplete: showResponse} );
}

// for all tabs
function showLoad()
{
  // $('load').style.display = 'block';
}


// for all tabs
function showResponse (originalRequest)
{
  var newData = originalRequest.responseText;
  $('load').style.display = 'none';

  if(newData.length > 10)
  {
    $('content').innerHTML = newData;
  }  
}

// for all tabs
function transmit_form(cgi_request)
{
  var myAjax = new Ajax.Request(cgi_request, {method: 'get', parameters: Form.serialize($('can2webform')), onLoading: showLoad, onComplete: showResponse });
 
}

// for CAN driver
function load_cyclic_1()
{
  var myAjax = new Ajax.Request('ajaxcandriver.cgi', { method: 'get', onLoading: showLoad, onComplete: showResponse} );
}

// for connection manager
function load_cyclic_2()
{
  var myAjax = new Ajax.Request('ajaxipstate.cgi', { method: 'get', onLoading: showLoad, onComplete: showResponse} );
}


// for test only

function load_cyclic_3()
{
  var myAjax = new Ajax.Request('ajaxbar2.cgi', { method: 'get', onLoading: showLoad, onComplete: showResponse} );
}

// end of file
