﻿function Validate()
{
	var initialMsg = "The following fields must be filled in to submit your data:\n";
	if (RequiredFields(initialMsg) )
	{
		  document.MyData.submit();
		  return true;
	}
		else
	{
		return false;		
	}
}

function chkNAN(char2chk)
{
   var validNum = "0123456789";
   if (validNum.indexOf(char2chk) == "-1")
      return(confirm("You have entered a non-numeric character.\nDo you want to turn off non-numeric character checking?"));
}

function maskIt(fld)
{
   fldVal = fld.value;

   var tmpStr = "(";
   keyCount = fldVal.length;
   keyEntered =fldVal.substring(keyCount-1,keyCount);

   if (keyCount < 2)   isNamedFone = false;
   if (!isNamedFone)   isNamedFone = chkNAN(keyEntered);

   keyCount++;
   with (document.RegisterAssociate)
   {
      switch (keyCount)
      {
         case 2:
            tmpStr +=  fldVal;
            fld.value = tmpStr;
            break;
         case 5:
            fld.value +=  ") ";
            break;
          case 10:
            fld.value += "-"; 
            break;
      }
   }
}

function RequiredFields(errorMsg)
{
	var isError = false;

	// Check for Email
	if (document.MyData.email.value == "")
	{
		errorMsg = errorMsg + "\t-->Email Missing\n";
		if (!isError) // if this is first error, set focus
		{
		  SetFocus('email');
		}
		isError = true;
	}

	// Check for Password
	if (document.MyData.password.value == "")
	{
		errorMsg = errorMsg + "\t-->Password Missing\n";
		if (!isError) // if this is first error, set focus
		{
		  SetFocus('password');
		}
		isError = true;
	}
		
	if (isError)
	{
		alert(errorMsg);
		return false;
	}
	else
	{
		return true;
	}
}

function SetFocus(field) 
{
  //set focus to field passed in (great for error correcting)
  eval ("document.MyData." + field + ".focus();");
}

function ClearFocus(field) 
{
  //this clears the field and sets focus to field passed in
  field.value = "";
  field.focus();
}



