function open_comment_form()
{
	if (document.getElementById('comment_form').style.display == "block")
		document.getElementById('comment_form').style.display = "none";
	else
		document.getElementById('comment_form').style.display = "block";	
}
function addComment()
{
	var dname = document.getElementById('dname').value;
	var demail = document.getElementById('demail').value;
	var dcomment = document.getElementById('dcomment').value;
	var dnewsid = document.getElementById('dnewsid').value;
	var dnewscategory = document.getElementById('dnewscategory').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('comment_form').style.display = "none";
				document.getElementById('add_comment_button').style.display = "none";
			}
			else
			{
				document.getElementById('comment_message').innerHTML = "Wystapiły problemy z dodawaniem komentarza, prosimy spróbowac później.";
				document.getElementById('comment_form').style.display = "none";
				document.getElementById('add_comment_button').style.display = "none";									
			}
		});
	}
}
function validateCommentForm()
{
	var dane_poprawne = true;
	var message = '';
	if ($("#dcomment").attr("value") == null)
	{
		message += 'Proszę wpisać treść komentarza<br />';
		dane_poprawne = false;
	}
	if ($("#dname").attr("value") == null)
	{
		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('comment_form').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;
}

function submenu(type, action)
{
	if(type == 'ekrany' && action == 'show')
	{
		document.getElementById('submenu_ekrany').style.display = '';
		document.getElementById('submenu_ekrany').style.position = 'absolute';
		document.getElementById('submenu_ekrany').style.left = '420px';
		document.getElementById('submenu_ekrany').style.top = '200px';
	}
	if(type == 'ekrany' && action == 'hide')
	{
		document.getElementById('submenu_ekrany').style.display = 'none';		
	}
	
	if(type == 'odtwarzacze' && action == 'show')
	{
		document.getElementById('submenu_odtwarzacze').style.display = '';
		document.getElementById('submenu_odtwarzacze').style.position = 'absolute';
		document.getElementById('submenu_odtwarzacze').style.left = '575px';
		document.getElementById('submenu_odtwarzacze').style.top = '130px';
		document.getElementById('submenu_odtwarzacze').style.zIndex = '999';
	}
	if(type == 'odtwarzacze' && action == 'hide')
	{
		document.getElementById('submenu_odtwarzacze').style.display = 'none';		
	}

	if(type == 'hdtv' && action == 'show')
	{
		document.getElementById('submenu_hdtv').style.display = '';
		document.getElementById('submenu_hdtv').style.position = 'absolute';
		document.getElementById('submenu_hdtv').style.left = '250px';
		document.getElementById('submenu_hdtv').style.top = '190px';
		document.getElementById('submenu_hdtv').style.zIndex = '999';
	}
	if(type == 'hdtv' && action == 'hide')
	{
		document.getElementById('submenu_hdtv').style.display = 'none';		
	}

}