// JavaScript Document
function all_friends(uid){
	$('#prijatelji_inner').load('/ajax/friend/getall/'+ uid);
}
function add_friend(ko,skim){
	if(confirm('Sigurno?')){
        $.ajax({
            type: "GET",
            url: "ajax.php?dod_ko="+ ko +"&dod_skim="+ skim,
            success: function(){
				document.location.href="profil.php?username="+ skim;
				$(location).attr('href',url);
            },
            error: function(){
                alert('fail');
            }
        });
	}
}
function del_friend(ko,skim){
	if(confirm('Sigurno?')){
        $.ajax({
            type: "GET",
            url: "ajax.php?ko="+ ko + "&skim="+ skim,
            success: function(){
				document.location.href="profil.php?username="+ skim;
				$(location).attr('href',url);
            },
            error: function(){
                alert('fail');
            }
        });
	}
}
function activate_friend_req(id){
	if(confirm('Sigurno?')){
        $.ajax({
            type: "GET",
            url: "/ajax/friend/activate/"+ id,
            success: function(){
        	$(".request_"+ id).hide('slow');
            },
            error: function(){
                alert('fail');
            }
        });
	}
}
function delete_friend_req(id){
	if(confirm('Sigurno?')){
        $.ajax({
            type: "GET",
            url: "/ajax/friend/delete_request/"+ id,
            success: function(){
        	$(".request_"+ id).hide('slow');
            },
            error: function(){
                alert('fail');
            }
        });
	}
}
function brisiporuku(id){
	if(confirm('Sigurno?')){
        $.ajax({
            type: "GET",
            url: "ajax.php?brisiporuku="+ id,
            success: function(){
        	$("#poruka_"+ id).hide('slow');
            },
            error: function(){
                alert('fail');
            }
        });
	}
}
function accept_add_friend_req(id){
	if(confirm('Sigurno?')){
        $.ajax({
            type: "GET",
            url: "/ajax/friend/accept_add/"+ id,
            success: function(){
        	$(".request_"+ id).hide('slow');
            },
            error: function(){
                alert('fail');
            }
        });
	}
}
function citiraj(id,autor){
	$("#citiraj_id").val(id); 
	$("#submit_button").val('Citiraj komentar');
	$("#fatform_text").val('@'+ autor +' ');
	$("#citiraj_label").html("<h2>Citiraj komentar od <strong>"+ autor +"</strong><h2>");
	$("#citiraj_label").show();
	$(".citiraj_button").hide();
	$("#ponisti_citiranje").show();
}
function citiraj_ponisti(){
	$("#citiraj_id").val('0'); 
	$("#submit_button").val('Dodaj komentar');
	$("#fatform_text").val('');
	$("#citiraj_label").html('');
	$("#citiraj_label").hide();
	$(".citiraj_button").show();
	$("#ponisti_citiranje").hide();
}
function add_medalju(uid,username,type){
	if(confirm('Sigurno dati medalju?')){
        $.ajax({
            type: "GET",
            url: "/ajax/medalja/add/"+ uid +"/"+ type,
            success: function(){
				document.location.href="/user/"+ username;
				$(location).attr('href',url);
            },
            error: function(){
                alert('fail');
            }
        });
	}
}
function del_medalju(uid,username,type){
	if(confirm('Sigurno obrisati medalju?')){
        $.ajax({
            type: "GET",
            url: "/ajax/medalja/del/"+ uid +"/"+ type,
            success: function(){
				document.location.href="/user/"+ username;
				$(location).attr('href',url);
            },
            error: function(){
                alert('fail');
            }
        });
	}
}
function add_gadget(gid){
	if(confirm('Sigurno dodaj ovaj gadget?')){
        $.ajax({
            type: "GET",
            url: "/ajax/gadget/add/"+ gid,
            success: function(){
				document.location.href="/shop";
				$(location).attr('href',url);
            },
            error: function(){
                alert('fail');
            }
        });
	}
}
function delnote(id,url){
        $.ajax({
            type: "GET",
            url: "/ajax/user/delnote/"+id,
            success: function(){
				//alert('obrisano!');
				$(location).attr('href',url);
            },
            error: function(){
                alert('fail');
            }
        });
}
function delpost(id){
    if(confirm('Sigurno obrisati post?')){

        $.ajax({
            type: "GET",
            url: "ajax.php?brisipost="+id,
            success: function(){
				//alert('Post obrisan!');
                $('#post_'+id).hide('slow');
            },
            
        });     
    }
}
function delgb(id){
    if(confirm('Sigurno obrisati upis?')){

        $.ajax({
            type: "GET",
            url: "/ajax/guestbook/del/"+id,
            success: function(){
				//alert('Post obrisan!');
                $('#gb_'+id).hide('slow');
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}

function delcom(id){
    if(confirm('Sigurno obrisati upis?')){

        $.ajax({
            type: "GET",
            url: "ajax.php?brisipost2="+id,
            success: function(){
				
                $('#com_'+id).hide('slow');
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}
function dobarpost(id){
    if(confirm('Sigurno thumbs up za post?')){

        $.ajax({
            type: "GET",
            url: "/ajax/forum/post/dobar/"+id,
            success: function(){
				$('.tup_button_'+id).hide();
				$('.tdown_button_'+id).hide();
				$('.post_tup_text_'+id).show('slow');
				
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}
function lospost(id){
    if(confirm('Sigurno thumbs down za post?')){

        $.ajax({
            type: "GET",
            url: "/ajax/forum/post/los/"+id,
            success: function(){
				$('.tup_button_'+id).hide();
				$('.tdown_button_'+id).hide();
				$('.post_tdown_text_'+id).show('slow');
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}
function deltopic(id){
    if(confirm('Sigurno obrisati topic?')){

        $.ajax({
            type: "GET",
            url: "ajax.php?id="+id,
            success: function(){
                alert('Topic obrisan!');
				document.location.href='forum.php';
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}

function sticktopic(id){
    if(confirm('Sigurno oznaciti temu kao sticky?')){

        $.ajax({
            type: "GET",
            url: "ajax.php?sticky="+id,
            success: function(){
				alert('Tema oznacena kao sticky!');
				$('#stickbutton').hide();
				$('#unstickbutton').show();
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}

function unsticktopic(idek){
    if(confirm('Sigurno oznaciti temu kao unsticky?')){

        $.ajax({
            type: "GET",
            url: "ajax.php?unstickyba="+idek,
            success: function(){
				alert('Tema oznacena kao unsticky!');
				$('#stickbutton').hide();
				$('#unstickbutton').show();
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}

function locktopic(id){
    if(confirm('Sigurno zakljucati temu?')){

        $.ajax({
            type: "GET",
            url: "ajax.php?brisi="+id,
            success: function(){
				//alert('Tema zakljucana!');
				$('#lockbutton').hide();
				$('#unlockbutton').show();
				$('.odgovori_label').hide();
				$('.locked_label').show();
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}

function unlocktopic(id){
    if(confirm('Sigurno odkljucati temu?')){

        $.ajax({
            type: "GET",
            url: "ajax.php?otkljuc="+id,
            success: function(){
				//alert('Tema odkljucana!');
				$('#lockbutton').show();
				$('#unlockbutton').hide();
				$('.locked_label').hide();
				$('.odgovori_label').show();
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}

function odobrivijest(id){
    if(confirm('Sigurno odobri vijest?')){

        $.ajax({
            type: "GET",
            url: "/ajax/vijest/odobri/"+id,
            success: function(){
				//alert('Vijest odobrena!');
				$('#publish_action').toggle('slow');
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}

function stickvijest(id){
    if(confirm('Sigurno oznaciti vijest kao sticky?')){

        $.ajax({
            type: "GET",
            url: "/ajax/vijest/stick/"+id,
            success: function(){
				//alert('Vijest oznacena kao sticky!');
				$('#stick_action').toggle('slow');
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}

function unstickvijest(id){
    if(confirm('Sigurno odznaciti vijest kao sticky?')){

        $.ajax({
            type: "GET",
            url: "/ajax/vijest/unstick/"+id,
            success: function(){
				//alert('Vijest odznacena kao sticky!');
				$('#unstick_action').toggle('slow');
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}
function delvijest(id){
    if(confirm('Sigurno obrisati vijest?')){

        $.ajax({
            type: "GET",
            url: "/ajax/vijest/del/"+id,
            success: function(){
                alert('Vijest obrisana!');
				document.location.href='/';
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}
function odobridload(id){
    if(confirm('Sigurno odobri dload?')){

        $.ajax({
            type: "GET",
            url: "/ajax/dload/odobri/"+id,
            success: function(){
				//alert('dload odobren!');
				$('#publish_action').toggle('slow');
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}
function brisi_gb(id){
	if(confirm('Sigurno izbrisati upis ?')){
        $.ajax({
            type: "GET",
            url: "ajax.php?brisi_gb="+ id,
            success: function(){
        	$("#gb_"+ id).hide('slow');
            },
            error: function(){
                alert('fail');
            }
        });
	}
}

function stickdload(id){
    if(confirm('Sigurno oznaciti dload kao sticky?')){

        $.ajax({
            type: "GET",
            url: "/ajax/dload/stick/"+id,
            success: function(){
				//alert('dload oznacen kao sticky!');
				$('#stick_action').toggle('slow');
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}

function unstickdload(id){
    if(confirm('Sigurno odznaciti dload kao sticky?')){

        $.ajax({
            type: "GET",
            url: "/ajax/dload/unstick/"+id,
            success: function(){
				//alert('dload odznacen kao sticky!');
				$('#unstick_action').toggle('slow');
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}

function deldload(id){
    if(confirm('Sigurno obrisati dload?')){

        $.ajax({
            type: "GET",
            url: "/ajax/dload/del/"+id,
            success: function(){
                alert('Aplikacija obrisana!');
				document.location.href='/';
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}


function apsamar(id,sta,dao,kome){
    if(confirm('Sigurno  zelite dati '+sta+' clanu ?')){

        $.ajax({
            type: "GET",
            url: "ajax.php?sta="+sta+"&id="+id+"&dao="+dao+"&kome="+kome,
            success: function(){
				alert('Akcija dodana !');
                
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}


function delcomment(id){
    if(confirm('Sigurno obrisati komentar?')){

        $.ajax({
            type: "GET",
            url: "ajax.php?del="+id,
            success: function(){
				alert('Komentar obrisan!');
                $('#komentar_'+id).hide('slow');
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}

function delsliku(id){
    if(confirm('Sigurno obrisati sliku?')){

        $.ajax({
            type: "GET",
            url: "/ajax/pic/del/"+id,
            success: function(){
                alert('Slika obrisana!');
				document.location.href='/';
            },
            error: function(){
                alert('fail');
            }
        });     
    }
}

function unban(ide){
	if( confirm("Sigurno zelis unbanovati korisnika?") ){
		$.ajax(
		{
			type: "GET",
			url: 'ajax.php?unban='+ide,
			success:function(){
				$('#korisnik_banovan').hide('slow');
				$('#banbutton').show('slow');
				$('#unbanbutton').hide('slow');
			}
		});
	}
}


function ban(id){
	if( confirm("Sigurno zelis banovati korisnika?") ){
		$.ajax(
		{
			type: "GET",
			url: 'ajax.php?ban='+id,
			success:function(){
				$('#korisnik_banovan').hide('slow');
				$('#banbutton').show('slow');
				$('#unbanbutton').hide('slow');
			}
		});
	}
}

// tooltip
$(document).ready(function() {
    //Tooltips
    $(".tooltip").hover(function(){
        tip = $(this).find('.tip');
        tip.show(); //Show tooltip
    }, function() {
        tip.hide(); //Hide tooltip
    }).mousemove(function(e) {
        var mousex = e.pageX + 20; //Get X coodrinates
        var mousey = e.pageY + 20; //Get Y coordinates
        var tipWidth = tip.width(); //Find width of tooltip
        var tipHeight = tip.height(); //Find height of tooltip

        //Distance of element from the right edge of viewport
        var tipVisX = $(window).width() - (mousex + tipWidth);
        //Distance of element from the bottom of viewport
        var tipVisY = $(window).height() - (mousey + tipHeight);

        if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
            mousex = e.pageX - tipWidth - 20;
        } if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
            mousey = e.pageY - tipHeight - 20;
        }
        //Absolute position the tooltip according to mouse position
        tip.css({  top: mousey, left: mousex });
    });
});
// countdown
function startCountdown ( timeLeft ){
    var interval = setInterval( countdown, 1000 );
    update();

    function countdown (){
        if ( --timeLeft > 0 )
            update();
        else {
            clearInterval( interval );
            update();
        }
    }

    function update (){
    	//hours   = Math.floor( timeLeft / 3600 );
    	//minutes = Math.floor( ( timeLeft % 3600 ) / 60 );
    	// seconds = timeLeft % 60;
        document.getElementById("timeframe").innerHTML = timeLeft;
    }
}
// characters left
function chars_left(input_id,target_div,min,max){
	var val = document.getElementById( input_id ).value;
	var len = val.length;
	
	if(len < min){
		var want_more = len - min;
		var want_more = -want_more;
		document.getElementById( target_div ).innerHTML = 'još ' + want_more;
	} else {
		if(len > max){
			val = val.substring(0,max);
			document.getElementById( input_id ).value = val;
			return false;
		}
		document.getElementById( target_div ).innerHTML = max-len + ' preostalo';
	}
}










var auto_refresh = setInterval(
function()
{
$('#porukice').fadeIn('slow').load('porukice.php').fadeIn("slow");
}, 1000);






function odobri(id){
	if(confirm('Sigurno odobriti vijest ?')){
        $.ajax({
            type: "GET",
            url: "ajax.php?odobri="+ id,
            success: function(){
        	alert('Vijest objavljena !');
            },
            error: function(){
                alert('fail');
            }
        });
	}
}


function odbij(id,ko){
	if(confirm('Sigurno odbiti vijest ?')){
        $.ajax({
            type: "GET",
            url: "ajax.php?odbij="+ id+"&pos="+ko,
            success: function(){
        	alert('Vijest odbijena !');
            },
            error: function(){
                alert('fail');
            }
        });
	}
}

function ukloni(ko){
	if(confirm('Sigurno ukloniti donatora i postaviti kao clana ?')){
        $.ajax({
            type: "GET",
            url: "ajax.php?ukloni="+ ko,
            success: function(){
        	$('#don_'+ko).hide('slow');
            },
            error: function(){
                alert('fail');
            }
        });
	}
}
function svijest(id){
	if(confirm('Sigurno oznaciti vijest kao sticky ?')){
        $.ajax({
            type: "GET",
            url: "ajax.php?svijest="+ id,
            success: function(){
        	$('#oznaka').hide('slow');
			$('#oznaka2').fadeIn('slow');
            },
            error: function(){
                alert('fail');
            }
        });
	}
}
function unstickit(idek){
    if(confirm('Sigurno oznaciti vijest kao unsticky?')){

        $.ajax({
            type: "GET",
            url: "ajax.php?unstickit="+idek,
            success: function(){
				
				$('#hea').hide();
				
            },
            error: function(){
                alert('faila');
            }
        });     
    }
}

function delkat(id){
    if(confirm('Sigurno obrisati kategoriju ?')){

        $.ajax({
            type: "GET",
            url: "ajax.php?brisikategoriju="+id,
            success: function(){
				//alert('Post obrisan!');
               
            },
            
        });     
    }
}
function brisisve(user){
    if(confirm('Sigurno obrisati sve poruke ?')){

        $.ajax({
            type: "GET",
            url: "ajax.php?brisisve="+user,
            success: function(){
				//alert('Post obrisan!');
               
            },
            
        });     
    }
}
function brisisliku(user){
    if(confirm('Sigurno obrisati sliku ?')){

        $.ajax({
            type: "GET",
            url: "ajax.php?brisisliku="+user,
            success: function(){
				//alert('Post obrisan!');
               
            },
            
        });     
    }
}


