/**
 * vSC Registration utilities
 * © Interactive Technology, Inc 2007
 */

function processRequest(doReq)
{
	if( doReq != null && !doReq )
	{
		post({},"DoRegistration","processApplications","rslt");
		return true;
	}

	var reqst = {};
	//PLAYER FIRSTNAME
	if( getInputValue("firstName").trim() == "" )
	{
		alert("A FIRST NAME for the player is required");
		$("firstName").focus();
		return false;
	}
	reqst.playerFirstName = getInputValue("firstName").trim();
	//PLAYER SURNAME
	if( getInputValue("lastName").trim() == "" )
	{
		alert("A LASTNAME for the player is required");
		$("lastName").focus();
		return false;
	}
	reqst.playerLastName = getInputValue("lastName").trim();
	//MIDDLE INITIAL
	if( getInputValue("mi").trim() == "" )
	{
		alert("A MIDDLE INITIAL for the player is required");
		$("mi").focus();
		return false;
	}
	reqst.playerMI = getInputValue("mi").trim();
	//ADDRESS
	if( getInputValue("address").trim() == "" )
	{
		alert("An ADDRESS for the player is required");
		$("address").focus();
		return false;
	}
	reqst.address = getInputValue("address").trim();
	//CITY
	if( getInputValue("city").trim() == "" )
	{
		alert("A CITY for the player is required");
		$("city").focus();
		return false;
	}
	reqst.city = getInputValue("city").trim();
	reqst.state = "AZ";
	//ZIPCODE
	if( getInputValue("postcode").trim() == "" )
	{
		alert("A ZIPCODE for the player is required");
		$("postcode").focus();
		return false;
	}
	reqst.postcode = getInputValue("postcode").trim();
	if( reqst.postcode.length != 5 || isNaN(parseInt(reqst.postcode)) )
	{
		alert("The ZIP CODE does not appear to be valid.\nPlease check you entry and resubmit.");
		$("postcode").focus();
		return false;
	}
	//DATE OF BIRTH
	if( $("mo").selectedIndex == 0 ||
			$("dy").selectedIndex == 0 ||
			$("yr").selectedIndex == 0
		)
	{
		alert("Please provide a date of birth for the player");
		$("mo").focus();
		return false;
	}
	reqst.mo = selectValue("mo");
	reqst.dy = selectValue("dy");
	reqst.yr = selectValue("yr");
	//M/F
	if( $("gender").selectedIndex == 0 )
	{
		alert("Please select a gender for the player");
		$("gender").focus();
		return false;
	}
	reqst.gender = selectValue("gender").trim();
	//SCHOOL
	if( $("school").selectedIndex == 0 )
	{
		alert("Please select a Vail school for the player");
		$("school").focus();
		return false;
	}
	reqst.school = selectValue("school");
	//GRADE
	if( $("grade").selectedIndex == 0 )
	{
		alert("Please select a Grade level for the player");
		$("school").focus();
		return false;
	}
	reqst.grade = selectValue("grade");
	//PLAYER PHONE and AREACODE
	if( getInputValue("playerTel").trim() != "" )
	{
		reqst.playerAreaCode = getInputValue("playerAreaCode").digit();
		if( reqst.playerAreaCode.length != 3 || isNaN(parseInt(reqst.playerAreaCode)) )
		{
			alert("The Player AREACODE does not appear to be valid.\nPlease check your entry and resubmit");
			$("playerAreaCode").focus();
			return false;
		}
		reqst.playerTel = getInputValue("playerTel").digit();
		if( reqst.playerTel.length != 7 || isNaN(parseInt(reqst.playerTel)) )
		{
			alert("The Player TELEPHONE does not appear to be valid.\nPlease check your entry and resubmit");
			$("playerTel").focus();
			return false;
		}
	}
	//PLAYER EMAIL
	if( getInputValue("playerEmail").trim() != "" )
		reqst.playerEmail = getInputValue("playerEmail").trim();
	//UNIFORM SIZE
	if( $("uniformSize").selectedIndex != -1 && selectValue("uniformSize") != "" )
		reqst.uniformSize = selectValue("uniformSize");
	//FATHER FIRSTNAME
	if( getInputValue("fatherFirstName").trim() == "" )
	{
		alert("A FIRST NAME for the father is required");
		$("fatherFirstName").focus();
		return false;
	}
	reqst.fatherFirstName = getInputValue("fatherFirstName").trim();
	//FATHER SURNAME
	if( getInputValue("fatherLastName").trim() == "" )
	{
		alert("A LASTNAME for the father is required");
		$("fatherLastName").focus();
		return false;
	}
	reqst.fatherLastName = getInputValue("fatherLastName").trim();
	//FATHER PHONE
	reqst.fatherAreaCode = getInputValue("fatherAreaCode").digit();
	if( reqst.fatherAreaCode.length != 3 ||
			isNaN(parseInt(reqst.fatherAreaCode)) ||
			(parseInt(reqst.fatherAreaCode)+"").length != 3 )
	{
		alert("The Father's AREACODE does not appear to be valid.\nPlease check your entry and resubmit");
		$("fatherAreaCode").focus();
		return false;
	}
	reqst.fatherTel = getInputValue("fatherTel").digit();
	if( reqst.fatherTel.length != 7 ||
			isNaN(parseInt(reqst.fatherTel)) ||
			(parseInt(reqst.fatherTel)+"").length != 7 )
	{
		alert("The Father's TELEPHONE does not appear to be valid.\nPlease check your entry and resubmit");
		$("fatherTel").focus();
		return false;
	}
	//FATHER EMAIL
	if( getInputValue("fatherEmail").trim() == "" )
	{
		alert("A valid EMAIL for the father is required");
		$("fatherEmail").focus();
		return false;
	}
	reqst.fatherEmail = getInputValue("fatherEmail").trim();
	//FATHER ASSIST
	reqst.fatherHelp = selectMultipleValues("fatherHelp",",");
	//MOTHER FIRSTNAME
	if( getInputValue("motherFirstName").trim() == "" )
	{
		alert("A FIRST NAME for the mother is required");
		$("motherFirstName").focus();
		return false;
	}
	reqst.motherFirstName = getInputValue("motherFirstName").trim();
	//MOTHER SURNAME
	if( getInputValue("motherLastName").trim() == "" )
	{
		alert("A LASTNAME for the mother is required");
		$("motherLastName").focus();
		return false;
	}
	reqst.motherLastName = getInputValue("motherLastName").trim();
	//MOTHER PHONE
	reqst.motherAreaCode = getInputValue("motherAreaCode").digit();
	if( reqst.motherAreaCode.length != 3 ||
			isNaN(parseInt(reqst.motherAreaCode)) ||
			(parseInt(reqst.motherAreaCode)+"").length != 3 )
	{
		alert("The Mother's AREACODE does not appear to be valid.\nPlease check your entry and resubmit");
		$("motherAreaCode").focus();
		return false;
	}
	reqst.motherTel = getInputValue("motherTel").digit();
	if( reqst.motherTel.length != 7 ||
			isNaN(parseInt(reqst.motherTel)) ||
			(parseInt(reqst.motherTel)+"").length != 7 )
	{
		alert("The Mother's TELEPHONE does not appear to be valid.\nPlease check your entry and resubmit");
		$("motherTel").focus();
		return false;
	}
	//MOTHER EMAIL
	if( getInputValue("motherEmail").trim() == "" )
	{
		alert("A valid EMAIL for the mother is required");
		$("motherEmail").focus();
		return false;
	}
	reqst.motherEmail = getInputValue("motherEmail").trim();
	//MOTHER ASSIST
	reqst.motherHelp = selectMultipleValues("motherHelp",",");
	//PHYSICIAN SURNAME
	if( getInputValue("physicianName").trim() == "" )
	{
		alert("A NAME for the physician is required");
		$("physicianName").focus();
		return false;
	}
	reqst.physicianName = getInputValue("physicianName").trim();
	//PHYSICIAN PHONE
	reqst.physicianAreaCode = getInputValue("physicianAreaCode").trim();
	if( reqst.physicianAreaCode.length != 3 ||
			isNaN(parseInt(reqst.physicianAreaCode)) ||
			(parseInt(reqst.physicianAreaCode)+"").length != 3 )
	{
		alert("The Physician's AREACODE does not appear to be valid.\nPlease check your entry and resubmit");
		$("physicianAreaCode").focus();
		return false;
	}
	reqst.physicianTel = getInputValue("physicianTel").digit();
	if( reqst.physicianTel.length != 7 ||
			isNaN(parseInt(reqst.physicianTel)) ||
			(parseInt(reqst.physicianTel)+"").length != 7 )
	{
		alert("The Physician's TELEPHONE does not appear to be valid.\nPlease check your entry and resubmit");
		$("physicianTel").focus();
		return false;
	}
	//PHYSICAL PROBLEMS
	if( getInputValue("physProblems").trim() != "" )
	{
		reqst.physProblems = getInputValue("physProblems").trim();
		if( reqst.physProblems.length>1024 )
			reqst.pysProblems = reqst.physProblems.substring(0,1024);
	}
	//RULES
	if( getInputValue("playerRuleName").trim() == "" ||
			getInputValue("parentRuleName").trim() == "" ||
			getRadioValue("ruleConsent") != "yes" )
	{
		alert("A Player must abide by the \"rules and regulations of the USYSA\".\n"+
					"Please provide a valid Player name, consenting Parent name and check the \"yes\""+
					" option in order to successfully submit this form.");
		$("playerRuleName").focus();
		return false;
	}
	reqst.playerRuleName = getInputValue("playerRuleName").trim();
	reqst.parentRuleName = getInputValue("parentRuleName").trim();
	reqst.ruleConsent = getRadioValue("ruleConsent");
	//MEDICAL CONSENT
	if( getInputValue("parentConsentMedicalName").trim() == "" ||
			getRadioValue("medicalConsent") != "yes" )
	{
		alert("A Parent must provide consent for emergency medical treatment for this player.\n"+
					"Please provide a consenting Parent name and check the \"yes\""+
					" option in order to successfully submit this form.");
		$("parentConsentMedicalName").focus();
		return false;
	}
	reqst.parentConsentMedicalName = getInputValue("parentConsentMedicalName").trim();
	reqst.medicalConsent = getRadioValue("medicalConsent");
	
	reqst.callback = "requestRslt";
	
	post(reqst,"DoRegistration","processApplication","rslt");	
}



function doSibling()
{
	if( confirm("Thank you your application is being processed.\n\nWould you like to register a sibling using the same data?") )
	{
		clearForSibling();
	}
	else
		post({},"DoRegistration","processApplications","rslt");
}


function clearForSibling()
{
	$("firstName").value = "";
	$("mi").value = "";
	$("mo").selectedIndex = 0;
	$("dy").selectedIndex = 0;
	$("yr").selectedIndex = 0;
	$("dy").setAttribute("defaultIndex","0")
	$("uniformSize").selectedIndex = 0;
	$("gender").selectedIndex = 0;
	$("school").selectedIndex = 0;
	$("grade").selectedIndex = 0;
	$("playerTel").value = "";
	$("playerEmail").value = "";
	$("playerRuleName").value = "";
	$("physProblems").value = "";
	$("ruleConsent").checked = true;
	$("medicalConsent").checked = true;
	tglBlks("siblingSubmit","normalSubmit");
	$("firstName").focus();
}



function showLink(link)
{
	var txt = "<a href='"+link+"' target='_blank' onclick=\"tglBlks(null,'siblingSubmit fileLink')\">"+
		"VSC APPLICATION<\/a>";
	$("fileLink").innerHTML = txt;
	tglBlks("fileLink link","siblingSubmit normalSubmit regForm")
}
