{% extends "::base.html.twig" %}  
{% block image %}{% endblock %}   
{% block body %}

<div id="assistance_edit">

<div id="override_javascript_alert"></div>

<form id="clientform" action="{{ path('DorcasTabithaBundle_assistance_updatesp', { 'assistance_id' : assistance.assistanceid } ) }}" method="post" {{ form_enctype(form) }} class="dorcas">

    <h4>Edit a Special Program - Admin Only</h4>

 

    <div style="width:36%; float:left;">
                Program*
                {{ form_widget(form.special_program, { 'attr': {'style': 'width: 220px;'} }) }}
    </div>
    <div style="width:20%; float:left;">
                {{ form_label(form.special_program_date) }}
                {{ form_errors(form.special_program_date) }}
                {{ form_widget(form.special_program_date, { 'attr': {'size': '11', 'class': 'datepicker'} }) }}
    </div>
    <div style="width:44%; float:left;">
                {{ form_label(form.special_program_recipient_name) }}
                {{ form_errors(form.special_program_recipient_name) }}
                {{ form_widget(form.special_program_recipient_name, { 'attr': {'size': '30'} }) }}
    </div>
    <br >&nbsp;<br />
    <div style="width:50%; float:left;">
                {{ form_label(form.special_program_parent_name) }}
                {{ form_errors(form.special_program_parent_name) }}
                {{ form_widget(form.special_program_parent_name, { 'attr': {'size': '30'} }) }}
    </div>
    <div style="width:23%; float:left;">
                {{ form_label(form.special_program_check) }}
                {{ form_errors(form.special_program_check) }}
                {{ form_widget(form.special_program_check, { 'attr': {'size': '10', 'onchange': 'isNumber(this)'} }) }} 
    </div>
 

<br>&nbsp;<br>
        <div style=" padding-top: 18px;">
    <input type="button" value="Save and Close Window" onclick="closeandreload()" >
    </div>      

                {{ form_rest(form) }}

            {% if app.session.hasFlash('notice') %}
                <div class="flash-notice" >
                    {{ app.session.flash('notice') }}
                </div>
            {% endif %}

    <br />
</form>
</div>

{% endblock %}

{% block logout %}{% endblock %}


{% block javascripts %}

{{ parent() }}
               
<script type="text/javascript">            

$(function() {
    $( ".datepicker" ).datepicker({ showAnim: "slideDown" });
});

</script>

<script type="text/javascript">

window.alert = function(message) {
	$('#override_javascript_alert').html(message).dialog({
		modal:true,
		title:'Tabitha Validation Message',
		buttons: {
			'OK':function(){
				$(this).dialog('close');
			}
		}
	});
};

/**--------------------------
//* Validate Date Field script- By JavaScriptKit.com
//* For this script and 100s more, visit http://www.javascriptkit.com
//* This notice must stay intact for usage
---------------------------**/

function checkdate(input){
    var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
    var returnval=false
    if (!validformat.test(input))
    {
//        alert("Invalid Date Format. Please correct and submit again.")
    }
    else{ //Detailed check for valid date ranges
        var monthfield=input.split("/")[0]
        var dayfield=input.split("/")[1]
        var yearfield=input.split("/")[2]
        var dayobj = new Date(yearfield, monthfield-1, dayfield)
        if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
        {
//            alert("Invalid Day, Month, or Year range detected. Please correct and submit again.")
        }
        else
            returnval=true
    }
//    if (returnval==false) input.select()
    return returnval
}

function closeandreload(){ 

    // Do Validation
//    var recipient = document.getElementById('assistanceform_special_program_recipient_name');
    var spcheck = document.getElementById('assistanceform_special_program_check');
//    var parent = document.getElementById('assistanceform_special_program_parent_name');
    var spdate = document.getElementById('assistanceform_special_program_date');
    var program = document.getElementById('assistanceform_special_program');
    var message = '';

    if ( spcheck.value == '' )
    {
        var valid = false;
        var message = message + '&#8227 Please enter an Amount.<br/>';
    }

    if ( program.value == '1' )
    {
        var valid = false;
        var message = message + '&#8227 Please select a Program.<br/>';
    }

    // Check Special Programs Date for valid date
    if ( spdate.value && !checkdate(spdate.value))
    {
        var valid = false;
        var message = message + '&#8227 Please enter a valid Date. <br/>';
    }

    if ( valid == false )
    {
        alert( message );
        return(false);
    }
    
    var form = document.forms["clientform"];
    form.submit();
    opener.location.reload(true); // or opener.location.href = opener.location.href;
    window.close(); // or self.close(); 
}


function isNumber(field)
{
     if( isNaN(field.value)){
        alert("&#8227 Please enter a dollar amount with no dollar sign.");
        field.value = 0;
        field.focus();
         }
}

    
</script>

    
{% endblock %}

 
