var FI = 0x01; // type: decimal
var FS = 0x02; // type: text
var FT = 0x04; // type: textarea
var VN = 0x10; // validate non-empty
var VP = 0x20; // validate phone
var VE = 0x40; // validate email

var FM = (FI|FS|FT);
var VM = (VP|VE);

function fsubmit(ctlist, form) 
{
	var r = true;
	for (i = 0; i < ctlist.length; i++)
	{
		var f = ctlist[i];
		var e = document.getElementById(f[1]);
		var v = e.value.replace(/^\s+|\s+$/g, '');
		var l = true;
		
		if (f[0] & VN) // non-empty
			l = (v != '');

		if (l && v != '')
		{	// type-validation
			switch (f[0] & VM) 
			{
				case VE:
					l = v.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/);
					break;
				default:
					break;
			}
		}
		if (f[2] != null)
		{
			var s = document.getElementById(f[2]);
			if (!l && r)
			{
				s.style.display = 'inline';
				e.focus();
				r = false;
			}
			else
			{
				s.style.display = 'none';
			}
		}
	}
	if (r)
		document.getElementById(form).submit();
	return false;
}

function fclear(ctlist)
{
	for (i = 0; i < ctlist.length; i++)
	{
		var f = ctlist[i];
		var e = document.getElementById(f[1]);
		switch (f[0] & FM)
		{
			case FS:
			case FT:
				e.value = "";
				break;
		}
	}
	return false;
}

