/* 
  Global JavaScript File
  It contains the commum script for the whole web site.
  Author    : Luciano Sampaio Martins de Souza
  Date      : 08/22/2007
  Version   : 1.0
  Copyright : ApolloMedia Inc
  Web Site  : www.apollomedia.ca
*/
// it says to the browser if any error occurs in the page, call this method.
window.onerror = HandleAllErrors;

// Check if is Internet Explorer IE ou FireFox FF.
var isIE = ( navigator.appName.indexOf("Netscape") == -1 );

// Handle the errors and don't stop the flow of the page to keep going.
function HandleAllErrors(msg, url, line)
{
	ShowErrorMessage(msg, url, line);
	return true;
}
// Show the message to the user.
function ShowErrorMessage(msg, url, line)
{
  alert("Error: " + msg + "\nUrl: "  + url + "\nLine: " + line);		
}
// Set the focus on the element.
function SetFocus(Id)
{
  if (document.getElementById(Id))
  {
    if (document.getElementById(Id).select)
			document.getElementById(Id).select();
    if (document.getElementById(Id).focus)
			document.getElementById(Id).focus();
  }
}
// Show a message to the user.
function ShowMSG(Id, MSG)
{
  if (document.getElementById(Id))
  {
    document.getElementById(Id).innerHTML = MSG;
  }
}
// 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;
}