anchor.diff:                  }
   
   
  -                function convertParamToObject(params){
  +                function convertParamToObject(params) {
                       oConf = {};
                       var paramsStr = params.replace("?", "");
                       var kv = paramsStr.split("&");
  -                    for ( var i=0; i<kv.length; i++){
  +                    for (var i = 0; i < kv.length; i++) {
                           var kv2 = kv[i].split("=");
                           oConf[kv2[0]] = kv2[1];
                       }
  
positive.code:                 }
  
  
  
                  // initialze search example qTip with close button and proper positioning
                 	var bqDoc = '<h3 id="bqdoc">How to use batch search</h3>'
                 	
                 		+ '<div id="docTabs">'
                  	+ '<ul>'
                    	+ '<li><a href="#tabs-1">Interface</a></li>'
                    	+ '<li><a href="#tabs-2">Data fields</a></li>'
                  	+ '</ul>'
                  	+ '<div id="tabs-1">'
                  	+ '<p>Query keywords can be either datatype-specific ID or IMPC marker symbol.<p>'
        				+ '<p>Simply click on one of the radio buttons on the left (the<b> Datatype Input panel</b>) to choose the datatype you want to search for.'
        				+ '</p>'
        				+ '<p>The data fields for the chosen datatype will be shown dynamically on the right (the <b>Customized Output panel</b>) and can be added/removed using checkboxes.'
        				+ '<p>'
        				+ '<p>The sample of results (<b>maximum of 10 records</b>) will be updated automatically after checking checkboxes.'
        				+ '<p>'
                  	+ '</div>'
                  	+ '<div id="tabs-2">'
                  	+ '<p>The data fields in additional annotations of the customized output panel are based on their being annotated to a datatype of your search.</p>'
        				+ '<p>For example, an MP term is annotated to an IMPC gene via phenotypic observations or experiments.</p>'
        				+ '<p>A disease term (human disease) is annotated to an IMPC mouse phenotype via <a href="http://database.oxfordjournals.org/content/2013/bat025" target="_blank">Phenodigm</a>, which is a semantic approach to map between clinical features observed in humans and mouse phenotype annotations.</p>'
        				+ '<p>An HP term is mapped to an MP term using similar Phenodigm semantic approach.</p>' 
        				+ '<p><b>hasQc</b>: IMPC lines with phenotyping data that has been quality controlled by the IMPC Data Coordination Center</p>'
                  	+ '<p><b>p value</b>: statistical confidence that the result is not due to chance. Lower is more significant. IMPC significant threshold value is 0.0001.</p>'
        				+ '</div>'
                   	+ '</div>';
                 	
                  $("a#bqdoc").qtip({            	   
                     	hide: false,
          			content: {
          				text: bqDoc,
          				title: {'button': 'close'}
          			},		 	
         			 	style: {
         			 		classes: 'qtipimpc',	 		
         			        tip: {corner: 'center top'}
         			    },
         			    position: {my: 'left top',
         			    		   adjust: {x: 0, y: 0}
         			    },
         			 	show: {
         					event: 'click' //override the default mouseover
         				},
         				events: {
         			        show: function(event, api) {
         			        	$('div#docTabs').tabs();
         			         	$('ul.ui-tabs-nav li a').click(function(){
         	            	   		$('ul.ui-tabs-nav li a').css({'border-bottom':'none', 'background-color':'#F4F4F4', 'border':'none'});
         	            	   		$(this).css({'border':'1px solid #666', 'border-bottom':'1px solid white', 'background-color':'white', 'color':'#666'});
         	               		});
         	               
         	               		$('ul.ui-tabs-nav li:nth-child(1) a').click();  // activate this by default
         			        }
         			    }
                  });
                  
                  $( "#accordion" ).accordion();
                  
                  // reset to default when page loads
                  $('input#gene').prop("checked", true) // check datatyep ID as gene by default 
                  $('input#datatype').val("gene"); // default
                  //$('div#fullDump').html("<input type='checkbox' id='fulldata' name='fullDump' value='gene'>Export full IMPC dataset via GENE identifiers");
                  
                  
                  freezeDefaultCheckboxes(); // not doing this for now: allow default ones to be selectable
                  //chkboxAllert();  for now, don't want automatic resubmit each time a checkbox is clicked
                  var currDataType  = false;
                  
                  toggleAllFields();
                  
                  // fetch dynamic data fields as checkboxes
                  $('input.bq').click(function(){
                  	if ( $(this).is(':checked') ){
                  		
                  		currDataType = $(this).attr('id');
                  		
                  		var currDataType2 = currDataType.toUpperCase().replace("_"," ");
                  		
                  		// assign to hidden field in fileupload section
                  		$('input#datatype').val(currDataType);
                  		
                  		$('td.idnote').text($(this).attr("value"));
                  		//console.log($(this).attr('id'));
                  		var id = $(this).attr('id');
                  		//$('div#fullDump').html("<input type='checkbox' id='fulldata' name='fullDump' value='" + id + "'>" + "Export full IMPC dataset via " + currDataType2 + " identifiers");
                  		$('div#fullDump').html("Please refer to our FTP site");
                  		// load dataset fields for selected datatype Id
                  		$.ajax({
                          	url: baseUrl + '/batchquery2?core=' + currDataType,
                              success: function(htmlStr) {
                                  //console.log(htmlStr);
                              	$('div#fieldList').html(htmlStr);
                              	freezeDefaultCheckboxes();
                              	toggleAllFields();
                              	//chkboxAllert();
                              },
                              error: function() {
                                  window.alert('AJAX error trying to fetch data');
                              }
                          });
                  	} 
                  });
                  
                  $('textarea#pastedList').val(''); // reset
                  $('input#fileupload').val(''); // reset
                  $('input#fulldata').attr('checked', false); // reset
                  
              });
              
              function chkboxAllert() {
              	// resubmit automatically whenever checkbox is clicked
  	        	$("div.fl2").find("input[class!='default']").click(function(){
  	        		resubmit();
  	        	});
              }
              function freezeDefaultCheckboxes(){
              	$('input.frozen').click(function(){
          			return false;
          		})
              }
              
              function toggleAllFields(){
                  $('button#chkFields').click(function(){
                  	if ( $(this).hasClass('checkAll') ){
                  		$(this).removeClass('checkAll').html('Check all fields');
                  		$("div.fl2").find("input[type='checkbox']").prop('checked', false);
  		                $("div.fl2 input.default").prop('checked', true);
                  	}
                  	else {
                  		$(this).addClass('checkAll').html('Reset to default fields')
                  		$("div.fl2").find("input[type='checkbox']").prop('checked', true);
                  	}
                  	
                  	//resubmit();
              	});
              }
              
              function resubmit(){
              	$('div#accordion').find('form:visible').find("input[type='submit']").click();
              }
              
              function submitPastedList(){
  	           
              	refreshResult(); // refresh first
              	
              	if ( $('textarea#pastedList').val() == ''){
              		alert('Please submit at least one identifier (ID/marker symbol).');
              	}
              	else { 
              		var currDataType = $('input.bq:checked').attr('id');
              		idList = parsePastedList($('textarea#pastedList').val(), currDataType);
              		
              		if ( idList !== false ){
              			
              			var fllist = fetchSelectedFieldList();
  
              			console.log(fllist);
                       	var currDataType = $('input.bq:checked').attr('id');
                       	
                       	prepare_dataTable(fllist);
                       	
                       	var oConf = {};
                       	oConf.idlist = idList;
                       	oConf.fllist = fllist;
                       	oConf.corename = currDataType;
  
                       	fetchBatchQueryDataTable(oConf);
              		}
              	}
              	return false;
              }
              
              function refreshResult(){
              	$('div#infoBlock, div#errBlock, div#bqResult').html(''); // refresh first
  	            var sampleData = "<p><span id='sample'>Showing maximum of 10 records for how your data looks like.<br>For complete dataset of your search, please use export buttons.</span>";
              	$('div#infoBlock').html("Your datatype of search: " + $('input.bq:checked').attr('id').toUpperCase() + sampleData);
              }
              
              function uploadJqueryForm(){
              	
              	refreshResult(); // refresh first
              	
              	var currDataType = $('input.bq:checked').attr('id');
               	$('input#dtype').val(currDataType);
               	
              	if ( $('input#fileupload').val() == '' ){
              		alert("Please upload a file with a list of identifiers");
              	}
              	else {
  	               	$('#bqResult').html('');
  	               	
  	               	$("#ajaxForm").ajaxForm({
  	                	success:function(jsonStr) { 
  	                      	//$('#bqResult').html(idList);
  	                      	//console.log(jsonStr)
  	                      	var j = JSON.parse(jsonStr);
  
  	                      	if ( j.badIdList != ''){
  	                      		$('div#errBlock').html("UPLOAD ERROR: unprocessed identifier(s): " + j.badIdList).show();
  	                      	}
  	                      		
  	                		var fllist = fetchSelectedFieldList();
  	                     	prepare_dataTable(fllist);
  	                     	
  	                     	var oConf = {};
  	                     	oConf.idlist = j.goodIdList;
  	                     	oConf.fllist = fllist;
  	                     	oConf.corename = currDataType;
  	                     	
  	                     	fetchBatchQueryDataTable(oConf);
  	                 	},
  	                 	dataType:"text"
  	               	}).submit();
              	}
              	return false; // so that the form can only be submitted via ajax
              }
              
              function fetchFullDataset(){
              	
              	 if ( $('input#fulldata').is(':checked') ){
              		refreshResult(); // refresh first 
              		
              		var fllist = fetchSelectedFieldList();
                   	var currDataType = $('input.bq:checked').attr('id') == 'marker_symbol' ? 'gene' : $('input.bq:checked').attr('id');
                   	
                   	prepare_dataTable(fllist);
                   	
                   	var oConf = {};
                   	oConf.idlist = '*';
                   	oConf.fllist = fllist;
                   	oConf.corename = currDataType;
                   	
                   	fetchBatchQueryDataTable(oConf);
                   }
                   else {
                   	alert ("Please tick the checkbox to fetch the full dataset");
                   }
                   return false;
              }
              
              function fetchSelectedFieldList(){
              	var fllist = [];
              	$("div#fieldList input:checked").each(function(){
              		fllist.push($(this).val());
              	});
              	return fllist.join(",");
              }
              
              function prepare_dataTable(fllist){
              	
              	var flList = fllist.split(',');
              	
              	var th = '';
              	for ( var i=0; i<flList.length; i++){
              		th += "<th>" + flList[i] + "</th>";
              	}
              	
              	var tableHeader = "<thead>" + th + "</thead>";
              	var tableCols = flList.length;
              	
                  var dTable = $.fn.fetchEmptyTable(tableHeader, tableCols, "batchq");
                  
                  $('div#bqResult').append(dTable);
              }
              
              function parsePastedList(val, dataType){
              	val = val.trim();
              	var aVals = val.split(/\n|,|\t|\s+/);
              	var aVals2 = [];
              	for ( var i=0; i<aVals.length; i++){
              		if ( aVals[i] == "" ){
              			continue;
              		}
              		var oriId = aVals[i].trim();
              		var uppercaseId = aVals[i].toUpperCase().trim();
              		var errMsg = "ERROR - " + uppercaseId + " is not an expected " + dataType + " identifier. Please try changing the datatype input.";
              		
              		if ( dataType == 'disease' ){
              			if ( ! (uppercaseId.indexOf('OMIM') == 0 ||
              				 uppercaseId.indexOf('ORPHA') == 0 ||
              				 uppercaseId.indexOf('DECIPHER') == 0) ){
              			
                  			alert(errMsg);
                  			return false;
                  		}
              		}
              		else if ( dataType == 'gene' && uppercaseId.indexOf('MGI:') != 0 ){
              			alert(errMsg);
              			return false;
              		}
              		else if ( dataType == 'ensembl' && uppercaseId.indexOf('ENSMUSG') != 0 ){
              			alert(errMsg);
              			return false;
              		}
              		else if ( (dataType == 'mp' || dataType == 'ma' || dataType == 'hp' ) && uppercaseId.indexOf(dataType.toUpperCase()) !== 0 ){
              			
                  		alert(errMsg);
                  		return false;
              		}
              		var thisId = dataType=="human_marker_symbol" ? uppercaseId : oriId;
              		aVals2.push('"' + thisId + '"');
              	}
  
              	return aVals2.join(",");
          	}
          	
              function getUniqIdsStr(inputIdListStr) {
              	var ids = inputIdListStr.split(",");
              	return $.fn.getUnique(ids).join(",");
              }
              function getFirstTenUniqIdsStr(inputIdListStr) {
              	var ids = inputIdListStr.split(",");
              	return $.fn.getUnique(ids.slice(0,10)).join(",");
              }
              
              function fetchBatchQueryDataTable(oConf) {
  
              	// deals with duplicates and take a max of first 10 records to show the users
              	oConf.idlist = getFirstTenUniqIdsStr(getUniqIdsStr(oConf.idlist));
  	            //oConf.idlist = getUniqIdsStr(oConf.idlist);
  
              	//var aDataTblCols = [0,1,2,3,4,5];
                  var oTable = $('table#batchq').dataTable({
                      "bSort": false, // true is default
                      "processing": true,
                      "paging": false,
                      //"serverSide": false,  // do not want sorting to be processed from server, false by default
                      //"sDom": "<<'#exportSpinner'>l<f><'#tableTool'>r>tip",
  	                "sDom": "<<'#exportSpinner'>l<'#tableTool'>r>tip",
                      "sPaginationType": "bootstrap",
                      "searchHighlight": true,
                      "iDisplayLength": 50,
  
negative.code:                     ],*/
                      "fnDrawCallback": function (oSettings) {  // when dataTable is loaded
  
                          $('div#sec2').show();
  
                          document.getElementById('sec2').scrollIntoView(true); // scrolls to results when datatable loads
  
                          var endPoint = baseUrl + '/bqExport';
  
                          $('div#tableTool').html("<span id='expoWait'></span><form id='dnld' method='POST' action='" + endPoint + "'>"
                              + "<span class='export2'>Export full dataset as</span>"
                              + "<input name='coreName' value='' type='hidden' />"
                              + "<input name='fileType' value='' type='hidden' />"
                              + "<input name='gridFields' value='' type='hidden' />"
                              + "<input name='idList' value='' type='hidden' />"
                              + "<button class='tsv fa fa-download gridDump'>TSV</button>"
                              + " or<button class='xls fa fa-download gridDump'>XLS</button>"
                              + "</form>");
  
                          $('button.gridDump').click(function () {
  
                              var fllist = fetchSelectedFieldList();
                              var errMsg = 'AJAX error trying to export dataset';
                              var currDataType = $('input.bq:checked').attr('id');
                              var idList = null;
                              var fileType = $(this).hasClass('tsv') ? 'tsv' : 'xls';
  
                              var formId = $('div#accordion').find('form:visible').attr('id');
                              var isForm = false;
  
                              if (formId == 'ajaxForm') {
                                  isForm = true;
                                  $("#ajaxForm").ajaxForm({
                                      url: baseUrl + '/batchQuery?dataType=' + currDataType,
                                      success: function (jsonStr) {
                                          var j = JSON.parse(jsonStr);
                                          idList = j.goodIdList;
                                          doExport(currDataType, fileType, fllist, idList, isForm);
                                      },
                                      dataType: "text",
                                      type: 'POST',
                                  }).submit();
                              }
                              else if (formId == 'pastedIds') {
                                  idList = parsePastedList($('textarea#pastedList').val(), currDataType);
                                  doExport(currDataType, fileType, fllist, idList, isForm);
                              }
                              else {
                                  idList = '*';
                                  doExport(currDataType, fileType, fllist, idList, isForm);
                              }
  
                              if (formId == 'ajaxForm') {
                                  return false;
                              }
                          });
  
                          $('body').removeClass('footerToBottom');
                      },
                      "ajax": {
                          "url": baseUrl + "/dataTable_bq?",
                          "data": oConf,
                          "type": "POST",
                          "error": function () {
                              $('div.dataTables_processing').text("Failed to fetch your query: keyword not found");
                              $('td.dataTables_empty').text("");
                          }
                      }
                  });
              }
  
              function doExport(currDataType, fileType, fllist, idList, isForm, phenoSimilarity_id, phenoSimilarity_term,
                                wantHumanCurated_id, wantHumanCurated_term) {
  
                  // deals with duplicates
                  if (idList.split(",").length > 500) {
                      var isOk = window.confirm("Please be aware that you have submitted > 500 identifiers and it will take longer to download\n\nWould you like to proceed?");
                      if (!isOk) {
                          return false; // won't do the rest
                      }
                  }
  
                  idList = getUniqIdsStr(idList);
  
                  $("form#dnld input[name='coreName']").val(currDataType);
                  $("form#dnld input[name='fileType']").val(fileType);
                  $("form#dnld input[name='gridFields']").val(fllist);
                  $("form#dnld input[name='idList']").val(idList);
  
                  if (isForm) {
                      $('button').unbind('click');
                      $("form#dnld").submit();
                      /*
                      $('button.xls').click(function() {
                          // submit the form
                          $("form#dnld").ajaxSubmit();
                          // return false to prevent normal browser submit and page navigation
                          return false;
                      });*/
                  }
              }
  
  
              // submit query
  
  
          </script>
         
          <script type="text/javascript" src="${baseUrl}/js/vendor/jquery/jquery.form.js"></script>
          <script type='text/javascript' src='https://bartaz.github.io/sandbox.js/jquery.highlight.js'></script>  
          <script type='text/javascript'
                  src='https://cdn.datatables.net/plug-ins/f2c75b7247b/features/searchHighlight/dataTables.searchHighlight.min.js'></script>
          <script type='text/javascript' src='${baseUrl}/js/utils/tools.js'></script>  
  
      </jsp:attribute>
  