  // An Object whose properties hold Arrays of OptionType/Value pairs
  var MAIN_OPTIONS = new Object();

  function update_MAIN_OPTIONS(sTargetFieldID, sTypeName, sOptionTypeValue){
    // create the MAIN_OPTIONS' object property that'll hold the array of type/value pairs for this set of options
    // as long as the property doesn't already exist.
    if (MAIN_OPTIONS[sTargetFieldID] == undefined){
      MAIN_OPTIONS[sTargetFieldID] = new Array();
    }

    // add the type/value pair to the array and an id, so we can directly update if needed.
    if (MAIN_OPTIONS[sTargetFieldID][sTypeName] == undefined){
      MAIN_OPTIONS[sTargetFieldID][MAIN_OPTIONS[sTargetFieldID].length] = sOptionTypeValue;
      MAIN_OPTIONS[sTargetFieldID][sTypeName] = new Array((MAIN_OPTIONS[sTargetFieldID].length-1),
      MAIN_OPTIONS[sTargetFieldID][MAIN_OPTIONS[sTargetFieldID].length-1]);
    } else {
    // directly update the type/value pair in the array.
      MAIN_OPTIONS[sTargetFieldID][sTypeName][1] = sOptionTypeValue;
      MAIN_OPTIONS[sTargetFieldID][MAIN_OPTIONS[sTargetFieldID][sTypeName][0]] = sOptionTypeValue;
    }
  }

  // Function for updating the hidden options field.
  function optionTypeValues(oSelectObj){
    // string for holding the select form element's name.
    var sTypeName = oSelectObj.name;

    // object ref which points to the related options hidden field.
    var oOptionTypeValues = eval("document.getElementById('mainForm').optionTypeValues_"+(sTypeName.split("_"))[1]);

    // string for holding the target field's ID.
    var sTargetFieldID = oOptionTypeValues.id;

    // string for holding the concatenated value of the optionTypePk and the optionPk.
    var sOptionTypeValue = (sTypeName.split("_"))[2] + "=" + oSelectObj[oSelectObj.selectedIndex].value;

    // update the MAIN_OPTIONS object to reflect additions or updates
    update_MAIN_OPTIONS(sTargetFieldID, sTypeName, sOptionTypeValue);

    // update the target field's value, for posting the data.
    oOptionTypeValues.value = MAIN_OPTIONS[sTargetFieldID].join(":");
  }

// Function for updating the hidden options fields for CoreMetrics.
  function optionTypeValuesCoreMetrics(oSelectObj, productID){
  	// Build a sku id (productID_Option1ID_Option2ID_...)
  	var divList = oSelectObj.parentNode.parentNode.childNodes;
  	var skuID = productID;
		for (var i = 0; i< divList.length; i++) {
  		//if (divList[i] instanceof HTMLDivElement) {
  		if (divList[i].tagName == "DIV") {
  			var selectList = divList[i].childNodes;
				for (var j = 0; j< selectList.length; j++) {
		  		//if (selectList[j] instanceof HTMLSelectElement) {
		  		if (selectList[j].tagName == "SELECT") {
		  			//alert("ind: " + j + " Obj: " + selectList[j][selectList[j].selectedIndex].value);
		  			skuID = skuID + '_' + selectList[j][selectList[j].selectedIndex].value;
					}
				}
			}
		}
		//alert(skuID);

    var CMskuval = eval("document.getElementById('mainForm').CMp"+skuID);
    if (CMskuval != undefined){
    	var oProdNm = eval("document.getElementById('mainForm').CMpName_p"+productID);
    	var oProdNmVal="";
    	if (oProdNm!=undefined)
    		oProdNmVal=oProdNm.value;
    	
    	var CatIDvalField = eval("document.getElementById('mainForm').DetailCatID");
    	var CatIDVal="";
    	if (typeof(CatIDvalField) != undefined){
    		CatIDVal = CatIDvalField.value;
    	}
    	//alert("SKU: " + CMskuval.value + ". Prod Name: " + oProdNmVal + ". Cat Id: " + CatIDVal);
    	cmCreateProductviewTag(CMskuval.value, escape(oProdNmVal), CatIDVal);
    }

  }