function chartInstructions(){
instructionWindow = open("recipeInstructions.html", "Instructions", "toolbar=no, location=no, directories=no, status=no, menubar=yes, scrollbars=no, resizable=no, width=400, height=125")
} // End chartInstructions function

function chartClearValues(){
document.conversionChart.firstMeasurement.selectedIndex=0
document.conversionChart.secondMeasurement.selectedIndex=0
document.conversionChart.measurementValue.value=""
document.conversionChart.outputValue.value=""

} // End chartClearValues function

function calculateChart(){
	// Assign variables
	firstUnit=document.conversionChart.firstMeasurement
	secondUnit=document.conversionChart.secondMeasurement
	userInput=document.conversionChart.measurementValue 
	chartOutput=document.conversionChart.outputValue 

	// Determine formula for Cups
	if(firstUnit.selectedIndex==0){
		switch(secondUnit.selectedIndex){
			case 0:  // Cups
				operation="multiply"
				amount=1
				break
			case 1:  // Gallons
				operation="divide"
				amount=16
				break
			case 2:  // Ounces
				operation="multiply"
				amount=8
				break
			case 3: // Pints
				operation="divide"
				amount=2
				break
			case 4: // Quarts
				operation="divide"
				amount=4
				break
			case 5: // Tablespoons
				operation="multiply"
				amount=16
				break
			case 6: // Teaspoons
				operation="multiply"
				amount=48
				break
		} // End Switch
	} // End Cups

	//Determine formula for Gallons
	if(firstUnit.selectedIndex==1){
		switch(secondUnit.selectedIndex){
			case 0: // Cups
				operation="multiply"
				amount=16
				break
			case 1: // Gallons
				operation="multiply"
				amount=1
				break
			case 2: // Ounces
				operation="multiply"
				amount=128
				break
			case 3: // Pints
				operation="multiply"
				amount=8
				break
			case 4: // Quarts
				operation="multiply"
				amount=4
				break
			case 5: // Tablespoons
				operation="multiply"
				amount=256
				break
			case 6: // Teaspoons
				operation="multiply"
				amount=768
				break				
		} // End switch
	} // End Gallons
	
	//Determine formula for Ounces
	if(firstUnit.selectedIndex==2){
		switch(secondUnit.selectedIndex){
			case 0: // Cups
				operation="divide"
				amount=8
				break
			case 1: // Gallons
				operation="divide"
				amount=128
				break
			case 2: // Ounces
				operation="multiply"
				amount=1
				break
			case 3: // Pints
				operation="divide"
				amount=16
				break
			case 4: // Quarts
				operation="divide"
				amount=32
				break
			case 5: // Tablespoons
				operation="multiply"
				amount=2
				break
			case 6: // Teaspoons
				operation="multiply"
				amount=6
				break
		} // End Switch
	} // End Ounces
	
	//Determine formula for Pints
	if(firstUnit.selectedIndex==3){
		switch(secondUnit.selectedIndex){
			case 0: // Cups
				operation="multiply"
				amount=2
				break
			case 1: // Gallons
				operation="divide"
				amount=8
				break
			case 2: // Ounces
				operation="multiply"
				amount=16
				break
			case 3: // Pints
				operation="multiply"
				amount=1
				break
			case 4: // Quarts
				operation="divide"
				amount=2
				break
			case 5: // Tablespoons
				operation="multiply"
				amount=32
				break
			case 6: // Teaspoons
				operation="multiply"
				amount=96
				break
		} // End Switch
	} // End Pints
	
	//Determine formula for Quarts
	if(firstUnit.selectedIndex==4){
		switch(secondUnit.selectedIndex){
			case 0: // Cups
				operation="multiply"
				amount=4
				break
			case 1: // Gallons
				operation="divide"
				amount=4
				break
			case 2: // Ounce
				operation="multiply"
				amount=32
				break
			case 3: // Pint
				operation="multiply"
				amount=2
				break
			case 4: // Quart
				operation="multiply"
				amount=1
				break
			case 5: // Tablespoon
				operation="multiply"
				amount=64
				break
			case 6: // Teaspoon
				operation="multiply"
				amount=192
				break
		} // End Switch
	} // End Quarts
	
	// Determine formula for Tablespoons
	if(firstUnit.selectedIndex==5){
		switch(secondUnit.selectedIndex){
			case 0: // Cups
				operation="divide"
				amount=16
				break
			case 1: // Gallons
				operation="divide"
				amount=256
				break
			case 2: // Ounce
				operation="divide"
				amount=2
				break
			case 3: // Pint
				operation="divide"
				amount=32
				break
			case 4: // Quarts
				operation="divide"
				amount=64
				break
			case 5: // Tablespoon
				operation="multiply"
				amount=1
				break
			case 6: // Teaspoon
				operation="multiply"
				amount=3
				break
		} // End Switch
	} // End Tablespoons
	
	// Determine formula for Teaspoons
	if(firstUnit.selectedIndex==6){
		switch(secondUnit.selectedIndex){
			case 0: // Cups
				operation="divide"
				amount=48
				break
			case 1: // Gallons
				operation="divide"
				amount=768
				break
			case 2: // Ounce
				operation="divide"
				amount=6
				break
			case 3: // Pint
				operation="divide"
				amount=96
				break
			case 4: // Quart 
				operation="divide"
				amount=192
				break
			case 5: // Tablespoon
				operation="divide"
				amount=3
				break
			case 6: // Teasoppn
				operation="multiply"
				amount=1
				break
		} // End Switch
	} // End Teaspoons
				
	// Perform math ******************************************************************************************
	// Convert fractional input to decimal for processing
	convertFractions(userInput)
	
	if(isNaN(userInput.value)){ alert("\"" + userInput.value + "\" is not a valid entry.  Please try again.") }
	else {
		if(operation=="multiply"){ chartOutput.value=userInput.value * amount }
		if(operation=="divide"){ chartOutput.value=userInput.value / amount }
	}
	
	// Convert decimal output to fractions if necessary.
	convertDecimals(chartOutput)
	convertDecimals(userInput)
} // End calculateChart

// Convert fractions to decimals
function convertFractions(whichField){
	if(whichField.value=="1/2") { whichField.value=.5 }
	if(whichField.value=="1/3") { whichField.value=.3333333333333333 }
	if(whichField.value=="1/4") { whichField.value=.25 }
	if(whichField.value=="1/6") { whichField.value=.6666666666666666 }
	if(whichField.value=="1/8") { whichField.value=.125 }
	if(whichField.value=="1/16") { whichField.value=.0625 }
	if(whichField.value=="1/32") { whichField.value=.03125 }
	if(whichField.value=="1/64") { whichField.value=.015625 }
	if(whichField.value=="1/128") { whichField.value=.0078125 }
	if(whichField.value=="1/256") { whichField.value=.00390625 }
}

// Convert decimals to fractions
function convertDecimals(whichField){
	if(whichField.value==.5) { whichField.value="1/2" }
	if(whichField.value==.3333333333333333) { whichField.value="1/3" }
	if(whichField.value==.25) { whichField.value="1/4" }
	if(whichField.value==.6666666666666666) { whichField.value="1/6" }
	if(whichField.value==.125) { whichField.value="1/8" }
	if(whichField.value==.0625) { whichField.value="1/16" }
	if(whichField.value==.03125) { whichField.value="1/32" }
	if(whichField.value==.015625) { whichField.value="1/64" }
	if(whichField.value==.0078125) { whichField.value="1/128" }
	if(whichField.value==.00390625) { whichField.value="1/256" }
} // End convertDecimals
