

function handleAjaxErrorFilter(XMLHttpRequest, textStatus, errorThrown) {
	alert('ajax error: ' + textStatus);  
	// typically only one of textStatus or errorThrown 
	  // will have info
	  //this; // the options for this ajax request
}

function handleAjaxRequestFilter(value) {
	document.getElementById('filter_loading').style.visibility = 'hidden';
	resetCombosFilter();
	var lines = value.split(";");
	for (var j = 0; j < lines.length; j++) {
		var args = lines[j].split(",");
		if (args == '') continue;
		var elSel = document.getElementById('filter_combo_' + args[2]);
		addOptionFilter(args[0], args[1], elSel);
	}
}

function resetCombosFilter() {
	for (var i = 1; i < 6; i++) {
		var elSel = document.getElementById('filter_combo_' + i);
		elSel.disabled = false;
		elSel.options.length = 0; // clear combo
		addOptionFilter("--- nezáleži ---", 0, elSel);
	}
}

function sendRequestFilter(type) {
	 $.ajax({
	        type: "POST",
	        url: "ajaxProxy.php",
	        data: "filter=" + type,
	        //contentType: "application/json; charset=utf-8",
	        //dataType: "json",
	        //beforSend : alert('befor'),
	        //completed : alert('completed'),
	        success: handleAjaxRequestFilter,
	        error : handleAjaxErrorFilter
	    });
}

function enableDisableElementsFilter(value) {
	for (var i = value+1; i < 4; i++) {
		var elSel = document.getElementById('filter_combo_' + i);
		elSel.disabled = true;
		elSel.options.length = 0;
		addOption("--- zvoľte ---", 0, elSel);
	}
}

function addOptionFilter(t, v, elSel) {
	if (t == null || v == null) return;
	var elOptNew = document.createElement('option');
	elOptNew.text = t;
	elOptNew.value = v;
	try {
		elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
	} catch(ex) {
		elSel.add(elOptNew); // IE only
	}
}

function fillComboFilter(type) {
	document.getElementById('filter_loading').style.visibility = 'visible';
	sendRequestFilter(type);
}

function enableSubmitFilter(value) {
	//document.getElementByName('pneu_submit').disabled = value;
}