##-- General function to generate the statistic and config windows --##
sub build_statwin {
	my ($title,$columncount,$param_ref) = @_; 
	#-- Window wide variables --#
	my ($window,$table,$scrollwin);
	#-- Generate the window --#
	$window = new Gtk::Window("toplevel");
	$window->signal_connect("delete_event",sub{$window->destroy();});
	$window->title("-=[ " . $$title . " ]=-");
	$window->border_width(2);

	#-- Adding some scrollbars when the lowres parameter is yes in conffile --#
	if ($fromconf{lowres} =~ /yes/) {
 		$window->set_default_size(($fromconf{screenwidth} - 40),($fromconf{screenheight} - 60));
 		$scrollwin = new Gtk::ScrolledWindow("","");
 		$scrollwin->set_policy("automatic", "automatic");
 		$scrollwin->border_width(2);
 		$window->add($scrollwin); 
 		$scrollwin->show();
	}
	else {
		$window->set_default_size(225,undef);
	}

	#-- Declaration of some temporary vars used to create new stat frames & buttons	
	my ($tmplabel,$tmpframe);
	my $numofparameters = scalar keys %$param_ref;
	my $numtablerow = sprintf "%d",($numofparameters / $$columncount);

	if (($numofparameters % $$columncount) > 0) {
		$numtablerow = $numtablerow + 2;
	}
	else {
		$numtablerow = $numtablerow + 1;
	}

	#-- Create the placement table --#
	$table = new Gtk::Table($numtablerow,$$columncount,$false);

	#-- Add the frame to the scrollbar if lowres is yes, or add it to the window if not
	if ($fromconf{lowres} =~ /yes/) {
		$scrollwin->add_with_viewport($table);
	}
	else {
		$window->add ($table);
	}
	
    	my $cntcolumn = 0;
    	my $cntrow = 0;
	my $tmpcount = 0;
	
	foreach my $key (sort keys (%$param_ref)) {
	  $tmpframe = new Gtk::Frame();
	  $tmpframe->set_shadow_type('out');
  	$tmpcount ++;

 	 if ($cntcolumn == $$columncount) {
	  	  $cntcolumn = 0;
	  	  $cntrow++;
	 
	}
  	if ($cntrow == $numtablerow -2 && $tmpcount == $numofparameters) {

			if ($cntcolumn < $$columncount) {
				$table->attach_defaults($tmpframe,$cntcolumn,$$columncount ,$cntrow,$cntrow +1);
			}
			else {
			  $table->attach_defaults($tmpframe,$cntcolumn,$cntcolumn +1 ,$cntrow,$cntrow +1);
			}				
			
	}
	  #-- Place the table to the window --#
	  $table->attach_defaults($tmpframe,$cntcolumn,$cntcolumn +1 ,$cntrow,$cntrow +1);

	  #-- Make the label and place it into the table --#
	  my $tmplabel = new Gtk::Label ($key . "\n" .$param_ref->{$key});
	  $tmpframe->add($tmplabel);	  
	  $tmplabel->show;
	  $tmpframe->show();

	  $cntcolumn++;

	  #-- Add a time to update the label regulary by getting from the coresponding hash --#
  	my $timer = Gtk->timeout_add(1000,sub{$tmplabel->set_text($key . "\n" .$param_ref->{$key});return($true);});	  
	}

	#-- Build the close button --#
	my $buttonexit = new Gtk::Button( 'Close' );
	$buttonexit->signal_connect("clicked",sub{$window->destroy();});
	if ($fromconf{cisco} =~ /yes/) {
		$table->attach_defaults($buttonexit,$$columncount / 2,$fromconf{txcolumn} ,$numtablerow -1, $numtablerow);
	}
	else {
		$table->attach_defaults($buttonexit,0,$fromconf{txcolumn} ,$numtablerow -1, $numtablerow);
	}
	$buttonexit->show();
	$table->show();
	$window->show;
}		
