$(function(){
  /* -------- BEGIN: addUrls ------- */
	$("#addUrls").click( function() {
		var nextId = parseInt($("#nextUrl").val());
		var i = 0;
		var max = nextId+5;
		for (i=nextId;i<=max;i++) {
			var whichUrl = 'url_'+i;
			var urlLabel = 'URL '+i;
			$("#urlFields").append('<label>'+urlLabel+': (if applicable)</label><input type="text" name="'+whichUrl+'" id="'+whichUrl+'" size="35" maxlength="255" style="margin-bottom:16px;display:block;" value="" class="'+whichUrl+'" />');
		}
		var newMax = max+1;
		$("#nextUrl").val(newMax);
	});
  /* ----- END: addUrls ---- */

  /* -------- BEGIN: URL deletion ------- */  
  // apply click handlers to relevant anchors
  $("a[id*='del_']").click(function(e){
  	var myId=$(this).attr('id');
  	var nextInput = $(this).next();
  	var text = nextInput.val();
  	// stop normal link click
  	e.preventDefault();
		var updateScript = '/stations/musicrights/lib/del.php';
 		if (confirm('Are you sure you want to delete this URL?')) {
  		// send request
  		$.post(updateScript, {args: $(this).attr('id')}, function(rtn) {
  			// Feedback to user via changing the input box for a span and using a strike-through:
  			// No need to include an 'undo' since they can still see it through the strike-through
  			// and can thus copy-paste to one of the new empty input boxes further down.
  			
  			nextInput.replaceWith('<span style="text-decoration: line-through;">' + text + '</span>');

  		});
  	}
  });
  /* ----- END: URL deletion ---- */

});

