// JavaScript Document
function iamhere(msg)
{
	alert(msg);
}

function goBack()
{
	window.history.back();
}

function checkForm(frm)
{
	/*MM_validateForm('fname','Name','R','email','Email','RisEmail','phone','Phone Number','isNum');
	return document.MM_returnValue;*/
	return true;
}

function checkRegForm(frm)
{
	var req = new Array (3);
	for (var i=0; i<formReq.length; ++i)
	{
		req = formReq[i].split("#");
		if (!validateFields(req[0], req[1], req[2]))
		{
			return false;
		}
	}
	return true;
}

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 validateFields()
{
	var i,p,q,nm,test,num,min,max,errors='',args=validateFields.arguments;
	var objFoc = new Array (args.length);
	var objFocI = 0;
	for (i=0; i<(args.length-2); i+=3)
	{
		test=args[i+2].split ('|');
		fld=MM_findObj(args[i]);
		if (!fld)
		{
			return true;
		}
		nm=args[i+1];
		for (rule in test)
		{
			switch (test[rule])
			{
			case ('isEmail'):
				val = fld.value;
				if (val.length == 0)
					break;
				p=val.indexOf('@');
				if (p<1 || p==(val.length-1) || p>(val.lastIndexOf (".")-2) || val.lastIndexOf (".")+3 > val.length)
				{
					errors+=nm+' must contain a valid Email address.\n';
					objFoc[objFocI] = args[i];
					objFocI++;
				}
				break;
			case ('R'):
				if ((val=fld.value)=="") //there is no value
				{
					if (nm.indexOf('@') != -1)
					{
						nm = nm.split('@');
						nm = nm[0];
					}
					errors += nm+' is required.\n';
					objFoc[objFocI] = args[i];
					objFocI++;
				}
				break;
			case ('isNum'):
				if (isNaN(val))
				{
					errors+=nm+' must be a number.\n';
					objFoc[objFocI] = args[i];
					objFocI++;
				}
				break;
			case ('inRange'):
				newName = nm.split ('@')
				if (isNaN(val))
				{
					errors+=newName[0]+' must be a number.\n';
					objFoc[objFocI] = args[i];
					objFocI++;
				}
				num = parseFloat(val);
				min=newName[1];
				max=newName[2];
				if (num<min || max<num)
				{
					errors+=newName[0]+' must be a number between '+min+' and '+max+'.\n';
					objFoc[objFocI] = args[i];
					objFocI++;
				}
				break;
			case ('Select-R'):	//must choose a select option - requires the existance of a "" value option (recommend 1st option be like <option value="">Select</option>)
				if (fld.options[fld.selectedIndex].value=="") //there is no value
				{
					errors += 'Please select ' + nm + '.\n';
					objFoc[objFocI] = args[i];
					objFocI++;
				}
				break;
			case ('Check-R'):
				if (!fld.checked)
				{
					errors += 'Please check the ' + nm + '.\n';
					objFoc[objFocI] = args[i];
					objFocI++;
				}
				break;
			case ('PIN'):
				//set the rules for the PIN#
				var pinlen = fld.value.length;
				if (pinlen < 7 || pinlen > 13)
				{
					errors += 'The PIN# you gave is incorrect.\nPlease recheck it and try again.\n';
					objFoc[objFocI] = args[i];
					objFocI++;
				}
				break;
			case ('PassC'):
				var newName = args[i+1].split('@');
				var pass = document.getElementById (newName [1]);
				var passC = document.getElementById (newName [2]);
				if (pass.value != passC.value)
				{
					errors += 'Please confirm your password.\n';
					objFoc[objFocI] = args[i];
					objFocI++;
				}
				break;
			}	//end switch
		}	//end for-in
	}	//end for (i)
	if (errors) alert('The following errors have occured:\n'+errors);
	if (errors != '')
	{
		MM_findObj(objFoc[0]).focus();
	}
	//document.MM_returnValue = (errors == '');
	return (errors == '');
}

function MM_validateForm() { //v4.0
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	var objFoc = new Array (args.length);
	var objFocI = 0;
	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 (val)
		{
			nm=args[i+1];
			if ((val=val.value)!="")
			{
				if (test.indexOf('isEmail')!=-1)
				{
					p=val.indexOf('@');
					if (p<1 || p==(val.length-1) || p>(val.lastIndexOf (".")-2) || val.lastIndexOf (".")+3 > val.length)
					{
						errors+=nm+' must contain a valid Email address.\n';
						objFoc[objFocI] = args[i];
						objFocI++;
					}
				}
				else if (test!='R')
				{
					num = parseFloat(val);
					if (isNaN(val))
					{
						errors+=nm+' must contain a number.\n';
						objFoc[objFocI] = args[i];
						objFocI++;
					}
					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 be anumber between '+min+' and '+max+'.\n';
							objFoc[objFocI] = args[i];
							objFocI++;
						}
					}
				}
			}
			else if (test.charAt(0) == 'R')
			{
				errors += nm+' is required.\n';
				objFoc[objFocI] = args[i];
				objFocI++;
			}
		}
	}
	if (errors) alert('The following errors have occured:\n'+errors);
	if (errors != '')
	{
		MM_findObj(objFoc[0]).focus();
	}
	document.MM_returnValue = (errors == '');
}
