/*
	general definitions
*/

URL_BASE 	= new String;
URL_BASE 	= "/cadcbin/";
URL_HOST 	= new String;
URL_HOST 	= "";

windowName 	= new Array();
windowList 	= new Array();

/*
                CADC popup windows: help only for now
*/

function wCADC( name,url ) {		// root popup window
  var fullURL;
  var n = windowName.length ; var wn = name;
  var tmp, w, i, x, y;
  /* Must determine the full URL */
  if (url.indexOf('://') >= 0) { fullURL = url }	
  else { if (url.substr(0,1) == '/') { fullURL = URL_HOST + url }
  else { fullURL = URL_BASE + url }}
  x = 640; y = 320;			// Default size
  i = name.indexOf('_'); 
  if (i >= 0) { 		// e.g. Window_500x500
      wn = name.substr(0, i);
      tmp = name.substr(i+1);
      i = tmp.indexOf('x') ;
      if (i >= 0) { x =  Number(tmp.substr(0, i)); y = Number(tmp.substr(i+1)) }
      else { y = Number(tmp) }
  }
  if (wn == "") { wn = "W" + windowName.length; i = n }
  else for (i=0; i<n; i++) { 
      if (windowName[i] != wn) continue ;
      w = windowList[i]; 
      if (w.closed) w = 0; 
      break ;
  }
  if (w) {	// Window already exists
    if ((y > 100) && (y <= 640)) w.innerHeight = y ;
    if ((x > 100) && (x <= 640)) w.innerWidth  = x ;
    w = window.open(fullURL, wn) ;
  }
  else { 	// New window -- create it 
    tmp= 'scrollbars=yes,resizable=yes,toolbar=0,location=0,status=0,menubar=0';
    tmp = tmp + ',height=' + y ;
    tmp = tmp + ',width=' + x ;
    w = window.open(fullURL, wn, tmp) ;
    windowName[i] = wn; windowList[i] = w ;
  }
  w.focus();
}

/*
  Generic CADC archiveHelp popup
  
  a 	= archive name (e.g. FUSE, HST, GEMINI)
  d	= data descriptor
  l	= language (EN)
*/
 
function cadcHelp( a, d, l ) {
  if ( l == "" ) { l = "EN" }
  var w = wCADC('wHelp_700x320','cadc/cadcHelp.pl?archive='+a+'&attribute='+d+'&language='+l);
}


/*
  Generic CADC archiveHelp popup
  
  a 	= archive name (e.g. FUSE, HST, GEMINI)
  d	= data descriptor
*/
 
function cadcHelp( a, d ) {
  var l = "EN";
  var w = wCADC('wHelp_700x320','cadc/cadcHelp.pl?archive='+a+'&attribute='+d+'&language='+l);
}


/* 
  Original gsaHelp window
*/

function gsaHelp(q) {
  var w = wCADC('wHelp_700x320', 'gsaHelp.pl?'+q) ;
}


/*
  Open a window to display GSA weather images...
*/

function gsaEnv(q) {
  var w = wCADC('gsaEnv_800x640', 'gsa/wdbi.cgi/gsa/gsa_environment/more?data_superset_id='+q) ;
}


/*
  Open a window to display details for a GSA science dataset
*/

function gsaDetails(q) {
  if ( q != 'Select Dataset to View Details')
  { 
    var w = wCADC('gsaDetails_800x640', 'gsa/wdbi.cgi/gsa/gsa_science/more/'+q) ;
  }  
}

/*
    Check all checkboxes in the form my_form
*/
function CheckAll(my_form_checkbox)
{
    if (my_form_checkbox.length == null)
    {
        my_form_checkbox.checked = 1;
        return;
    }
    for (i = 0; i < my_form_checkbox.length; i++)
    {
        if (my_form_checkbox[i].checked == 0)
        {
            my_form_checkbox[i].checked = 1;
        }
    }
}
