function getCounts() {

	var myAjax = new Ajax.Request(
			'get_counts.asp', 
			{
				method: 'get', 
				parameters: '', 
				asynchronous: false,  
				onComplete: function(response) {
					currentCounts = eval('(' + response.responseText + ')');
					drawCounts(currentCounts);
				}
			});
}


/*---------------------------------------------------------------*/

function drawCounts(Counts) {
	
	strCounts = '(Shows ' + Counts['counts'][0].FirstRecord + '-' + Counts['counts'][0].LastRecord + ' of ' + Counts['counts'][0].TotalRecords + ')';
	table =  '<table height="16" border="0" cellpadding="0" cellspacing="0" align="right">';
	table += '<tr>' 
	table += '<td height="16" align="right" class="text twelve medium grey">' + strCounts + '</td>';
	table += '<td width="10"></td>';
	
	if (Counts['counts'][0].CurrentPage > 1) {
		table += '<td width="20" height="16" align="center"><a href="#" onclick="getResults('+ 99999 + ',' + 99999 + ',' + '\'' + 99999 + '\',' + 99999 + ',' + eval(parseInt(Counts['counts'][0].CurrentPage) - 1) + ');getCounts();"><div style="background:url(../graphics/btn_prev_small.png) no-repeat 0px 0px; height:16px; width:20px" title="Previous Page"></div></a></td>';
		}
	else
		{
		table += '<td width="20" height="16" align="center"><div style="background:url(../graphics/btn_prev_small.png) no-repeat 0px -16px; height:16px; width:20px" title="Previous Page"></div></td>';
		}
	
	table += '<td width="2"></td>';
	
	if (Counts['counts'][0].CurrentPage < Counts['counts'][0].TotalPages) {
		table += '<td width="20" height="16" align="center"><a href="#" onclick="getResults('+ 99999 + ',' + 99999 + ',' + '\'' + 99999 + '\',' + 99999 + ',' + eval(parseInt(Counts['counts'][0].CurrentPage) + 1) + ');getCounts();"><div style="background:url(../graphics/btn_next_small.png) no-repeat 0px 0px; height:16px; width:20px" title="Next Page"></div></a></td>';
		}
	else
		{
		table += '<td width="20" height="16" align="center"><div style="background:url(../graphics/btn_next_small.png) no-repeat 0px -16px; height:16px; width:20px"  title="Next Page"></div></td>';
		}
		
	table += '</tr>'
	table += '</table>';
	
	
	document.getElementById("RecordCountsTop").innerHTML = table;
	document.getElementById("RecordCountsBot").innerHTML = strCounts;
			
	table =  '<table width="600" border="0" cellspacing="10" cellpadding="0">';
	table += '<tr>' 

	table += '<td width="250" height="28" style="background:url(../graphics/btn_pages_bg.png) no-repeat; height:28px; width:250px"><div class="text twelve white" style="padding-left:10px; width:250px"><span class="text twelve bold white">Page:</span>&nbsp;&nbsp;';
	table += '<input name="CurrentPage" title="Enter Page" id="CurrentPage" onChange="jumpPage('+ 99999 + ',' + 99999 + ',' + '\'' + 99999 + '\',this.value,'+Counts['counts'][0].PageSize+','+Counts['counts'][0].TotalPages+','+Counts['counts'][0].CurrentPage+');" type="text" class="text twelve white" id="textfield" style="background-color:#222222; width:50px; height:18px; vertical-align:middle; border:1px solid #333333; padding:0px; text-align:center" value="' + Counts['counts'][0].CurrentPage + '"> of ' + Counts['counts'][0].TotalPages + '</div></td>';
	
	table += '<td width="210" align="center" class="text twelve mediumgrey">&nbsp;</td>';
	
	if (Counts['counts'][0].CurrentPage > 1) {
		table += '<td width="80" height="28" align="center"><a href="#" onclick="getResults('+ 99999 + ',' + 99999 + ',' + '\'' + 99999 + '\',' + 99999 + ',' + eval(parseInt(Counts['counts'][0].CurrentPage) - 1) + ');getCounts();"><div style="background:url(../graphics/btn_prev.png) no-repeat 0px 0px; height:28px; width:80px" title="Previous Page"></div></a></td>';
		}
	else
		{
		table += '<td width="80" height="28" align="center"><div style="background:url(../graphics/btn_prev.png) no-repeat 0px -28px; height:28px; width:80px" title="Previous Page"></div></td>';
		}
	
	if (Counts['counts'][0].CurrentPage < Counts['counts'][0].TotalPages) {
		table += '<td width="80" height="28" align="center"><a href="#" onclick="getResults('+ 99999 + ',' + 99999 + ',' + '\'' + 99999 + '\',' + 99999 + ',' + eval(parseInt(Counts['counts'][0].CurrentPage) + 1) + ');getCounts();"><div style="background:url(../graphics/btn_next.png) no-repeat 0px 0px; height:28px; width:80px" title="Next Page"></div></a></td>';
		}
	else
		{
		table += '<td width="80" height="28" align="center"><div style="background:url(../graphics/btn_next.png) no-repeat 0px -28px; height:28px; width:80px" title="Next Page"></div></td>';
		}
	
	table += '</tr>';
	table += '</table>';
	
	document.getElementById("PagingControls").innerHTML = table;
	
	if (Counts['counts'][0].TotalRecords == 0) {
		
		document.getElementById("view").innerHTML = "<span class=\"text sixteen bold\">Sorry there are no current shows</span>";
	}

}

function jumpPage(cat,lang,ts,x,pz,tp,cp) {
	if (IsInteger(x))
		{
		if (x == 0) {
			alert('Page number entered cannot be zero - please re-enter');
			}
		else if (x > tp) {
				alert('Page number exceeds maximum - please re-enter');
				}
			else
				{
				getResults(cat,lang,ts,pz,x);
				getCounts();
				}
		}
	else
		{
		alert('Page number entered is invalid - please re-enter');
		}
	}
	
function IsInteger(strString) {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;
   if (strString.length == 0) return false;
   for (i = 0; i < strString.length && blnResult == true; i++) {
     strChar = strString.charAt(i);
     if (strValidChars.indexOf(strChar) == -1) {
       blnResult = false;
     }
   }
   return blnResult;
 }
	
	

