//-----------------------------------------------------------------
// Name			: ClearDropDownList
// Description	: Clear a DropDown List Control of all content
//-----------------------------------------------------------------
// Intrants		: DropDownName - Name of the DropDown List Control
// Extrants		: None
//-----------------------------------------------------------------
// History		:
// Date				Author			Comments
// ----------------	---------------	-------------------------------
// 2005-03-24		DenommeB		Creation
//-----------------------------------------------------------------
function ClearDropDownList(DropDownName)
{
	//-------------------------------------------------------------
	// Extract the DropDownList Control
	//-------------------------------------------------------------
	var DropDownList;
	DropDownList = document.getElementById(DropDownName);

	//-------------------------------------------------------------
	// Extract the Number of element in the DropDownList
	//-------------------------------------------------------------
	var ElementCount;
	ElementCount = DropDownList.options.length;

	//-------------------------------------------------------------
	// Delete all the Options in the DropDownList Starting from the
	// end.
	//-------------------------------------------------------------
	for (i = ElementCount; i >= 0; i--)
	{
		DropDownList.options.remove(i);
	}
}

//-----------------------------------------------------------------
// Name			: LoadDropDownList
// Description	: Load a DropDown List Control From an Array
//-----------------------------------------------------------------
// Intrants		: DropDownName - Name of the DropDown Control
//				  DataSource - Array as the source of the Control
//							   (must be a 2 level Array)
//				  IndexForText - Index in array for the Text Value
//				  IndexForValue- Index in array for the Value Value
// Extrants		: None
//-----------------------------------------------------------------
// History		:
// Date				Author			Comments
// ----------------	---------------	-------------------------------
// 2005-03-24		DenommeB		Creation
//-----------------------------------------------------------------
function LoadDropDownList(DropDownName, DataSource, IndexForText, IndexForValue)
{
	//-------------------------------------------------------------
	// Extract the DropDownList Control
	//-------------------------------------------------------------
	var DropDownList;
	DropDownList = document.getElementById(DropDownName);

	//-------------------------------------------------------------
	// Extract the Number of element in the Array (DataSource)
	//-------------------------------------------------------------
	var ElementCount;
	ElementCount = DataSource.length;

	//-------------------------------------------------------------
	// Extract the Number of element in the Array (DataSource)
	//-------------------------------------------------------------
	for(i = 0; i < ElementCount; i++)
	{
		DropDownList.options[i] = new Option(DataSource[i][IndexForText], DataSource[i][IndexForValue]);
	}
}
//-----------------------------------------------------------------
// Name			: FindArray
// Description	: Find and return an Array contain in a Array 
//				  according to the ID to find and the Index of the
//				  ID Column.
//-----------------------------------------------------------------
// Intrants		: ArraySource	- Cource Array to look in
//				  ID			- Id to seach in the Array
//				  Index			- Index of the ID Column in the Array
// Extrants		: Array found corresponding to the ID
//-----------------------------------------------------------------
// History		:
// Date				Author			Comments
// ----------------	---------------	-------------------------------
// 2005-03-29		DenommeB		Creation
//-----------------------------------------------------------------
function FindArray(ArraySource, ID,Index)
{
	for(i=0; i< ArraySource.length; i++)
	{
		if(ArraySource[i][Index] == ID)
		{
			return ArraySource[i];
		}
	}

	return null;
}
//-----------------------------------------------------------------
// Name			: GetPartArray
// Description	: Find and return an Array of Child Part associated
//				  to a MediaID.
//-----------------------------------------------------------------
// Intrants		: MediaID	- Id media to seach for
//				  Index		- Index of the ID Media Column in the Array
// Extrants		: Array of Araay of Parts
//-----------------------------------------------------------------
// History		:
// Date				Author			Comments
// ----------------	---------------	-------------------------------
// 2005-03-29		DenommeB		Creation
//-----------------------------------------------------------------
function GetPartArray(MediaID, Index, ControlName)
{
	var rtnArray = new Array();
	var PartIndex;
	PartIndex = 0;

	for(i=0; i< eval(ControlName + 'DataSourcePart').length; i++)
	{

		if(eval(ControlName + 'DataSourcePart')[i][Index] == MediaID)
		{
			rtnArray[PartIndex] = eval(ControlName + 'DataSourcePart')[i];
			PartIndex ++;
		}
	}

	return rtnArray;
}
//-----------------------------------------------------------------
// Name			: LoadMediaValue
// Description	: Load the Media Section (Title and Description)
//-----------------------------------------------------------------
// Intrants		: ControlName - Name of the Media Control
// Extrants		: None
//-----------------------------------------------------------------
// History		:
// Date				Author			Comments
// ----------------	---------------	-------------------------------
// 2005-03-24		DenommeB		Creation
//-----------------------------------------------------------------
function LoadMediaValue(ControlName)
{
	//-------------------------------------------------------------
	// Extract the Title Control
	//-------------------------------------------------------------
	var Title;
	Title = document.getElementById(eval(ControlName + 'TitleName'));

	//-------------------------------------------------------------
	// Extract the Description Control
	//-------------------------------------------------------------
	var Description;
	Description = document.getElementById(eval(ControlName + 'DescriptionName'));

	//-------------------------------------------------------------
	// Extract the Media DropDown Control
	//-------------------------------------------------------------
	var Media;
	Media = document.getElementById(eval(ControlName + 'MediaName'));

	//-------------------------------------------------------------
	// Extract the Media.SelectedValue
	//-------------------------------------------------------------
	var SelectedMediaID;
	if(Media.selectedIndex > -1)
	{
		SelectedMediaID = Media.options[Media.selectedIndex].value;

		//-------------------------------------------------------------
		// Find The Array to load the data From
		//-------------------------------------------------------------
		var DataSource;
		DataSource = FindArray(eval(ControlName + 'DataSourceMedia'), SelectedMediaID, 0);

		//-------------------------------------------------------------
		// Set the Title from the Array (DataSource)
		//-------------------------------------------------------------
		Title.value = DataSource[1];

		//-------------------------------------------------------------
		// Set the Description from the Array (DataSource)
		//-------------------------------------------------------------
		Description.value = DataSource[2];

		//-------------------------------------------------------------
		// Load the Part DropDown List Childs
		//-------------------------------------------------------------
		LoadPartDropDown(ControlName);
	}	
}
//-----------------------------------------------------------------
// Name			: LoadPartDropDown
// Description	: Load the Part DropDownList Control from the Media
//				  DropDown Control Selected Value
//-----------------------------------------------------------------
// Intrant		: MediaID	- Selected MediaID
// Extrants		: None
//-----------------------------------------------------------------
// History		:
// Date				Author			Comments
// ----------------	---------------	-------------------------------
// 2005-03-24		DenommeB		Creation
//-----------------------------------------------------------------
function LoadPartDropDown(ControlName)
{
	//-------------------------------------------------------------
	// Extract the Part DropDown Control
	//-------------------------------------------------------------
	var Part;
	Part = document.getElementById(eval(ControlName + 'PartName'));

	//-------------------------------------------------------------
	// Extract the Media DropDown Control
	//-------------------------------------------------------------
	var Media;
	Media = document.getElementById(eval(ControlName + 'MediaName'));

	//-------------------------------------------------------------
	// Clear the Part DropDown Content
	//-------------------------------------------------------------
	ClearDropDownList(eval(ControlName + 'PartName'));

	//-------------------------------------------------------------
	// Extract the Media DropDown Control
	//-------------------------------------------------------------
	var Media;
	Media = document.getElementById(eval(ControlName + 'MediaName'));

	//-------------------------------------------------------------
	// Extract the Media.SelectedValue
	//-------------------------------------------------------------
	var SelectedMediaID;
	SelectedMediaID = Media.options[Media.selectedIndex].value;

	//-------------------------------------------------------------
	// Extract The Child Parts assoicated with the selected mediaID
	//-------------------------------------------------------------
	var DataSource = new Array();
	DataSource = GetPartArray(SelectedMediaID, 0, ControlName);

	//-------------------------------------------------------------
	// Fill the Part DropDown Control
	//-------------------------------------------------------------
	LoadDropDownList(eval(ControlName + 'PartName'), DataSource, 2, 1);

	//-------------------------------------------------------------
	// Refresh the Part Section Information
	//-------------------------------------------------------------
	LoadPartValue(ControlName);
}
//-----------------------------------------------------------------
// Name			: LoadPartValue
// Description	: Load the Part Section (link, FileNameMed, 
//				  FileNameHigh, MediaTpe)
//-----------------------------------------------------------------
// Intrants		: None
//				  DataSource - Array of Media/Aprt Values
// Extrants		: None
//-----------------------------------------------------------------
// History		:
// Date				Author			Comments
// ----------------	---------------	-------------------------------
// 2005-03-24		DenommeB		Creation
//-----------------------------------------------------------------
function LoadPartValue(ControlName)
{
	//-------------------------------------------------------------
	// Extract the Link Control
	//-------------------------------------------------------------
	var Link;
	Link = document.getElementById(eval(ControlName + 'LinkName'));

	//-------------------------------------------------------------
	// Extract the FileNameMed Control
	//-------------------------------------------------------------
	var FileNameMed;
	FileNameMed = document.getElementById(eval(ControlName + 'FileNameMedName'));

	//-------------------------------------------------------------
	// Extract the FileNameHigh Control
	//-------------------------------------------------------------
	var FileNameHigh;
	FileNameHigh = document.getElementById(eval(ControlName + 'FileNameHighName'));

	//-------------------------------------------------------------
	// Extract the MediaType Control
	//-------------------------------------------------------------
	var MediaType;
	MediaType = document.getElementById(eval(ControlName + 'MediaTypeName'));

	//-------------------------------------------------------------
	// Extract the Part DropDown Control
	//-------------------------------------------------------------
	var Part;
	Part = document.getElementById(eval(ControlName + 'PartName'));

	//-------------------------------------------------------------
	// Extract the File Medium Source DropDown Control
	//-------------------------------------------------------------
	var FileSourceMedium;
	FileSourceMedium = document.getElementById(eval(ControlName + 'FileSourceMediumName'))

	//-------------------------------------------------------------
	// Extract the File Higj Source DropDown Control
	//-------------------------------------------------------------
	var FileSourceHigh;
	FileSourceHigh = document.getElementById(eval(ControlName + 'FileSourceHighName'))

	//-------------------------------------------------------------
	// Extract the Part.SelectedValue
	//-------------------------------------------------------------
	var SelectedPartID;
	if(Part.selectedIndex > -1)
	{

		SelectedPartID = Part.options[Part.selectedIndex].value;
		//-------------------------------------------------------------
		// Extract the DataSource from the Part Array
		//-------------------------------------------------------------
		var DataSource;
		DataSource = FindArray(eval(ControlName + 'DataSourcePart'), SelectedPartID, 1);		
	
		//-------------------------------------------------------------
		// Set the Link Value from the Array (DataSource)
		//-------------------------------------------------------------
		Link.value = DataSource[2];

		//-------------------------------------------------------------
		// Set the FileNameMed Value from the Array (DataSource)
		//-------------------------------------------------------------
		FileNameMed.value = DataSource[3];

		//-------------------------------------------------------------
		// Set the FileNameHigh Value from the Array (DataSource)
		//-------------------------------------------------------------
		FileNameHigh.value = DataSource[4];

		//-------------------------------------------------------------
		// Set the MediaType Value from the Array (DataSource)
		//-------------------------------------------------------------
		MediaType.selectedIndex	= DataSource[5]-1;

		//-------------------------------------------------------------
		// Set the FileSourceMedium Value from the Array (DataSource)
		//-------------------------------------------------------------
		FileSourceMedium.selectedIndex	= DataSource[6]-1;

		//-------------------------------------------------------------
		// Set the FileSourceHigh Value from the Array (DataSource)
		//-------------------------------------------------------------
		FileSourceHigh.selectedIndex = DataSource[7]-1;

	}
	else
	{
		Link.value = "";
		FileNameMed.value = "";
		FileNameHigh.value = "";
		MediaType.selectedIndex	= 0;
		FileSourceMedium.selectedIndex = 0;
		FileSourceHigh.selectedIndex = 0;
	};
}
//-----------------------------------------------------------------
// Name			: ValidateMedia
// Description	: Validate The BR for for the Media Section
//-----------------------------------------------------------------
// Intrants		: None
// Extrants		: True if the BR are valid
//-----------------------------------------------------------------
// History		:
// Date				Author			Comments
// ----------------	---------------	-------------------------------
// 2005-03-30		DenommeB		Creation
//-----------------------------------------------------------------
function ValidateMedia(EditMode,ControlName)
{

	var strMessage;
	strMessage = "";

	var HasError;
	HasError = false;

	//-----------------------------------------------------------------
	// The Title is mandatory (Add + Modify)
	//-----------------------------------------------------------------
	if(document.getElementById(eval(ControlName + 'TitleName')).value == "" && (EditMode == "Add" || EditMode == "Modify"))
	{
		strMessage = "The Media 'Title' is mandatory.";
		HasError = true;
	}

	//-----------------------------------------------------------------
	// The Description is mandatory (Add + Modify)
	//-----------------------------------------------------------------
	if(document.getElementById(eval(ControlName + 'DescriptionName')).value == "" && (EditMode == "Add" || EditMode == "Modify"))
	{
		strMessage = strMessage + "\nThe Media 'Title' is mandatory.";
		HasError = true;
	}

	//-----------------------------------------------------------------
	// An Element must be selected in MediaList (Modify + Delete)
	//-----------------------------------------------------------------
	if(document.getElementById(eval(ControlName + 'MediaName')).selectedIndex < 0 && (EditMode == "Modify" || EditMode == "Delete"))
	{
		if(strMessage != "")
		{
			strMessage = strMessage + "\n";
		}

		strMessage = strMessage + "You must select a 'Media' in the Media List.";
		HasError = true;
	
	}

	if(HasError == true)
	{
		alert(strMessage);
		return false;
	}
	else
	{
		return true;
	};

}
//-----------------------------------------------------------------
// Name			: ValidatePart
// Description	: Validate The BR for for the Part Section
//-----------------------------------------------------------------
// Intrants		: None
// Extrants		: True if the BR are valid
//-----------------------------------------------------------------
// History		:
// Date				Author			Comments
// ----------------	---------------	-------------------------------
// 2005-03-30		DenommeB		Creation
//-----------------------------------------------------------------
function ValidatePart(EditMode,ControlName)
{

	var strMessage;
	strMessage = "";

	var HasError;
	HasError = false;

	//-----------------------------------------------------------------
	// The Link is mandatory (Add + Modify)
	//-----------------------------------------------------------------
	if(document.getElementById(eval(ControlName + 'LinkName')).value == "" && (EditMode == "Add" || EditMode == "Modify"))
	{
		strMessage = "The Part 'Description' is mandatory.";
		HasError = true;
	}

	//-----------------------------------------------------------------
	// The FileNameMedium is mandatory (Add + Modify)
	//-----------------------------------------------------------------
	if(document.getElementById(eval(ControlName + 'FileNameMedName')).value == "" && (EditMode == "Add" || EditMode == "Modify"))
	{
		strMessage = strMessage + "\nThe Part 'FileName Medium' is mandatory.";
		HasError = true;
	}

	//-----------------------------------------------------------------
	// The FileNameHigh is mandatory (Add + Modify)
	//-----------------------------------------------------------------
	if(document.getElementById(eval(ControlName + 'FileNameHighName')).value == "" && (EditMode == "Add" || EditMode == "Modify"))
	{
		strMessage = strMessage + "\nThe Part 'FileName High' is mandatory.";
		HasError = true;
	}

	//-----------------------------------------------------------------
	// An Element must be selected in PartList (Modify + Delete)
	//-----------------------------------------------------------------
	if(document.getElementById(eval(ControlName + 'PartName')).selectedIndex < 0 && (EditMode == "Modify" || EditMode == "Delete"))
	{
		if(strMessage != "")
		{
			strMessage = strMessage + "\n";
		}

		strMessage = strMessage + "You must select a 'Part' in the Parts List.";
		HasError = true;
	
	}

	//-----------------------------------------------------------------
	// An Element must be selected in MediaList (Add)
	//-----------------------------------------------------------------
	if(document.getElementById(eval(ControlName + 'MediaName')).selectedIndex < 0 && (EditMode == "Add"))
	{
		if(strMessage != "")
		{
			strMessage = strMessage + "\n";
		}

		strMessage = strMessage + "You must select a 'Media' in the Media List.";
		HasError = true;
	
	}

	if(HasError == true)
	{
		alert(strMessage);
		return false;
	}
	else
	{
		return true;
	};
}