function addComment()
{
	var dname = $('#dname').attr('value');
	var demail = $('#demail').attr('value');
	var dcomment = $('#dcomment').attr('value');
	var dnewsid = $('#dnewsid').attr('value');
	var dnewscategory = $('#dnewscategory').attr('value');
	if (validateCommentForm() == true)
	{
		$.post('/ajax/addComment', {
		    name: dname,
		    comment: dcomment,
		    email : demail,
		    newsid : dnewsid,
		    categoryid : dnewscategory
		}, function(data) {
		    if (data == 'ok')
		    {
				document.getElementById('comment_message').innerHTML = "Komentarz został dodany, po akceptacji przez moderatora zostanie on opublikowany.";
				document.getElementById('commentform').style.display = "none";
			}
			else
			{
			alert(data);	
				document.getElementById('comment_message').innerHTML = "Wystapiły problemy z dodawaniem komentarza, prosimy spróbowac później.";
				document.getElementById('commentform').style.display = "none";
			}
		});
	}
}
function validateCommentForm()
{
	var dane_poprawne = true;
	var message = '';	
	if ($("#dcomment").attr('value') == '' || $("#dcomment").attr('value') == null)
	{
		message += 'Proszę wpisać treść komentarza<br />';
		dane_poprawne = false;
	}

	if ($("#dname").attr("value") == '')
	{
		message += 'Proszę wpisać imie<br/>';
		dane_poprawne = false;
	}
	if ($("#demail").attr("value") != null)
	{
	if ($("#demail").attr("value").match(/^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/))
		{
		}
		else
		{
			message += 'Adres e-mail jest niepoprawny';
			dane_poprawne = false;
		}
	}
	if (dane_poprawne == true)
	{
		document.getElementById('commentform').innerHTML = "<img src=\"/img/ajax-loader.gif\"/ style=\"margin-left: 210px\">";
		message = 'zapisuje komentarz';
	}
	else
	{
}
	document.getElementById('comment_message').style.display = "block";
	document.getElementById('comment_message').innerHTML = message;
	return dane_poprawne;
}
