/***************************************************************************************
* LFA Show Application Class Library
****************************************************************************************
* This JavaScript library handles form hide/display, futurity and ALSA class calculations as well
* as dollar amount and quantity calculations for the recap sheet section of the form.
***************************************************************************************/

// Set futurity entry deadline date (the month parameter is 0-based, so 8 is September)
var FuturityDeadline = new Date(2010,8,1);

// Set ALSA show date to be used for class calculations
var ALSAShowDate = new Date(2010,8,17);

// Hide all Llama form tables except the first one.  This function runs in the onload event handler
function hideLlamaEntries()
	{
		for(var i=2;i<=8;i++) 
			{
				document.getElementById("llamaentry" + i).style.display = "none";
			}
	}
	
// Show the next llama form table on the page, if applicable
function addEntry()	
	{		
		// Iterate through the entries and see which one to enable next
		for(var i=2;i<=8;i++) 
			{
					if(document.getElementById("llamaentry" + i).style.display == "none")
						{
							document.getElementById("llamaentry" + i).style.display = "";
							//alert(i + ': ' + document.getElementById("llamaentry" + i).style.display);
							break;
							
						}
			}		
			
		// If we are above #1, display the Remove Entry button
		if(document.getElementById("llamaentry2").style.display == "")
			{				
				document.getElementById("delentry").style.display = "";				
			}
			
				
		// If we are at #8, hide the "Add Another Entry" button
		if(document.getElementById("llamaentry8").style.display == "")
			{
				document.getElementById("newentry").style.display = "none";
			}
	}
	
// Remove the current llama form table, if applicable
function removeEntry() 
	{	
		// Iterate through the entries and see which one to remove
		for(var i=8;i>=2;i--) 
			{
					if(document.getElementById("llamaentry" + i).style.display == "")
						{
							document.getElementById("llamaentry" + i).style.display = "none";
							
							// Llama Name
							document.getElementById("idLlama" + i).value = "";
							// DOB
							document.getElementById("DOB" + i).value = "";
							// Sex
							document.getElementById("Sex" + i).selectedIndex = 0;
							// ILR #
							document.getElementById("idILRNum" + i).value = "";
							// Handler's Name
							document.getElementById("idHandlersName" + i).value = "";
							// Futurity Entry Division
							document.getElementById("fen" + i).selectedIndex = 0;
							CalcFuturity();
							// Futurity Class
							document.getElementById("fcn" + i).selectedIndex = 0;
							// Sire Name
							document.getElementById("idSireName" + i).value = "";
							// Sire Owner
							document.getElementById("idSireOwner" + i).value = "";
							// Jackpot Obstacle
							// document.getElementById("idJO" + i).selectedIndex = 0;
							// CalcJackpot();
							// ALSA Membership #
							// document.getElementById("idAlsaNum" + i).value = "";
							// ALSA Animal #
							// document.getElementById("idAlsaAnimal" + i).value = "";
							// ALSA Class
							document.getElementById("acn" + i).selectedIndex = 0;
							// Halter Entry
							document.getElementById("aen" + i).selectedIndex = 0;
							CalcHalter();
							// Herdsire Name
							document.getElementById("idHerdsire" + i).value = "";
							// Herdsire ILR #
							document.getElementById("idHerdsireILR" + i).value = "";
							CalcHerdsire();
							break;
							
						}
			}
			
		// If we are at #1, disable the Remove Entry button
		if(document.getElementById("llamaentry2").style.display == "none")
			{				
				document.getElementById("delentry").style.display = "none";				
			}
			
		// If we are below #8, enable the Add New Entry button
		if(document.getElementById("llamaentry8").style.display == "none")
			{				
				document.getElementById("newentry").style.display = "";				
			}
			
	}
	
	
	
/* Futurity Show Classes */

// Amateur

var c0_date1 = ParseDate("9/21/2006");
var c0_date2 = ParseDate("4/21/2008");

// Silky/Traditional

var c12_date1 = ParseDate("6/19/2009");
var c12_date2 = ParseDate("4/19/2010");

var c34_date1 = ParseDate("9/19/2008");
var c34_date2 = ParseDate("6/20/2009");

// Suri

var cs12_date1 = ParseDate("6/19/2009");
var cs12_date2 = ParseDate("4/19/2010");

var cs34_date1 = ParseDate("9/19/2008");
var cs34_date2 = ParseDate("6/20/2009");

// Get the Division from the appropriate drop-down (either Futurity Entry Division or ALSA Wool Division	

function GetDivision(showType,thisLlama) {		
	var lDiv = document.getElementById(showType + thisLlama);
	return lDiv.options[lDiv.selectedIndex].value;
}	
	
		
function DetermineFuturityClass(thisLlama) {
	// alert(thisLlama);
	var varLlamaClass = 0;		
	var LlamaSex = "Sex" + thisLlama;
	var LlamaDOB = "DOB" + thisLlama;
	var showType = "fen";
	
	if ((document.getElementById(LlamaSex).value != "") && (document.getElementById(LlamaDOB).value != "") 
	&& (GetDivision(showType,thisLlama) != "")) {	
		
		// alert("inside division check");
		
		var varLlamaDOB = ParseDate(document.getElementById(LlamaDOB).value);
		
		// alert(varLlamaDOB + "\n" + c12_date1);
		
		var varDivision = GetDivision(showType,thisLlama);
		
		if (varDivision == "Silky/Traditional") {
		
			if ((varLlamaDOB >= c12_date1) && (varLlamaDOB <= c12_date2)) {
				varLlamaClass = 1;
			} else if ((varLlamaDOB >= c34_date1) && (varLlamaDOB <= c34_date2)) {
				varLlamaClass = 3;
			}
			
		} else if(varDivision == "Suri") {
			if ((varLlamaDOB >= cs12_date1) && (varLlamaDOB <= cs12_date2)) {
				varLlamaClass = 5;
			} else if ((varLlamaDOB >= cs34_date1) && (varLlamaDOB <= cs34_date2)) {
				varLlamaClass = 7;
			}
		} else if(varDivision == "Non-breeder") {
			if ((varLlamaDOB >= c0_date1) && (varLlamaDOB <= c0_date2)) {
				varLlamaClass = 9;
			}
		}
		
		if (document.getElementById(LlamaSex).value != "M" && varLlamaClass > 0) {
			varLlamaClass ++;
		}
		
		// Automatically select class			
		document.getElementById("fcn" + thisLlama).selectedIndex = varLlamaClass;
		
	}
	// Set the appropriate entry division back to N/A
	else { document.getElementById("fcn" + thisLlama).selectedIndex = 0; }
}
	
	
	
	
	
/*******************************************************************
* ALSA Show 
*******************************************************************/

function setAlsaDate(m) {
	var thisDate = new Date(ALSAShowDate);	
	thisDate.setMonth(thisDate.getMonth() - m);	
	return thisDate;
}


// Classes

// Suri
	
	var s1_Start = setAlsaDate(12);
	var s1_End = setAlsaDate(5);	
	var s2_Start = setAlsaDate(24);
	var s2_End = setAlsaDate(12);
	var s3_Start = setAlsaDate(36);
	var s3_End = setAlsaDate(25);
	var s4_Start = setAlsaDate(37);
	var s4_End = setAlsaDate(37);
	
// Silky
	
	var sk1_Start = setAlsaDate(12);
	var sk1_End = setAlsaDate(5);	
	var sk2_Start = setAlsaDate(24);
	var sk2_End = setAlsaDate(12);	
	var sk3_Start = setAlsaDate(36);
	var sk3_End = setAlsaDate(25);	
	var sk4_Start = setAlsaDate(37);
	var sk4_End = setAlsaDate(37);


// Light / Medium	
	
	var lm1_Start = setAlsaDate(12);
	var lm1_End = setAlsaDate(5);	
	var lm2_Start = setAlsaDate(24);
	var lm2_End = setAlsaDate(12);	
	var lm3_Start = setAlsaDate(36);
	var lm3_End = setAlsaDate(25);	
	var lm4_Start = setAlsaDate(37);
	var lm4_End = setAlsaDate(37);
	
// Medium / Heavy
	
	var mh1_Start = setAlsaDate(12);
	var mh1_End = setAlsaDate(5);	
	var mh2_Start = setAlsaDate(24);
	var mh2_End = setAlsaDate(12);	
	var mh3_Start = setAlsaDate(36);
	var mh3_End = setAlsaDate(25);	
	var mh4_Start = setAlsaDate(37);
	var mh4_End = setAlsaDate(37);

// Extreme Heavy
	
	var eh1_Start = setAlsaDate(12);
	var eh1_End = setAlsaDate(5);	
	var eh2_Start = setAlsaDate(24);
	var eh2_End = setAlsaDate(12);	
	var eh3_Start = setAlsaDate(36);
	var eh3_End = setAlsaDate(25);	
	var eh4_Start = setAlsaDate(37);
	var eh4_End = setAlsaDate(37);

// Mini
	
	var mini1_Start = setAlsaDate(12);
	var mini1_End = setAlsaDate(5);	
	var mini2_Start = setAlsaDate(24);
	var mini2_End = setAlsaDate(12);	
	var mini3_Start = setAlsaDate(36);
	var mini3_End = setAlsaDate(25);	
	var mini4_Start = setAlsaDate(37);
	var mini4_End = setAlsaDate(37);

	
	
	
// Non-breeder
	var nb1_Start = ParseDate("09/18/2007");
	var nb1_End = ParseDate("09/18/2008");
	var nb2_Start = ParseDate("09/18/2006");
	var nb2_End = ParseDate("08/18/2007");
	// 37 months AND OVER
	var nb3_Start = ParseDate("08/18/2006");
	var nb3_End = ParseDate("08/18/2006");



function DetermineAlsaClass(thisLlama) {
	var varLlamaClass = 0;		
	var LlamaSex = "Sex" + thisLlama;
	var LlamaDOB = "DOB" + thisLlama;
	var showType = "aen";
	
	if ((document.getElementById(LlamaSex).value != "") && (document.getElementById(LlamaDOB).value != "") 
	&& (GetDivision(showType,thisLlama) != "")) {			
		
		// alert("inside division check");
		
		var varLlamaDOB = ParseDate(document.getElementById(LlamaDOB).value);
		
		// alert(varLlamaDOB + "\n" + c12_date1);
		
		var varDivision = GetDivision(showType,thisLlama);		
		
		if(varDivision == "Suri") {
			if ((varLlamaDOB >= s1_Start) && (varLlamaDOB <= s1_End)) {
				varLlamaClass = 1;
			} else if ((varLlamaDOB >= s2_Start) && (varLlamaDOB <= s2_End)) {
				varLlamaClass = 2;
			} else if ((varLlamaDOB >= s3_Start) && (varLlamaDOB <= s3_End)) {
				varLlamaClass = 3;
			} else if (varLlamaDOB <= s4_Start) {
				varLlamaClass = 4;
			}
		}
		
		else if(varDivision == "Silky") {
			if ((varLlamaDOB >= sk1_Start) && (varLlamaDOB <= sk1_End)) {
				varLlamaClass = 9;
			} else if ((varLlamaDOB >= sk2_Start) && (varLlamaDOB <= sk2_End)) {
				varLlamaClass = 10;
			} else if ((varLlamaDOB >= sk3_Start) && (varLlamaDOB <= sk3_End)) {
				varLlamaClass = 11;
			} else if (varLlamaDOB <= sk4_Start) {
				varLlamaClass = 12;
			}
		}
		
		
		else if (varDivision == "Light/Medium") {
		
			if ((varLlamaDOB >= lm1_Start) && (varLlamaDOB <= lm1_End)) {
				varLlamaClass = 17;
			} else if ((varLlamaDOB >= lm2_Start) && (varLlamaDOB <= lm2_End)) {
				varLlamaClass = 18;
			} else if ((varLlamaDOB >= lm3_Start) && (varLlamaDOB <= lm3_End)) {
				varLlamaClass = 19;
			} else if (varLlamaDOB <= lm4_Start) {
				varLlamaClass = 20;
			}
		}		
		
		else if (varDivision == "Medium/Heavy") {
		
			if ((varLlamaDOB >= mh1_Start) && (varLlamaDOB <= mh1_End)) {
				varLlamaClass = 25;
			} else if ((varLlamaDOB >= mh2_Start) && (varLlamaDOB <= mh2_End)) {
				varLlamaClass = 26;
			} else if ((varLlamaDOB >= mh3_Start) && (varLlamaDOB <= mh3_End)) {
				varLlamaClass = 27;
			} else if (varLlamaDOB <= mh4_Start) {
				varLlamaClass = 28;
			}
		}		
		
		else if(varDivision == "Extreme Heavy") {
			if ((varLlamaDOB >= eh1_Start) && (varLlamaDOB <= eh1_End)) {
				varLlamaClass = 33;
			} else if ((varLlamaDOB >= eh2_Start) && (varLlamaDOB <= eh2_End)) {
				varLlamaClass = 34;
			} else if ((varLlamaDOB >= eh3_Start) && (varLlamaDOB <= eh3_End)) {
				varLlamaClass = 35;
			} else if (varLlamaDOB <= eh4_Start) {
				varLlamaClass = 36;
			}
		}
		
		else if(varDivision == "Mini") {		
			
			if ((varLlamaDOB >= mini1_Start) && (varLlamaDOB <= mini1_End)) {
				varLlamaClass = 41;
			} else if ((varLlamaDOB >= mini2_Start) && (varLlamaDOB <= mini2_End)) {
				varLlamaClass = 42;
			} else if ((varLlamaDOB >= mini3_Start) && (varLlamaDOB <= mini3_End)) {
				varLlamaClass = 43;
			} else if (varLlamaDOB <= mini4_Start) {
				varLlamaClass = 44;
			}
		}		
		
		else if(varDivision == "Non-breeder") {
			
			if ((varLlamaDOB >= nb1_Start) && (varLlamaDOB <= nb1_End)) {
				varLlamaClass = 25;
			} else if ((varLlamaDOB >= nb2_Start) && (varLlamaDOB <= nb2_End)) {
				varLlamaClass = 27;				
			} else if (varLlamaDOB <= nb3_Start) {				
				varLlamaClass = 29;
			}
		}	
		
		if ((document.getElementById(LlamaSex).value != "F") && (varLlamaClass > 0) && (varDivision != "Non-breeder")) {
			varLlamaClass = varLlamaClass + 4;
		}	
		
		// Automatically select class
		document.getElementById("acn" + thisLlama).selectedIndex = varLlamaClass;
		
	}
	// Set the appropriate entry division back to N/A
	else { document.getElementById("acn" + thisLlama).selectedIndex = 0; }
}
	
	
	

/***********************************************************************************
/* Calculate programmtic recap line items
/***********************************************************************************/

// Calculate Halter (ALSA) Entries
function CalcHalter() {	
	// Zero out the futurity entries variable and re-calculate	
	document.getElementById("idALSAEntries").value = 0;	
	for(var i=1;i<=8;i++) 
			{
				if (document.getElementById("aen" + i).value != "")
					{						
						document.getElementById("idALSAEntries").value++;
					}
			}			
	// Change ALSA Entries & Fee Display
	document.getElementById("divALSAEntries").innerHTML = document.getElementById("idALSAEntries").value;
	document.getElementById("divFeeALSA").innerHTML = "= $" 
	+ 
	round_decimals(document.getElementById("idFeeALSA").value * document.getElementById("idALSAEntries").value,2);
	
	CalculateTotal();
	
	}
	
// Calculate Futurity Entries
function CalcFuturity() {	
	
	// Set current date
	var curDate = new Date(); // 2009,11,1
	
	// Futurity type (Member before/after, non-member)	
	var idEntries = "idFuturityEntriesNon";
	var divEntries = "divFuturityNon";
	var divFee = "divFeeFuturityNon";
	var idFee = "idFeeFuturityNon";
	
	// Amateur Futurity variables		
	// amIdEntries = "idAmFuturityEntries";
	// amDivEntries = "divAmFuturity";
	// amDivFee = "divFeeAmFuturity";
	// amIdFee = "idFeeAmFuturity";
	// document.getElementById("idAmFuturityEntries").value = 0;
	// document.getElementById("divAmFuturity").innerHTML = "0";
	
	// Zero out the futurity entries variable and re-calculate	
	document.getElementById("idFuturityEntriesBefore").value = 0;
	document.getElementById("divFuturityBefore").innerHTML = "0";
	document.getElementById("divFeeFuturityBefore").innerHTML = "= $0.00";
	document.getElementById("idFuturityEntriesAfter").value = 0;
	document.getElementById("divFuturityAfter").innerHTML = "0";
	document.getElementById("divFeeFuturityAfter").innerHTML = "= $0.00";
	document.getElementById("idFuturityEntriesNon").value = 0;
	document.getElementById("divFuturityNon").innerHTML = "0";
	document.getElementById("divFeeFuturityNon").innerHTML = "= $0.00";
	document.getElementById("idFuturityEntriesNonLate").value = 0;
	document.getElementById("divFuturityNonLate").innerHTML = "0";
	document.getElementById("divFeeFuturityNonLate").innerHTML = "= $0.00";
	
	// Determine membership status and date
	if (document.getElementById("LFAMemberTrue").checked == 1) {
		// Member, so check date
		if (curDate <= FuturityDeadline) {
			// Before or on deadline			
			idEntries = "idFuturityEntriesBefore";
			divEntries = "divFuturityBefore";
			divFee = "divFeeFuturityBefore";
			idFee = "idFeeFuturityBefore";
		}
		else {
			// After deadline			
			idEntries = "idFuturityEntriesAfter";
			divEntries = "divFuturityAfter";
			divFee = "divFeeFuturityAfter";
			idFee = "idFeeFuturityAfter";
		}
	}
	
	// Non-member, check deadline
	else {
		if (curDate > FuturityDeadline) {
			// After deadline (default is on/before deadline so nothing needs to be done further if that is the case	
			idEntries = "idFuturityEntriesNonLate";
			divEntries = "divFuturityNonLate";
			divFee = "divFeeFuturityNonLate";
			idFee = "idFeeFuturityNonLate";
		}	
	}
	
	for(var i=1;i<=8;i++) 
			{
				if (document.getElementById("fen" + i).value != "")
					{
						// If the current Entry Division select box is "Amateur" increment the counts for that line item
						if (document.getElementById("fen" + i).value == "Amateur") {
							document.getElementById(amIdEntries).value++;
						}
						// Increment counts for the current futurity type				
						else {
						document.getElementById(idEntries).value++;
						}
					}
			}			
	
	// Change futurity Entries & Fee Display
	document.getElementById(divEntries).innerHTML = document.getElementById(idEntries).value;	
	
	document.getElementById(divFee).innerHTML = "= $" 
	+ 
	round_decimals(document.getElementById(idFee).value * document.getElementById(idEntries).value,2);	
	
	/* Amateur Futurity
	document.getElementById(amDivEntries).innerHTML = document.getElementById(amIdEntries).value;
	document.getElementById(amDivFee).innerHTML = "= $" 
	+ 
	round_decimals(document.getElementById(amIdFee).value * document.getElementById(amIdEntries).value,2);
	*/
	
	CalculateTotal();
	
	}
	
	
	// Calculate Complementary Stalls
	function CalcCompStalls(sType) {	
		var cStalls = 0;		
		
		if(sType == "Diamond") {
			cStalls = 2;
			}
		else if (sType == "Gold") {
			cStalls = 1;
			}

		document.getElementById("idCompStalls").value = cStalls;
		document.getElementById("divCompStalls").innerHTML = cStalls;
		
		}
	
	/* Calculate Jackpot Entries
	function CalcJackpot() {	
		// Zero out the jackpot entries variable and re-calculate	
		document.getElementById("idJackpotEntries").value = 0;
		document.getElementById("idJackpotEntriesG").value = 0;
		for(var i=1;i<=8;i++) 
				{
					if (document.getElementById("idJO" + i).value != "")
						{
							// Obstacle type check
							if(document.getElementById("idJO" + i).value == "Open") {
								document.getElementById("idJackpotEntries").value++;
							}
							else {
								document.getElementById("idJackpotEntriesG").value++;
							}
						}
				}			
		// Change Jackpot Entries & Fee Display
		document.getElementById("divJackpotEntries").innerHTML = document.getElementById("idJackpotEntries").value;
		document.getElementById("divJackpotPrice").innerHTML = "= $" 
		+ 
		round_decimals(document.getElementById("idFeeJackpot").value * document.getElementById("idJackpotEntries").value,2);

		document.getElementById("divJackpotEntriesG").innerHTML = document.getElementById("idJackpotEntriesG").value;
		document.getElementById("divJackpotPriceG").innerHTML = "= $" 
		+ 
		round_decimals(document.getElementById("idFeeJackpotG").value * document.getElementById("idJackpotEntriesG").value,2);

		CalculateTotal();

		}
	*/
	
	// Calculate Herdsire entries
	function CalcHerdsire() {
		// Zero out the herdsire entries variable and re-calculate	
	document.getElementById("idHerdsireNomCount").value = 0;	
	for(var i=1;i<=8;i++) 
			{
				if (document.getElementById("idHerdsire" + i).value != "")
					{						
						document.getElementById("idHerdsireNomCount").value++;
					}
			}			
	// Change Jackpot Entries & Fee Display
	document.getElementById("divHerdsireNomCount").innerHTML = document.getElementById("idHerdsireNomCount").value;
	document.getElementById("divHerdsireFee").innerHTML = "= $" 
	+ 
	round_decimals(document.getElementById("idHerdsireNominationFee").value 
	* 
	document.getElementById("idHerdsireNomCount").value,2);
	
	CalculateTotal();
	
	}
	
	// Calculate Program Advertising
	function CalcProgramAd(adOption) {	
		var programAdFee = 0;		
		// Zero out the jackpot entries variable and re-calculate	
		if (adOption != "") {
			if (adOption == "Full Page Ad") programAdFee = document.getElementById("idFeeProgramAdFull").value;
			else if (adOption == "Half Page Ad") programAdFee = document.getElementById("idFeeProgramAdHalf").value;
			else if (adOption == "Quarter Page Ad") programAdFee = document.getElementById("idFeeProgramAdQuarter").value;
			else if (adOption == "Business Card") programAdFee = document.getElementById("idFeeProgramAdBC").value;
		}			
		
		if (programAdFee > 0) {
			document.getElementById("divProgramAdQty").innerHTML = 1;
			document.getElementById("divProgramAdFee").innerHTML = "$" + round_decimals(programAdFee,2);
			document.getElementById("divProgramAdTotal").innerHTML = "= $" + round_decimals(programAdFee,2);
			}
		else {
			// Set all back to 0
			document.getElementById("divProgramAdQty").innerHTML = 0;
			document.getElementById("divProgramAdFee").innerHTML = "$0.00";
			document.getElementById("divProgramAdTotal").innerHTML = "= $0.00";
		}
		
		document.getElementById("idFeeProgramAdTotal").value = programAdFee;
		
		CalculateTotal();
		
	}
	
	// Calculate Harvest class sponsorship
	function CalcHarvestSponsor(spOption) {	
		var sponsorFee = 0;		
		// Zero out the harvest class sponsor fee and recalculate
		if (spOption != "") {
			if (spOption == "Class Sponsor") sponsorFee = document.getElementById("idFeeHarvestSponsorClass").value;
			else if (spOption == "Grand/Reserve Division Sponsor") sponsorFee = document.getElementById("idFeeHarvestSponsorReserve").value;			
		}			
		
		if (sponsorFee > 0) {
			document.getElementById("divHarvestSponsorQty").innerHTML = 1;
			document.getElementById("divHarvestSponsorFee").innerHTML = "$" + round_decimals(sponsorFee,2);
			document.getElementById("divHarvestSponsorTotal").innerHTML = "= $" + round_decimals(sponsorFee,2);
			}
		else {
			// Set all back to 0
			document.getElementById("divHarvestSponsorQty").innerHTML = 0;
			document.getElementById("divHarvestSponsorFee").innerHTML = "$0.00";
			document.getElementById("divHarvestSponsorTotal").innerHTML = "= $0.00";
		}
		
		document.getElementById("idHarvestSponsorTotal").value = sponsorFee;
		
		CalculateTotal();
		
	}
	
/***********************************************************************************
/* Calculate manually-entered recap line items
/***********************************************************************************/

// Check for NaN onblur() and set the field back to 0
function CheckNaN(thisField) {
	if(isNaN(thisField.value) || thisField.value == '') {
		thisField.value = 0;
	}
	
	CalculateTotal();
	
}

// Calculate Non-ALSA Members Fee
function CalcNonALSA() {	
	// Change Non-ALSA Members Fee Display
		if(!isNaN(document.getElementById("idNonALSAEntries").value)) {		
		document.getElementById("divFeeNonALSA").innerHTML = "= $" 
		+ 
		round_decimals(document.getElementById("idNonALSAEntries").value 
		* 
		document.getElementById("idFeeNonALSA").value,2);		
		}
		else {			
			document.getElementById("idNonALSAEntries").value = 0;
			}
			
		CalculateTotal();
	}
	
// Calculate Late Entries
function CalcLateALSA() {	
	// Change Late Entries
		if(!isNaN(document.getElementById("idLateEntries").value)) {		
		document.getElementById("divFeeLateEntries").innerHTML = "= $" 
		+ 
		round_decimals(document.getElementById("idLateEntries").value 
		* 
		document.getElementById("idFeeLateEntries").value,2);		
		}
		else {			
			document.getElementById("idLateEntries").value = 0;
			}
			
		CalculateTotal();
			
	}
	
// Calculate Sod for stalls
function CalcSod() {	
	// Change Sod Entry
		if(!isNaN(document.getElementById("idNumSod").value)) {		
		document.getElementById("divSodFee").innerHTML = "= $" 
		+ 
		round_decimals(document.getElementById("idNumSod").value 
		* 
		document.getElementById("idSodFee").value,2);		
		}
		else {			
			document.getElementById("idNumSod").value = 0;
			}
			
		CalculateTotal();
			
	}
	
	
// Calculate Manually Entered Recap Items
function CalcRecapItem(numUnits,pricePerUnit,dspTotal) {	
	// Change Futurity price
		if(!isNaN(document.getElementById(numUnits).value)) {		
		document.getElementById(dspTotal).innerHTML = "= $" 
		+ 
		round_decimals(document.getElementById(numUnits).value 
		* 
		document.getElementById(pricePerUnit).value,2);		
		}
		else {			
			document.getElementById(numUnits).value = 0;
			}
			
		CalculateTotal();
	}
	
	
// Calculate Total Number of Sale Consignments
function CalcSaleConsignments() {	
	// Change Futurity price
		if(!isNaN(document.getElementById("idTotalSaleConsignments").value)) {		
			// Change Grand Total Number of Stalls
		}
		else {			
			document.getElementById("idTotalSaleConsignments").value = 0;
			}
			
		CalculateTotal();
			
	}
	
// Calculate Grand Total Number of Stalls Needed:
// Total Stalls (Animal or Display) + Herdsire Row + Transit Stall + Total Number of Sale Consignments
function CalcTotalStalls() {
		var gtStalls = 		
		// Total Stalls (Animal or Display)
		parseInt(document.getElementById("idTotalNumStalls").value,10)		
		+
		// Patio Front Stalls
		parseInt(document.getElementById("idPatioStallFront").value,10)
		+
		// Complementary Stalls
		parseInt(document.getElementById("idCompStalls").value,10)
		+
		// Herdsire Row (includes stall w/sod)
		parseInt(document.getElementById("idHerdsireRowQty").value,10)
		+
		// Transit Stall (2 llamas/stall)
		parseInt(document.getElementById("idTransitStallQty").value,10)
		+
		// Total Number of Sale Consignments
		parseInt(document.getElementById("idTotalSaleConsignments").value,10);
		
		if(isNaN(gtStalls)) gtStalls = 0;
		
		// Set hidden form field w/ grand total number of stalls
		document.getElementById("idGrandTotalStalls").value = gtStalls;
		// Set div w/ grand total number of stalls
		document.getElementById("divGrandTotalStalls").innerHTML = gtStalls;
		
		CalculateTotal();
		
	}
	
function CalculateTotal() {
		var Total = 0;
		
		Total = Total + 
		( document.getElementById("idALSAEntries").value * document.getElementById("idFeeALSA").value );
		
		Total = Total + 
		( document.getElementById("idTotalNumStalls").value * document.getElementById("idStallFee").value );
		
		Total = Total + 
		( document.getElementById("idPatioStallFront").value * document.getElementById("idPatioStallFrontFee").value );
		
		Total = Total + 
		( document.getElementById("idHerdsireRowQty").value * document.getElementById("idHerdsireRowFee").value );
		
		Total = Total + 
		( document.getElementById("idTransitStallQty").value * document.getElementById("idTransitStallFee").value );
		
		/*
		Total = Total + 
		( document.getElementById("idNonALSAEntries").value * document.getElementById("idFeeNonALSA").value );
		*/
		
		Total = Total + 
		( document.getElementById("idLateEntries").value * document.getElementById("idFeeLateEntries").value );
		 
		Total = Total + 
		( document.getElementById("idNumSod").value * document.getElementById("idSodFee").value );
		 
		/*
		Total = Total + 
		( document.getElementById("idJackpotEntries").value * document.getElementById("idFeeJackpot").value );
		*/
		
		/*
		Total = Total + 
		( document.getElementById("idJackpotEntriesG").value * document.getElementById("idFeeJackpotG").value );
		*/
		
		Total = Total + 
		( document.getElementById("idFuturityEntriesBefore").value * document.getElementById("idFeeFuturityBefore").value );
		Total = Total + 
		( document.getElementById("idFuturityEntriesAfter").value * document.getElementById("idFeeFuturityAfter").value );
		Total = Total + 
		( document.getElementById("idFuturityEntriesNon").value * document.getElementById("idFeeFuturityNon").value );
		Total = Total + 
		( document.getElementById("idFuturityEntriesNonLate").value * document.getElementById("idFeeFuturityNonLate").value );
		/*
		Total = Total + 
		( document.getElementById("idAmFuturityEntries").value * document.getElementById("idFeeAmFuturity").value );
		*/
		
		Total = Total + 
		( document.getElementById("idHerdsireNomCount").value 
		* document.getElementById("idHerdsireNominationFee").value );
		 
		Total = Total + 
		( 1 * document.getElementById("idFeeProgramAdTotal").value );
		
		Total = Total + 
		( 1 * document.getElementById("idHarvestSponsorTotal").value );
		
		// Set TotalFee
		document.getElementById("idTotalFee").value = Total;
		
		// Set Total Fee div
		document.getElementById("divTotalFee").innerHTML = "$" + round_decimals(Total, 2);
				
	}
	
// Enable the Futurity and ALSA class drop-downs on form submission
function enableClasses() {
	for(var i=1;i<=8;i++) {
		document.getElementById("fcn" + i).disabled = "";
		document.getElementById("acn" + i).disabled = "";
	}
	return true;
}



function CheckRequiredFields() {
		var missingfields = ""
		
		if (document.form1.EntrantsName.value == "") {
			missingfields = missingfields + "Entrants Name \n";
		}
		if (document.form1.FarmName.value == "") {
			missingfields = missingfields + "Farm Name \n";
		}
		if (document.form1.FarmAddress_1.value == "") {
			missingfields = missingfields + "Farm Street Address \n";
		}
		if (document.form1.FarmCity.value == "") {
			missingfields = missingfields + "Farm City \n";
		}
		if (document.form1.FarmState.value == "") {
			missingfields = missingfields + "Farm State \n";
		}
		if (document.form1.FarmZip.value == "") {
			missingfields = missingfields + "Farm Zip \n";
		}
		if (document.form1.FarmPhone.value == "") {
			missingfields = missingfields + "Farm Phone \n";
		}
		if (document.form1.OfficePhone.value == "") {
			missingfields = missingfields + "Office Phone \n";
		}
		if (document.form1.FarmEmail.value == "") {
			missingfields = missingfields + "Email Address \n";
		}
		
		if (missingfields != "") {
			alert("The following required fields have been left blank. \n" + missingfields);
			return false;
			} 
		else {			
				return CheckRequiredLlamaFields();			
				return true;
			}		
		}

	function CheckRequiredLlamaFields() {
		var missingfields = "";		
		
		// Futurity Class for entry #1
		var fClass = document.getElementById("fcn1");
		
		// ALSA Class for entry #1
		var aClass = document.getElementById("acn1");
		
		// Combine the class number and alsa class of the first entry.
		// This variable will then be checked to see if at least one drop-down has a selection
		var checkClass = fClass.options[fClass.selectedIndex].value +
		aClass.options[aClass.selectedIndex].value;		
		
		if (document.getElementById("idLlama1").value == "") {
			missingfields = missingfields + "Llama Name \n";
		}
		if (document.getElementById("idILRNum1").value == "") {
			missingfields = missingfields + "Llama ILR Number \n";
		}
		if (document.getElementById("Sex1").value == "") {
			missingfields = missingfields + "Llama Sex \n";
		}
		if (document.getElementById("DOB1").value == "") {
			missingfields = missingfields + "Llama DOB \n";
		}
		if (checkClass == "") {
			missingfields = missingfields + "Llama and/or ALSA Class (This is an automated field based on the Sex, DOB, and selected Division. Please check that this animal falls into an appropriate class) \n";
		}
		
		/* Removed per Fran, 9/3/2009
		if (document.getElementById("idSireName1").value == "") {
			missingfields = missingfields + "Llama Sire Name \n";
		}
		if (document.getElementById("idSireOwner1").value == "") {
			missingfields = missingfields + "Llama Sire Owner \n";
		}
		*/
	
		if (missingfields != "") {
			alert("The following required fields have been left blank. \n" + missingfields);
			return false;
		} else {
			return CheckTermsAndConditions();
		}
	}