function addToNewsletter(emailObject)
{
	if(document.getElementById(emailObject).value == "")
	{
		alert("Wpisz adres email.");
		return;
	}
	
	advAJAX.get
	({
	    url: "functions/newsletter.php",
	    parameters : 
	    {
	    	'action' : 'add',
	    	'email' : document.getElementById(emailObject).value
	    },
	    onLoading : function(obj)
	    {
	    	//showLoading();
	    },
	    onError : function(obj) 
	    {
	    	alert(obj.status);
	    },
	    onSuccess : function(obj) 
	    {
	    	
	    	if(obj.responseText == "1")
	    	{
	    		document.getElementById(emailObject).value = "";
	    		alert("Dodano");
	    	}
	    	else
	    		alert(obj.responseText);
	    }
	    
	});
}

function deleteFromNewsletter(id)
{
	if(!confirm("Czy na pewno chces usunąć pozycję?"))
		return;
	
	advAJAX.get
	({
	    url: "../functions/newsletter.php",
	    parameters : 
	    {
	    	'action' : 'delete',
	    	'id' : id
	    },
	    onLoading : function(obj)
	    {
	    	//showLoading();
	    },
	    onError : function(obj) 
	    {
	    	alert(obj.status);
	    },
	    onSuccess : function(obj) 
	    {
	    	if(obj.responseText == "1")
	    	{
	    		   window.location.reload( false );

	    	}
	    	else
	    		alert(obj.responseText);
	    }
	    
	});
}

function newNewsletter()
{
	advAJAX.get
	({
	    url: "../functions/newsletter.php",
	    parameters : 
	    {
	    	'action' : 'getForm'
	    },
	    onLoading : function(obj)
	    {
	    	//showLoading();
	    },
	    onError : function(obj) 
	    {
	    	alert(obj.status);
	    },
	    onSuccess : function(obj) 
	    {
	    	document.getElementById('new').innerHTML = obj.responseText;
	    }
	    
	});
}

function save()
{
	var oEditor = FCKeditorAPI.GetInstance('fckeditor');
   	
	advAJAX.post
		({
		    url: "../functions/newsletter.php",
		    parameters : 
		    {
		    	'action' : 'send',
		    	'text' : oEditor.GetXHTML(true)
		    },
		    onLoading : function(obj)
		    {
		    	document.getElementById('new').innerHTML = "Trwa wysyłanie...";
		    },
		    onError : function(obj) 
		    {
		    	alert(obj.status);
		    },
		    onSuccess : function(obj) 
		    {
		    	if(obj.responseText == "1")
		    	{
		    		document.getElementById('new').innerHTML = "Newsletter został wysłany.";
		    	}
		    	else
		    		document.getElementById('new').innerHTML = obj.responseText;
		    }
		    
		});
}



