//form check

function formCheck(formobj){
	// Enter name of mandatory fields
	
	var fieldRequired = Array("firstName", "lastName", "usag", "address" , "city" , "state" , "zipcode" , "club" , "coach" , "tshirt", "region" , "program" , "division" , "event[]","birthdate","grade");
	
	// Enter field description to appear in the dialog box
		  
	
	var fieldDescription = Array("First Name", "Last Name", "USAG #", "Address" , "City" , "State" , "Zip Code" , "Club" , "Coach" , "T-Shirt Size" , "Region" , "Program" , "Division" , "Event/Aparatus", "Birth Date","Grade/Year in School");
	
	
	// dialog message
	
	var alertMsg = "Please complete the following fields:\n\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}


function checkNumeric(objName,comma,period,hyphen)
{
	var numberfield = objName;
	if (chkNumeric(objName,comma,period,hyphen) == false)
	{
		numberfield.select();
		numberfield.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function chkNumeric(objName,comma,period,hyphen)
{
// only allow 0-9 be entered, plus any values passed
// (can be in any order, and don't have to be comma, period, or hyphen)
// if all numbers allow commas, periods, hyphens or whatever,
// just hard code it here and take out the passed parameters
var checkOK = "0123456789" + comma + period + hyphen;
var checkStr = objName;
var allValid = true;
var decPoints = 0;
var allNum = "";

for (i = 0;  i < checkStr.value.length;  i++)
{
ch = checkStr.value.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}
if (!allValid)
{	
alertsay = "Please enter only these values \""
alertsay = alertsay + checkOK + "\" in this field."
alert(alertsay);
checkStr.value="";
return (false);
}
}

function checkLength(inname)
  
  {
  
  var zip = "zipcode";
      
  if (inname == zip)
  
  {
  
  if (document.visaForm.zipcode.value.length < 5)
  
  {
  
  alert ("Your Zip Code must contain 5 digits");
  var toFocus = document.visaForm.zipcode;
  toFocus.focus();
  
  }
  
  }
  
  if (inname == "usag")
  
  {
  
  if (document.visaForm.usag.value.length < 6)
  
  {
  
  alert ("Your USAG# must contain 6 digits");
  var toFocus = document.visaForm.usag;
  toFocus.focus();
  
  }
  
  }
  
  }


function checkPhone()
  
  {
  
  var phone1= document.visaForm.homePhone1.value;
  var phone2= document.visaForm.homePhone2.value;
  var phone3= document.visaForm.homePhone3.value;
  var homePhone = phone1 + "-" + phone2 + "-" + phone3;
  
    
  if (homePhone.length != 12)
  
  {
  
  alert ("Your home phone number is required.");
  return false;
  
  }
  
   
  }
