// --- Global responder that registers every Ajax request and handles timeout conditions
Ajax.Responders.register
({
  onCreate: function(request)
  {
    request['timeoutId'] = window.setTimeout
    (
      function()
      {
        if (connection_handler(request.transport))
        {
          request.transport.abort();
          alert('There has been a problem connecting to the server. Perhaps you can wait a minute and try again?');
          if (request.options['onFailure']) { request.options['onFailure'](request.transport, request.json); }
        }
      }, 200000
    )
  },
  onComplete: function(request)
  {
    window.clearTimeout(request['timeoutId']);
  }
});


// --- Helper function for connection timeouts
function connection_handler(req)
{
  switch (req.readyState)
  {
    case 1: case 2: case 3:
      return true;
      break;
    default:
      return false;
      break;
  }
}

function addcpid()
{
 new Ajax.Request("../php/createcpid.php",
 {
   onSuccess : function (resp)
   {
   window.location.reload();
   document.getElementById("testdiv").innerHTML=resp.responseText;
   },
   method: 'post',
   parameters : Form.serialize($('cpid-data'))
 });
}

function changecpid()
{
 new Ajax.Request("../php/updatecpid.php",
 {
   onSuccess : function (resp)
   {
   window.location.reload();
   document.getElementById("testdiv").innerHTML=resp.responseText;
   },
   method: 'post',
   parameters : Form.serialize($('cpid-data'))
 });
}

function addteam_apply()
{
 new Ajax.Request("/php/updates/addteamcommit.php",
 {
   onSuccess : function (resp)
   {
   window.location.reload();
   document.getElementById("testdiv").innerHTML=resp.responseText;
   document.getElementById("testdiv").style.display='block';
   },
   method: 'post',
   parameters : Form.serialize($('addteam-data'))
 });
}


