/*
 Copyright INRA

 Sebastien.Carrere@toulouse.inra.fr
 Jerome.Gouzy@toulouse.inra.fr

 This software is a computer program whose purpose is to provide
 a code generator framework for BioMoby web-services.

 This software is governed by the CeCILL license under French law and
 abiding by the rules of distribution of free software.  You can  use,
 modify and/ or redistribute the software under the terms of the CeCILL
 license as circulated by CEA, CNRS and INRIA at the following URL
 "http://www.cecill.info".

 As a counterpart to the access to the source code and  rights to copy,
 modify and redistribute granted by the license, users are provided only
 with a limited warranty  and the software's author,  the holder of the
 economic rights,  and the successive licensors  have only  limited
 liability.

 In this respect, the user's attention is drawn to the risks associated
 with loading,  using,  modifying and/or developing or reproducing the
 software by the user in light of its specific status of free software,
 that may mean  that it is complicated to manipulate,  and  that  also
 therefore means  that it is reserved for developers  and  experienced
 professionals having in-depth computer knowledge. Users are therefore
 encouraged to load and test the software's suitability as regards their
 requirements in conditions enabling the security of their systems and/or
 data to be ensured and,  more generally, to use and operate it in the
 same conditions as regards security.

 The fact that you are presently reading this means that you have had
 knowledge of the CeCILL license and that you accept its terms.
*/
MAIN:
{
	function Load()
	{
    	var a_img = $$('img.expand');
		var a_all = $$('img.expand_all');
		var index = 0;
		//If you have no expand_all image or just one
		if (a_all.length<=1)
		{
			var a_o_ec = new Array();
			for (var i = index; i < a_img.length; i++)
			{
				var o_ec = new ExpandableClass(a_img[i]);
				a_o_ec.push(o_ec);
    			}
			if (a_all.length==1)
			{
				new LinkAllExpandClass(a_all[0],a_o_ec);
			}
		}
		//With many expand_all, we have to be carefull about which <div> elements we want to manage.
		//We assume that they are ordered, we "sort" by id
		else
		{
			for (var j = 0;j < a_all.length; j++)
			{
				var a_o_ec = new Array();
				var current = a_img[index].nextSibling.id;
				var str = current.sub(/_\d+/,"");
				var reg = new RegExp(str);
    				for (var i = index; i < a_img.length; i++)
    				{
					if (!reg.test(a_img[i].nextSibling.id))
					{
						break;
					}
					var o_ec = new ExpandableClass(a_img[i]);
					a_o_ec.push(o_ec);
        				index++;
    				}
				new LinkAllExpandClass(a_all[j],a_o_ec);
			}
		}
	
	    InitAutocomplete('ID_KNOWLEDGE_BP','KnowledgeBase_GetBiologicalProcessJSON','KnowledgeBase');
		InitAutocomplete('ID_KNOWLEDGE_CONDITION','KnowledgeBase_GetConditions','KnowledgeBase');
		
// 		new KnowledgeClass();
// 		InitTable();
		
	};
    	
	Event.observe(window, 'load', Load);
}

function InitAutocomplete(field_id,function_name,main_menu_name)
{
    if ($(field_id) == null)
    {
        return;
    }
	var o_ajax_data = new LipmAjaxDataClass();
	o_ajax_data.SubmitAjax('__wb_function=' + function_name +  '&__wb_main_menu=' + main_menu_name,function(response){
		var a_data = o_ajax_data.GetData();
		var o_data_source  = new YAHOO.widget.DS_JSArray( a_data );
		o_data_source.queryMatchContains = true;
		o_data_source.queryMatchCase =false;
		var o_auto_complete= new YAHOO.widget.AutoComplete($(field_id).down('input').identify(),$(field_id).down('div').identify(),o_data_source);
		o_auto_complete.maxResultsDisplayed = 20; 
	});
}

/*

=pod

=head1 NAME
 nc_knowledge.js - js for presenting knowledge data

=cut
*/

/*
=pod

=head1 SYNOPSIS

 KnowledgeClass

=cut
*/

/*
=pod

=head2 KnowledgeClass

 Title:     KnowledgeClass
 Usage:     var o_know=new KnowledgeClass();
 Constructor Args: none
 Globals:   none

=cut
*/

KnowledgeClass = Class.create( {
	initialize: function()
	{
		// 1- source de donnee
		//data_source               =new YAHOO.util.LocalDataSource($('table_sortable'));
		data_source               =new YAHOO.util.LocalDataSource(YAHOO.util.Dom.get("table_sortable"));
		data_source.responseType  = YAHOO.util.DataSource.TYPE_HTMLTABLE;
		data_source.responseSchema= {
		       fields     : [ "","Description", "Condition", "Factor",
		                      "Reference", "Confidence", "Date","delete"]
			};

// 		2- la description des colonnes
		var cols = [ { key: "", sortable: false },
					{ key: "Description", sortable: true },
					{ key: "Condition", sortable: true },
					{ key: "Factor", parser:"number", sortable: true },
					{ key: "Reference", sortable: true },
					{ key: "Confidence", parser:"number", sortable: true },
					{ key: "Date"},
					{ key: "delete", sortable: false },
					];

		// 2- le tableau
		var knowledge_dt = new YAHOO.widget.DataTable('div_table_sortable',cols,data_source);
	}
} );
// function InitTable()
// {
// 
// 
// 		
// 		1- source de donnee
// 		data_source               =new YAHOO.util.LocalDataSource($('table_sortable'));
// 		var data_source               =new YAHOO.util.DataSource(YAHOO.util.Dom.get("table_sortable"));
// 		data_source.responseType = YAHOO.util.DataSource.TYPE_HTMLTABLE;
// 		data_source.responseSchema= {
// 		       fields     : [ "","Description", "Condition", "Factor",
// 		                      "Reference", "Confidence", "Date","delete"]
// 			};
// // 
// // // 		2- la description des colonnes
// 		var cols = [ { key: "", sortable: false },
// 					{ key: "Description", sortable: true },
// 					{ key: "Condition", sortable: true },
// 					{ key: "Factor", parser:"number", sortable: true },
// 					{ key: "Reference", sortable: true },
// 					{ key: "Confidence", parser:"number", sortable: true },
// 					{ key: "Date"},
// 					{ key: "delete", sortable: false },
// 					];
// 
// 		// 2- le tableau
// 		var knowledge_dt = new YAHOO.widget.DataTable("div_table_sortable",cols,data_source,{caption:"Example: Progressively Enhanced Table from Markup",sortedBy:{key:"Factor",dir:"desc"}});
// 
// 		var knowledge_dt = new YAHOO.widget.DataTable();
// // 
// 
// }
