function X = database_DiPol_V2_load2html(X,varargin)
%DATABASE_DIPOL_V2_LOAD2HTML load data and make html per sample
%
%See also: xls2struct, database_DiPol_V2_load

%% Version <http://svnbook.red-bean.com/en/1.5/svn.advanced.props.special.keywords.html>
% $Id$
% $Date$
% $Author$
% $Revision$
% $HeadURL$
% $Keywords: $

OPT.Samples = 1;

OPT = setproperty(OPT,varargin);

disp(['... Please wait ', mfilename,' html-ifying '])

%% Samples html
if OPT.Samples
for i=1 :length(X.SamplesQuery.SampleId)

    html = ['<hr><table bgcolor="#333333" cellpadding="3" cellspacing="1"><tbody><tr><td colspan="2" bgcolor="#666666"><div style="color:#FFFFFF;">Samples</div></td></tr>'];

    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">Station                     </td><td bgcolor="#FFFFFF">',         X.SamplesQuery.Station{i}                      ,'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">Lat                         </td><td bgcolor="#FFFFFF">', num2str(X.SamplesQuery.Lat(i)                         ),'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">Lon                         </td><td bgcolor="#FFFFFF">', num2str(X.SamplesQuery.Lon(i)                         ),'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">LCS                         </td><td bgcolor="#FFFFFF">',         X.SamplesQuery.LCS{i}                          ,'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">SamplingStart               </td><td bgcolor="#FFFFFF">',         X.SamplesQuery.SamplingStart{i}                ,'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">SampleOriginType            </td><td bgcolor="#FFFFFF">',         X.SamplesQuery.SampleOriginType{i}             ,'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">SampleOriginSubType         </td><td bgcolor="#FFFFFF">',         X.SamplesQuery.SampleOriginSubType{i}          ,'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">Chemical Quality            </td><td bgcolor="#FFFFFF">', num2str(X.SamplesQuery.Chemical_Quality(i)            ),'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">Chemical/msPAF              </td><td bgcolor="#FFFFFF">', num2str(X.SamplesQuery.Chemical_msPAF(i)              ),'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">Chemical/msPAF-Metals       </td><td bgcolor="#FFFFFF">', num2str(X.SamplesQuery.Chemical_msPAF_Metals(i)       ),'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">Chemical/msPAF-PAHs         </td><td bgcolor="#FFFFFF">', num2str(X.SamplesQuery.Chemical_msPAF_PAHs(i)         ),'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">Chemical/msPAF-other        </td><td bgcolor="#FFFFFF">', num2str(X.SamplesQuery.Chemical_msPAF_other(i)        ),'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">Chemical/MaxValueVsWFD-EQS  </td><td bgcolor="#FFFFFF">', num2str(X.SamplesQuery.Chemical_MaxValueVsWFD_EQS(i)  ),'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">Chemical/TUmax-Algae        </td><td bgcolor="#FFFFFF">', num2str(X.SamplesQuery.Chemical_TUmax_Algae(i)        ),'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">Chemical/TUmax-Invertebrates</td><td bgcolor="#FFFFFF">', num2str(X.SamplesQuery.Chemical_TUmax_Invertebrates(i)),'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">Chemical/TUmax-Fish         </td><td bgcolor="#FFFFFF">', num2str(X.SamplesQuery.Chemical_TUmax_Fish(i)         ),'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">Toxicity                    </td><td bgcolor="#FFFFFF">', num2str(X.SamplesQuery.Toxicity(i)                    ),'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">EcologicalQuality           </td><td bgcolor="#FFFFFF">', num2str(X.SamplesQuery.EcologicalQuality(i)           ),'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">Pathogens-WaterQuality      </td><td bgcolor="#FFFFFF">', num2str(X.SamplesQuery.Pathogens_WaterQuality(i)      ),'</td></tr>']);
    html = strvcat(html,['<tr><td bgcolor="#FFFFFF">Pathogens-Bathing           </td><td bgcolor="#FFFFFF">', num2str(X.SamplesQuery.Pathogens_Bathing(i)           ),'</td></tr>']);
    
    html = strvcat(html,'</table>');

    X.SamplesQuery.Html{i} = html;

end
end

%% Stations html

for i=1:length(X.Stations.StationId)

   html = ['<hr><table bgcolor="#333333" cellpadding="3" cellspacing="1"><tbody><tr><td colspan="2" bgcolor="#666666"><div style="color:#FFFFFF;">Stations</div></td></tr>'];
   html = strvcat(html,['<tr><td bgcolor="#FFFFFF">name                        </td><td bgcolor="#FFFFFF">',X.Stations.StationName{i} ,'</td></tr>']);
   html = strvcat(html,['<tr><td bgcolor="#FFFFFF">longitude                   </td><td bgcolor="#FFFFFF">',num2str(X.Stations.Lon(i)),'</td></tr>']);
   html = strvcat(html,['<tr><td bgcolor="#FFFFFF">latitude                    </td><td bgcolor="#FFFFFF">',num2str(X.Stations.Lat(i)),'</td></tr>']);
   
   html = strvcat(html,'</table>');

   X.Stations.Html{i} = html;

end

%% Stations overview html

   html = ['<hr><table bgcolor="#333333" cellpadding="3" cellspacing="1"><tbody><tr><td colspan="2" bgcolor="#666666"><div style="color:#FFFFFF;">Stations</div></td></tr>'];
   for i=1:length(X.Stations.StationId);
   LCS = X.LCS.LCSName{X.Stations.LCSId(i)};
   html = strvcat(html,['<tr><td bgcolor="#FFFFFF">',LCS,'</td><td bgcolor="#FFFFFF">',...
                                                    X.Stations.StationName{i},'</td></tr>']);
   end   
   html = strvcat(html,'</table>');

   X.Stations.Html_overview = html;

%% Indicators html

for i=1:length(X.Indices.UpperLimit)

   html = ['<hr><table bgcolor="#333333" cellpadding="3" cellspacing="1"><tbody><tr><td colspan="2" bgcolor="#666666"><div style="color:#FFFFFF;">Integral parameters</div></td></tr>'];
   html = strvcat(html,['<tr><td bgcolor="#FFFFFF">Name        </td><td bgcolor="#FFFFFF">',num2str(X.Indices.Name       {i}),'</td></tr>']);
   html = strvcat(html,['<tr><td bgcolor="#FFFFFF">LowerLimit  </td><td bgcolor="#FFFFFF">',num2str(X.Indices.LowerLimit (i)),'</td></tr>']);
   html = strvcat(html,['<tr><td bgcolor="#FFFFFF">UpperLimit  </td><td bgcolor="#FFFFFF">',num2str(X.Indices.UpperLimit (i)),'</td></tr>']);
   html = strvcat(html,['<tr><td bgcolor="#FFFFFF">Description </td><td bgcolor="#FFFFFF">',num2str(X.Indices.Description{i}),'</td></tr>']);
   html = strvcat(html,'</table>');

   X.Indices.Html{i} = html;

end

%% Parameters html

for i=1:length(X.Parameters.ParameterId)
   html = ['<hr><table bgcolor="#333333" cellpadding="3" cellspacing="1"><tbody><tr><td colspan="2" bgcolor="#666666"><div style="color:#FFFFFF;">Integral parameters</div></td></tr>'];
   html = strvcat(html,['<tr><td bgcolor="#FFFFFF">ParameterLong   </td><td bgcolor="#FFFFFF">',        X.Parameters.ParameterLong{i}    ,'</td></tr>']);
   html = strvcat(html,['<tr><td bgcolor="#FFFFFF">ParameterShort  </td><td bgcolor="#FFFFFF">',        X.Parameters.ParameterShort{i}   ,'</td></tr>']);
   html = strvcat(html,['<tr><td bgcolor="#FFFFFF">ParameterUnit   </td><td bgcolor="#FFFFFF">',        X.Parameters.ParameterUnit{i}    ,'</td></tr>']);
   html = strvcat(html,['<tr><td bgcolor="#FFFFFF">CAS             </td><td bgcolor="#FFFFFF">',        X.Parameters.CAS{i}              ,'</td></tr>']);
   html = strvcat(html,['<tr><td bgcolor="#FFFFFF">WFD_EQS_Fresh   </td><td bgcolor="#FFFFFF">',num2str(X.Parameters.WFD_EQS_Fresh   (i)),'</td></tr>']);
   html = strvcat(html,['<tr><td bgcolor="#FFFFFF">WFD_EQS_Other   </td><td bgcolor="#FFFFFF">',num2str(X.Parameters.WFD_EQS_Other   (i)),'</td></tr>']);
   html = strvcat(html,['<tr><td bgcolor="#FFFFFF">LC50_Daphnia    </td><td bgcolor="#FFFFFF">',num2str(X.Parameters.LC50_Daphnia    (i)),'</td></tr>']);
   html = strvcat(html,['<tr><td bgcolor="#FFFFFF">LC50_Pimephales </td><td bgcolor="#FFFFFF">',num2str(X.Parameters.LC50_Pimephales (i)),'</td></tr>']);
   html = strvcat(html,['<tr><td bgcolor="#FFFFFF">LC50_Selenastrum</td><td bgcolor="#FFFFFF">',num2str(X.Parameters.LC50_Selenastrum(i)),'</td></tr>']);
   html = strvcat(html,'</table>');

   X.Parameters.Html{i} = html;

end
