// ###########################################
// Master Script for XANCASTLE (ajax version)
// Programming and Concept by CyberKnightXan
// Copyright (c) 2008,2009, 2010 by Xan Software
// All rights reserved.
// Script Version Date: July 19 2010
// PLEASE DO NOT MODIFY THIS SCRIPT
// Licensed to www.gamersmafia.us
// ###########################################
// FUNCTIONS USED IN MASTER_XC.JS
//
// 
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// autocenter_mm(x)
// ----------------
// Centers the labels in any navigation menu bar. x is the index.
//
// load_navbar() 
// ------------
// Calls autocenter_mm(x) the number of times equal to the index
// of any particular menubar to create a custom auto-centered navbar.
// These navigation bars are used in each of the different portals.
//
//
// showhide(objectID)
// ------------------
// Show and hide the objectID we give it to give the appearance of a page
// loading instantly. Used for showing and hiding DIVs on the website.
//
// load_skin(x)
// -------------
// Set a skin type to be loaded into the Xan Castle interface. It will be loaded as
// a fixed background image on the loaded page. The skin loaded is determined by
// the value passed in the variable skin_type.
//
// load_portal(x)
// --------------
// Set up a portal link image to stay highlighted depending on the number passed to the function.
//
//
// cr_footer()
// -----------
// Show the copyright info in the footer and visitor counter.
//
// set_title(x)
// ---------------
// Changes the title of the current webpage.
//
// generate_page(x)
// ----------------
// Dynamically creates a new page inside the XANCASTLE interface. 
//
// ajax engine functions:
// ----------------------
// These two functions are used to dynamically include content on the page
// without reloading it. Thus, this is using AJAX. Not External Domain.
//
// GetContent(url,id)
// PublishContent(content,id)
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


// GLOBAL VARIABLES FOR MENU BAR (ajax version)

var navbarlabel=new Array(9);  // Allocate Memory for 8 labels (user defined in navbar.js)
var navbarlink=new Array(9);   // Allocate Memory for 8 URL links (user defined in navbar.js)
// var urltargetwin=new Array(8); // _blank, _parent, _self, _top, or window name (user defined in navbar.js)
                                  // In Ajax version targetwin is actually div id so its not needed here.

                               // image as 'blank' to compensate for firefox browser rendering bug.
var BLANK = "<img src='./Library/Hosted/System/Navbar/headbg.png' width='16px' height='15px' align='texttop'>";
//var BLANK = "&nbsp;&nbsp;";

var separator ="&#124;";       // separator is a vertical bar that defines where the labels start and stop. Its put right before each label.
var labelcount = 9;            // Max number of labels in a navbar
var firstind = 0;              // The first index number of the label in a navbar
var lastind = labelcount-1;    // The last index number of the label in a navbar

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


function navbarwidth(x){
// Determine Navbar width by number of labels

var lc = eval(x)               // The Number of Labels in our Navivigation Bar.
var nblw = 87;                 // 87 Pixels is the length of each label area by default
var navbarlength = (lc*nblw);  // Calculate the Navbar Length in Pixels.


document.write(navbarlength);  // Write out the result.
}

function autocenter_mm(x){

// The function autocenter_mm creates one centered menu label. It is called 
// repeatedly to build a dynamic menubar evenly spaced depending on the
// number of characters in the label itself. In the event of a label having
// an uneven amount of spaces, a math function is performed to determine
// the correct amount to add on each side of the menu label.

// When calling this function, x is the index (a number)

var nblanks="";         // nblanks starts off with nothing in it. The string of blanks before and after the label.
var mbs;                // max number of blank spaces to appear in label
var mxc = 16;           // mxc is the maximum number of characters allowed between the separators including the space fillers on each side.
var ncl;                // ncl is number of non-filler space characters in a label (default is 16 after truncation and filler)
var lindx = eval(x);    // lindx is the label index number we are working with
var mxstr = 16;         // mxstr is the maximum number of characters allowed in a label not including space fillers on each side (Default is 16)
var leftside;           // The number of spaces to fill in on the left side of a label.
var rightside;          // The number of spaces to fill in on the right side of a label.
var leftover;           // The number assigned to mbs after a modulo divide by 2. Used to see if a number is odd or even.     

// Define a blank depending on the screen resolution.
/*
if (screen.width == 1024)
BLANK = "<img src='./Library/Hosted/System/Navbar/headbg.png' width='12px' height='15px' align='texttop'>";
if (screen.width == 1280)
BLANK = "<img src='./Library/Hosted/System/Navbar/headbg.png' width='16px' height='15px' align='texttop'>";
*/



// This truncates the current length of the label string to no more than the value mxc above.
// Changing the number in mxc can give you more menus on the menu bar or longer labels.
// My personal preference is 7 menus at a maximum 15 characters each with a one space filler
// at both ends of every label by default. It can be any amount of labels and any amount of
// characters per label, it's up to the user.

navbarlabel[lindx] = navbarlabel[lindx].substring(0,mxstr);            // truncate label to max string length (default 16)

ncl = navbarlabel[lindx].length;                                       // ncl is the truncated label length
mbs = mxc - ncl;                                                       // mbs is the maximum number of characters with spaces allowed
                                                                       // minus the truncated label length
/*
leftover = mbs % 2;                          				           // Assign leftover to mbs modulo 2 (the remainder of a divide by 2)
	if (leftover == 0){                          			           // Check if mbs is an even number
   		leftside = mbs / 2;						 			           // Calculate the number of spaces needed on the left side of a label.	
        rightside = leftside;				 			               // Calculate the number of spaces needed on the left side of a label.

	}
	else {                    
   		leftside  = mbs / 2;					 			           // Calculate the number of spaces needed on the left side of a label.
	    rightside =  leftside -1;							           // Calculate the number of spaces needed on the right side of a label.
	}
*/
rightside = 2;
leftside = 2;
// This section builds one single label and link on the menubar.

// 

// ================================================================================================  
		document.write(separator);							           // Draw a seperator.
		
		for(var b = 0;b<leftside;b++){						           // Calculate the number of blanks to display
    		nblanks = nblanks+BLANK;                                   //  as a filler on the left side of the label.
		}
		document.write(nblanks);							           // Dynamically write the blanks.
		nblanks="";											           // Reset the blanks variable called nblanks.
  
document.write('<a href="');
document.write(navbarlink[lindx]);
document.write('" class=gseyebrow>');				                   // Choose the eyebrow class from the CSS to light up the menubar label.
document.write(navbarlabel[lindx]);					                   // Write the navbar label chosen by the user.
document.write('</a>');

		for(var b = 0;b<rightside;b++){						           // Calculate the number of blanks to display as a filler on the right side of the label.
   		 	nblanks = nblanks+BLANK;
		}
		document.write(nblanks);							           // Dynamically write the blanks.
		nblanks="";											           // Reset the number of blanks variable called nblanks.											

 if (lindx == lastind) document.write(separator);		           // If we are on the last index draw an extra seperator.
}
// ================================================================================================




// BUILD THE EXPANDABLE NAVBAR AND LOAD IT

function load_navbar(){	
      document.write('<table width="');
	navbarwidth(9);
	document.write('px" border=0 cellpadding=0 cellspacing=0 bgcolor=#222222>'); 
	document.write('<tr valign="top"><td  width="');
      navbarwidth(9);
      document.write('px" height="15" background=./Library/Hosted/System/Navbar/headbg.png border="0" class=gsgrey10><nobr>');
	document.write('<img src="./Library/Hosted/System/Navbar/headlt.png" border="0" width="16" height="15"');
	document.write(' align="texttop">');
		for(var index = 0;index<labelcount;index++){autocenter_mm(index);}
	document.write('<img src="./Library/Hosted/System/Navbar/headrt.png" border="0" width="16" height="15"');
	document.write(' align="texttop">');
	document.write('</td></tr></table>'); 
}



// SET TITLE
// =================================
// Purpose:
// Use a switch to determine which set of code to execute to load up
// a webpage dynamically using XANCASTLE.
// =================================
// Titles of our webpages, and their ID's:
// 0 = GamersMafia.us Index
// 1 = GamersMafia.us Support
// 2 = GamersMafia.us General
// 3 = GamersMafia.us News
// 4 = GamersMafia.us Entertainment
// 5 = GamersMafia.us Gaming
// 6 = GamersMafia.us Creativity
// 7 = GamersMafia.us Technology
// 8 = GamersMafia.us Famous Last Words Shout Board
// =================================
function set_title(x){
var page_id = eval(x);    // The variable title_id tells us which page to choose depending on the number passed to us.
var title_str='';         // Set up a null string to initialize TITLE code string.
var code_str ='';         // Set up a nulll string to initalize HTML code string.
var page_data_url ='';    // Set up a null string to initialize page data URL string.

	switch(page_id){
		default:
		case 0:
			title_str = "GamersMafia.us Index";
		break;
		case 1:
			title_str = "GamersMafia.us Support";
		break;
		case 2:
			title_str = "GamersMafia.us General";
		break;
		case 3:
			title_str = "GamersMafia.us News";
		break;
		case 4:
			title_str = "GamersMafia.us Entertainment";			
		break;
		case 5:
			title_str = "GamersMafia.us Gaming";		
		break;
		case 6:
			title_str = "GamersMafia.us Creativity";		
		break;
		case 7:
		    title_str = "GamersMafia.us Technology"
		break;
		case 8:
		    title_str = "GamersMafia.us Famous Last Words Shout Board"
		break;    
	 }
// GENERATE CODE FOR PAGE TITLE	 
 document.title = title_str;
}


// LOAD PORTAL
// =================================
// Purpose:
// Use a switch to determine which set of code to execute to load up
// an image highlighted depending on the portal title. 
// Currently 9 Portals to choose from, 0 thru 9.
// =================================
// Titles of our webpages, and their ID's:
// 0 = Index
// 1 = Support
// 2 = General
// 3 = News
// 4 = Entertainment
// 5 = Gaming
// 6 = Creativity
// 7 = Technology
// 8 = Famous Last Words Shout Board
// =================================
function load_portal(x){

var code_str ='';         // Set up a nulll string to initalize HTML code string.
var image_id = eval(x);

	switch(image_id){
		default:
		case 0:
			   code_str = '<img class="Event_Banners" src="./Library/Hosted/Images/hitman.jpg" alt="Index"/>';
		break;
		case 1:
                code_str = '<img class="Event_Banners" src="./Library/Hosted/Images/support.jpg" alt="Support"/>';
		break;
		case 2:
	            code_str = '<img class="Event_Banners" src="./Library/Hosted/Images/general.jpg" alt="General"/>'; 	
		break;
		case 3:
			    code_str = '<img class="Event_Banners" src="./Library/Hosted/Images/news.jpg" alt="News"/>';
		break;
		case 4:
				code_str = '<img class="Event_Banners" src="./Library/Hosted/Images/entertainment.jpg" alt="Entertainment"/>';			
		break;
		case 5:
				code_str = '<img class="Event_Banners" src="./Library/Hosted/Images/gaming.jpg" alt="Gaming"/>';	
		break;
		case 6:	
				code_str = '<img class="Event_Banners" src="./Library/Hosted/Images/creativity.gif" alt="Creativity"/>';
		break;
		case 7:	
				code_str = '<img class="Event_Banners" src="./Library/Hosted/Images/technology.jpg" alt="Technology"/>';
        break;
        case 8:	
				code_str = '<img class="Event_Banners" src="./Library/Hosted/Images/flw_logo.jpg" alt="Famous Last Words"/>';
        break;

	 }	 
	 
// GENERATE CODE FOR PORTAL IMAGE	 
 document.write(code_str);
}



// LOAD A SKIN FROM THE SKIN IMAGE LIBRARY
// =================================
// Purpose:
// Use a switch to determine which skin to display.
// =================================
// 0 = Skin type is GM Splash
// 1 = Skin type is GM Index
// 2 = Skin type is GM Support
// 3 = Skin type is GM General
// 4 = Skin type is GM News
// 5 = Skin type is GM Entertainment
// 6 = Skin type is GM Gaming
// 7 = Skin type is GM Creativity
// 8 = Skin type is GM Technology
// =================================


function load_skin(x){
var skin_type = eval(x);    // The variable skin_type tells us which skin to choose depending on the number passed to us.
var str='';                // Set up a null string to initialize.

switch(skin_type){
case 0:
default:
str+='    		<table summary="The current skin used">';
str+='      			<tr>';
str+='        			<td>';
str+='        				<img class="Screen" src=".\/Library\/Hosted\/System\/Interface\/Skins\/skin_splash.png" ';
str+='        					  alt="Gamers Mafia Welcome with Click - Copyright (c) 2008 Xan Software." \/>';
str+='        			<\/td>';
str+='      			<\/tr>';
str+='    		<\/table>';
break;
case 1:
str+='    		<table summary="The current skin used">';
str+='      			<tr>';
str+='        			<td>';
str+='        				<img class="Screen" src="./Library\/Hosted\/System\/Interface\/Skins\/skin_index.png" ';
str+='        					  alt="Gamers Mafia Forum Index - Copyright (c) 2009 Xan Software." \/>';
str+='        			<\/td>';
str+='      			<\/tr>';
str+='    		<\/table>';
break;
case 2:
str+='    		<table summary="The current skin used">';
str+='      			<tr>';
str+='        			<td>';
str+='        				<img class="Screen" src="./Library\/Hosted\/System\/Interface\/Skins\/skin_support.png" ';
str+='        					  alt="Gamers Mafia Support Forum - Copyright (c) 2009 Xan Software." \/>';
str+='        			<\/td>';
str+='      			<\/tr>';
str+='    		<\/table>';
break;
case 3:
str+='    		<table summary="The current skin used">';
str+='      			<tr>';
str+='        			<td>';
str+='        				<img class="Screen" src="./Library\/Hosted\/System\/Interface\/Skins\/skin_general.png" ';
str+='        					  alt="Gamers Mafia General Forum - Copyright (c) 2009 Xan Software." \/>';
str+='        			<\/td>';
str+='      			<\/tr>';
str+='    		<\/table>';
break;
case 4:
str+='    		<table summary="The current skin used">';
str+='      			<tr>';
str+='        			<td>';
str+='        				<img class="Screen" src="./Library\/Hosted\/System\/Interface\/Skins\/skin_news.png" ';
str+='        					  alt="Gamers Mafia News Forum - Copyright (c) 2009 Xan Software." \/>';
str+='        			<\/td>';
str+='      			<\/tr>';
str+='    		<\/table>';
break;
case 5:
str+='    		<table summary="The current skin used">';
str+='      			<tr>';
str+='        			<td>';
str+='        				<img class="Screen" src="./Library\/Hosted\/System\/Interface\/Skins\/skin_entertainment.png" ';
str+='        					  alt="Gamers Mafia Entertainment Forum - Copyright (c) 2009 Xan Software." \/>';
str+='        			<\/td>';
str+='      			<\/tr>';
str+='    		<\/table>';
break;
case 6:
str+='    		<table summary="The current skin used">';
str+='      			<tr>';
str+='        			<td>';
str+='        				<img class="Screen" src="./Library\/Hosted\/System\/Interface\/Skins\/skin_gaming.png" ';
str+='        					  alt="Gamers Mafia Entertainment Forum - Copyright (c) 2009 Xan Software." \/>';
str+='        			<\/td>';
str+='      			<\/tr>';
str+='    		<\/table>';
break;
case 7:
str+='    		<table summary="The current skin used">';
str+='      			<tr>';
str+='        			<td>';
str+='        				<img class="Screen" src="./Library\/Hosted\/System\/Interface\/Skins\/skin_creativity.png" ';
str+='        					  alt="Gamers Mafia Creativity Forum - Copyright (c) 2009 Xan Software." \/>';
str+='        			<\/td>';
str+='      			<\/tr>';
str+='    		<\/table>';
break;
case 8:
str+='    		<table summary="The current skin used">';
str+='      			<tr>';
str+='        			<td>';
str+='        				<img class="Screen" src="./Library\/Hosted\/System\/Interface\/Skins\/skin_technology.png" ';
str+='        					  alt="Gamers Mafia Technology Forum - Copyright (c) 2009 Xan Software." \/>';
str+='        			<\/td>';
str+='      			<\/tr>';
str+='    		<\/table>';
break;
case 9:
str+='    		<table summary="The current skin used">';
str+='      			<tr>';
str+='        			<td>';
str+='        				<img class="Screen" src="./Library\/Hosted\/System\/Interface\/Skins\/skin_black.png" ';
str+='        					  alt="Gamers Mafia Famous Last Words Shoutboard - Copyright (c) 2009 Xan Software." \/>';
str+='        			<\/td>';
str+='      			<\/tr>';
str+='    		<\/table>';
break;

}
// Fall through and display selected skin type.
document.write(str);
}


// COPYRIGHT FOOTER INFO
function cr_footer(){
var str='';
str+='          <br \/>';
str+='<p>';
str+='   <a href="http://validator.w3.org/check?uri=http%3A%2F%2Fwww.gamersmafia.us%2F"><img';
str+='      src="http://www.w3.org/Icons/valid-xhtml10"';
str+='      alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>';
str+='</p>';
document.write(str);
}


function advertisement(){
var str='';
str+=' <br \/>';
str+='<p>';
str+='<a href="http://www.jdoqocy.com/i5116efolfn26AAB473243843884" target="_blank" onmouseover="window.status=\'http://us.bigpoint.com/?aid=1438&aig=25&aip=3778140_10510551_\';return true;" onmouseout="window.status=\' \';return true;">
<img src="http://www.awltovhc.com/fd66g04tzxIMQQRKNJIKJOKJOOK" alt="DarkOrbit Advertisement" border="1"/></a>';
str+='</p>';
document.write(str);
}


// SHOW AND HIDE DIVS

function showhide(objectID) {
var object = document.getElementById(objectID);
state = object.style.visibility;
if(state == 'hidden')
object.style.visibility = 'visible';
else{
if(state == 'visible')
object.style.visibility = 'hidden';
else object.style.visibility = 'visible';
}
}

//Ajax Engine (custom ajax added to library)

function GetContent(url,id) {
var httpRequest;
if (window.XMLHttpRequest) {
   try { httpRequest = new XMLHttpRequest(); }
   catch(e) {}
   } 
else if (window.ActiveXObject) {
   try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } 
      catch(e) {}
      }
   }
if(! httpRequest) {
   alert('\n\nSorry, unable to open a connection to the server.');
   return false;
   }
httpRequest.onreadystatechange = function() { PublishContent(httpRequest,id); };
httpRequest.open('GET',url,true);
httpRequest.send('');
}

function PublishContent(content,id) {
try {
   if (content.readyState == 4) {
      if(content.status == 200) { document.getElementById(id).innerHTML=content.responseText; }
      else { alert('\n\nContent request error, status code:\n'+content.status+' '+content.statusText); }
      }
   }
catch(error) { alert('Error: '+error.name+' -- '+error.message); }
}
