<%@ 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">

    //create a global variable so the window object can be accessed elsewhere

    function createWindow(url) {

        var winNum = self.opener.winNum;
        var imgWin = self.opener.imgWin[winNum];

        //if the window.name isn't set, create the window
        if(imgWin == null) {
            var targetWin = "ImageWindow_"+winNum.toString();
            imgWin = window.open(url,targetWin,'status=yes,top=20,left=20,dependent=yes,scrollbars=yes,resizable=no,width=400,height=400,menubar=no');
            //imgWin.location.replace(url);
            imgWin.location.reload();

            self.opener.imgWin[winNum] = imgWin;
            winNum++;
            self.opener.winNum = winNum;
        }//
        else {
            if(imgWin.name != null) {
                imgWin.focus();
            }
        }//else

    }//function createWindow(url)


    function loadFrame(url,target) {
       
	      
		  var  newWin=window.open(url,target); 		    
		    newWin.location.replace(url);
					
        //newWin.location.reload();

    } //function loadFrame(url,target)


</script>
<script LANGUAGE="JavaScript">
    function underConstruction( ) {
        window.alert("This option is now under construction : " );
    } //function underConstruction()
</script>
<script LANGUAGE="JavaScript">
    function message( message ) {
        window.alert( message);
    } //function underConstruction()
</script>
<script LANGUAGE="JavaScript">

    function runApp(url) {

        var newWin = window.open(url,"any");
        newWin.focus();

    } //function runApp(url)

</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://localhost:8000/smarthome/maps/europe/europe.html";
	
	String mapURL="http://peta-esru.mecheng.strath.ac.uk: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 = {"living_1"};

    String[] years = {"1994","1995","1996","1997","1998","1999","2000"};
    String fuelType = "1";
    String scope = "living_1";
    String resultType = "";
    String fromMonth = "";
    String toMonth = "";
    String fromYear = "";
    String toYear = "";

    String[] months = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep",
                    "Oct", "Nov","Dec" } ;

%>
<jsp:useBean id="em" scope="session" class="EntrakMain"/>
<jsp:useBean id="mcpm" scope="session" class="MainControlPanel_Map"/>
<jsp:useBean id="epm" scope="session" class="EnergyProfileManager"/>
<%

        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();

            epm.setConnection(mcpm.getConnection());
            epm.setDatabase(mcpm.getDatabase());
			// System.out.println("JSP_EPM, epm.database: " + mcpm.getDatabase());
			
            epm.setUrlScope(mcpm.urlScope);
            epm.setUrlEntrakHome(mcpm.getUrlEntrakHome());

            System.out.println("ConsumptionAnalysis, epm.urlEntrakHome: " + epm.getUrlEntrakHome());

            String clName = ClassLoaderName.getName(getClassLoader().toString());
			epm.setClassLoaderName(clName);    //This is important for Web client!
            
		    //System.out.println("EPM.jsp, " + epm.getClassLoaderName());
            epm.setup(); 
			
            fuelTypeStrings = epm.getFuelTypeStrings();
            fuelTypeCode = epm.getFuelTypeCode();
            scopeNameSet = epm.scopeNameSet;
            years = epm.getYears();

            String [] yearsArray = epm.getYears();

            if(yearsArray != null)
                years = yearsArray;

        } //try

        catch(MalformedURLException mue) {
              // System.out.println( mue.getMessage() );
        } //catch(MalformedURLException mue)

    if(actionButtonName != null) {

        fuelType = request.getParameter("fuelType");
		
        epm.fuelTypePane.itemCombo.setSelectedItem(fuelType);
        int fuel = epm.fuelTypePane.itemCombo.getSelectedIndex();
        String fuelString = String.valueOf(fuel);

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

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


        resultType = request.getParameter("resultType");

        if(resultType.equals("yearly")) {
            epm.resultTypePane.itemRadio[0].doClick();
            //epm.resultTypePane.itemRadio[0].setSelected(true);
            //epm.resultTypePane.itemRadio[1].setSelected(false);
        } //if(resultType.equals("yearly"))

        else {
            epm.resultTypePane.itemRadio[1].doClick();
            //epm.resultTypePane.itemRadio[1].setSelected(true);
            //epm.resultTypePane.itemRadio[0].setSelected(false);
        } //else

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

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

        if (actionButtonName.equals("Profile")) {

            System.out.println("JSPEnergyProfileManager.jsp, actionButtonName = Profile");
            epm.setFuelWC(fuel);
            epm.setItemTitleWC(itemTitle);

%>
<script>     		  
                loadFrame("drawImg.jsp","imgFrame");
            </script>
<%

        } //if (actionButtonName.equals("Profile"))


        else if (actionButtonName.equals("Individual Trend")) {

            boolean success = epm.processForLineChart(fuel,itemTitle);
            if(success) {

                JFrame frame = epm.getChartJFrame();

                if(frame!=null) {
                    File f = new File("/usr/java/j2sdkee1.2.1/public_html/eeis/frameObject");
					//File f = new File("c:\\j2sdkee1.2.1\\public_html\\eeis\\frameObject");
                    if(f.exists())
                        f.delete();
					System.out.println(" jsp energyprogfile : update 191:00");
					
                    ObjectReadWrite.write(f,frame);
					
%>
<script>					     					    
                        loadFrame("showApplet.jsp","imgFrame");
                    </script>
<%


                }//if(frame!=null)

                else {

                    System.out.println("JSP_EPM, frame = null");

                } //

            } //if(success)

            else {

                System.out.println("JSP_EPM, success = false");

            } //


        }//else if (actionButtonName.equals("Individual Trend"))


        else if (actionButtonName.equals("Table")) {

            boolean success = epm.processForTable(itemTitle);

            if(success) {

                MyTableModel tm = epm.getTm();

                if(tm!=null) {

                   File f = new File("/usr/java/j2sdkee1.2.1/public_html/eeis/tableObject");
				  // File f = new File("c:\\j2sdkee1.2.1\\public_html\\eeis\\tableObject"); //mstolinux
                    if(f.exists())
                        f.delete();
                    
					ObjectReadWrite.write( f,tm);	
					
                    System.out.println("EPM, written to tableObject");

%>
<script>
                     loadFrame("showApplet2.jsp","imgFrame");
                    </script>
<%

                }//if(table!=null)

                else {

                    System.out.println("JSP_EPM, Table, table = null");

                } //

            } //if(success)

            else {

                System.out.println("JSP_EPM, Table, success = false");

            } //


        }//else if (actionButtonName.equals("Table"))

        else { //actions for other buttons goes here
%>
<script>
                loadFrame("blank.jsp","imgFrame");				
            </script>
<%

        } //else

    } //if(actionButtonName != null)

    else {


%>
<script>
            loadFrame("blank.jsp","imgFrame");
            //underConstruction( " actionButtonName == null" )	;
        </script>
<%

    } //else



%>
<!--
<p>
        mapURL : <%=mapURL%>
</p>
-->
</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><font FACE="Arial, Helvetica, sans-serif" SIZE="2"> 
<%

        } //if(ueHome == null)


%>
</font> 
<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><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">Scope:</font></td>
			<td> <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><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">Fuel 
			  type:</font></td>
			<td> <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><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">Result 
			  type:</font></td>
			<td> <font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF"> 
			  <%
                    if(resultType.equals("yearly")) {
                %>
			  <input TYPE="radio" NAME="resultType" VALUE="yearly" CHECKED>
			  Yearly 
			  <input TYPE="radio" NAME="resultType" VALUE="monthly">
			  Monthly 
			  <%
                    } //if(resultType.equals("yearly"))

                    else {
                %>
			  <input TYPE="radio" NAME="resultType" VALUE="yearly">
			  Yearly 
			  <input TYPE="radio" NAME="resultType" VALUE="monthly" checked>
			  Monthly 
			  <%
                    } //else {
					
%>
			  </font></td>
		  </tr>
		  <tr BGCOLOR="#999999"> 
			<td><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF"> 
			  Duration: </font></td>
			<td> <font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF">From: 
			  <select NAME="selectasdasd">
				<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><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF"><%=months[i]%></font></option>
				<%
                                    } //if(months[i].equals(toMonth))
                                    else {
                            %>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF"><%=months[i]%></font></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><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF"><%=years[i]%></font></option>
				<%
                                    } //if(years[i].equals(toYear))
                                    else {
                            %>
				<option><font FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FFFFFF"><%=years[i]%></font></option>
				<%
                                    } //else
                                } //for(int i=0;i<years.length;i++)
                            %>
			  </select>
			  </font></td>
		  </tr>
		  <tr BGCOLOR="#999999"> 
			<td COLSPAN="2"> 
			  <center>
				<input TYPE="submit" VALUE="Profile" NAME="action">
				<input TYPE="submit" VALUE="Individual Trend" NAME="action">
				<input TYPE="submit" VALUE="Table" NAME="action">
			  </center>
			</td>
		  </tr>
		</table>
	  </td>
	</tr>
  </table>
</form>
</body>
</html>






