<script language="javascript" type="text/javascript"><!--hide it---
function checkPartialPayments(form){
    if(form.elements.invoices.length != undefined){
        if(form.elements.payments.length == undefined){
            alert(lang("There was an error retrieving the payments") + "." + lang("The number of invoices is different from the number of payments"));
            return (false);
        }
        
        if(form.elements.invoices.length != form.elements.payments.length){
            alert(lang("There was an error retrieving the payments") + "." + lang("The number of invoices is different from the number of payments"));
            return (false);
        }
        
        for (var i = 0; i < form.elements.invoices.length; i++){
            if (form.elements.payments[i].value !=""){
                if (isNaN(form.elements.payments[i].value) || form.elements.payments[i].value < 0){
                    alert(lang("Your payment for invoice #% has a wrong format or is not valid", form.elements.invoices[i].value));
                    return (false);
                }
            }
        }
    }else{
        if(form.elements.payments.length != undefined){
            alert(lang("There was an error retrieving the payments") + "." + lang("The number of invoices is different from the number of payments"));
            return (false);
        }
        
        if (form.elements.payments.value !=""){
            if (isNaN(form.elements.payments.value) || form.elements.payments.value < 0){
                alert(lang("Your payment for invoice #% has a wrong format or is not valid", form.elements.invoices.value));
                return (false);
            }
        }
    }
    return (true);
}
//-->
</script>
<body>
<form name="variablePaymentForm" method="POST" action="">
    <table width='100%' cellpadding=0 border=0 cellspacing=0>
        <tr>
            <td class="snapshot-header-left"></td>
            <td class="snapshot-header" nowrap><div style="font-size:11px;font-weight:bold;color:white;">[l]VARIABLE PAYMENTS[/l]</div></td>
            <td class="snapshot-header" align=right></td>
            <td class="snapshot-header-right"></td>
        </tr>
    </table>
    <table cellspacing='1' cellpadding='3' border='0' width="100%" border="0" bgcolor="white">
        <tr class=header>
            <td align="right">
                [l]Invoice #[/l]
            </td>
            <td align="right">
                [l]Balance Due[/l]
            </td>
            <td align="right">
                [l]Payment Amount[/l]
            </td>
        </tr>
    <!-- BEGIN DYNAMIC BLOCK: invoice -->
        <tr>
            <td align="right">
                <input type="hidden" name="invoices" value="{INVOICE_ID}">
                {INVOICE_ID}
            </td>
            <td align="right">
                {BALANCE_DUE}
            </td>
            <td align="right">
                <input type="text" size="15" name="payments" style="text-align:right;" value={PAYMENT}>
            </td>
        </tr>
    <!-- END DYNAMIC BLOCK: invoice -->
        <tr>
            <td colspan="3">
                <br>
                <input type="button" class="button_large" value="[lh]Apply Payments[/lh]" onclick="if(checkPartialPayments(form)) {window.opener.VariablePayments(form); window.close();}" />
            </td>
        </tr>
    </table>
</form>
</body>