//---------------------------------------------------------------------------------------------------------
//	DHTML JavaScript (ver 2.3)
//---------------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------------
//	Show/ Hide menus
//-------------------------------------------------------------------------------------------------------
function show(group,item,imgId,imgBase)
{
	if(document.getElementById)
	{
		menuCount	= eval("m_" + group);
		
		mainMenu	= document.getElementById("m" + group + "0");
		subMenu		= document.getElementById("m" + group + item);

		//	Does object exist?
		if( !subMenu )
		{
			//	No, don't process
			return false;
		}
		
		if( imgId != 'NULL' )
		{
			imgObj	= document.getElementById( imgId );
			imgObj.setAttribute( 'base', imgBase );
			imgObj.setAttribute( 'src', imgBase );
		}
		
		mainMenu.style.visibility	= "visible";
		
		if ((mainMenu != subMenu) && (item != 0))
		{
			subMenu.style.visibility	= "visible";
			for (i = 1; i <= menuCount; i++)
			{
				if (i != item)
				{
					document.getElementById("m" + group + i).style.visibility	= "hidden";
				}
			}
		}
	}
}

//-------------------------------------------------------------------------------------------------------
//	Hide menu
//-------------------------------------------------------------------------------------------------------
function hide(group,item,imgId,imgBase)
{
	if(document.getElementById)
	{
		menuCount	= eval("m_" + group);

		//	Does object exist?
		if( !document.getElementById( "m" + group + menuCount ))
		{
			//	No, don't process
			return false;
		}
		
		if( imgId != 'NULL' )
		{
			imgObj	= document.getElementById( imgId );
			imgObj.setAttribute( 'base', imgBase );
			imgObj.setAttribute( 'src', imgBase );
		}
		
		if (item == 0)
		{
			startFrom	= 0;
		}
		else
		{
			startFrom	= 1;
		}
		for (i = startFrom; i <= menuCount; i++)
		{
			document.getElementById("m" + group + i).style.visibility	= "hidden";
		}
	}
}

//-------------------------------------------------------------------------------------------------------
//	Image swap
//-------------------------------------------------------------------------------------------------------
function swapImg(id,img)
{
	if( document.getElementById)
	{
		obj	= document.getElementById(id);
		obj.setAttribute( 'src', img );
	}
}

//-------------------------------------------------------------------------------------------------------
//	Client_text Selector
//-------------------------------------------------------------------------------------------------------
//	track what Client_text is highlighted in the sponsor a Client_text selector
currentClient_text	= 0;

function showClient_text(what)
{
	Client_textId			= "Client_text" + what;
	
	if(document.getElementById)
	{
		if ( !document.getElementById(Client_textId) )
		{
			return;
		}

		document.getElementById(Client_textId).style.visibility	= "visible";
		if (currentClient_text != what)
		{
			previousClient_textId		= "Client_text" + currentClient_text;
			document.getElementById(previousClient_textId).style.visibility	= "hidden";
		}
	}

	currentClient_text	= what;
}

//-------------------------------------------------------------------------------------------------------
//	Client_image Selector
//-------------------------------------------------------------------------------------------------------
//	track what Client_image is highlighted in the sponsor a Client_image selector
currentClient_image	= 0;

function showClient_image(what)
{
	Client_imageId			= "Client_image" + what;
	
	if(document.getElementById)
	{
		if ( !document.getElementById(Client_imageId) )
		{
			return;
		}

		document.getElementById(Client_imageId).style.visibility	= "visible";
		if (currentClient_image != what)
		{
			previousClient_imageId		= "Client_image" + currentClient_image;
			document.getElementById(previousClient_imageId).style.visibility	= "hidden";
		}
	}

	currentClient_image	= what;
}

//-------------------------------------------------------------------------------------------------------
//	Redirect
//-------------------------------------------------------------------------------------------------------
function redirectTo( nav )
{
	//	Selected a url?
	dropdown	= nav.options;
	value		= dropdown[dropdown.selectedIndex].value;

	if ( value )
	{
		window.location.href = value;	
	}
}


//---------------------------------------------------------------------------------------------------------
//	Validate Amount
//---------------------------------------------------------------------------------------------------------
function validateAmount()
{
	form = document.details;
	
	// Verify the dollar amount entered is correct on the Make a Donation Forms
	if ( form["fields[Dollar Amt]"] != 0 )
	{
		control = form["fields[Dollar Amt]"]; 
		if ( !confirm("You have entered a donation amount of $" + str_trim(control.value) + ".00.\nPlease click cancel if this is not correct.\nOtherwise, click the OK button to continue.") )
		{
			alert(3);

			control.focus();
			return false;
		}
	}
}


//-------------------------------------------------------------------------------------------------------
//	Redirect to New
//-------------------------------------------------------------------------------------------------------
function redirectToNew( nav )
{
	//	Selected a url?
	dropdown	= nav.options;
	value		= dropdown[dropdown.selectedIndex].value;

	if ( value )
	{
		window.open(value,"_new");	
	}
}

//-------------------------------------------------------------------------------------------------------
//	Gallery functionality
//-------------------------------------------------------------------------------------------------------
function gallerySwap(id)
{
	detailsImage	= document.getElementById('detailsgraphic');
	detailsImage.setAttribute( 'src', gallery[id] );
	
	textElement		= document.getElementById('detailstitle');
	textElement.innerHTML	= gallerytitle[id];
	
	textElement		= document.getElementById('detailstext');
	textElement.innerHTML	= gallerytext[id];
}

//*********************************************************************************************************
//	Positioning Tools
//*********************************************************************************************************
var positionShown  = false;

//-------------------------------------------------------------------------------------------------------
//	Turn position reporting On/Off
//-------------------------------------------------------------------------------------------------------
function togglePositionReporting()
{
	//	What ctrl key combination was hit
	if ( event.ctrlKey && (event.keyCode == 71) )
	{
		if (!document.getElementById('grid') || !document.getElementById('poslabel'))
		{
			return;
		}
		
		//	Get the tool objects
		gridObj  = document.getElementById('grid');
		labelObj = document.getElementById('poslabel');
		
		//	Turn the monitoring off
		if (positionShown)
		{
			//	Hide the grid
			gridObj.style.display = 'none';
			
			//	Show the position label
			labelObj.style.display = 'none';
			
			//	Stop monitoring
			document.onmousemove = '';
		}

		//	Turn the monitoring on
		else
		{
			//	Show the label
			labelObj.style.display = 'block';
			
			//	Show the grid
			gridObj.style.display	= 'block';
			gridObj.style.height	= document.body.clientHeight + 'px';

			//	Start monitoring
			document.onmousemove = showMousePosition;
		}

		//	Reset the state
		positionShown = positionShown ? false : true;
	}
}

//-------------------------------------------------------------------------------------------------------
//	Show the mouse position
//-------------------------------------------------------------------------------------------------------
function showMousePosition()
{
	//	Get the label
	labelObj = document.getElementById('poslabel');
	
	//	Get the scroll position
	if (document.compatMode && document.compatMode != "BackCompat")
	{
		scroll_left = document.documentElement.scrollLeft;
		scroll_top  = document.documentElement.scrollTop;
	}
	else
	{
		scroll_left = document.body.scrollLeft;
		scroll_top  = document.body.scrollTop;
	}

	//	Get the mouse position
	xMousePos	 = window.event.x + scroll_left - 2;
	yMousePos	 = window.event.y + scroll_top  - 3;
	xMousePosMax = document.body.clientWidth +  scroll_left;
	yMousePosMax = document.body.clientHeight + scroll_top;

	//	Reposition the label in the correct position
	labelObj.style.top  = yMousePos + 5;
	labelObj.style.left = xMousePos + 15;
	
	//	Update the label
	labelObj.innerText = xMousePos + ", " + yMousePos;
}


//-------------------------------------------------------------------------------------------------------
//	Child Selector
//-------------------------------------------------------------------------------------------------------

function showChild(what)
{
	childId			= "child" + what;
	
	if(document.getElementById)
	{
		document.getElementById(childId).style.visibility	= "visible";
		if (currentChild != what)
		{
			previousChildId		= "child" + currentChild;
			document.getElementById(previousChildId).style.visibility	= "hidden";
		}
	}

	//	Netscape 4.x hack
	else if (document.layers)
	{
		document.layers[childId].visibility	= "visible";
		if (currentChild != what)
		{
			previousChildId		= "child" + currentChild;
			document.layers[previousChildId].visibility	= "hidden";
		}
	}
	
	currentChild	= what;
}

function setCurrentChild(what)
{
	inload = 0;
    currentChild = what;
    showChild(what); 
}


//---------------------------------------------------------------------------------------------------------
//	Pop - Up Window
//---------------------------------------------------------------------------------------------------------
	
function showDetails(content,target)
{
	window.open(content,target,"menubar=0,statusbar=0,scrollbars=0,toolbar=0,location=0,width=500,height=380,screenX=400,screenY=400,top=100,left=100");
}

function showDetails2(content,target)
{
	window.open(content,target,"menubar=0,statusbar=0,scrollbars=1,toolbar=0,location=0,width=500,height=380,screenX=400,screenY=400,top=100,left=100");
}

function showStatus(id)
{
	url     = '/childmgr/status_history.php/id/' + id;
	target  = "_new";
	sizeX   = 400;
	sizeY   = 400;

	//	Center the window
	leftpos	= (screen.width)  ? (screen.width-sizeX)/2 : 100;
	toppos	= (screen.height) ? (screen.height-sizeY)/2 : 100;
	
	//	Open the window
	winobject				= window.open(url,target,"menubar=0,statusbar=0,scrollbars=1,toolbar=0,location=0,width=" + sizeX + ",height=" + sizeY + ",left=" + leftpos + ",top=" + toppos + ",resizable=0" );
	winobject.focus();
}

function showErrors(id)
{
	url     = '/childmgr/show_error_log.php/id/' + id;
	target  = '_new';
	sizeX   = 400;
	sizeY   = 400;

	//	Center the window
	leftpos	= (screen.width)  ? (screen.width-sizeX)/2 : 100;
	toppos	= (screen.height) ? (screen.height-sizeY)/2 : 100;
	
	//	Open the window
	winobject				= window.open(url,target,"menubar=0,statusbar=0,scrollbars=1,toolbar=0,location=0,width=" + sizeX + ",height=" + sizeY + ",left=" + leftpos + ",top=" + toppos + ",resizable=0" );
	winobject.focus();
}

function showWarnings(id)
{
	url     = '/childmgr/show_warning_log.php/id/' + id;
	target  = '_new';
	sizeX   = 400;
	sizeY   = 400;

	//	Center the window
	leftpos	= (screen.width)  ? (screen.width-sizeX)/2 : 100;
	toppos	= (screen.height) ? (screen.height-sizeY)/2 : 100;
	
	//	Open the window
	winobject				= window.open(url,target,"menubar=0,statusbar=0,scrollbars=1,toolbar=0,location=0,width=" + sizeX + ",height=" + sizeY + ",left=" + leftpos + ",top=" + toppos + ",resizable=0" );
	winobject.focus();
}

function showUpdated(id)
{
	url     = '/childmgr/show_updated_log.php/id/' + id;
	target  = '_new';
	sizeX   = 400;
	sizeY   = 400;

	//	Center the window
	leftpos	= (screen.width)  ? (screen.width-sizeX)/2 : 100;
	toppos	= (screen.height) ? (screen.height-sizeY)/2 : 100;
	
	//	Open the window
	winobject				= window.open(url,target,"menubar=0,statusbar=0,scrollbars=1,toolbar=0,location=0,width=" + sizeX + ",height=" + sizeY + ",left=" + leftpos + ",top=" + toppos + ",resizable=0" );
	winobject.focus();
}

function showAdded(id)
{
	url     = '/childmgr/show_added_log.php/id/' + id;
	target  = '_new';
	sizeX   = 400;
	sizeY   = 400;

	//	Center the window
	leftpos	= (screen.width)  ? (screen.width-sizeX)/2 : 100;
	toppos	= (screen.height) ? (screen.height-sizeY)/2 : 100;
	
	//	Open the window
	winobject				= window.open(url,target,"menubar=0,statusbar=0,scrollbars=1,toolbar=0,location=0,width=" + sizeX + ",height=" + sizeY + ",left=" + leftpos + ",top=" + toppos + ",resizable=0" );
	winobject.focus();
}

function openPopup ( content, target, sizeX, sizeY )
{
	//	Center the window
	leftpos	= (screen.width)  ? (screen.width-sizeX)/2 : 100;
	toppos	= (screen.height) ? (screen.height-sizeY)/2 : 100;

	//	Define the window size
	widthVar  = 'width=' + sizeX + ',';
	heightVar = 'height=' + sizeY + ',';
	
	//	Open the window
	winobject    = window.open(content,target,"menubar=0,statusbar=no,scrollbars=1,toolbar=0,location=0," + widthVar + heightVar + "left=" + leftpos + ",top=" + toppos + ",resizable=0" );
	winobject.focus();

}

function toggleGoogleStats( box_id )
{
	stats_box_table = document.getElementById( box_id );

	if ( !stats_box_table )
	{
		return;
	}

	if ( stats_box_table.style.display == 'block' )
	{
		stats_box_table.style.display = 'none';
	}
	else
	{
		stats_box_table.style.display = 'block';
	}
}

//---------------------------------------------------------------------
//	Home page - issues navigation
//---------------------------------------------------------------------
function toggleIssue(idx,mainImg,navImage,overImage)
{
	//	Deselect the previously selected image
	swapImg('issue' + selected,selectimage);
	
	//	Deselect the previously selected text
	selectedtext = 'issuetext' + selected;
	document.getElementById( selectedtext ).style.display	= "none";
	
	//	Swap the main and nav images
	swapImg('issueimage',mainImg);
	swapImg('issue' + idx,overImage);
	
	//	Turn on the new text
	newtext = 'issuetext' + idx;
	document.getElementById( newtext ).style.display	= "block";
	
	//	Remember what's selected so we can turn it off next time around
	selected = idx;
	selectimage = navImage;
}