function initialize() {
    var latlng = new google.maps.LatLng(45.494407,15.550321);
    var myOptions = {
        zoom: 15,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
    var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        title:"Ured državne uprave"
    });
}

$(document).ready(function(){
    $('a.more').data('open',false);
    $("#radio").buttonset();
	
    //--------------LOGIN DIALOG------------------------------------------------
    $("#login_dialog").dialog({
        autoOpen: false,
        modal: true,
        hide: 'explode',
        resizable: false,
        buttons: {
            "Prijavi se": function() {
                $('#login_dialog form').submit();
            },
            "Odustani": function() {
                $(this).dialog("close");
            }
        }
    });
	
    //---------PRIMJENA jquer ui NA SVE GUMBE-------------------
    $(":input:button, :submit").button();
    $("button").button();

});

//----------dajXMLHTTP-------------------------------------------------------------------------
function dajXMLHTTP(){
    xmlhttp=kreirajObjekt();

    if(xmlhttp==null){
        alert("Objekt nije kreiran");
        return false;
    }
    return xmlhttp;
}

//----------sakri - Skrivanje i prikazivanje obavijesti----------------------------------------
function sakri(id,duljina){
    if(!$('a#more-'+id).data('open')){
        $('#skraceno-'+id).height("100%");
        visina=$('#skraceno-'+id).height();
        if(duljina!=0){
        $('#skraceno-'+id).height("33px");
        }else{
            $('#skraceno-'+id).height("0px");
        }
        //alert(visina);

        if(visina>"40" && duljina!=0){
            $('#skraceno-'+id).animate({
                height: visina
            }, 'slow');
        }
        $('#tri_tocke-'+id).hide();
        $('a#more-'+id).data('open',true)
        $("#more-"+id).text("Manje...");

    }else{
        //alert(visina);
        if(visina>"40" && duljina!=0){
            $('#skraceno-'+id).animate({
                height: '33px'
            }, 'slow');
       }
        $('a#more-'+id).data('open',false)
        $('#tri_tocke-'+id).show();
        $("#more-"+id).text("Više...");
    }

}

//----------Pretrazivanje----------------------------------------------------------------------
function pretrazi(){
    pojam=document.getElementById('pojam').value;
    if (pojam.length>2) {
        xmlhttp=kreirajObjekt();
	
        if(xmlhttp==null){
            alert("Objekt nije kreiran");
            return false;
        }
        var url="podaci.php?pretrazi&pojam="+pojam;
        xmlhttp.onreadystatechange=stateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
}

function otvori_login_dialog(){
    document.getElementById('login_forma').reset();
    document.getElementById('user').style.backgroundColor="";
    document.getElementById('pass').style.backgroundColor="";
    $('#login_dialog').dialog('open');
}

//----------Login------------------------------------------------------------------------------
function login(){
    username = document.getElementById('user').value;
    password = document.getElementById('pass').value;
    trenutna_str = document.getElementById('trenutna_stranica').value;
	
    if(username == "" || password == ""){
        if(username == ""){
            document.getElementById('user').style.backgroundColor="#F00";
        }else{
            document.getElementById('user').style.backgroundColor="";
        }
        if(password == ""){
            document.getElementById('pass').style.backgroundColor="#F00";
        }else{
            document.getElementById('pass').style.backgroundColor="";
        }
    }else{
        $("#login_dialog").dialog("close");
        //alert("ok");
        xmlhttp=kreirajObjekt();
	
        if(xmlhttp==null){
            alert("Greška! Objekt nije kreiran");
            return;
        }
        params="login=&username="+username+"&password="+password+"&trenutna_str="+trenutna_str;
        //alert(params);
        xmlhttp.open("POST","podaci.php",true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length", params.length);
        xmlhttp.setRequestHeader("Connection", "close");
        xmlhttp.onreadystatechange=stateChanged;
        xmlhttp.send(params);
    }
}

//----------Logout-----------------------------------------------------------------------------
function odjava(){
    xmlhttp=kreirajObjekt();
	
    if(xmlhttp==null){
        alert("Objekt nije kreiran");
        return false;
    }
    var url="podaci.php?logout";
    //alert(url);
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    return true;
}

//----------prikazi----------------------------------------------------------------------------
function prikazi(id){
    //alert(id);
    xmlhttp=kreirajObjekt();

    if(xmlhttp==null){
        alert("Objekt nije kreiran");
        return false;
    }
    //$("#progressbar_modal").dialog({ modal: true, resizable: false});
	
    ht = "<div id=\"progressbar\" style=\"width:520px; float:left;\"></div>";
    document.getElementById('content').innerHTML=ht;
	
    $("#progressbar").progressbar({
        value: 0
    });
	
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET","podaci.php?prikazi&id="+id,true);
    xmlhttp.send(null);
}

//----------prikazi_podcrtano------------------------------------------------------------------
function prikazi_podcrtano(id,pojam){
    //alert(id+" "+pojam);
    xmlhttp=kreirajObjekt();

    if(xmlhttp==null){
        alert("Objekt nije kreiran");
        return false;
    }
    //$("#progressbar_modal").dialog({ modal: true, resizable: false});
	
    ht = "<div id=\"progressbar\" style=\"width:520px; float:left;\"></div>";
    document.getElementById('content').innerHTML=ht;
	
    $("#progressbar").progressbar({
        value: 0
    });
	
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET","podaci.php?prikazi_podcrtano&id="+id+"&pojam="+pojam,true);
    xmlhttp.send(null);
}

/*var ctrl= false;
var paste=false;
function provjeri_paste(ev){
	paste=false;
	if(ev.keyCode==17){
		ctrl=true;
	}
	if(ctrl&&ev.keyCode==86){
		//alert(event2.keyCode);
		ctrl=false;
		paste=true;
		return false;
	}
}*/

//----------provjeri_email------------------------------------------------------------------
function provjeri_email(email,email2){
    if(email!=email2){
        document.getElementById('email').style.backgroundColor="red";
        document.getElementById('email2').style.backgroundColor="red";
    }else{
        document.getElementById('email').style.backgroundColor="#00FF00";
        document.getElementById('email2').style.backgroundColor="#00FF00";
    }
    return true;
}

//----------prikazi_upozorenje------------------------------------------------------------------
function prikazi_upozorenje(email){
    if(email==""){
        document.getElementById('upozorenje').innerHTML="Ako ne upišete e-mail nećemo vam moći odgovoriti na poruku.";
    }else{
        document.getElementById('upozorenje').innerHTML="";
    }
}

//----------posalji_email------------------------------------------------------------------
function posalji_email(){
    ime_posiljatelja=document.getElementById('ime_posiljatelja').value;
    email=document.getElementById('email').value;
    email2=document.getElementById('email2').value;
    naslov=document.getElementById('naslov').value;
    sadrzaj=document.getElementById('sadrzaj').value;
	
    document.getElementById('naslov').style.backgroundColor="";
    document.getElementById('sadrzaj').style.backgroundColor="";
    document.getElementById('email').style.backgroundColor="";
    document.getElementById('email2').style.backgroundColor="";
	
    if(naslov==""){
        document.getElementById('naslov').style.backgroundColor="red";
    }
	
    if(sadrzaj==""){
        document.getElementById('sadrzaj').style.backgroundColor="red";
    }
	
    if(email!=email2 && (email!="" || email2!="")){
        document.getElementById('email').style.backgroundColor="red";
        document.getElementById('email2').style.backgroundColor="red";
    }
	
    if(email!=email2 || sadrzaj=="" || naslov==""){
        return false;
    }else{
        xmlhttp=kreirajObjekt();
        if(xmlhttp==null){
            alert("Objekt nije kreiran");
            return false;
        }
        var url="podaci.php?posalji_email&ime_posiljatelja="+ime_posiljatelja+"&email="+email+"&naslov="+naslov+"&sadrzaj="+sadrzaj;
        //alert(url);
        xmlhttp.onreadystatechange=stateChanged13;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
		
        return true;
    }
}

//----------Kreiraj objekt---------------------------------------------------------------------
function kreirajObjekt(){
    if(window.XMLHttpRequest){
        return new XMLHttpRequest();
    }
    if(window.ActiveXObject){
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
}

//----------State changed----------------------------------------------------------------------
function stateChanged(){	
    if(xmlhttp.readyState==0){
        $("#progressbar").progressbar( "option", "value", 5 );
    }
    if(xmlhttp.readyState==1){
        $("#progressbar").progressbar( "option", "value", 35 );
    }
    if(xmlhttp.readyState==2){
        $("#progressbar").progressbar( "option", "value", 50 );
    }
    if(xmlhttp.readyState==3){
        $("#progressbar").progressbar( "option", "value", 75 );
    }
    if(xmlhttp.readyState==4){
        $("#progressbar").progressbar( "option", "value", 100 );
		
        $("#progressbar").progressbar( "destroy" );
        //alert(xmlhttp.responseText);
        var noviDiv=document.getElementById('content');
        noviDiv.innerHTML=xmlhttp.responseText;
    }
}

//----------State changed 13-------------------------------------------------------------------
function stateChanged13(){
    if(xmlhttp.readyState==4){
        //alert(xmlhttp.responseText);
        var noviDiv=document.getElementById('poruka');
        noviDiv.innerHTML=xmlhttp.responseText;
    }
}
