//<![CDATA[
//----------------------------------------------------------------------------------------------------------------------------
//support.js        Support functions for the javascript used on mulitple pages
//called by:        index.html	
//updates:			2009-09-24 :: mm :: original file
// 										added fx page_reloaded, GetFeeds
//					2010-02-19 :: mm :: stripped down for rmp's new homepage
//----------------------------------------------------------------------------------------------------------------------------
//version:      0.1
//status:       CHECKED IN
//----------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------
//GLOBALS :: should act as static vars due to being an included file
//----------------------------------------------------------------------------------------------------------------------------
var DebugMode = true;       //set to true or false to see or hide the alert boxes.
var bt = new Array(); 		//holds all the xmlHttp requests in an organized array

//----------------------------------------------------------------------------------------------------------------------------
//ErrorHandler: Global Error Handler for all the javascript code
//called by:    all .js fx
//inputs:       error object
//outputs:      alert box if in debug mode -- else silenty fails
//updates:      2009-09-24 :: mm :: original file
//----------------------------------------------------------------------------------------------------------------------------
function ExceptionHandler(e,str_AdditionalMessage)
{
    if(str_AdditionalMessage===undefined){str_AdditionalMessage=".";}
    if(DebugMode)
    {
    	var ParseError = "fx " + e.constructor + "  generated an error \n" + e.name + " :: " + e.message + "\n Line: " + e.lineNumber + " FileName: " + e.fileName;
    	ParseError = ParseError + "\n\n" + str_AdditionalMessage;
        alert(ParseError);
        throw (null);
    }
    else
    {
        throw("An unanticipated error occured");
    }
    
}


//------------------------------------------------------------------------------------------------------------------------------
//page_reloaded:    after the page has been refreshed
//called by:        avail.php/body onload="page_reloaded()"
//uses:             
//calls:            GetFeeds(request number, div id to place results, file to fetch)
//                  
//updates:          2009-09-24 :: mm :: original file
//
//------------------------------------------------------------------------------------------------------------------------------
function  PageReloaded()
{
	try
	{
			//Call the fx GetFeeds(request number, div id to place results, file to fetch)
	        GetFeeds(1,"div_News","lastpost/newspost.php");	//Get the news for the left side			
	        GetFeeds(2,"div_Topics","lastpost/lastpost.php");	//Get the posts for the middle
	        GetFeeds(3,"div_POTD","potd/potd.php");				//Get the photo of the day for the right side
	        GetFeeds(4,"div_WOTD","wotd/wotd.php");				//Get the word of the day for the right side
			google_track();										//run the google analytics
	}
	catch (e) 
	{
	    ExceptionHandler(e);
	}
}


//------------------------------------------------------------------------------------------------------------------------------
//GetFeeds:			xml requests to get the .html for the divs
//called by:        PageReloaded()
//passing in:       request number, div id to place results, file to fetch, new class name for the div
//uses:             var bt								//array to hold all the xml feed requests
//calls:            XML request
//outputs:          html - showing the news, posts, photos
//updates:          2009-09-24 :: mm :: original file
//					2009-09-29 :: mm :: add option to update the class
//
//------------------------------------------------------------------------------------------------------------------------------
function GetFeeds(requestnum,iddiv,htmlfile,newclass) 
{
	try 
	{		
		if(window.XMLHttpRequest)
		{
			bt[requestnum] = new XMLHttpRequest(); // code for Firefox, Opera, IE7, etc.
		}
		else if (window.ActiveXObject)
		{
			bt[requestnum] = new ActiveXObject("Microsoft.XMLHTTP"); // code for IE6, IE5
		}
		if (bt[requestnum] != null) 
		{
			bt[requestnum].onreadystatechange = function() 
			{
				if(bt[requestnum].readyState == 4)
				{
					if (bt[requestnum].status == 200)
					{
					    document.getElementById(iddiv).innerHTML = bt[requestnum].responseText; 	//output the html to the DIV
					    if(newclass!=null){document.getElementById(iddiv).className = newclass;}
					}
					else
					{
						ExceptionHandler(e, "Code: " + bt[requestnum].status + " :: " + bt[requestnum].statusText);						
					}
				}
			};
			bt[requestnum].open("GET", htmlfile, true);
			bt[requestnum].send(null);
		}
		else
		{
			ExceptionHandler(e, "Your browser of choice is ill-equiped for the situation at hand");
		}
	}
	catch (e) 
	{
	    ExceptionHandler(e,"GetFeeds: " + e.name + " :: " + e.message);
	}
}
//------------------------------------------------------------------------------------------------------------------------------
//for google analytics
//------------------------------------------------------------------------------------------------------------------------------
function google_track()
{
	try
	{
		var pageTracker = _gat._getTracker("UA-13228398-1");
		pageTracker._trackPageview();
	}
	catch(err) 
	{
		//exit do nothing
	}
}
//------------------------------------------------------------------------------------------------------------------------------
//for dropdown menus
//------------------------------------------------------------------------------------------------------------------------------
var dropdownmi = 0;
var timer_close = 0;
var int_timeamt = 500;
//document.onclick = menuclose();	//ie doesn't like this

function menuopen(menuid)
{	// open hidden layer
		menucancelclose();		// cancel the close timer
		if(dropdownmi)
		{
			dropdownmi.style.visibility = 'hidden';	//hide the previous menu
		}
		dropdownmi=document.getElementById(menuid);	//get the new menu id
		dropdownmi.style.visibility = 'visible';	//show the menu - div
}
function menuclose()
{
	timer_close = window.setTimeout(hidediv, int_timeamt);	//set the timer
}
function hidediv()
{
	if(dropdownmi)
	{
		dropdownmi.style.visibility = 'hidden';			//hide the div
	}	
}
function menucancelclose()
{
	if(timer_close)
	{
		window.clearTimeout(timer_close);		//cancel the close timer
		timer_close = null;						//set it to null
	}
}
//]]>