function createWindowArray()
{
  var t1 = new Array();
  t1[0]  = 'messagewindow';
  t1[1]  = 'detailswindow';
  t1[2]  = 'indexwindow';
  t1[3]  = 'printwindow';
  t1[4]  = 'mainwindow';
  t1[5]  = 'topwindow';
  t1[6]  = 'bottomwindow';
  t1[7]  = 'searchwindow';
  t1[8]  = 'forummessagewindow';
  t1[9]  = 'groupdatawindow';
  t1[10] = 'tutordatawindow';
  t1[11] = 'ownsettingswindow';
  t1[12] = 'paragraph_language_window';


  var t2 = new Array();
  for(var i=0; i<t1.length; i++)
  {
    t2[t1[i]] = null;
  }

  if(typeof (top.frames['right'].wa) == "undefined")
  {
    top.frames['right'].wa = t2;
    top.frames['right'].wa_n = t1;
    top.frames['right'].wa_blank = new Array();
  }

}

function checkFrameStructure()
{
  if(opener)
  {
    while(opener.opener)
    {
      opener = opener.opener;
    }
  }

}

function closeWindowT() {
  if(!opener)
  {
    for(var i=0; i<top.frames['right'].wa_n.length; i++)
    {
    	try{top.frames['right'].wa[top.frames['right'].wa_n[i]].close(); } catch(err) {}
    }
  }
  else
  {
    while(opener.opener)
    {
      opener = opener.opener;
    }
    for(var i=0; i<opener.top.frames['right'].wa_n.length; i++)
    {
    	try{ opener.top.frames['right'].wa[opener.top.frames['right'].wa_n[i]].close(); } catch(err) {}
    }
  }

}

function openWindowT(name,URL,id,t,focus) {
  if(!opener)
  {
  	top.frames['right'].wa[name] = window.open(URL,name+id,t);
    if(focus == 1) { top.frames['right'].wa[name].focus(); }
    return top.frames['right'].wa[name];
  }
  else
  {
    if(opener.opener)
    {
      opener = opener.opener;
    }

    if(opener.top.frames['right'].wa[name] == null)
    {
    	opener.top.frames['right'].wa[name] = window.open(URL,name+id,t);
    }
    else
    {
      if(opener.top.frames['right'].wa[name].closed)
      {
      	opener.top.frames['right'].wa[name] = window.open(URL,name+id,t);
      }
      else
      {
        opener.top.frames['right'].wa[name].location = URL;
      }
    }
    if(focus == 1) { opener.top.frames['right'].wa[name].focus(); }
    return opener.top.frames['right'].wa[name];
  }
}

function openWindowBlankT(URL,t,focus) {
    var tmp = self.open(URL,'_blank',t);
    if(focus == 1) tmp.focus();
}



function refreshMain()
{
  while(opener.opener)
  {
    opener = opener.opener;
  }
  try { opener.top.frames['right'].wa['mainwindow'].location = 'serve.php4?command=' }
  catch(err) {}
}





function goError(msg)
{
  if(!opener)
  {
    self.location = 'error.php4?msg='+msg;
  }
  else
  {
    if(opener.opener)
    {
      opener = opener.opener;
    }
    opener.location = 'error.php4?msg='+msg;
  }
  closeWindowT();
}



function lib_bwcheck()
{
  this.ver    = navigator.appVersion
  this.agent  = navigator.userAgent
  this.dom    = document.getElementById?1:0
  this.opera5 = this.agent.indexOf("Opera 5")>-1
  this.ie5    = (this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
  this.ie6    = (this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
  this.ie4    = (document.all && !this.dom && !this.opera5)?1:0;
  this.ie     = this.ie4||this.ie5||this.ie6
  this.mac    = this.agent.indexOf("Mac")>-1
  this.ns6    = (this.dom && parseInt(this.ver) >= 5) ?1:0;
  this.ns4    = (document.layers && !this.dom)?1:0;
  this.ns     = this.ns4||this.ns6
  this.bw     = (this.ie||this.ns||this.opera5)
  return this
}

bw=new lib_bwcheck() //Browsercheck object

var ScreenWidth, ScreenTop, ScreenHeight, ScreenLeft, HalfScreen, wdiff, hdiff;

function getScreenSize()
{
  ScreenWidth  = screen.availWidth;
  ScreenHeight = screen.availHeight;

  if      (bw.ie)  { wdiff = 8; hdiff = 30; ScreenTop = 0 ;                        ScreenLeft = 0; }
  else if (bw.ns6) { wdiff = 4; hdiff = 28; ScreenTop = parseInt(screen.availTop); ScreenLeft = parseInt(screen.availLeft); }
  else if (bw.ns4) { wdiff = 8; hdiff = 30; ScreenTop = parseInt(screen.availTop); ScreenLeft = parseInt(screen.availLeft); }
  else             { wdiff = 8; hdiff = 30; ScreenTop = 0 ;                        ScreenLeft = 0; }

  HalfHeight   = Math.floor((ScreenHeight - ScreenTop) / 2);
}

function openOwnSettings(content,id)
{
  var f = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=0,left=0,width=788,height=480';
  openWindowT('ownsettingswindow',content,id,f,1);
}

function openGroupData(content,id)
{
  var f = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=100,left=100,width=500,height=400';
  openWindowT('groupdatawindow',content,id,f,1);
}

function openTutorData(content,id)
{
  var f = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=100,left=100,width=500,height=400';
  openWindowT('tutordatawindow',content,id,f,1);
}

function openForumMessages(content,id)
{
  var f = 'scrollbars=yes,status=no,resizable=yes,width=550,height=400';
  openWindowT('forummessagewindow',content,id,f,1);
}


function openCourseDetails(content,id)
{
  var f = 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,left=0,top=0,width=720,height=400';
  openWindowT('detailswindow',content,id,f,1);
}

function openMessage(content,id)
{
  var f = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=0,top=0,width=600,height=450';
  openWindowT('messagewindow',content,id,f,1);
}


function openIndex(content,id)
{
  var f = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=0,top=0,width=568,height=250';
  openWindowT('indexwindow',content,id,f,1);
}

function openPrint(content,id)
{
  var f = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=0,top=0,width=790,height=545';
  openWindowT('printwindow',content,id,f,1);
}

function openSearch(content,id)
{
  var f = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=0,top=0,width=620,height=545';
  openWindowT('searchwindow',content,id,f,1);
}

function openMain(content,id)
{
  getScreenSize();

  // main window size & oposition
  mw    = 800 - (wdiff + 4);
  mh    = ScreenHeight - hdiff;
  mt    = ScreenTop;
  ml    = ScreenLeft;

  var f = 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,left='+ml+',top='+mt+',width='+mw+',height='+mh;
  openWindowT('mainwindow',content,id,f,1);
}

function openTop(content,id)
{

  getScreenSize();

  if      (bw.ie)  { mainWidth = document.body.offsetWidth; }
  else if (bw.ns6) { mainWidth = document.body.offsetWidth + 20; }
  else if (bw.ns4) { mainWidth = window.width; }

  // top window size & oposition
  if(ScreenWidth > 1024){ tw    = ScreenWidth - 800 - wdiff; }
  else                  { tw    = 224 - wdiff; }
  th    = HalfHeight - hdiff;
  tt    = ScreenTop;
  if (mainWidth + wdiff + tw + wdiff > ScreenWidth) { tl = ScreenWidth - tw - wdiff; }
  else                                              { tl = mainWidth + wdiff; }

  var f = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left='+tl+',top='+tt+',width='+tw+',height='+th;
  openWindowT('topwindow',content,id,f,1);
}

function openTopBlank(content,id)
{
  var f = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=200,top=100,width=300,height=400';
  openWindowBlankT(content,f,1);
}


function openTopNoFocus(content,id)
{

  getScreenSize();

  if      (bw.ie)  { mainWidth = document.body.offsetWidth; }
  else if (bw.ns6) { mainWidth = document.body.offsetWidth + 20; }
  else if (bw.ns4) { mainWidth = window.width; }

  // top window size & oposition
  if(ScreenWidth > 1024){ tw    = ScreenWidth - 800 - wdiff; }
  else                  { tw    = 224 - wdiff; }
  th    = HalfHeight - hdiff;
  tt    = ScreenTop;
  if (mainWidth + wdiff + tw + wdiff > ScreenWidth) { tl = ScreenWidth - tw - wdiff; }
  else                                              { tl = mainWidth + wdiff; }

  var f = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left='+tl+',top='+tt+',width='+tw+',height='+th;
  openWindowT('topwindow',content,id,f,0);
}

function openBottom(content,id)
{
  getScreenSize();

  if      (bw.ie)  { mainWidth = document.body.offsetWidth; }
  else if (bw.ns6) { mainWidth = document.body.offsetWidth + 20; }
  else if (bw.ns4) { mainWidth = window.width; }

  // bottom window size & oposition
  if(ScreenWidth > 1024){ bw    = ScreenWidth - 800 - wdiff; }
  else                  { bw    = 224 - wdiff; }
  bh    = HalfHeight - hdiff;
  bt    = HalfHeight;
  if (mainWidth + wdiff + bw + wdiff > ScreenWidth) { bl = ScreenWidth - bw - wdiff; }
  else                                              { bl = mainWidth + wdiff; }

  var f = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left='+bl+',top='+bt+',width='+bw+',height='+bh;
  openWindowT('bottomwindow',content,id,f,1);
}

function openCourse(cm,ct,cb,id)
{

  getScreenSize();

  // main window size & oposition
  mw    = 800 - (wdiff + 4);
  mh    = ScreenHeight - hdiff;
  mt    = ScreenTop;
  ml    = ScreenLeft;

  // top window size & oposition
  if(ScreenWidth > 1024){ tw    = ScreenWidth - 800 - wdiff - 4; }
  else                  { tw    = 224 - wdiff - 4; }
  th    = HalfHeight - hdiff;
  tt    = ScreenTop;
  if (mw + (wdiff + 4) + tw + (wdiff + 4) > ScreenWidth) { tl = ScreenWidth - tw - (wdiff + 4); }
  else                                                   { tl = mw + (wdiff + 4); }

  // bottom window size & oposition
  if(ScreenWidth > 1024){ bw    = ScreenWidth - 800 - wdiff - 4; }
  else                  { bw    = 224 - wdiff - 4; }
  bh    = HalfHeight - hdiff;
  bt    = HalfHeight;
  if (mw + (wdiff + 4) + bw + (wdiff + 4) > ScreenWidth) { bl = ScreenWidth - bw - (wdiff + 4); }
  else                                                   { bl = mw + (wdiff + 4); }

  var f1 = 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,left='+ml+',top='+mt+',width='+mw+',height='+mh;
  var f2 = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left='+tl+',top='+tt+',width='+tw+',height='+th;
  var f3 = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left='+bl+',top='+bt+',width='+bw+',height='+bh;
  var t = openWindowT('mainwindow',cm,id,f1,1);
  openWindowT('topwindow',ct,id,f2,0);
  openWindowT('bottomwindow',cb,id,f3,0);

  t.focus();

}

function openParagraphLanguage(content,id)
{

  getScreenSize();

  // window size & oposition
  mw    = 800 - (wdiff + 4);
  mh    = (ScreenHeight - hdiff ) /3;
  mt    = ScreenTop + ((ScreenHeight - hdiff ) /3);
  ml    = ScreenLeft;

  var f1 = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left='+ml+',top='+mt+',width='+mw+',height='+mh;
  var t = openWindowT('paragraph_language_window',content,id,f1,1);
  t.focus();
}

                                                                
