
//////////////////////////////////////////////////////////////////////////////////////////////////////

// LOAD IMAGES
var vote_out = new Image();
vote_out.src = "images/vote_out.gif";
var vote_over = new Image();
vote_over.src = "images/vote_over.gif";

var suggestion_out = new Image();
suggestion_out.src = "images/suggestion_out.gif";
var suggestion_over = new Image();
suggestion_over.src = "images/suggestion_over.gif";

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// bigPromosArr holds the 2 big promoted games 
//var bigPromosArr = new Array("Reel Gold", "Beaver Brothers");
//var bigPromosArr = new Array("More Bloons", "Reel Gold");
//var bigPromosArr = new Array("More Bloons", "Ice Slide");
//var bigPromosArr = new Array("More Bloons", "Camp Rock");
//var bigPromosArr = new Array("Come2Play", "Hooked Media");
var bigPromosArr = new Array("More Bloons", "Hooked Media");

//////////////////////////////////////////////////////////////////////////////////////////////////////

// search form functions
var searchStr="";

function SelectCategory()
{
	// zero the search string
	searchStr="";
	
	var i, cat;
	for(i=0; i<document.searchForm.selectCategory.length; i++)
	{
		if(document.searchForm.selectCategory.options[i].selected)
		{
			cat = document.searchForm.selectCategory.options[i].value;
			break;
		}
	}
	FillTempArrayByCategory(cat);
	SetCurGroupDiv();
}


function SetSearchResults()
{
	// set the value of the search string
	searchStr = document.searchForm.keywords.value;
	if(searchStr)
	{
		if( FillTempArrayByKeywords(searchStr) > 0 )
		{
			SetCurGroupDiv();
		}
		else
		{
			alert("keywords not found :(");
		}
	}
}


/*
function KeyPress(e)
{
	var keycode;
	if (window.event)
	{
		keycode = window.event.keyCode;
	}	
	else if (e)
	{
		keycode = e.which;
	}	
	//alert("keycode="+keycode)
	if(keycode == 13)
	{
		//void(0);
		SetSearchResults();
	}	
}
*/

function KeyPress(e) 
{
	if(!e) // !FF
	{
		var e = window.event;
	}
	
	if(navigator.userAgent.toLowerCase().indexOf("firefox") == -1) //IE
	{
		//alert("char="+e.keyCode)
		if (e.keyCode == 13)
		{
			e.keyCode = 0;
			void(0);
			SetSearchResults();
		}	
	}
	else
	{
		//alert("char="+e.which)
		if (e.which == 13)
		{
			e.which = 0;
			void(0);
			SetSearchResults();
		}
	}
}

/*
function KeyPress_orig() 
{
	//alert(window.event.keyCode)
	if (window.event.keyCode == 13)
	{
		window.event.keyCode = 0;
		SetSearchResults();
	}
}
*/

//////////////////////////////////////////////////////////////////////////////////////////////////////

var init_category_param = "Arcadia";
function Init()
{
	FillTempArrayByCategory(init_category_param);
	SetCurGroupDiv();
}

function SetCurGroupDiv()
{
	var i, imgSrc, curUrl, gameId, buffer="";
	var numOfRows = 9;
	var rows_counter = (someGamesArr.length > numOfRows-1)? someGamesArr.length : 9;

	buffer += "<table border=0 cellpadding=0 cellspacing=0 width=600 height=379>";
	for(i=0; i<rows_counter; i++)
	{
		buffer += "<tr><td colspan=2 height=1 bgcolor=black></td></tr>";
		
		buffer += "<tr>";
		if(someGamesArr[i])
		{
			imgSrc = "images/smallIcons/" + someGamesArr[i].smallIcon;
			curUrl = "games.pl?category="+someGamesArr[i].category+"&amp;dispName="+someGamesArr[i].dispName+"&amp;searchStr="+searchStr;
			if( someGamesArr[i].url.indexOf('http') === 0 )
			{
				curUrl =  someGamesArr[i].url
			}
			
			// set the game icon
			buffer += "<td width=56 height=40 align=center><a href='"+curUrl+"' onclick=\"javascript:urchinTracker('/GAS/centers/games/"+someGamesArr[i].dispName+"')\" target='_blank'><img border=0 src='"+imgSrc+"'></a></td>";
			
			// set the game description
			gameId = "gameId_" + i;
			buffer += "<td width=544 align=left valign=middle>";
				buffer += "<table border=0 cellpadding=0 cellspacing=0>";
					buffer += "<tr>";
						buffer += "<td align=left valign=middle width=490><a class='A_orange' onclick=\"javascript:urchinTracker('/GAS/centers/games/"+someGamesArr[i].dispName+"')\" href='"+curUrl+"' target='_blank'><b>"+someGamesArr[i].dispName.toUpperCase()+"</b></a><span class='regText'><br>"+someGamesArr[i].description+"</span></td>";
						buffer += "<td align=left valign=middle width=5></td>";
						buffer += "<td align=left valign=middle width=39>";
						buffer += (someGamesArr[i].viewStatus == 2)? "<span style='font-family:arial narrow; font-size:10px; font-weight:bold; color:#ffffff; background-color:#ff0000;'>&nbsp;NEW!&nbsp;</span>" : "";
						buffer += "</td>";
						buffer += "<td align=left valign=middle width=10></td>";
					buffer += "</tr>";
				buffer += "</table>";
			buffer += "</td>";
		}
		else
		{
			buffer += "<td colspan=2 height=40></td>";
		}
		buffer += "</tr>";
	}
	buffer += "</table>";
	
	// set the new category
	var cur_obj = document.getElementById('curGroupDiv');
	cur_obj.innerHTML = buffer;
	
	// scroll up to see the content
	cur_obj.scrollTop = 0;
		
	// view or hide the 'get more games' arrows
	//document.getElementById('moreGamesDiv').style.visibility = (someGamesArr.length > numOfRows)? "visible" : "hidden";
	
	// set the Num Of Games view
	document.getElementById('numOfGamesDiv').innerHTML = "<span class='brightText'><b>&nbsp;Search results: "+someGamesArr.length+" Games</b></span>";
}

//////////////////////////////////////////////////////////////////////////////////////////////////////

// THE POLL FUNCTIONS

var vote_param = -1;
function SetVote(theparam)
{
	vote_param = theparam;
}

function SubmitQuiz()
{
	if(vote_param > 0)
	{
		var id_param = 158;
		var subject_param = "GamesCenter06";
		var voteFormParam = "id=" + id_param + "&subject=" + subject_param + "&vote=" + vote_param + "&viewer_mode=CenterPoll";
		var voteFormLink = "http://www.girlsense.com/kiddonet/polls/saveVotePoll.pl?" + voteFormParam;

		// replace the bg of poll
		document.all.item("quizDiv").innerHTML = "<table border=0 width='100%' height='100%' bgcolor=white><tr><td align=center valign=middle><img border=0 src='images/thanks4voting.gif'></tr></td></table>";

		//submit the poll
		window.open(voteFormLink, "votepopup", "width=397,height=267");
	}
	else
	{
		alert("Please choose an answer.");
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function UsersSuggestion()
{
	//theLink = '/tools/feedback/index.pl?project=GamesCenter';
	//activityWinHandler = window.open(theLink,'premiumActivityWinFeedback','scrollbars=auto,toolbar=no,resizable=yes,left=10,top=10,width=480,height=500');
	theLink = 'http://www.girlsense.com/tools/feedback/index_CenterTemplate.pl?project=GamesCenter';
	activityWinHandler = window.open(theLink,'pollsWin','toolbar=no,menubar=no,scrollbar=no,resizable=yes');
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function SetNewBgDivsHeight()
{
	var page_height = document.body.scrollHeight;

	// set the centerDiv height
	document.getElementById('centerDiv').style.height = page_height;	

	// set the backgroundDivRepeat height (page height - (top bar + top ad + title image))
	document.getElementById('backgroundDivRepeat').style.height = 50 + (page_height - parseInt(document.getElementById('backgroundDivRepeat').style.top));	
}

function SetFooterTopStyle()
{
	var page_height = document.body.scrollHeight;
	document.getElementById('bottomBarDiv').style.visibility = "visible";
	document.getElementById('bottomBarDiv').style.top = page_height - 30;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
