<!--
function KRS_findObj(n, d) 
{
	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=KRS_findObj(n,d.layers[i].document);
	}
	if (!x && d.getElementById) {
		x=d.getElementById(n);
	}
	return x;
}



function KRS_validateForm() {
	var i,p,q,formName,prefFieldLabel,test,num,min,max,errors="",args=arguments;
	for (i=0; i<(args.length-3); i+=4) {
		test=args[i+3]; 
		val=KRS_findObj(args[i]);
		if (val) { 
			formName=val.name; 
			prefFieldLabel=args[i+1]; 

			/* Test for required fields. */
			if ((val=val.value)!="") {
				if (test.indexOf('isEmail')!=-1) { 
					var emailFilter=/^.+@.+\..{2,3}$/;
					if (!(emailFilter.test(val))) {
						errors += "-- " + prefFieldLabel + " must be a valid email address.\n";
					}
					else {
					//test email for illegal characters
						var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
						if (val.match(illegalChars))
						{
							errors += "-- " + prefFieldLabel + " contains illegal characters.\n";
						}
					}
				} 
				else if (test!='R') {
					if (isNaN(val)) {
						errors += "-- " + prefFieldLabel + " must contain a number.\n";
					}
					if (test.indexOf('inRange') != -1) { 
						p=test.indexOf(':');
						min=test.substring(8,p); 
						max=test.substring(p+1);
						if (val<min || max<val) 
						{
							errors += "-- " + prefFieldLabel + " must contain a number between " + min + " and " + max + ".\n";
						}
					} 
				} 
			} 
			else if (test.charAt(0) == 'R') {
				errors += "-- " + prefFieldLabel + " is required.\n";
			} 
		}
	} 


	// Specific to Kalena's Guest Book

	// Validate textarea for "Comments"
	if (document.forms[0].name == 'guestbook') {
		var tComments, tPhoneNumber, tPhoneType, iSelectIndex, tSelectOptionValue;

		tComments = document.guestbook.Comments.value;
		if (tComments == "") {
			errors += "-- Comments is required.\n";
		}
		tPhoneNumber = document.guestbook.Phone.value;
		tPhoneType   = document.guestbook.Phone_Type.value;
		iSelectIndex = document.guestbook.Phone_Type.selectedIndex;
		tSelectOptionValue = document.guestbook.Phone_Type.options[iSelectIndex].value;
		if ( (tPhoneNumber != "") && (tSelectOptionValue == "") ) {
			errors += "-- If you enter a phone number, also select a phone type.\n";
		}
		else if ( (tPhoneNumber == "") && (tSelectOptionValue != "") ) {
			errors += "-- If you select a phone type, also enter a phone number.\n";
		}

	}


	// Generate summary of form error messages
	if (errors) {
		alert("The following error(s) occurred:\n" + errors + "\n");
	}
	document.KRS_returnValue = (errors == "");
	return errors;
}
//-->

