<!--

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}



function checkFormObjects(obj, test, name)
{
	var pos1, pos2, pos3, maxNum, minNum, number;
	var errors = '';
	
	test.toUpperCase();
	switch(test.charAt(0))
	{
		case 'R' :
			/* This field is required */
			if ((!obj.value) || (obj.value == ""))
			{
				errors += "The field <strong>" + name + "</strong> is a required field.\n";
			}
			break;
		case 'E' :
			/* This field needs an email address */
			pos1 = obj.value.indexOf('@');
			if ((pos1 < 1) || (pos1 >= (obj.length - 1)))
			{
				errors += "The field <strong>" + name + "</strong> must contain an email address.\n";
			}
			break;
		case 'X' :
			/* This field needs to be in a range of numbers */
			number = parseFloat(obj.value);
			if (isNaN(number))
			{
				errors += "The field <strong>" + name + "</strong> must contain a valid number in the range: " + minNum + "&ndash;" + maxNum + "\n";
			}
			pos1 = test.indexOf(':');
			pos2 = pos3 = -1;
			if (pos1 != -1)
			{
				pos2 = test.indexOf('-', pos1);
			}
			if (pos2 != -1)
			{
				pos3 = test.indexOf(':', pos2);
			}
			if (pos3 == -1)
			{
				errors += "The field <strong>" + name + "</strong> has an incorrect html form test format.\n"
			}
			minNum = test.substring(pos1 + 1, pos2);
			maxNum = test.substring(pos2 + 1, pos3);
			if ((number < minNum) || (maxNum < number))
			{
				errors += "The field <strong>" + name + "</strong> must contain a number between " + minNum + " and " + maxNum + ".\n";
			}
			break;
	}
	
	return errors;
}

function validateForm()
{
	var i, errors, allErrors, args;
	
	error = '';
	allErrors = '';
	args = validateForm.arguments;
	
	for (i = 0; i < (args.length - 2); i += 3)
	{
		obj = MM_findObj(args[i]);
		name = args[i + 1];
		test = args[i + 2];
		if (obj)
		{
			if (!obj.originalBgColor)
			{
				obj.originalBgColor = (obj.style.backgroundColor) ? obj.style.backgroundColor : document.bgColor;
				obj.originalClass = obj.className;
			}
			errors = checkFormObjects(obj, test, name);
			allErrors += errors;
			if (errors != '')
			{
				//obj.style.backgroundColor = "#ffcccc";
				obj.className = "formWarning";
			}
			else
			{
				//obj.style.backgroundColor = (obj.originalBgColor) ? obj.originalBgColor : "";
				obj.className = obj.originalClass ? obj.originalClass : "";
			}
		}
	}
	
	if (allErrors != '')
	{
		errorContainer = document.getElementById("errorContainer");
		if (errorContainer)
		{
			errorContainer.innerHTML = "<h3>The following form error(s) need to be corrected:</h3>\n" + allErrors;
			errorContainer.className = "showErrors";
		}
		//alert("The following form error(s) need to be corrected:\n" + allErrors);
	}
	return (errors == '');
}

//-->
