<%@ page language="java" import="java.util.*,java.sql.*,java.net.*,java.awt.*,java.awt.image.*,javax.swing.*,java.io.*"%>

<html>
<head>
<title>Energy Environment Information System</title>
<script LANGUAGE="JavaScript">
    function loadFrame(url,target) {	      
		  var  newWin=window.open(url,target); 		    
		    newWin.location.replace(url);
    } //function loadFrame(url,target)
</script>
</head>
<body BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#000000" VLINK="#000000" ALINK="#000000" LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">
<font FACE="Arial, Helvetica, sans-serif" SIZE="2"> 
<%!
 
	String mapURL="http://130.159.40.252:8000/eeis/maps/europe/europe.html";
    String[]  fuelTypeStrings = { "0 : Total","1 : Electricity(kWh)", "2 : Gas(kWh)", "3 : Oil"} ;
    String[]  fuelTypeCode   = {"0","1","2","3" };
    String[]  scopeNameSet = {"Residences","offices"};

    String[] years = {"1994","1995","1996","1997","1998","1999","2000"};
	String[] months = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep",
                    "Oct", "Nov","Dec" } ;
    String fuelType = "1";
    String scope = "Residences";
    String resultType = "";
    String fromMonth = "";
    String toMonth = "";
    String fromYear = "";
    String toYear = "";
%>
<jsp:useBean id="em" scope="session" class="EntrakMain"/>
<jsp:useBean id="mcpm" scope="session" class="MainControlPanel_Map"/>
<jsp:useBean id="egpm" scope="session" class="EmissionGasProfileManager2"/>
<%

        String actionButtonName = request.getParameter("action");

        try {
            
            mcpm.linkDatabase(new URL(mapURL));
			//mcpm.setDatabase( em.database );
			mcpm.setDatabase("strathclyde");
			
            ScopeFileManager sfm = new ScopeFileManager(mcpm.urlScope);
            sfm.readScopeFileWC();

            egpm.setConnection(mcpm.getConnection());
            egpm.setDatabase(mcpm.getDatabase());
			
            egpm.setUrlScope(mcpm.urlScope);
            egpm.setUrlEntrakHome(mcpm.getUrlEntrakHome());

            String clName = ClassLoaderName.getName(getClassLoader().toString());
			
            egpm.setClassLoaderName(clName);    //This is important for Web client!
            
            egpm.setup(); 			

            fuelTypeStrings = egpm.getFuelTypeStrings();
            fuelTypeCode = egpm.getFuelTypeCode();
            scopeNameSet = egpm.scopeNameSet;
            years = egpm.getYears();

            String[] yearsArray = egpm.getYears();

            if(yearsArray != null)
                years = yearsArray;

        } //try
        catch(MalformedURLException mue) {
        } //catch(MalformedURLException mue)

    if(actionButtonName != null) {
	
        fuelType = request.getParameter("fuelType");
		
        egpm.fuelTypePane.itemCombo.setSelectedItem(fuelType);
        int fuel = egpm.fuelTypePane.itemCombo.getSelectedIndex();
        String fuelString = String.valueOf(fuel);

        scope = request.getParameter("scope");
        egpm.selectSetPane.itemCombo.setSelectedItem(scope);

        fuelTypeStrings = egpm.getFuelTypeStrings();
        String itemTitle = new String( " " +fuelTypeStrings[ fuel ] +" in " + " \'" +
                     (String) egpm.selectSetPane.itemCombo.getSelectedItem() + 
					 "\' ");

        //egpm.resultTypePane.itemRadio[1].doClick();

        fromMonth = request.getParameter("fromMonth");
        toMonth = request.getParameter("toMonth");
        fromYear = request.getParameter("fromYear");
        toYear = request.getParameter("toYear");

        egpm.fromPane.combo[0].setSelectedItem(fromMonth);
        egpm.toPane.combo[0].setSelectedItem(toMonth);
        egpm.fromPane.combo[1].setSelectedItem(fromYear);
        egpm.toPane.combo[1].setSelectedItem(toYear);

        if (actionButtonName.equals("Profile")) {
            egpm.setFuelWC(fuel);
            egpm.setItemTitleWC(itemTitle);
%>
<script>     		  
			loadFrame("drawImgGasEmissions.jsp","imgFrame");
</script>
<%

        } //if (actionButtonName.equals("Profile"))
    } //if(actionButtonName != null)
	
    else {
%>
<script>
			loadFrame("blank.jsp","imgFrame");
</script>
<%
    } //else
%>
</font> <font FACE="Arial, Helvetica, sans-serif" SIZE="2"> 
<%

        Connection c = mcpm.getConnection();
        String us = mcpm.urlScope;
        String ueHome = mcpm.getUrlEntrakHome();

        if(c == null) {
%>
</font> <font FACE="Arial, Helvetica, sans-serif" SIZE="2"> Connection c is null. 
</font><font FACE="Arial, Helvetica, sans-serif" SIZE="2"> 
<%

        } //if(c == null)


        if(us == null) {
%>
</font> <font FACE="Arial, Helvetica, sans-serif" SIZE="2"> String us is null. 
</font><font FACE="Arial, Helvetica, sans-serif" SIZE="2"> 
<%

        } //if(us == null)


        if(ueHome == null) {
%>
</font> <font FACE="Arial, Helvetica, sans-serif" SIZE="2"> String ueHome is null. 
</font>
<%

        } //if(ueHome == null)


%>
<form METHOD="post">
  <table WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="100%">
	<tr>
	  <td ALIGN="CENTER" VALIGN="MIDDLE"> 
		<table WIDTH="80%" BORDER="0" VSPACE="5" HSPACE="5" CELLPADDING="2" BGCOLOR="#000000" ALIGN="CENTER">
		  <tr BGCOLOR="#999999"> 
			<td WIDTH="40%"><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">Scope:</font></td>
			<td WIDTH="60%"> <font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF"> 
			  <select NAME="scope" SIZE="1">
				<%
                        for(int i=0;i<scopeNameSet.length;i++) {

                            if(scopeNameSet[i].equals(scope)) {
                    %>
				<option selected><%=scopeNameSet[i]%></option>
				<%
                            } //if(scopeNameSet[i].equals(scope))

                            else {
                    %>
				<option><%=scopeNameSet[i]%></option>
				<%
                            } //else

                        } //for(int i=0;i<scopeNameSet.length;i++)
                    %>
			  </select>
			  </font></td>
		  </tr>
		  <tr BGCOLOR="#999999"> 
			<td WIDTH="40%"><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">Fuel 
			  type:</font></td>
			<td WIDTH="60%"> <font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF"> 
			  <select NAME="fuelType" SIZE="1">
				<%
                        for(int i=0;i<fuelTypeStrings.length;i++) {
                            if(fuelTypeStrings[i].equals(fuelType)) {

                    %>
				<option selected><%=fuelTypeStrings[i]%></option>
				<%

                            } //if(fuelTypeStrings[i].equals(fuelType))

                            else {
                    %>
				<option><%=fuelTypeStrings[i]%></option>
				<%
                            } //else
                        } //for(int i=0;i<fuelTypeStrings.length;i++)
                    %>
			  </select>
			  </font></td>
		  </tr>
		  <tr BGCOLOR="#999999"> 
			<td WIDTH="40%"><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF"> 
			  Duration: </font></td>
			<td WIDTH="60%"> <font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">From: 
			  <select NAME="select">
				<option SELECTED><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">1</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">2</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">3</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">4</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">5</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">6</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">7</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">8</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">9</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">10</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">11</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">12</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">13</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">14</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">15</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">16</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">17</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">18</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">19</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">20</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">21</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">22</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">23</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">24</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">25</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">26</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">27</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">28</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">29</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">30</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">31</font></option>
			  </select>
			  <select NAME="fromMonth" SIZE="1">
				<%
                                for(int i=0;i<months.length;i++) {

                                    if(months[i].equals(fromMonth)) {
                            %>
				<option selected><%=months[i]%></option>
				<%
                                    } //if(months[i].equals(fromMonth))
                                    else {
                            %>
				<option><%=months[i]%></option>
				<%
                                    } //else
                                } //for(int i=0;i<months.length;i++)
                            %>
			  </select>
			  <select NAME="fromYear" SIZE="1">
				<%
                                for(int i=0;i<years.length;i++) {
                                    if(years[i].equals(fromYear)) {
                            %>
				<option selected><%=years[i]%></option>
				<%
                                    } //if(years[i].equals(fromYear))
                                    else {
                            %>
				<option><%=years[i]%></option>
				<%
                                    } //else
                                } //for(int i=0;i<years.length;i++)
                            %>
			  </select>
			  To: 
			  <select NAME="select2">
				<option SELECTED><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">1</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">2</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">3</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">4</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">5</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">6</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">7</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">8</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">9</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">10</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">11</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">12</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">13</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">14</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">15</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">16</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">17</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">18</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">19</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">20</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">21</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">22</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">23</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">24</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">25</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">26</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">27</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">28</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">29</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">30</font></option>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">31</font></option>
			  </select>
			  <select NAME="toMonth" SIZE="1">
				<%
                                for(int i=0;i<months.length;i++) {

                                    if(months[i].equals(toMonth)) {
                            %>
				<option selected><%=months[i]%></option>
				<%
                                    } //if(months[i].equals(toMonth))
                                    else {
                            %>
				<option><%=months[i]%></option>
				<%
                                    } //else
                                } //for(int i=0;i<months.length;i++)
                            %>
			  </select>
			  <select NAME="toYear" SIZE="1">
				<%
                                for(int i=0;i<years.length;i++) {
                                    if(years[i].equals(toYear)) {
                            %>
				<option selected><%=years[i]%></option>
				<%
                                    } //if(years[i].equals(toYear))
                                    else {
                            %>
				<option><%=years[i]%></option>
				<%
                                    } //else
                                } //for(int i=0;i<years.length;i++)
                            %>
			  </select>
			  </font></td>
		  </tr>
		  <tr BGCOLOR="#999999"> 
			<td COLSPAN="2"> 
			  <center>
				<font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF"> 
				<input TYPE="submit" VALUE="Profile" NAME="action">
				</font> 
			  </center>
			</td>
		  </tr>
		</table>
	  </td>
	</tr>
  </table>
  </form>
</body>
</html>
