// Javascritpt Functions
// Description: All functions are used for managing hot products in the list at 
//              the editing first page.
// Version: Patch 022
// Last update: 12 April 2006

function isItemExist(objList,vList)
{
	var numList	=	objList.length;
	var isFound =   false;
	for( var i=0; i<numList; i++ )
	{
		if( objList.options[i].value == vList )
		{
			isFound = true;
			break;
		}
	}
	return isFound;
}
function isMaxList(objList)
{
	if( objList.length == 6 )
		return true;
	else
		return false;
}
function allSelected(objList)
{
  if (objList.length == 0)
	  return;
  for (i=0;i<objList.length;i++)
  {
     objList.options[i].selected = true;
  }
}

function addItem(sList,dList)
{
	var sID 		= sList.selectedIndex;
	var sTxt; 
	var sValue;
	var current_dID	= dList.length;
	
	if( sID < 0 ) // Make sure that there is a selected item.
	{
		alert("To add an item, plese select an item.");
	}
	else
	{
		sValue 		= sList.options[sID].value;
		sTxt		= sList.options[sID].text;
		if( !isItemExist(dList,sValue) )
		{
			if( !isMaxList(dList) )
			{
				newOption = new Option(sTxt, sValue, false, false);
				dList.options[current_dID] = newOption;	
			}
			else
			{
				alert("The maximum number of items was reached.");
			}
		}
		else
		{
			alert("An selected item was already in the list.");
		}
	}
}
function removeItem(dList)
{
	var dID		= dList.selectedIndex;
	var dTxt;
	if( dID < 0 ) // Make sure that there is a selected item.
	{
		alert("To remove an item, plese select an item.");
	}
	else
	{
		dList.options[dID] = null;
	}
}

function submitFront(obj)
{
	allSelected(obj);
	var hot = new Array(6);
	hot[0] = '';
	hot[1] = '';
	hot[2] = '';
	hot[3] = '';
	hot[4] = '';
	hot[5] = '';
	
	for (var i = 0; i < obj.length; i++) 
	{          
			hot[i] = obj.options[i].value;
		
	}
    updateRTEs();
	frontForm.action = "makefront.php?h1="+hot[0]+"&h2="+hot[1]+"&h3="+hot[2]+"&h4="+hot[3]+"&h5="+hot[4]+"&h6="+hot[5];
	frontForm.submit();

}