    /*Methods for accessory finder BEGIN */
    //Takes in line, fam & mod as params.
    //Get accessory finder options by making an AJAX request
    function afinOpt(afinConfig, stt1, stt2, stt3, sttSeries) {
        try {
			// stt1 and stt2 and stt3 are optional. if not passed-in use current list value
			if (!stt1)
				stt1 = document.getElementById("stt1").value;
			if (!stt2)
				stt2 = document.getElementById("stt2").value;
            if (!stt3)
            	stt3 = document.getElementById("stt3").value;
            if (!sttSeries)
            	sttSeries = document.getElementById("sttSeries").value;

			if (stt1 == 'Laptop PCs')
				stt1 = 'Notebook PCs';
			var afinOptUrl = "afinopt.jsp?line=" + stt1 + "&fam=" + stt2 + "&mod=" + stt3 + "&ser=" + sttSeries;
			//alert("IN afinOptUrl(): " + afinOptUrl)
            getAccFinResponse(afinConfig, afinOptUrl, "GET");
        } catch(ex) {
		    alert("Error in afinOpt()" +ex);
	    }
    }

    //Reset the Family to "All" when the Line changes
    function afinCat(afinConfig, stt1) {
		// stt1 and stt2 are optional. if not passed-in use current list value
		if (!stt1)
			stt1 = document.getElementById("stt1").value;

		document.getElementById("stt2").value = "All";
        afinOpt(afinConfig, stt1);
    }

    //On Page Load, load accesory finder options for the LINE -- Notebook PCs
    function afinLoad(afinConfig) {
        try {
            var afinOptUrl = "afinopt.jsp?line=Notebook%20PCs&fam=" + document.getElementById("stt2").value;
            getAccFinResponse(afinConfig, afinOptUrl, "GET");
        } catch(ex) {}
    }

    //remove all select options prior to populating them with new ones
    function removeOptions(selElement) {
        for (var i = selElement.length - 1; i>=0; i--) {
            selElement.remove(i);
        }
    }

    //Add options to the given SELECT element and index of the options to start with
    function addOptions(afinConfig, selElement, docNodes, optCnt) {
		for(var i=0; i<docNodes.length; i++) {
            try {
                var opt = docNodes[i].firstChild.nodeValue;
				if (selElement.id == "stt1")
                  selElement.options[optCnt] = new Option(afinConfig.catPrefix + opt, opt);
                else if (selElement.id == "sttSeries")
                   selElement.options[optCnt] = new Option(opt.replace(/^.*\^/, ""), opt);
                else
                   selElement.options[optCnt] = new Option(opt, opt);
                optCnt++;
            } catch (ex) {}
        }
    }

    //Parse the response for the AJAX request and populated Line, family, model for accessory finder
    function getAccFinResponse(afinConfig, afinURL, reqMethod) {
        var stt1 = document.getElementById("stt1");
		var stt2 = document.getElementById("stt2");
		var stt3 = document.getElementById("stt3");
		var sttSeries = document.getElementById("sttSeries");
		try {
			//alert("IN getAccFinResponse()");
            stt2.disabled = true;
            stt3.disabled = true;
            sttSeries.disabled = true;

			//alert("Making AJAX call: " + afinURL);
            var xmldoc = getLoadedXMLDoc(afinURL, reqMethod);
			var lines = xmldoc.getElementsByTagName('line');
            removeOptions(stt1);
            //stt1.options[0] = new Option("Choose Category", "All");
            addOptions(afinConfig, stt1, lines, 0);
            stt1.value = xmldoc.getElementsByTagName('sel-line')[0].firstChild.nodeValue;

	    //A fix for IE 6-8. The stt1.value wsa not being set correctly.
	    if ( ! (stt1.value == 'PDAs' || stt1.value == 'Projectors') )
	    	stt1.value = stt1.options[0].value;

            var fams = xmldoc.getElementsByTagName('fam');
            removeOptions(stt2);
            stt2.options[0] = new Option(afinConfig.typeFirstOptionText, "All");
            addOptions(afinConfig, stt2, fams, 1);
            stt2.value = xmldoc.getElementsByTagName('sel-fam')[0].firstChild.nodeValue;

			if (! (stt1.value == "Projectors")) {
            	var sers = xmldoc.getElementsByTagName('ser');
	            removeOptions(sttSeries);
            	sttSeries.options[0] = new Option(afinConfig.seriesFirstOptionText, "All");
            	addOptions(afinConfig, sttSeries, sers, 1);
            	sttSeries.value = xmldoc.getElementsByTagName('sel-ser')[0].firstChild.nodeValue;
            	//i.e. hack
            	if (sttSeries.value == "") sttSeries.value = "All";
			}

            var mods = xmldoc.getElementsByTagName('mod');
            removeOptions(stt3);
			//alert("afinConfig.modelFirstOptionText: " + afinConfig.modelFirstOptionText);
            stt3.options[0] = new Option(afinConfig.modelFirstOptionText, "All");
            addOptions(afinConfig, stt3, mods, 1);
            stt3.value = xmldoc.getElementsByTagName('sel-mod')[0].firstChild.nodeValue;
			//i.e. hack
			if (stt3.value == "") stt3.value = "All";

            stt2.disabled = false;
            stt3.disabled = false;
            sttSeries.disabled = false;

			//alert(afinConfig.typeFirstOptionText + ":" + afinConfig.modelFirstOptionText);

        } catch(objException) {
			alert("Error occurred");
			stt2.disabled = false;
            stt3.disabled = false;
            //do nothing
			//lert("Error occurred in getAccFinResponse()");
		}
    }

	// Simple object to encapsulate Accessory Finder client-side config data
	function AfinConfig() {
		// Text to be pre-pended to Category display values in lists.
		this.catPrefix = "";

		// Display value for first option (All) for types.  Normally "All" is displayed, but if we want "Choose Type"
		// instead we would set this property's value to be "Choose Type".  "All" is still passed in the URL.
		this.typeFirstOptionText = "All";

		// Display value for first option (All) for types.  Normally "All" is displayed, but if we want "Choose Type"
		// instead we would set this property's value to be "Choose Type".  "All" is still passed in the URL.
		this.seriesFirstOptionText = "All";

		// Display value for first option (All) for models.  Normally "All" is displayed, but if we want "Choose Model"
		// instead then we would set this property's value to be "Choose Model".  "All" is still passed in the URL.
		this.modelFirstOptionText = "All";
	}

	/*Methods for accessory finder END */
