﻿$(document).ready(function() {
	// show full thesaurus JS functionality
	$("li.thesaurus").show();
	$("li.thesaurus.no-script").hide();

	// handle click on thesaurus search button, or textfield.
	$("li.thesaurus a.btn-search, li.thesaurus input:text").click(function() {
		var $this = $(this);
		var textField = $this.parent().children("input:text");
		var hiddenField = $this.parent().children("input:hidden");
		if (textField == null || hiddenField == null) {
			alert("Could not find hidden and/or text field");
		}
		else {
			var url = "/helvetosaurus/index.html?k=0&textfield=" + textField.attr("id") + "&idfield=" + hiddenField.attr("id") + "&TB_iframe=true&width=700&height=540";
			tb_show(null, url);
		}
	});
	
	// handle click on thesaurus reset button
	$("li.thesaurus a.btn-clear").click(function(event) {
		event.preventDefault();
	
		var $this = $(this);
		var textField = $this.parent().children("input:text");
		var hiddenField = $this.parent().children("input:hidden");
		if (textField == null || hiddenField == null) {
			alert("Could not find hidden and/or text field");
		} 
		else {
			textField.val("");
			hiddenField.val("");
		}
	});
});

