function connect_new(){
	if (window.XMLHttpRequest)
		http_request = new XMLHttpRequest();
	else if(window.ActiveXObject)
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
		
	http_request.onreadystatechange = function()
	{
		if(http_request.readyState == 4)
			if(http_request.status == 200)
				return true;
			else
				connect_new();
	}
}

function online(id)
{
	connect_new();

	http_request.open('GET', 'http://'+ id +'.twojesny.pl/ajax/online.php', true);
	http_request.send(null);	
}

function otworz(url, width, height, scrollbars) {
noweOkno = window.open(url, 'windowup', 'menubar=no, toolbar=no, location=no, scrollbars='+scrollbars+', resizable=no, status=no, width='+width+', height='+height+',top=100,left=300')
}

function connect(){
	if (window.XMLHttpRequest){
		http_request = new XMLHttpRequest();
}
else if(window.ActiveXObject){ 
	http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
}

function report_comment(comment_id, user_id){
if (window.XMLHttpRequest){
http_request = new XMLHttpRequest();
}else if(window.ActiveXObject){ 
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
http_request.onreadystatechange = function() { check_and_do(comment_id, user_id); };
if(confirm('Napewno chcesz zglosic ten komentarz do moderacji? (nieuzasadnione zglaszanie komentarzy, bedzie odpowiednio karane.)')){
http_request.open('GET', 'http://www.twojesny.pl/ajax/abuse_comment.php?comment_id='+comment_id+'&user_id='+user_id, true);
}
http_request.send(null);
}

function check_and_do(comment_id, user_id){
if(http_request.readyState == 4){
if(http_request.status == 200){
document.getElementById("c"+comment_id).innerHTML += '<br /><br /><span style="font-size:12px; color:#FF0000; font-weight:bold;">Dziekujemy! Komentarz zostal zgloszony do moderacji.</span>';
}else{
report(comment_id, user_id);
}}}





function vote_correct(target_id, ayes){
	
	connect();
	
	http_request.onreadystatechange = function(){ 	

		if(http_request.readyState == 4){
			if(http_request.status == 200){
			
			document.getElementById("VoteInfo").innerHTML='Dzi'+String.fromCharCode(281)+'kujemy! G'+String.fromCharCode(322)+'os zosta'+String.fromCharCode(322)+' zapisany.';	
		
			}else vote(target_id, ayes);			
		}}
	
	http_request.open('GET', 'http://www.twojesny.pl/ajax/vote_correct.php?target_id='+target_id+'&ayes='+ayes, true);	
	http_request.send(null);

}

function url(id){
var gourl = id.options[id.selectedIndex].value; 
window.self.location.href = gourl;
}

function ShowHide(id){
	obj = document.getElementById(id);
		if(obj.style.display == 'block') {
			obj.style.display = 'none';
		}
		else {
			obj.style.display = 'block';
		}
}

function Show(id){
	obj = document.getElementById(id);
	obj.style.display = 'block';
}

function Hide(id){
	obj = document.getElementById(id);
	obj.style.display = 'none';
}

function delete_blog_comment(blog_name, comment_id){
	
	if (confirm('Czy na pewno chcesz usuna' + String.fromCharCode(263) + ' ten komentarz?')) {
		connect();
		
		http_request.onreadystatechange = function(){ 	
	
			if(http_request.readyState == 4) {
				if(http_request.status == 200) {
				
				document.getElementById("c" + comment_id).innerHTML='Komentarz zosta'+String.fromCharCode(322)+' usuni'+String.fromCharCode(281)+'ty.';
			
				}
				else delete_blog_comment(blog_name, comment_id);			
			}
		}
		
		http_request.open('GET', 'http://' + blog_name + '.twojesny.pl/ajax/delete_blog_comment.php?comment_id='+comment_id, true);	
		http_request.send(null);
	}
}

function bbcode(typ, opcja, id) {
	var sel = '';

	if (id.length != 0)
	
		switch (id) {
		
		case 'size':
			document.getElementById(id + '_dialog').innerHTML = opcja + 'px';
			document.getElementById(id + '_list').style.display = 'none';
		break;
		
		case 'color':
			document.getElementById(id + '_dialog').style.background  = opcja;
			document.getElementById(id + '_list').style.display = 'none';
		break;
		
		case 'url':
			var opcja = prompt('Podaj adres URL:', 'http://');
		break;
		}
	
	obj = document.getElementById('post_text');
	
	obj.focus();
	
	if (document.selection)
		sel = document.selection.createRange().text;
	else
		sel = obj.value.substring(obj.selectionEnd, obj.selectionStart);
	
	if (opcja.length != 0)
		if (id == "url" && sel.length == 0) 
		{
			var opcja2 = prompt('Podaj nazwe linku:', '')
			obj.value = obj.value += "["+typ+"="+opcja+"]"+opcja2+"[/"+typ+"]";
		}
		else
			obj.value = obj.value.replace(sel, "["+typ+"="+opcja+"]"+sel+"[/"+typ+"]");
	else 
		obj.value = obj.value.replace(sel, "["+typ+"]"+sel+"[/"+typ+"]");
}

function confirm_delete()
{
    if (document.getElementById('confirmdelete').checked == true)
    {
        document.getElementById('sdelete').disabled = false;
    }
    else
    {
        document.getElementById('sdelete').disabled = true;
    }
} 
