
function SetFocus () 
{
	// Do these tests to avoid errors on the pages that doesn't have the form.
	if (document.ContactUs !== null)
	{
		if (document.ContactUs.btnSubmit !== null)
		{
			// Go first to the button.
			document.ContactUs.btnSubmit.focus();
		}
		if (document.ContactUs.Title !== null)
		{
			// Then to the textbox.
			document.ContactUs.Title.focus();
		}
	}
}

// Set the focus on the element.
function SetFocusById(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;
  }
}
// Show a message to the user.
function SetValue(Id, MSG)
{
  if (document.getElementById(Id))
  {
    document.getElementById(Id).value = 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 < arguments.length; I++)
	{
		var ElementId = arguments[I];
		if (document.getElementById(ElementId))
		{
			if ( (document.getElementById(ElementId).style.display != "none") && (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.
				SetFocusById(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 ShowHideObject(Id, Type) 
{ 
	//safe function to hide an element with a specified id
	if (document.getElementById) 
	{ // DOM3 = IE5, NS6
		if (document.getElementById(Id) !== null) 
		{
			document.getElementById(Id).style.display = Type;
		}
	}
	else 
	{
		if (document.layers) 
		{ // Netscape 4
			if (document.Id !== null) 
			{
				document.Id.display = Type;
			}
		}
		else 
		{ // IE 4
			if (document.all.Id !== null) 
			{
				document.all.Id.style.display = Type;
			}
		}
	}
}

function ShowHideOtherOptions(ElementId, OtherElementId)
{
	if (document.getElementById(ElementId).value == "Other")
	{
		// Make it visible.
		Type = "block";
	}
	else
	{
		// Make it hidden.		
		Type = "none";
		SetValue(OtherElementId, "");
	}	
	ShowHideObject(OtherElementId, Type);
	if (Type != "none") 
	{
		SetFocusById(OtherElementId);
	}
}