		function getObject(sFieldName, dDocument)
		{
			var nPos,nIndex,sObject;
			if (!dDocument)
			{
				dDocument = document;
			}
			if ((nPos = sFieldName.indexOf("?")) > 0 && parent.frames.length)
			{
				dDocument = parent.frames[sFieldName.substring(nPos+1)].document;
				sFieldName = sFieldName.substring(0,nPos);
			}
			if (!(sObject = dDocument[sFieldName]) && dDocument.all)
			{
				sObject = dDocument.all[sFieldName];
			}
			for (nIndex = 0; !sObject && nIndex < dDocument.forms.length; nIndex++)
			{
				sObject = dDocument.forms[nIndex][sFieldName];
			}
			for (nIndex = 0; !sObject && dDocument.layers && nIndex < dDocument.layers.length; nIndex++)
			{
				sObject = getObject(sFieldName, dDocument.layers[nIndex].document);
			}
			return sObject;
		}
		
		function stringReplace(sString, sReplaceWhat, sWithWhat)
		{
			var nPos = 0;
			var nLen = sReplaceWhat.length;
			nPos = sString.indexOf(sReplaceWhat);
			while (nPos != -1)
			{
				preString = sString.substring(0, nPos);
				postString = sString.substring(nPos+nLen, sString.length);
				sString = preString + sWithWhat + postString;
				nPos = sString.indexOf(sReplaceWhat);
			}
			return sString;
		}
		
		errors='';
		
		function validateField()
		{
			var nIndex,nPos,fieldName,validationRule,nNumber,nMinimum,nMaximum,args, nAux, bError, sFieldObj;
			args = validateField.arguments;
			for (nIndex = 0; nIndex < (args.length-2); nIndex += 3)
			{
				validationRule = args[nIndex+2]; fieldName = args[nIndex+1]; sFieldObj = getObject(args[nIndex]);
				validationRule = validationRule.toUpperCase();
				if (sFieldObj)
				{
					if (fieldName=='')
					{
						fieldName = sFieldObj.name;
					}
					sField = "";
					 //check the field if the it isn't null
					if ((sField = sFieldObj.value) != "")
					{	
						// check to see if it is a valid e-mail address
						if (validationRule.indexOf('ISEMAIL') != -1)
						{
							bError = false;
							sField = stringReplace(sField, ' ', '');
							//contains @
							nPos = sField.indexOf('@');
							if (nPos < 1 || nPos == (sField.length-1))
							{
								bError = true;
							}
							//contains at least one dot after the @
							nAux = nPos;
							nPos = sField.indexOf('.', nAux);
							if (nPos == -1)
							{
								bError = true;
							}
							if (bError)
							{
								errors += '- '+ fieldName +' must contain a valid e-mail address.\n';
							}
						}
						// check to see if it contains only spaces and digits
						if (validationRule.indexOf('ISDIGIT') != -1)
						{
							bError = false;
							//contains 0 on position 1
							nPos = sField.indexOf('0');
							if (nPos != 0)
							{
								bError = true;
							}
							//contains only digits and spaces
							for(var i = 0; i < sField.length; i++)
							var ch = sField.substring(i,i+1);
							if (ch<'0' || ch>'9')
							{
								if (ch !=' ')
								{
									bError = true;
								}
							}
							if (bError)
							{
								errors += '- '+ fieldName +' may only contain digits and spaces. The first digit must be 0 (zero)\n';
							}
						}
						// check to see if it is a valid positive number
						if (validationRule.indexOf('ISPOSITIVENUMBER') != -1)
						{
							bError = false;
							sField = stringReplace(sField, ' ', '');
							nNumber = parseFloat(sField);
							//if (sField != ''+nNumber)
							if (isNaN(sField) == true)
							{
								bError = true;
							}
							else
							{
								if (nNumber <= 0)
								{
									bError = true;
								}
							}
							if (sField=='') {bError = false;}
							if (bError)
							{
								errors += '- '+ fieldName +' must contain a valid value.\n';
							}
						}
						// check to see if it is a valid positive ans zero number
						if (validationRule.indexOf('ISPOSITIVEZERONUMBER') != -1)
						{
							bError = false;
							sField = stringReplace(sField, ' ', '');
							nNumber = parseFloat(sField);
							//if (sField != ''+nNumber)
							if (isNaN(sField) == true)
							{
								bError = true;
							}
							else
							{
								if (nNumber < 0)
								{
									bError = true;
								}
							}
							if (sField=='') {bError = false;}
							if (bError)
							{
								errors += '- '+ fieldName +' must contain a valid value.\n';
							}
						}
						// check to see if it is a valid negative number
						if (validationRule.indexOf('ISNEGATIVENUMBER') != -1)
						{
							bError = false;
							sField = stringReplace(sField, ' ', '');
							nNumber = parseFloat(sField);
							//if (sField != ''+nNumber)
							if (isNaN(sField) == true)
							{
								bError = true;
							}
							else
							{
								if (nNumber > 0)
								{
									bError = true;
								}
							}
							if (sField=='') {bError = false;}
							if (bError)
							{
								errors += '- '+ fieldName +' must contain a negative number.\n';
							}
						}
						// check to see if it is a valid number
						if (validationRule.indexOf('ISNUMBER') != -1)
						{
							bError = false;
							sField = stringReplace(sField, ' ', '');
							nNumber = parseFloat(sField);
							if (isNaN(sField) == true)
							{
								bError = true;
							}
							if (sField=='') {bError = false;}
							if (bError)
							{
								errors += '- '+ fieldName +' must contain a valid number.\n';
							}
						}
						// check to see if it is a valid number not equal to 0
						if (validationRule.indexOf('ISNOTNULLNUMBER') != -1)
						{
							bError = false;
							sField = stringReplace(sField, ' ', '');
							nNumber = parseFloat(sField);
							//if (sField != ''+nNumber)
							if (isNaN(sField) == true)
							{
								bError = true;
							}
							else
							{
								if (nNumber == 0)
								{
									bError = true;
								}
							}
							if (sField=='') {bError = false;}
							if (bError)
							{
								errors += '- '+ fieldName +' - Please select one...\n';
							}
						}
						// check to see if it is a valid password
						if (validationRule.indexOf('ISPASSWORD') != -1)
						{
							bError = false;
							if (sField.length<6)
							{
								bError = true;
							}
							else
							{
								for (i=0;i<sField.length;i++)
								{
									var sAux1 = sField.substring(i, i+1);
									if ((sAux1>='0' && sAux1<='9') || (sAux1>='A' && sAux1<='Z') || (sAux1>='a' && sAux1<='z'))
									{
										//OK
									}
									else
									{
										bError = true;
									}
								}
							}
							if (sField=='') {bError = false;}
							if (bError)
							{
								errors += '- '+ fieldName +' is invalid...\n';
							}
						}
						// check to see if it is a valid Date
						if (validationRule.indexOf('ISDATE') != -1)
						{
							var nDay, nMonth, nYear, sFindWhat;
							sFindWhat = '/';
							bError = false;
							
							sField = stringReplace(sField, ' ', '');
							var nPos = 0;
							nPos = sField.indexOf(sFindWhat);
							nDay = sField.substring(0, nPos);
							sField = sField.substring(nPos+1, sField.length);
							
							nPos = sField.indexOf(sFindWhat);
							nMonth = sField.substring(0, nPos);
							sField = sField.substring(nPos+1, sField.length);
							
							nYear = sField
							
							nDay = parseInt(nDay, 10);
							if (isNaN(nDay))
							{
								bError = true;
							}
							else
							{
								if (nDay<1 || nDay>31)
								{
									bError = true;
								}
							}
							
							nMonth = parseInt(nMonth, 10);
							if (isNaN(nMonth))
							{
								bError = true;
							}
							else
							{
								nMonth--;
								if (nMonth<0 || nMonth>11)
								{
									bError = true;
								}
							}
							
							nYear = parseInt(nYear, 10);
							if (isNaN(nYear))
							{
								bError = true;
							}
							else
							{
								if (nYear<1800 || nYear>2010)
								{
									if (nYear<00 || nYear>90)
									{
										bError = true;
									}
								}
							}
							
							if (bError)
							{
								errors += '- '+ fieldName +' is not a valid Date.\n';
							}
							else
							{
								var nDate = new Date(nYear,nMonth, nDay);
							}
						}
						// check to see if it is a valid PostCode
						if (validationRule.indexOf('ISPOSTCODE') != -1)
						{
							var strPost2,strPost1;
							bError = false;
							sField = stringReplace(sField, ' ', '');
							sField = sField.toUpperCase();
							
							if (sField.length < 5)
							{
								bError = true;
							}
							if (!bError)
							{
								strPost2 = sField.substring(sField.length-3, sField.length);
								strPost1 = sField.substring(0, sField.length-3);
								if (strPost2.length < 3)
								{
									bError = true;
									alert("1");
								}
								if (strPost1.length > 4)
								{
									bError = true;
								}
							}
							if (!bError)
							{
								sCh = strPost1.substring(0,1);
								if (sCh<'A' || sCh>'Z')
								{
									bError = true;
								}
							}
							if (!bError)
							{
								sCh = strPost1.substring(1,2);
								if (sCh<'0' || sCh>'Z')
								{
									bError = true;
								}
								if (sCh>'9' && sCh<'A')
								{
									bError = true;
								}
								sCh = strPost1.substring(2,3);
								if (sCh != '')
								{
									if (sCh<'0' || sCh>'Z')
									{
										bError = true;
									}
									if (sCh>'9' && sCh<'A')
									{
										bError = true;
									}
									if (strPost1.length == 4)
									{
										if (!bError)
										{
											sCh = strPost1.substring(3,4);
											if (sCh<'0' || sCh>'Z')
											{
												bError = true;
											}
											if (sCh>'9' && sCh<'A')
											{
												bError = true;
											}
										}
									}
								}
							}
							if (!bError)
							{
								sCh = strPost2.substring(0,1);
								if (sCh<'0' || sCh>'9')
								{
									bError = true;
								}
							}
							if (!bError)
							{
								sCh = strPost2.substring(1,2);
								if (sCh<'A' || sCh>'Z')
								{
									bError = true;
								}
							}
							if (!bError)
							{
								sCh = strPost2.substring(2,3);
								if (sCh<'A' || sCh>'Z')
								{
									bError = true;
								}
							}

							if (bError)
							{
								errors += '- '+ fieldName +' is not a valid Post Code.\n';
							}
							else
							{
								sFieldObj.value = strPost1 + " " + strPost2;
							}
						}
					}
					else
					{
						if (validationRule.charAt(0) == 'R')
						{
							errors += '- '+ fieldName  + '\n';
						}
					}
				}
			}
		}
		    
		function displayErrors()
		{
			if (errors)
			{
				alert('The following fields are required or contain errors:\n\n' + errors);
				errors='';
				return false;
			}
			else
			{
				return true;
			}
		}
