$(document).ready(
	function() {
		$("#searchCompany").change(function() {
			var thisid = $(this).attr('id');
			var app_id= $(this).find("option[@selected]").attr("value");
			$.ajax({
			  url: "/si/ajax/",
			  data: "act=get_sub_categories&app_id="+app_id,
			  async: false,
			  success: function(response) {
				 $("#searchModel").html(response);
			  }
			});
			var searchModel = $(this).find("option[@selected]").attr("value");
			if(searchModel == 0){
				document.getElementById("searchProduct").disabled="disabled";
				document.getElementById("search_product_prod").disabled="disabled";
			}
			else{
				document.getElementById("searchProduct").disabled= false;
				document.getElementById("search_product_prod").disabled= false;
				document.getElementById("nula").selected=true;
				document.getElementById("nula1").selected=true;
			}
		});
		$("#searchModel").change(function(){
			var searchModel = $(this).find("option[@selected]").attr("value");
			if ($(this).attr("id") == 'searchModel') {
				$("#search_product_subcat").find("[value=" + searchModel + "]").attr("selected", "selected");
			}
			else 
				if ($(this).attr("id") == 'search_product_subcat') {
				$("#searchModel").find("[value="+searchModel+"]").attr("selected","selected");	
			}
			var search_product_prod = $("#search_product_prod").find("option[@selected]").attr("value");
			if(searchModel == 0){
				document.getElementById("searchProduct").disabled="disabled";
				document.getElementById("search_product_prod").disabled="disabled";
			}
			else{
				document.getElementById("searchProduct").disabled= false;
				document.getElementById("search_product_prod").disabled= false;
				document.getElementById("nula").selected=true;
				document.getElementById("nula1").selected=true;
			}
		});
		if(document.getElementById("search_product_cat")){
			var izbran = document.getElementById("search_product_cat").value;
			if(izbran != '0'){
				if(document.getElementById("searchModel")){
					$.ajax({
						url: "/si/ajax/",
						data: "act=get_sub_categories1&app_id="+izbran,
						async: false,
						success: function(response){
							$("#searchModel").html("<option value='0'></option>" + response);
						}
					});
				}
				$.ajax({
				  url: "/si/ajax/",
				  data: "act=get_sub_categories&app_id="+izbran,
				  async: false,
				  success: function(response){}
				});
			}
		}
		if(document.getElementById("modelll")){
			if(document.getElementById("modelll") != 'undefined'){
				var pravilen = document.getElementById("modelll").rel;
				if(pravilen != ''){
					if(document.getElementById(pravilen)){
						document.getElementById(pravilen).selected=true;
					}
					if(document.getElementById(pravilen + '1')){
						document.getElementById(pravilen + '1').selected=true;
					}
				}
			}
		}
		if(document.getElementById("searchModel")){
			var searchModel = $("#searchModel").find("option[@selected]").attr("value");
			if(searchModel != 0 && searchModel != ''){
				document.getElementById("searchProduct").disabled=false;
				document.getElementById("search_product_prod").disabled=false;
			}
		}
		//equalHeight($(".content .artikel"));
	}
);
/**
* @desc Izenačimo višine elementov v skupini.
* @param group DOM Skupina objektov, katere višino želimo izenačiti.
* @return /
*/
function equalHeight(group) {
	if (group.length > 1) {
		var max =  0;
		group.each(function() {
			if ($(this).height() > max) {
				max = parseInt($(this).height());
			}
		});
		group.height(max);
	}
}

