function toggle(id)
{
	var e = document.getElementById(id);
	e.style.display = ( e.style.display == 'block' ? 'none' : 'block' );
}

function addEvent(obj, evType, fn){ 
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	} else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	} else { 
		return false; 
	} 
}

function LoadXMLFile(url, callback)
{
	var xml = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();

	if( xml == null )
		return false;									
	
	xml.onreadystatechange = function()
	{
		if(xml.readyState==4)
		{
			var xmlDoc = null;
			
			if( window.ActiveXObject )
			{
				xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
				xmlDoc.async = false;
				xmlDoc.loadXML(xml.responseText);
			}
			else
			{
				xmlDoc = (new DOMParser()).parseFromString(xml.responseText, "text/xml");
			}
			
			callback(xmlDoc);
		}
	}
	
	xml.open("GET", url, true);
	xml.send(null);
	
	return true;
}

function pagination(fmtUrl, numPages, curPage)
{	
	var numLinks = 7;
	var offset = Math.floor(numLinks / 2);
	var start = Math.max(1, curPage - offset);
	var end = Math.min(numPages, curPage + offset);

	var html = '<ul class="pagination"><li>Page:</li>';
	
	if( curPage != 1) {
		html += '<li><a href="' + fmtUrl.replace('?', 1) + '">First</a></li>';
	} else {
		html += '<li class="sel">First</li>';
	}

	for( var i = start; i <= end; i++ ) 
	{
		if( ( i != 1 ) && ( i != numPages ) )
		{
			if( i != curPage ) {
				html += '<li><a href="' + fmtUrl.replace('?', i) + '">' + i + '</a></li>';
			} else {
				html += '<li class="sel">' + i + '</li>';
			}				
		}
	}

	if( curPage != numPages ) {
		html += '<li><a href="' + fmtUrl.replace('?', numPages) + '">Last</a></li>';
	} else {
		html += '<li class="sel">Last</li>';
	}

	html += '<ul>';
	
	return html;
}
