/*
Provides openwindow() function
*/

// This must be declared as a global
var winref=null;

/*
 null openwindow(string URL, [string paramlist], [boolean reuseflag])
 
 URL:
   Stored absolute or relative URI of page that is opened in the window

 paramlist (Optional):
   Parameter string that is passed to the window.open() function

 reuse (Optional):
   true  - If window is already open it used again (Default behaviour)
   false - A separate new window is always opened.

*/

function openwindow(URL,paramlist,reuse) {
  if (reuse==null) reuse = false;
  var day= new Date(); 
  var id = day.getTime(); 
  if (paramlist==null) paramlist ='top=10,left=10,width=800,height=610,resizeable=1,toolbar=0,location=0,status=0,menubar=0,scrollbars=0'
  if (!winref || !reuse) {
    winref=window.open(URL,id,paramlist);
        return(winref);
  }
  else {
    try {        //Catch any errors that may occur attempting to set the focus on the child window
      winref.location.href=URL;
      winref.focus();
    }catch(e) {                // If user closes the child window and we attempt to set the focus on it we simply call openwindow() again
      winref=null;
      openwindow(URL,paramlist);
    }
  }
}
