var RSSRequestObject = false; // XMLHttpRequest for calendar feed

// We are now using extended ajax object XMLHTTP instead of built-in 
// XMLHttpRequest
if ( 0 )
{
if (window.XMLHttpRequest) 
{
	// try to create XMLHttpRequest
	RSSRequestObject = new XMLHttpRequest();	
}

if (window.ActiveXObject)	
{
	// if ActiveXObject use the Microsoft.XMLHTTP
	RSSRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}
}
else
RSSRequestObject = new XMLHTTP();

function ReqChange()
{
	// If data received correctly
	if (RSSRequestObject.readyState==4) {

		clearTimeout( groupTimer );
	
		// if data is valid
		if (RSSRequestObject.responseText.indexOf('invalid') == -1) 
		{ 	
			// Parsing Feeds
			var node = RSSRequestObject.responseXML.documentElement;
			content = '';
			// Browse items 
			items = node.getElementsByTagName('entry');
			if (items.length == 0) {
				content += '<ul><li><div class="ajaxMessage">Failed to load the links. Please refer to the group directly</div></li></ul>';
			} else {
				content += '<div class="reportList"><ul>';
		//		for (var n=items.length-1; n >= 0; n--)
				for ( var n=0; n < items.length; n++ )
				{
					titleObj = items[n].getElementsByTagName('title').item(0).firstChild;
					// If the subject field is empty,
					// titleObj is null.
					if ( titleObj == null )
						continue;
					title = titleObj.data;
					pubdate= items[n].getElementsByTagName('updated').item(0).firstChild.data; 
					pubdate = pubdate.substr( 0,10); 
					link = items[n].getElementsByTagName('summary').item(0).firstChild.data;
					// remove sig
					link = link.substring( 0, link.indexOf( "</a>")+4 );
					link = link.replace( "[link]", title );
					content += '<li>'+link;
				}
				
				content += '</ul></div>';
			}
			// Display the result
			document.getElementById("ajaxReader").innerHTML = content;

			// Tell the reader the everything is done
			document.getElementById("ajaxStatus").innerHTML = "Done.";
			
		}
		else {
			// Tell the reader that there was error requesting data
			document.getElementById("ajaxStatus").innerHTML = "<div class=error>Error requesting data.<div>";
		}
		
		HideShow('ajaxStatus');
	}
	
}

var groupTimer;

function groupTimeout()
{
//	groupRequest.abort();
	document.getElementById("ajaxStatus").innerHTML = "Could not load the links.  Please refer to the google group directly.</div>";
} 


/*
* Main AJAX RSS reader request
*/
function RSSRequest() {

	// change the calStatus to requesting data
	HideShow('ajaxStatus');
	document.getElementById("ajaxStatus").innerHTML = "Loading links...";
	
	
	RSSRequestObject.open( "GET", backend, true );

	// Set the onreadystatechange function
	RSSRequestObject.onreadystatechange = ReqChange;

	// Send
	RSSRequestObject.send(null); 

	groupTimer = setTimeout( groupTimeout, 5000 );
}


function HideShow(id){
	var el = GetObject(id);
	if(el.style.display=="none")
	el.style.display='';
	else
	el.style.display='none';
}

function GetObject(id){
	var el = document.getElementById(id);
	return(el);
}
