// JavaScript Document
var url = "php/list.php";
var h1cim=" jegyzőjénél nyilvántartásba vett kereskedelmi tevékenységek";

var emptytext = "<td colspan='28'><em>Nincs megjeleníthető elem</em></td>";

$(document).ready(function(){ 

$("#datatable thead td.sort").click(function(){
var q = $("#polg_hiv").children("option:selected").val();
var neve = "__polg_hiv__";
var val = q;
var src = $('#searchButton').attr("disabled") == false;

if(q != "default"){	
		if($(this).hasClass("ascend")) { //csökkenőre állítjuk
			$(this).removeClass("ascend").addClass("descend");
      
      if (src){
        $('#searchButton').click();
      }
      else {

      $.get(url,
			{"sort" : "descend",
			 "field" : $(this).attr("id"),
			 "__polg_hiv__" : q
			},
			function(s){$("#datatable tbody").html(s);})						 
      }
						
		} else
		if($(this).hasClass("descend")) { //növekvőre állítjuk
			$(this).removeClass("descend").addClass("ascend");
      if (src){
        $('#searchButton').click();
      }
      else {
			
      $.get(url,
			{"sort" : "ascend",
			 "field" : $(this).attr("id"),
			 "__polg_hiv__" : q
			},
			function(s){$("#datatable tbody").html(s);})
      }			
		} else { //ezt a mezőt állítjuk be sortolónak
			$("#datatable thead td.sort").removeClass("ascend").removeClass("descend");
			$(this).addClass("ascend");

      if (src){
        $('#searchButton').click();
      }
      else {

      $.get(url,
			{"sort" : "ascend",
			 "field" : $(this).attr("id"),
			 "__polg_hiv__" : q
			},
			function(s){$("#datatable tbody").html(s);})
			}
			
		}

   }
		
	})

$('#loader')
    .hide()  // hide it initially
    .ajaxStart(function() {
        $(this).show();
    })
    .ajaxStop(function() {
        $(this).hide();
    })
;


  $.get(url,{"regi_jo" : 1},function(s){$("#regio").html(s)});
	//Resetálás inicializáláskor
	$("#regio")[0].selectedIndex = 0;
	$("#polg_hiv").attr("disabled","disabled")[0].selectedIndex = 0;
	$("#showButton").attr("disabled","disabled");
  $("#searchButton").attr("disabled","disabled");
  $("#hideButton").attr("disabled","disabled");
  
  // Lap headere mindig kimegy
 	$("h1").html("[] "+h1cim);
  
  //$("#telep").attr("value","");
	//Régió kezelés
	$("#regio").change(function(){		
		var v = $(this).children("option:selected").val();
  	$("h1").html("[] "+h1cim);
    $("#datatable thead td.sort").removeClass("ascend").removeClass("descend");		
    $("#nyilvtart").addClass("ascend");		
		$("#datatable tbody").html(emptytext);
		$("#showButton").attr("disabled","disabled");		
		$(".searchForm").removeClass("showSearch");		
    $("#searchButton").attr("disabled","disabled");
    $("#hideButton").attr("disabled","disabled");
    if(v != "default"){	
			$.get(url, {"regio" : v},	function(s){$("#polg_hiv").html(s).removeAttr("disabled");})
		} else { //Ha default, nem csinál semmit, cserébe disabled lesz a másik kettő select
			$("#polg_hiv").attr("disabled","disabled")[0].selectedIndex = 0;
		}
	})
	
	//Polg.hiv.  kezelés
	$("#polg_hiv").change(function(){		
		var v = $(this).children("option:selected").val();
    $("#datatable thead td.sort").removeClass("ascend").removeClass("descend");		
    $("#nyilvtart").addClass("ascend");		
		$(".searchForm").removeClass("showSearch");
		if(v != "default"){	
			$("#datatable tbody").html(emptytext);
//			$.get(url, {"polg_hiv" : v}, function(s){$("#telepules").html(s).removeAttr("disabled");});

    	$("h1").html($(this).children("option:selected").text()+h1cim);
//      $("#telep").attr("value",$(this).children("option:selected").text());
      $("#showButton").show();
  		$("#showButton").removeAttr("disabled");  		
			$.get(url, {"__polg_hiv__" : v}, function(s){$("#datatable tbody").html(s);})
 
			
		} else { //Ha default, nem csinál semmit, cserébe disabled lesz a másik kettő select
	      $("h1").html("[] "+h1cim);
  			$("#datatable tbody").html(emptytext);
				$("#showButton").attr("disabled","disabled");
        $("#searchButton").attr("disabled","disabled");
        $("#hideButton").attr("disabled","disabled");

		}
	})
	
	
})

