/*
Required Form Attribute
	onSubmit="return valid(this);"

Extend input tags to contain:

	notRequired - The user is not required to enter data into this field
	numerical		-	This input must contain numberical digits only

An input with the id = "emailTo" is checked for a correct email format
*/

function valid(myForm)
{
	for(var mainInputNo = 0; mainInputNo < myForm.elements.length; mainInputNo++)
	{
		var mainInput = myForm.elements[mainInputNo];

		if ( (mainInput.value == "") && ( (mainInput.notRequired == undefined) || (mainInput.notRequired == "false") ) )
		{
		  alert("please enter a value for " + mainInput.name);
		  mainInput.focus();

		  return false;
		}

		// at this point we only have fields that have value or are not required

		if (mainInput.id == "emailTo")
		{
			if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mainInput.value)))
			{
				alert("Email format incorrect.");
				mainInput.focus();

				return false;
			}
		}

		if ( (mainInput.numerical != undefined) && (!(/\d+/.test(mainInput.value))) )
		{
		  alert(mainInput.name + " must contain numerical characters only");
		  mainInput.focus();

		  return false;
		}
	}

	return true;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function changeWindowStatus(string) { //function to format the window.status
	//the XSLt processor is sending us &amp;amp; so using frontend JS to sort out
	if(string=="") {
		window.status='The Alexander Beard Group Plc.';
	}
	else {
		window.status=string.replace('amp;','');
	}
}

function hideShowSubMenus(id) { //function to hide/show submenu rows
	if(document.getElementById(id).style.display != "block") {
		document.getElementById(id).style.display = "block";
	}
	else {
		document.getElementById(id).style.display = "none";
  }
}

function winpop(url,width,height)
{
	window.open(url,'newwindow','height='+height+',width='+width+',left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
	//if (window.focus) {newwindow.focus()}
}