var iSpeed=4000;
var checkflag = "false";

/*--------------------------------------------------------------------------*/
/* Message handlers */

function _confirm(s) {
	_clr();
	$("#Q").css('display','block');
	$("#Q").addClass("warning");
	$("#Q").html(s);
}

jQuery.toggleCookie = function(Cookie) {
	$.cookie(Cookie,$.cookie(Cookie) == 1 ? 0 : 1);
};

function _err(s,o){
	_clr();
	$("#Q").css('display','block');
	$("#Q").addClass("error");
	if(o){
		$("#Q").html("An error occurred:<br /><input style='width:100%;' value='"+s+"' /><br />Please send this message to <a href='mailto:webmaster@nintendoage.com'>webmaster@nintendoage.com</a>");
		$("#Q").append("<br /><input type='button' onclick='_bye();' value='Ok' />");
	}else{
		$("#Q").html(s);
		setTimeout("_bye()", 4000);
	}
}
function _msg(s,y){
	_clr();
	$("#Q").addClass("success");
	$("#Q").html(s);
	setTimeout("_bye()", 4000);
}
function _clr(){
	$("#Q").empty();
	$("#Q").removeClass();
}
function _bye(){
	$("#Q").fadeOut("slow");
	_clr();
}

String.prototype.pluralize = function(count, plural)
{
  if (plural == null)
    plural = this + 's';

  return (count == 1 ? this : plural)
}


function flashMsgBox(sTxt,bState) {
	var elemBox = getElementReference('flashBox');
	var elemTxt = getElementReference('flashText');
	if((elemBox) && (elemTxt)) {
		elemTxt.innerHTML = sTxt;
		if(bState) {
			elemBox.className = 'flashBoxOn';
		} else {
			elemBox.className = 'flashBoxOff';
		}
	}
	setTimeout("killMsgBox()", iSpeed)
}
function killMsgBox() {
	var elemBox = getElementReference('flashBox');
	var elemTxt = getElementReference('flashText');
	elemTxt.innerHTML = '';
}
function getManualPages(setId)
{
	$.AjaxCFC({
	   url: "/components/na-jax.cfc",
	   method: "getSetManual",
	   data: {"Set_ID":setId},
	   unnamedargs: false,
	   serialization: "json",
	   success: function(rs) {
		  GB_showFullScreenSet(eval(rs), 1);
	   }
	});
}

/* extensions to jQuery */
jQuery.fn.toggleFade = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);
}; 
jQuery.fn.pluralize = function(count, plural) {
  if (plural == null)
    plural = this + 's';
  return (count == 1 ? this : plural)
};
function _Q(uId,lst,bIn) {
	$.AjaxCFC({
		url: "/components/na-jax.cfc",
		method: "queueItems",
		data: {"userId":uId, "Items":lst, "bIn":bIn},
		unnamedargs: false,
		serialization: "json",
		success: function(resp) {
			setMsgBoxText(resp);
		}
	});
}
function _Qi(uId) {
	$.AjaxCFC({
		url: "/components/na-jax.cfc",
		method: "getQueueCount",
		data: {"userId":uId},
		unnamedargs: false,
		serialization: "json",
		success: function(resp) {
			$.dump(eval(resp));
		}
	});
}
function verbiageCount(argItems,bIn) {
	var iCount = listLen(argItems);
	var sVerbiage = isPlural(iCount,'item');
	if(bIn){
		flashMsgBox(iCount+' '+sVerbiage+' queued', true);
	} else {
		flashMsgBox(iCount+' '+sVerbiage+' removed', false);
	}
}
function getCollectionImages(colId,uId)
{
	$.AjaxCFC({
	   url: "/components/na-jax.cfc",
	   method: "getCollectionImages",
	   data: {"collection_id" : colId, "user_id" : uId, returnFormat : "json"},
	   unnamedargs: false,
	   serialization: "json",
	   success: function(rs) {
		  GB_showFullScreenSet(eval(rs), 1);
	   }
	});
}
function initMsgQueue(bAlt)
{
	if(bAlt){
		jQuery.AjaxCFC({
		   url: "/components/na-jax.cfc",
		   method: "getLastQueuedMessage",
		   data: {},
		   unnamedargs: false,
		   serialization: "json",
		   success: function(msg) {
		      //$.dump(myQuery);
			  setMsgBoxText(msg);
		   }
		});
	} else {
		$.AjaxCFC({
		   url: "/components/na-jax.cfc",
		   method: "getLastQueuedMessage",
		   data: {},
		   unnamedargs: false,
		   serialization: "json",
		   success: function(msg) {
		      //$.dump(myQuery);
			  setMsgBoxText(msg);
		   }
		});
	}
}
function clearMsgBoxText() {
	var msgDiv = getElementReference('flashText');
	msgDiv.innerHTML = '';
}
function setMsgBoxText(sTxt) {
	var msgDiv = getElementReference('flashText');
	if(msgDiv){
		clearMsgBoxText();
		msgDiv.innerHTML = sTxt;
	}
}
function go(sURL) {
	location.href=sURL;
}
function popup(sURL) { 
  var winWidth = (screen.width - 100);
  var winHeight = (screen.height - 200);
  winprops = 'height=' + winHeight + ',width=' + winWidth + ',top=100,left=50,location=no,menubar=no,resizable=yes,status=no,titlebar=no,statusbar=-1,toolbar=no,scrollbars=yes';
  window.open(sURL, "", winprops)
}
function listLen(lst,delim){
	if(!delim){
		var delim = ",";
	}
	if(lst.substring(lst.length, lst.length-1) == delim){
		lst = lst.substring(0, lst.length-1);
	}
	try {
		var arrList = lst.split(delim);
		return arrList.length;
	} catch(e) {}
}
function isPlural(iCount,sSingularWord) {
	var sWord = sSingularWord;
	if(parseInt(iCount) != 1) {
		var sWord = sSingularWord + 's';
	}
	return sWord;
}
function popAlpha(sAlpha){
	var frm = document.forms['Search'];
	frm.elements['alpha'].value=sAlpha;
	frm.submit();
}
function check4Value(){
	sErr = '';
	sErr = sErr + isNotNULL('frmSearch','Keywords','\n - Please enter a search value.');
	if (sErr!= '') {
		alert("********* Error ***********" + sErr);
		document.forms["frmSearch"].elements["Keywords"].focus();
		return false;
	} else {
		return true;
	}
}
function check(_1) {
   if(checkflag == "false") {
      if(_1) {
         if(_1.length) {
            for(i = 0; i < _1.length; i++) {
               _1[i].checked = true;
               }
            checkflag = "true";
            }
         else {
            _1.checked = true;
            checkflag = "true";
            }
         }
      return "Uncheck All";
      }
   else {
      if(_1) {
         if(_1.length) {
            for(i = 0; i < _1.length; i++) {
               _1[i].checked = false;
               checkflag = "false";
               }
            }
         else {
            _1.checked = false;
            checkflag = "false";
            }
         }
      return "Check All";
      }
   }
function checkAll(_2) {
   if(_2) {
      if(_2.length) {
         for(i = 0; i < _2.length; i++) {
            _2[i].checked = true;
            }
         }
      else {
         _2.checked = true;
         }
      }
   }
function uncheckAll(_3) {
   if(_3) {
      if(_3.length) {
         for(i = 0; i < _3.length; i++) {
            _3[i].checked = false;
            }
         }
      else {
         _3.checked = false;
         }
      }
   }
function getElementReference(_6) {
   var _7 = false;
   if(document.ids) {
      _7 = document.ids[_6];
      }
   else {
      if(document.layers) {
         _7 = document.layers[_6];
         }
      else {
         if(document.all) {
            _7 = document.all[_6];
            }
         else {
            if(document.getElementById) {
               _7 = document.getElementById(_6);
               }
            }
         }
      }
   return _7;
   }
function getStyleReference(_8) {
   var _9 = false;
   if(getElementReference(_8)) {
      _9 = getElementReference(_8);
      if(!document.layers) {
         _9 = _9.style;
         }
      }
   return _9;
   }
function toggle(_a) {
	$(_a).toggle();
   //$(_b).addClass("ArrowDown");
   //objArrow.className = ("ArrowDown" == objArrow.className ? "ArrowSide" : "ArrowDown");
   }
function utilBox(FA, w, h) {
   self.focus();
   var h, w;
   var _11 = 0;
   if(!w) {
      w = document.documentElement.clientWidth - 100;
      }
   if(!h) {
      h = document.documentElement.clientHeight - 100;
      }
   GB_showCenter("", FA, h, w);
   }

/* Forum functions */
function ftgetpermission(_15) {
   return window.confirm(_15);
   }
function winopen(url, _17, x, y) {
   var _1a = "toolbar=no,scrollbars=yes,resizable=yes,width=" + x + ",height=" + y;
   msgWindow = window.open(url, _17, _1a);
   }
function verifyemail() {
   if(document.profileform.FTVAR_EMAILADDRESSFRM.value != document.profileform.FTVAR_EMAILADDRESSVERFRM.value) {
      alert("Sorry your e-mail addresses do not match, please make sure both e-mail addresses match for verification \n");
      return false;
      }
   return true;
   }
function getPerm(_1d, loc) {
   if(window.confirm(_1d)) {
      location.href = loc;
      }
   else {
      return false;
      }
   }
function selectall(_1f, _20, _21, el) {
   if(_20.value == "true") {
      var _23 = false;
      _20.value = "false";
      _21.value = "Select All";
      }
   else {
      var _24 = true;
      _20.value = "true";
      _21.value = "Clear All";
      }
   for(var i = 0; i < el.elements.length; i++) {
      var e = el.elements[i];
      if(e.name == _1f) {
         e.checked = _24;
         }
      }
   }
/* //end Forum functions */

/* Feedback functions */
var sMax;
var preSet = [];
function rating(num) {
   sMax = 0;
   for(n = 0; n < num.parentNode.childNodes.length; n++) {
      if(num.parentNode.childNodes[n].nodeName == "IMG") {
         sMax++;
         }
      }
   sp = num.id.split("-");
   s = sp[1];
   r = sp[0];
   for(i = 1; i <= sMax; i++) {
      document.getElementById(r + "-" + i).className = (i <= s ? "rateOn" : "rateOff");
      }
   }
function off(me) {
   r = me.id.split("-")[0];
   if(!preSet[r]) {
      for(i = 1; i <= sMax; i++) {
         document.getElementById(r + "-" + i).className = "rateOff";
         }
      }
   else {
      rating(preSet[r]);
      }
   }
function rateIt(me) {
   t = me.id.split("-")[0];
   preSet[t] = me;
   sendRate(me);
   rating(me);
   }
function sendRate(sel) {
   spa = sel.id.split("-");
   tt = spa[0];
   ttt = spa[1] + "/10";
   ttc = tt + "r";
   document.getElementById(tt).innerHTML = ttt;
   document.getElementById(ttc).value = spa[1];
   }
/* //end Feedback functions */

/* JS clock */
var dN=new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
var mN=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
function dE(x){ if(x==1||x==21||x==31){ return 'st'; } if(x==2||x==22){ return 'nd'; } if(x==3||x==23){ return 'rd'; } return 'th'; } 
function lZ(x){ return (x>9)?x:'0'+x; } 
function MakeArrayday(size)
{
  this.length = size;
  for(var i = 1; i <= size; i++)
    this[i] = "";
  return this;
}
function MakeArraymonth(size)
{
  this.length = size;
  for(var i = 1; i <= size; i++)
    this[i] = "";
  return this;
}
function twoDigit(_v)
{
  if(_v<10)_v="0"+_v;
  return _v;
}
function dE(x){ if(x==1||x==21||x==31){ return 'st'; } if(x==2||x==22){ return 'nd'; } if(x==3||x==23){ return 'rd'; } return 'th'; } 
function work()
{
  if (!document.layers && !document.all && !document.getElementById) return;
  var runTime = new Date();
  var dn = "AM";
  var shours = hours;
  var sminutes = minutes;
  var sseconds = seconds;
  if (shours >= 12)
  {
    dn = "PM";
    shours-=12;
  }
  if (!shours) shours = 12;
  sminutes=twoDigit(sminutes);
  sseconds=twoDigit(sseconds);
  movingtime = "NA Time: " + dN[day] + " " + mN[months] + " " + days + "" + dE(days) + ", " + years + " - " + shours + ":" + sminutes +":"+sseconds+"" + dn + " (EDT/GMT-4)";
  if (document.getElementById){
    if(document.getElementById("clock")){
	    document.getElementById("clock").innerHTML=movingtime;
	}
  } else if (document.layers) {
    if(document.layers.clock) {
	    document.layers.clock.document.open();
	    document.layers.clock.document.write(movingtime);
	    document.layers.clock.document.close();
	}
  }  else if (document.all) {
  	if(clock) {
	    clock.innerHTML = movingtime;
	}
  }
  if(++seconds>59)
  {
    seconds=0;
    if(++minutes>59)
    {
      minutes=0;
      if(++hours>23)
      {
        hours=0;
      }
    }
  }
}
/* //end JS clock */