// ###########################################
// Master Script for XANCASTLE
// Programming and Concept by CyberKnightXan
// Copyright (c) 1999-2010 by Xan Software
// All rights reserved.
// Script Version Date: December 30 2009
// PLEASE DO NOT MODIFY THIS SCRIPT
// ###########################################
// 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.
//
// donate()
// --------
// This is the donation button that appears at the center of the XanQuest.com page.
//
// 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

var navbarlabel=new Array(7);  // Allocate Memory for 7 labels (user defined in navbar.js)
var navbarlink=new Array(7);   // Allocate Memory for 7 URL links (user defined in navbar.js)
var urltargetwin=new Array(7); // _blank, _parent, _self, _top, or window name (user defined in navbar.js)

                               // image as 'blank' to compensate for firefox browser rendering bug.
var BLANK = "<img src='http://www.xansoftware.com.us/XanCastle/Library/Hosted/System/Navbar/headbg.png' width='12px' height='15px' align='texttop'>";

var separator ="&#124;";       // separator is a vertical bar that defines where the labels start and stop. Its put right before each label.
var labelcount = 7;            // 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 autocenter_mm(x){

// 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='http://www.xansoftware.com/Library/Hosted/System/Navbar/headbg.png' width='12px' height='15px' align='texttop'>";
if (screen.width == 1280)
BLANK = "<img src='http://www.xansoftware.com/Library/Hosted/System/Navbar/headbg.png' width='28px' 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.

navbarlabel[lindx] = navbarlabel[lindx].substring(0,mxstr); // truncate label to max string length (default 20)

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.
	}

// Create link and label using dynamic conditional statements
// ARE WE ON THE LAST INDEX?

	if (lindx == lastind){									
	// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
	// If yes... (YES, WE ARE ON THE LAST INDEX)
	// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
	
		document.write(separator);							// Draw a seperator.
		for(var b = 0;b<leftside;b++){						// Calculate the number of blanks to display as a filler on the left side of the label.
    		nblanks = nblanks+BLANK;
		}
		document.write(nblanks);							// Dynamically write the blanks.
		nblanks="";											// Reset the number of blanks variable called nblanks.
		document.write('<a target="');						// Create the target window that was chosen by the user.
		document.write(urltargetwin[lindx]);
		document.write('" href="');
		document.write(navbarlink[lindx]);					// Create the URL that was chosen by the user.
		document.write('" class=gseyebrow>');				// Choose the eyebrow class from the CSS.
		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.
		document.write(separator);							// Draw a seperator and exit this IF statement.
	}
	else{
	// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ 
	//If no... (NO, WE HAVE NOT REACHED THE LAST INDEX YET)
	// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
	
		document.write(separator);							// Draw a seperator.							
		for(var b = 0;b<leftside;b++){						// Calculate the number of blanks to display as a filler on the left side of the label.
    		nblanks = nblanks+BLANK;
		}
		document.write(nblanks);							// Dynamically write the blanks.
		nblanks="";											// Reset the number of blanks variable called nblanks.
		document.write('<a target="');						// Create the target window that was chosen by the user.
		document.write(urltargetwin[lindx]);
		document.write('" href="');
		document.write(navbarlink[lindx]);					// Create the URL that was chosen by the user. 
		document.write('" class=gseyebrow>');				// Choose the eyebrow class from the CSS.
		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.											
	}
}


// BUILD THE EXPANDABLE NAVBAR AND LOAD IT

function load_navbar(){
	
switch(screen.width){
case 1024:
	document.write('<table width="960px" border=0 cellpadding=0 cellspacing=0 bgcolor=#222222>'); 
	document.write('<tr valign="top"><td  width="980px" height="15" background=http://www.xansoftware.com/Library/Hosted/System/Navbar/headbg.png border="0" class=gsgrey10><nobr>');
	document.write('<img src="http://www.xansoftware.com/Library/Hosted/System/Navbar/headlt.png" border="0" width="10" height="15"');
	document.write(' align="texttop">');
		for(var index = 0;index<labelcount;index++){autocenter_mm(index);}
	document.write('<img src="http://www.xansoftware.com/Library/Hosted/System/Navbar/headrt.png" border="0" width="10" height="15"');
	document.write(' align="texttop">');
	document.write('</td></tr></table>'); 
	break;
case 1280:
	document.write('<table width="1000px" border=0 cellpadding=0 cellspacing=0 bgcolor=#222222>'); 
	document.write('<tr valign="top"><td  width="1210px" height="15" background=http://www.xansoftware.com/Library/Hosted/System/Navbar/headbg.png border="0" class=gsgrey10><nobr>');
	document.write('<img src="http://www.xansoftware.com/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="http://www.xansoftware.com/Library/Hosted/System/Navbar/headrt.png" border="0" width="16" height="15"');
	document.write(' align="texttop">');
	document.write('</td></tr></table>');
	break;
case 1152:
default:
	document.write('<table width="980px" border=0 cellpadding=0 cellspacing=0 bgcolor=#222222>'); 
	document.write('<tr valign="top"><td  width="1012px" height="15" background=http://www.xansoftware.com/Library/Hosted/System/Navbar/headbg.png border="0" class=gsgrey10><nobr>');
	document.write('<img src="http://www.xansoftware.com/Library/Hosted/System/Navbar/headlt.png" border="0" width="12" height="15"');
	document.write(' align="texttop">');
		for(var index = 0;index<labelcount;index++){autocenter_mm(index);}
	document.write('<img src="http://www.xansoftware.com/Library/Hosted/System/Navbar/headrt.png" border="0" width="12" height="15"');
	document.write(' align="texttop">');
	document.write('</td></tr></table>');
	break;
 }
}

// INSERT SPACE
// ======================================
// Purpose:
// Use in the situation where you need to insert more than just a few spaces into HTML code.
// Pass the number of spaces to the functions and generate a string of blank spaces.
// The entire function becomes the string.
// ======================================
function insert_space(x){
var num_spaces = eval(x);
var nspaces ='';      // nspaces is blank.
var space ='!';  // space is a non-breakable html space character.

for(var index_count = 0;index_count<num_spaces;index_count++){	// Calculate the number of blanks to insert.
    		nspaces = nspaces+space;                            // Keep adding another space until loop is done.
		} 
document.write(nspaces);
}

// 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 = Welcome to Xan Software
// 1 = Cyber Knights
// 2 = Software
// 3 = Resources
// 4 = XanCastle
// 5 = Links
// 6 = XanQuest.com
// =================================
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 = "Welcome to Xan Software";
		break;
		case 1:
			title_str = "Cyber Knights";
		break;
		case 2:
			title_str = "Software";
		break;
		case 3:
			title_str = "Resources";
		break;
		case 4:
			title_str = "XanCastle";			
		break;
		case 5:
			title_str = "Links";		
		break;
		case 6:
			title_str = "XanQuest.com";		
		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.
// =================================
// Titles of our webpages, and their ID's:
// 0 = Welcome to Xan Software
// 1 = Cyber Knights
// 2 = Software
// 3 = Resources
// 4 = XanCastle
// 5 = Links
// 6 = XanQuest.com
// =================================
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="http://www.xansoftware.com/Library/Hosted/System/Interface/Skins/skin_aurora_logo.png" alt="Multi-Color Logo"/>';
		break;
		case 1:
                code_str = '<img class="Event_Banners" src="http://www.xansoftware.com/Library/Hosted/System/Interface/Skins/skin_aurora_logo_red.png" alt="Red Logo"/>';
		break;
		case 2:
		//    	code_str = '<img class="Event_Banners" src="http://www.xansoftware.com/Library/Hosted/System/Interface/Skins/skin_aurora_logo_blu.png" alt="Blue Logo"/>';
	            code_str = '<img class="Event_Banners" src="http://www.xansoftware.com/Library/Hosted/Images/Icons/mazerworld_fusionss.png" alt="Software"/>'; 	
		break;
		case 3:
			    code_str = '<img class="Event_Banners" src="http://www.xansoftware.com/Library/Hosted/System/Interface/Skins/skin_aurora_logo_grn.png" alt="Green Logo"/>';
		break;
		case 4:
				code_str = '<img class="Event_Banners" src="http://www.xansoftware.com/Library/Hosted/System/Interface/Skins/skin_aurora_logo_gld.png" alt="Gold Logo"/>';			
		break;
		case 5:
				code_str = '<img class="Event_Banners" src="http://www.xansoftware.com/Library/Hosted/System/Interface/Skins/skin_aurora_logo_pur.png" alt="Purple Logo"/>';	
		break;
		case 6:	
		//		code_str = '<img class="Event_Banners" src="http://www.xansoftware.com/Library/Hosted/System/Interface/Skins/skin_aurora_logo_yel.png" alt="Yellow Logo"/>';
				code_str = '<img class="Event_Banners" src="http://www.xansoftware.com/Library/Hosted/Images/xanquest_image/xanquest.png" alt="Xan Quest"/>';	

		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 Aurora
// 1 = Skin type is Aurora_Red
// 2 = Skin type is Aurora_Blue
// 3 = Skin type is Aurora_Gold
// 4 = Skin type is Aurora_Yellow
// 5 = Skin type is Aurora_Green
// 6 = Skin type is Aurora_Purple
// 7 = Skin type is Plain Black
// =================================
// AURORA MULTI COLOR SKIN

function load_skin(x){
var skin_type = eval(x);    // The variable portal_id tells us which portal to choose depending on the number passed to us.
var str='';                // Set up a null string to initialize.

switch(skin_type){

default:
case 0:
str+='        				<img class="Screen" src="http:\/\/www.xansoftware.com\/Library\/Hosted\/System\/Interface\/Skins\/skin_aurora_logo.png" ';
str+='        					  alt="Aurora Skin - Copyright (c) 2008 Xan Software." \/>';
break;
case 1:
str+='        				<img class="Screen" src="http:\/\/www.xansoftware.com\/Library\/Hosted\/System\/Interface\/Skins\/skin_aurora_logo_red.png" ';
str+='        					  alt="Aurora Skin - Copyright (c) 2008 Xan Software." \/>';
break;
case 2:
str+='        				<img class="Screen" src="http:\/\/www.xansoftware.com\/Library\/Hosted\/System\/Interface\/Skins\/skin_aurora_logo_blu.png" ';
str+='        					  alt="Aurora Skin - Copyright (c) 2008 Xan Software." \/>';
break;
case 3:
str+='        				<img class="Screen" src="http:\/\/www.xansoftware.com\/Library\/Hosted\/System\/Interface\/Skins\/skin_aurora_logo_grn.png" ';
str+='        					  alt="Aurora Skin - Copyright (c) 2008 Xan Software." \/>';
break;
case 4:
str+='        				<img class="Screen" src="http:\/\/www.xansoftware.com\/Library\/Hosted\/System\/Interface\/Skins\/skin_aurora_logo_gld.png" ';
str+='        					  alt="Aurora Skin - Copyright (c) 2008 Xan Software." \/>';
break;
case 5:
str+='        				<img class="Screen" src="http:\/\/www.xansoftware.com\/Library\/Hosted\/System\/Interface\/Skins\/skin_aurora_logo_pur.png" ';
str+='        					  alt="Aurora Skin - Copyright (c) 2008 Xan Software." \/>';
break;
case 6:
str+='        				<img class="Screen" src="http:\/\/www.xansoftware.com\/Library\/Hosted\/System\/Interface\/Skins\/skin_aurora_logo_yel.png" ';
str+='        					  alt="Aurora Skin - Copyright (c) 2008 Xan Software." \/>';
break;
case 7:
str+='        				<img class="Screen" src="http:\/\/www.xansoftware.com\/Library\/Hosted\/System\/Interface\/Skins\/skin_blk.png" ';
str+='        					  alt="Aurora Skin - Copyright (c) 2008 Xan Software." \/>';
break;
}
// Fall through and display selected skin type.
document.write(str);
}

// PAYPAL DONATE BUTTON
function donate(){
var str='';
str+=' <form action="https:\/\/www.paypal.com\/cgi-bin\/webscr" method="post">';
str+=' <input type="hidden" name="cmd" value="_s-xclick">';
str+=' <input type="hidden" name="hosted_button_id" value="1961394">';
str+=' <input type="image" src="https:\/\/www.paypal.com\/en_US\/i\/btn\/btn_donateCC_LG.gif" border="0" name="submit" alt="">';
str+=' <img alt="" border="0" src="https:\/\/www.paypal.com\/en_US\/i\/scr\/pixel.gif" width="1" height="1">';
str+='<\/form>';
document.write(str);
}


// COPYRIGHT FOOTER INFO
function cr_footer(){
var str='';
str+='  		<h4 class="bold">';
str+='              <img src="/tinc?key=UImAtaO1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://whos.amung.us/stats/7wv2oexd0euv/"><img src="http://whos.amung.us/widget/7wv2oexd0euv.png" width="56" height="20" border="0" title="Click to see how many people are online" /></a>';
str+='              <br \/>';
str+='    			Copyright &#0169; 1999-2010 ';
str+='    				<a class="plain" href="http:\/\/www.xansoftware.com">';
str+='    					Xan Software';
str+='    				<\/a>';
str+='    			all rights reserved.';
str+='    			<br \/>';
str+='    			Powered by XanCastle&#0153 v1.15  December 30, 2009';
str+='              <br \/>';
str+='    		<\/h4>';
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

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); }
}
