w2v-server: handle empty word
diff --git a/templates/index.html.ep b/templates/index.html.ep
index d34f174..9656c56 100644
--- a/templates/index.html.ep
+++ b/templates/index.html.ep
@@ -32,6 +32,11 @@
 
 			 $(".selector").tabs({ active: 1 });
 
+		   $(function(){
+			   $("#SEARCH").click(function() {
+				   window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
+			   });
+		   });
 
 			 $('#firsttable').DataTable({
 				 "sScrollY": "780px",
@@ -69,9 +74,9 @@
 
 			 var collocatorData = <%= b(Mojo::JSON::to_json($collocators)) %>;
        var maxHeat; // = Math.max.apply(Math,collocatorData.map(function(o){return o.cprob;}))
-       maxHeat = Math.max.apply(Math,collocatorData.map(function(o){return Math.max.apply(Math,o.heat);}))
 
 			 if (collocatorData != null) {
+         maxHeat = Math.max.apply(Math,collocatorData.map(function(o){return Math.max.apply(Math,o.heat);}))
 				 var t = $('#secondtable').DataTable({
            data: collocatorData,
 					 "sScrollY": "800px",
@@ -134,12 +139,6 @@
 		 });
 
 		 $(function(){
-			 $("#SEARCH").click(function() {
-				 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
-			 });
-		 });
-
-		 $(function(){
 			 $("td.collocator").click(function(){
 				 queryKorAPCII(this.textContent + " /w5 " + urlParams.get('word'));
 			 });
@@ -752,41 +751,41 @@
 								 showMap(<%= b(Mojo::JSON::to_json({target => " $word ", mergedEnd=> $mergedEnd, words => \@words, vecs => \@vecs, ranks => \@ranks, marked => \@marked, urlprefix => $urlprefix})); %>);
 							 });
 							</script>
-            % } else {
-							<div id="wrapper">
-								<div id="not-found-dialog" title="Not found">
-									<p>ERROR: "<%= $word %>" not found in vocabluary.</p>
-									<p>If you are sure you have spelled the word as intended, you can try to increase the cutoff parameter in the options menu.</p>
-								</div>
-								<script>
-								 $( function() {
-									 $( "#not-found-dialog" ).dialog({
-										 autoOpen: true,
-										 modal: true,
-										 draggable: false,
-										 height: "auto",
-										 width: "auto",
-										 resizable: false,
-										 buttons: {
-											 "OK": function() {
-												 $( this ).dialog( "close" );
-											 },
-											 "Apply": function() {
-												 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
-											 }
+						  <div id="second">
+							  <div id="embed">
+							  </div>
+							  <div id="cost">
+							  </div>
+						  </div>
+					  </div>
+            % } elsif($word !~ /^\s*$/) {
+						<div id="wrapper">
+							<div id="not-found-dialog" title="Not found">
+								<p>ERROR: "<%= $word %>" not found in vocabluary.</p>
+								<p>If you are sure you have spelled the word as intended, you can try to increase the cutoff parameter in the options menu.</p>
+							</div>
+							<script>
+							 $( function() {
+								 $( "#not-found-dialog" ).dialog({
+									 autoOpen: true,
+									 modal: true,
+									 draggable: false,
+									 height: "auto",
+									 width: "auto",
+									 resizable: false,
+									 buttons: {
+										 "OK": function() {
+											 $( this ).dialog( "close" );
+										 },
+										 "Apply": function() {
+											 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
 										 }
-									 });
+									 }
 								 });
-								</script>
+							 });
+							</script>
 							</div>
 						% }
-						<div id="second">
-							<div id="embed">
-							</div>
-							<div id="cost">
-							</div>
-						</div>
-					  </div>
 				</div>
         <div id="tabs-2">
 					<div id="som2" style="width: 800; height: 800px">