function validatePostCode(s)
{
	if(s['length']!=6)return false;
	var OK=true;
	for(var i=0;i<3;i++)OK=/[A-Z]/['test'](s[2*i])&&(/[0-9]/['test'](s[2*i+1]))&&OK;
	return OK;
}

function trimAll( strValue )
{
 var o = /^(\s*)$/;
    //check for all spaces
    if(o.test(strValue)) {
       strValue = strValue.replace(o, '');
       if( strValue.length == 0)
          return strValue;
    }
   //check for leading & trailing spaces
   o = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(o.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(o, '$2');
    }
  return strValue;
}
function validateField(name,val)
{ // The string should start with a bunch of alphanumerical (letters or numbers), underscores, dots or dashes
	var OK;
	switch(name)
	{
		case 'PostalCode': OK=validatePostCode(val['toUpperCase']()['split']('')); break;
		default: OK=val['length'];
	}
	if(!OK)alert(name+' is required.');
	return OK;
}
function ValidateForm(form)
{
	var val, OK=true;
	for(var i=0,l=form['length'];i<l;i++)
	{
		if(form[i]['type']=='select-one')
		{
			val=form[i].options[form[i].selectedIndex].text;
			if(val=='Select')val='';
		}
		else val=form[i]['value'];

		OK=OK&&validateField(form[i]['name'],trimAll(val));
	}
	return OK;
}