$(document).ready(function(){
    function oc(a) //converts array to object array
    {
        var o = {};
        for (var i = 0; i < a.length; i++) {
            o[a[i]] = '';
        }
        return o;
    }
    function setMaxLength(element_id, length){
        $(element_id).attr("maxlength", length);
        note = element_id + '_note';
        $(note).html('(up to ' + length + ' characters)');
    }
    $("#1_design").bind("change", function(e){
        $('#3_text1').val(''); //set value to none when onchange
        $('#4_text2').val(''); //set value to none when onchange
        $('#5_text3').val(''); //set value to none when onchange
        var opt = this.options[this.selectedIndex].value;
        if (opt == 'herringbone' || opt == 'dots' || opt == 'floral' || opt == 'stripes' || opt == 'swirl') {
            $('#5_text3div').show();
            setMaxLength('#3_text1', 11);
            setMaxLength('#4_text2', 11);
            setMaxLength('#5_text3', 9);
        }
        if (opt == "harmony") {
            $('#5_text3div').show();
            setMaxLength('#3_text1', 20);
            setMaxLength('#4_text2', 18);
            setMaxLength('#5_text3', 20);
        }
        if (opt == "leaf") {
            $('#5_text3div').hide();
            setMaxLength('#3_text1', 15);
            setMaxLength('#4_text2', 25);
        }
        if (opt == "signature" || opt == "love_banner") {
            $('#5_text3div').hide();
            setMaxLength('#3_text1', 15);
            setMaxLength('#4_text2', 20);
        }
        if (opt == "vegas_dice" || opt == "new_york") {
            $('#5_text3div').hide();
            setMaxLength('#3_text1', 20);
            setMaxLength('#4_text2', 20);
        }
        if (opt == "san_francisco") {
            $('#5_text3div').hide();
            setMaxLength('#3_text1', 20);
            setMaxLength('#4_text2', 25);
        }
        if (opt == "london") {
            $('#5_text3div').hide();
            setMaxLength('#3_text1', 18);
            setMaxLength('#4_text2', 20);
        }
        if (opt == "vegas_club") {
            $('#5_text3div').hide();
            setMaxLength('#3_text1', 18);
            setMaxLength('#4_text2', 18);
        }
        if (opt == "signature_double_happiness") {
            $('#5_text3div').hide();
            setMaxLength('#3_text1', 12);
            setMaxLength('#4_text2', 25);
        }
        if (opt == "photo") {
            $('#5_text3div').hide();
            setMaxLength('#3_text1', 12);
            setMaxLength('#4_text2', 25);
        }
        if (opt == "signature_double_happiness") {
            $('#5_text3div').hide();
            setMaxLength('#3_text1', 12);
            setMaxLength('#4_text2', 25);
        }
        if (opt == "photo") {
            $('#5_text3div').hide();
            setMaxLength('#3_text1', 20);
            setMaxLength('#4_text2', 17);
        }
        if (opt == "double_happiness_banner") {
            $('#5_text3div').hide();
            setMaxLength('#3_text1', 13);
            setMaxLength('#4_text2', 20);
        }
        if (opt == "double_happiness_large") {
            $('#5_text3div').hide();
            setMaxLength('#3_text1', 20);
            setMaxLength('#4_text2', 15);
        }
		if (opt == "round_dots") {
            $('#5_text3div').hide();
            setMaxLength('#3_text1', 15);
            setMaxLength('#4_text2', 25);
        }
    });
    $('#1_design').trigger("change");
});
