function clearform()
{
document.memform.fname.value = "";
document.memform.midinit.value = "";
document.memform.lname.value = "";
document.memform.sufx.value = "";
document.memform.maddr1.value = "";
document.memform.maddr2.value = "";
document.memform.mcity.value = "";
document.memform.mstate.value = "";
document.memform.mzip5.value = "";
document.memform.mzip4.value = "";
document.memform.marea1.value = "";
document.memform.mhmphone.value = "";
document.memform.marea2.value = "";
document.memform.mcellphone.value = "";
document.memform.muserid.value = "";
document.memform.memail.value = "";
document.memform.mpasswd.value = "";
}

function chknamefields()
{
var failsw=0;

	if (chkfname() == false)
           {
            failsw = 1;
           }
	if (chklname() == false)
           {
           failsw =  1;
           }

	if (chkstate() == false)
           {
           failsw =  1;
           }

        if (chkzip5() == false)
           {
           failsw = 1;
           }

        if (chkzip4() == false)
           {
           failsw = 1;
           }

        if (chkmarea1() == false)
           {
           failsw = 1;
           }

        if (chkphone() == false)
           {
           failsw = 1;
           }

        if (chkmarea2() == false)
           {
           failsw = 1;
           }

        if (chkcellphone() == false)
           {
           failsw = 1;
           }

        if (chkemail() == false)
           {
           failsw = 1;
           }

        if (chkuserid() == false)
           {
           failsw = 1;
           }

        if (chkpassword() == false)
           {
           failsw = 1;
           }

        if (failsw == 1)
           {
           return false;
           }
        else
           {
           return true;
           }
}

function chkfname()
{

	if (document.memform.fname.value == "" || document.memform.fname.value == null)
           {
		alert("\n invalid first name entered or none");
		return false;
	   }
	else
	   {
		return true;
	   }
}

function chklname()
{

	if (document.memform.lname.value == "" || document.memform.lname.value == null)
           {
		alert("\n invalid last name entered or none");
		return false;
	   }
	else
	   {
		return true;
	   }
}

function chkemail()
{

	if (document.memform.memail.value == "" || document.memform.memail.value == null)
           {
		alert("\n You must enter an email address");
		return false;
	   }
	else
	   {
		return true;
	   }
}

function chkstate()
{
var stabrv = new Array(50);
var stix = 0;
var wstate = "  ";

stabrv[0] = "AL";
stabrv[1] = "AK";
stabrv[2] = "AS";
stabrv[3] = "AZ";
stabrv[4] = "AR";
stabrv[5] = "CA";
stabrv[6] = "CO";
stabrv[7] = "CT";
stabrv[8] = "DE";
stabrv[9] = "DC";
stabrv[10] = "FM";
stabrv[11] = "FL";
stabrv[12] = "GA";
stabrv[13] = "GU";
stabrv[14] = "HI";
stabrv[15] = "ID";
stabrv[16] = "IL";
stabrv[17] = "IN";
stabrv[18] = "IA";
stabrv[19] = "KS";
stabrv[20] = "KY";
stabrv[21] = "LA";
stabrv[22] = "ME";
stabrv[23] = "MH";
stabrv[24] = "MD";
stabrv[25] = "MA";
stabrv[26] = "MI";
stabrv[27] = "MN";
stabrv[28] = "MS";
stabrv[29] = "MO";
stabrv[30] = "MT";
stabrv[31] = "NE";
stabrv[32] = "NV";
stabrv[33] = "NH";
stabrv[34] = "NJ";
stabrv[35] = "NM";
stabrv[36] = "NY";
stabrv[37] = "NC";
stabrv[38] = "ND";
stabrv[39] = "MP";
stabrv[40] = "OH";
stabrv[41] = "OK";
stabrv[42] = "OR";
stabrv[43] = "PW";
stabrv[44] = "PA";
stabrv[45] = "PR";
stabrv[46] = "RI";
stabrv[47] = "SC";
stabrv[48] = "SD";
stabrv[49] = "TN";
stabrv[50] = "TX";
stabrv[51] = "UT";
stabrv[52] = "VT";
stabrv[53] = "VI";
stabrv[54] = "VA";
stabrv[55] = "WA";
stabrv[56] = "WV";
stabrv[57] = "WI";
stabrv[58] = "WY";
stabrv[59] = "AE";
stabrv[60] = "AA";
stabrv[61] = "AP";

var tabmax = stabrv.length;

	if (document.memform.mstate.value == "" || document.memform.mstate.value == null)
           {
		return true;
	   }
	else
	   {
            wstate = document.memform.mstate.value;
            wstate = wstate.toUpperCase();

            for ( stix = 0; stix < tabmax; stix++)
                {
                 if (stabrv[stix] == wstate)
                    {
                     return true;
                     break;
                    }
                }
                 if (stix == tabmax)
                    {
                     alert("\n the state abbreviation is not correct. ");
                     return false;
                    }

	   }
}

function chkpassword()
{
var wstr = "1";

        wstr = document.memform.mpasswd.value;

	if (document.memform.mpasswd.value == "" || document.memform.mpasswd.value == null)
           {
		alert("\n no password entered");
		return false;
	   }
	else
	   {
            if (wstr.length < 6)
               {
		alert("\n password must be at least 6 characters");
		return false;
	       }
            else
               {
		return true;
               }

	   }
}

function chkuserid()
{
var wstr = "1";

        wstr = document.memform.muserid.value;

	if (document.memform.muserid.value == "" || document.memform.muserid.value == null)
           {
		alert("\n no UserID entered");
		return false;
	   }
	else
	   {
            if (wstr.length < 5)
               {
		alert("\n UserID is less than 5 characters");
		return false;
	       }
            else
               {
		return true;
               }
	   }
}

function chkzip5()
{
var wstr = "1";

        wstr = document.memform.mzip5.value;

	if (document.memform.mzip5.value != "" && document.memform.mzip5.value != null)
           {
            if (isNaN(document.memform.mzip5.value))
               {
                alert("\n zip code is not a number");
		return false;
	       }
            else
               {
                if (wstr.length < 5)
                   {
                    alert("\n zip code is less than 5 digits");
		    return false;
	           }
                else
                   {
                    return true;
                   }
               }
            }
	else
	   {
		return true;
	   }
}

function chkzip4()
{
var wstr = "1";

        wstr = document.memform.mzip4.value;

	if (document.memform.mzip4.value != "" && document.memform.mzip4.value != null)
           {
            if (isNaN(document.memform.mzip4.value))
               {
                alert("\n zip plus4 code is not a number");
		return false;
	       }
            else
               {
                if (wstr.length < 4)
                   {
                    alert("\n zip plus4 code is less than 4 digits");
		    return false;
	           }
                else
                   {
                    return true;
                   }
               }
            }
	else
	   {
		return true;
	   }
}

function chkmarea1()
{
var wstr = "1";

        wstr = document.memform.marea1.value;

	if (document.memform.marea1.value != "" && document.memform.marea1.value != null)
           {
            if (isNaN(document.memform.marea1.value))
               {
                alert("\n area code code is not a number in home phone");
		return false;
	       }
            else
               {
                if (wstr.length < 3)
                   {
                    alert("\n  home phone area code is less than 3 digits");
		    return false;
	           }
                else
                   {
                    return true;
                   }
               }
            }
	else
	   {
		return true;
	   }
}

function chkmarea2()
{
var wstr = "1";

        wstr = document.memform.marea2.value;

	if (document.memform.marea2.value != "" && document.memform.marea2.value != null)
           {
            if (isNaN(document.memform.marea2.value))
               {
                alert("\n cell phone area code code is not a number");
		return false;
	       }
            else
               {
                if (wstr.length < 3)
                   {
                    alert("\n cell phone area code is less than 3 digits");
		    return false;
	           }
                else
                   {
                    return true;
                   }
               }
            }
	else
	   {
		return true;
	   }
}

function chkphone()
{
var wstr = "1";
var wcleanstr = "1";
var wpre = "1";
var wnum = "1";
var wfoundpos = 0;

        wstr = document.memform.mhmphone.value;

	if (document.memform.mhmphone.value != "" && document.memform.mhmphone.value != null)
           {
            wfoundpos = wstr.indexOf("-");
            if (wfoundpos == -1)
               {
                wcleanstr = wstr;
                if (chkphonesub(wcleanstr) == false)
                   {
                    return false;
                   }
                else
                   {
                    return true;
                   }
               }
            else
               {
                if (wfoundpos != 3)
                   {
                    alert("\n dash is out of position in Home Phone");
		    return false;
                   }
                else
                   {
                    wpre = wstr.substr(0, 3);
                    wnum = wstr.substr(wfoundpos + 1);
                    wcleanstr= wpre.concat(wnum);
                    if (chkphonesub(wcleanstr) == false)
                       {
                        return false;
                       }
                    else
                       {
                        return true;
                       }
                   }
               }
            }

}

function chkphonesub(wcleanstr)
{

            if (isNaN(wcleanstr))
               {
                alert("\n Home Phone number is not a valid number");
		return false;
	       }
            else
               {
                if (wcleanstr.length < 7)
                   {
                    alert("\n Home phone number is less than 7 digits");
		    return false;
	           }
                else
                   {
                    if (document.memform.marea1.value == "" || document.memform.marea1.value == null)
                       {
                        alert("\n Home Phone area code is missing");
                        return false;
                       }
                    else
                       {
                        return true;
                       }
                   }
                }

}

function chkcellphone()
{
var wstr = "1";
var wcleanstr = "1";
var wpre = "1";
var wnum = "1";
var wfoundpos = 0;

        wstr = document.memform.mcellphone.value;

	if (document.memform.mcellphone.value != "" && document.memform.mcellphone.value != null)
           {
            wfoundpos = wstr.indexOf("-");
            if (wfoundpos == -1)
               {
                wcleanstr = wstr;
                if (chkphonesub2(wcleanstr) == false)
                   {
                    return false;
                   }
                else
                   {
                    return true;
                   }
               }
            else
               {
                if (wfoundpos != 3)
                   {
                    alert("\n dash is out of position in cell phone");
		    return false;
                   }
                else
                   {
                    wpre = wstr.substr(0, 3);
                    wnum = wstr.substr(wfoundpos + 1);
                    wcleanstr= wpre.concat(wnum);
                    if (chkphonesub2(wcleanstr) == false)
                       {
                        return false;
                       }
                    else
                       {
                        return true;
                       }
                   }
               }
            }

}

function chkphonesub2(wcleanstr)
{

            if (isNaN(wcleanstr))
               {
                alert("\n Phone number is not a valid number");
		return false;
	       }
            else
               {
                if (wcleanstr.length < 7)
                   {
                    alert("\n cell phone number is than 7 digits");
		    return false;
	           }
                else
                   {
                    if (document.memform.marea2.value == "" || document.memform.marea2.value == null)
                       {
                        alert("\n cell area code is missing");
                        return false;
                       }
                    else
                       {
                        return true;
                       }
                   }
                }

}
