/****************************************************************************
* Method:		OpenPhoto(url)
* Purpose:		Runs when user clicks on a menu link.
* Parameters:	Page to go to.
*****************************************************************************/
function OpenPhoto(url)
{
        url = window.open(url,"photo","toolbar=no,location=no,status=no,menubar=no,scrollbars=no,width=700,height=525,resizable=no,left=40,top=40");
}

/****************************************************************************
* Method:		PrintMembers(url)
* Purpose:		Runs when user clicks on a menu link.
* Parameters:	Page to go to.
*****************************************************************************/
function PrintMembers(url)
{
        url = window.open(url,"members","toolbar=yes,location=no,status=no,menubar=yes,scrollbars=yes,width=1000,height=800,resizable=yes,left=40,top=40");
}

/****************************************************************************
* Method:		PrintMemberList(url)
* Purpose:		Runs when user clicks on a menu link.
* Parameters:	Page to go to.
*****************************************************************************/
function PrintMemberList(url)
{
        url = window.open(url,"memberlist","toolbar=yes,location=no,status=no,menubar=yes,scrollbars=yes,width=1000,height=800,resizable=yes,left=40,top=40");
}

/****************************************************************************
* Method:		Link_Clicked(object)
* Purpose:		Runs when user clicks on a menu link.
* Parameters:	Page to go to.
*****************************************************************************/
function Link_Clicked(strLink)
{
	location.href = strLink;
	return true;
}

/****************************************************************************
* Method:		Change_Classname(object, classname)
* Purpose:		Runs when user mouses over link.
* Parameters:	object:element causing call
*****************************************************************************/
function Change_Classname(object, strClassname)
{
	object.className = strClassname;
	return true;
}

/***************************************************
* Method:		Trim_String()
* Purpose:		Removes leading and trailing spaces 
*				from the passed string. Also removes
*				consecutive spaces and replaces it 
*				with one space. If something besides
*				a string is passed in (null, custom 
*				object, etc.) then return the input.
* Parameters:	(String)Email Address
****************************************************/
function Trim_String(strInput) 
{
	if (typeof strInput != "string") 
	{ 
		return strInput; 
	}
	
	var retValue = strInput;
	var ch = retValue.substring(0, 1);
	
	// Check for spaces at the beginning of the string
	while (ch == " ") 
	{ 
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
	}
   
	ch = retValue.substring(retValue.length-1, retValue.length);
   
	// Check for spaces at the end of the string
	while (ch == " ") 
	{
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
	}
   
	// Note that there are two spaces in the string - look for multiple spaces within the string
	while (retValue.indexOf("  ") != -1) 
	{
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	}
	
	// Return the trimmed string back to the user
	return retValue; 
	
} 

function AddClicked(selFrom, selTo)
{
	var strText;	//Holds text of option to be added.
	var strvalue;	//Holds value of option to be added.
	var intIndex;	//Index of current option.
		
	//Loop through From select.
	for(intIndex=0; intIndex<selFrom.length; intIndex++)
	{
		
		//If it is selected, grab the text and value.
		if(selFrom.options[intIndex].selected)
		{
			strText = selFrom.options[intIndex].text;
			strValue = selFrom.options[intIndex].value;
					
			//Insert item into destination box.
			AddOption(strText, strValue, selTo)
			
			//Delete item from source box.
			DeleteOption(selFrom,intIndex)
		}
	}
	
	SortSelect(selFrom)
	SortSelect(selTo)
}

function RemoveClicked(selTo, selFrom)
{
	var strText;
	var strvalue;
	var intIndex;
		
	//Loop through From select
	for(intIndex=0; intIndex<selTo.length; intIndex++)
	{
		
		//If it is selected, grab the text and value
		if(selTo.options[intIndex].selected)
		{
			strText = selTo.options[intIndex].text;
			strValue = selTo.options[intIndex].value;
					
			//Insert item into box
			AddOption(strText, strValue, selFrom)
			
			//Delete item from box
			DeleteOption(selTo,intIndex)
		}
	}
	
	SortSelect(selFrom)
	SortSelect(selTo)
}

function AddOption(strText, strValue, selTo)
{
	var strCurText;
	
	var optNew = new Option(strText, strValue);
	var lngSelLength = selTo.length;
		
	selTo.options[lngSelLength] = optNew;

}

function DeleteOption(selFrom, intIndex)
{
	if(selFrom.length > 0)
	{
		selFrom.options[intIndex] = null;
	}

}

function SortSelect(selSource)
{
	var aryValues = new Array();
	var intIndex1;
	var intIndex2;
	var strText;
	var strValue;
	var aryNew;
	var strSplit;
	
	//Loop through select
	for(intIndex1=0; intIndex1<selSource.length; intIndex1++)
	{
		//Make array item a new array of 2.
		aryValues[intIndex1] = new Array(2);
	
		//Loop through new array item
		for(intIndex2=0; intIndex2<2; intIndex2++)
		{
			//If it is the first item, get the text.
			if (intIndex2 == 0)
			{
				aryValues[intIndex1][0] = selSource.options[intIndex1].text;
			}
			//Otherwise get the value.
			else
			{
				aryValues[intIndex1][1] = selSource.options[intIndex1].value;
			}
		}
	}
		
	//Sort the array. Could use a compare function here for different comparisons.
	aryValues.sort();
	
	//Clear the source of the select.
	selSource.innerHTML = "";
	
	//Loop through select
	for(intIndex1=0; intIndex1<aryValues.length; intIndex1++)
	{
		//Insert item into box
		AddOption(aryValues[intIndex1][0] , aryValues[intIndex1][1] , selSource)
	}
}

