////get the saved value function - return the value of "v" from localStorage.
function getSavedValue  (v,def){
    if (sessionStorage.getItem(v)==null) {
        return def;// You can change this to your defualt value.
    }
    console.log("nije null "+v);
    var select=document.getElementById(v);
    if(select){
            if (select.tagName.toLowerCase()==="select") {

            console.log("select "+v);
            for(var i=0;i<select.options.length;i++){
                if(select.options[i].value==sessionStorage.getItem(v)){
                    console.log("ima "+sessionStorage.getItem(v));
                    return sessionStorage.getItem(v);
                }
            }
        }
        else{
            return sessionStorage.getItem(v);
        }
    }
    console.log("nema "+sessionStorage.getItem(v));
    return def;
}
//
window.onload = function() {
    document.getElementById("kljuc").value = getSavedValue("kljuc","");    // set the value to this input
    if(document.getElementById("lokacija"))
        document.getElementById("lokacija").value = getSavedValue("lokacija","0");
    if(document.getElementById("radOdKuce"))
        document.getElementById("radOdKuce").value = getSavedValue("radOdKuce","none");
    if(document.getElementById("oblast")){
        console.log("ima oblast");
        document.getElementById("oblast").value = getSavedValue("oblast","0");
        promeniPodkategorije(document.getElementById("oblast"));
    }
    if(document.getElementById("sortSelect"))
        document.getElementById("sortSelect").value = getSavedValue("sortSelect","novi");

    }

 // set the value to this input
        /* Here you can add more inputs to set value. if it's saved */

//Save the value function - save it to localStorage as (ID, VALUE)
function saveValue(e){
    var id = e.id;  // get the sender's id to save it .
    var val = e.value; // get the value.
    sessionStorage.setItem(id, val);// Every time user writing something, the localStorage's value will override .
}



