/********************************************************************************
*      Script: ajax.js
* Description: java script routines to support AJAX for the IYFR web page 
*    Comments: Intilectual property of Clint Collier: on loan to iyfr.
*					Currently only in use in /rotafloat/index.php
*     Created: 11/06/06 [CLC]
*    Modified: 12/24/06 [clc] added routines for /members/bridgedocuments/index.php
*********************************************************************************/

//*******************************************************************************
// Make an AJAX XMLHTTP object
//*******************************************************************************
function getXMLHTTPRequest(){
var request = false;
try {
	request = new XMLHttpRequest(); // Mozilla (Firefox, Netscape) & IE7
}
catch(err1) {
	try {
		request = new ActiveXObject("MSXML2.XMLHTTP"); // current versions of IE
	}
	catch(err2) {
		try {
			request = new ActiveXObject("Microsoft.XMLHTTP"); // earlier versions of IE
		}
		catch(err3) {
			request = false;
		}
	}
}
return request;
} //getXMLHTTPRequest

var myAjaxRequest = getXMLHTTPRequest();

//----------------------------------------------------------------------------//
//																										//
// Routines used by /rotafloat/index.php													//	
//																										//
//----------------------------------------------------------------------------//

//*******************************************************************************
// Send a year back to the server to request a new list of Rotafloats
//*******************************************************************************
function AjaxGetYearList(year) {
	// to prevent browser caching, append a random number to our request
	var randomno = parseInt(Math.random()*99999999);
	var url = "ajaxgetyearlist.php?rotafloatyear="+year+"&random="+randomno;
	document.getElementById('rotafloatissues').innerHTML = "<I>Retrieving issues...</I>";
	myAjaxRequest.open("GET",url,true);
	myAjaxRequest.onreadystatechange = AjaxNewYearList;
	myAjaxRequest.send(null);
} //AjaxGetYearList


//*******************************************************************************
// Populate our new list of Rotafloats when returned from the server
//*******************************************************************************
function AjaxNewYearList(){
	if (myAjaxRequest.readyState == 4) {
		if (myAjaxRequest.status == 200) {
			document.getElementById('rotafloatissues').innerHTML = myAjaxRequest.responseText;
		} else {
			alert ("Ajax Error: " + myAjaxRequest.status + " " + myAjaxRequest.statusText);
		}
	}
} //AjaxNewYearList


//----------------------------------------------------------------------------//
//																										//
// Routines used by /members/bridgedocuments/index.php								//	
//																										//
//----------------------------------------------------------------------------//

//*******************************************************************************
// Send a directory name back to the server to request a list of its contents
//*******************************************************************************
function AjaxGetFileList(directory) {
	// to prevent browser caching, append a random number to our request
	var randomno = parseInt(Math.random()*99999999);
	var url = "ajaxgetfilelist.php?directory="+directory+"&random="+randomno;
	document.getElementById('filelist').innerHTML = "<I>Retrieving document list...</I>";
	// alert(url);
	myAjaxRequest.open("GET",url,true);
	myAjaxRequest.onreadystatechange = AjaxNewFileList;
	myAjaxRequest.send(null);
} //AjaxGetdirList


//*******************************************************************************
// Populate our new list of directory content when returned from the server
//*******************************************************************************
function AjaxNewFileList(){
	if (myAjaxRequest.readyState == 4) {
		if (myAjaxRequest.status == 200) {
			document.getElementById('filelist').innerHTML = myAjaxRequest.responseText;
		} else {
			alert ("Ajax Error: " + myAjaxRequest.status + " " + myAjaxRequest.statusText);
		}
	}
} //AjaxNewdirList