
function memberDetail(t,uname)
{
	
	//console.log('in tribes')
	// p=1 indicate this is the fantasy game
	var url1 = '../../../community/pickgame/tribeListUserPicks.html';

	new Ajax.Request(url1, {
	  method: 'post',
	  parameters: {t: t},

	  onSuccess: function(transport) {
			//var jsonTXT = transport.responseText;
			var json = transport.responseText.evalJSON();




			//console.log(json.tribeList.length);

			var max = json.members.length;
			var arrID = new Array();
			
			//$('insertMemberInfo').innerHTML = max;

			for(i=0; i<max; i++)
			{
				if(json.members[i].username == uname)
				{
					
					//console.log('colins:'+json.members[i].answerSetList[0].bonusChoiceIdList.length)
					
					if(json.members[i].answerSetList.length > 0)
					{
						//console.log(json.members[i].username)	
						for(j=0; j<json.members[i].answerSetList[0].bonusChoiceIdList.length; j++)
						{
							arrID.push(json.members[i].answerSetList[0].bonusChoiceIdList[j]);
							
						}
					}
					else
					{
				memberInfo = '<div style="font-weight:bold;">This Group Member has currently not made any picks</div>';
				$('insertMemberInfo').innerHTML = '<h3 style="border-bottom:none;">'+uname+'</h3><p style="height:auto;">'+memberInfo+'</p><div class="clear"></div>';
				$('DetailInfo').style.display = 'block';
					}
				}
			}

	
	//alert(arrID)
	
	
	if(arrID.length > 0)
	{
		//match this against the display controller
		memberDetailDisplay(arrID,uname);
	}
	  }
	});


	return false;
}

function memberDetailDisplay(arrID,uname)
{
	//console.log('in tribes')
	// p=1 indicate this is the fantasy game
	var url1 = '../../../community/pickgame/display.html';

	new Ajax.Request(url1, {
	  method: 'post',
	  parameters: {p: '5'},

	  onSuccess: function(transport) {
			//var jsonTXT = transport.responseText;
			//console.log(jsonTXT)
			//alert(jsonTXT)
			
			var json = transport.responseText.evalJSON();

			//console.log(json.tribeList.length);

			var myTribes = '';
			var myTribesHeader = '';
			var myMore = '';
var memberInfo = '';
			var maxI = json.pickGame.segmentList[0].bonusQuestionList.length;

//console.log(max)			
			//$('insertMemberInfo').innerHTML = max;
			var max = arrID.length;
			
			
			
			if (max == 0)
			{
				memberInfo = '<div style="font-weight:bold;">This Group Member has currently not made any picks</div>';
				$('insertMemberInfo').innerHTML = '<h3 style="border-bottom:none;">'+uname+'</h3><p style="height:auto;">'+memberInfo+'</p><div class="clear"></div>';
				$('DetailInfo').style.display = 'block';

				
			}
			else
			{
			
			
			for(k=0; k<max; k++)
			{
			

				curID = arrID.pop();
//console.log(curID)

				
				
//console.log(max2)

				for(i=0; i<maxI; i++) // loop thru all 12 tables
				{
					var max2 = json.pickGame.segmentList[0].bonusQuestionList[i].bonusChoiceList.length;

					
					for(j=0; j<max2; j++) // loop thru each of the 12 table
					{
						
	//console.log(curID+'---'+json.pickGame.segmentList[0].bonusQuestionList[i].bonusChoiceList[j].id);					
						
						if(curID == json.pickGame.segmentList[0].bonusQuestionList[i].bonusChoiceList[j].id)
						{
							
							//console.log('match:'+curID)
							
							
							//console.log(json.pickGame.segmentList[0].bonusQuestionList[i].question)
							//console.log(json.pickGame.segmentList[0].bonusQuestionList[i].bonusChoiceList[j].choice)
							
							memberInfo += '<div style="font-weight:bold;">'+json.pickGame.segmentList[0].bonusQuestionList[i].question+'</div>';
							memberInfo += '<div style="margin-bottom:5px;">'+json.pickGame.segmentList[0].bonusQuestionList[i].bonusChoiceList[j].choice+'</div>';
	
						}
					}
				} // end k loop
			}

			$('insertMemberInfo').innerHTML = '<h3 style="border-bottom:none;">'+uname+'</h3><p style="height:auto;">'+memberInfo+'</p><div class="clear"></div>';
			$('DetailInfo').style.display = 'block';
			
			} // end else
			
			
			
	  }
	});


}

function answerBQ(data)
{

	var url = '../../../community/pickgame/answerPickGame.html?' + data;



//console.log(url);


	new Ajax.Request(url, {
		method: 'get',

		onSuccess: function(transport) {
			// to look at plain text
			//var jsonTXT = transport.responseText;
			
			// to view it in JSON
			var json = transport.responseText.evalJSON();

			if (json.success)
			{
				window.location = "tribes.php?selection=tribes&thankyou=true";							
			}
			else
			{
				if (json.isLoggedIn == false)
				{
					// if you're not login 
					alert("Please login.");
				}
				else
				{
					// if you're log-in but with a different mpin
					alert("You must be registered for the game in order to make your selection");
				}
			}
		}
	});

//alert(url);
	
}


function getRowCount()
{
	rows = 5;
	
	return rows;
}

function checkLogin()
{
	if($('uname').value.toString().match(/\s/g))
	{
		$('errUser').innerHTML = 'Username can not contain space';
		$('errUser').style.visibility='visible';
		
		if($('pword').value == '')
		{
			$('errPassword').style.visibility='visible';
		}
		else
		{
			$('errPassword').innerHTML = '';
		}
		
		return false;
	}
	else
	{
		$('errUser').innerHTML = '';
	}
	
	if($('uname').value != '' && $('pword').value != '')
	{
		
		return true;
	}
	else
	{
		if($('uname').value == '')
		{
			$('errUser').innerHTML = 'Please enter your username';
			$('errUser').style.visibility='visible';
		}
		else
		{
			$('errUser').innerHTML = '';
		}
		
		if($('pword').value == '')
		{
			$('errPassword').style.visibility='visible';
		}
		else
		{
			$('errPassword').innerHTML = '';
		}
		

		return false;
	}	
}

function showBtn(){
		
		var url1 = '../../../community/pickgame/display.html';

	new Ajax.Request(url1, {
	  method: 'post',
	  parameters: {p: 5},

	  onSuccess: function(transport) {
			var jsonTXT = transport.responseText;
			
			//alert(jsonTXT)
			
			var json = transport.responseText.evalJSON();

			//console.log(json.tribeList.length);



			if(json.entry.answerSetList.length > 0)
			{
			
			//alert('show')
					$('printBtn').style.display = "block";
				return true;
				
			}
			else
			{
				//alert('hide')
						$('printBtn').style.display = "none";
				return false;
			}
	}
	
	});

}


function pickemRetunUser(){
		//alert(1);
		var url1 = '../../../community/pickgame/display.html';

	new Ajax.Request(url1, {
	  method: 'post',
	  parameters: {p: 5},

	  onSuccess: function(transport) {
			var jsonTXT = transport.responseText;
			
			//alert(jsonTXT)
			
			var json = transport.responseText.evalJSON();

			//console.log(json.tribeList.length);



			if(json.entry.answerSetList.length > 0)
			{
				//alert(2);
				window.location = "pickem.php?selection=pickem";
				
			}
	
	}
	
	});

}

