<%@ page import="jet.cs.util.*, jet.server.api.http.*, jet.web.dhtml.*,jet.server.api.*, jet.server.jrc.*, jet.server.jrserver.*, java.util.*, java.io.*, jet.server.util.ServerUtil" %>
<%@ page errorPage="errorpage.jsp" %>
<%@ include file="AuthCheck.jsp" %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<%
	  Hashtable param = HttpUtil.getParameters(request);
	  String name = (String)param.get("jrs.linkname");
    String query="";
    Enumeration keys=param.keys();
    while( keys.hasMoreElements()){
        String key =(String) keys.nextElement();
		    query+=("&"+key+"="+param.get(key));
    }
%>

<body onLoad="init('<%=name%>', '<%=query%>')" >
 <table width="100%"  border="0">
  <tr> <td align="left"> 
	<input name="EXIT" type="button" onClick="closeAll()" value="EXIT">
  </td>
  <tr>
    <td id="hyperscontainer" align="left"> 
    </td>
  </tr>
 </tr>
</table>

 <table width="100%" height="100%"  border="0">
   <tr>
     <td id="framecontainer" width="100%" align="left" valign="bottom">      
     </td>
   </tr>
 </table>
</body>
<SCRIPT TYPE="TEXT/JAVASCRIPT" LANGUAGE="JAVASCRIPT">
function init(name, qry){
    addLink( name);
    addFrame(qry);
}

function createSubReport(name, qry){
    hideCurrentFrame();
    addLink(name);
    addFrame(qry);
}


function drillup(index){
    removeFrame(index+1);
    remove(index+1);
    showFrame(index);
}


function addLink(name)
{
	var linkContainer = document.getElementById("hyperscontainer");
	var linkObjs= document.getElementsByTagName("A");
	var linkObj = document.createElement("A");
	linkObj.id="hyperlink"+linkObjs.length;
	linkObj.innerHTML = name;	
  linkObj.href = "javascript:"+"drillup("+linkObjs.length+")";
	

	//linkObj.index = linkObjs.length; 
	//linkObj.attachEvent("onclick", drillup);

	linkContainer.appendChild(linkObj);
	
	var labelObj=document.createElement("label");
	labelObj.innerHTML="->";

	linkContainer.appendChild(labelObj); 

}

function remove(from)
{
	var linkContainer = document.getElementById("hyperscontainer");
	var linkObjs = document.getElementsByTagName("A");
	while (linkObjs.length > from)	{
		linkContainer.removeChild(linkObjs[linkObjs.length-1]);
	}
	
	var lblObjs = document.getElementsByTagName("label");
	while (lblObjs.length > from)	{
		linkContainer.removeChild(lblObjs[lblObjs.length-1]);
	}
}

function hideCurrentFrame(){

    var frmObjs= document.getElementsByTagName("IFRAME");
    if( frmObjs.length >0){
      var framename = "frame"+(frmObjs.length-1);
      document.getElementById(framename).style.display = "none";
    }
}

function showFrame(index){
    
    document.getElementById("frame"+index).style.display = "block";
}

function addFrame(qry){
	var frmContainer = document.getElementById("framecontainer");
	var frmObjs= document.getElementsByTagName("IFRAME");
	var frmObj = document.createElement("IFRAME");
	frmObj.id="frame"+frmObjs.length;
	frmObj.height="100%";
	frmObj.width="100%";
	frmContainer.appendChild(frmObj);
	//frmObj.src="http://localhost:8888/dhtmljsp/dhtml.jsp?"+qry+"&jrs.report_id="+<%=request.hashCode()%>+"-"+frmObjs.length;
	frmObj.src="dhtml.jsp?"+qry+"&jrs.report_id="+<%=request.hashCode()%>+"-"+frmObjs.length;
}

function removeFrame(from){
	var frmContainer = document.getElementById("framecontainer");
	var frmObjs= document.getElementsByTagName("IFRAME");
	while (frmObjs.length > from)	{
		var frmObj = frmObjs[frmObjs.length-1];
    frmObj.src="removeReport.jsp?"+"&jrs.report_id="+<%=request.hashCode()%>+"-"+frmObjs.length;
		frmContainer.removeChild(frmObj);
	}
}
function closeAll(){
    var frmObjs= document.getElementsByTagName("IFRAME");
    window.location.href ="master_detail_closeall.jsp?jrs.report_id_prefix="+<%=request.hashCode()%>+"&jrs.num_of_opening_rpt="+frmObjs.length;
}

</SCRIPT>

</html>

