function numbersOnly(myfield, e, dec)
{
	var key;
	var keychar;
	if (window.event)
	{	
		key = window.event.keyCode;
	}
	else if (e)
	{
	   key = e.which;
	}else
	{
		return true;
	}
	
	
	keychar = String.fromCharCode(key);
	
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
	return true;
	
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
		return true;
	
	// decimal point jump
	else if (dec && (keychar == "."))
		{
		myfield.form.elements[dec].focus();
		return false;
		}
	else
return false;
}


function validateForm()
{




	var f = document.forms['contactForm'];	// f = the form
	var errorMessagePrefix = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"border:1px solid #BF3636; margin-left:30px; margin-bottom:15px;\"><tr><td valign=\"top\"><img src=\"images/error.jpg\" alt=\"Error\" /></td><td><div class=\"errorBoxText\">Sorry, your enquiry can not be sent until you complete the following fields...<br /><strong>";
	var errorMessageSuffix = "</strong><br />Incomplete fields are marked like this <span class=\"required\">*</span>.</div></td></tr></table>";
	var errors = "";						// reset errors
	var outputStr = "";
	var info = document.getElementById('formErrors');
	
	var emailFilter= /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
	
	// Check first name
	if( f['firstName'].value.length < 1)
	{
		errors += 'First Name. ';
		f['firstName'].parentNode.className = 'incompleteForm';
	}
	else
	{
		f['firstName'].parentNode.className = 'completedForm';
	}
	
	// Check last name
	if( f['lastName'].value.length < 1)
	{
		errors += 'Last Name. ';
		f['lastName'].parentNode.className = 'incompleteForm';
	}
	else
	{
		f['lastName'].parentNode.className = 'completedForm';
	}
	
	
	// Check Email
	if( !(emailFilter.test(f['email'].value)) )
	{
		errors += 'Email address. ';
		f['email'].parentNode.className = 'incompleteForm';
	}
	else
	{
		f['email'].parentNode.className = 'completedForm';
	}
	
	// Check message
	if (f['message'].value.length < 1)
	{
		errors += 'Message. ';
		f['message'].parentNode.className = 'incompleteForm';
	}else
	{
		f['message'].parentNode.className = 'completedForm';
	}
	
	// Check Security Code
	if( f['code'].value.length < 1)
	{
		errors += 'Security Code. ';
		f['code'].parentNode.className = 'incompleteForm';
	}
	else
	{
		f['code'].parentNode.className = 'completedForm';
	}
	
	if(Number(f['quantity'].value) > 0)
	{
		// Check address
		if( f['stAddress'].value.length < 5)
		{
			errors += 'Street Address. ';
			f['stAddress'].parentNode.className = 'incompleteForm';
		}
		else
		{
			f['stAddress'].parentNode.className = 'completedForm';
		}
		
		if( f['suburb'].value.length < 2)
		{
			errors += 'Suburb. ';
			f['suburb'].parentNode.className = 'incompleteForm';
		}
		else
		{
			f['suburb'].parentNode.className = 'completedForm';
		}
		
		// Check city
		if( f['city'].value.length < 3)
		{
			errors += 'City. ';
			f['city'].parentNode.className = 'incompleteForm';
		}
		else
		{
			f['city'].parentNode.className = 'completedForm';
		}
	}
	
	// Check if we have encountered any errors?
	if ( errors.length > 0)
	{
		outputStr = errorMessagePrefix + errors + errorMessageSuffix;
		
		while(info.childNodes.length)
		{
			info.removeChild(info.childNodes[0]);
		}
		
		info.innerHTML = outputStr;
		info.className = 'infoBox';
		info.style.display = "block";
		return false;
	}
	else
	{
		outputStr = "";
		info.innerHTML = outputStr;
		info.style.display = "none";
		return true;
	}
}


function clearForm()
{
	var f = document.forms['contactForm'];	// f = the form
	
	var divs = f.getElementsByTagName('DIV')
	var d;
	
	for ( var i=0; i<divs.length; i++ )
	{
		d = divs[i];
		if(d.className == 'incompleteForm' || d.className == 'completedForm')
		{
			d.className = null;
		}
	}
	
	var errors = document.getElementById('formErrors');
	errors.style.display = 'none';
	
	var pa = document.getElementById('postalAddress');
	pa.style.display = 'none';

	return true;
}


function updateQuantity(q)
{
	var pa = document.getElementById('postalAddress');
	
	if(Number(q.value) > 0)
	{
		pa.style.display = 'block';
	}else
	{
		pa.style.display = 'none';
		var ids = [document.getElementById('stAddress'), document.getElementById('suburb'), document.getElementById('city')];
		for(var i=0; i<ids.length; i++)
		{
			ids[i].parentNode.className = null;
		}
	}
	return true;
}