function openWin(url) {
  var aWin = window.open(url, 'Help', 'scrollbars,width=400,height=350,left=300,top=200,screenX=300,screenY=200'); aWin.focus();
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
	}



function PopWindow(PageToLoad,Width,Height)
	{
	var WindowAttributes = 'width=' + Width + ',height=' + Height + ',menubar=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=yes,top=0,left=0';
	GamesWindow = window.open(PageToLoad,'GamesWindow',WindowAttributes);
	GamesWindow.focus();
	}
	
function ChangeDate(FormField,NewDate)
	{
	alert ("Mooo");
	//document.AdminForm.elements[FormField].value = NewDate;
	}
	
function JumpToAPage( url, TotalPages, ViewPerPage, CurrentPage )
	{
	msg = "What page number would you like to go to? (Between 1 " + " and " + TotalPages + ")";
	pageUserWants = prompt( msg, CurrentPage);
	if ( pageUserWants > 0 ) {
		if ( pageUserWants < 1 ) { pageUserWants = 1; }
		//if ( pageUserWants > TotalPages ) { pageUserWants = TotalPages; }	// This line does not work for View=3 Goto page 3 to 9
		if ( pageUserWants == 1 ) { start = 0; }
		else { start = (pageUserWants - 1) * ViewPerPage; }
		window.location = url + "&Start=" + start + "&View=" + ViewPerPage;
		}
	else if (pageUserWants != null)
		{
		alert("Please enter a number between 1 " + " and " + TotalPages);
		JumpToAPage( url, TotalPages, ViewPerPage, CurrentPage );
		}
	}

// I have been working on the following to fade the second level breadcrumbs in and out but it takes too long for them to show up
// Based on http://www.olate.com/articles/view.php?id=179
// You need to include <script type='text/javascript' src='http://127.0.0.1/Customize/Javascripts/styley.js'></script>
// You also need to add a class to all the second level breadcrumbs so it has something to grab ahold of
// I was thinking I could fill all the occurances into an array then just edit those arrays
// or step through the subelements of just this ul and change them
var hex=0;
function fadeout(fadeelement)
{

	if(hex<=255)  //If color is not black yet
	{
		hex+=40; // increase color darkness
		setStyleByClass('A',fadeelement,'color',"rgb("+hex+","+hex+","+hex+")");
		setTimeout("fadeout('"+fadeelement+"')",10);
	}
	else hex=0 //reset hex value
}
function fadein(fadeelement)
{
	if(hex>=0)  //If color is not black yet
	{
		hex-=10; // increase color darkness
		setStyleByClass('A',fadeelement,'color',"rgb("+hex+","+hex+","+hex+")");
		setTimeout("fadein('"+fadeelement+"')",10);
	}
	else hex=255 //reset hex value
}

function fadeId(eName) {
	var elem = document.getElementById(eName);
	elem.style.display = "block";
	r -= 4;
	if(r < 0) r = 0;
	var color = "rgb("+r+","+r+","+r+")";
	elem.style.color = color;
	if(r > 0) {
		setTimeout("fadeId('"+eName+"')",10);
	}
}

// Adapted from http://www.alistapart.com/articles/dropdowns/
//function startList() 
//{
//	var IdToGet = "breadcrumbnav_root";		// This should be made a variable passed into this function
//	if (document.all&&document.getElementById)
//	{
//		navRoot = document.getElementById(IdToGet);
//		for (i=0; i<navRoot.childNodes.length; i++) 
//		{
//			node = navRoot.childNodes[i];
//			if (node.nodeName=="LI") 
//			{
//				node.onmouseover=function() 
//				{
//					this.className=" over";
//  				}
//				node.onmouseout=function() 
//				{
//					this.className=this.className.replace(" over", "");
//   				}
//   			}
//		}
//	}
//
//}

// Adapted from http://home.arcor.de/michaels.interface/tutors/javascript/show.hide/
function ShowHide(id, visibility) {
    obj = document.getElementsByTagName("div");
    if (visibility == 'toggle') 
    {
    	if (obj[id].style.display == 'none')	{obj[id].style.display = 'block';}
    	else	{obj[id].style.display = 'none'}
    }
    else {obj[id].style.display = visibility;}
}

var HighlightField1 = null;
var HighlightField2 = null;

function HighlightFields(Field1,Field1Type,Field2,Field2Type,ThisEvent) {
    obj = document.getElementsByTagName(Field1Type);
    obj2 = document.getElementsByTagName(Field2Type);
    
    if (ThisEvent == 'in')
    {
	HighlightField1 = obj[Field1].style.background;
	if(Field1Type=='a') {obj[Field1].style.border = '5px solid yellow';} else {obj[Field1].style.background = 'yellow';}
    	HighlightField2 = obj2[Field2].style.background;
    	obj2[Field2].style.color = '#333';
    }
    else 
    {
	if(Field1Type=='a') {obj[Field1].style.border = HighlightField1;} else {obj[Field1].style.background = HighlightField1;}
    	obj2[Field2].style.color = HighlightField2;
    
    }
}

function ShowText(id, visibility) {
    obj = document.getElementsByTagName("span");
    if (visibility == 'toggle') 
    {
    	if (obj[id].style.display == 'none')	{obj[id].style.display = 'inline';}
    	else	{obj[id].style.display = 'none'}
    }
    else {obj[id].style.display = visibility;}
}

function FormFocusIn(element)
{
//  This adds a mac like glow around the current item focused on
// However it shifts the page around and looks weird
// Here is the html to add to the form element onblur='FormFocusOut("postdate")' onfocus='FormFocusIn("postdate")'
//	setStyleById(element,"color","#666");
//	setStyleById(element,"margin","0")
//	setStyleById(element,"filter","progid:DXImageTransform.Microsoft.Glow(color=#ff4500,strength=2);")
}
function FormFocusOut(element)
{
//	setStyleById(element,"color","#ccc");
//	setStyleById(element,"margin","2")	// This is to prevent shifting on the page
//	setStyleById(element,"filter","")
}
var AdvancedOptions = false;
function ToggleAdvancedOptions(element)
{
	ShowHide('advanced_options','toggle');
	if (!AdvancedOptions) {element.value='Less Options';AdvancedOptions = true;}
	else	{element.value='More Options';AdvancedOptions = false;}
}
var ImageOptions = false;
function ToggleImageOptions(element)
{
	ShowHide('image_options','toggle');
	if (!ImageOptions) {element.value='Close Images';ImageOptions = true;}
	else	{element.value='Attach Images';ImageOptions = false;}
}
var SearchOptions = false;
function ToggleSearchOptions(element)
{
	ShowHide('search_dropbox','toggle');
	ShowHide('search_querybox','toggle');
	if (!SearchOptions) {element.src=SearchToggleImg2;SearchOptions = true;}
	else	{element.src=SearchToggleImg1;SearchOptions = false;}
}

// Send it something like C:\my documents\picture.jpg and it will return picture
function GetFileNameWithoutExt(TheFilename)
{
	// We have to check for  / or \ because of differences between PC/MAC/Linux
	var tmp = TheFilename.split("\\");
	var tmp2 = tmp.pop();
	var tmp = tmp2.split("/");
	var tmp2 = tmp.pop();
	var tmp = tmp2.split(".");
	var tmp2 = tmp.shift();
	return tmp2;
}

var TrackDiscussionImages = new Array();		// We need this to know the current state of the TrackDiscussion buttons
function TrackDiscussionToggle(ThisImage,ContentId,ContentType)
{
	var ArrayOfImagePath=ThisImage.src.split("/");
	var ThisImageName = ArrayOfImagePath.pop();
	var ImagePath = ArrayOfImagePath.join("/");
	if (typeof(TrackDiscussionImages[ThisImage.name]) != 'undefined') {ThisImageName = TrackDiscussionImages[ThisImage.name];}
	
	if (ThisImageName == 'DiscussionNew.gif') {var NewImage = 'DiscussionTracking.gif';var Action = 'ClearNew';}				// It's set to new, clear the new ones
	else if (ThisImageName == 'DiscussionTracking.gif') {var NewImage = 'DiscussionAvailable.gif';var Action = 'StopTracking';}			// It's on, turn it off
	else {var NewImage = 'DiscussionTracking.gif';var Action = 'TrackItem';}									// It's off, turn it on
	
	// Change the image
	// Send them to a script which will change their image
	//alert(NewImage + ' ' + Action);
	//location.href = 'TrackDiscussionToggle.php?Action=' + Action + '&ContentId=' + ContentId + '&ContentType=' + ContentType;
	
	ThisImage.src = 'TrackDiscussionToggle.php?Action=' + Action + '&ContentId=' + ContentId + '&ContentType=' + ContentType;
	ThisImage.title = '';
	TrackDiscussionImages[ThisImage.name] = NewImage;
	
}
var ToggleComponentSettings = new Array();
function ToggleComponent(ThisImage,ThisComponent)
{
	var ArrayOfImagePath=ThisImage.src.split("/");
	var ThisImageName = ArrayOfImagePath.pop();
	var ImagePath = ArrayOfImagePath.join("/");
	var ThisComponentId = ThisComponent + 'Details';

	if (typeof(ToggleComponentSettings[ThisComponent]) != 'undefined') {ThisImageName = ToggleComponentSettings[ThisComponent];}

	if (ThisImageName == 'dropdownundo.gif') 
	{	
		var NewImage = 'dropdown.gif';var Action = 'Show';			// It's on, turn it off
		ShowHide(ThisComponentId,"block");
	}
	else
	{
		var NewImage = 'dropdownundo.gif';var Action = 'Hide';				// It's set to new, clear the new ones
		ShowHide(ThisComponentId,"none");
	}
	
	// Change the image
	ThisImage.src = 'ToggleComponent.php?Action=' + Action + '&Component=' + ThisComponent;
	ThisImage.title = '';
	ToggleComponentSettings[ThisComponent] = NewImage;
}
var ToggleNodeSettings = new Array();
function OpenNode(ThisNode)
{
	var NodeName = 'MenuNode' + ThisNode;
	var NodeImage = 'NodeImage' + ThisNode;
	var ThisImage = document[NodeImage];

	var ArrayOfImagePath=ThisImage.src.split("/");
	var ThisImageName = ArrayOfImagePath.pop();
	var ImagePath = ArrayOfImagePath.join("/");
	if (typeof(ToggleNodeSettings[ThisNode]) != 'undefined') {ThisImageName = ToggleNodeSettings[ThisNode];}

	if (ThisImageName == 'Contract.gif') 
	{	
		var NewImage = 'Expand.gif';var Action = 'Hide';			// It's on, turn it off
	}
	else
	{
		var NewImage = 'Contract.gif';var Action = 'Show';				// It's set to new, clear the new ones
	}
	
	// Toggle the text now so they don't have to wait to see it
	ShowHide(NodeName,"toggle");
	
	
	// Change the image
	//alert('ToggleNode.php?Action=' + Action + '&Node=' + ThisNode);
	ThisImage.src = '../Community/ToggleNode.php?Action=' + Action + '&Node=' + ThisNode;
	ToggleNodeSettings[ThisNode] = NewImage;
	
	return false;	// This will cancel the link
}
var needToConfirmExit = false;

window.onbeforeunload = confirmExit;
function confirmExit()
{
    if (needToConfirmExit)
      return ("All your changes will be lost if you continue");
  }
  
// Only show allow a few characters and then show the abbreviation for the link
function TitleCount(ThisTitle)
{
	obj = document.getElementsByTagName("tr");
	if (obj['row_LinkName'].style.display != '')
	{
		if (ThisTitle.value.length <= 15) {document.AdminForm.LinkName.value=ThisTitle.value;}
		else 
		{

		    obj['row_LinkName'].style.display = '';
		    alert("Please enter a shorter name under 'LinkName' to appear in the navigation bar for this page");
		}
	}	
}
//window.onload=startList;

var GetTextOutputTo = '';
var GetText = function (File,OutputTo) 
{
	// Start up AJAX
	// 	Documentation on AJAX
	//	- http://www.alistapart.com/articles/gettingstartedwithajax
	//	- http://xkr.us/code/javascript/XHConn/
	
	// See if AJAX is working
	GetTextOutputTo = OutputTo;
	var myConn = new XHConn();
	if (!myConn) location.href='http://chrispriebe.mytwu.com/mytwu/Page/Admin/GetHelpText.php?File='+File;	// Go ahead with the link instead
	document.getElementById(GetTextOutputTo).innerHTML = "Loading...";
	myConn.connect('../Admin/GetHelpText.php', 'GET', 'File='+File+'&ThisDiv='+OutputTo,GetTextDone);
	
}
var GetTextDone = function (oXML)
{
	// Save it for later
	document.getElementById(GetTextOutputTo).innerHTML = oXML.responseText;
	
}