$(document).ready(function(){
	$(".show_form").toggle(function(){
		$(".show_form_email").animate({ height: 'show', opacity: 'show' }, 'slow');
	},function(){
		$(".show_form_email").animate({ height: 'hide', opacity: 'hide' }, 'slow');
	});
});


function najzanimljiviji() {
    $.ajax({
        type: "POST",
        url: "/ajaxReq.php?type=najzanimljiviji",
        success: function(msg){
            $("#najzanimljiviji").html(msg);
        }
    });
    return false;
}

function najcitaniji() {
    $.ajax({
        type: "POST",
        url: "/ajaxReq.php?type=najcitaniji",
        success: function(msg){
            $("#najcitaniji").html(msg);
        }
    });
    return false;
}

function najnoviji() {
    $.ajax({
        type: "POST",
        url: "/ajaxReq.php?type=najnoviji",
        success: function(msg){
            $("#najnoviji").html(msg);
        }
    });
    return false;
}

function postAd() {
    $.ajax({
        type: "POST",
        url: "/ajaxReq.php?type=dodaj",
        data: "category_id=" + document.getElementById('category_id').value + "&cat_type=" + document.getElementById('cat_type').value + "&title=" + document.getElementById('title').value + "&short_desc=" + document.getElementById('short_desc').value + "&country=" + document.getElementById('country').value + "&osoba=" + document.getElementById('osoba').value + "&fon=" + document.getElementById('fon').value + "&email=" + document.getElementById('email').value + "&allow_contact=" + document.getElementById('allow_contact').checked + "&terms=" + document.getElementById('terms').checked,
        success: function(msg){
            $("#addNewResponse").html(msg);
        }
    });
    return false;
}
$(document).ready(function() {
    $("#plice_check").click(function() {
        $("#plice").show();
    });

    $("#flice_check").click(function() {
        $("#plice").hide();
    });
});

function loginMe() {
	$.ajax({
		type: 'POST',
		url: '/login.php',
		data: ({'name': $('#name').val(), 'pass': $('#Password').val()}),
		success: function(msg) {
			if (msg == 0) {//error
				$("#TB_ajaxContent").height('auto');
				$('#errorLogin').show();
				$('#errorLogin').html('<h3>Greška:</h3><ol><li>Pogrešna e-mail adresa ili lozinka</li></ol>');

			} else if (msg == 1 || msg == 2) {//user
//				$('#toggleLog').html('<a href="/admin">Administracija</a> | <a href="/logout.php">Odjavite se</a>');
//				$('#toggleLog').html('<a href="/logout.php">Odjavite se</a>');
				$('#TB_ajaxContent').html($('#login_sucess').html());
				$('#TB_ajaxContent').height('auto');
// 				setTimeout(tb_remove, '2500');
 				setTimeout(gotoHome, '1500');
			}
		}
	});
	return false;
}

function passRecovery() {
	$.ajax({
		type: 'POST',
		url: '/ajaxReq.php?type=pass_recovery',
		data: ({'email': $('#email').val()}),
		success: function(msg) {
			if (msg == 0) {//error
//				$('#errorLogin').show();
//				$('#errorLogin').html('<h3>Greška:</h3><ol><li>Pogrešna e-mail adresa ili lozinka</li></ol>');

			} else if (msg == 1) {//user
				location.href = '/lozinka_poslata';
//				$('#TB_ajaxContent').html($('#recovery_sucess').html());
//				$('#TB_ajaxContent').height('auto');
// 				setTimeout(tb_remove, '2500');
// 				setTimeout(gotoHome, '1500');
			}
		},
		clearForm: true
	});
	return false;
}

function gotoHome() {
	location.href = '/';
}

function printMe() {
    window.print();
}

function bookmarkMe() {
    var title = "Plave Strane";
    var url = window.location.href;
    if(document.all) { // IE Favorite
        window.external.AddFavorite(url, title);
    }
    else if(window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title,url,url);
    }
}