// funkcija za trim stringa
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }

// funkcija startsWith za string
String.prototype.startsWith = function(str) { return (this.match("^"+str)==str); }

// funkcija endsWith za string
String.prototype.endsWith = function(str) { return (this.match(str+"$")==str); }


/* funkcije za meni za izbor jezika */
function makeTall(){ 
    document.getElementById('languages').style.height = '295px'; document.getElementById('languages').style.border = '1px solid #3366CC';
}
function makeShort(){ 
    document.getElementById('languages').style.height = '18px'; document.getElementById('languages').style.border = 'none';
}

function showMakes ()
{
	$("#make_panel").fadeIn ("fast");
}

function change_menu (item)
{
    var location = window.location.href;
    var lang = "";
    var url = "";
    var split = location.split("/");
    
    if (split[3] != "")
    {
        lang = split[3];
        url = location.replace ("/" + lang, "/" + item.id);
    }
    else
    {
        url = location + item.id;
    }
    
    window.location = url;
}

function bodyClicked ()
{
    document.getElementById("searchbox").innerHTML = "";
}

function clearIt (searchBox, text)
{	
    if (searchBox.value == text)
    {
        searchBox.value = "";
        searchBox.style.color = "black";
    }
}

function isFilled(searchBox, whatToWrite)
{
    if (searchBox.value == "")
    {
        searchBox.value = whatToWrite;
        searchBox.style.color = "#AAAAAA";
    }
}

//promenio sam
function submitWhat (lang, field)
{
    var loc = window.location.href;
    var changed = document.getElementById (field).value.replace(/ /g, ";");
    
    var url = "";
	
    if (loc.indexOf ("/" + lang) == -1)
    {
        url = loc + lang;
    }
    else
    {
        url = loc.substring (0, loc.indexOf ("/" + lang) + 3);
    }
	
    if (loc.indexOf ("/visual-search") != -1)
    {
    	url += "/visual-search";
    }
    else
    {
    	url +=  "/used-cars";
    }
    
    url +=  "/what-" + changed + "/page-1";
	
	
    window.location = url;
	
    return false;
}

function item_click (item)
{
	var url = item.href;

	item.href = url.replace(/#/, "/");
}