function Francesca_ButtonHover() 
{
	//find all occurances of button
	var oButton = document.getElementsByTagName( "button" );
	for( var i = 0; i < oButton.length; i++ ) 
	{
		// add mouse over functions to change the class on hover to 'over'
		oButton[ i ].onmouseover = function() 
		{ 
			this.className = "over"; 
		} 
		oButton[ i ].onmouseout = function() 
		{ 
			this.className = "";
		}
	}
	var oButton = document.getElementsByTagName( "input" );
	for( var i = 0; i < oButton.length; i++ ) 
	{
		if( oButton[ i ].className == "button" )
		{
			// add mouse over functions to change the class on hover to 'over'
			oButton[ i ].onmouseover = function() 
			{ 
				this.className = "button over"; 
			} 
			oButton[ i ].onmouseout = function() 
			{ 
				this.className = "button";
			}
		}
	}
	var oDiv = document.getElementsByTagName( "div" );
	for( var i = 0; i < oDiv.length; i++ ) 
	{
		if( oDiv[ i ].className == "listedit" || oDiv[ i ].className == "listdelete" || oDiv[ i ].className == "listadd" )
		{
			// add mouse over functions to change the class on hover to 'over'
			oDiv[ i ].onmouseover = function() 
			{ 
				var oSpan = this.getElementsByTagName( "span" )[ 0 ];
				oSpan.className = "over"; 
			} 
			oDiv[ i ].onmouseout = function() 
			{ 
				var oSpan = this.getElementsByTagName( "span" )[ 0 ];
				oSpan.className = ""; 
			}
		}
	}
} 


//this function is responsible for showing and hiding the password forms
function Francesca_PasswordForm() 
{
	//disable this functionality for IE5
	if( navigator.appVersion.indexOf( "MSIE" ) != -1 && parseFloat( navigator.appVersion.split( "MSIE" )[ 1 ] ) < 6 )
	{
		return;
	}
	
	var oPassword = document.getElementById( "user_newpassword" );
	if( oPassword )
	{
		var oConfirmPassword = document.getElementById( "confirmpassword" );
		
		if( oConfirmPassword )
		{
			// add on change function
			oPassword.onkeypress = function() 
			{
				var oConfirmPassword = document.getElementById( "confirmpassword" );
				if( oConfirmPassword )
				{
					oConfirmPassword.style.display = "block";
				}
				
				var oCurrentPassword = document.getElementById( "currentpassword" );
				if( oCurrentPassword )
				{
					oCurrentPassword.style.display = "block";
				}
			}
		}
	}
}


//this function is responsible for finding fieldsets with a class of 'showhide'
//grabbing the text from the legend
//hiding the legend and replacing it with a label and a button
//hiding the content of the fieldset
//and adding functions to show/hide the contents on the button click
function Francesca_HideShow() 
{
	//disable this functionality for IE5
	if( navigator.appVersion.indexOf( "MSIE" ) != -1 && parseFloat( navigator.appVersion.split( "MSIE" )[ 1 ] ) < 6 )
	{
		return;
	}
	
	var oFieldset = document.getElementsByTagName( "fieldset" );
	if( oFieldset )
	{
		for( var i = 0; i < oFieldset.length; i++ )
		{
			var oDiv = oFieldset[ i ].getElementsByTagName( "div" );
			var oDivCount = oDiv.length
			
			for( var j = 0; j < oDivCount; j++ )
			{
				
				if( oDiv[ j ].className == "hide" || oDiv[ j ].className == "show" )
				{
				
					//create the button
					var oAddButton = document.createElement( "div" );
					var oAddButtonForm = document.createElement( "button" );
					var oAddButtonSpan = document.createElement( "span" );
					
					var boHidden = true;
					var strButtonText;
					
					strButtonText = oDiv[ j ].title
					
					if( oDiv[ j ].className == "hide" )
					{
						var oAddButtonSpanText = document.createTextNode( strButtonText );
					}
					else if( oDiv[ j ].className == "show" )
					{
						var oAddButtonSpanText = document.createTextNode( strButtonText );
						boHidden = false;
					}
					
					//set attributes
					oAddButtonForm.setAttribute( "type", "button" );
				
					//create node
					oAddButtonSpan.appendChild( oAddButtonSpanText );
					oAddButtonForm.appendChild( oAddButtonSpan );
					oAddButton.appendChild( oAddButtonForm );
					
					// add nodes to structure
					oDiv[ j ].parentNode.insertBefore( oAddButton, oDiv[ j ] );
					
					// most increase j and count to allow for extra added div
					j++;
					oDivCount++;
				}
			}
			
			//add on click
			var oButton = oFieldset[ i ].getElementsByTagName( "button" );
			if( oButton )
			{
				for( var j = 0; j < oButton.length; j++ )
				{
					if( oButton[ j ].type == "button" )
					{
						//set initial classes
						if( boHidden )
						{
							oButton[ j ].parentNode.className = "button open";
						}
						else
						{
							oButton[ j ].parentNode.className = "button close";
						}
						
						//set on click
						oButton[ j ].onclick = function() 
						{ 			
							//change parent div to show different button
							this.parentNode.className = this.parentNode.className == "button close" ? "button open" : "button close";
							
							//toggle visibility of the div
							var oParent = this.parentNode.parentNode;
							//find div
							var oDiv = oParent.getElementsByTagName( "div" );
							var boFoundMyself = false;
							
							for( var k = 0; k < oDiv.length && !boFoundMyself; k++ )
							{
								if( oDiv[ k ] == this.parentNode )
								{
									boFoundMyself = true;
									if( oDiv[ k + 1 ].className == "hide" )
									{
										oDiv[ k + 1 ].className = "show";
									}
									else if( oDiv[ k + 1 ].className == "show" )
									{
										oDiv[ k + 1 ].className = "hide";
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

function Francesca_ExternalLinks()
{
	var oLink = document.getElementsByTagName( "a" );
	if( oLink )
	{
		for( var i = 0; i < oLink.length; i++ )
		{
			if( oLink[ i ].getAttribute("rel") == "external" )
			{
				oLink[ i ].target = "_blank";
			}
		}
	}
}

function Francesca_HelpLink()
{
	var oLink = document.getElementById( "helpback" );
	if( oLink )
	{
		oLink.href="javascript:history.back();"
	}
	oLink = document.getElementById( "tophelpback" );
	if( oLink )
	{
		oLink.href="javascript:history.back();"
	}
}

function Francesca_PageTree()
{
	var oListItem = document.getElementsByTagName( "li" );
	if( oListItem )
	{
		
		for( var i = 0; i < oListItem.length; i++ )
		{
			//if page item is a label
			if( oListItem[ i ].className.indexOf( "label" ) != -1 )
			{
				
				//find icon
				var oDiv = oListItem[ i ].getElementsByTagName( "div" );
				if( oDiv )
				{
					for( var j = 0; j < oDiv.length; j++ )
					{
						//div is the page icon
						if( oDiv[ j ].className.indexOf( "icon" ) != -1 )
						{
							
							//add onclick function
							oDiv[ j ].onclick = function() 
							{ 			
								//toggle visibility of the div
								var oParent = this.parentNode;
								//find div
								var oUl = oParent.getElementsByTagName( "ul" )[ 0 ];
								
								if( oUl )
								{
									
									if( oUl.style.display == "none" )
									{
										oUl.style.display = "block";
									}
									else
									{
										oUl.style.display = "none";
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

function Francesca_Init()
{
	//all start up functions here
	//Francesca_PageTree();
	Francesca_HideShow();
	Francesca_PasswordForm();
	
	//rel links
	Francesca_ExternalLinks();
	
	//setup return link for help page
	Francesca_HelpLink();
	
	//should be called last to set up hover states
	Francesca_ButtonHover();
}

var oNewWindow = null;

function Francesca_CloseWin(){
	if (oNewWindow != null){
		if(!oNewWindow.closed)
			oNewWindow.close();
	}
}

function Francesca_PopUpWin(url, type, strWidth, strHeight){
	
	Francesca_CloseWin();
	
	if (type == "fullScreen"){
		strWidth = screen.availWidth - 10;
		strHeight = screen.availHeight - 160;
	}
	
	var tools="";
	if (type == "standard" || type == "fullScreen") tools = "resizable,toolbar=no,location=no,scrollbars=yes,menubar=no,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console") tools = "resizable,toolbar=no,location=no,scrollbars=yes,width="+strWidth+",height="+strHeight+",left=0,top=0";
	if (type == "external") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,width="+strWidth+",height="+strHeight+",left=0,top=0";	
	if (type == "popup") tools = "resizable=no,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";		
	oNewWindow = window.open(url, 'newWin', tools);
	oNewWindow.focus();
}

// set the html to have a css class of hasjs
// this enables us to change css styles to hide things we want hidden
// before the page is loaded, and thus stop the FOPSC (Flash Of Partially Styled Content)
document.getElementsByTagName( "html" )[0].className = "hasjs";
// NB. disable this functionality for IE5
if( navigator.appVersion.indexOf( "MSIE" ) != -1 && parseFloat( navigator.appVersion.split( "MSIE" )[ 1 ] ) < 6 )
{
	document.getElementsByTagName( "html" )[0].className = "";
}

// once the page has totally loaded, call our functions
window.onload = Francesca_Init;
