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

function validate_number(v) 
{
	return (!(v == null || v == "" || isNaN(v)));
}

function validate_email(v) 
{
	rx = new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");
	return (rx.test(v));
}

// trying to make some sense out of this function - update 01/10
function checkform() 
{
	// var a will contain all args passed to checkform()
	var a = checkform.arguments, oo = true, v = '', s = '', err = false, r, o, at, o1, t, i, j, ma, rx, cd, cm, cy, dte, at;

	// loop through a, 4 elements at a time. starting from position 1 (2nd arg)
	for (i = 1; i < a.length; i = i + 4) 
	{
		// check if 2nd element is a js function - check for ()
		// set err to js function
		if (a[i + 1].indexOf('()') != -1) 
		{
			eval("err = " + a[i + 1] + ";");
		} 
		else 
		{
			// if 2nd element starts with '#', set r to true and remove the '#'
			// r = required and is used when o is of type 'text' or 'password' or 'hidden'
			if (a[i + 1].charAt(0) == '#') 
			{
				r = true;
				a[i + 1] = a[i + 1].substring(1);
			} 
			else 
			{
				r = false;
			}
			
			// reg exp = /pattern/attributes; attribs = ig (i=ignore case, g=global)
			// pattern = \[\d+\] = digits only in []  
			o = MM_findObj(a[i].replace(/\[\d+\]/ig, ""));
			o1 = MM_findObj(a[i + 1].replace(/\[\d+\]/ig, ""));
			v = o.value;
			
			// t = type
			t = a[i + 2];
			// o of type 'text' or 'password' or 'hidden'
			if (o.type == 'text' || o.type == 'password' || o.type == 'hidden') 
			{
				// required and empty
				if (r && v.length == 0) 
				{
					err = true;
				}
				if (v.length > 0)
				{
					// fromto
					if (t == 1) 
					{ 
						ma = a[i + 1].split('_');
						if (!validate_number(v) || v < ma[0] / 1 || v > ma[1] / 1) 
						{
							err = true;
						}
					} 
					// email validation
					else if (t == 2) 
					{
						err = !validate_email(v);
					} 
					// date
					else if (t == 3) 
					{ 
						ma = a[i + 1].split("#");
						at = v.match(ma[0]);
						if (at) 
						{
							cd = (at[ma[1]]) ? at[ma[1]] : 1;
							cm = at[ma[2]] - 1;
							cy = at[ma[3]];
							dte = new Date(cy, cm, cd);
							if (dte.getFullYear() != cy || dte.getDate() != cd || dte.getMonth() != cm) 
							{
								err = true;
							}
						} 
						else 
						{
							err = true;
						}
					} 
					// time
					else if (t == 4) 
					{ 
						ma = a[i + 1].split("#");
						at = v.match(ma[0]);
						if (!at) 
						{
							err = true;
						}
					} 
					// check this 2
					else if (t == 5) 
					{ 
						if (o1.length)
						{
							o1 = o1[a[i + 1].replace(/(.*\[)|(\].*)/ig, "")];
						}
						if (!o1.checked) 
						{
							err = true;
						}
					} 
					// the same
					else if (t == 6) 
					{ 
						if (v != MM_findObj(a[i + 1]).value) 
						{
							err = true;
						}
					} 
					// length
					else if (t == 7) 
					{ 
						ma = a[i + 1].split('_');
						if (v.length < ma[0] / 1 || v.length > ma[1] / 1) 
						{
							err = true;
						}
					} 
					// number validation
					else if (t == 8) 
					{ 
						if (!validate_number(v)) 
						{
							err = true;
						}
					}
				}
			} 
			// object o of type 'radio'
			else if (!o.type && o.length > 0 && o[0].type == 'radio') 
			{
				// pattern = /(.*)\[(\d+)\].* = any string having digits in []
				at = a[i].match(/(.*)\[(\d+)\].*/i);
				
				o2 = (o.length > 1) ? o[at[2]] : o;
				if (t == 1 && o2 && o2.checked && o1 && o1.value.length / 1 == 0) 
				{
					err = true;
				}
				if (t == 2) 
				{
					oo = false;
					for (j = 0; j < o.length; j++) 
					{
						oo = oo || o[j].checked;
					}
					if (!oo) 
					{
						s += '* ' + a[i + 3] + '\n';
						err = true;
					}
				}
				if (t == 3) 
				{
					if (!o2.checked) 
					{
						err = true;
					}
				}
			} 
			// object o of type 'checkbox'
			else if (o.type == 'checkbox') 
			{
				if ((t == 1 && o.checked == false) || (t == 2 && o.checked && o1 && o1.value.length / 1 == 0)) 
				{
					err = true;
				}
			} 
			// object o of type 'select-one' or 'select-multiple'
			else if (o.type == 'select-one' || o.type == 'select-multiple') 
			{
				if (t == 1 && o.selectedIndex / 1 == 0) 
				{
					err = true;
				}
			} 
			// object o of type 'textarea'
			else if (o.type == 'textarea') 
			{
				if (v.length < a[i + 1]) 
				{
					err = true;
				}
			}
		}
		
		var eo = getObject(a[i].replace(/\[\d+\]/ig, "") + "_error");
		var elo = getRawObject(a[i].replace(/\[\d+\]/ig, "") + "_label");		
		if (err) 
		{
			if (eo) 
			{
				eo.display = 'block';
			}
			if (elo) 
			{
				elo.className = 'error_label';
			}
			s += '* ' + a[i + 3] + '\n';
			err = false;
		} 
		else 
		{
			if (eo) 
			{
				eo.display = 'none';
			}
			if (elo) 
			{
				elo.className = 'form_label';
			}
		}
	}

	var eo = getObject("any_errors");
	if (eo) 
	{
		if (s != '') 
		{
			eo.display = 'block';
		} 
		else 
		{
			eo.display = 'none';
		}
	}
	return (s == '');
}
