$(document).ready(function(){
   $('#shape').bind("change", function(){
        textfieldchange();
    });
	$('#design').bind("change", function(){
        textfieldchange();
    });
    $("select#shape").change(function(){
        if ($(this).children("option:selected").val() == "1_375_circle") 
            $("span#0_quantity_note").html("sheet(s) of 35 labels");
        else 
            if ($(this).children("option:selected").val() == "diamond") 
                $("span#0_quantity_note").html("sheet(s) of 15 labels");
            else 
                if ($(this).children("option:selected").val() == "oval") 
                    $("span#0_quantity_note").html("sheet(s) of 28 labels");
                else 
                    if ($(this).children("option:selected").val() == "2_inch_circle") 
                        $("span#0_quantity_note").html("sheet(s) of 15 labels");
                    else 
                        if ($(this).children("option:selected").val() == "2_inch_square") 
                            $("span#0_quantity_note").html("sheet(s) of 12 labels");
    });
    function setMaxLength(element_id, length){
        $(element_id).attr("maxlength", length);
        note = element_id + '_note';
        $(note).html('(up to ' + length + ' characters)');
    };
     function prepFields(text_lengths){
        if (text_lengths[0]){$('#4_text1div').show();setMaxLength('#4_text1', text_lengths[0]);} else {$('#4_text1div').hide();}
		if (text_lengths[1]){$('#5_text2div').show();setMaxLength('#5_text2', text_lengths[1]);} else {$('#5_text2div').hide();}
		if (text_lengths[2]){$('#6_text3div').show();setMaxLength('#6_text3', text_lengths[2]);} else {$('#6_text3div').hide();}
		
    }
    function textfieldchange(){
        $('#4_text1').val(''); //set value to none when onchange
        $('#5_text2').val(''); //set value to none when onchange
        $('#6_text3').val(''); //set value to none when onchange
        var shape = $("#shape").val();
        var design = $("#design").val();
		if((shape=='2_inch_square')&&(design =='AM_beads')){prepFields([13])};	
		if((shape=='2_inch_circle')&&(design =='AM_beads')){ prepFields([13])};	
		if((shape=='oval')&&(design =='AM_beads')){ prepFields([12])};	
		if((shape=='1_375_circle')&&(design =='AM_beads')){ prepFields([13])};	
		if((shape=='diamond')&&(design =='AM_beads')){ prepFields([10])};
		if((shape=='2_inch_square')&&(design =='AM_butterfly')){ prepFields([10,13,15])};	
		if((shape=='2_inch_circle')&&(design =='AM_butterfly')){ prepFields([10,13,15])};	
		if((shape=='oval')&&(design =='AM_butterfly')){ prepFields([9,12])};	
		if((shape=='1_375_circle')&&(design =='AM_butterfly')){ prepFields([10,13,15])};	
		if((shape=='diamond')&&(design =='AM_butterfly')){ prepFields([10,13,15])};
		if((shape=='2_inch_square')&&(design =='NW_chicks')){ prepFields([18,12,15])};
		if((shape=='2_inch_circle')&&(design =='NW_chicks')){ prepFields([15,12,14])};	
		if((shape=='oval')&&(design =='NW_chicks')){ prepFields([10,12,8])};	
		if((shape=='1_375_circle')&&(design =='NW_chicks')){ prepFields([15,12,14])};
		if((shape=='diamond')&&(design =='NW_chicks')){ prepFields([10,12])};
		if((shape=='2_inch_square')&&(design =='NW_elephants')){ prepFields([20,12,16])};	
		if((shape=='2_inch_circle')&&(design =='NW_elephants')){ prepFields([20,12,16])};	
		if((shape=='oval')&&(design =='NW_elephants')){ prepFields([14,12,10])};	
		if((shape=='1_375_circle')&&(design =='NW_elephants')){ prepFields([15,12,12])};	
		if((shape=='diamond')&&(design =='NW_elephants')){ prepFields([14,12,10])};
		if((shape=='2_inch_square')&&(design =='JSS_hotdog')){ prepFields([15,15,13])};	
		if((shape=='2_inch_circle')&&(design =='JSS_hotdog')){ prepFields([10,13,12])};
		if((shape=='oval')&&(design =='JSS_hotdog')){ prepFields([9,11,11])};	
		if((shape=='1_375_circle')&&(design =='JSS_hotdog')){ prepFields([10,13,9])};
		if((shape=='diamond')&&(design =='JSS_hotdog')){ prepFields([8,13,10])};
		if((shape=='2_inch_square')&&(design =='CM_kids')){ prepFields([15,15,20])};	
		if((shape=='2_inch_circle')&&(design =='CM_kids')){ prepFields([12,15,20])};	
		if((shape=='oval')&&(design =='CM_kids')){ prepFields([12,15,20])};
		if((shape=='1_375_circle')&&(design =='CM_kids')){ prepFields([12,15,20])};	
		if((shape=='diamond')&&(design =='CM_kids')){ prepFields([10,13,20])};	
   };
  });
