// Format of function call:
// onClick="frm_valid('link_title','','R','page_title','','RisEmail','textfield3','','NisNum','textfield32','','RinRange10:200');return document.frm_valid_return">


function 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=findObj(n,d.layers[i].document);

	if(!x && document.getElementById)
		x=document.getElementById(n);

	return x;
}


function frm_valid()
{
	var i,p,q,nm,test,num,min,max,errors='',args=frm_valid.arguments, focus_field='';
	
	for (i=0; i<(args.length-2); i+=3)
	{
		test=args[i+2];
		val=findObj(args[i]);
		if (focus_field == '') focus_field = val;

		if (val)
		{
			nm=val.title;

			// If field contains a value
			// -------------------------
			if ((val=val.value)!="")
			{
				// If this is a Password field
				// ---------------------------
				if (test.indexOf('isPass')!=-1)
				{
					// If passwords don't match
					// ------------------------
					if (document.forms[0].password.value != document.forms[0].password_confirm.value)
						errors+= '- ' + document.forms[0].password.title + ' and ' + document.forms[0].password_confirm.title + ' don\'t match.\n';
				}
				// If this is a E-mail field
				// -------------------------
				else if (test.indexOf('isEmail')!=-1)
				{
					at	= val.indexOf('@');
					dot	= val.indexOf('.');

					// If e-mail is invalid
					// --------------------
					if (
						at < 1 ||
						at == (val.length - 1) ||
						at == (val.length - 2)
						//dot < 1 ||
						//dot == (val.length - 1) ||
						//at == dot + 1 ||
						//dot == at + 1 ||

					   )
						errors+='- '+nm+' must contain a valid e-mail address.\n';
				}
				// If this is a Numeric field
				// --------------------------
				else if (test.indexOf('isNum')!=-1)
				{
					// If value is not numeric
					// -----------------------
					if (isNaN(val))
						errors+='- '+nm+' must contain a number.\n';
				}
				// If this is a Range Numeric field
				// --------------------------------
				else if (test.indexOf('inRange') != -1)
				{
					p	=test.indexOf(':');
					min	=test.substring(8,p);
					max	=test.substring(p+1);

					// If value is not in range
					// ------------------------
					if (val<min || max<val)
						errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
				}
			}
			
			// If field doesn't contain a value but it is a required field
			// -----------------------------------------------------------
			else if (test.charAt(0) == 'R')
			{
				errors += '- '+nm+' is a required field.\n';
			}
		}
	}

	if (errors)
	{
		alert('Please Note:\n\n'+errors);
		//focus_field.focus();
	}
	
	document.frm_valid_return = (errors == '');
}