

function getHeckleMsgPageRail(count)
{
	var url = '../../community/pickgame/allUGCGameTextByDate.html';
	var size = 12;
	var recentHeckles = '';
	
	new Ajax.Request(url, {
	  method: 'post',
	  parameters: {p: 9, begin: 0, size: size},
  	  asynchronous:  false,

	
		onSuccess: function(transport) {		
			var json = transport.responseText.evalJSON();
			
			var heckle = '';

			for(i=0; i<json.gameTexts.length; i++)
			{
				var msg 	= json.gameTexts[i].text;
				var uname	= json.gameTexts[i].user.username;
				var city	= json.gameTexts[i].city;
				var state	= json.gameTexts[i].state;
				var vote	= json.gameTexts[i].count;
				
				var msgCount = msg.length;

				heckle = heckle + '<div onClick="window.location.href=\'all_heckles.php\'" class="hMsg" id="content'+count+'" style="cursor:pointer;height: 68px; margin-top: 3px; border:0px solid red; padding-top:6px; padding-left:13px; width:303px; display:block; float:left;">';
				
				if (msgCount < 168)
				{
					heckle = heckle + '<div class="floatLeft" style="min-height:18px; color:#FFFFFF; font-weight:bold;">'+msg+'</div>';
				}
				else
				{
					heckle = heckle + '<div class="floatLeft" style="min-height:18px; color:#FFFFFF; font-weight:bold;">'+msg.substring(0,166)+' ...</div>';
				}
				
				/*if(uname == 'Anonymous')
				{
					heckle = heckle + '<div class="floatLeftVote" style="min-height:18px; color:#FFFFFF;">from '+uname+ '</div>';
				}
				else
				{
					heckle = heckle + '<div class="floatLeftVote" style="min-height:18px; color:#FFFFFF;">from '+uname+' in '+city+', '+state+ '</div>';
				}*/		
				
				heckle = heckle + '<div class="clear"></div>';
				heckle = heckle + '</div>';		
				
				count++;
			}
			
			

			this.recentHeckles = heckle;
			
			

		}.bind(this)
		
		
	});
		
	return (this.recentHeckles);
}

function getHeckleMsgPageRailqqqqq()
{
	var url = '../../community/pickgame/allUGCGameTextByDate.html';
	var size = 6;
	var recentHeckles = '';
	
	new Ajax.Request(url, {
	  method: 'post',
	  parameters: {p: 9, begin: 0, size: size},
  	  asynchronous:  false,

	
		onSuccess: function(transport) {		
			var json = transport.responseText.evalJSON();
			
			var heckle = '';
			var heckle2 = '';
			var refreshHeckle = '';


			for(i=0; i<json.gameTexts.length; i++)
			{
				var msg 	= json.gameTexts[i].text;
				var uname	= json.gameTexts[i].user.username;
				var city	= json.gameTexts[i].city;
				var state	= json.gameTexts[i].state;
				var vote	= json.gameTexts[i].count;
				
				heckle = heckle + '<div class="hMsg" id="content'+i+'" style="height: 68px; margin-top: 3px; border:0px solid red; padding-top:6px; padding-left:13px; width:303px; display:block; float:left;">';
				heckle = heckle + '<div class="floatLeft" style="min-height:18px; color:#FFFFFF; font-weight:bold;">'+msg+'</div>';
				heckle = heckle + '<div class="floatLeft" style="min-height:18px; color:#FFFFFF;">from '+uname+' in '+city+', '+state+ '</div>';
				heckle = heckle + '<div class="clear"></div>';
				heckle = heckle + '</div>';			
			}
			
			for(j=eval(json.gameTexts.length-3); j<json.gameTexts.length; j++)
			{
				var msg 	= json.gameTexts[j].text;
				var uname	= json.gameTexts[j].user.username;
				var city	= json.gameTexts[j].city;
				var state	= json.gameTexts[j].state;
				var vote	= json.gameTexts[j].count;
					
				heckle2 = heckle2 + '<div class="hMsg" id="content'+j+'" style="height: 68px; margin-top: 3px; border:0px solid red; padding-top:6px; padding-left:13px; width:303px; display:block; float:left;">';
				heckle2 = heckle2 + '<div class="floatLeft" style="min-height:18px; color:#FFFFFF; font-weight:bold;">'+msg+'</div>';
				heckle2 = heckle2 + '<div class="floatLeft" style="min-height:18px; color:#FFFFFF;">from '+uname+' in '+city+', '+state+ '</div>';
				heckle2 = heckle2 + '<div class="clear"></div>';
				heckle2 = heckle2 + '</div>';
			}


				heckle2 = $('myCode').value;
				$('myCode').value = heckle2;
			


			this.recentHeckles = heckle2 + heckle;
			
			

		}.bind(this)
		
		
	});
		
	return (this.recentHeckles);
}


function voteHeckle(id,div)
{	
	var url = '../community/pickgame/ugcGameTextVote.html';

	new Ajax.Request(url, {
	  method: 'post',
	  parameters: {ugcGameTextId: id},
	
		onSuccess: function(transport) {
			var json = transport.responseText.evalJSON();
			
			if (json.message == 'User already voted for this item')
			{
				$('hContent_'+div).style.backgroundImage= "url(/heckleu/images/content/blue_bg_hand_box.gif)";
				$('vote_now').innerHTML = "";
				setTimeout("$('vote_now').innerHTML = 'You have already voted for this heckle.'", 300);
				$('vote_now').style.color = "red";
				
				setTimeout("$('vote_now').innerHTML = 'Click on a heckle to vote for your favorite!';$('vote_now').style.color='#0E7DB2'", 10000);
			}
			else
			{
				$('hContent_'+div).style.backgroundImage= "url(/heckleu/images/content/blue_bg_hand2_box.gif)";
				$('vote_now').innerHTML = 'Click on a heckle to vote for your favorite! <b>Thank you for voting.</b>';
				$('vote_now').style.color = "#0E7DB2";
				setTimeout("$('vote_now').innerHTML = 'Click on a heckle to vote for your favorite!';$('vote_now').style.color='#0E7DB2';", 10000);
			}
		}
	});
	
	
	return false;
}

function getHeckleMsgPage(myDivID,p,begin,size)
{
	if(myDivID == 'recentHeckles')
	{
		var url = '../community/pickgame/allUGCGameTextByDate.html';
	}
	else
	{
		var url = '../community/pickgame/allUGCGameTextByVote.html';
	}
	
	new Ajax.Request(url, {
	  method: 'post',
	  parameters: {p: p, begin: begin, size: size},
	
		onSuccess: function(transport) {
			//var jsonTXT = transport.responseText;
			
			var json = transport.responseText.evalJSON();
			var heckle = '';

			for(i=0; i<json.gameTexts.length; i++)
			{
				var msg 	= json.gameTexts[i].text;
				var uname	= json.gameTexts[i].user.username;
				var city	= json.gameTexts[i].city;
				var state	= json.gameTexts[i].state;
				var vote	= json.gameTexts[i].count;
				var id	= json.gameTexts[i].id;
				
				var myID = myDivID + '_' + id;
				
				
				var msgCount = msg.length;
				
				heckle = heckle + '<div onClick="return voteHeckle(\''+id+'\',\''+myID+'\')" class="hVoteMsg" id="hContent_'+myDivID+'_'+id+'" style="cursor: pointer;height: 66px; margin-top: 0px; border:0px dotted red; padding-top:6px; padding-left:0px; width:303px; display:block; float:left;">';
				
				heckle = heckle +'<div class="voteLink">'+vote+'</div>';
				
				heckle = heckle +'<div style="float:right;">';
				
				if (msgCount < 141)
				{
					heckle = heckle + '<div class="floatLeftVote" style="min-height:18px; color:#FFFFFF; font-weight:bold;">'+msg+'</div>';
				}
				else //more than 141 chars
				{
					heckle = heckle + '<div class="floatLeftVote" style="min-height:18px; color:#FFFFFF; font-weight:bold;">'+msg.substring(0,141)+' ...</div>';
				}
				
				/*if(uname == 'Anonymous')
				{
					heckle = heckle + '<div class="floatLeftVote" style="min-height:18px; color:#FFFFFF;">from '+uname+ '</div>';
				}
				else
				{
					heckle = heckle + '<div class="floatLeftVote" style="min-height:18px; color:#FFFFFF;">from '+uname+' in '+city+', '+state+ '</div>';
				}*/
				
				heckle = heckle +'</div>';

				
				heckle = heckle + '<div class="clear"></div>';
				heckle = heckle + '</div>';
			}
			
			//console.log(heckle)
			//this.colins=json.totalCount;
			
			$(myDivID).innerHTML = heckle;
			
			//console.log($('myCode').value);
			
		}.bind(this)
	});
	
	
}

function buildPagination(pc, p, c, o) {
	
		var category = c;
		var pid = 0;
		var show = 'test';
		var page = eval(p);
		var number_of_pages = eval(pc);
		
		var nine = 4;
		var ten	 = 5;
		var eleven = 6;
	
	
	
		if(c == 'RECENT')
		{
			extra = '&offsetPopular='+o+'&popularCategory=POPULAR';
			offset = 'offsetRecent'
			vcategory = 'recentCategory';
		}
		else //POPULAR
		{
			extra = '&offsetRecent='+o+'&recentCategory=RECENT';
			offset = 'offsetPopular'
			vcategory = 'popularCategory';
		}
	
	
	
		if (number_of_pages <= ten) {
			
			
			for (i=0; i<number_of_pages; i++) {
				if (page != i) {
					document.write('<div class="navdot"><a href="?'+offset+'=' + i + '&'+vcategory+'=' + category + '&reload=true&pid=' + pid + '&show=' + show + extra + '">' + (i+1) + '</a></div>')
				}
				else {
					document.write('<div class="navdotSelected">' + (i+1) + '</div>')
				}
			}
			
		}
		
		else {
				if (number_of_pages - (page+1) < nine ) {

	for (i=number_of_pages-ten; i<number_of_pages; i++) {
					if (page != i) {
						document.write('<div class="navdot"><a href="?'+offset+'=' + i + '&'+vcategory+'=' + category + '&reload=true&pid=' + pid + '&show=' + show + extra + '">' + (i+1) + '</a></div>')
					}
					else {
						document.write('<div class="navdotSelected">' + (i+1) + '</div>')
					}
				}
			}
			
			
			//else if ((page >= nine)&&(number_of_pages - (page+1) >= nine )) {
				
			else if ((page >= nine)&&(number_of_pages - (page+1) >= nine )) {
				
				
				if (number_of_pages - (page+1) >= ten) 
				{
					
					pagesToShow = ten;
					
				}
				else
				{
						pagesToShow = ten;
				}



				//for (i=page-nine; i<page+pagesToShow; i++) {
				for (i=(page+2)-nine; i<page+(pagesToShow-2); i++) {

if (page != i) {
						document.write('<div class="navdot"><a href="?'+offset+'=' + i + '&'+vcategory+'=' + category + '&reload=true&pid=' + pid + '&show=' + show + extra + '">' + (i+1) + '</a></div>')
					}
					else {
						document.write('<div class="navdotSelected">' + (i+1) + '</div>')
					}
				}
				
			}
			
			else if (page < nine) {
				for (i=0; i<ten; i++) {
					if (page != i) {
						document.write('<div class="navdot"><a href="?'+offset+'=' + i + '&'+vcategory+'=' + category + '&reload=true&pid=' + pid + '&show=' + show + extra + '">' + (i+1) + '</a></div>')
					}
					else {
						document.write('<div class="navdotSelected">' + (i+1) + '</div>')
					}
				}
				
			}
			
			else {
				for (i=page; i<page+ten; i++) {
					if (page != i) {
						document.write('<div class="navdot"><a href="?'+offset+'=' + i + '&'+vcategory+'=' + category + '&reload=true&pid=' + pid + '&show=' + show + extra + '">' + (i+1) + '</a></div>')
					}
					else {
						document.write('<div class="navdotSelected">' + (i+1) + '</div>')
					}
				}
				
			}
		
		}

	
	
}

