<?php

/* DorcasTabithaBundle:Finance:financeformupdate.html.twig */
class __TwigTemplate_a1ab92ed13debe44a0eb653a8d30e658 extends Twig_Template
{
    public function __construct(Twig_Environment $env)
    {
        parent::__construct($env);

        $this->parent = $this->env->loadTemplate("::base.html.twig");

        $this->blocks = array(
            'body' => array($this, 'block_body'),
            'javascripts' => array($this, 'block_javascripts'),
        );
    }

    protected function doGetParent(array $context)
    {
        return "::base.html.twig";
    }

    protected function doDisplay(array $context, array $blocks = array())
    {
        $this->parent->display($context, array_merge($this->blocks, $blocks));
    }

    // line 3
    public function block_body($context, array $blocks = array())
    {
        // line 4
        echo "
        <div id=\"override_javascript_alert\"></div>

        <form id=\"clientform\" action=\"";
        // line 7
        echo twig_escape_filter($this->env, $this->env->getExtension('routing')->getPath("DorcasTabithaBundle_finance_update", array("client_id" => $this->getAttribute($this->getAttribute($this->getContext($context, "finance"), "client"), "clientid"))), "html", null, true);
        echo "\" method=\"post\" ";
        echo $this->env->getExtension('form')->renderEnctype($this->getContext($context, "form"));
        echo " class=\"dorcas\">
            ";
        // line 8
        $this->env->loadTemplate("DorcasTabithaBundle:Finance:financelayout.html.twig")->display($context);
        // line 9
        echo "        </form>

";
    }

    // line 13
    public function block_javascripts($context, array $blocks = array())
    {
        // line 14
        echo "
";
        // line 15
        $this->displayParentBlock("javascripts", $context, $blocks);
        echo "

<script type=\"text/javascript\">

window.alert = function(message) {
\t\$('#override_javascript_alert').html(message).dialog({
\t\tmodal:true,
\t\ttitle:'Tabitha Validation Message',
\t\tbuttons: {
\t\t\t'OK':function(){
\t\t\t\t\$(this).dialog('close');
\t\t\t}
\t\t}
\t});
};

function calculate(field)
{

// ToDo:  merge income and expense
// Changes:  Changed to run without input variable passed

//var oForm = field.form;
//var list = oForm.getElementsByTagName(\"div\");
var list = document.getElementsByTagName(\"div\");
var totalIncome = 0;
var totalIncomeValue = 0;

for(var i=0;i<list.length;i++){
   if(list[i].className == 'financeinput'){
    if(list[i].parentNode.id == 'topLeftCenter' || list[i].parentNode.id == 'topRight'){
//      list[i].style.backgroundColor = 'black';
      totalIncomeValue = Number(list[i].childNodes[1].value);
     if( isNaN(totalIncomeValue)){
        list[i].childNodes[1].value = 0;
        list[i].childNodes[1].focus();
        alert(\"&#8227 Please enter whole number only, no <br />&nbsp; dollar sign.\");
      }
      totalIncome = totalIncome + totalIncomeValue;
 //     oForm.form_totalIncome.value = totalIncome;
        var fieldTotalIncome = list.totalincome.children.form_totalIncome;
        fieldTotalIncome.value = totalIncome;
//      oForm.form_totalIncome.value = totalIncome.toFixed(2);
         }}}


var totalExpenses = 0;
var totalExpensesValue = 0;

for(var i=0;i<list.length;i++){
   if(list[i].className == 'financeinput'){
    if(list[i].parentNode.id == 'bottomLeftCenter' || list[i].parentNode.id == 'bottomRight'){
//      list[i].style.backgroundColor = 'black';
      totalExpensesValue = Number(list[i].childNodes[1].value);
     if( isNaN(totalExpensesValue)){      
        list[i].childNodes[1].value = 0;
        list[i].childNodes[1].focus();
        alert(\"&#8227 Please enter whole number only, no <br />&nbsp;  dollar sign.\");
      }
      totalExpenses = totalExpenses + totalExpensesValue;
 //     oForm.form_totalExpenses.value = totalExpenses;
        var fieldTotalExpenses = list.totalexpense.children.form_totalExpenses;
        fieldTotalExpenses.value = totalExpenses;
//      oForm.form_totalExpenses.value = totalExpenses.toFixed(2);
         }}}

    var deficit = 0;
    var fieldDeficit = list.surplusdeficit.children.form_deficit;
    fieldDeficit.value = totalIncome - totalExpenses;
    //oForm.form_deficit.value = totalIncome - totalExpenses;
    // change the color to red if negative
    if( fieldDeficit.value < 0 )
    {
        fieldDeficit.style.color=\"red\";
    }
    else
    {
        fieldDeficit.style.color=\"black\";
    }

}


window.onload = calculate(document); 

</script>

    
";
    }

    public function getTemplateName()
    {
        return "DorcasTabithaBundle:Finance:financeformupdate.html.twig";
    }

    public function isTraitable()
    {
        return false;
    }

    public function getDebugInfo()
    {
        return array (  55 => 15,  52 => 14,  49 => 13,  43 => 9,  41 => 8,  35 => 7,  30 => 4,  27 => 3,);
    }
}
