function callInProgress (xmlhttp) {
   switch (xmlhttp.readyState) {
      case 1: case 2: case 3:
         return true;
         break;
      // Case 4 and 0
      default:
         return false;
         break;
   }
}

function showFailureMessage() {
   alert('uh oh, it looks like the network is down. Try again shortly');
}

// Register global responders that will occur on all AJAX requests
Ajax.Responders.register({
   onCreate: function(request) {
      request['timeoutId'] = window.setTimeout(
         function() {
            // If we have hit the timeout and the AJAX request is active, abort it and let the user know
            if (callInProgress(request.transport)) {
               request.transport.abort();
               showFailureMessage();
               // Run the onFailure method if we set one up when creating the AJAX object
               if (request.options['onFailure']) {
                  request.options['onFailure'](request.transport, request.json);
               }
            }
         },
         5000 // Five seconds
         );
   },
   onComplete: function(request) {
      // Clear the timeout, the request completed ok
      window.clearTimeout(request['timeoutId']);
   }
});




function submitClicked(divblock,editfield,resultsfield)
{
   if ($F(editfield).length > 0)
   {
      setDisabled($(divblock),true);
      $(resultsfield).innerHTML = "<span class='loginworking'>Please wait...</span>";

      var url = 'customerlogin/loginproc.php';
     // var params = 'account='+$F(editfield);
      var ajax = new Ajax.Updater(
      {
         success: resultsfield
      },
      url,
      {
         //method: 'get',
         //parameters: params,
         method: 'post',
         postBody: 'account='+ $F(editfield),
         onFailure: reportError,
         onSuccess: reportSuccess
      });

      ajax['resultsfield']=$(resultsfield);
      ajax['divblock']=$(divblock);

   }
}
//todo: fix the hard code here
function reportError(ajxrespionse) {
   setDisabled(ajxrespionse.request['divblock'],false);
   ajxrespionse.request['resultsfield'].innerHTML = "<span class='loginfailure'>Unable to process customer logins at this time. Please try again later.</span>";
}

function reportSuccess(ajxrespionse)
{
   setDisabled(ajxrespionse.request['divblock'],false);
}

function setDisabled(el,f) {
   try {
      el.disabled = f;
   }
   catch(E){}

   if (el.childNodes && el.childNodes.length > 0) {
      for (var x = 0; x < el.childNodes.length; x++) {
         setDisabled(el.childNodes[x],f);
      }
   }
}
