/****************************************************************
 *  Ajax callback function that collects info from calling page
 */
 function ajcNewMatchDay(date)
 {
// parameter values to send on http.send()
   var params = "date=" + date;

// file to call for server processing
   var action   = "newMatchDay.php";

   http.open("POST", action, true);

// Send the proper header information along with the request
   http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   http.setRequestHeader("Content-length", params.length);
   http.setRequestHeader("Connection", "close");

   http.onreadystatechange = function () {ajrNewMatchDay()};
   http.send(params);
 } /* end function */

/****************************************************************
 *  Ajax response function
 */
 function ajrNewMatchDay()
 {
   if(http.readyState == 4) {
     if(http.status == 200) {
/*       document.getElementById(controlname).innerHTML = http.responseText; */

       /* NO NEED FOR ACTION ==> DATABASE WAS UPDATED BY PHP FILE */

     } else {
       alert("Error: " + http.statusText);
     }
   }
 } /* end function */



/****************************************************************
 *  Ajax callback function that collects info from calling page
 */
 function ajcChangeCourt(controlName, newCourt)
 {
// hidden control on calling page stores the old court number
// the hidden control name has an "h" where the corresponding button name has a "b"
   var hidden = controlName.replace("b", "h");

   var oldCourt = document.getElementById(hidden).innerHTML;

// parameter values to send on http.send()
   var params = "control=" + controlName + "&oldcourt=" + oldCourt + "&newcourt=" + newCourt;

// file to call for server processing
   var action   = "changeCourt.php";

   http.open("POST", action, true);

// Send the proper header information along with the request
   http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   http.setRequestHeader("Content-length", params.length);
   http.setRequestHeader("Connection", "close");

   http.onreadystatechange = function () {ajrChangeCourt(hidden, newCourt)};
   http.send(params);
 } /* end function */


/****************************************************************
 *  Ajax response function
 */
 function ajrChangeCourt(hidden, newCourt)
 {
   if(http.readyState == 4) {
     if(http.status == 200) {

     // update the hidden control's value property with the new court number
       document.getElementById(hidden).innerHTML = newCourt;
       document.getElementById('count').innerHTML = '';

     } else {
       alert("Error: " + http.statusText);
     }
   }
 } /* end function */

/****************************************************************
 *  Ajax callback function that cancels match
 */
 function ajcCancelMatch(matchID)
 {
// parameter values to send on http.send()
   var params = "SelectedMatchID=" + matchID;

// file to call for server processing
   var action   = "cancelMatch.php";

   http.open("POST", action, true);

// Send the proper header information along with the request
   http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   http.setRequestHeader("Content-length", params.length);
   http.setRequestHeader("Connection", "close");

   http.onreadystatechange = function () {ajrCancelMatch()};
   http.send(params);
 } /* end function */

/****************************************************************
 *  Ajax response function
 */
 function ajrCancelMatch()
 {
   if(http.readyState == 4) {
     if(http.status == 200) {

     // update the hidden control's value property with the new court number
       window.location.href=window.location.href;
     } else {
       alert("Error: " + http.statusText);
     }
   }
 } /* end function */

/****************************************************************
 *  Ajax callback function that collects info from calling page
 */
 function callAjax(name)
 {
/*** start collecting and pre-processing page info ***/

   var sTime = document.Time.Start.value;
   var nameprefix = name;

/*** end page info ***/

// file to call for server processing
   var action   = "callAjax.php";

// parameter values to send on http.send()
   var params = "begin=" + nameprefix + "&name=Sheedy";

   http.open("POST", action, true);

// Send the proper header information along with the request
   http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   http.setRequestHeader("Content-length", params.length);
   http.setRequestHeader("Connection", "close");

   http.onreadystatechange = function () {setAjaxResponse("JS parameters")};
   http.send(params);
 } /* end function */


/****************************************************************
 *  Ajax response function
 */
 function setAjaxResponse(parameters)
 {
   if(http.readyState == 4) {
     if(http.status == 200) {
       alert("Server Response: " + parameters + " " + http.responseText);
     } else {
       alert("Error: " + http.statusText);
     }
   }
 } /* end function */


/****************************************************************
 *  create a new Ajax Request object
 */
 function newAjaxRequest()
 {
   var request = false;
   if(window.XMLHttpRequest) {
     http = new XMLHttpRequest();
   } else if (window.ActiveXObject) {
     http = new ActiveXObject("Msxml2.XMLHTTP");
     if(!http) {
       http = new ActiveXObject("Microsoft.XMLHTTP");
     }
   }
 } /* end function */



