
// functions.js
// j. michael raymond

function toSplit(text,sep) {
   var chopd = text.split(sep);
   return chopd;
}

function newWin(path,config,w,h) {              
   // Configure new window (static display only)
   // Format for config is 'skmtl' etc; default for all options is off
   
  // HACK for not building this to utilize named windows
  if (config.indexOf(':') >0) {
      var nam = toSplit(config,':');
	  var config = nam[1];
  }
  
  else {
  // Get the page, window name
   var page = toSplit(path,"/");                
   var n    = page.length-1;                    
   var nam  = toSplit(page[n],".");    
  }
  
  // Configure width/height             
   var size = "width=" + w + ",height=" + h;    

  // Window options
   var winConfig;
   var opts  = new Array('S','M','D','T','L','K','R');   // references to properties
   var cntrl = toSplit("status menu directories toolbars location scrollbars resizable"," ");

  // properties for window are defined, now match options and turn on specific requests
  
   if (config != '') {
       var CNF = config.toUpperCase();            // make sure letters match
           for (i=0;i<cntrl.length;i++) {         
               cntrl[i]  += (CNF.indexOf(opts[i])>=0) ? '=yes' : '=no';
               winConfig += (i<opts.length -1) ? cntrl[i] + ',' : cntrl[i]; // add options

   // commas are placed between elements (no spaces) above, for every 
   // element execpt the last. The comma between config and width and 
   // height is generated further on by thisWin.

            }
    }

    else {       // no options defined; set all to no 
      
          for (i=0;i<cntrl.length;i++)
            winConfig += (i<opts.length -1) ? cntrl[i] + '=no,' : cntrl[i] + '=no'; 
       }        
    
  // Open new window
   var thisWin = window.open(path, nam[0], winConfig + ',' + size);
   thisWin.focus();

 }

