    function ParseDate( str1 )
    {
        // Parse the string in DD/MM/YYYY format
        re = /(\d{1,2})\/(\d{1,2})\/(\d{4})/
        var arr = re.exec( str1 );
		try {
        	return new Date( parseInt(arr[3]), parseInt(arr[1], 10) - 1, parseInt(arr[2], 10) );
		}
		catch(er) {
			alert("'" + str1 + "' is not a valid date value");
		}
    }
	
	function round_decimals(original_number, decimals) {
		var result1 = original_number * Math.pow(10, decimals)
		var result2 = Math.round(result1)
		var result3 = result2 / Math.pow(10, decimals)
		return pad_with_zeros(result3, decimals)
	}

	function pad_with_zeros(rounded_value, decimal_places) {
	
		// Convert the number to a string
		var value_string = rounded_value.toString()
		
		// Locate the decimal point
		var decimal_location = value_string.indexOf(".")
	
		// Is there a decimal point?
		if (decimal_location == -1) {
			
			// If no, then all decimal places will be padded with 0s
			decimal_part_length = 0
			
			// If decimal_places is greater than zero, tack on a decimal point
			value_string += decimal_places > 0 ? "." : ""
		}
		else {
	
			// If yes, then only the extra decimal places will be padded with 0s
			decimal_part_length = value_string.length - decimal_location - 1
		}
		
		// Calculate the number of decimal places that need to be padded with 0s
		var pad_total = decimal_places - decimal_part_length
		
		if (pad_total > 0) {
			
			// Pad the string with 0s
			for (var counter = 1; counter <= pad_total; counter++) 
				value_string += "0"
			}
		return value_string
	}
	
	function CheckTermsAndConditions() {
		if (document.form1.TermsConditions.checked != true) {
			alert("You must agree to the Terms & Conditions of this application before continuing.");
			return false;
		} else {
			return true;
		}
	}
	
	function CheckRequiredFarmFields(SecondaryCheck) {
		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 {
			if (SecondaryCheck == 1) {
				return CheckRequiredAnimalFields();
			} else if (SecondaryCheck == 2) {
				return CheckRequiredSaleAnimalFields();
			} else {
				return true;
			}
		}
	}

	function CheckRequiredAnimalFields() {
		var missingfields = ""
		
		if (document.form1.LlamaName.value == "") {
			missingfields = missingfields + "Llama Name \n";
		}
		if (document.form1.LlamaILR.value == "") {
			missingfields = missingfields + "Llama ILR Number \n";
		}
		if (document.form1.LlamaSex.value == "") {
			missingfields = missingfields + "Llama Sex \n";
		}
		if (document.form1.LlamaDOB.value == "") {
			missingfields = missingfields + "Llama DOB \n";
		}
		if (document.form1.LlamaClass.value == "") {
			missingfields = missingfields + "Llama 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";
		}
		if (document.form1.LlamaSireName.value == "") {
			missingfields = missingfields + "Llama Sire Name \n";
		}
		if (document.form1.LlamaSireOwner.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();
		}
	}
	
	function CheckRequiredSaleAnimalFields() {
		var missingfields = ""
		
		if (document.form1.LlamaName.value == "") {
			missingfields = missingfields + "Llama Name \n";
		}
		if (document.form1.LlamaILR.value == "") {
			missingfields = missingfields + "Llama ILR Number \n";
		}
		if (document.form1.LlamaSex.value == "") {
			missingfields = missingfields + "Llama Sex \n";
		}
		if (document.form1.LlamaDOB.value == "") {
			missingfields = missingfields + "Llama DOB \n";
		}
		if (document.form1.LlamaServiceSire.value == "") {
			missingfields = missingfields + "Llama Service Sire \n";
		}
		/*
		if (form1.LlamaBreedingDate.value == "") {
			missingfields = missingfields + "Llama Breeding Date \n";
		}
		*/
		if (document.form1.LlamaCatalogStatement.value == "") {
			missingfields = missingfields + "Catalog Statement \n";
		}
	
		if (missingfields != "") {
			alert("The following required fields have been left blank. \n" + missingfields);
			return false;
		} else {
			return CheckTermsAndConditions();
		}
	}
	
	function CheckSponsorshipFields() {
		var missingfields = ""
		
		if (document.form1.SuperintendentName.value == "") {
			missingfields = missingfields + "Superintendent Name \n";
		}
		if (document.form1.SuperintendentEmail.value == "") {
			missingfields = missingfields + "Superintendent Email \n";
		}
		if (document.form1.SuperintendentPhone.value == "") {
			missingfields = missingfields + "Superintendent Phone \n";
		}
		if (document.form1.SubmittedBy.value == "") {
			missingfields = missingfields + "Submitted By \n";
		}		
	
		if (missingfields != "") {
			alert("The following required fields have been left blank. \n" + missingfields);
			return false;
		} else {
			return true;
		}
	}	
