function SetFocus(Id) 
{
	if (document.getElementById(Id) != null)
		document.getElementById(Id).focus();
}

function CheckSelectedCategory()
{ 
	SetFocus("CategoryName");
	SetFocus("ProductName");	
}

function SetImage(Id, Img) 
{ 
	//safe function to hide an element with a specified id
	if (document.getElementById) 
	{ // DOM3 = IE5, NS6
		if (document.getElementById(Id) != null)
			document.getElementById(Id).src = Img;
	}
	else 
	{
		if (document.layers) 
		{ // Netscape 4
			if (document.Id != null)
				document.Id.src = Img;
		}
		else 
		{ // IE 4
			if (document.all.Id != null)
				document.all.Id.src = Img;
		}
	}
}

function handleOver(Id, Img) 
{
	SetImage(Id, Img)
}

function handleOut(Id, Img) 
{
	SetImage(Id, Img);	
}

<!-- //
function addToFavorites(Title) 
{ 
	var title = Title; //document.title;
	var url = location.href;	

	if (window.sidebar) 
	{ // Mozilla Firefox Bookmark		
		window.sidebar.addPanel(title, url, "");	
	} 
	else if (window.external) 
	{ // IE Favorite		
		window.external.AddFavorite(url, title); 
	}	
	else if(window.opera && window.print) 
	{ // Opera Hotlist		
		return true; 
	}
} // -->

function OpenPopUp(Img) 
{
	if ( Img != "" ) 
	{
		var height = 500;
		var width  = 700;
		URL 		     = "/database.php/product/product_frontend/showpicture/" + Img;
		PageName     = "PopUp";
		var winl     = (screen.width  - width) / 2;
		var wint     = (screen.height - height) / 2;
		Parameters   = 'height=' + height + ',width=' + width + ',top=' + wint + ',left=' + winl + ',resizable=0';
		Parameters   += ',toolbar=0,location=0,directories=0,status=0,fullscreen=no,menubar=0,scrollbars=0';
		window.open(URL, PageName, Parameters);
	}
}

function OpenWindowToPrint(Id, Img) 
{
	if ( Id != "" ) 
	{
		if ( Img != null )
			Img = "/" + Img;
		else
			Img = "";
		
		var height = 500;
		var width  = 700;
		URL 		     = "/database.php/product/product_frontend/printproduct/" + Id + Img;
		PageName     = "PopUp";
		var winl     = (screen.width  - width) / 2;
		var wint     = (screen.height - height) / 2;
		Parameters   = 'height=' + height + ',width=' + width + ',top=' + wint + ',left=' + winl + ',resizable=0';
		Parameters   += ',toolbar=0,location=0,directories=0,status=0,fullscreen=no,menubar=0,scrollbars=0';
		window.open(URL, PageName, Parameters);
	}
}

function EmailProduct(Id) 
{
	if ( Id != "" ) 
	{
		var height = 600;
		var width  = 630;
		URL 		     = "/database.php/product/product_frontend/emailproduct/" + Id;		
		PageName     = "PopUp";
		var winl     = (screen.width  - width) / 2;
		var wint     = (screen.height - height) / 2;
		Parameters   = 'height=' + height + ',width=' + width + ',top=' + wint + ',left=' + winl + ',resizable=0';
		Parameters   += ',toolbar=0,location=0,directories=0,status=0,fullscreen=no,menubar=0,scrollbars=1';
		window.open(URL, PageName, Parameters);
	}
}

function ChangePicture(Img) 
{
	SetImage("SelectedImg", "/images/" + Img);
}

// Check to see the all the required fields were filled by the user.
function CheckRequiredFields()
{
	// It needs to go through the whole collection.
  for (var I = 0; I < CheckRequiredFields.arguments.length; I++)
	{
		var ElementId = CheckRequiredFields.arguments[I];
		if (document.getElementById(ElementId))
		{
			if (document.getElementById(ElementId).value == "")
			{
				// Show a message to inform the user that this field is required.
				ShowMSG("Error" + ElementId, "This is a required field.");
				// Set the focus on the element that was not filled.
				SetFocus(ElementId)
				// It means this field was not filled.
				return false;
			}
			else
			{
				// Show a message to inform the user that this field is required.
				ShowMSG("Error" + ElementId, "");
			}
		}
  }
	// If it reachs here it means all the fields were filled by the user.
	return true;
}
function ShowMSG(Id, MSG)
{
	//safe function to hide an element with a specified id
	if (document.getElementById) 
	{ // DOM3 = IE5, NS6
		if (document.getElementById(Id) != null)
			    document.getElementById(Id).innerHTML = MSG;
	}
	else 
	{
		if (document.layers) 
		{ // Netscape 4
			if (document.Id != null)
				document.Id.innerHTML = MSG;
		}
		else 
		{ // IE 4
			if (document.all.Id != null)
				document.all.Id.innerHTML = MSG;
		}
	}
}