
//
// Supposed to be defined:
//  Facets, RFacets  
//  Regions, RRegions  
//
//
//

var Regs = new Array;
var OK = new Array;

var RSels = new Array;  // List of mutually exclusive "region" selects
var FSels = new Array;  // List of Facets


AR_NS4 = (document.layers) ? true : false;

function runit()
{
  var ustr = 
	"http://cap-devel.jou.ufl.edu/cgi-bin/test2.cgi?action=query";

  ustr += collect_values(window.document.leftform.region);
  ustr += collect_values(window.document.leftform.facet);

  top.frames["right"].location = ustr;

}

function submit_link()
{
  document.bar.submit();
}


function test_url()
{
  var the_url = window.document.forms[0].url.value; 
  var new_window = open(the_url);
}


inact_cat_str = "This category is 'Inactive'.\nYou are welcome to investigate it,\nbut it is likely that there will be\nmuch less data collected here than under active categories.";

function inactive_cat_warn() {  alert(inact_cat_str); }

function inactive_cat_choice() { return(confirm(inact_cat_str)); };

var FEBUG = false;

function doody()
{ alert(document.headform.region.value) }


function big_doody(where)
{
  if (FEBUG) alert("In: ["+where+"]\nA:["+document.headform.action.value+"]\n"+"F:["+document.headform.facet.value+"]\n"+"R:["+document.headform.region.value+"]\n"+"Ra:["+document.headform.region_a.value+"]\n"+"Rb:["+document.headform.region_b.value+"]\n");
}

function hideit() {  } 


function fset_f(facet)
{
  big_doody("fset_f");

  document.headform.facet.value = facet;
  //  document.forms["foo"]["facet"].value = facet;
  // category_display_update(facet);
}

function fset_c(dcase)
{
  document.headform.dcase.value = dcase;
  big_doody("fset_c");
}

function fset_a(action)
{
  document.headform.action.value = action;
  big_doody("fset_a");
}

function fset_r(region)
{
  debugger
  document.headform.region.value = region;
  fset_r_a(region);
  big_doody("fset_r");
}

function fset_r_a(region)
{
  document.headform.region_a.value = region;
  big_doody("fset_r_a");
}

function fset_r_b(region)
{
  document.headform.region_b.value = region;
  big_doody("fset_r_b");
}


function fset_o(ordering)
{
  document.headform.ordering.value = ordering;
  big_doody("fset_o");
}

function fset_h(hint)
{
  document.headform.hint.value = hint;
  big_doody("fset_h["+hint+"]");
}


function fubmit_r(region)
{
  fset_r(region);
  big_doody("fubmit_r");
  document.headform.submit();
}


function fubmit_f(facet)
{
  fset_f(facet);
  big_doody("fubmit_f");
  document.headform.submit();
}

function fubmit_r_a(region)
{
  fset_r(region);
  big_doody("fubmit_r_a");
  document.headform.submit();
}

function fubmit_r_b(region)
{

  fset_r_b(region);
  big_doody("fubmit_r_b");
  document.headform.submit();
}

function fubmit(action)
{
  document.headform.action.value = action;
  document.headform.submit();
}

var FUB = false;

function maybe_just_fubmit(action)
{
  if (FUB) document.headform.submit();
}

function just_fubmit()
{
  big_doody("just_fubmit");
  document.headform.submit();
}

function fubmit_a(action)
{
  big_doody("fubmit_a ["+action+"]");
  document.headform.action.value = action;
  just_fubmit();
}

function fubmit_af(action,facet)
{
  document.headform.action.value = action;
  document.headform.facet.value  = facet;
  document.headform.submit();
}

function fubmit_ar(action,facet)
{
  document.headform.action.value = action;
  fset_r(region);
  document.headform.submit();
}

function fubmit_afr(action,facet,region)
{
  document.headform.action.value = action;
  document.headform.facet.value  = facet;
  fset_r(region);
  document.headform.submit();
}


function not_avail(hint,facet,region)
{

  window.open
    (
     '/index.cgi?action=notavailbox&facet='+facet+'&region='+region+'&hint='+hint,
     'Confirm',
     'toolbar=no,directories=no,status=no,menubar=no,copyhistory=no,width=500,height=170,left=100,top=100,location=no'
     );

}


function definition(facet)
{

  window.open
    (
     '/index.cgi?action=dynamicdefinitions&facet='+facet,
     'Definition',
     'toolbar=no,directories=no,status=no,menubar=no,copyhistory=no,width=500,height=150,left=100,top=100,location=no'
     );

}



function collect_values(dsel)
{
  var tstr = ""
  var tname = dsel.name
  for ( var i = 0; i < dsel.length; i++ )
  {
	if ( dsel[i].selected )
	{
	tstr +="&"+tname+"="+dsel[i].value
	}

  }

  return tstr;
}


DaRe = new RegExp("hide");

function hidem()
{
  ds = "";
  
  if ( AR_NS4 ) 
    {
      for ( i = 0; i < document.layers.length; i++)
	{
	  tl = document.layers[i];
	  ds = ds + "\n" + tl.name+ ": ";
	  if ( DaRe.test(tl.name) )
	    {  tl.visibility="hide"; 
	    ds = ds + " Hidden. "; 
	    }
	  
	}
      //alert (ds);
    }
  else
    {
      
      fookthis("hide","hidden");
      fookthis("hide_a","hidden");
      fookthis("hide_b","hidden");
      fookthis("hide_j","hidden");
      fookthis("hide_display","hidden");
    }
  
}


function showem()
{
  if (AR_NS4)
    {
      ds = "";
      for ( i = 0; i < document.layers.length; i++)
	{
	  tl = document.layers[i];
	  ds = ds + "\n" + tl.name+ ": ";
	  if ( DaRe.test(tl.name) )
	    {
	      tl.visibility="show";
	    ds = ds + " shown. "; 	      
	    }	
	}
      //alert (ds);  
    }
  else
    {

      fix_on();
     
      /*
      fookthis("hide","visible");
      fookthis("hide_a","visible");
      fookthis("hide_b","visible");
      fookthis("hide_display","visible");
      */

    }
  
}


function category_display_update(_f)
{
  _v = "Currently selected: '"+FLU[_f]+"'";
  if (AR_NS4)
    {
      document.layers.category_display.document.open();
      document.layers.category_display.document.write(_v);
      document.layers.category_display.document.close();
    }
  else
    {
      if ( document.all.category_display ) 
	{
	  document.all.category_display.innerHTML = _v;
	}

      if ( document.forms.display )
	{
	  if ( document.forms.display.facet )
	    {
	      document.forms.display.facet.selectedIndex = FLO[_f];
	    }
	}
    }
}


var WhereToLook = new Array();
WhereToLook[0] = "hide_a";
WhereToLook[1] = "hide_b";
WhereToLook[2] = "hide_c";
WhereToLook[3] = "hide_g";
WhereToLook[4] = "hide_h";
WhereToLook[5] = "hide_j";
WhereToLook[6] = "hide_t1";
WhereToLook[7] = "hide_t2";
WhereToLook[8] = "hide_t3";
WhereToLook[9] = "hide_t4";
// WhereToLook[4] = "hide";


var WhatsOff = new Array();

function walla()
{
  _str = "";

  for ( i = 0; i < WhatsOff.length ; i++)
    {
      _str = _str +"["+i+"]:"+WhatsOff[i]+"\n" ;
    }
  alert(_str);
 
}

function all_off()
{
  for ( i = 0; i < WhereToLook.length ; i++)
    {
      WhatsOff[i] = WhereToLook[i];
    }
}

function all_on()
{
  for ( i = 0; i < WhereToLook.length ; i++)
    {
      WhatsOff[i] = "";
    }
}


function  fookemalloff()
{
  all_off();
  fix_on();
}

function  fookemallon()
{
  all_on();
  fix_on();
}

function fix_on()
{
  //    walla();
  for ( i = 0; i < WhereToLook.length ; i++)
    {
      _on = true;
      for ( j = 0; j < WhatsOff.length ; j++)
	{
	  if (WhereToLook[i].search(WhatsOff[j]) >= 0 )
	    {
	      _on = false;
	    }
	}
      if (_on)
	{
	  fookthis(WhereToLook[i],"visible");
	  //alert("on: "+WhereToLook[i]);
	}
      else
	{
	  fookthis(WhereToLook[i],"hidden");
	  //alert("off: "+WhereToLook[i]);
	}
    }
}


function  fookthis(_t,_s)
{

  if ( eval ("document.all"))
    {
      if ( eval("document.all."+_t) )
	{
	  if (eval("document.all."+_t+".style"))
	    {
	      str = "document.all."+_t+".style.visibility = \""+_s+"\"";
	      eval(str);
	    }
	  else
	    {
	      max = eval("document.all."+_t+".length")
		for ( i = 0; i < max ; i++)
		  {
		    str = "document.all."+_t+"["+i+"].style.visibility = \""+_s+"\"";
		    eval(str);
		  }
	    }
	}
      else
	{
	  // alert("No "+_t);
	}
    }
  else
    {
      if ( document.getElementById(_t) )
	{
	  fooObj = document.getElementById(_t).style;      
	  fooObj.visibility=_s;
	}
    }


}

function some_off()
{
  WhatsOff = new Array();
  for (i=arguments.length-1;i>=0;i--)
    {
      WhatsOff[i]=arguments[i];
    }
  fix_on();
}


function visible_stateprinc()
{ some_off("hide_b","hide_c","hide_h","hide_j","hide_t2","hide_t3","hide_t4"); }

function visible_capsule()
{ some_off("hide_b","hide_h","hide_t1","hide_t3","hide_t4"); }

function visible_bycat()
{ some_off("hide_a","hide_b","hide_g","hide_t1","hide_t2","hide_t3"); }

function visible_compare()
{ some_off("hide_h","hide_t1","hide_t2","hide_t4"); } 


function assearch_opt(_trg)
{
  // alert("Setting to "+_trg);
  control.wq[_trg].checked = true;
  //  control.wq[_trg].Click();
}

function __foo()
{

for ( i=0; i < document.radio.wq.length ; i++ ) 
{
  _t0 =  document.radio.wq[i];
  if (_t0.value == document.headform.hint.value)
    {
      /* alert("YES!"+_t0.value + "=="+ document.headform.hint.value );     */
      _t0.click();
      _t0.checked = true;
    }
  else
    {
      /* alert(_t0.value + "!="+ document.headform.hint.value ); */
    }
}

}


