$(function() {
	$('#add-more-fields').click(function(){

		var ttl_fields;
		var valid_search_fields;
		
		ttl_fields = parseInt(document.getElementById("ttl_fields").value)+1;
		valid_search_fields = document.getElementById("valid_search_fields").value;
		
		$.ajax({
			type: "POST",
			url: "/xml/adv_search_row.php",
			cache: false,
			dataType: "html",
			data: "ttl_fields="+ttl_fields+"&valid_search_fields="+valid_search_fields+"",
			success: function(html) {
				$("#advanced-search-rows").append(html);
				document.getElementById("ttl_fields").value = ttl_fields;
			}
		});
		

	});										
});

//Used for sorting the results by date, title, etc

function empty_sort_by() 
{
	document.getElementById('sort_by').value == null;
}

function sort_by_results (info)
{
	var info_array = info.split(":");
	
	var field = info_array[0];
	var order = info_array[1];
	if(info_array[2] != "") var url = info_array[2];
	
	if(url != null)
	{
		if(field != null && order != null && field != "" && order != "")
		{
			window.location.href = url + "&sort_by=" + field + "+" + order;
		}
		else
		{
			window.location.href = url;
		}
	}
	else
	{
		return false;
	}
}
