var ajax_load = '<img src="images/website/ajax-loader.gif" alt="loading" />';

$(document).ready(function(){
	refresh_favorites();
	
	$("#frmAddFavo").submit(function(){
		$("#favo-ajax").html(ajax_load);  
		$.get(  
       		"ajax/favorieten.php",  
        	{rnd: Math.floor(Math.random()*9999), title: escape($("#titel").val()), url: escape($("#url").val())},  
        	function(responseText){  
          		$("#favo-ajax").html(responseText);  
        	},  
        	"html"  
        )
		
		$('#favorieten-form').toggle(false);
		refresh_favorites();
		return false;
	});
	
	$("#frmEditFavo").submit(function(){
		$("#favo-ajax").html(ajax_load);  
		$.get(  
       		"ajax/favorieten.php",  
        	{rnd: Math.floor(Math.random()*9999), edit: true, id: escape($("#hdFavId").val()), title: escape($("#titel-edit").val()), url: escape($("#url-edit").val())},  
        	function(responseText){  
          		$("#favo-ajax").html(responseText);  
        	},  
        	"html"  
        )
		
		$('#favorieten-edit-form').toggle(false);
		refresh_favorites();
		return false;
	});
});

function refresh_favorites()
{
	$("#favo-ajax").html(ajax_load);  
    $.get(  
       	"ajax/favorieten.php?rnd="+Math.floor(Math.random()*9999),  
        {},  
        function(responseText){  
          	$("#favo-ajax").html(responseText);  
        },  
        "html"  
    );
}

function delete_fav(id)
{
	$.get(  
       	"ajax/favorieten.php",  
        {rnd: Math.floor(Math.random()*9999), delete_id: id},  
        function(responseText){  
          	$("#favo-ajax").html(responseText);  
        },  
        "html"  
    )
}

function edit_fav(title, url, id)
{
	$("#hdFavId").val(id);
	$("#titel-edit").val(title);
	$("#url-edit").val(url);
	
	$("#favorieten-form").toggle(false);
	$("#favorieten-edit-form").toggle(true);
}
