/*
*** Multiple dynamic combo boxes
*** by Mirko Elviro, 9 Mar 2005
*** Script featured and available on JavaScript Kit (http://www.javascriptkit.com)
***
***Please do not remove this comment
*/

// This script supports an unlimited number of linked combo boxed
// Their id must be "combo_0", "combo_1", "combo_2" etc.
// Here you have to put the data that will fill the combo boxes
// ie. data_2_1 will be the first option in the second combo box
// when the first combo box has the second option selected

window.onload = function () {
	//get a reference to the second comboBox.
	var currentCOMBO = document.getElementById("combo_1")
	//Check to see if it has a null value (false) - if so that means were dealing with I.E., so refresh the page.
	if (!currentCOMBO.value) { 
		window.location = window.location; // on reload the currentCombo.value = 1. No idea why.
	}; 
}
data_0 = new Option("", ""); //Nothing Selected
	data_0_1 = new Option("", "");
data_1 = new Option("Sq_Rec", "Square and Rectangular"); //Sq_Rec
	data_1_1 = new Option("3 x 3", "3x3");
	data_1_2 = new Option("4 x 4", "4x4");
	data_1_3 = new Option("4 x 5.65", "4x5.65");
	data_1_4 = new Option("5 x 5", "5x5");
	data_1_5 = new Option("5.65 x 5.65", "5.65x5.65");
	data_1_6 = new Option("6.6 x 6.6", "6.6x6.6");
data_2 = new Option("Screw-In", "Screw-In"); //Screw-In
	data_2_1 = new Option("37mm", "37mm");
	data_2_2 = new Option("40.5mm", "40.5mm");
	data_2_3 = new Option("43mm", "43mm");
	data_2_4 = new Option("48mm", "48mm");
	data_2_5 = new Option("58mm", "58mm");
	data_2_6 = new Option("62mm", "62mm");
	data_2_7 = new Option("72mm", "72mm");
	data_2_8 = new Option("77mm", "77mm");
	data_2_9 = new Option("82mm", "82mm");
	data_2_10 = new Option("95mm", "95mm");
	data_2_11 = new Option("102mm", "102mm");
	data_2_12 = new Option("105mm", "105mm");
	data_2_13 = new Option("127mm", "127mm");
data_3 = new Option("Round Drop-In", "Round Drop-In"); //Round Drop-In
	data_3_1 = new Option("Series 9", "Series9");
	data_3_2 = new Option("4 1/2 Inch", "4.5");
	data_3_3 = new Option("138mm", "138mm");
	data_3_4 = new Option("Five Inch", "5");
	data_3_5 = new Option("Six Inch", "6");
	data_3_6 = new Option("9 1/2 Inch", "9.5");
	

// other parameters
    var displaywhenempty="&nbsp;"
    var valuewhenempty=-1
	var displaywhennotempty="- Select or click search -"
    var valuewhennotempty=""
		
// Pass the .value property to this var from the selected combo, only when 'currentbox' is created in the change(currentbox) function. WM.
	var selectedComboURL="";
	
// submit button onClick: check if only the first combo options has been selected, if so 'manually' forward to page, if not then send user to page. WM.
function goToURL () {
	switch (selectedComboURL) {
		case "value1": alert ("Please selected from the drop down");
		break;
		case "value2": window.location = "/ecommerce/CatalogSubCategoryDisplay.aspx?CID=56";
		break;
		case "value3": window.location = "/ecommerce/CatalogSubCategoryDisplay.aspx?CID=57";
		break;
		default: window.location = selectedComboURL;
	};
}


function change(currentbox) {
	selectedComboURL = currentbox.value
	numb = currentbox.id.split("_");
	currentbox = numb[1];
    i=parseInt(currentbox)+1

// I empty all combo boxes following the current one
    while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) &&
           (document.getElementById("combo_"+i)!=null)) {
         son = document.getElementById("combo_"+i);
	     // I empty all options except the first one (it isn't allowed)
	     for (m=son.options.length-1;m>0;m--) son.options[m]=null;
	     // I reset the first option
	     son.options[0]=new Option(displaywhenempty,valuewhenempty)
	     i=i+1
    }

// now I create the string with the "base" name ("stringa"), ie. "data_1_0"
// to which I'll add _0,_1,_2,_3 etc to obtain the name of the combo box to fill
    stringa='data'
    i=0
    while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) &&
           (document.getElementById("combo_"+i)!=null)) {
           eval("stringa=stringa+'_'+document.getElementById(\"combo_"+i+"\").selectedIndex")
           if (i==currentbox) break;
           i=i+1
    }

// filling the "son" combo (if exists)
    following=parseInt(currentbox)+1

    if ((eval("typeof(document.getElementById(\"combo_"+following+"\"))!='undefined'")) &&
       (document.getElementById("combo_"+following)!=null)) {
       son = document.getElementById("combo_"+following);
       stringa=stringa+"_"
       i=0
       while ((eval("typeof("+stringa+i+")!='undefined'")) || (i==0)) {

       // if there are no options, I empty the first option of the "son" combo
	   // otherwise I put "-select-" in it
	   	  if ((i==0) && eval("typeof("+stringa+"0)=='undefined'"))
	   	      if (eval("typeof("+stringa+"1)=='undefined'"))
	   	         eval("son.options[0]=new Option(displaywhenempty,valuewhenempty)")
	   	      else
	             eval("son.options[0]=new Option(displaywhennotempty,valuewhennotempty)")
	      else
              eval("son.options["+i+"]=new Option("+stringa+i+".text,"+stringa+i+".value)")
	      i=i+1
	   }
       //son.focus()
       i=1
       combostatus=''
       cstatus=stringa.split("_")
       while (cstatus[i]!=null) {
          combostatus=combostatus+cstatus[i]
          i=i+1
          }
       return combostatus;
    }
}


