		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 replaceHTML()
		{
			var re=/[(<>"'&]/g
			for (i=0; i<=document.forms.length-1; i++)
				for (j=0; j<=document.forms(i).elements.length-1; j++)
					document.forms(i).elements(j).value = document.forms(i).elements(j).value.replace(re, function(m){return replacechar(m)})
		}
		
		//errors += (document.forms(i).elements(j).value.replace(/(<([^>]+)>)/ig,"") + '\n');
		//errors += (document.forms(i).elements(j).value.replace(re, function(m){return replacechar(m)}))
		
		function replacechar(match){
		if (match=="<")
		return "&lt;"
		else if (match==">")
		return "&gt;"
		else if (match=="\"")
		return "&quot;"
		else if (match=="'")
		return "&#039;"
		else if (match=="&")
		return "&amp;"
		else if (match=="(")
		return "--"
		else if (match==")")
		return "--"
		}

		function validateField()
		{
			//replaceHTML();
			//return 0;
			var bErrall,nIndex, bFileExt,nPos,fieldName,validationRule,nNumber,nMinimum,nMaximum, bMinimumEqual, bMaximumEqual,args, nAux, bError, sFieldObj, sFieldRadioObj;
			args = validateField.arguments;
			for (nIndex = 0; nIndex < (args.length-2); nIndex += 3)
			{
				validationRule = args[nIndex+2]; 
				validationRule = validationRule.toUpperCase();
				fieldName = args[nIndex+1]; 
				if (validationRule.indexOf('ISRADIO') != -1)
				{
					sFieldRadioObj = getObject(args[nIndex]);
					sFieldObj = getObject(args[nIndex])[0];
				}
				else
				{
					sFieldObj = getObject(args[nIndex]);
				}
				
				
				nMinimum = 1.234
				nMaximum = 1.235
				bMinimumEqual = false
				bMaximumEqual = false
				
				if (validationRule.indexOf(';>=') != -1)
				{	
					nPos = validationRule.indexOf(';>=') + 3
					nMinimum = validationRule.substring(nPos,validationRule.indexOf(';',nPos))
					bMinimumEqual = true
				}
				else
				{
					if (validationRule.indexOf(';>') != -1)
					{	
						nPos = validationRule.indexOf(';>') + 2
						nMinimum = validationRule.substring(nPos,validationRule.indexOf(';',nPos))
						bMinimumEqual = false
					}
				}
				
				if (validationRule.indexOf(';<=') != -1)
				{	
					nPos = validationRule.indexOf(';<=') + 3
					nMaximum = validationRule.substring(nPos,validationRule.indexOf(';',nPos)) 
					bMaximumEqual = true
				}
				else
				{
					if (validationRule.indexOf(';<') != -1)
					{	
						nPos = validationRule.indexOf(';<') + 2
						nMaximum = validationRule.substring(nPos,validationRule.indexOf(';',nPos))
						bMaximumEqual = false
					}
				}
				
				nMinimum = parseFloat(nMinimum);
				nMaximum = parseFloat(nMaximum);
				
				bFileExt = (validationRule.indexOf(';*.') != -1)
				
				if (sFieldObj)
				{
					bErrall = false;
					
					if (sFieldObj.disabled==false)
					{
						if (fieldName=='')
						{
							fieldName = sFieldObj.name;
						}
						sField = sFieldObj.value + "";
						//check the field if the it isn't null
						
						if (sField != "")
						{							
							// 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;bErrall = true;
								}
								//contains at least one dot after the @
								nAux = nPos;
								nPos = sField.indexOf('.', nAux);
								if (nPos == -1)
								{
									bError = true;bErrall = 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('ISPHONE') != -1)
							{
								bError = false;
								//contains 0 on position 1
								nPos = sField.indexOf('0');
								if (nPos != 0)
								{
									bError = true;bErrall = 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;bErrall = true;
									}
								}
								if (bError)
								{
									errors += '- '+ fieldName +' may only contain digits and spaces. The first digit must be 0 (zero)\n';
								}
							}
							// check to see if it contains only digits
							if (validationRule.indexOf('ISDIGIT') != -1)
							{
								bError = false;
								//contains only digits
								for(var i = 0; i < sField.length; i++)
								var ch = sField.substring(i,i+1);
								if (ch<'0' || ch>'9')
								{
									bError = true;bErrall = true;
								}
								if (bError)
								{
									errors += '- '+ fieldName +' may only contain digits.\n';
								}
							}
							// check to see if it contains only digits
							if (validationRule.indexOf('NOSPACES') != -1)
							{
								bError = false;
								//contains no spaces
								if (sField.indexOf(' ') != -1)
								{
									bError = true;bErrall = true;
								}
								if (bError)
								{
									errors += '- '+ fieldName +' must not contain spaces.\n';
								}
							}
							if (validationRule.indexOf('ISNUMBER') != -1)
							{
								bError = false;
								sField = stringReplace(sField, ' ', '');
								nNumber = parseFloat(sField);
								if (isNaN(sField) == true)
								{
									bError = true;bErrall = true;
								}
								if (sField=='') {bError = false;}
								var bMin, bMax
								
								bMin = false
								bMax = false
								
								if (nMinimum!=1.234)
								{
									if (bMinimumEqual)
									{
										if (nNumber>=nMinimum) bMin=true
									}
									else
									{
										if (nNumber>nMinimum) bMin=true
									}
								}
								else
								{
									bMin=true
								}
								
								if (nMaximum!=1.235)
								{
									if (bMaximumEqual)
									{
										if (nNumber<=nMaximum) bMax=true
									}
									else
									{
										if (nNumber<nMaximum) bMax=true
									}
								}
								else
								{
									bMax = true
								}
								
								if (nMinimum==nMaximum)
								{
									if (bMin == bMax) {bError = true;bErrall = true;}
								}
								else
								{
									if (bMin != bMax) {bError = true;bErrall = true;}
								}
								
								if (bError)
								{
									errors += '- '+ fieldName +' must contain a valid number';
									if ((nMinimum != 1.234) & (nMaximum != 1.235))
									{
										if (nMinimum==nMaximum)
										{
											errors += ' not equal to ' + nMinimum ;
										}
										else
										{
											errors += ' greater than ' 
											if (bMinimumEqual) errors += 'or equal to ' 
											errors += nMinimum;
											errors += ' and less than ';
											if (bMaximumEqual) errors += 'or equal to ' 
											errors += nMaximum
										}		
									}
									else
									{
										if (nMinimum != 1.234)
										{
											errors += ' greater than ' 
											if (bMinimumEqual) errors += ' or equal to ' 
											errors += nMinimum;
										}
										if (nMaximum != 1.235)
										{
											errors += ' less than ';
											if (bMaximumEqual) errors += ' or equal to ' 
											errors += nMaximum
										}
									}
									errors += '.\n';
								}
								
							}
							
							// check to see if it is a valid radio box
							if (validationRule.indexOf('ISCHECKED') != -1)
							{
								/*bError = true;
								for (i=0;i<=sFieldRadioObj.length-1;i++)
								{
									if (sFieldRadioObj[i].checked) bError = false;
								}
								*/
								
								if (!sFieldObj.checked)
								{
									errors += '- '+ fieldName +' has to be ticked.\n';
									bErrall = true;
								}
							}
							
							// check to see if it is a valid radio box
							if (validationRule.indexOf('ISRADIO') != -1)
							{
								bError = true;
								for (i=0;i<=sFieldRadioObj.length-1;i++)
								{
									if (sFieldRadioObj[i].checked) bError = false;
								}
								
								if (bError)
								{
									errors += '- '+ fieldName +' has to be ticked.\n';
									bErrall = true;
								}
							}
							
							//check for strong passwords
							if (validationRule.indexOf('ISSTRONGPASSWORD') != -1)
							{
								//It must not contain a space
								if (sField.indexOf(" ") > -1) {
									errors += '- '+ fieldName +' cannot include a space.\n';
									bErrall = true;
								}     
								 
								//It must contain at least one number character
								if (!(sField.match(/\d/))) {
									errors += '- '+ fieldName +' must include at least one number.\n';
									bErrall = true;
								}
								//It must start with at least one letter     
								if (!(sField.match(/^[a-zA-Z]+/))) {
									errors += '- '+ fieldName +' must start with a letter.\n';
									bErrall = true;
								}
								//It must contain at least one upper case character     
								if (!(sField.match(/[A-Z]/))) {
									errors += '- '+ fieldName +' must include at least one uppercase letter.\n';
									bErrall = true;
								}
								//It must contain at least one lower case character
								if (!(sField.match(/[a-z]/))) {
									errors += '- '+ fieldName +' must include at least one lowercase letter.\n';
									bErrall = true;
								}
								//It must contain at least one special character
								//if (!(sField.match(/\W+/))) {
								//	errorMsg += "\nThe password must include at least one special character - #,@,%,!\n";
								//	errors += '- '+ fieldName +' cannot include a space.\n';
								//}
								//It must be at least 8 characters long.
								if (!(sField.length >= 8)) {
									errors += '- '+ fieldName +' must be at least 8 characters long.\n';
									bErrall = true;
								}
							}
							
							// 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;bErrall = true;
								}
								else
								{
									if (nDay<1 || nDay>31)
									{
										bError = true;bErrall = true;
									}
								}
								
								nMonth = parseInt(nMonth, 10);
								if (isNaN(nMonth))
								{
									bError = true;bErrall = true;
								}
								else
								{
									nMonth--;
									if (nMonth<0 || nMonth>11)
									{
										bError = true;bErrall = true;
									}
								}
								
								nYear = parseInt(nYear, 10);
								if (isNaN(nYear))
								{
									bError = true;bErrall = true;
								}
								else
								{
									if (nYear<1800 || nYear>2069)
									{
										if (nYear<00 || nYear>90)
										{
											bError = true;bErrall = true;
										}
									}
								}
								
								var ddate1 = new Date(nYear,nMonth,nDay)
								//ddate1.setFullYear(nYear)
								//ddate1.setMonth (nMonth)
								//ddate1.setDate(nDay)
								if (ddate1.getDate()!=nDay) {bError = true;bErrall = true;}
								
								if (bError)
								{
									errors += '- '+ fieldName +' is not a valid Date.\n';
								}
								else
								{
									if (validationRule.indexOf('ISDATENOPAST') != -1)
									{
										var today = new Date();
										var nDay2, nMonth2, nYear2;
										nYear2 = today.getYear()
										nMonth2 = today.getMonth()
										nDay2 = today.getDate()
										
										if (compareDates (nYear, nMonth, nDay, nYear2, nMonth2, nDay2 ) == -1)
										errors += '- '+ fieldName +' can not be in the past.\n';
									}
									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;bErrall = true;
								}
								if (!bError)
								{
									strPost2 = sField.substring(sField.length-3, sField.length);
									strPost1 = sField.substring(0, sField.length-3);
									if (strPost2.length < 3)
									{
										bError = true;bErrall = true;
										alert("1");
									}
									if (strPost1.length > 4)
									{
										bError = true;bErrall = true;
									}
								}
								if (!bError)
								{
									sCh = strPost1.substring(0,1);
									if (sCh<'A' || sCh>'Z')
									{
										bError = true;bErrall = true;
									}
								}
								if (!bError)
								{
									sCh = strPost1.substring(1,2);
									if (sCh<'0' || sCh>'Z')
									{
										bError = true;bErrall = true;
									}
									if (sCh>'9' && sCh<'A')
									{
										bError = true;bErrall = true;
									}
									sCh = strPost1.substring(2,3);
									if (sCh != '')
									{
										if (sCh<'0' || sCh>'Z')
										{
											bError = true;bErrall = true;
										}
										if (sCh>'9' && sCh<'A')
										{
											bError = true;bErrall = true;
										}
										if (strPost1.length == 4)
										{
											if (!bError)
											{
												sCh = strPost1.substring(3,4);
												if (sCh<'0' || sCh>'Z')
												{
													bError = true;bErrall = true;
												}
												if (sCh>'9' && sCh<'A')
												{
													bError = true;bErrall = true;
												}
											}
										}
									}
								}
								if (!bError)
								{
									sCh = strPost2.substring(0,1);
									if (sCh<'0' || sCh>'9')
									{
										bError = true;bErrall = true;
									}
								}
								if (!bError)
								{
									sCh = strPost2.substring(1,2);
									if (sCh<'A' || sCh>'Z')
									{
										bError = true;bErrall = true;
									}
								}
								if (!bError)
								{
									sCh = strPost2.substring(2,3);
									if (sCh<'A' || sCh>'Z')
									{
										bError = true;bErrall = true;
									}
								}

								if (bError)
								{
									errors += '- '+ fieldName +' is not a valid Post Code.\n';
								}
								else
								{
									sFieldObj.value = strPost1 + " " + strPost2;
								}
							}
							
							// Required string
							if ((validationRule == 'R') | (validationRule.substring(0,1) == ';') | (validationRule.substring(0,2) == 'R;'))
							{
								bError = false;
								nNumber = sField.length
								bMin = false
								bMax = false
								
								if (nMinimum!=1.234)
								{
									if (bMinimumEqual)
									{
										if (nNumber>=nMinimum) bMin=true
									}
									else
									{
										if (nNumber>nMinimum) bMin=true
									}
								}
								else
								{
									bMin=true
								}
								
								if (nMaximum!=1.235)
								{
									if (bMaximumEqual)
									{
										if (nNumber<=nMaximum) bMax=true
									}
									else
									{
										if (nNumber<nMaximum) bMax=true
									}
								}
								else
								{
									bMax = true
								}
								
								if (nMinimum==nMaximum)
								{
									if (bMaximumEqual && bMinimumEqual)
									{
										if (bMin != bMax) {bError = true;bErrall = true;}
									}
									else
									{
										if (bMin == bMax) {bError = true;bErrall = true;}
									}
								}
								else
								{
									if (bMin != bMax) {bError = true;bErrall = true;}
								}
								
								if (bError)
								{
									errors += '- '+ fieldName +' must contain a string with a length';
									if ((nMinimum != 1.234) & (nMaximum != 1.235))
									{
										if (nMinimum==nMaximum)
										{
											if (bMaximumEqual && bMinimumEqual)
												errors += ' equal to ' + nMinimum ;
											else
												errors += ' not equal to ' + nMinimum ;
										}
										else
										{
											errors += ' greater than ' 
											if (bMinimumEqual) errors += 'or equal to ' 
											errors += nMinimum;
											errors += ' and less than ';
											if (bMaximumEqual) errors += 'or equal to ' 
											errors += nMaximum
										}		
									}
									else
									{
										if (nMinimum != 1.234)
										{
											errors += ' greater than ' 
											if (bMinimumEqual) errors += ' or equal to ' 
											errors += nMinimum;
										}
										if (nMaximum != 1.235)
										{
											errors += ' less than ';
											if (bMaximumEqual) errors += ' or equal to ' 
											errors += nMaximum
										}
									}
									errors += ' characters.\n';
								}
							}
						}
						else
						{
							if (validationRule.charAt(0) == 'R')
							{
								errors += '- '+ fieldName  + '\n';
								bErrall = true;
							}
						}
						
						//check file extension
						if (bFileExt)
						{
							sAux = validationRule.indexOf(sField.substring(sField.indexOf('.'),sField.length).toUpperCase());
							if (sAux <= 0) 
							{	
								errors += '- '+ fieldName  + ' must be a file with the following extension ' + validationRule.substring(validationRule.indexOf('R;')+2,validationRule.length) + ' \n';
								bErrall = true;
							}
						}
					}
								
								
				if (bErrall)
					if (validationRule.indexOf('ISDATE') != -1)
					{
						getObject(args[nIndex]+"_d").className = "error";
						getObject(args[nIndex]+"_m").className = "error";
						getObject(args[nIndex]+"_y").className = "error";
					}
					else
					{
						if ((validationRule.indexOf('ISRADIO') != -1))
						for (i=0;i<=sFieldRadioObj.length-1;i++)
						{
							sFieldRadioObj[i].className = "error";
						}
						else
							sFieldObj.className = "error";
					}
				else
					if (validationRule.indexOf('ISDATE') != -1)
					{
						if (getObject(args[nIndex]+"_d").className == "error") getObject(args[nIndex]+"_d").className = "body";
						if (getObject(args[nIndex]+"_m").className == "error") getObject(args[nIndex]+"_m").className = "body";
						if (getObject(args[nIndex]+"_y").className == "error") getObject(args[nIndex]+"_y").className = "body";
					}
					else
					{
						if ((validationRule.indexOf('ISRADIO') != -1) || (validationRule.indexOf('ISCHECKED') != -1))
						for (i=0;i<=sFieldRadioObj.length-1;i++)
						{
							if (sFieldRadioObj[i].className == "error") sFieldRadioObj[i].className = "body";
						}
						else
							if (sFieldObj.className == "error") sFieldObj.className = "body";
					}
				}
			}
		}
		    
		function confirmErrors()
		{	var bOK;
			if (errors)
			{
				bOK = confirm('The following fields are required or contain errors:\n\n' + errors );
				errors = '';
				return bOK;
			}
			else
			{
				return true;
			}
		}
		
		function displayErrors()
		{	
			if (errors)
			{
				alert('The following fields are required or contain errors:\n\n' + errors + '');
				errors='';
				return false;
			}
			else
			{
				return true;
			}
		}
		
		function compareDates (year1, month1, date1, year2, month2, date2) {
		//	return 0 if the dates are same 
		//	return -1 if the first one is an earlier date 
		//	return 1 if the first one is a later date 

		if (year1 > year2) return 1;
		else if (year1 < year2) return -1;
		else if (month1 > month2) return 1;
		else if (month1 < month2) return -1;
		else if (date1 > date2) return 1;
		else if (date1 < date2) return -1;
		else return 0;
		} 
		
		function keyDown(DnEvents)
		{ var sAux;
		k = (netscape) ? DnEvents.which : window.event.keyCode;
		sAux = document.location + "";
		
		if (sAux.indexOf('index.asp') == -1)
			if ((k == 13) & (document.activeElement.type!="submit") & (!(document.activeElement.rows>0))) netscape ? DnEvents.which=9 : window.event.keyCode=9;
		return true;
		}
		
		function GeneratePassword(sFieldName) {
			if (parseInt(navigator.appVersion) <= 3) {
				alert("Sorry this only works in 4.0+ browsers");
				return true;
			}

			var sPassword = "";
			if (getRandomNum(0, 2)==0)
			{
				sPassword = sPassword + String.fromCharCode(getRandomNum(65, 91)); //A-Z
				sPassword = sPassword + String.fromCharCode(getRandomNum(97, 123)); //a-z
			}
			else
			{
				sPassword = sPassword + String.fromCharCode(getRandomNum(97, 123)); //a-z
				sPassword = sPassword + String.fromCharCode(getRandomNum(65, 91)); //A-Z
			}
			sPassword = sPassword + String.fromCharCode(getRandomNum(48, 58)); //0-9
			for (i=0; i < 5; i++)
			{
				switch(getRandomNum(0, 3))
				{
					case 0:
						sPassword = sPassword + String.fromCharCode(getRandomNum(65, 91)); //A-Z
						break;
					case 1:
						sPassword = sPassword + String.fromCharCode(getRandomNum(97, 123)); //a-z
						break;
					case 2:
						sPassword = sPassword + String.fromCharCode(getRandomNum(48, 58)); //0-9
						break;
				}
			}
			sPassword.replace("l","i");
			sPassword.replace("I","L");
			sPassword.replace("O","Q");
			sPassword.replace("o","q");
			getObject(sFieldName).value = sPassword
			return true;
		}

		function getRandomNum(nFrom, nTo) {
			var rndNum = Math.random();
			// rndNum from 0 - 1000
			rndNum = parseInt(rndNum * 1000);
			if (nFrom < nTo)
				rndNum = (rndNum % (nTo-nFrom)) + nFrom
			else
				rndNum = (rndNum % (nFrom-nTo)) + nTo;
			return rndNum;
		}

		netscape = "";
		ver = navigator.appVersion; len = ver.length;
		for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
		netscape = (ver.charAt(iln+1).toUpperCase() != "C");

		document.onkeydown = keyDown;
		
