/**
 * file: addpurchaseorder.js
 */


$(function() {

     $('#PurchaseOrderIssueDateDisplay').datepicker({
        showButtonPanel: true,
        dateFormat: 'DD d MM yy',
        altFormat: 'yy-mm-dd',
        altField: '#PurchaseOrderIssueDate'

    });


       $('#PurchaseOrderDispatchDateDisplay').datepicker({
        showButtonPanel: true,
        dateFormat: 'DD d MM yy',
        altFormat: 'yy-mm-dd',
        altField: '#PurchaseOrderDispatchDate'

    });

       $('#PurchaseOrderDateArrivedDisplay').datepicker({
        showButtonPanel: true,
        dateFormat: 'DD d MM yy',
        altFormat: 'yy-mm-dd',
        altField: '#PurchaseOrderDateArrived'

    });

    /**
     * A more generic way of handling the HABTM <ul> <li>[REMOVE BUTTON] NAME [HIDDEN INPUT]</li> </ul>
     */
    function addToList(modelName, id, value, ULelement) {
	var thisLI = $('<li></li>');
	var thisButton = $('<button>X</button>');
	thisButton.addClass('removeFromList');
	thisButton.button();

	var thisHiddenInput = $('<input type="hidden">');

	var modelString = '['+modelName+']';

	thisHiddenInput.attr('name', 'data'+modelString+modelString+'[]');

	thisHiddenInput.attr('value', id);

	thisLI.attr('id', modelName+'ID_'+id);
	thisLI.html(value);
	thisLI.prepend(thisButton);
	thisLI.append(thisHiddenInput);
	ULelement.append(thisLI);

    }

});