function rawurldecode( str ) {
    // Decodes URL-encodes string  
    // 
    // version: 905.412
    // discuss at: http://phpjs.org/functions/rawurldecode
    var histogram = {}, ret = str.toString(), unicodeStr='', hexEscStr='';

    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };

    // The histogram is identical to the one in urlencode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';


    for (unicodeStr in histogram) {
        hexEscStr = histogram[unicodeStr]; // Switch order when decoding
        ret = replacer(hexEscStr, unicodeStr, ret); // Custom replace. No regexing
    }

    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = ret.replace(/%([a-fA-F][0-9a-fA-F])/g, function (all, hex) {return String.fromCharCode('0x'+hex);}); // These Latin-B have the same values in Unicode, so we can convert them like this
    ret = decodeURIComponent(ret);

    return ret;
}


function displayPopup(msg){
	$('#popup-message').dialog({
		autoOpen:false,
		buttons:{'Ok':function(){$(this).dialog("close");}},
		closeOnEscape:true,
		draggable:false,
		modal:true,
		resizable:false,
		title:'Information',
		width:480
	});
	$('#popup-message').html(msg);
	$('#popup-message').dialog('open');
}

function confirmDelete(){
	input_box=confirm("Are you sure you want to delete?\nClick OK to confirm or CANCEL to cancel.");
	if (input_box==true){
		document.admin_delete.submit();
	}
}

function playTrack(id){
	$.get("ajax_create_player.php", {id:id}, function(data){
		var player = document.getElementById('mpl');
		player.sendEvent("LOAD", rawurldecode(data));
	});			
}

function confirmDeleteBlogCategoryLink(id, link){
	input_box=confirm("Are you sure you want to delete?\nClick OK to confirm or CANCEL to cancel.");
	if (input_box==true){
		$.get("ajax_delete_blog_category_link.php", {id:id, link:link}, function(data){
			if(data == 'true'){
				window.location = 'blog_categories.php?id='+id;
			}
		});
	}		
}

function confirmDeleteBlogYoutubeLink(id, link){
	input_box=confirm("Are you sure you want to delete?\nClick OK to confirm or CANCEL to cancel.");
	if (input_box==true){
		$.get("ajax_delete_blog_youtube_link.php", {id:id, link:link}, function(data){
			$("#ajax-delete").html(data);
		});
	}		
}

function confirmDeleteBlogLink(id, link){
	input_box=confirm("Are you sure you want to delete?\nClick OK to confirm or CANCEL to cancel.");
	if (input_box==true){
		$.get("ajax_delete_blog_link.php", {id:id, link:link}, function(data){
			$("#ajax-delete").html(data);
		});
	}		
}

