var SONGS_PER_PAGE = 5;
var sng_noOfPages=0;
var sng_noOfRecords=0;
var sng_pageNo=0;


		function trimTopSongs()
		{
			var leftRecords;
			sng_noOfRecords = topSinglesDataArr.length;
			if(sng_noOfRecords==0) 
			{
				document.getElementById("tblMainTopSingles").style.display = 'inline';
				for(i = 1; i<=5; i++)
				{
					document.getElementById("tdTSOrder" + i).innerHTML = "&nbsp;<BR><BR>&nbsp;";
					document.getElementById("tdTSArtAbmName" + i).innerHTML = "&nbsp;<BR>&nbsp;";
					document.getElementById("tdTSPrice" + i).innerHTML = "&nbsp;<BR>&nbsp;";
					document.getElementById("tdTSFormat" + i).innerHTML = "&nbsp;<BR>&nbsp;";
					document.getElementById("tdTSBuyShare" + i).innerHTML = "&nbsp;<BR>&nbsp;";
				}	
				EnableSongButtons(0);
				return;
			}
			
			if(sng_pageNo == 0 && sng_noOfRecords > 0) 
			{
				leftRecords = sng_noOfRecords%SONGS_PER_PAGE;

				if(leftRecords > 0)
				{
					sng_noOfPages = Math.floor(sng_noOfRecords / SONGS_PER_PAGE) + 1; 
				}
				else
				{ 
					sng_noOfPages = Math.floor(sng_noOfRecords / SONGS_PER_PAGE);
				}
				sng_pageNo = 1;
				sng_FirstPage();
			}
		}
		
		function sng_LastPage()
		{
			sng_pageNo = sng_noOfPages;
			FillSongControl(sng_pageNo);
			EnableSongButtons(sng_pageNo);
		}
		
		function sng_NextPage()
		{
			if(sng_pageNo < sng_noOfPages) sng_pageNo++;
			FillSongControl(sng_pageNo);
			EnableSongButtons(sng_pageNo);
		}
		
		function sng_PreviousPage()
		{
			if(sng_noOfPages == 0) FillSongControl(0);
			if(sng_pageNo > 1 && sng_pageNo != 0) sng_pageNo--;
			FillSongControl(sng_pageNo);
			EnableSongButtons(sng_pageNo);
		}		
		
		function sng_FirstPage()
		{
			if(sng_noOfPages==0)
			{	
				sng_pageNo = 0;
				FillSongControl(0);
			}
			else
			{
				sng_pageNo = 1;
				FillSongControl(1);
			}
			EnableSongButtons(sng_pageNo);
		}


		
		function EnableSongButtons(currentPage)		
		{
			
			if( (currentPage == 1 && sng_noOfPages == 1) || (currentPage == 0) )
			{
				document.getElementById("tdTSLinkLeft").style.display = 'none';
				document.getElementById("tdTSLinkRight").style.display = 'none';
			}
			else if(currentPage == 1 && sng_noOfPages > 1)
			{
				document.getElementById("tdTSLinkLeft").style.display = 'none';
				document.getElementById("tdTSLinkRight").style.display = 'inline';
			}
			else if(currentPage > 1 && currentPage < sng_noOfPages)
			{
				document.getElementById("tdTSLinkLeft").style.display = 'inline';
				document.getElementById("tdTSLinkRight").style.display = 'inline';
			}
			else if(currentPage == sng_noOfPages && sng_noOfPages >1)
			{
				document.getElementById("tdTSLinkLeft").style.display = 'inline';
				document.getElementById("tdTSLinkRight").style.display = 'none';
			}
		}


		
		function FillSongControl(pgNo)
		{
			var startRecord=0;
			var endRecord=0;
			var PA = "<span title='Explicit Content - Parental Advisory' style='CURSOR: text; COLOR: red'>[PA]</span>";
			var ED = "<span title='Edited Version' style='CURSOR: text; COLOR: black'>[E]</span>";
			startRecord = ((pgNo-1) * SONGS_PER_PAGE);
			endRecord = (pgNo * SONGS_PER_PAGE);
			EmptySongs();			
			if (endRecord > topSinglesDataArr.length)
					endRecord = topSinglesDataArr.length;
			document.getElementById("tblMainTopSingles").style.display = 'inline';
			var i = 0;
			var j = 1;
			var pre;
			for(i = startRecord; i<endRecord; i++,j++)
			{
				var x = i + 1;
				artSng = '';
				pre = '';
				document.getElementById("tdTSOrder" + j).innerHTML = "<strong>" + x  + ".<a href='" + albPath + topSinglesDataArr[i][0] +  "'><img height=50 width=50 hspace=15 src='" + topSinglesDataArr[i][3] +  "' align=textTop border=0></a></strong>";//TABLE_TOP_SINGLES_CONTENT[i][0];
				
				if  (topSinglesDataArr[i][7].toUpperCase() == "VARIOUS ARTISTS")
				{artSng ="<strong><nobr><span id=spnTSArtist" + i + ">" + topSinglesDataArr[i][7] + "</span></nobr></a></strong><br><nobr><span id=spnTSName" + i + ">" + topSinglesDataArr[i][5] + "</span></nobr>&nbsp;";//
				}
				else
				{artSng = "<strong><a href=javascript:goArtist1('" + artPath + "'," + i + "); class='aTableItem' onmouseover='underline();' onmouseout='removeUnderline();'><nobr><span id=spnTSArtist" + i + ">" + topSinglesDataArr[i][7] + "</span></nobr></a></strong><br><nobr><span id=spnTSName" + i + ">" + topSinglesDataArr[i][5] + "</span></nobr>&nbsp;";//
				}
				pre = "&nbsp;<a href='javascript:PreviewSong1(" + i + ");'><IMG height='11' src='images/speaker_icon.gif' width='6' align='absMiddle' border='0'></a>"
			
				if (topSinglesDataArr[i][4] == 1)
				{
					 document.getElementById("tdTSArtAbmName" + j).innerHTML = artSng + PA + pre;
				}
				else if (topSinglesDataArr[i][4] == 2)
				{
					document.getElementById("tdTSArtAbmName" + j).innerHTML = artSng + ED +  pre ;
				}
				else
				{
					document.getElementById("tdTSArtAbmName" + j).innerHTML = artSng + "&nbsp;" + pre;
				}
					document.getElementById("tdTSFormat" + j).innerHTML = "<span id=spnFormat name=spnFormat class='fileFormat'> " +topSinglesDataArr[i][13]+ "</span>" 
				
				if (topSinglesDataArr[i][11] == "0")
				{
					document.getElementById("tdTSPrice" + j).innerHTML = "<table width='100%'><tr><td width='100%' align='center'><span class='bluelink' title='Song only available with album download'>Album Only</span></td></tr></table>";
					document.getElementById("tdTSBuyShare" + j).innerHTML = "<a href=javascript:openPassAlongPopUp1(" + i + ");><img id='img1pass" + i +"' name='img1pass"+ i +"' height=15 hspace=3 src='images/1pass.gif' width=46 align=absMiddle vspace=0 border=0></a>";
				}	
				else
				{
					document.getElementById("tdTSPrice" + j).innerHTML = topSinglesDataArr[i][11];
					document.getElementById("tdTSBuyShare" + j).innerHTML ="<a href=javascript:AddToCart('PId=1&ItemId=" + topSinglesDataArr[i][8] + "&Type=1');><img id='imgbuysong" + i +"' name='imgbuysong"+ i +"' height=15 hspace=3 src='images/buysong.gif' width=46 align=absMiddle vspace=0 border=0></a><a href=javascript:openPassAlongPopUp1(" + i + ");><img id='img1pass" + i +"' name='img1pass"+ i +"' height=15 hspace=3 src='images/1pass.gif' width=46 align=absMiddle vspace=0 border=0></a>";
				}
			}	
			
			if(sng_noOfPages!=0)
			{		
				document.getElementById("spnSngPageFooter").innerHTML = "Page " + sng_pageNo + " of " + sng_noOfPages;
			}
			
			ControlText('spnTSArtist',0,20,104);
			ControlText('spnTSName',0,20,81);		
		}		
		
		
		
		

		function EmptySongs()
		{
			var j;
			for(j = 1; j<=5; j++)
			{
				document.getElementById("tdTSOrder" + j).innerHTML = "&nbsp;";
				document.getElementById("tdTSArtAbmName" + j).innerHTML = "&nbsp;";
				document.getElementById("tdTSPrice" + j).innerHTML = "&nbsp;";
				document.getElementById("tdTSFormat" + j).innerHTML = "&nbsp;";
				document.getElementById("tdTSBuyShare" + j).innerHTML = "&nbsp;";
			}	
		}