/**
 * @author Alfred
 */
var currentSeachTerm = webroot+"finder/index/1/yes/?";
$("input[type='checkbox']").click(function(){
	checkAll();
});

$("input[type='radio']").click(function(){
	checkAll();
});
$("select").change(function(){
	checkAll();
});
$(".finderpagination").find("li").find("a").click(function(){
	$("#finderresult").slideUp();
	$.ajax({
  		type: "GET",
 		url: this.href,
 		success: function(msg){
    		$("#finderresult").html(msg);
  			$("#finderresult").slideDown();
		}
	});
	return false;
});
var hasKeyword=false;
$("button").click(function(){
	hasKeyword=true
	checkAll();
	return false;
});
var timeoutID;
function checkAll(){
	clearTimeout(timeoutID);
	currentSeachTerm = webroot+"finder/index/1/yes/?";
	$("input[type='checkbox']").each(function(){
		if(this.checked){
			currentSeachTerm+= this.name+"="+this.value+"&";
		}
	});
	$("input[type='radio']").each(function(){
		if(this.checked){
			currentSeachTerm+= this.name+"="+this.value+"&";
		}
	});
	if($("select").attr("value")!=undefined){
		currentSeachTerm += "relation="+$("select").attr("value");
	}
	if(hasKeyword){
		currentSeachTerm += "keywords="+$("#keywords").attr("value");
	}
	//alert(currentSeachTerm);
	timeoutID = setTimeout("doLivesearch()",200);
}
function doLivesearch(){
	hasKeyword=false;
	$("#finderresult").slideUp();
	$.ajax({
  		type: "GET",
 		url: currentSeachTerm,
 		success: function(msg){
    		$("#finderresult").html(msg);
  			$("#finderresult").slideDown();
		}
	});
	
}
