
function FldChk_byID_labels(flds, labels )
{
	for( i=0; i < flds.length; i++ )
	{
		box = document.getElementById( flds[i] );
		if( box.type=="text" || box.type=='textarea' || box.type=="password" )
		{
			if(box.value=='')
			{
				alert("Please fill in this required field: " + labels[i] );
				box.focus();
				return false;
			}
		}
		else if(box.type=="select-one")
		{
			seltext = box.options[box.selectedIndex].value;
			if(seltext==0 || seltext=='')
			{
				alert("Please select an option in this required field: " + labels[i]);
				box.focus();
				return false;
			}
		}
	}

	return true;
}

function Clear_Form( form_name )
{
	formObj = document.getElementById( form_name );

	for( i=0; i < formObj.length; i++ )
	{
		box = formObj[i];

		if( box.type == 'select-one' )
		{
			box.selectedIndex = 0;
		}
		else if( box.type == 'radio' || box.type == 'checkbox' )
		{
			box.checked = false;
		}
		else if( box.type != 'button' )
		{
			box.value = '';
		}
	}
}

function validateForm( field, tld )
{
	box = document.getElementById( field );
	var dot    = new RegExp("\\.");
	var domfp  = new RegExp("(^[a-zA-Z0-9]+$)|(^[a-zA-Z0-9]+[a-zA-Z0-9\-]+[a-zA-Z0-9]$)");
	var dom    = new RegExp("^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$");

	if( tld ) // check for TLD
	{
		if( box.value=='' )
		{
			alert("Please type in the first part of your\ndomain name including .com.au etc)");
			box.focus();
			return false;
		}

		if( !box.value.match(dom) || !box.value.match(dot) )
		{
			alert("Please include the domain suffix (eg .com.au)");
			box.focus();
			return false;
		}

	}
	else // here we dont want the TLD
	{
		if( box.value=='' )
		{
			alert("Please type in the first part of your\ndomain name (not including .com.au etc)");
			box.focus();
			return false;
		}

		if( box.value.match(dot) )
		{
			alert("Please do not include the domain suffix .com.au etc\nselect your domain suffix from the box below");
			box.focus();
			return false;
		}

		if( !box.value.match(domfp) )
		{
			alert("Domain appears to be invalid");
			box.focus();
			return false;
		}
	}

	return true;
}