
<!-- Begin

//complete option list for three search boxes 
 
prod_all = new Array(
//  new Array("Reset","reset"),
new Array("GOES 4km IR","goes_ir"),
new Array("GOES 4km VIS","goes_vis"),
new Array("GOES 4km WV","goes_wv"),
new Array("Ocean Color","red_tide"),
new Array("Aqua SST","aquaSSTcomp"),
new Array("Terra SST","terraSSTcomp")
);


inst_all = new Array(
new Array("Reset","reset"),
new Array("Disasters","disasters"),
new Array("Ocean/Marine Environments","ocean"),
new Array("Weather","weather"));


plat_all = new Array(
new Array("Reset","reset"),
new Array("Hurricanes","hurricanes"),
new Array("Ocean Color","redtide"));

var prod_num=7;
var inst_num=4;
var plat_num=3;
var firstChoice=-1;
var secondChoice=-1;



//Main Lists: Change in one list will cause the changes in the other two lists

//complete option list for instrument, with respect to the options in Product box.
//in another words, when user select a perticular option in Product box, the corresponding
//instrument box should display one element of this array.

prod_i = new Array(
new Array(
new Array("Disasters","disasters"),
new Array("Weather","weather")),
new Array(
new Array("Disasters","disasters"),
new Array("Weather","weather")),
new Array(
new Array("Disasters","disasters"),
new Array("Weather","weather")),
new Array(
new Array("Ocean/Marine Environments","ocean"))
);



//complet list of Platform list, with respect to the options in Production box
prod_a = new Array(
new Array(
new Array("Hurricanes","hurricanes"),
new Array("Hurricanes","hurricanes")),
new Array(
new Array("Hurricanes","hurricanes"),
new Array("Hurricanes","hurricanes")),
new Array(
new Array("Hurricanes","hurricanes"),
new Array("Hurricanes","hurricanes")),
new Array(
new Array("Ocean Color","redtide"))
);



//complete list of production, with respect to the options in Instrument box
inst_r = new Array(
new Array(
new Array("GOES 4km IR","goes_ir"),
new Array("GOES 4km VIS","goes_vis"),
new Array("GOES 4km WV","goes_wv")),
new Array(
new Array("Ocean Color","red_tide")),
new Array(
new Array("GOES 4km IR","goes_ir"),
new Array("GOES 4km VIS","goes_vis"),
new Array("GOES 4km WV","goes_wv"))
);



//complete list of Platform, with respect to the options in Instrument box
inst_a = new Array(
new Array(
new Array("Hurricanes","hurricanes")),
new Array(
new Array("Ocean Color","redtide")),
new Array(
new Array("Hurricanes","hurricanes"))
);

//Complete list of Products, with respect to the options in Platform box
plat_r = new Array(
new Array(
new Array("GOES 4km IR","goes_ir"),
new Array("GOES 4km VIS","goes_vis"),
new Array("GOES 4km WV","goes_wv")),
new Array(
new Array("Ocean Color","red_tide"))
);

//Complete list of Instruments, with respect to the options in Platform box
plat_i = new Array(
new Array(
new Array("Disasters","disasters"),
new Array("Weather","weather")),
new Array(
new Array("Ocean/Marine Environments","ocean"))
);

//Secondary Lists: Change in one list caused the changes in the other two lists,
// and if one of these two lists gets changed again, it will only affect the other list,
// not the first list who got changed first.

//list of Platform, after Product got changed, followed by a change in Instrument
prod_ia = new Array(
new Array(
new Array(
new Array("Hurricanes","hurricanes")),
new Array(
new Array("Hurricanes","hurricanes"))
),
new Array(
new Array(
new Array("Hurricanes","hurricanes")),
new Array(
new Array("Hurricanes","hurricanes"))
),
new Array(
new Array(
new Array("Hurricanes","hurricanes")),
new Array(
new Array("Hurricanes","hurricanes"))
),
new Array(
new Array(
new Array("Ocean Color","redtide"))
)
);

//list of Instrument, after Product got changed, followed by change in Platform
prod_ai=new Array(
new Array(
new Array(
new Array("Disasters","disasters"),
new Array("Weather","weather"))
),
new Array(
new Array(
new Array("Disasters","disasters"),
new Array("Weather","weather"))
),
new Array(
new Array(
new Array("Disasters","disasters"),
new Array("Weather","weather"))
),
new Array(
new Array(
new Array("Ocean/Marine Environments","ocean"))
)
);

prod_ia=new Array(
new Array(
new Array(
new Array("Hurricanes","hurricanes")),
new Array(
new Array("Hurricanes","hurricanes"))
),
new Array(
new Array(
new Array("Hurricanes","hurricanes")),
new Array(
new Array("Hurricanes","hurricanes"))
),
new Array(
new Array(
new Array("Hurricanes","hurricanes")),
new Array(
new Array("Hurricanes","hurricanes"))
),
new Array(
new Array(
new Array("Ocean Color","redtide"))
)
);

//list of Product, after Inst got changed, followed by change in Platform
inst_ar = new Array(
new Array(
new Array(
new Array("GOES 4km IR","goes_ir"),
new Array("GOES 4km VIS","goes_vis"),
new Array("GOES 4km WV","goes_wv"))
),
new Array(
new Array(
new Array("Ocean Color","red_tide"))
),
new Array(
new Array(
new Array("GOES 4km IR","goes_ir"),
new Array("GOES 4km VIS","goes_vis"),
new Array("GOES 4km WV","goes_wv"))
)
);

//list of Platf, after Inst got changed, followed by change in Product
inst_ra = new Array(
new Array(
new Array(
new Array("Hurricanes","hurricanes")),
new Array(
new Array("Hurricanes","hurricanes")),
new Array(
new Array("Hurricanes","hurricanes"))
),
new Array(
new Array(
new Array("Ocean Color","redtide"))
),
new Array(
new Array(
new Array("Hurricanes","hurricanes")),
new Array(
new Array("Hurricanes","hurricanes")),
new Array(
new Array("Hurricanes","hurricanes"))
)
);

plat_ri=new Array(
new Array(
new Array(
new Array("Disasters","disasters"),
new Array("Weather","weather")),
new Array(
new Array("Disasters","disasters"),
new Array("Weather","weather")),
new Array(
new Array("Disasters","disasters"),
new Array("Weather","weather"))
),
new Array(
new Array(
new Array("Ocean/Marine Environments","ocean"))
)
);

plat_ir=new Array(
new Array(
new Array(
new Array("GOES 4km IR","goes_ir"),
new Array("GOES 4km VIS","goes_vis"),
new Array("GOES 4km WV","goes_wv")),
new Array(
new Array("GOES 4km IR","goes_ir"),
new Array("GOES 4km VIS","goes_vis"),
new Array("GOES 4km WV","goes_wv"))
),
new Array(
new Array(
new Array("Ocean Color","red_tide"))
)
);

//list of Production, after Instrument got changed, followed by change in Platform
//Not Applicable. Because no matter which Platform, the Product lists are the same.
//therefore, no need for secondary lists.

//list of Production, after Platform got changed, followed by change in Instrument
//Not Applicable. Because One Platform to One instrument, No secondary lists

//list of Instrument, after Platform got changed, followed by change in Product
//Not Applicable. Because One Platform to One instrument, No secondary lists

//list of Platform, after Instrument got changed, followed by change in Product
//Not Applicable. Becuase Once Instrument fixed, no matter which plaform, the product lists are the same

//When Adding a new product
//1. change the prod_all list, change inst_all list, change plat_all list.
//2. change the prod_i list, prod_a list, inst_r list, inst_a list, and plat_i list, plat_r list
//3. change the prod_ia list, prod_ai list ( if one product corresponds to two instruments, 
//      there will be two prod_ia lists. 
//4. check inst_ra, inst_ar, and plat_ri, plat_ir lists, to see if they exist. (if following rule holds,
//      these four lists will not exist: One platform corresponds to one instrument. One instrument
//      , no matter which platform, has the same product list.

function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
   var i, j;
   var prompt;
// empty existing items
   for (i = selectCtrl.options.length; i >= 0; i--) {
      selectCtrl.options[i] = null; 
   }
   prompt = (itemArray != null) ? goodPrompt : badPrompt;
   if (prompt == null) {
      j = 0;
   } else {
      selectCtrl.options[0] = new Option(prompt);
      j = 1;
   }
   if (itemArray != null) {
// add new items
      for (i = 0; i < itemArray.length; i++) {
         selectCtrl.options[j] = new Option(itemArray[i][0]);
         if (itemArray[i][1] != null) {
            selectCtrl.options[j].value = itemArray[i][1]; 
         }
         j++;
      }
// select first item (prompt) for sub list
      if(j==2) {
         selectCtrl.options[1].selected = true;
      } else {
         selectCtrl.options[0].selected = true;
      }
   }
}


function resetallfields(i) {
if(i==0){
   firstChoice=-1;
   secondChoice=-1;
}
if(i==0 || i==1) fillSelectFromArray(document.main.Product, prod_all,null,null);
if(i==0 || i==2) fillSelectFromArray(document.main.Inst, inst_all,null,null);
if(i==0 || i==3) fillSelectFromArray(document.main.Platf, plat_all,null,null);
}


function getURLArgs(caseBool)
{
  var casefree = ( (true == caseBool) || (caseBool >= 1)) ? true: false;
  var args  = new Object();
  var query = location.search.substring(1);

  var pairs = query.split("&");
  for(var i = 0; i< pairs.length; i++)
         {
                pairs[i]= unescape(pairs[i]);
                var pos=pairs[i].indexOf('=');
                if(-1 == pos) continue;
                var argname;
                if(true != casefree) { argname = pairs[i].substring(0,pos); }
                else { argname = pairs[i].substring(0,pos).toLowerCase(); }
                var value = pairs[i].substring(pos+1);
                args[argname] = value;
         }
  return args;
}

var URLargs = getURLArgs(true);

//prod=BTS&inst=ssmi&plat=dmspf14&sd=2003/04/27&ed=2003/05/08

var instselect="";
var platselect="";
var prodselect="";
var sdselect="";
var edselect="";

if (URLargs.prod) { prodselect = URLargs.prod;  }
if (URLargs.inst) { instselect = URLargs.inst;  }
if (URLargs.plat) { platselect = URLargs.plat;  }
if (URLargs.sd) { sdselect = URLargs.sd; }
if (URLargs.ed) { edselect = URLargs.ed; }

if (URLargs.product) { prodselect = URLargs.product; prodselect = prodselect.replace(/\%2F/g,"\/"); }
if (URLargs.inst) { instselect = URLargs.inst;  instselect = instselect.replace(/\%2F/g,"\/"); }
if (URLargs.platf) { platselect = URLargs.platf;  platselect = platselect.replace(/\%2F/g,"\/"); }
if (URLargs.start2) { sdselect = URLargs.start2; sdselect = sdselect.replace(/\%2F/g,"\/"); }
if (URLargs.end2) { edselect = URLargs.end2; edselect = edselect.replace(/\%2F/g,"\/"); }

function list_prod() {
document.write("<select name=Product class=smallblack id=Product onChange=\"");
document.write("var prodLength = this.form.Product.length;");
document.write("if(firstChoice == -1) firstChoice = 1;");
document.write("if(secondChoice== -1 && firstChoice != 1) secondChoice =1;");
document.write("if(firstChoice == 1) {");
document.write("   fillSelectFromArray(this.form.Inst, ((this.selectedIndex == 0 ) ? inst_all : prod_i[this.selectedIndex-1]),'Reset','Reset'); ");
document.write("   fillSelectFromArray(this.form.Platf, ((this.selectedIndex == 0 ) ? plat_all : prod_a[this.selectedIndex-1]),'Reset','Reset');");
document.write("   if(this.selectedIndex == 0 || this.options[this.selectedIndex].value == '   ') resetallfields(0);");

document.write("} else if(firstChoice == 2 && secondChoice == 1) {");
document.write("   if(this.selectedIndex == 0) {");
document.write("      resetallfields(0);");
document.write("   } else { ");document.write("fillSelectFromArray(this.form.Platf, ((this.selectedIndex == 0) ? null : inst_ra[this.form.Inst.selectedIndex-1][this.selectedIndex-1]),'Reset','Reset');");
document.write("   }");


document.write("} else {");
document.write("   if(this.options[this.selectedIndex].text == 'Reset') resetallfields(0);");
document.write("   if(this.options[this.selectedIndex].value == '   ') resetallfields(1);   ");
document.write("}\">");

for(i=0; i<prod_num; i++) {
   if(prodselect == prod_all[i][1]) {
      document.write("<option value=\""+prod_all[i][1]+"\" selected>"+prod_all[i][0]+"</option>");
   }else {
      document.write("<option value=\""+prod_all[i][1]+"\">"+prod_all[i][0]+"</option>");
   }
//   document.write("<option value=\""+prod_all[i][1]+"\">"+prod_all[i][0]+"</option>");
}
document.write("</select>");
}



function list_inst() {
document.write("<select name=Inst class=smallblack onChange=\"");
document.write("var instLength = this.form.Inst.length;");
document.write("if(firstChoice == -1) firstChoice = 2;");
document.write("if(secondChoice== -1 && firstChoice != 2) secondChoice =2;");
document.write("if(firstChoice == 2) {");
document.write("   fillSelectFromArray(this.form.Product, ((this.selectedIndex == 0 ) ? prod_all[0] : inst_r[this.selectedIndex-1]),'Reset','Reset');");
document.write("   fillSelectFromArray(this.form.Platf, ((this.selectedIndex == 0 ) ? plat_all[0] : inst_a[this.selectedIndex-1]),'Reset','Reset');");
document.write("   if(this.selectedIndex == 0 || this.options[this.selectedIndex].value == '   ') resetallfields(0);");
document.write("} else if(firstChoice == 1 && secondChoice == 2) {");
document.write("   if(this.selectedIndex == 0) {"); 
document.write("      resetallfields(0);");
document.write("   } else { ");
document.write("fillSelectFromArray(this.form.Platf, ((this.selectedIndex == 0) ? null : prod_ia[this.form.Product.selectedIndex-1][this.selectedIndex-1]),'Reset','Reset');");
document.write("   }");
document.write("} else {");
document.write("   if(this.selectedIndex == 0) { resetallfields(0); } ");
//document.write("   if(this.options[this.selectedIndex].value == 'reset') resetallfields(0);");
//document.write("   if(this.options[this.selectedIndex].value == '   ') resetallfields(2);   ");
document.write("}\">");
for(i=0; i<inst_num; i++) {
   if(instselect == inst_all[i][1]) {
      document.write("<option value=\""+inst_all[i][1]+"\" selected>"+inst_all[i][0]+"</option>");
   }else {
      document.write("<option value=\""+inst_all[i][1]+"\">"+inst_all[i][0]+"</option>");
   }
//   document.write("<option value=\""+inst_all[i][1]+"\">"+inst_all[i][0]+"</option>");
}
document.write("</select>");
}



function list_plat() {
document.write("<select name=Platf class=smallblack id=Platf onChange=\"");
document.write("var platLength = this.form.Platf.length;");
document.write("if(firstChoice == -1) firstChoice = 3;");
document.write("if(secondChoice== -1 && firstChoice !=3) secondChoice = 3;");
document.write("if(firstChoice == 3) {");
document.write("   fillSelectFromArray(this.form.Product, ((this.selectedIndex == 0 ) ? prod_all[0] : plat_r[this.selectedIndex-1]),'Reset','Reset');");
document.write("   fillSelectFromArray(this.form.Inst, ((this.selectedIndex == 0 ) ? inst_all[0] : plat_i[this.selectedIndex-1]),'Reset','Reset');");
document.write("   if(this.selectedIndex == 0 || this.options[this.selectedIndex].value == '   ') resetallfields(0);");
document.write("} else if(firstChoice == 1 && secondChoice == 3) {");
document.write("   if(this.selectedIndex == 0) {");
document.write("      resetallfields(0);");
document.write("   } else { ");
document.write("fillSelectFromArray(this.form.Inst, ((this.selectedIndex == 0) ? null : prod_ai[this.form.Product.selectedIndex-1][this.selectedIndex-1]),'Reset','Reset');");
document.write("   }");

document.write("} else if(firstChoice == 2 && secondChoice == 3) {");
document.write("   if(this.selectedIndex == 0) {");
document.write("      resetallfields(0);");
document.write("   } else { ");
document.write("fillSelectFromArray(this.form.Product, ((this.selectedIndex == 0) ? null : inst_ar[this.form.Inst.selectedIndex-1][this.selectedIndex-1]),'Reset','Reset');");
document.write("   }");

document.write("} else {");
document.write("   if(this.selectedIndex == 0) { resetallfields(0); } ");
//document.write("   if(this.options[this.selectedIndex].text == 'Reset') resetallfields(0);");
//document.write("   if(this.options[this.selectedIndex].value == '   ') resetallfields(3);   ");
document.write("}\">");
for(i=0; i<plat_num; i++) {
   if(platselect == plat_all[i][1]) {
      document.write("<option value=\""+plat_all[i][1]+"\" selected>"+plat_all[i][0]+"</option>");
   }else {
      document.write("<option value=\""+plat_all[i][1]+"\">"+plat_all[i][0]+"</option>");
   }
//   document.write("<option value=\""+plat_all[i][1]+"\">"+plat_all[i][0]+"</option>");
}
document.write("</select>");
}
//  End -->
