//=====================================================================
var activeMenu;
activeMenu = "none"; // <-- default value
var topMenu;
topMenu = 256; // <-- default value
//=====================================================================
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 hideLayer(LayerName) {
	if (LayerName != activeMenu) {
		if (document.getElementById) { 
  			menustyle = document.getElementById(LayerName).style; 
	  	} else {
			var doc = document.layers; 
			var style = '';
	    	menustyle = eval('doc.' + LayerName + style);
		}
   		menustyle.visibility='hidden';
	}
}
//=====================================================================
function showLayer(LayerName) {
	hideLayer('mHome');
	hideLayer('mSB');
	hideLayer('mTakeAction');
	hideLayer('mChallenge');
	hideLayer('mWaysToGive');
	hideLayer('mOpenDoors');
	hideLayer('mResources');	
	if (document.getElementById) { 
  		menustyle = document.getElementById(LayerName).style; 
  	} else {
		var doc = document.layers; 
		var style = '';
	    menustyle = eval('doc.' + LayerName + style);
	}
	menustyle.top = topMenu;
   	menustyle.visibility = 'visible'; 
}
//=====================================================================
function hideAllLayers() {
	MM_swapImgRestore();	
	hideLayer('mHome');
	hideLayer('mSB');
	hideLayer('mTakeAction');
	hideLayer('mChallenge');
	hideLayer('mWaysToGive');
	hideLayer('mOpenDoors');
	hideLayer('mResources');	
}
//=====================================================================
function initMenu() {
	var blnMakeVisible;
	var objImage;
	switch (activeMenu) {
	case "mHome" :
		objImage = document.getElementById('menu_home');
		objImage.src = "images/menu_home_f2.jpg";
		blnMakeVisible = true;
		break
	case "mSB" :
		objImage = document.getElementById('menu_sb');
		objImage.src = "images/menu_sb_f2.jpg";
		blnMakeVisible = true;		
		break
	case "mTakeAction" :
		objImage = document.getElementById('menu_take');
		objImage.src = "images/menu_take_f2.jpg";
		blnMakeVisible = true;		
		break
	case "mChallenge" :
		objImage = document.getElementById('menu_challenge');
		objImage.src = "images/menu_challenge_f2.jpg";
		blnMakeVisible = true;		
		break
	case "mWaysToGive" :
		objImage = document.getElementById('menu_ways');
		objImage.src = "images/menu_ways_f2.jpg";
		blnMakeVisible = true;		
		break
	case "mOpenDoors" :
		objImage = document.getElementById('menu_od');
		objImage.src = "images/menu_od_f2.jpg";
		blnMakeVisible = true;		
		break
	case "mResources" :
		objImage = document.getElementById('menu_resources');
		objImage.src = "images/menu_resources_f2.jpg";
		blnMakeVisible = true;		
		break
	default :
		blnMakeVisible = false;
	}
	if (blnMakeVisible == true) {
		if (document.getElementById) { 
	  		menustyle = document.getElementById(activeMenu).style; 
	  	} else {
			var doc = document.layers; 
			var style = '';
		    menustyle = eval('doc.' + activeMenu + style);
		}
		menustyle.top = topMenu;
		menustyle.zIndex = 1; 	
	   	menustyle.visibility = 'visible'; 
	}
}
//=====================================================================
function printfriendly() {
childWindow = window.open("printFriendly.htm", "printFriendly", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600,left=50,top=50");
if (childWindow.opener == null) childWindow.opener = self;
}	
//=====================================================================
function doOnMouseOverInline(obj) {
	obj.className='btnInlineHover';
	//obj.style.cursor='hand';
}
//=====================================================================
function doOnMouseOutInline(obj) {
	obj.className='btnInline';
	//obj.style.cursor='';
}
//=====================================================================
// challenge chat menu
function doChallengeChatNavigation(loggedIn) {
	if (loggedIn == 'True') {
		windowOpener('chat.aspx', 'windowFORUM');
	} else {
		window.location = "challenge_chat.aspx";
	}
}
//=====================================================================
// POPUP WINDOWS
var objNamedWindow;

function windowOpener(url, name) {
	var args;
	switch (name) {
		case "windowTAF" :
			args="height=575,left=50,location=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,top=50,width=550";
			break;
		case "windowFORUM" :
			args="height=600,left=50,location=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,top=50,width=800";
			break;
		case "windowPURCHASE" :
			args="height=600,left=50,location=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,top=50,width=1000";
			break;
		case "windowVIDEO" :
			args="height=375,left=200,location=no,resizable=no,scrollbars=no,status=no,toolbar=no,top=200,width=580";
			break;
			
		default :
			args="height=575,left=50,location=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,top=50,width=550";
	}
	if (typeof(objNamedWindow) != "object"){
		objNamedWindow = window.open(url,name,args);
	} else {
		if (!objNamedWindow.closed){
			//objNamedWindow.focus(); // cheaper when no data changes
			objNamedWindow.location.href = url;
		} else {
			objNamedWindow = window.open(url,name,args);
		}
	}
    objNamedWindow.focus();
}

function windowCloser(objWin) {
	if (typeof(objWin) == "object"){
		objWin.close();
	}
}
//e.g. in caller:
//onClick='windowOpener("Detail.aspx?Id=<?>","windowX");'
//onUnload='windowCloser(objNamedWindow);'
// & in pop up:
function doCloseMe() {
	window.close();
}
//=====================================================================
function setFocusOnLoad(vstrControlID) {
	var blnSet = false;

	if (vstrControlID != null) {
		var objControl = new getObj(vstrControlID).obj;
		if (objControl != null) {
			objControl.focus();
			blnSet = true;
		}
	}
	
	if (!(blnSet)) {
 		//Step 1. Exit function if there is not any form
		if (document.forms.length ==0)
			return

  		//Step 2. filter out the form element, only allow the following type get through
  		//	text							textarea
		//	checkbox						select
		//	radio							password
		//	Filter out the element which is disabled or readonly
		//	If the client browser is IE, then filter out the visible object only (CSS attribute)
		//	finally, Set focus on the first object then exit the function

		try {
			for (var j=0; j<document.forms.length;j++){
				for (var i=0; i<document.forms[j].elements.length; i++ ){
					var o=document.forms[j].elements[i]
					if (
						(o.type=='checkbox')
						||(o.type=='password')
						||(o.type=='radio')
						||(o.type=='select-multiple')
						||(o.type=='select-one')
						||(o.type=='text')
						||(o.type=='textarea')
					) {
						if ((o.readOnly!=true) && (o.disabled!=true)) {
							if ((o.style.visibility != 'hidden') && (o.style.display != 'none')) {
								o.focus();
								return;
								} //end of ie.hidden 
						} //end of readOnly
					}//detect type
				}//loop throught the element
			}//end of form loop
		}
		catch (exception) {
			return;
		}
	}
}
//=====================================================================
function searchHandler() {
	var strCache = '';
	var objControl = new getObj('txtSearchTerms').obj;

	if (objControl != null) {
		strCache = objControl.value;  // need parse into array?
		if ((strCache != null) && (strCache != '')) {
			document.location = "http://search.freefind.com/find.html?id=63617329&pageid=r&_charset_=utf-8&bcd=%C3%B7&scs=1&Find=Search&mode=ALL&query=" + strCache;			
		} else {
			alert('No search terms.');
		}
	} else {
		alert('Search term control not found.');
	}
}
//=====================================================================
function getObj(vstrControlID) {
	try {
		if (document.getElementById) {
			this.obj = document.getElementById(vstrControlID);
			this.style = document.getElementById(vstrControlID).style;
		}
		else if (document.all) {
			this.obj = document.all[vstrControlID];
			this.style = document.all[vstrControlID].style;
		}
		else if (document.layers) {
			this.obj = document.layers[vstrControlID];
			this.style = document.layers[vstrControlID];
		}
	}
	catch (exception) {
		//alert(exception);
		return;
	}
}
//=====================================================================
