<!--
	// General variables...
	//var g_strURL = "http://localhost/WebSiteManager/Libs/Functions/ASP/";
	var g_strURL = "http://www.lri.co.uk/Libs/Functions/ASP/";
	var g_strAOK = false;
	
	// Colours for the highlights...
	var g_strNrm = "#FFFFFF";
	var g_strErr = "#E7EFF7";
	
	// Other variables...
	var g_intDec = 2;
	
	function CheckField(strID)
	{
		// Create the references to the form elements...
		var objFld = eval("document.frmEnquiryForm.frmFieldID" + strID);
		var strVal = Trim(objFld.value);
		
		// Get the information from the hidden field and check it...
		var strIDs = document.frmEnquiryForm.frmFieldIDs.value;
		
		// Do we have a set of ID's to check...
		if (strIDs.length > 0)
		{
			var arrRow = strIDs.split("]|[");
			
			for (var i = 0; i < arrRow.length; i++)
			{
				var arrCol	= arrRow[i].split("||");
				var intID	= parseInt(arrCol[0]);
				var strTyp	= arrCol[1].toUpperCase();
				var blnRqd	= eval(arrCol[2].toLowerCase());
				var strTxt	= arrCol[3].toString();
				var strVTy	= arrCol[4].toUpperCase();
				
				// If this is the correct field, check the details...
				if (strID == intID)
				{
					// Set the border style and do validation...
					if (strVal.length > 0)
					{
						if (strVTy == "EMAIL")
						{
							if (CheckValidEMail(strVal))
							{
								objFld.style.backgroundColor = g_strNrm;
							}
							else
							{
								objFld.style.backgroundColor = g_strErr;
							}
						}
						else if (strVTy == "NUMERIC")
						{
							if (CheckNumber(strVal, g_intDec))
							{
								objFld.style.backgroundColor = g_strNrm;
							}
							else
							{
								objFld.style.backgroundColor = g_strErr;
							}
						}
						else
						{
							objFld.style.backgroundColor = g_strNrm;
						}
					}
					else if (blnRqd)
					{
						objFld.style.backgroundColor = g_strErr;
					}
				}
			}
		}
	}
	
	function SaveEnquiry()
	{
		var blnAOK = true;
		var strMsg = "";
		var strIDs = document.frmEnquiryForm.frmFieldIDs.value;
		//alert("Processing form...");
		
		// Do we have a set of ID's to check...
		if (strIDs.length > 0)
		{
			var arrRow = strIDs.split("]|[");
			
			for (var i = 0; i < arrRow.length; i++)
			{
				var arrCol	= arrRow[i].split("||");
				var intID	= parseInt(arrCol[0]);
				var strTyp	= arrCol[1].toUpperCase();
				var blnRqd	= eval(arrCol[2].toLowerCase());
				var strTxt	= arrCol[3].toString();
				var strVTy	= arrCol[4].toUpperCase();
				
				// If this is an INPUT box of a different type (i.e. EMAIL or NUMERIC), then set the type so we don't have verbose repeating code...
				if ((Left(strTyp, 5) == "INPUT") && (strTyp.length > 5))
				{
					strTyp = "INPUT";
				}
				
				//alert("Checking FieldID [" + intID + "] of type [" + strTyp + "]");
				switch(strTyp)
				{
					case "CHECKBOX":
					
						// Create the references to the form elements...
						var objFld = eval("document.frmEnquiryForm.frmFieldID" + intID);
						var intCnt = 0;
						var intNum = objFld.length;
						if (intNum==undefined)
						//This check was added to account for the situation of having only one checkbox. (when this is the case there is no array and the code fails)
						{
								if (objFld.checked)
								{
									intCnt++;
								}
						}
						else
						{
							// Loop through the options to see if any are checked...
							for (var j = 0; j < objFld.length; j++)
							{
								if (objFld[j].checked)
								{
									intCnt++;
								}
							}
						}
						
						// If none have been selected, append the message...
						if ((intCnt == 0) && (blnRqd))
						{
							strMsg +=	"\n - " + strTxt;
							blnAOK	= false;
						}
						break;
					
					case "SELECT":
					
						var objFld = eval("document.frmEnquiryForm.frmFieldID" + intID);
						var intVal = parseInt(objFld.value);
						
						if ((intVal <= 0) && (blnRqd))
						{
							strMsg +=	"\n - " + strTxt;
							blnAOK	= false;
							
							// Highlight the box...
							objFld.style.backgroundColor = g_strErr;
						}
						else
						{
							// Highlight the box...
							objFld.style.backgroundColor = g_strNrm;
						}
						break;
					
					case "LABEL":
					
						break;
					
					case "RADIO":
					
						// Create the references to the form elements...
						var objFld = eval("document.frmEnquiryForm.frmFieldID" + intID);
						var intCnt = 0;
						var intNum = objFld.length;
						
						// Loop through the options to see if any are checked...
						for (var j = 0; j < objFld.length; j++)
						{
							if (objFld[j].checked)
							{
								intCnt++
							}
						}
						
						// If none have been selected, append the message...
						if ((intCnt == 0) && (blnRqd))
						{
							strMsg +=	"\n - " + strTxt;
							blnAOK	= false;
						}
						break;
					
					case "TEXTAREA":
					
						var objFld = eval("document.frmEnquiryForm.frmFieldID" + intID);
						var strVal = Trim(objFld.value);
						
						if ((strVal.length <= 0) && (blnRqd))
						{
							strMsg +=	"\n - " + strTxt;
							blnAOK	= false;
							
							// Highlight the box...
							objFld.style.backgroundColor = g_strErr;
						}
						else
						{
							// Highlight the box...
							objFld.style.backgroundColor = g_strNrm;
						}
						break;
					
					case "INPUT":
					
						var objFld = eval("document.frmEnquiryForm.frmFieldID" + intID);
						var strVal = Trim(objFld.value);
						
						if ((strVal.length <= 0) && (blnRqd))
						{
							// Append the information to the message...
							strMsg +=	"\n - " + strTxt;
							blnAOK	= false;
							
							// Highlight the box...
							objFld.style.backgroundColor = g_strErr;
						}
						else if (strVal.length > 0)
						{
							// Check validation type...
							if (strVTy == "EMAIL")
							{
								if (CheckValidEMail(strVal))
								{
									objFld.style.backgroundColor = g_strNrm;
								}
								else
								{
									objFld.style.backgroundColor = g_strErr;
								}
							}
							else if (strVTy == "NUMERIC")
							{
								if (CheckNumber(strVal, g_intDec))
								{
									objFld.style.backgroundColor = g_strNrm;
								}
								else
								{
									objFld.style.backgroundColor = g_strErr;
								}
							}
							else
							{
								objFld.style.backgroundColor = g_strNrm;
							}
						}
						else
						{
							// Highlight the box...
							objFld.style.backgroundColor = g_strNrm;
						}
						break;
					
					case "DEFAULT":
					
						break;
					
				}
			}
		}
		
		// Do we have to do an alert...
		if (blnAOK)
		{
			// Set the action URL, submitted value and submit the form...
			document.frmEnquiryForm.action = window.location;
			document.frmEnquiryForm.frmSubmitted.value = "TRUE";
			document.frmEnquiryForm.submit();
		}
		else
		{
			strMsg = "You have not provided responses to every question on the form and the\nfollowing items are required:-\n" + strMsg + "\n\nPlease complete the required elements and try again.";
				
			alert(strMsg);
		}
	}

	function CheckValidEMail(strEMail)
	{
		if (strEMail.length <= 0)
		{
			return false;
		}
		else
		{
			var strAt	= "@";
			var dot		= ".";
			var lat		= strEMail.indexOf(strAt);
			var lstr	= strEMail.length;
			var ldot	= strEMail.indexOf(dot);
			
			if (strEMail.indexOf(strAt)==-1)
			{
				return false;
			}
			if (strEMail.indexOf(strAt) == -1 || strEMail.indexOf(strAt) == 0 || strEMail.indexOf(strAt) == lstr)
			{
				return false;
			}
			if (strEMail.indexOf(dot) == -1 || strEMail.indexOf(dot) == 0 || strEMail.indexOf(dot) == lstr)
			{
				return false;
			}
			if (strEMail.indexOf(strAt, (lat + 1)) != -1)
			{
				return false;
			}
			if (strEMail.substring(lat - 1, lat) == dot || strEMail.substring(lat + 1, lat + 2) == dot)
			{
				return false;
			}
			if (strEMail.indexOf(dot, (lat + 2)) == -1)
			{
				return false;
			}
			if (strEMail.indexOf(" ") != -1)
			{
				return false;
			}
			return true;
		}
	}
	
	function CheckNumber(intValue, intDec)
	{
		var intMax = intDec;								// how many decimals are allowed?
		var decTxt;
		
		if (isNaN(intValue) || intValue == "")
		{
			return false
		}
		else
		{
			if (intDec > 0)
			{
				if (intValue.indexOf('.') == -1)
				{
					intValue += ".";
					decTxt = intValue.substring(intValue.indexOf('.') + 1, intValue.length);
				
					if (decTxt.length > intDec)
					{
						return false
					}
				}
			}
		}
		return true
	}

//-->
