// JavaScript Document

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function openCenteredWindow(url, height, width, name, parms) {
   var left = Math.floor( (screen.width - width) / 2);
   var top = Math.floor( ((screen.height-35) - height) / 2);
   if (top < 0) top = 0
   var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
   if (parms) { winParms += "," + parms; }
   var win = window.open(url, name, winParms);
   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
   return win;
}

function launchuserinfo(userID,urltoken){
	var attributes = "toolbar=no,scrollbars=auto,resizable=yes,width=300,height=450,left=100,top=100";
	msgWindow=window.open("http://www.mmorpg.com/userinfo.cfm?" + urltoken + "&userID=" + userID,"UserInformation",attributes);
	}

function showScreen(width,height,id,gameID,type)
{
	if(!type){
		type = 1;
	}
	openCenteredWindow('/view_screenshot.cfm?gameID=' + gameID + '&screenID=' + id + '&type=' + type,height+50,width+8,'screenView','');
}

function showScreen2(id,gameId,type,mode){
	if(!type){
		type = 1;
	}
	if(!mode){
		mode = 1;
	}
	openCenteredWindow('/dsp/dspScreenViewer.cfm?gameId=' + gameId + '&screenId=' + id + '&type=' + type + '&mode=' + mode,625,801,'screenViewer','');
}

function viewImage(width,height,file)
{	
	var sWidth, sHeight;
	var aWidth	= screen.width - 8;
	var aHeight	= screen.height - 50;	
	var scroll	= 'no';
	
	// if the width or height exceeds the users screen dimensions alter it
	sWidth	= width;
	sHeight	= height;
	
	if(aWidth < width){
		sWidth	= aWidth;
		scroll	= 'yes';
	}
	
	if(aHeight < height){
		sHeight	= aHeight;
		scroll	= 'yes';
	}	
	
	openCenteredWindow('http://www.mmorpg.com/view_screenshot.cfm?file=' + file,sHeight+50,sWidth+8,'imageView','scrollbars='+scroll);
	return;
}
function testCookies() { 
 var exp = new Date(); 
 exp.setTime(exp.getTime() + 1800000); 
 // first write a test cookie 
 setCookie("cookies", "cookies", exp, false, false, false); 
 if (document.cookie.indexOf('cookies') != -1) { 
  found = false;
 } 
 else { 
    found = true;
 } 
 // now delete the test cookie 
  exp = new Date(); 
  exp.setTime(exp.getTime() - 1800000); 
  setCookie("cookies", "cookies", exp, false, false, false); 
  return found;
 }

function setCookie(name, value, expires, path, domain, secure) { 
 var curCookie = name + "=" + escape(value) + 
    ((expires) ? "; expires=" + expires.toGMTString() : "") + 
    ((path) ? "; path=" + path : "") + 
    ((domain) ? "; domain=" + domain : "") + 
    ((secure) ? "; secure" : ""); 
 document.cookie = curCookie; }
 
 function everyPage()
 {
 	if (testCookies())
		if (!cookieBypass)document.location = '/errors/nocookies.cfm';
 }
 function showPrivacy()
{
	openCenteredWindow('http://www.mmorpg.com/privacy.cfm',500,400,'privacy','toolbar=true,scrollbars=yes,resizable=yes');
}
function showCopyright()
{
	openCenteredWindow('http://www.mmorpg.com/copyright.cfm',270,400,'copyright','toolbar=false,scrollbars=no,resizable=yes');
}
function showRules()
{
	openCenteredWindow('http://www.mmorpg.com/rules.cfm',500,400,'rules','toolbar=false,scrollbars=yes,resizable=yes');
}
function lostpw()
{
	var attributes = "toolbar=no,scrollbars=no,resizable=no,titlebar=no,status=no,menubar=no,directories=no";
	openCenteredWindow("http://www.mmorpg.com/lostpw.cfm?firstload=true",250,350,"lostpw",attributes);
}

//****** Retrieve a reference to an object in the document
//
function getObj(objID)
{
    if(document.getElementById){
        return document.getElementById(objID);
    } else if (document.all){
        return document.all[objID];
    } else if (document.layers){
        return document.layers[objID];
    }
}

//******
// Retrieve a reference to an object in the parent's dom
function getParentObj(objID){
    if(document.getElementById){
        return parent.document.getElementById(objID);
    } else if (document.all){
        return parent.document.all[objID];
    } else if (document.layers){
        return parent.document.layers[objID];
    }   
}

//******
// Get a page elements X
function DL_GetElementLeft(eElement)
{
	if (!eElement && this)                       // if argument is invalid
	{                                            // (not specified, is null or is 0)
		eElement = this;                         // and function is a method
	}                                            // identify the element as the method owner
	
	var nLeftPos = eElement.offsetLeft;          // initialize var to store calculations
	var eParElement = eElement.offsetParent;     // identify first offset parent element  
	while (eParElement != null)
	{                                            // move up through element hierarchy
		nLeftPos += eParElement.offsetLeft;      // appending left offset of each parent
		eParElement = eParElement.offsetParent;  // until no more offset parents exist
	}
	return nLeftPos;                             // return the number calculated
}

//******
// Get a page elements Y
function DL_GetElementTop(eElement)
{
	if (!eElement && this)
	{
		eElement = this;
	}

	var nTopPos = eElement.offsetTop;
	var eParElement = eElement.offsetParent;
	while (eParElement != null)
	{
		nTopPos += eParElement.offsetTop;
		eParElement = eParElement.offsetParent;
	}
	return nTopPos;
}

//******
// Show the user post report frame
function showUserPostReport(elem,userId,postId,offsetX,offsetY){	
	var obj	= getObj(elem);
	
	if(!offsetX){
		offsetX	= -100;
	}
	
	if(!offsetY){
		offsetY	= 16;
	}
	
	var x	= (DL_GetElementLeft(obj)+ offsetX) + 'px';
	var y	= (DL_GetElementTop(obj)+ offsetY) + 'px';
	var ws	= getObj('userPostReport');
	var uf	= getObj('userPostReportFrame');											
	
	// hide?							
	if(ws.style.left == x && ws.style.top == y && ws.style.display == ''){								
		ws.style.display	= 'none';
		return;
	}
	
	// set the iframe src to the correct user
	uf.src	= 'dsp/dspUserPostReport.cfm?userId=' + userId + '&postId=' + postId;
	
	// move the div into position
	ws.style.left	= x;
	ws.style.top	= y;					
	ws.style.display	= '';																	
}

//******
// Close user post report
function closeUserPostReport(){
	var ws	= getObj('userPostReport');
	ws.style.display	= 'none';
}

//******
// Show the user actions
function showUserActions(elem,userId,postId,offsetX,offsetY){	
	var obj	= getObj(elem);
	
	if(!offsetX){
		offsetX	= -100;
	}
	
	if(!offsetY){
		offsetY	= 16;
	}
	
	var x	= (DL_GetElementLeft(obj)+ offsetX) + 'px';
	var y	= (DL_GetElementTop(obj)+ offsetY) + 'px';
	var ws	= getObj('userActions');
	var uf	= getObj('userActionFrame');											
	
	// hide?							
	if(ws.style.left == x && ws.style.top == y && ws.style.display == ''){								
		ws.style.display	= 'none';
		return;
	}
	
	// set the iframe src to the correct user
	uf.src	= 'dsp/dspUserActions.cfm?userId=' + userId + '&postId=' + postId;
	
	// move the div into position
	ws.style.left	= x;
	ws.style.top	= y;					
	ws.style.display	= '';																	
}

//******
// Close user actions
function closeUserActions(){
	var ws	= getObj('userActions');
	ws.style.display	= 'none';
}

/***********************************************
* Tabbed Document Viewer script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var selectedtablink=""
var tcischecked=false

function handlelink(aobject){
	selectedtablink=aobject.href
	tcischecked=(document.tabcontrol && document.tabcontrol.tabcheck.checked)? true : false
	if (document.getElementById && !tcischecked){
		var tabobj=document.getElementById("tablist")
		var tabobjlinks=tabobj.getElementsByTagName("A")
		for (i=0; i<tabobjlinks.length; i++)
		tabobjlinks[i].className=""
		aobject.className="current"
		document.getElementById("tabiframe").src=selectedtablink
		return false
	}
	else
		return true
}

function handleview(){
	tcischecked=document.tabcontrol.tabcheck.checked
	if (document.getElementById && tcischecked){
		if (selectedtablink!="")
		window.location=selectedtablink
	}
}



//******
// Game Jump Bar logic
function fillGameSection(){
	var gameId = document.gqjForm.gameId.options[document.gqjForm.gameId.selectedIndex].value;
	var features = false;
	var reviews	= false;
	var hype	= false;
	var	ratings	= false;
	var forum	= 0;
	var arrSectionStyle;
	var sBox	= document.gqjForm.section;
	var	opt;
	var arrStyles	= new Array();			
	
	sBox.options.length = 0;
	
	arrStyles[0] = new Object();
	arrStyles[0].style = 'color';
	arrStyles[0].value = 'white';
	addOption2Select(sBox,'Select Section','',arrStyles);
	
	if(!games[gameId]){				
		return;
	}
	else{
		arrSectionStyle	= games[gameId].sectionStyle.split(',');
		
		if(arrSectionStyle[0] == 1){
			features = true;
		}			
		
		if(arrSectionStyle[1] == 1){
			reviews	= true;
		}
		
		forum = arrSectionStyle[2];
		
		switch(arrSectionStyle[3]){
			case '1':
				hype = true;	
				break;
			case '2':
				hype = true;
				break;
			case '3':
				ratings = true;
				break;
		}
		
		//arrStyles[0].value = 'yellow';
		addOption2Select(sBox,'Overview','overview',arrStyles);
		
		if(reviews){
			addOption2Select(sBox,'Reviews','review',arrStyles);
		}
		
		if(features){
			addOption2Select(sBox,'Features','features',arrStyles);
		}
		
		if(forum > 0){
			addOption2Select(sBox,'Forums','forums',arrStyles);
		}			
		
		addOption2Select(sBox,'Resources','resources',arrStyles);
		//arrStyles[0].value = 'white';
		addOption2Select(sBox,'  Guides','resources',arrStyles);
		addOption2Select(sBox,'  Maps','resources',arrStyles);
		
		//arrStyles[0].value = 'yellow';
		addOption2Select(sBox,'Screenshots','screens',arrStyles);
		
		addOption2Select(sBox,'News','news',arrStyles);
		
		if(hype){
			addOption2Select(sBox,'Hype-Meter','hype',arrStyles);
		}
		
		if(ratings){
			addOption2Select(sBox,'Ratings','ratings',arrStyles);
		}
		
		addOption2Select(sBox,'Links','links',arrStyles);				
		
	}
	
	return;
	
}

function addOption2Select(obj,text,value,arrStyles){
	var opt = new Option(text,value);	
	if(arrStyles){
		for(var i=0;i<arrStyles.length;i++){
			opt.style[arrStyles[i].style] = arrStyles[i].value;
		}
	}
	obj.options[obj.options.length] = opt;
			
	return;		
}

function gqjSubmit(){
	var strLink;
	var gameId	= document.gqjForm.gameId.options[document.gqjForm.gameId.selectedIndex].value;
	var section = document.gqjForm.section.options[document.gqjForm.section.selectedIndex].value;
	var arrSectionStyle;
	
	if(gameId){	
		
		if(section && section != 'forums'){
			strLink = '/gamelist.cfm/gameId/' + gameId + '/setView/' + section;
			
			/*if(section == 'features'){
				strLink += '/loadFeature/0';
			}*/
			
		}
		else if(section && section == 'forums'){
			arrSectionStyle	= games[gameId].sectionStyle.split(',');
			strLink = '/discussion.cfm/load/forums/loadClass/' + arrSectionStyle[2];
		}
		else{
			strLink = '/gamelist.cfm/gameId/' + gameId;
		}
		
		location.href = strLink;				
		
	}	
}

//*****
// Create the mailTo for an email href
function writeEmailAddress(obj,user,domain,args){
	var rVal = user + '@' + domain;
	rVal += args != '' ? '?' + args : '';
	
	obj.href	= 'mailTo:' + rVal;
}

//*****
// Change the className of an obj
function changeClass(obj,newClass){
	obj.className	= newClass;
}


//******
// Switch an objects vis
function switchVis(elem){
	var obj	= getObj(elem);		
	
	if(obj.style.display == 'none'){
		obj.style.display = '';
	}
	else{
		obj.style.display = 'none';
	}
}

//******
// Switch an elements text
function switchText(elem,str1,str2){
	var obj	= getObj(elem);
	
	if(obj.innerHTML == str1){
		obj.innerHTML	= str2;	
	}
	else{
		obj.innerHTML	= str1;
	}
}

//******
// Do Nothing
function doNothing(){
	
}





