HEX
Server: Apache
System: Linux p3plzcpnl489526.prod.phx3.secureserver.net 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: vmasmheia229 (9244908)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /home/vmasmheia229/domains/taylorfarmsschoolservice.com/html/test/calc.html
<!--
validate input
-->
<html>
<head>

    <meta content="text/html;charset=utf-8" http-equiv="content-type" />
    <meta name="description" content="cmsmasters responsive html5 website template" />
    <meta name="keywords" content="html5, css3, template, responsive, adaptive" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="css/styles/fonts.css" type="text/css" media="screen" />
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:300,400,400italic,600' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="css/styles/jquery.prettyPhoto.css" type="text/css" media="screen" />

	<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
	<script type="text/javascript" src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
	<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/coffee-script/1.3.3/coffee-script.min.js"></script>
	<script type="text/javascript" src="https://github.com/typicaljoe/taffydb/raw/master/taffy.js"></script>

	<!--<link rel="stylesheet" href="js/datatables/css/jquery.dataTables.css"/>-->
	<link rel="stylesheet" href="js/tabletools/css/TableTools_JUI.css"/>
	<link rel="stylesheet" href="js/tabletools/css/TableTools.css"/>	
	<script type="text/javascript" src="js/datatables/js/jquery.dataTables.min.js"></script>


	<script type="text/javascript" src="js/tabletools/js/ZeroClipboard.js"></script>
	<script type="text/javascript" src="js/tabletools/js/TableTools.min.js"></script>
	

	<script>
 

	document.products = TAFFY(
		[
			 {"productid":1, "name": "Shredded Romaine W/Carrot 75/25 6/2#", "img":"http://k.img.com.ua/img/forall/a/14825/47.jpg"},
			 {"productid":2, "name": "Lite Caesar Kit 6/2#", "img":"http://k.img.com.ua/img/forall/a/14825/48.jpg"},
			 {"productid":3, "name": "Broccoli Slaw W/ Carrot 50/50 4/3#", "img":""},
			 {"productid":4, "name": "Broccoli Slaw Kit 4/3#", "img":""},
			 {"productid":5, "name": "Shredders Lite Caesar 50Ct", "img":""},
			 {"productid":6, "name": "Shredders Sesame Ginger Kit 50Ct", "img":""},
			 {"productid":7, "name": "Cinnamon Swirl Carrot Chips 50CT", "img":""}
//			 ,{"productid":8, "name": "Arugula 1/4#"} 
		]
	);
	
	document.nslp = TAFFY(
	[
{"productid":1,"quantity":2,"servings":73.66071428571428,"n1":"0","n2":"0","n3":"0","n4":"0.75","n5":"0.25","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":1,"quantity":1.875,"servings":78.57142857142857,"n1":"0","n2":"0","n3":"0","n4":"0.75","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":1,"quantity":1.75,"servings":84.18367346938774,"n1":"0","n2":"0","n3":"0","n4":"0.75","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":1,"quantity":1.625,"servings":90.65934065934064,"n1":"0","n2":"0","n3":"0","n4":"0.625","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":1,"quantity":1.5,"servings":98.21428571428571,"n1":"0","n2":"0","n3":"0","n4":"0.625","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":1,"quantity":1.375,"servings":107.14285714285712,"n1":"0","n2":"0","n3":"0","n4":"0.5","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":1,"quantity":1.25,"servings":117.85714285714285,"n1":"0","n2":"0","n3":"0","n4":"0.5","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":1,"quantity":1.125,"servings":130.95238095238093,"n1":"0","n2":"0","n3":"0","n4":"0.375","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":1,"quantity":1,"servings":147.32142857142856,"n1":"0","n2":"0","n3":"0","n4":"0.375","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":1,"quantity":0.875,"servings":168.36734693877548,"n1":"0","n2":"0","n3":"0","n4":"0.375","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":1,"quantity":0.75,"servings":196.42857142857142,"n1":"0","n2":"0","n3":"0","n4":"0.25","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":1,"quantity":0.625,"servings":235.7142857142857,"n1":"0","n2":"0","n3":"0","n4":"0.25","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":1,"quantity":0.5,"servings":294.6428571428571,"n1":"0","n2":"0","n3":"0","n4":"0.125","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":1,"quantity":0.25,"servings":589.2857142857142,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":1,"quantity":0.125,"servings":1178.5714285714284,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"}

, 

{"productid":2,"quantity":2,"servings":73.66071428571428,"n1":"0","n2":"0.625","n3":"0","n4":"0.75","n5":"0.25","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":2,"quantity":1.875,"servings":78.57142857142857,"n1":"0","n2":"0.5","n3":"0","n4":"0.75","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":2,"quantity":1.75,"servings":84.18367346938774,"n1":"0","n2":"0.5","n3":"0","n4":"0.75","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":2,"quantity":1.625,"servings":90.65934065934064,"n1":"0","n2":"0.5","n3":"0","n4":"0.625","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":2,"quantity":1.5,"servings":98.21428571428571,"n1":"0","n2":"0.375","n3":"0","n4":"0.625","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":2,"quantity":1.375,"servings":107.14285714285712,"n1":"0","n2":"0.375","n3":"0","n4":"0.5","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":2,"quantity":1.25,"servings":117.85714285714285,"n1":"0","n2":"0.375","n3":"0","n4":"0.5","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":2,"quantity":1.125,"servings":130.95238095238093,"n1":"0","n2":"0.25","n3":"0","n4":"0.375","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":2,"quantity":1,"servings":147.32142857142856,"n1":"0","n2":"0.25","n3":"0","n4":"0.375","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":2,"quantity":0.875,"servings":168.36734693877548,"n1":"0","n2":"0.25","n3":"0","n4":"0.375","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":2,"quantity":0.75,"servings":196.42857142857142,"n1":"0","n2":"0.125","n3":"0","n4":"0.25","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":2,"quantity":0.625,"servings":235.7142857142857,"n1":"0","n2":"0.125","n3":"0","n4":"0.25","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":2,"quantity":0.5,"servings":294.6428571428571,"n1":"0","n2":"0.125","n3":"0","n4":"0.125","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":2,"quantity":0.25,"servings":589.2857142857142,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":2,"quantity":0.125,"servings":1178.5714285714284,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"}
 
,

{"productid":3,"quantity":2,"servings":40,"n1":"0","n2":"0","n3":"0","n4":"1","n5":"1","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":3,"quantity":1.875,"servings":42.666666666666664,"n1":"0","n2":"0","n3":"0","n4":"0.875","n5":"0.875","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":3,"quantity":1.75,"servings":45.714285714285715,"n1":"0","n2":"0","n3":"0","n4":"0.875","n5":"0.875","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":3,"quantity":1.625,"servings":49.23076923076923,"n1":"0","n2":"0","n3":"0","n4":"0.75","n5":"0.75","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":3,"quantity":1.5,"servings":53.333333333333336,"n1":"0","n2":"0","n3":"0","n4":"0.75","n5":"0.75","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":3,"quantity":1.375,"servings":58.18181818181818,"n1":"0","n2":"0","n3":"0","n4":"0.625","n5":"0.625","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":3,"quantity":1.25,"servings":64,"n1":"0","n2":"0","n3":"0","n4":"0.625","n5":"0.625","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":3,"quantity":1.125,"servings":71.11111111111111,"n1":"0","n2":"0","n3":"0","n4":"0.5","n5":"0.5","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":3,"quantity":1,"servings":80,"n1":"0","n2":"0","n3":"0","n4":"0.5","n5":"0.5","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":3,"quantity":0.875,"servings":91.42857142857143,"n1":"0","n2":"0","n3":"0","n4":"0.375","n5":"0.375","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":3,"quantity":0.75,"servings":106.66666666666667,"n1":"0","n2":"0","n3":"0","n4":"0.375","n5":"0.375","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":3,"quantity":0.625,"servings":128,"n1":"0","n2":"0","n3":"0","n4":"0.25","n5":"0.25","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":3,"quantity":0.5,"servings":160,"n1":"0","n2":"0","n3":"0","n4":"0.25","n5":"0.25","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":3,"quantity":0.25,"servings":320,"n1":"0","n2":"0","n3":"0","n4":"0.125","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":3,"quantity":0.125,"servings":640,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"}
 
,
 
{"productid":4,"quantity":2,"servings":40,"n1":"0","n2":"0","n3":"0.25","n4":"1","n5":"1","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":4,"quantity":1.875,"servings":43,"n1":"0","n2":"0","n3":"0.25","n4":"0.875","n5":"0.875","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":4,"quantity":1.75,"servings":46,"n1":"0","n2":"0","n3":"0.25","n4":"0.875","n5":"0.875","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":4,"quantity":1.625,"servings":49,"n1":"0","n2":"0","n3":"0.125","n4":"0.75","n5":"0.75","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":4,"quantity":1.5,"servings":53,"n1":"0","n2":"0","n3":"0.125","n4":"0.75","n5":"0.75","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":4,"quantity":1.375,"servings":58,"n1":"0","n2":"0","n3":"0.125","n4":"0.625","n5":"0.625","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":4,"quantity":1.25,"servings":64,"n1":"0","n2":"0","n3":"0.125","n4":"0.625","n5":"0.625","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":4,"quantity":1.125,"servings":71,"n1":"0","n2":"0","n3":"0.125","n4":"0.5","n5":"0.5","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":4,"quantity":1,"servings":80,"n1":"0","n2":"0","n3":"0.125","n4":"0.5","n5":"0.5","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":4,"quantity":0.875,"servings":91,"n1":"0","n2":"0","n3":"0.125","n4":"0.375","n5":"0.375","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":4,"quantity":0.75,"servings":107,"n1":"0","n2":"0","n3":"0","n4":"0.375","n5":"0.375","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":4,"quantity":0.625,"servings":128,"n1":"0","n2":"0","n3":"0","n4":"0.25","n5":"0.25","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":4,"quantity":0.5,"servings":160,"n1":"0","n2":"0","n3":"0","n4":"0.25","n5":"0.25","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":4,"quantity":0.25,"servings":320,"n1":"0","n2":"0","n3":"0","n4":"0.125","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":4,"quantity":0.125,"servings":640,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"}
 
,

{"productid":5,"quantity":"n/a","servings":50,"n1":"0.25","n2":"0.5","n3":"0","n4":"0.625","n5":"0.125","n6":"0","n7":"0","n8":"0","n9":"0"}

,

{"productid":6,"quantity":"n/a","servings":50,"n1":"0.25","n2":"0","n3":"0.125","n4":"0.625","n5":"0.625","n6":"0","n7":"0","n8":"0","n9":"0"}

, 

{"productid":7,"quantity":"n/a","servings":50,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0.75","n6":"0","n7":"0","n8":"0","n9":"0"}
 
, 

{"productid":8,"quantity":2,"servings":66.66666666666667,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":8,"quantity":1.875,"servings":71.11111111111111,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":8,"quantity":1.75,"servings":76.19047619047619,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":8,"quantity":1.625,"servings":82.05128205128206,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":8,"quantity":1.5,"servings":88.8888888888889,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":8,"quantity":1.375,"servings":96.96969696969698,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":8,"quantity":1.25,"servings":106.66666666666667,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":8,"quantity":1.125,"servings":118.51851851851853,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":8,"quantity":1,"servings":133.33333333333334,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":8,"quantity":0.875,"servings":152.38095238095238,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":8,"quantity":0.75,"servings":177.7777777777778,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":8,"quantity":0.625,"servings":213.33333333333334,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":8,"quantity":0.5,"servings":266.6666666666667,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":8,"quantity":0.25,"servings":533.3333333333334,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"},
{"productid":8,"quantity":0.125,"servings":1066.6666666666667,"n1":"0","n2":"0","n3":"0","n4":"0","n5":"0","n6":"0","n7":"0","n8":"0","n9":"0"}
]

);

document.savedEntries = TAFFY([]);
/*
	document.nslp = TAFFY(
		[
		
			{"productid":1, "quantity":2.00, "servings":74, "n1":0,"n2":0,"n3":0,"n4":0.75,"n5":0.25,"n6":0,"n7":0,"n8":0,"n9":0},
			{"productid":1, "quantity":1.875, "servings":79, "n1":0,"n2":0,"n3":0,"n4":0.75,"n5":0.125,"n6":0,"n7":0,"n8":0,"n9":0},			 				
			{"productid":1, "quantity":1.75, "servings":84, "n1":0,"n2":0,"n3":0,"n4":0.75,"n5":0.125,"n6":0,"n7":0,"n8":0,"n9":0},				 				
			{"productid":1, "quantity":1.625, "servings":91, "n1":0,"n2":0,"n3":0,"n4":0.625,"n5":0.125,"n6":0,"n7":0,"n8":0,"n9":0},			 					
			{"productid":1, "quantity":1.50, "servings":98, "n1":0,"n2":0,"n3":0,"n4":0.625,"n5":0.125,"n6":0,"n7":0,"n8":0,"n9":0},			 					
			{"productid":1, "quantity":1.375, "servings":107, "n1":0,"n2":0,"n3":0,"n4":0.50,"n5":0.125,"n6":0,"n7":0,"n8":0,"n9":0},			 					
			{"productid":1, "quantity":1.25, "servings":118, "n1":0,"n2":0,"n3":0,"n4":0.50,"n5":0.125,"n6":0,"n7":0,"n8":0,"n9":0},			 					
			{"productid":1, "quantity":1.125, "servings":131, "n1":0,"n2":0,"n3":0,"n4":0.375,"n5":0.125,"n6":0,"n7":0,"n8":0,"n9":0},				 					
			{"productid":1, "quantity":1.00, "servings":147, "n1":0,"n2":0,"n3":0,"n4":0.375,"n5":0.125,"n6":0,"n7":0,"n8":0,"n9":0},				 				
			{"productid":1, "quantity":0.875, "servings":168, "n1":0,"n2":0,"n3":0,"n4":0.375,"n5":0.0,"n6":0,"n7":0,"n8":0,"n9":0},			 					
			{"productid":1, "quantity":0.75, "servings":196, "n1":0,"n2":0,"n3":0,"n4":0.25,"n5":0.0,"n6":0,"n7":0,"n8":0,"n9":0},				 				
			{"productid":1, "quantity":0.625, "servings":236, "n1":0,"n2":0,"n3":0,"n4":0.25,"n5":0.0,"n6":0,"n7":0,"n8":0,"n9":0},			 					
			{"productid":1, "quantity":0.50, "servings":295, "n1":0,"n2":0,"n3":0,"n4":0.125,"n5":0.0,"n6":0,"n7":0,"n8":0,"n9":0},			 				
			{"productid":1, "quantity":0.25, "servings":589, "n1":0,"n2":0,"n3":0,"n4":0.0,"n5":0.0,"n6":0,"n7":0,"n8":0,"n9":0},				 					
			{"productid":1, "quantity":0.125, "servings":1179, "n1":0,"n2":0,"n3":0,"n4":0.0,"n5":0.0,"n6":0,"n7":0,"n8":0,"n9":0}				 
			
		]
	);
	*/
	</script>
<script type="text/coffeescript">
dec2frac = (n) ->
  if not isNaN(n) and n isnt "" and n isnt "0" and n isnt "Infinity" and n isnt "-Infinity"
    dn = n.substr(n.lastIndexOf("."))
    nd = dn.length - 1
    den = 1
    i = undefined
    i = 1
    while i <= nd
      den *= 10
      i++
    num = Math.floor(n * den)
    i = 2
    while (if num > den then i < num else i < den)
      if num % i is 0 and den % i is 0
        den /= i
        num /= i
        i = 1
      i++
    num2 = num % den
    den2 = den
    fr = (num - num2) / den
    res = ""
    res = fr.toString() if fr isnt 0
    res +=" "+num2 + "/" + den2 if num2>0 and res.length>0
    return res if res.length>0
    return num + "/" + den

$(document).ready ()->


 x = ()->
  productId = parseInt do $("#product").val
  quantity = parseFloat do $("#quantity").val
  quantity = (do $("#quantity").val) if not quantity
  cases = parseInt do $("#cases").val 
  if cases<1 || (parseFloat(do $("#cases").val)!=parseInt(do $("#cases").val)) 
   alert "You must choose at least 1 case."
   return false
  rec = document.nslp({productid:productId,quantity:quantity}).first()
  console.log JSON.stringify rec
  #display
  $("#fed").html parseInt(rec.servings*cases)
 
  for i in [1..2]
   $("#n#{i}").html (parseFloat(rec["n#{i}"])*cases).toFixed(2)
  
  for i in [3..9]
   if parseFloat(rec["n#{i}"]) > 0 then $("#n#{i}").html dec2frac round (parseFloat(rec["n#{i}"])*cases) else $("#n#{i}").html "0"
 

 round = (x)->
  t = Math.floor(parseFloat(x)/(1/8.00))
  t = 1/8 if t is 0
  ((Math.floor(t))*(1/8)).toString()
 
  
 $("#product").on "change",(e)->
  $("#productimage").attr "src",document.products({productid: parseInt do $("#product").val}).first().img
  do $("#quantity option").remove
  
  for q in document.nslp({productid: parseInt do $("#product").val}).distinct("quantity")  
   qval = parseFloat(q)
   if qval 
    qval =  dec2frac round qval 
   else 
    qval = "n/a"
   $("#quantity").append "<option value=\"#{q}\">#{qval}</option>" 
  do x
  do e.preventDefault
  
 $("#quantity").on "change",(e)->
  do x
  do e.preventDefault
 
 $("#cases").on "change",(e)->
  do x
  do e.preventDefault


 #init 
 #load products
 initCalc=->
	 do $("#product option").remove
	 document.products().each (p,v)->$("#product").append "<option value=\"#{p.productid}\">#{p.name}</option>"
	 #load quantity
	 do $("#quantity option").remove
	 for q in document.nslp({productid: parseInt document.products().first().productid}).distinct("quantity")  
	  qval = parseFloat(q)
	  if qval 
	   qval =  dec2frac round qval 
	  else 
	   qval = "n/a"
	  $("#quantity").append "<option value=\"#{q}\">#{qval}</option>" 

 do initCalc

 #entries management
 displayEntries=(id)->
  do $("#savedEntries").dataTable().fnClearTable
  document.savedEntries({userid:id}).each (it)->
   ###
   $("#savedEntries tbody").append """
<tr>
	<td> <span id="productname">#{it.productname}</span> </td>
	<td> <span id="quantity">#{it.quantity}</span> </td>
	<td> <span id="cases">#{it.cases}</span> </td>
	<td> <span id="fed">#{it.fed}</span> </td>

	<td> <span id="n1">#{it.n1}</span> </td>
	<td> <span id="n2">#{it.n2}</span> </td>
	<td> <span id="n3">#{it.n3}</span> </td>
	<td> <span id="n4">#{it.n4}</span> </td>
	<td> <span id="n5">#{it.n5}</span> </td>
	<td> <span id="n6">#{it.n6}</span> </td>
	<td> <span id="n7">#{it.n7}</span> </td>
	<td> <span id="n8">#{it.n8}</span> </td>
	<td> <span id="n9">#{it.n9}</span> </td>	
</tr>   
   """
   ###
   d=[
    it.productname,
    it.quantity,
    it.cases,
    it.fed
   ]
   d.push it["n#{i}"] for i in [1..9]
   $("#savedEntries").dataTable().fnAddData d
   
 getUserKey=->
  "abc"
 
 saveDatabase=->
  console.log "saving database to remote location"

 $("#clearAllBtn").on "click",->
  document.savedEntries({userid:do getUserKey}).remove()
  displayEntries do getUserKey

 $("#saveEntryBtn").on "click",->
  entry = 
   userid: do getUserKey
   productid: parseInt do $("#product").val
   productname: do $("#product option:selected").text
   quantity: parseFloat do $("#quantity option:selected").val
   cases: parseInt do $("#cases").val
   fed: parseFloat do $("#fed").text
  entry["n#{i}"]=$("#n#{i}").html() for i in [1..9]
  document.savedEntries.insert entry
  do saveDatabase
  displayEntries do getUserKey
  

 #display saved entries if any
 $("#savedEntries").dataTable 
  sDom: 'T<"clear">lfrtip'
  oTableTools: 
   sSwfPath: "js/tabletools/swf/copy_csv_xls_pdf.swf"
 displayEntries do getUserKey
 do x  
</script>
</head>
<body>
	<table id=example>
	</table>

<!-- __________________________________________________ Start Page -->
    <section id="page">
      <a href="#" id="slide_top"></a>
      <div class="container">
<!-- __________________________________________________ Start Header -->
        <header id="header">
          <div class="header_inner">
            <a class="logo" href="index.html"><img src="images/logo.png" alt="" /></a>
            <a class="resp_navigation" href="javascript:void(0);"></a>
            <nav>
              <ul id="navigation">
                <li class="current_page_item drop">
                  <a href="javascript:void(0);"><span>Home</span></a>
                  <!-- <ul>
                    <li class="current_page_item"><a href="index.html"><span>Responsive Slider</span></a></li>
                    <li><a href="index-2.html"><span>Revolution Slider</span></a></li>
                  </ul> -->
                </li>
                <li class="drop"><a href="javascript:void(0);"><span>NSLP Basics</span></a>
                </li>
                <li class="drop">
                  <a href="javascript:void(0);"><span>Planning</span></a>
                </li>
                <li class="drop">
                  <a href="javascript:void(0);"><span>Reimbursement</span></a>
                </li>
                <li>
                  <a href="#"><span>Resources</span></a>
                </li>
              </ul>
            </nav>
            <div class="cl"></div>
          </div>
        </header>
<!-- __________________________________________________ Finish Header -->

<!-- __________________________________________________ Start Middle -->
        <section id="middle">
          <div class="headline">
            <h2>About Us</h2>
          </div>
          <div class="cont_nav"><a href="index.html">Home</a>&nbsp;/&nbsp;<a href="resources.html">Resources</a>&nbsp;/&nbsp;<span>Calculator</span></div>
          <div class="content_wrap nobg">
<!-- __________________________________________________ Start Content -->
            <section id="middle_content">
              <div class="entry">
                <div class="fullwidth">


<!-- calc -->
<div class="pricing_table">
  <h2 class="calc_title">NSLP Planning Calculator</h2>
<!-- product image -->

    <div class="wp-caption alignright" style="width:250px; margin-right:150px;">
                  <a href="#"><img src="images/calc/tfss-shredders-thumb.jpg" id="productimage" width="250" alt="" title="This is caption"></a>
                   
    </div>

      <div style="margin-left:125px;margin-top:0px;">
<!-- products -->
        <div class="calc_form">
          <span class="calc_span" style="margin-right:1px;">Select a product:</span>
            <select id="product">
              <option value="1">Shredded Romaine W/Carrot 75/25 6/2#</option>
              <option>Lite Caesar Kit 6/2#</option>
              <option>Broccoli Slaw W/ Carrot 50/50 4/3#</option>
              <option>Broccoli Slaw Kit 4/3#</option>
              <option>Shredders Lite Caesar 50Ct</option>
              <option>Shredders Sesame Ginger Kit 50Ct</option>
              <option>Cinnamon Swirl Carrot Chips 50CT</option>
              <option>Arugula 1/4#</option>
            </select>
        </div>

</br>

<div class="calc_form">
<span class="calc_span">Servings in Cups:</span>
<!-- servings (in cups) -->
<select id="quantity">
<option>2.00</option>
<option>1.88</option>
<option>1.75</option>
<option>1.62</option>
<option>1.50</option>
<option>1.38</option>
<option>1.25</option>
<option>1.12</option>
<option>1.00</option>
<option>0.88</option>
<option>0.75</option>
<option>0.62</option>
<option>0.50</option>
<option>0.25</option>
<option>0.12</option>
</select>
</div>

</br>
<div>
<span class="calc_span">Number of Cases:</span>
<!-- cases -->
<input id="cases" type="number" min="1" value="1" class="calc_case">
</div>
</br>

<div style="margin-top:25px;"><h3>Mouths fed: <span id="fed"></span></h3>
</div>
</div>
</br>

      <div class="cmsms_price glow_yellow">
        <span class="pricing_currency">NSLP Creditable Amounts</span>
      </div>

<!-- NSLP Creditable Amounts -->
<table class="calcTable">

<thead>
<th>Meat (oz)</th>
<th>Grain (oz)</th>
<th>Fruit (cups)</th>
<th>Dark Green Veg (cups)</th>
<th>Red Orange Veg (cups)</th>
<th>Starchy Veg (cups)</th>
<th>Beans/Peas (cups)</th>
<th>Starchy Veg (cups)</th>
<th>Other Veg (cups)</th>
</thead>
<tbody>
<tr>
	<td> <span id="n1"></span> </td>
	<td> <span id="n2"></span> </td>
	<td> <span id="n3"></span> </td>
	<td> <span id="n4"></span> </td>
	<td> <span id="n5"></span> </td>
	<td> <span id="n6"></span> </td>
	<td> <span id="n7"></span> </td>
	<td> <span id="n8"></span> </td>
	<td> <span id="n9"></span> </td>	
</tr>
</tbody>
</table>
</div>
<!-- end calc -->
<!-- start saved entries -->
<button id="saveEntryBtn">Add to Planner</button>
<button id="clearAllBtn">Clear all</button>
<br><br>Planner:<br><br>
<table  class="display" id="savedEntries">

<thead>
<th>Product</th>
<th>Cups</th>
<th>Cases</th>
<th>Mouths fed</th>

<th>Meat (oz)</th>
<th>Grain (oz)</th>
<th>Fruit (cups)</th>
<th>Dark Green Veg (cups)</th>
<th>Red Orange Veg (cups)</th>
<th>Starchy Veg (cups)</th>
<th>Beans/Peas (cups)</th>
<th>Starchy Veg (cups)</th>
<th>Other Veg (cups)</th>
</thead>
<tbody> 
</tbody>
</table>


<!-- end saved entries -->
</div>


<div class="cl"></div>
              </div>
            </section>
<!-- __________________________________________________ Finish Content -->
          </div>
        </section>
<!-- __________________________________________________ Finish Middle -->

<!-- __________________________________________________ Start Bottom -->
        <section id="bottom">
          <div class="one_fourth">
            <aside class="widget widget_links">
              <h3 class="widgettitle">Nutrition</h3>
              <ul>
                <li><a href="http://www.choosemyplate.gov">Choose My Plate</a></li>
                <li><a href="http://www.choosemyplate.gov/healthy-eating-tips/ten-tips.html">Education Materials</a></li>
                <li><a href="http://www.usda.gov/wps/portal/usda/usdahome?navid=PEOPLES_GARDEN">People's Garden</a></li>
                <li><a href="http://teamnutrition.usda.gov/Default.htm">Team Nutrition</a></li>
              </ul>
            </aside>
          </div>
          <div class="one_fourth">
            <aside class="widget widget_links">
              <h3 class="widgettitle">Programs</h3>
              <ul>
                <li><a href="http://www.fns.usda.gov/cnd/Lunch/">NSLP</a></li>
                <li><a href="http://www.fns.usda.gov/cnd/Breakfast/Default.htm">School Breakfast</a></li>
                <li><a href="http://www.fns.usda.gov/cnd/Afterschool/default.htm">Afterschool Snack</a></li>
                <li><a href="http://www.fns.usda.gov/cnd/Milk/Default.htm">Special Milk</a></li>
              </ul>
            </aside>
          </div>
          <div class="one_fourth">
            <aside class="widget widget_links">
              <h3 class="widgettitle">Background</h3>
              <ul>
                <li><a href="http://www.fns.usda.gov/cnd/Lunch/AboutLunch/NSLPFactSheet.pdf">NSLP Facts</a></li>
                <li><a href="http://www.fns.usda.gov/cnd/Lunch/AboutLunch/ProgramHistory.htm">History</a></li>
                <li><a href="http://www.fns.usda.gov/cnd/Guidance/EliMan.pdf">Eligibility</a></li>
                <li><a href="http://www.fns.usda.gov/cnd/Governance/Legislation/CNR_2010.htm">Legislation</a></li>
              </ul>
            </aside>
          </div>
          <div class="one_fourth">
            <aside class="widget widget_links">
              <h3 class="widgettitle">Food Safety</h3>
              <ul>
                <li><a href="http://www.fns.usda.gov/cnd/guidance/foodsafety_bestpractices.pdf">In Schools</a></li>
                <li><a href="http://www.fns.usda.gov/cnd/guidance/foodsafety_classrooms.pdf">In Classrooms</a></li>
                <li><a href="http://www.fns.usda.gov/cnd/guidance/foodsafety_saladbars.pdf">Salad Bars</a></li>
                <li><a href="http://www.fns.usda.gov/cnd/guidance/foodsafety_storage.pdf">Storing Produce</a></li>
              </ul>
            </aside>
          </div>
        </section>
<!-- __________________________________________________ Finish Bottom -->
      </div>

<!-- __________________________________________________ Start Footer -->
      <footer id="footer">
        <!-- <ul class="social_list">
          <li><a href="#" title="Facebook"><img src="images/socicons/facebook.png" alt="" /></a></li>
          <li><a href="#" title="Flickr"><img src="images/socicons/flickr.png" alt="" /></a></li>
          <li><a href="#" title="Twitter"><img src="images/socicons/twitter.png" alt="" /></a></li>
          <li><a href="#" title="Vimeo"><img src="images/socicons/vimeo.png" alt="" /></a></li>
          <li><a href="#" title="Google Plus"><img src="images/socicons/googleplus.png" alt="" /></a></li>
        </ul> -->
        <span class="cmsms_copy">&copy; 2012 Taylor Farms Foodservice</span>
        <ul class="footer_nav">
          <li><a href="#">Contact us</a></li>
          <li><a href="#">Privacy statement</a></li>
        </ul>
      </footer>
<!-- __________________________________________________ Finish Footer -->
    </section>
<!-- __________________________________________________ Finish Page -->

  </body>
</html>