
var	showLongDesc = 'enabled';
var currentList = new Array(6);

function LongDesc(){
	showLongDesc = 'enabled';
}

/* ajax upadate error display */
function throw_error(errorObj, statusObj, errorCode){
	$(errorObj).className+=' errorbackground';
	$(statusObj).innerHTML = '<span class=\"error\">'+ errorCode +'</span>';
}

function updateGame (gid){
	showLongDesc = 'false';
	var loc = document.getElementById('SelectedValue').value;
	var pars = 'pid='+pid+'&loc='+loc.split("_")[1]+'&gid='+gid;
	currentGames(loc,gid);
	myEditbox.end();
	var myAjax = new Ajax.Updater(loc,"edit_games.php", {evalScripts:true, method: 'get', parameters: pars,onComplete: function(){ LongDesc(); pointy_tips(loc)}});
}

function loadFlash (flashPath, infoPath) {
	var featureFlash = new SWFObject(flashPath, "featureFlash", "175", "150", "7", "#FFFFFF");
	featureFlash.addParam("wmode", "transparent");
	featureFlash.addParam("FlashVars",infoPath);
	 featureFlash.write("featured_img");
}

function updatEditbox(current){
	if(current == 'game_0'){
		$('menuTitleinner').innerHTML = 'Featured ';
	}else{
		$('menuTitleinner').innerHTML = 'Top 5 ';
	}
	$('editbox').innerHTML = $('menuContainer').innerHTML;
}

function currentGames(loc,gid){
	for(i=0;i<6;i++){
		if(i == loc){
			currentList[i] = gid;
		}
	}
}

function hidecurrent(){
	for(i=0;i<currentList.length;i++){
		if($(currentList[i])){
			$(currentList[i]).style.display = "none";
		}
	}
}

function editThisReview(reviewText, reviewGameID, reviewGameTitle, reviewLocation){
   if($('reviewText')){
  		reviewText = unescape(reviewText)
    	reviewText = reviewText.replace(/\\/g,'');
		$('reviewText').value = reviewText;
		$('reviewGameID').value = reviewGameID;
		$('reviewPTitle').innerHTML = reviewTitle;
		$('reviewTitle').innerHTML = reviewGameTitle;
		$('reviewLocation').value =  reviewLocation;
	}
	
	if($('rrBox')) {
		$('rrBoxTitle').innerHTML = reviewGameTitle;
	}
}

function editThisTitle(pageTitle,OpageTitle){
	if($('pageTitle')){
	  	pageTitle = unescape(pageTitle)
	    pageTitle = pageTitle.replace(/\\/g,'');
		$('pageTitle').value = pageTitle;
	  	OpageTitle = unescape(OpageTitle)
	    OpageTitle= OpageTitle.replace(/\\/g,'');
		$('OpageTitle').value = OpageTitle;
	}
}

function editThisWelcome(welcomeText,OwelcomeText){
	if($('welcomeText')){
		welcomeText = unescape(welcomeText)
		welcomeText = welcomeText.replace(/\\/g,'');
		$('welcomeText').value = welcomeText;
		OwelcomeText = unescape(OwelcomeText)
		OwelcomeText = OwelcomeText.replace(/\\/g,'');
		$('OwelcomeText').value = OwelcomeText;
	}
}

function gameview(url){
	var popWidth = 820;
	var popHeight = (getPageSize()[1]*.75);
	if (getPageSize()[0] < 780) { popWidth = (getPageSize()[0]*.75) }
	gamewindow=window.open(url,'gameview','toolbar,menubar,scrollbars,resizable,location,top=100,left=100,height='+ popHeight +',width='+ popWidth +'');
	if (window.focus) {
		gamewindow.focus()
	}
}

function addField (form,l,i) {
	var input = document.createElement('input');
	input.setAttribute('type', 'hidden');
	input.setAttribute('value', i);
	if(l !== "pageTitle"){
		input.setAttribute('name', l);
		input.setAttribute('id', l);
	} else {
		input.setAttribute('name', 'title');
		input.setAttribute('id', 'title');
	}
	form.appendChild(input);
}

function getLongDesc (obj,gid){
	if(!$('gamebox')){	return false;	}
	if(showLongDesc == 'enabled'){
		if(obj)	{
			myGamebox.start(obj);
			var pars = 'gid='+gid;
			var myAjax = new Ajax.Updater("gamebox", "request_gameinfo.php", {method: 'get', parameters: pars});
		}
	}
}

function closeDesc(){
	if(!$('gamebox')){	return false;	}
	Element.hide('gamebox');
}

var reviewprocess = 'false';
var currev_id = '';

function getGameReview (obj,pid,gid){
	if(reviewprocess == 'true'){ return; }
	if(currev_id == gid){ return; }
	currev_id = gid;
	reviewprocess = 'true';
	var pars = 'gid='+gid+'&pid='+pid;
	Effect.BlindUp('SubReview', { duration:.9, afterFinish: function(){	var myAjax = new Ajax.Updater(obj, "request_reviews.php", { method: 'get', parameters: pars, onComplete:Effect.BlindDown('SubReview', { duration:.9, afterFinish: function(){ reviewprocess = "false"; }}) }); }});
}


function closeGameReview(){
	Effect.BlindUp('SubReview', {duration:.9, afterFinish: function(){ reviewprocess = 'false'; currev_id = ''; } });
}

function featureReview(mode){
	if(mode == 'expand'){
		$('feature_review_entry').style.display = 'none';
		$('feature_review_more').style.display= 'block';
	}else{
		$('feature_review_entry').style.display = 'block';
		$('feature_review_more').style.display= 'none';
	}
}

function check_maxlength(obj, maxlength, status_id)
{
	if (obj.value.length >= maxlength) {
		obj.value = obj.value.substring(0, maxlength);
	}
	if ($(status_id)) {
		$(status_id).innerHTML = obj.value.length + '/' + maxlength;
	}
	/* clear any error class that may exit */
	obj.setAttribute("class","");
	obj.setAttribute("className","");
}