<?php

/* DorcasTabithaBundle:Finance:financeformnew.html.twig */
class __TwigTemplate_0959c59f5175331fea6fa7003c15aa09 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_create", 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 14
    public function block_javascripts($context, array $blocks = array())
    {
        // line 15
        echo "
";
        // line 16
        $this->displayParentBlock("javascripts", $context, $blocks);
        echo "

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



\$(document).ready(function () {
  \$('input.financeinput, select.financeinput').live('keydown', function(e) { 
 if (e.keyCode==13) { 
  var focusable = \$('input,a,select,button,textarea').filter(':visible'); 
  focusable.eq(focusable.index(this)+1).focus(); 
  return false; 
 } 
});
});

window.alert = function(message) {
\t\$('#override_javascript_alert').text(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 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)){
            alert(\"&#8227 Please enter whole number only, no dollar sign..\");
            list[i].childNodes[1].value = 0;
            list[i].childNodes[1].focus();
        }
        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:financeformnew.html.twig";
    }

    public function isTraitable()
    {
        return false;
    }

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