$(function(){
  $("select#ctlCategory").change(function(){
    $.getJSON("setmaker.php",{id: $(this).val(), ajax: "true", type:"category"}, function(j){
      var options = '';
      for (var i = 0; i < j['motives'].length; i++) {
        options += '<option value="' + j['motives'][i].id + '">' + j['motives'][i].name + '</option>';
      }
      $("select#ctlMotive").html(options);
	  $("select#ctlMotive > option").removeAttr("selected");
	  $("div#categorydescription").html(j['categorydescription']);
	  $("div#motivedescription").html(j['motivedescription']);
	  $("div#innercontent").html(j['innercontent']);
	  $("div#smaker_giveaways").html(j['giveaway_products']);
	
    })
  })
});


$(function(){
  $("select#ctlMotive").change(function(){
    $.getJSON("setmaker.php",{id: $(this).val(), ajax: 'true', type:'motive'}, function(j){
	  $("div#motivedescription").html(j['motivedescription']);
	  $("div#innercontent").html(j['innercontent']);
	  $("div#contentsofset").html(j['contentsofset']);
	  $("div#smaker_giveaways").html(j['giveaway_products']);
    })
  })
});


$(function(){
$('input[@name^=intoset]') 
    .livequery('keyup', function(event) { 
		$.getJSON("setmaker.php",{value: $(this).val(), ajax: 'true', type:'intoset', id:$(this).attr('id') }, function(j){
		$("div#contentsofset").html(j['contentsofset']);
		$("div#smaker_giveaways").html(j['giveaway_products']);
		$('input[@id="' + j['intosetid'] +  '"]').val(j['count']);
		})
    });
});

$(function(){
	$('input[@name^=delfromset]') 
	    .livequery('click', function(event) { 
			$.getJSON("setmaker.php",{value: $(this).val(), ajax: 'true', type:'delfromset', id:$(this).attr('id') }, function(j){
			$("div#contentsofset").html(j['contentsofset']);
			$("div#smaker_giveaways").html(j['giveaway_products']);
			$('input[@id="' + j['intosetid'] +  '"]').val(j['count']);
			})
	    });
	});

$(function(){
	$('input[@name^=delgiveaway]') 
	    .livequery('click', function(event) { 
	    	$.getJSON("setmaker.php",{value: $(this).val(), ajax: 'true', type:'delgiveaway', id:$(this).attr('id') }, function(j){
			$("div#contentsofset").html(j['contentsofset']);
			$("div#smaker_giveaways").html(j['giveaway_products']);
			})
	    });
	});


$(function(){
$('select#motives')
    .livequery('change', function(event) { 
		$("a#jumptoset").attr("href", "http://www.schulranzen.net/setmaker.php?motive=" + $('select#motives').val()      );
    });
});


$(function(){
	$('input:image[@name^=getgiveaway]') 
	.livequery('click', function(event) { 
		$.getJSON("setmaker.php",{id: $(this).val(), ajax: 'true', type:'giveaway',id:$(this).attr('id')}, function(j){
		$("div#contentsofset").html(j['contentsofset']);
		})
		return false;
	});
});


