<!--//XMLhttp variable will hold the XMLHttpRequest object
var xmlhttp = false;
// If the user is using Mozilla/Firefox/Safari/etc
if (window.XMLHttpRequest) { // Mozilla, Safari,... &&ie7!
        //Intiate the object
        xmlhttp = new XMLHttpRequest();
        //Set the mime type JAVLJA ERROR
        /*
        http_request = new XMLHttpRequest();
        if (http_request.overridemimetype){ //Not in ie7
        xmlhttp.overrideMimeType('charset=utf-8');
        }
        */
} else if (window.ActiveXObject) {
        //Intiate the object
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
function preSearch() {
    //Put the form data into a variable
	var theQuery = document.getElementById('fq').value;


    //Display or not (together with)
    // izmena zbog strict.dtd
    // if (theQuery !== "") result.style.display = 'block';
    // if (theQuery !== "") document.getElementById('result').style.display = 'block';
       if (theQuery.length>"2") document.getElementById('result').style.display = 'block';
    // if (theQuery !== "") all.style.display = 'block';
    // if (theQuery !== "") document.getElementById('all').style.display = 'block';
       if (theQuery.length>"2") document.getElementById('all').style.display = 'block';

    //if (theQuery.length<"3") result.style.display = 'none';
    //if (theQuery.length<"3") all.style.display = 'block';

    //if (theQuery == "") result.style.display = 'none';
    //if (theQuery == "") document.getElementById('result').style.display = 'none';
      if (theQuery.length<"3") document.getElementById('result').style.display = 'none';
    //if (theQuery == "") all.style.display = 'none';
    //if (theQuery == "") document.getElementById('all').style.display = 'none';
      if (theQuery.length<"3") document.getElementById('all').style.display = 'none';



    //If the form data is *not* blank, query the DB and return the results
	if(theQuery !== "") {
    //Change the content of the "result" DIV to "Searching..."
    //This gives our user confidence that the script is working if it takes a moment for the result to be returned. However the user will likely never see this...
	// document.getElementById('result').innerHTML = "Searching...";

    function replaceAll( str, from, to ) {
                                     var idx = str.indexOf( from );
                                     while ( idx > -1 ) {
                                                        str = str.replace( from, to );
                                                        idx = str.indexOf( from );
                                                        }
                                     return str;
                                     }

    theQuery = replaceAll( theQuery, "Ž", "382" );
    theQuery = replaceAll( theQuery, "ž", "382" );
    theQuery = replaceAll( theQuery, "Đ", "273" );
    theQuery = replaceAll( theQuery, "đ", "273" );
    theQuery = replaceAll( theQuery, "Š", "353" );
    theQuery = replaceAll( theQuery, "š", "353" );
    theQuery = replaceAll( theQuery, "Ć", "267" );
    theQuery = replaceAll( theQuery, "ć", "267" );
    theQuery = replaceAll( theQuery, "Č", "269" );
    theQuery = replaceAll( theQuery, "č", "269" );

        //This sets a variable with the URL (and query strings) to our PHP script
		var url = 'http://srbija.aladin.info/suggest/dropdown.php?q=' + theQuery;
        //Open the URL above "asynchronously" (that's what the "true" is for) using the GET method
		xmlhttp.open('GET', url, true);

        //Check that the PHP script has finished sending us the result
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                //Replace the content of the "result" DIV with the result returned by the PHP script
				document.getElementById('result').innerHTML = xmlhttp.responseText + '';
			} else {
                //If the PHP script fails to send a response, or sends back an error, display a simple user-friendly notification
				document.getElementById('result').innerHTML = '';
			}
		};
		xmlhttp.send(null);
	}
}//-->