function openwindow(source_id,wheight,wwidth,notetext){

// When generating the new window, we eliminate timing problems
//  by writing the various documents literally instead of referring
//  to other files.
 
  using_css = (source_id.firstChild.className == 'rules');

  w2=open("", "", "height="+(wheight+60)+",width="+
               wwidth+",resizable,top=50,left=50,status=yes");
  with (w2.document){
     open();
     write('<html><head><title>Example Window</title></head>'+
      '<frameset rows="*,58" frameborder="no" scrolling="no" '+
      '    framespacing="0" border="0">'+
      '<frame name="ex" marginheight="4" marginwidth="6" />'+
      '<frame name="exnote" marginheight="0" '+
      'marginwidth="4"/></frameset></html>');
     close();
     }
  with (w2.document.frames[0].document){
     open()
     write('<html><head>');
     write('</head><body></body>');
     close();
     }
  with (w2.document.frames[1].document){
     open()
     write('<html><head><link rel="stylesheet" type="text/css" '+
      'href="lesson.css" /><script language="JavaScript">'+
      'var count=30; var Id=0;function countdown(){ '+
      'if (--count==0) parent.close(); counter.innerHTML=count; '+
      '  Id = setTimeout("countdown()",1000); }'+
      'function keepopen(){clearTimeout(Id);}</script></head>'+
      '<body background="exnoteback.gif" margintop="2" onload="countdown()">'+
      '<table cellpadding="4" width="100%" cellspacing="0">'+
      '<tr><td valign="top" class="exnote"><b>NOTE:</b></td>'+
      '<td valign="top"><div class="exnote" id="note">  </div></td>'+
      '<td width="80" align="center" style="font-size:60%;font-weight:bold">'+
      'will close in<br /><span id="counter">20</span> seconds<br />'+
      '<a href="javascript:parent.close()">(close now)</a><br />'+
      '<a href="javascript:keepopen()">(keep open)</a></td></tr></table>'+
      '</body></html>');
     close();
     }
  if (source_id.lastChild.firstChild.tagName=="FORM"){
     var str=source_id.lastChild.firstChild.firstChild.innerHTML;
     notetext="This is the result of your changes.";
     }
  else
     var str=source_id.lastChild.innerHTML;
  while (str.indexOf('&lt;')>=0)
     str=str.replace("&lt;","<");
  while (str.indexOf('&gt;')>=0)
     str=str.replace("&gt;",">"); 
  with (w2.frames[0].document){
    clear();
    writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">');
    writeln('<html>\n<head>\n<title>Example Window</title>');
//    writeln('<link ref="stylesheet" type="text/css" ref="example.css">');
    if (using_css){
        writeln('<style type="text/css">\n<!--');
        writeln(source_id.firstChild.firstChild.innerText);
        writeln('-->\n</style>');
        };
    writeln('</head>\n<body>');
    writeln(str);
    writeln('</body>\n</html>');
    close();
    }
  w2.frames[1].document.all["note"].innerHTML=notetext;
}

function editexample(source_id){
    if (source_id.firstChild.className == 'rules'){
       str=source_id.firstChild.firstChild.innerText;
       if (str.indexOf('<TEXTAREA name') != 0){
          count=(str.split('\n')).length;
          str="<form><textarea name=\"t1\" rows=\""+count+"\" cols=\"63\">"+
                str+"</textarea></form>";
          source_id.firstChild.innerHTML=str;
          }
       }

    str=source_id.lastChild.innerHTML;
    if (str.indexOf('<TEXTAREA name') < 0){
       count=(str.split('\n')).length;
       str="<form><textarea name=\"t1\" rows=\""+count+"\" cols=\"64\">"+
             str+"</textarea></form>";
       source_id.lastChild.innerHTML=str;
      }
    }

function getlesson(keyword){
    with (parent.sframe){
       lesson.async=false;
       lesson.load("getmodule.cgi?"+keyword);
       XSLTarget.innerHTML=lesson.transformNode(format.XMLDocument);
//       document.all(document.all.length-4).className='btnenddm';
       document.all(document.all.length-1).className='btnenddm';
       showpage("?0");
       }
    }
       
function dim(d){
   d.className=d.className.replace(/hi/,"dm");
   }
function off(d){
   d.className=d.className.replace(/on/,"dm");
   }
function hilite(d){
   d.className=d.className.replace(/dm/,"hi");
   } 
function clickit(d){
   for (i=0;i<document.all.length;i++){
      off(document.all(i));
      dim(document.all(i));
      } 
   d.className=d.className.replace(/dm/,"on");
   }

function showpage(num){
    if (num.length==0)
       num="0";
    else
       num=num.substr(1);
    with (parent.pframe){
       var pageNode = format.XMLDocument.selectSingleNode("//xsl:template[@match='page']");
       pageNode.setAttribute('match',"page["+num+"]");
       XSLTarget.innerHTML=
            parent.sframe.lesson.transformNode(format.XMLDocument);
       pageNode.setAttribute('match',"page");
       }
    with (parent.tframe){
       var pageNode = format.XMLDocument.selectSingleNode("//xsl:template[@match='page']");
       pageNode.setAttribute('match',"page["+num+"]");
       XSLTarget.innerHTML=
           parent.sframe.lesson.transformNode(format.XMLDocument);
       pageNode.setAttribute('match',"page");
       }
    with (parent.sframe){
       if (document.all["topic"+(1+parseInt(num))]){
/*       for (ii=0;ii<20;ii++){
         if (document.all["topic"+ii])
          with (document.all["topic"+ii]){
             style.backgroundColor="transparent";
             }
         }
       with (document.all["topic"+(1+parseInt(num))]){
             style.backgroundColor="#FFFFCC";
             }
*/
       clickit(document.all["topic"+(1+parseInt(num))]);
       }
    }
    parent.pframe.focus();
    parent.pframe.scrollTo(0);
}

function forums(){
win = open("/wwwthreads/wwwthreads.php","","height=500,width=720,"+
       "resizable,toolbar=yes,location=no,top=60,left=55,scrollbars=yes");
}  
function chat(){
win = open("chat.html","","height=420,width=620,toolbar=no,location=no,"+
       "top=60,left=65,scrollbars=yes");
}
function admin(){
win = open("admin.cgi","","height=420,width=620,toolbar=no,location=no,"+
       "top=60,left=65,scrollbars=yes");
}
function help(){
/* win = open("tempnav.html","","height=420,width=620,toolbar=no,location=no,"+
       "top=60,left=65,scrollbars=yes"); */
   getlesson("0010");
}
function logout(){
  if (confirm(' Do you want to close the \n     Lesson window now? ')){
     parent.close()}}
function tempnav(){
win = open("tempnav.html","","height=420,width=620,toolbar=no,location=no,"+
       "top=60,left=65,scrollbars=yes");
}
function sforums(){
win = open("forum.html","","height=420,width=720,toolbar=no,location=no,"+
       "top=60,left=55,scrollbars=yes");
}  
function schat(){tempnav();}
function sadmin(){tempnav();}
function shelp(){tempnav();}
function slogout(){
  if (confirm(' Do you want to close the \nSample Lesson window now? ')){
     parent.close()}
}

