//editme - perhaps it can be done better than this
document.getElementById("loading").style.display="block";

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
	window.onload = func;
  } else {
	window.onload = function() {
	  if (oldonload) {
		oldonload();
	  }
	  func();
	}
  }
}

addLoadEvent(function() {
  document.getElementById("loading").style.display="none";
});

//FROM PRODUCTS PAGES - WHERE VIDEOS ARE INCLUDED
function popPresentation(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=640,height=515,left = 320,top = 142.5');");
}
// By suppling no content attribute, the library uses each elements title attribute by default

// VALIDATE CONTACT FORM
function validate_required(field,alerttxt)
{
	with (field)
	{
	if (value==null||value=="")
	  {alert(alerttxt);return false}
	else {return true}
	}
}
function validate_email(field,alerttxt)
{
	with (field)
	{
	apos=value.indexOf("@")
	dotpos=value.lastIndexOf(".")
	if (apos<1||dotpos-apos<2) 
	  {alert(alerttxt);return false}
	else {return true}
	}
} 
function validate_form(thisform)
{
	
	var tab = $("input[name='tab']").val();
	if (tab == "problem")
	{
		if ($('select[name="sel_problem"] option:selected').val() == "")
		{
			alert("Please select a topic first");
			$('select[name="sel_problem"]').focus();
			return false;
		}
		var opt_name = $('select[name="sel_problem"] option:selected').attr("name");
		
		if (opt_name)
		{
			if ($('select[name="products"] option:selected').val() == "")
			{
				alert("Specify the product in question");
				$('select[name="products"]').focus();
				return false;
			}
		}
	}
	
	with (thisform)
	{
	if (validate_email(email,"Enter your email address")==false)
	  {email.focus();return false}
	if (validate_required(msg,"The message appears to be empty. Please write a few sentences.")==false)
	  {msg.focus();return false}
	}
}
