// guarantee-reg.js
// ----------------
// Allows the user to add more than one product code
//
// @author:     ian oxley
// @date:       2007-11-12
// @requires:   jquery.js

$(document).ready(function() {
    
    // the maximum number of times that we should allow
    // the user to add more products
    var limit = 10;
    var counter = 1;
    
    // add a button that the user can click to add another product code
    var codes = $('#productCodes');
    codes.append('<input type="button" id="addAnother" value="Add Another" title="Add another product code" class="button" />');
    
    var maxLength = codes.find('input[@type=text]').attr('maxlength');
    
    $('#addAnother').click(function(e) {
        if (++counter >= limit) {
            $(this).hide();
        }
        
        var inputId = 'productCode' + counter.toString();
        var lbl = 'Product Code ' + counter.toString();
        codes.find('p:last').after('<p><label for="' + inputId + '">' + lbl + '</label><input type="text" id="' + inputId + '" name="productCodes[]" class="productCode" value="" maxlength="' + maxLength + '" /></p>');
        
        return false;
    });
    
});
