	//global pager vars
	var itemsPerPage = 5;
	var sPage = 1;
	var sPageAvgSize = 100; // this value must match the number of returned recordsets
	var pageMax = 10;
	var pageOffset = 1;
	var totalRetItems ='';
	var totalItems ='';
	var filter ='';

	var commentItems=new Array();

function commentItem(vars)
	{
		this.commentID=vars['commentID'];
		this.comment=vars['comment'];
		this.user_name=vars['user_name'];
	}
	commentItem.prototype.commentID;
	commentItem.prototype.comment;
	commentItem.prototype.user_name;

 function getPage(sPage, sectionID)
 {
 //alert(sPage +","+ sectionID);
  commentItems = new Array();
 var queryData='method=getWeddingSectionPage&page='+ sPage +'&sectionId='+ sectionID +'&rand='+randDARTNumber;

 jqN.ajax({
				type:"GET",
				url:"app/office/wedding/services/index.php",
				data: queryData,
				dataType:"xml",
				error: function(){
					alert('<b>Failed to lookup request</b>');
				},
				success: function(xml){
					jqN('item',xml).each(function(i){
					vars=new Array();
					vars['commentID']=jqN('id',this).text();
					vars['user_name']=jqN('name',this).text();
					vars['comment']=jqN('comment',this).text();
					CommentItem = new commentItem(vars);
					commentItems.push(CommentItem);
				});
				totalItems = jqN('totalItems',xml).text();
				totalRetItems = commentItems.length;
				//current page
				if(pageOffset > (totalItems / itemsPerPage)){pageOffset = Math.ceil(totalItems / itemsPerPage);}
				renderPage(pageOffset);
		}
 });
}

function renderPage(page)
{

	if (locationCheck(page))
	{
			var pageEnd = (page * itemsPerPage) - (sPageAvgSize *(sPage -1));
			var pageStart = pageEnd - itemsPerPage;
			if (pageEnd > totalRetItems){pageEnd = totalRetItems;}

		jqN('#comments').html('');
		jqN('#pagerBottom').html('');
		var outputHtml ='';
		//alert('Page: ' + page + '\n' +'itemsPerPage: ' + itemsPerPage + '\n' + 'pageStart: ' + pageStart + '\n' + 'pageEnd: ' + pageEnd + '\n' + 'totalItems: ' + totalItems + 'totalRetItems: ' + totalRetItems);
	for(i=pageStart;i<pageEnd;i++)
	{
		outputHtml += "<p>"+commentItems[i].comment ;
		outputHtml += "<span>- "+commentItems[i].user_name+"</span></p>";
	}
	jqN('#comments').append(outputHtml);
	Pager(page);
	//newNBCPageview();
	} 
		else 
	{
		getPage(sPage, sectionID)
	}
}
	
function Pager(page){

		var numOfPages = totalItems / itemsPerPage
		var pageNumbers ='';
		var prevPage = '';
		var nextPage = '';

		
	if (page > 5){
		startOffset = page - 5;
		endOffset = page + 5;
	}else{
		startOffset = 1;
		endOffset = pageMax;
	}
	if (endOffset > numOfPages ){
		endOffset = Math.ceil(numOfPages);
		startOffset = endOffset - (pageMax -1);
	}
	if (startOffset <= 0)
	{
		startOffset = 1;
	}
	if (page < 0 ){
		page = 0;
	}
	for(i=startOffset; i<=endOffset; i++){
			if (i == page) 
			{
				pageNumstyle = 'background-color:#D2E0E6;color:#b31b1b;';
				rollover = 'onMouseOver="highlightOn(this);" onMouseOut=""';
			} 
			 else
			{ 
				pageNumstyle = 'color:#000000;'; 
				rollover = 'onMouseOver="highlightOn(this);" onMouseOut="highlightOff(this);"';
			}
			pageNumbers += '<div id="pagerItem" name="pagerItem" onclick="renderPage('+i+');" style="'+ pageNumstyle + '" '+ rollover + ' >'+i+'</div> ';
			if (page == 1){prevPage = 1;} else {prevPage = page - 1;}
			if (page == endOffset){nextPage = endOffset;}  else {nextPage = page + 1;}
	}	



	
		var sPager = '<div id="pagerItem" name="pagerItem"  onclick="renderPage(1);" onMouseOver="highlightOn(this)" onMouseOut="highlightOff(this)"><<</div>'+
		'<div id="pagerItemPrev" name="pagerItemPrev" onclick="renderPage('+ prevPage +');" onMouseOver="highlightOn(this)" onMouseOut="highlightOff(this)">< Prev</div> '+
		 pageNumbers +
		' <div id="pagerItemPrev" name="pagerItemPrev" onclick="renderPage('+ nextPage +');" onMouseOver="highlightOn(this)" onMouseOut="highlightOff(this)">Next ></div>'+
		'<div id="pagerItem" name="pagerItem" onclick="renderPage('+ Math.ceil(numOfPages) +');" onMouseOver="highlightOn(this)" onMouseOut="highlightOff(this)">>></div>';
		
		jqN('#pagerBottom').append(sPager);

		return true;
		
		
	}
	
function locationCheck(page)
{
	var retVal = true;
	var nextsPage = Math.ceil((page)/(Math.ceil(sPageAvgSize / itemsPerPage)))

	if(sPage != nextsPage)
		{
			sPage = Math.ceil((page)/(Math.ceil(sPageAvgSize / itemsPerPage)));
			pageOffset = page;
			retVal = false;
		}
			return retVal;
}

function highlightOn(arg)
	{
		arg.style.backgroundColor ='#D2E0E6';
		arg.style.color = "#b31b1b";
	}

function highlightOff(arg)
{
		arg.style.backgroundColor='';
		arg.style.color = "#b31b1b";
}

function newNBCPageview()
{
	s.t();
	window.ad728x90.location.reload();  // Delete this line if there are no 728x90 leaderboard iframes on the page
	window.ad300x250.location.reload(); // Delete this line if there are no 300x250 iframes on the page
}

function submitComment()
{
	var nameTxt = jqN("#name").val();
	var commentTxt = jqN("#comment").val();

if ((nameTxt !=='') && (commentTxt !==''))
	{
		jqN.post("app/office/wedding/wedding.php",{ name: nameTxt, comment: commentTxt, section: sectionID},
			function()
			{
				jqN("#postform").html('Thank you for your comment!')
			}
		);
	}
	else
	{ 
		alert('You must enter a user name and a comment.');
	}
}

