$(function(){
	// Register alert window.
  $('#alert').jqm();
	// Register RTE CSS.
	$('.rte-zone').rte('/css/jqRTE.css');

	// Automatic form validation.
	$("form").submit(function(){
		return validate(this);
	});
	
	// Automatically add appropriate odd/even classes for table rows.
	var i = 0;
	$("table").find("tr").each(function(){
		if (i > 0)
		{
			if ((i % 2) == 0)
			{
				$(this).addClass("even");
			}
			else
			{
				$(this).addClass("odd");
			}
		}
		i++;
	});
});

// Override default alert function.
function alert(strTitle, strMessage) {
  $('#alert').jqmShow();
  $('#alert').find('#jqmAlertTitleContent').html(strTitle);
  $('#alert').find('div.jqmAlertContent').html(strMessage);
}

// Explain form elements.
function explain(strElement)
{
	var strTitle = "";
	var strContent = "";
	if (strElement.search("dat_") != -1)
	{
		strTitle = "Date";
		strContent = "This field expects a date in the format 'DD/MM/YYYY'.";
	}
	else if (strElement.search("num_") != -1)
	{
		strTitle = "Numeric";
		strContent = "This field expects any positive number.";
	}
	else if (strElement.search("eml_") != -1)
	{
		strTitle = "Email";
		strContent = "This field expects an email address in the format 'someone@somewhere.com'.";
	}
	else if (strElement.search("url_") != -1)
	{
		strTitle = "URL";
		strContent = "This field expects an URL in the format 'http://www.somewhere.com/'.";
	}
	else
	{
		strTitle = "Text";
		strContent = "This field expects any type of alphanumeric input.";
	}				
	if (strElement.search("req_") == 0)
	{
		strContent += "<br>This field must be completed before the form can be successfully processed.";
	}
	strTitle += " Field";
	alert(strTitle, strContent);
	return false;
}