
var agt		= navigator.userAgent.toLowerCase();
var versInt	= parseInt(navigator.appVersion);
var is_aol	= (agt.indexOf("aol") != -1);
var cookiesAvailable = FIRE_cookieDetector();
var undefined;


/* If no menu exists define one */
if (!fireNavMenu) 
{
	var fireNavMenu = new Object();
	fireNavMenu.menuItems = new Array();
	fireNavMenu.menuActions = new Array();
	fireNavMenu.menuItemTypes = new Array();
	fireNavMenu.subMenus = new Array();
}

function FIRE_goTo( url ) 
{
	window.location.href = url;	
}

function fireTodaysDate()
{
	var now = new Date();
	document.write(now.toLocaleString());
}

function FIRE_navBar( tableCellRef, hoverFlag, navStyle ) 
{
	/* onMouseOver or onClick   */
	if ( hoverFlag ) 
	{
		switch ( navStyle ) 
		{
			/*  onMouseOver  	           */
			case 1:
				tableCellRef.style.backgroundColor = '#69C';
				break;
			/*  onMouseOver  	           */
			case 2:
				tableCellRef.style.backgroundColor = '#FFBB00';
				break;
			/*  onClick					          */
			default:
				if ( document.getElementsByTagName ) 
				{										
					tableCellRef.getElementsByTagName( 'a' )[0].style.color = '#C00'; 
				}
		}
	}
	/* onMouseOut 			*/
	else 
	{
		switch ( navStyle ) 
		{
			case 1:
				tableCellRef.style.backgroundColor = '#036';
				break;
			case 2:
				tableCellRef.style.backgroundColor = '#FF9900';
				break;	
			default:
				if ( document.getElementsByTagName ) 
				{
					
					tableCellRef.getElementsByTagName( 'a' )[0].style.color = '#000';
				}
		}
	}
}

function FIRE_navBarClick( tableCellRef, navStyle, callFire_NavBar ) 
{
	if (callFire_NavBar == 1)
		FIRE_navBar( tableCellRef, 0, navStyle );
	var url = FIRE_locateActionTarget(tableCellRef);
	FIRE_goTo( url );
}
// Locate the HTMLDivElement which contains the HTMLAnchorElement then obtain the 
// HTMLHrefElement value to use as the target of the window.location.href;
function FIRE_locateActionTarget(tableCellRef) 
{
	// Locate the HTMLDivElement
	var divList = tableCellRef.getElementsByTagName("div");
	// Locate the HTMLDivElement
	var anchors = divList[0].getElementsByTagName("a");
	return  anchors[0].href;		
}
// this is for opening pop-up windows
function FIRE_openPopup( url, name, widgets, openerUrl )
{
	var host = location.hostname;
	var popupWin = window.open( url, name, widgets );
	
	if ( popupWin && popupWin.opener ) {
		if ( openerUrl )
		{
			popupWin.opener.location = openerUrl;
			popupWin.focus();
		}
		popupWin.opener.top.name = "opener";
	}
}

function FIRE_createNavBar(menuItemToHilite) 
{
	fireNavBarTable = document.getElementById("fireNavBar");
	var theRows = new Array();	
	for (var i=0; i < fireNavMenu.menuItems.length; i++)	
	{
		// Append the new row to the fireNavBar				
		theRows[i] = fireNavBarTable.insertRow(i);		
		
		if (menuItemToHilite == fireNavMenu.menuItems[i])
		{			
			FIRE_createNavHilitedRow(theRows[i],i);			
		}
		else
		{	
			// Set attributes of the NavRow			
			theRows[i].className= fireNavMenu.menuItemTypes[i];			
			
			switch(fireNavMenu.menuItemTypes[i])
			{
				case "fireNavHelpRow":
					FIRE_createNavHelpRow(theRows[i],i);										
				break;
				case "fireNavRow":
					FIRE_createNavRow(theRows[i],i);										
				break;				
				case "fireNavOtherRow":
					FIRE_createNavOtherRow(theRows[i],i);
				break;
				
				case "fireNavGroupRow":					
					FIRE_createNavGroupRow(theRows[i],i);
				break;
			}						
		}
	}
}

// Creates a Navigation Bar Hilited Row
function FIRE_createNavHilitedRow(theRow,rowIndex)
{
	
	// Create the swath HTMLTableCellElement
	var swathCell = theRow.insertCell(0);
		
	// Create the text HTMLTableCellElement
	var textCell = theRow.insertCell(1);
	
	// Set attributes of the fireNavHiliteRow		
	theRow.bgColor = "#CCCCCC";
	theRow.className= "fireNavHiliteRow";			
	
	// Set the attributes of the swathCell
	swathCell.width= "8";
	swathCell.className = "swath";
	
	// Create the TextNode for the swath
	// Should be using &nbsp
	var nbsp = "&nbsp\;";			
	swathText = document.createTextNode(" ");  
	
	// Append the swath textNode to the cell 
	swathCell.appendChild(swathText);
	
	// Set the attributes of the HTMLTableCellElement for the text
	textCell.className = "fireNavHilite";
	textCell.onclick= function() {FIRE_NavBarClick(this,1,0); };
	
	// Create the Div with the label in it
	var div = FIRE_createNavBarHTMLDivElement(rowIndex);
			
	// Append the HTMLDivElement to the HTMLTableCellElement		
	textCell.appendChild(div);
}

// Creates a Navigation Bar Row
function FIRE_createNavRow(theRow, rowIndex)
{
	// Create the swath HTMLTableCellElement
	var swathCell = theRow.insertCell(0);
		
	// Create the text HTMLTableCellElement
	var textCell = theRow.insertCell(1);
	
	// Set the attributes of the swathCell
	swathCell.width= "8";
	swathCell.className = "swath";
	
	// Create the TextNode for the swath			
	swathText = document.createTextNode(" ");
				
	// Append the swath textNode to the cell 
	swathCell.appendChild(swathText);
	
	// Set the attributes of the HTMLTableCellElement for the text
	textCell.className = "fireNav";
	
	// Set the onMouseOver, onMouseOut and onClick functions
	textCell.onmouseover = function() { FIRE_navBar(this,1,1); };
	textCell.onmouseout= function() { FIRE_navBar(this,0,1);};
	textCell.onclick = function() {FIRE_navBarClick(this,1,0); };

	var div = FIRE_createNavBarHTMLDivElement(rowIndex);
	
	// Append the HTMLDivElement to the HTMLTableCellElement		
	textCell.appendChild(div);
}
// Creates a Navigation Bar Row
function FIRE_createNavHelpRow(theRow, rowIndex)
{
	// Create the swath HTMLTableCellElement
	var swathCell = theRow.insertCell(0);
		
	// Create the text HTMLTableCellElement
	var textCell = theRow.insertCell(1);
	
	// Set the attributes of the swathCell
	swathCell.width= "8";
	swathCell.className = "swath";
	
	// Create the TextNode for the swath			
	swathText = document.createTextNode(" ");
				
	// Append the swath textNode to the cell 
	swathCell.appendChild(swathText);
	
	// Set the attributes of the HTMLTableCellElement for the text
	textCell.className = "fireNavHelp";
	
	// Set the onMouseOver, onMouseOut and onClick functions
	textCell.onmouseover = function() { FIRE_navBar(this,1,2); };
	textCell.onmouseout= function() { FIRE_navBar(this,0,2);};
	textCell.onclick = function() {FIRE_navBarClick(this,1,0); };

	var div = FIRE_createNavBarHTMLDivElement(rowIndex);
	
	// Append the HTMLDivElement to the HTMLTableCellElement		
	textCell.appendChild(div);
}
// Creates a Navigation Bar OtherRow 
function FIRE_createNavOtherRow(theRow,rowIndex)
{
	// Create the swath HTMLTableCellElement
	var swathCell = theRow.insertCell(0);
		
	// Create the text HTMLTableCellElement
	var textCell = theRow.insertCell(1);
	
	// Set the attributes of the swathCell
	swathCell.width= "8";
	swathCell.className = "swath";
	// Create the TextNode for the swath			
	swathText = document.createTextNode(" ");

	// Append the swath textNode to the cell 
	swathCell.appendChild(swathText);
	
	// Set the attributes of the HTMLTableCellElement for the text
	textCell.className = "fireNavOther";
	
	textCell.onmouseover = function() { FIRE_navBar(this,1,0); };
	textCell.onmouseout= function() { FIRE_navBar(this,0,0);};
	textCell.onclick = function() {FIRE_navBarClick(this,0,0); };

	var div = FIRE_createNavBarHTMLDivElement(rowIndex);
	
	// Append the HTMLDivElement to the HTMLTableCellElement		
	textCell.appendChild(div);
}

// Creates a Navigation Bar Group Row
function FIRE_createNavGroupRow(theRow,rowIndex)
{
	// Set the row background color to dark gray
	theRow.bgColor = "#999999";
	
	// Create the text HTMLTableCellElement
	var textCell = theRow.insertCell(0);
		
	// Set the attributes of the HTMLTableCellElement for the text
	textCell.className = "fireNavGroup";
	textCell.colSpan = "2";	

	// Create the DIV element
	var div = document.createElement("div");
	div.className = "fireNavText";	
	
	// Create the HTMLTextNode			
	buttonText = document.createTextNode(fireNavMenu.menuItems[rowIndex]);
	
	// Append the HTMLTextNode to the HTMLDivElement
	div.appendChild(buttonText);
	
	// Append the HTMLDivElement to the HTMLTableCellElement		
	textCell.appendChild(div);
}	

// Creates a Navigation Bar HTMLDivElement
function FIRE_createNavBarHTMLDivElement(rowIndex)
{
	// Create the DIV element
	var div = document.createElement("div");
	div.className = "fireNavText";
		
	// Create an HTMLAnchorElement
	var a = document.createElement("a");
	a.href= fireNavMenu.menuActions[rowIndex];
	
	// Append the HTMLAnchorElement to the HTMLDivElement
	div.appendChild(a);
	
	// Create the HTMLTextNode			
	buttonText = document.createTextNode(fireNavMenu.menuItems[rowIndex]);
	
	// Append the HTMLTextNode to the HTMLDivElement
	a.appendChild(buttonText);	
	return div;			
}


function fireAddMenuToNavBar(menuName,menuAction,menuItemType) 
{		
	fireNavMenu.menuItems.push(menuName);
	fireNavMenu.menuActions.push(menuAction);
	fireNavMenu.menuItemTypes.push(menuItemType);
	
}

function fireAddSubMenuToMenu(menuName,subMenuName,menuAction,menuItemType)
{
	for (var i=0; i < fireNavMenu.menuItems.length; i++)	
	{
		if (fireNavMenu.menuItems[i] == menuName)
		{
			if (fireNavMenu.subMenus[i] == undefined)
			{
				fireNavMenu.subMenus[i] = new Object();
			
				fireNavMenu.subMenus[i].menuItems = new Array();
				fireNavMenu.subMenus[i].menuActions = new Array();
				fireNavMenu.subMenus[i].menuItemTypes = new Array();
			}
			fireNavMenu.subMenus[i].menuItems.push(subMenuName);
			fireNavMenu.subMenus[i].menuActions.push(menuAction);
			fireNavMenu.subMenus[i].menuItemTypes.push(menuItemType);
		}
	}	
}
// Redirects the search form (if necessary)
function validate( theFormValidate ) 
{ 
	return FIRE_validateSearchForm( theFormValidate ); 
}
function FIRE_validateSearchForm( theForm )
{
	var site = '4inthefire.org';
	var queryString = '';
	
	if ( theForm.sitesearch )
	{
		if ( theForm.sitesearch.options ) 
		{	
			site = theForm.sitesearch.options[theForm.sitesearch.selectedIndex].value;
		} 
		else 
		{
			if ( theForm.sitesearch.length )
			{
				for ( i = 0; i < theForm.sitesearch.length; i++ )
				{
					if ( theForm.sitesearch[i].checked ) 
					{
						site = theForm.sitesearch[i].value;
					}
				}
			}
			else
			{
				site = theForm.sitesearch.value;
			}
		}
	}
	
	if ( theForm.query ) 
	{	   
		queryString = theForm.query.value;		
	} 
	else 
	{		
		if ( theForm.q ) 
		{			
			queryString = theForm.q.value;			
		}				
	}
	
	
	if ( !queryString ) 
	{
		alert("Type text for which to search and click 'Search'");
		return false;
	}
	
	switch ( site.toLowerCase() ) 
	{
		case "google":
			theForm.q.value = queryString;						
			return true;
		
		case "4inthefire.org":
			theForm.q.value = queryString;
			return true;
		
		default:			
			return true;
	}
}
function FIRE_cookieDetector()
{
	if (navigator.cookieEnabled)
	{
		return true;
	}
	else 
	{
		return false;
	}
}
function FIRE_generateWelcome()
{
	alert("FIRE_generateWelcome executing");
	fireWelcomeCell = document.getElementById("welcome");
	
	if (fireWelcomeCell != null)
	{
		var daysLeft = FIRE_getDaysUntilDeparture(); 
		welcomeText = document.createTextNode(daysLeft + " days left until we depart for Russia!!");
		fireWelcomeCell.appendChild(welcomeText);
	}
	
	alert("FIRE_generateWelcome terminating");
}
function FIRE_generateDeparture()
{
	fireDepartureCell = document.getElementById("departureDays");
	
	if (fireDepartureCell != null)
	{
		var daysLeft = FIRE_getDaysUntilDeparture();
		departureText = document.createTextNode(daysLeft + " days left until we depart for Russia");
		fireDepartureCell.appendChild(departureText);
	}
	
}
function FIRE_getDaysUntilDeparture()
{
	var oneMinute = 60 * 1000;
	var oneHour = oneMinute * 60;
	var oneDay = oneHour * 24;
	var today = new Date();
	var departureDate = new Date();
	departureDate.setMonth(11);
	departureDate.setDate(27);
	var diff = departureDate.getTime() - today.getTime();
	diff = Math.floor(diff/oneDay);
	return diff;
}

function FIRE_checkRegistrationData()
{	
	var focusSet = false;
	var msg = "";
	if (top.document.registrationForm.userid.value == "")
	{
		msg += "\rThe userid field is required.";
				
		if (!focusSet)
		{
   		top.document.registrationForm.userid.focus();
   		top.document.registrationForm.userid.select();
			focusSet = true;
		}   
	}
	var a = top.document.registrationForm.email.value;
	var b = top.document.registrationForm.emailConfirmation.value;
	
	if (a == "" && b == "")
	{
		msg += "\rBoth the email address and the email confirmation address are required fields.\r" +
		  		"Please confirm your email address again.";
		if (!focusSet)
		{		
			top.document.registrationForm.email.focus();
   		top.document.registrationForm.email.select();
			focusSet = true;
		}		
	}
	if (a == "" || b == "" )
	{
		msg += "\rThe email address and the email confirmation address are required fields.";
					 
		if (!focusSet)
		{		
			top.document.registrationForm.email.focus();
   		top.document.registrationForm.email.select();
			focusSet = true;
		}		
	}
	if (a != b) 
	{
		top.document.registrationForm.emailConfirmation.value = "";
      msg += "\rYour email addresses did not match." + 
				"\rYou entered \"" +a+ "\" as your email address." + 
				"\rYou entered \"" +b+ "\" in the confirmation field."; 
				
		if (!focusSet)
		{
   		top.document.registrationForm.email.focus();
   		top.document.registrationForm.email.select();
			focusSet = true;
		}    
   } 
	if (top.document.registrationForm.fname.value == "")
	{
		msg += "\rThe first name field is required.";
				
		if (!focusSet)
		{
   		top.document.registrationForm.fname.focus();
   		top.document.registrationForm.fname.select();
			focusSet = true;
		}   
	}
	if (top.document.registrationForm.lname.value == "")
	{
		msg += "\rThe last name field is required.";
				
		if (!focusSet)
		{
   		top.document.registrationForm.lname.focus();
   		top.document.registrationForm.lname.select();
			focusSet = true;
		}   
	}
	if (top.document.registrationForm.addr1.value == "")
	{
		msg += "\rThe address field is required.";
				
		if (!focusSet)
		{
   		top.document.registrationForm.addr1.focus();
   		top.document.registrationForm.addr1.select();
			focusSet = true;
		}   
	}
	if (top.document.registrationForm.city.value == "")
	{
		msg += "\rThe city field is required.";				
		if (!focusSet)
		{
   		top.document.registrationForm.city.focus();
   		top.document.registrationForm.city.select();
			focusSet = true;
		}   
	}
	if (top.document.registrationForm.state.value == "")
	{
		msg += "\rThe state field is required.";				
		if (!focusSet)
		{
   		top.document.registrationForm.state.focus();
   		//top.document.registrationForm.state.select();
			focusSet = true;
		}   
	}
	if (top.document.registrationForm.zip.value == "")
	{
		msg += "\rThe zip code field is required.";				
		if (!focusSet)
		{
   		top.document.registrationForm.zip.focus();
   		top.document.registrationForm.zip.select();
			focusSet = true;
		}   
	}
	if (top.document.registrationForm.country.value == "")
	{
		msg += "\rThe country field is required.";				
		if (!focusSet)
		{
   		top.document.registrationForm.country.focus();
   		//top.document.registrationForm.country.select();
			focusSet = true;
		}   
	}
	if (top.document.registrationForm.gender.value == "")
	{
		msg += "\rThe gender field is required.";				
		if (!focusSet)
		{
   		top.document.registrationForm.gender.focus();
   		//top.document.registrationForm.gender.select();
			focusSet = true;
		}   
	}
	if (top.document.registrationForm.age.value == "")
	{
		msg += "\rThe age field is required.";				
		if (!focusSet)
		{
   		top.document.registrationForm.age.focus();
   		top.document.registrationForm.age.select();
			focusSet = true;
		}   
	}
	if (msg != "")
	{
		msg += "\r\rPlease provide the information requested."
		alert(msg);
		return false;
	}
	else
	{
		top.document.registrationForm.submit(); 
	}		
}



//Disable right mouse click Script
//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com

var message="This site is copyright protected by Four in The Fire Ministries. \rPlease do not copy our site.";


function clickIE4()
{
	if (event.button==2)
	{
		alert(message);
		return false;
	}
}

function clickNS4(e)
{
	if (document.layers||document.getElementById&&!document.all)
	{
		if (e.which==2||e.which==3)
		{
			alert(message);
			return false;
		}
	}
}

if (document.layers)
{
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById)
{
	document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")


function Fire_setHomePage(theDocument)
{
	alert("Setting home page!");
	theDocument.style.behavior="url(#default#homepage)";
	theDocument.setHomePage("http://www.4inthefire.org");
}
