window.addEvent("domready", function() {
    new Autocompleter.Request.JSON("cat1", "/datastores/_categories.php", {
        "postVar": "kw",
        "minLength": 3,
		"width": 200,
		"selectMode": "type-ahead",
		"filterSubset": true,
		"indicator": true,
		"idField": "catid1"
    });

    new Autocompleter.Request.JSON("ed", "/datastores/_publishers.php", {
        "postVar": "kw",
        "minLength": 3,
		"width": 200,
		"selectMode": "type-ahead",
		"filterSubset": true,
		"indicator": true,
		"idField": "edid"
    });

    new Autocompleter.Request.JSON("aut", "/datastores/_authors.php", {
        "postVar": "kw",
        "minLength": 4,
		"width": 200,
		"selectMode": "type-ahead",
		"filterSubset": true,
		"indicator": true,
		"idField": "autid"
    });
    
	$("adv-search-form").addEvent("submit", function() {
		var _kw = $("kw1").value;
		var _catid = $("catid1").value;
		var _autid = $("autid").value;
		var _edid = $("edid").value;
		var _isbn = $("isbn").value;
		var _pmin = $("pret1").value;
		var _pmax = $("pret2").value;
		
		if (_kw == "") {
			_alert("Trebuie sa specificati termenul dupa care se face cautarea!", "alert");
			return false;
		}			
		
		var _url = "/cautare.php?kw=" + _kw;
		
		if (_catid != "") {
			_url += "&cat=" + _catid;
		}

		if (_autid != "") {
			_url += "&aut=" + _autid;
		}

		if (_edid != "") {
			_url += "&ed=" + _edid;
		}

		if (_isbn != "") {
			_url += "&isbn=" + _isbn;
		}

		if (_pmin != "") {
			_url += "&pmin=" + _pmin;
		}

		if (_pmax != "") {
			_url += "&pmax=" + _pmax;
		}

		window.location = _url + "#lista-cartilor";
		
		return false;
	});
    
});

