/*
 * jquery.iea-rms - IEA Study Data Repository JavaScript
 *
 * Copyright (c) 2008 IEA (iea.nl)
 *
 * $Date: 2008-04-01 00:21:25 -0500 (Wed, 06 Feb 2008) $
 * $Rev: 4663 $
 */
var __iea_rms_view_=new __iea_rms_view();
$(document).ready(function(){	
							//__iea_rms_view_ = new __iea_rms_view();
   						__iea_rms_view_.init();
   						DEBUG=true;
});

/*
 * __iea_rms_view .ctor
 */
function __iea_rms_view()
{
	this._state = new Object();
	this._selection=[];
	this._selectionc=[];
	this._falser=[];
	
	DEBUG = true;
	////$.log(this);
};
/*
 * initialize __iea_rms_view objec
 */
__iea_rms_view.prototype.init = function(){
	
	
	this._state["loaded"]=true;
	this._state["yearselected"]=false;
	this._state["yearid"]='';
	this._state["cntrytypeselected"]=false;
	this._state["formatselected"]=false;
	this._state["downloaditemselected"]=false;
	this._state["downloadnameisvalid"]=false;
	this._state["docuselected"]=false;
	
	var me=this;
	
	
	$("#msg").ajaxError(function(event, request, settings){
   $(this).append("<li>Error requesting page " + settings.url + "</li>");
 	});
 
	$("#navSearch").show();
	$("#navBasket").show();
	
	$("#IEA_RMS_VIEW_SearchTree").hide();
	$("#IEA_RMS_VIEW_Basket").hide();
	$("#IEA_RMS_VIEW_COUNTRY_FILETYPE_MATRIX").hide();
	$("#IEA_RMS_VIEW_COUNTRY_FILETYPE_MATRIX_HEADER").hide();
	$("#IEA_RMS_VIEW_DOCUMENTATION").hide();
	$("#IEA_RMS_VIEW_Format").hide();
	$("#IEA_RMS_DOWNLOADNAME").hide();
	$("#IEA_RMS_ADDTOBASKET").hide();
	$("#IEA_RMS_VIEW_Welcome").show();
	$("#IEA_RMS_selectionheader").hide();
	$("#IEA_RMS_scrollable").hide();
	$("#IEA_RMS_selectall").hide();

								   		
							$("#nav_main li").click(function(){
								   /*$(this).hide("slow");*/
								   $("#current").attr("id",$("#current").attr("class"));
								   $(this).attr("id","current");
							   
								   if($("#current").attr("class")=="navWelcome"){
								   		$("#IEA_RMS_VIEW_SearchTree").hide();
								   		$("#IEA_RMS_VIEW_Basket").hide();
								   		$("#IEA_RMS_VIEW_COUNTRY_FILETYPE_MATRIX").hide();
								   		$("#IEA_RMS_VIEW_COUNTRY_FILETYPE_MATRIX_HEADER").hide();
								   		$("#IEA_RMS_VIEW_DOCUMENTATION").hide();
								   		$("#IEA_RMS_VIEW_Format").hide();
								   		$("#IEA_RMS_DOWNLOADNAME").hide();
								   		$("#IEA_RMS_ADDTOBASKET").hide();
								   		$("#IEA_RMS_VIEW_Welcome").show();
								   		$("#IEA_RMS_selectionheader").hide();
								   		$("#IEA_RMS_scrollable").hide();
								   		$("#IEA_RMS_selectall").hide();
								   }
								   if($("#current").attr("class")=="navSearch"){
								   		
								   		$("#IEA_RMS_VIEW_Basket").hide();
								   		$("#IEA_RMS_VIEW_Welcome").hide();
								   		
								   		$("#IEA_RMS_VIEW_SearchTree").show();
								   		$("#IEA_RMS_selectionheader").hide();
								   		$("#IEA_RMS_VIEW_COUNTRY_FILETYPE_MATRIX").show();
								   		$("#IEA_RMS_VIEW_DOCUMENTATION").show();
								   		$("#IEA_RMS_VIEW_Format").show();
								   		$("#IEA_RMS_DOWNLOADNAME").show();
								   		$("#IEA_RMS_ADDTOBASKET").show();
								   		$("#IEA_RMS_scrollable").hide();
								   		$("#IEA_RMS_selectall").show();
								   		
								   		me.__iea_rms_m_enablesubm(false);
								   		me.__iea_rms_m_enableformat(false);
								   		me.__iea_rms_m_enabledocu(false);
								   		
								   }
								   if($("#current").attr("class")=="navBasket"){
								   		$("#IEA_RMS_VIEW_SearchTree").hide();
								   		$("#IEA_RMS_VIEW_COUNTRY_FILETYPE_MATRIX").hide();
								   		$("#IEA_RMS_VIEW_COUNTRY_FILETYPE_MATRIX_HEADER").hide();
								   		$("#IEA_RMS_VIEW_DOCUMENTATION").hide();
								   		$("#IEA_RMS_VIEW_Format").hide();
								   		$("#IEA_RMS_DOWNLOADNAME").hide();
								   		$("#IEA_RMS_ADDTOBASKET").hide();
								   		$("#IEA_RMS_VIEW_Welcome").hide();
								   		$("#IEA_RMS_VIEW_Basket").show();
								   		$("#IEA_RMS_selectionheader").hide();
								   		$("#IEA_RMS_scrollable").hide();
								   		$("#IEA_RMS_selectall").hide();
								   		me.__iea_rms_men_sb();
								   }
								   return true;
								 });
		
		/*$("#IEA_RMS_VIEW_SearchTree").treeview({
			toggle: function() {
				console.log("%s was toggled.", $(this).find(">span").text());
			}
		});*/
		
		$("#IEA_RMS_VIEW_SearchTree").treeview({persist: "location",animated: "fast",
		collapsed: true,unique: true});
	   
            
		           
}
//#MO added to click on Button
__iea_rms_view.prototype.__iea_rms_btn_v = function()
{
								$("#current").attr("id",$("#current").attr("class"));
							$("#navBasket").attr("id","current");

								   		$("#IEA_RMS_VIEW_SearchTree").hide();
								   		$("#IEA_RMS_VIEW_COUNTRY_FILETYPE_MATRIX").hide();
								   		$("#IEA_RMS_VIEW_COUNTRY_FILETYPE_MATRIX_HEADER").hide();
								   		$("#IEA_RMS_VIEW_DOCUMENTATION").hide();
								   		$("#IEA_RMS_VIEW_Format").hide();
								   		$("#IEA_RMS_DOWNLOADNAME").hide();
								   		$("#IEA_RMS_ADDTOBASKET").hide();
								   		$("#IEA_RMS_VIEW_Welcome").hide();
								   		$("#IEA_RMS_scrollable").hide();
								   		$("#IEA_RMS_VIEW_Basket").show();
								   		$("#IEA_RMS_selectionheader").hide();
							
								   		__iea_rms_view.prototype.__iea_rms_men_sb();	
}



/*
 * load basket - ajax: IEA_RMS_VIEW_Basket
 */
__iea_rms_view.prototype.__iea_rms_men_sb = function()
{
  	
  	//$("#IEA_RMS_BASKET").empty();
  	//$("#IEA_RMS_BASKET").load("/index/basket");
  	$("#IEA_RMS_VIEW_Basket").remove();
  	$("#IEA_RMS_VIEW_Progress_BASKET").show();
  	
  	$.ajax({
	   type: "POST",
	   url: "/index/xmlhttpbasket",
	   cache: false,
	   success:function(html){
								   	
								   	
								   	$("#IEA_RMS_BASKET").append(html);
								   	
								   	$("#IEA_RMS_VIEW_Progress_BASKET").hide();
							   		
							   		
							   		$("a.jTip")
									   .hover(function(){JT_show(this.href,this.id,this.name)},function(){$('#JT').remove()})
							           .click(function(){return false});	
							      $("#IEA_RMS_VIEW_Basket").show();  
							      
							      
							     /* if($("#IEA_RMS_VIEW_Basket tr").find("no items available"))
							      	__iea_rms_view_.__iea_rms_men_updateBaskettab($("#IEA_RMS_VIEW_Basket tr").length-2);
							      else
							      	__iea_rms_view_.__iea_rms_men_updateBaskettab($("#IEA_RMS_VIEW_Basket tr").length-1);
							        
							 			*/
							 			
							 			if($(".basketitems")){	
							 				__iea_rms_view_.__iea_rms_men_updateBaskettab($(".basketitems").length);
							 			}
							 			else{
							 				__iea_rms_view_.__iea_rms_men_updateBaskettab(0);
							 			}
							 	}
	 });
	 
  	//$("#IEA_RMS_BASKET").load("/index/basket", function(){
   		
 			
};


/*
 * load matrix - ajax: IEA_RMS_VIEW_COUNTRY_FILETYPE_MATRIX
 * @param idp     tx_IEA_RMS_year_id (mysql) 
 */
__iea_rms_view.prototype.__iea_rms_st_sm=function(idp, name){

//alert(name);

  var me=this;
  this._state["yearselected"]=true;
  
  idx=idp.indexOf('_');
	lastidx=idp.length;						
  this._state["yearid"]=escape(idp.substring(idx+1,lastidx));
  
 		//this.__iea_rms_m_enabledocu(this._state["yearselected"]);
 		
 			
  	$("#IEA_RMS_VIEW_COUNTRY_FILETYPE_MATRIX").remove();
  	$("#IEA_RMS_VIEW_COUNTRY_FILETYPE_MATRIX_HEADER").remove();
  	$("#IEA_RMS_VIEW_Format").remove();
  	$("#IEA_RMS_VIEW_DOCUMENTATION").remove();
  	$("#IEA_RMS_VIEW_selectionheader").remove();
  	
  	
  	$("#IEA_RMS_VIEW_selectionheader").show();
  	$("#IEA_RMS_VIEW_Progress_MATRIX").show();
  	$("#IEA_RMS_VIEW_COUNTRY_FILETYPE_MATRIX_HEADER").show();
  	$("#IEA_RMS_VIEW_Progress_FORMAT").show();
  	$("#IEA_RMS_VIEW_Progress_DOC").show();
  	$("#IEA_RMS_scrollable").show();
  	$("#IEA_RMS_selectionheader").show();
  	
 		$.ajax({
	   type: "GET",
	   data:{id:idp},
	   url: "/index/xmlhttpmatrix",
	   cache: true,
	   success:function(html){
								   									   	
					  $("#IEA_RMS_COUNTRY_FILETYPE_MATRIX").append(html);	
					  $("#IEA_RMS_VIEW_Progress_MATRIX").hide();
						$("#IEA_RMS_VIEW_COUNTRY_FILETYPE_MATRIX").show();
				}
	 });
	 
	 $.ajax({
	   type: "GET",
	   data:{id:idp},
	   url: "/index/xmlhttpformat",
	   cache: true,
	   success:function(html){
								   									   	
					  $("#IEA_RMS_FORMAT").append(html);	
					  $("#IEA_RMS_VIEW_Progress_FORMAT").hide();
   					me.__iea_rms_m_enableformat(false);
   					$("#IEA_RMS_VIEW_Format").show();
				}
	 });
 		
 	$.ajax({
	   type: "GET",
	   data:{id:idp},
	   url: "/index/xmlhttpdocum",
	   cache: true,
	   success:function(html){
								   									   	
					  $("#IEA_RMS_DOCUMENTATION").append(html);	
					  $("#IEA_RMS_VIEW_Progress_DOC").hide();
			   		me.__iea_rms_m_enabledocu(true);
			   		$("#IEA_RMS_VIEW_DOCUMENTATION").show();
				}
	 });
 	$.ajax({
	   type: "GET",
	   data:{id:idp},
	   url: "/index/xmlhttphead",
	   cache: true,
	   success:function(html){
								   									   	
					  $("#IEA_RMS_selectionheader").append(html);	
					  $("#IEA_RMS_VIEW_Progress_MATRIX").hide();
			   		me.__iea_rms_m_enabledocu(true);
			   		$("#IEA_RMS_VIEW_selectionheader").show();
				}
	 });	
	  $.ajax({
	   type: "GET",
	   data:{id:idp},
	   url: "/index/xmlhttpmatrixhead",
	   cache: true,
	   success:function(html){
								   									   	
					  $("#IEA_RMS_COUNTRY_FILETYPE_MATRIX_HEADER").append(html);	
					  $("#IEA_RMS_VIEW_Progress_MATRIX").hide();
			   		me.__iea_rms_m_enabledocu(true);
			   		$("#IEA_RMS_COUNTRY_FILETYPE_MATRIX_HEADER").show();
				}
	 });	
 		
 		$("input").attr("value", "");
 		$("#IEA_RMS_Exclamation").hide();
 		this.__iea_rms_m_enablesubm(false);
					
					
 		
 
};


/*
 * toggle all check boxes of a matrix column
 * @param type     tx_IEA_RMS_type_id(mysql) 
 */
__iea_rms_view.prototype.__iea_rms_m_td =function (type){
	
	todo = true
	i = 0;
	while(this._falser[i] != null)
	{
	if(this._falser[i] == type)
	{
	
	todo = false;
	this._falser.shift();
	
	} 
	i++;	
	}
	//search for all checkboxes which ends with number:type
	$("input[id$='"+type+"']").each(
				function()
				{
					//#MO before he should check he should enable the format field
					__iea_rms_view.prototype.__iea_rms_m_enableformat(true);
					if(this.disabled==false)
						this.checked = todo;
						
					
					
					
				}
			);
			if(todo == true){
			this._falser.push(type);
			}
			__iea_rms_view_.__iea_rms_m_setitemselectionstate();
			
};

/*
 * toggle all check boxes of a matrix row (country)
 * @param cntry     tx_IEA_RMS_country_id(mysql) 
 */
__iea_rms_view.prototype.__iea_rms_m_tr=function(cntry){
	
	todo = true
	i = 0;
	while(this._falser[i] != null)
	{
	if(this._falser[i] == cntry)
	{
	
	todo = false;
	this._falser.shift();
	
	} 
	i++;	
	}
	
	//search for all checkboxes for the country with id:cntry
	$('#'+cntry).siblings("td >input[@type=checkbox]").children().each(
				function()
				{
					if(this.disabled==false)
						this.checked = todo;
				}
			);
						if(todo == true){
			this._falser.push(cntry);
			}
			__iea_rms_view_.__iea_rms_m_setitemselectionstate();
};

/*
 * Select all or deselectall
 * @param type     tx_IEA_RMS_type_id(mysql) 
 */
__iea_rms_view.prototype.__iea_rms_m_sa =function (type){
	this._falser=[];
		var me=this;


		$("#IEA_RMS_COUNTRY_FILETYPE_MATRIX input").each(function(){
			if(this.disabled==false){
			this.checked=true;
		}
		});
	
			
			__iea_rms_view_.__iea_rms_m_setitemselectionstate();
			
			

			
};

__iea_rms_view.prototype.__iea_rms_m_da =function (type){
				this._falser=[];
		var me=this;

				$("#IEA_RMS_COUNTRY_FILETYPE_MATRIX input").each(function(){
			this.checked=false;
		});


		
			
			__iea_rms_view_.__iea_rms_m_setitemselectionstate();
			
};

/*
 * Select all or deselectall
 * @param type     tx_IEA_RMS_type_id(mysql) 
 */
__iea_rms_view.prototype.__iea_rms_m_sa_docu =function (type){
	this._falser=[];
		var me=this;
	//search for all checkboxes which ends with number:type


$("#IEA_RMS_DOCUMENTATION input").attr("checked", "checked");

	
			
			__iea_rms_view_.__iea_rms_m_setitemselectionstate();
			
};
__iea_rms_view.prototype.__iea_rms_m_da_docu =function (type){
	this._falser=[];
		var me=this;
	//search for all checkboxes which ends with number:type


		$("#IEA_RMS_DOCUMENTATION input").each(function(){
			this.checked=false;
		});
		
			
			__iea_rms_view_.__iea_rms_m_setitemselectionstate();
			
};
/*
 * Select all or deselectall
 * @param type     tx_IEA_RMS_type_id(mysql) 
 */
__iea_rms_view.prototype.__iea_rms_m_sa_form =function (type){
	this._falser=[];
		var me=this;
	//search for all checkboxes which ends with number:type


$("#IEA_RMS_FORMAT input").attr("checked", "checked");

	
			
			__iea_rms_view_.__iea_rms_m_setitemselectionstate();
			
};
__iea_rms_view.prototype.__iea_rms_m_da_form =function (type){
	this._falser=[];
		var me=this;
	//search for all checkboxes which ends with number:type


		$("#IEA_RMS_FORMAT input").each(function(){
			this.checked=false;
		});
		
			
			__iea_rms_view_.__iea_rms_m_setitemselectionstate();
			
};



/*
 * validate download name
 * @param field     input text field id for the download name
 */
__iea_rms_view.prototype.__iea_rms_m_valid=function(field){

	var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
	var temp;
	
	if(field.val()=='') return false;
	
	for (var i=0; i<field.val().length; i++) {
		temp = "" + field.val().substring(i, i+1);
		////$.log('__iea_rms_m_valid: '+temp);
		if (valid.indexOf(temp) == "-1")return false;
	}
	
	return true;

};
/*
 * add user selection to basket: onClick event of IEA_RMS_ADDTOBASKET_BTN
 */
__iea_rms_view.prototype.__iea_rms_m_subm=function(){
	//DEBUG=true;
	var inputs = [];
	var i=1;
  var me=this;      	
         	if(!this.__iea_rms_m_valid($("#IEA_RMS_DOWNLOADNAME input"))){

         		$.post("/index/xmlhttpdownloadname",{name:$("#IEA_RMS_DOWNLOADNAME input").val(), suc:'false'}, function(html){
         			$("#IEA_RMS_Exclamation").remove();							   									   	
					  $("#IEA_RMS_DOWNLOADNAME").append(html);
					  	$("#IEA_RMS_Exclamation").show();	
			   		$("#IEA_RMS_VIEW_Downloadname").show();
				
         			});
 			         	
         		$("#IEA_RMS_Exclamation").css({ display:"inline"});

         		return false;
         	}
         	else{
      
               		$.post("/index/xmlhttpdownloadname",{name:$("#IEA_RMS_DOWNLOADNAME input").val(), suc:'true'}, function(html){
         			$("#IEA_RMS_Exclamation").remove();							   									   	
					  $("#IEA_RMS_DOWNLOADNAME").append(html);
					  	$("#IEA_RMS_Exclamation").show();	
			   		$("#IEA_RMS_VIEW_Downloadname").show();
				
         			});
      
         		$("#IEA_RMS_Exclamation").hide();
  
         		this._selection.push('_did='+ $("#IEA_RMS_DOWNLOADNAME input").val());
         		
         	}
         	
         	this._selection.push('_yid='+ this._state["yearid"]);
         	
         
          $("#IEA_RMS_VIEW_Progress").show();
          
          //////$.log(__iea_rms_view_._selection);
          
          
          $.post('/index/xmlhttpaddtobasket', this._selection.join('&'), function(data, textStatus){
				   		//$.log(data);
				   		__iea_rms_view_.__iea_rms_men_updateBaskettab(data);
				   		$("#IEA_RMS_VIEW_Progress").hide();
				   		me.__iea_rms_m_clearselection();
						  
				 		});
				 		
				 		
				 		
				 		return false;
};
/*
 * deletes selected basket item - ajax:
 * @param iid     tx_IEA_RMS_archive_id (mysql)
 */
__iea_rms_view.prototype.__iea_rms_men_deletebasketitem=function(iid){
	
	$.get("/index/xmlhttpdeletebasketitem",{id:iid}, function(){
   		$("#"+iid).remove();
   		__iea_rms_view.prototype.__iea_rms_men_updateBaskettab($(".basketitems").length);
 		});
	
	
}
/*
 * deletes all basket items - ajax:
 */
__iea_rms_view.prototype.__iea_rms_men_deleteallbasketitems=function(){
	
	//#MO written that just the selected will be deleted
		var iid;
	var me=this;
	
	$.post("/index/xmlhttpdeleteallbasketitems",__iea_rms_view_._selectionc.join('&'), function(){

   		$('#IEA_RMS_VIEW_Basket input[@type=checkbox]').each(
				function()
				{
					
						if(this.checked){
							idx=this.id.indexOf('_');
							lastidx=this.id.length;
							iid=this.id.substring(idx+1,lastidx);

							
						  $("#"+iid).remove();
						
						}
				}
			);
   		
   		
   		__iea_rms_view.prototype.__iea_rms_men_updateBaskettab($(".basketitems").length);
   		
 		});

	
	
}
/*
 * check/uncheck all basket checkboxes: IEA_RMS_VIEW_Basket
 * @param check     true/false
 */
__iea_rms_view.prototype.__iea_rms_men_checkbasketitems=function(check){
	var me=this;
	
 	$('#IEA_RMS_VIEW_Basket input[@type=checkbox]').each(
				function()
				{
				
						this.checked = check;
						me.__iea_rms_setitemselectionstate_basket();
				}
			);
		};
			//#MO added 
__iea_rms_view.prototype.__iea_rms_setitemselectionstate_basket=function(){
					var i=1;
         
   this._selectionc.length=0; 
   
   var me=this;
   
   var idx=-1;
   var lastidx=-1;
        
          $('#IEA_RMS_VIEW_Basket input[@type=checkbox]').each(function() {
            
						if(this.checked)
						{
								
								idx=this.id.indexOf('_');
								lastidx=this.id.length;
								me._selectionc.push('id'+ i + '=' + escape(this.id.substring(idx+1,lastidx)));
								i=i+1;
						}
            //
          });
	
         
				 		
				 		return false;
};
	
	

/*
 * updates basket menu tab
 * @param numberofitems     number of available basket items
 */
__iea_rms_view.prototype.__iea_rms_men_updateBaskettab=function(numberofitems){
	
	if(numberofitems==0)
		$("#abasket").text('Basket');
	else if(numberofitems==1)
		$("#abasket").text('Basket ('+ numberofitems + ' item)');
	else
		$("#abasket").text('Basket ('+ numberofitems + ' items)');
	
}
/*
 * sets overall selection state
 */
__iea_rms_view.prototype.__iea_rms_m_setitemselectionstate=function(){
	
	
	var i=1;
         	
   this._selection.length=0; 
   this._state["cntrytypeselected"]=false; 
   this._state["downloaditemselected"]=false;   
   this._state["formatselected"]=false; 
   this._state["docuselected"]=false; 
   var me=this;
   
   var idx=-1;
   var lastidx=-1;
   var typeid = 0
          $('#IEA_RMS_VIEW_COUNTRY_FILETYPE_MATRIX input').each(function() {
            
						if(this.checked)
						{
								me._state["cntrytypeselected"]=true;
								idx=this.id.indexOf('_');

								
								me._selection.push('_ct'+ i + '=' + escape(this.id.substring(0,idx)));
								i=i+1;
						}
						
            //
          });
          
          i=1;
          $('#IEA_RMS_VIEW_Format input').each(function() {
            
						if(this.checked)
						{
								me._state["formatselected"]=true;
								idx=this.id.indexOf('_');
								lastidx=this.id.length;
								me._selection.push('_datf'+ i + '=' + escape(this.id.substring(idx+1,lastidx)));
								i=i+1;
						}
            //
          });
          
          i=1;
          $('#IEA_RMS_VIEW_DOCUMENTATION input').each(function() {
            
						if(this.checked)
						{
								me._state["docuselected"]=true;
								idx=this.id.indexOf('_');
								lastidx=this.id.length;
								me._selection.push('_docf'+ i + '=' + escape(this.id.substring(idx+1,lastidx)));
								i=i+1;
						}
            //
          });
          
          
          if(me._selection.length>0)
							me._state["downloaditemselected"]=true;
					else
							me._state["downloaditemselected"]=false;
	/*$.log('cntrytypeselected: '+me._state["cntrytypeselected"]);
	$.log('downloaditemselected: '+me._state["downloaditemselected"]);
	$.log('formatselected: '+me._state["formatselected"]);
	$.log('yearselected: '+me._state["yearselected"]);*/
	
	me.__iea_rms_m_enablesubm((me._state["downloaditemselected"] & me._state["formatselected"])||this._state["docuselected"]);// 
	me.__iea_rms_m_enableformat(me._state["cntrytypeselected"]);
	me.__iea_rms_m_enabledocu(me._state["yearselected"]);
	
	//$.log(me._selection);
	
         
				 		
				 		return false;
};
/*
 * clears whole users selection
 */
__iea_rms_view.prototype.__iea_rms_m_clearselection=function(){
	//DEBUG=true;
	
				$('#IEA_RMS_VIEW_COUNTRY_FILETYPE_MATRIX input').each(function() {
            
						this.checked=false;
						
          })
          this._state["cntrytypeselected"]=false;
          this._state["downloaditemselected"]=false;
          this._state["formatselected"]=false;
          this._selection.length=0;
          
          this.__iea_rms_m_enablesubm(false);
					this.__iea_rms_m_enableformat(false);
					this.__iea_rms_m_enabledocu(false);
					$("#IEA_RMS_DOWNLOADNAME input").val('');
         
};

/*
 * controls enabled state of IEA_RMS_ADDTOBASKET_BTN Button
 * @param enable     true/false
 */
__iea_rms_view.prototype.__iea_rms_m_enablesubm=function(enable){
	//DEBUG=true;
	//$("#IEA_RMS_ADDTOBASKET_BTN").attr("disabled", "disabled");
	
	if(!enable){
		$("#IEA_RMS_ADDTOBASKET_BTN").attr("disabled", "disabled");
	}
	else{
		$("#IEA_RMS_ADDTOBASKET_BTN").removeAttr("disabled");
	}			 		
				 		return false;
};
/*
 * controls enabled state of IEA_RMS_VIEW_Format file format list
 * @param enable     true/false
 */
__iea_rms_view.prototype.__iea_rms_m_enableformat=function(enable){
	//DEBUG=true;
	//$.log('__iea_rms_m_enableformat: '+enable);
	if(!enable){
		$("#IEA_RMS_VIEW_Format input").each(function(){
			this.checked=false;
		});
		$("#IEA_RMS_VIEW_Format input").attr("disabled", "disabled");
	}
	else{
		$("#IEA_RMS_VIEW_Format input").removeAttr("disabled");
	}
	
				 		return false;
};
/*
 * controls enabled state of IEA_RMS_DOCUMENTATION documentation list
 * @param enable     true/false
 */
__iea_rms_view.prototype.__iea_rms_m_enabledocu=function(enable){
	//DEBUG=true;
	
	if(!enable){
		$("#IEA_RMS_DOCUMENTATION input").each(function(){
			this.checked=false;
		});
		$("#IEA_RMS_DOCUMENTATION input").attr("disabled", "disabled");
	}
	else{
		$("#IEA_RMS_DOCUMENTATION input").removeAttr("disabled");
	}
		
				 		return false;
};
/*
 * JTip
 * By Cody Lindley (http://www.codylindley.com)
 * Under an Attribution, Share Alike License
 * JTip is built on top of the very light weight jquery library.
 */

//on page load (as soon as its ready) call JT_init
$(document).ready(JT_init);

function JT_init(){
	//DEBUG=true;
	//$.log('init');
	       $("a.jTip")
		   .hover(function(){JT_show(this.href,this.id,this.name)},function(){$('#JT').remove()})
           .click(function(){return false});	   
}

function JT_show(url,linkId,title){
	
	//alert(url);
	//$.log(url);
	//$.log(linkId);
	//$.log(title);
	
	if(title == false)title="&nbsp;";
	var de = document.documentElement;
	var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var hasArea = w - getAbsoluteLeft(linkId);
	var clickElementy = getAbsoluteTop(linkId) - 3; //set y position
	
	
	
	var queryString = url.replace(/^[^\?]+\??/,'');
	var params = parseQuery( queryString );
	if(params['width'] === undefined){params['width'] = 250};
	if(params['link'] !== undefined){
	$('#' + linkId).bind('click',function(){window.location = params['link']});
	$('#' + linkId).css('cursor','pointer');
	}
	
	if(hasArea>((params['width']*1)+75)){
		$("body").append("<div id='JT' style='width:"+params['width']*1+"px'><div id='JT_arrow_left'></div><div id='JT_close_left'>"+title+"</div><div id='JT_copy'><div class='JT_loader'><div></div></div>");//right side
		var arrowOffset = getElementWidth(linkId) + 11;
		var clickElementx = getAbsoluteLeft(linkId) + arrowOffset; //set x position
	}else{
		$("body").append("<div id='JT' style='width:"+params['width']*1+"px'><div id='JT_arrow_right' style='left:"+((params['width']*1)+1)+"px'></div><div id='JT_close_right'>"+title+"</div><div id='JT_copy'><div class='JT_loader'><div></div></div>");//left side
		var clickElementx = getAbsoluteLeft(linkId) - ((params['width']*1) + 15); //set x position
	}
	
	
	$('#JT').css({left: clickElementx+"px", top: clickElementy+"px"});
	$('#JT').show();
	$('#JT_copy').load(url);

}

function getElementWidth(objectId) {
	x = document.getElementById(objectId);
	return x.offsetWidth;
}

function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	o = document.getElementById(objectId)
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	return oLeft
}

function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	return oTop
}

function parseQuery ( query ) {
   var Params = new Object ();
   if ( ! query ) return Params; // return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) continue;
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}

function blockEvents(evt) {
              if(evt.target){
              evt.preventDefault();
              }else{
              evt.returnValue = false;
              }
}


__iea_rms_view.prototype.__iea_rms_men_downloadallbasketitems=function(){
	


$('#IEA_RMS_VIEW_Basket input[@type=checkbox]').each(function()				
{	


if(this.checked){
//$("#IEA_RMS_VIEW_Progress_download").show();	
	window.open('index/download/id/'+this.id, this.id); 
	} });
	
	//$("#IEA_RMS_VIEW_Progress_download").hide();
}


