

// The turkey calculator stuff 
function turktime()        //this defines the function (the script to run) 
{

//variables
var adults = window.document.turkey_form.adult_count.value;
var kids = window.document.turkey_form.kid_count.value;
var serve_time_picked = window.document.turkey_form.dinner_time_picked.selectedIndex;


//calculations
var total_turkey_weight = adults*1.5 + kids*.75; 
var total_stuffing = 2*(adults*1.5 + kids*.75);
var serve_time = serve_time_picked;

//calculation for total cooking time
if(total_turkey_weight=="0")
	{var total_cook_time = 0;}
else if(total_turkey_weight<18)
	{var total_cook_time = (0.04412*(total_turkey_weight-1)+3.75);}
else if (total_turkey_weight<23)
	{var total_cook_time = 4.5+(total_turkey_weight-18)*(0.125);}
else if (total_turkey_weight<24)
	{var total_cook_time = 5.25;}
else if (total_turkey_weight<25)
	{var total_cook_time = 5.5;}
else if (total_turkey_weight<31)
	{var total_cook_time = 5.5+(total_turkey_weight-24)*(0.166666);}
else
	{var total_cook_time = "N/A";
	 var adults=0;
	 var kids=0;
	 window.document.turkey_form.adult_count.value = 0;
	 window.document.turkey_form.kid_count.value = 0;
	 alert("This group is too big for one turkey.  Consider cooking two...or dining out!");
	 turktime();}


//calculate and display time to serve
var hours_serve = serve_time_picked+12;           	//hour in 24-hour format to serve
var mins_serve = 0;										//minutes to serve

if(hours_serve>12)
	{var hours_display=hours_serve-12;
	 var AM_PM=" PM";}
else if(hours_serve=="12")
	{var hours_display=12;
	 var AM_PM=" Noon";}
else
	{var hours_display=hours_serve;
	 var AM_PM=" AM";}
window.document.turkey_form.serve_time_here.value = hours_display+":0"+	mins_serve	+AM_PM;	//print to box


//new calculation of total cook time and print it to box
var hours_cook = parseInt(total_cook_time);											//hours to cook
var mins_cook =  parseInt((total_cook_time-parseInt(total_cook_time))*60);		//minutes to cook
window.document.turkey_form.total_cook_time_here_alt.value = hours_cook +" Hrs. " + mins_cook + " Mins.";				//print to box

//new calculations for "put in oven", "cover with foil" and "start 1 hour prep"


//minutes_display - "put in oven"
if(60-mins_cook=="60"){var put_in_oven_minutes="00";full_hour=0;}
else if(60-mins_cook<10){var put_in_oven_minutes="0"+(60-mins_cook);full_hour=1;}
else {var put_in_oven_minutes = 60-mins_cook;full_hour=1;}

//hours_display - "put in oven"  
if(hours_serve-hours_cook-full_hour>12){var put_in_oven_hours=hours_serve-hours_cook-full_hour-12; var AM_PM=" PM";}
else if(hours_serve-hours_cook-full_hour=="12"){var put_in_oven_hours=12; var AM_PM=" Noon";}
else{var put_in_oven_hours=hours_serve-hours_cook-full_hour; var AM_PM=" AM";}

//write put-in-oven-time to screen
window.document.turkey_form.put_in_oven_time_here.value = put_in_oven_hours +":" + put_in_oven_minutes + AM_PM;				//print to box

//new calculations for "cover with foil" 
total_foil_time=total_cook_time*.33;
var hours_foil_time = parseInt(total_foil_time);											//hours to cover
var mins_foil_time =  parseInt((total_foil_time-parseInt(total_foil_time))*60);		//minutes to cover

//minutes_display - "cover with foil"
if(60-mins_foil_time=="60"){var foil_minutes="00";foil_full_hour=0;}
else if(60-mins_foil_time<10){var foil_minutes="0"+60-mins_foil_time;foil_full_hour=1;}
else {var foil_minutes = 60-mins_foil_time;foil_full_hour=1;}

//hours_display - "cover with foil"  
if(hours_serve-hours_foil_time-foil_full_hour>12){var foil_hours=hours_serve-hours_foil_time-foil_full_hour-12; var foil_AM_PM=" PM";}
else if(hours_serve-hours_foil_time-foil_full_hour=="12"){var foil_hours=12; var foil_AM_PM=" Noon";}
else{var foil_hours=hours_serve-hours_foil_time-foil_full_hour; var foil_AM_PM=" AM";}

//display foil turkey time
window.document.turkey_form.cover_time_here.value = foil_hours + ":"+foil_minutes+foil_AM_PM;

//new calculations for "start prep" 
//this is one hour earlier than put in oven time so simply calculated the new hour_display and AM/PM

//hours_display - "prep"  
if(hours_serve-hours_cook-full_hour-1>12){var prep_hours=hours_serve-hours_cook-full_hour-13; var prep_AM_PM=" PM";}
else if(hours_serve-hours_cook-full_hour-1=="12"){var prep_hours=12; var prep_AM_PM=" Noon";}
else{var prep_hours=hours_serve-hours_cook-full_hour-1; var prep_AM_PM=" AM";}
window.document.turkey_form.prep_here.value = prep_hours +":" + put_in_oven_minutes + prep_AM_PM;				//print to box

//calculation for defrost time  - Defrost 1 day for every 4 lbs. of turkey
var defrost_days=parseInt(total_turkey_weight/4)+1;
var thanksgiving_date=22;
var defrost_date=22-defrost_days;
 

	if (defrost_days==1){var defrost_day = "Thu, Dec. 24" ;}
	else if (defrost_days==2){var defrost_day = "Wed, Dec. 23" ;}
	else if (defrost_days==3){var defrost_day = "Tue, Dec. 22" ;}
	else if (defrost_days==4){var defrost_day = "Mon, Dec. 21" ;}
	else if (defrost_days==5){var defrost_day = "Sun, Dec. 20" ;}
	else if (defrost_days==6){var defrost_day = "Sat, Dec. 19" ;}
	else if (defrost_days==7){var defrost_day = "Fri, Dec. 18" ;}
	else if (defrost_days==8){var defrost_day = "Thu, Dec. 17" ;}
	else if (defrost_days==9){var defrost_day = "Wed, Dec. 16" ;}
	else{var defrost_day = "N/A";}

window.document.turkey_form.defrost_here.value = defrost_day + ", 2009 before "+prep_hours +":" + put_in_oven_minutes + prep_AM_PM;  

//outputs and displays
window.document.turkey_form.pounds.value = total_turkey_weight + " LBS.";    //display turkey weight
window.document.turkey_form.cups.value = total_stuffing + " Cups";           //display stuffing needed

}
//end of turkey calculator stuff

