

function determineProductFormat(oMenu){
	// set object variables used below
	f = oMenu.form;
	oSelectedProductFormatMenuOption = oMenu.options[oMenu.selectedIndex];
	
	
	/* commented out - 7/29/04 - RH
	
	Originally, pdf files were uploaded.  When a user already had an existing pdf downloadable file for a 'pdf' product, but then decided to change
	the product so that it's no longer a 'pdf' product, we warned the user that their existing pdf file would be deleted.  However, now that files
	are managed through TeamSite, the file does not get deleted.  Instead, the drop down menu is automatically disabled when the user changes the
	product format to something other than 'pdf'.  Therefore, this section of code has been commented out.
	
	// if the user has switched product format from 'pdf' to something else AND there is already a downloadable pdf file assigned to this product,
	// then inform the user that the existing pdf file will be removed and ask if they wish to continue
	bResetMenu = false;
	if((parseInt(f.iLastProductFormatID.value) == 7) && (parseInt(oSelectedProductFormatMenuOption.value) != 7) && (f.bHasExistingFile_DownloadablePDF)){
		msg = "";
		msg += "You are changing the product format and this product will no longer\n";
		msg += "be a 'PDF' product.  When the form is submitted, the existing\n"; 
		msg += "'Downloadable PDF File' will be removed.\n\n";
		msg += "Are you sure you wish to make this change?";
		bResetMenu = !confirm(msg)
	}

	// if the user chose not to continue changing product format, then change the menu's selected item back to what is originally was
	if (bResetMenu){
		// loop through menu options and select the one that has the last value (stored before menu was changed)
		for (i=0; i<oMenu.options.length; i++){
			if (oMenu.options[i].value == f.iLastProductFormatID.value){
				oMenu.selectedIndex = i;
				break;
			}
		}
		// return false so the rest of the function is not executed
		return false;
	}
	*/
	
	// store the current selected value as the last selected value, so next time we'll know the value before the user changed the menu
	f.iLastProductFormatID.value = oSelectedProductFormatMenuOption.value;
	
	// Create array to hold fields that are only allowed under a certain product format
	aSpecificFormatFields = new Array();
	
	// Trim Size is only allowed for Book product format
	i = aSpecificFormatFields.length;
	aSpecificFormatFields[i] = new Array();
	aSpecificFormatFields[i]["fld"] = f.S_RUNNING_TIME;
	aSpecificFormatFields[i]["aProductFormatIDs"] = new Array(1);
	aSpecificFormatFields[i]["aProductFormatIDs"][0] = 1;
	aSpecificFormatFields[i]["aProductFormatIDs"][1] = 3;
	aSpecificFormatFields[i]["aProductFormatIDs"][2] = 4;
	aSpecificFormatFields[i]["aProductFormatIDs"][3] = 5;
	
	// Trim Size is only allowed for Book product format
	i = aSpecificFormatFields.length;
	aSpecificFormatFields[i] = new Array();
	aSpecificFormatFields[i]["fld"] = f.S_TRIM_SIZE;
	aSpecificFormatFields[i]["aProductFormatIDs"] = new Array(1);
	aSpecificFormatFields[i]["aProductFormatIDs"][0] = 2;
	
	// Page Count is only allowed for Book product format
	i = aSpecificFormatFields.length;
	aSpecificFormatFields[i] = new Array();
	aSpecificFormatFields[i]["fld"] = f.I_PAGE_COUNT;
	aSpecificFormatFields[i]["aProductFormatIDs"] = new Array(1);
	aSpecificFormatFields[i]["aProductFormatIDs"][0] = 2;
	
	// Downloadable PDF HREF is only allowed for PDF product format
	i = aSpecificFormatFields.length;
	aSpecificFormatFields[i] = new Array();
	aSpecificFormatFields[i]["fld"] = f.S_DOWNLOAD_PDF_HREF;
	aSpecificFormatFields[i]["aProductFormatIDs"] = new Array(1);
	aSpecificFormatFields[i]["aProductFormatIDs"][0] = 7;
	
	// Loop over arrays and enable/disable fields according to product format they're allowed in
	for (i=0; i<aSpecificFormatFields.length; i++){
		fld = aSpecificFormatFields[i]["fld"];
		// If selected format is in array of formats to be allowed for this field in loop, then enable this field
		if (posFoundInArray(aSpecificFormatFields[i]["aProductFormatIDs"], parseInt(oSelectedProductFormatMenuOption.value)) > -1){
			// don't assign a class when field is enabled
			fld.className = "";
			// reassign stored value based on field type
			if (fld.type == "select-one"){
				// With select lists, the 'removed_value' variable holds "SELECT_LIST" by default, which triggers this code
				// to replace it with the originally selected value.
				if (fld.removed_value == "SELECT_LIST") fld.removed_value = fld.selectedIndex;
				fld.selectedIndex = fld.removed_value;
			} else {
				fld.value = fld.removed_value;
			}
			// enable field
			fld.disabled = false;
		} else {
			// assign a class to this field so it looks disabled
			fld.className = "disabled-input-field";
			// store current value based on field type
			if (fld.type == "select-one"){
				fld.removed_value = fld.selectedIndex;
				fld.selectedIndex = 0;
			} else {
				fld.removed_value = fld.value;
				fld.value = "";
			}
			// disable field
			fld.disabled = true;
		}
	}
}

function toggleCLEFields(oCheckboxElement_CLE){
	// set object variables used below
	f = oCheckboxElement_CLE.form;
	
	iCLE_ProductTypeID = oCheckboxElement_CLE.value;
	bIsCLE = oCheckboxElement_CLE.checked;
	
	// Create array to hold fields that are only allowed under a certain product format
	aCLEFields = new Array();
	
	// Hours is only allowed for CLE product type
	i = aCLEFields.length;
	aCLEFields[i] = new Array();
	aCLEFields[i]["fld"] = f.I_HOURS;
	aCLEFields[i]["aProductTypeIDs"] = new Array(1);
	aCLEFields[i]["aProductTypeIDs"][0] = iCLE_ProductTypeID;
	
	// Hours is only allowed for CLE product format
	i = aCLEFields.length;
	aCLEFields[i] = new Array();
	aCLEFields[i]["fld"] = f.I_HOURS_ETHICS;
	aCLEFields[i]["aProductTypeIDs"] = new Array(1);
	aCLEFields[i]["aProductTypeIDs"][0] = iCLE_ProductTypeID;
	
	// Loop over arrays and enable/disable fields according to product format they're allowed in
	for (i=0; i<aCLEFields.length; i++){
		fld = aCLEFields[i]["fld"];
		// If selected type is in array of types to be allowed for this field in loop, then enable this field
		if (bIsCLE){
			// don't assign a class when field is enabled
			fld.className = "";
			// reassign stored value based on field type
			if (fld.type == "select-one"){
				// With select lists, the 'removed_value' variable holds "SELECT_LIST" by default, which triggers this code
				// to replace it with the originally selected value.
				if (fld.removed_value == "SELECT_LIST") fld.removed_value = fld.selectedIndex;
				fld.selectedIndex = fld.removed_value;
			} else {
				fld.value = fld.removed_value;
			}
			// enable field
			fld.disabled = false;
		} else {
			// assign a class to this field so it looks disabled
			fld.className = "disabled-input-field";
			// store current value based on field type
			if (fld.type == "select-one"){
				fld.removed_value = fld.selectedIndex;
				fld.selectedIndex = 0;
			} else {
				fld.removed_value = fld.value;
				fld.value = "";
			}
			// disable field
			fld.disabled = true;
		}
	}
}

function togglePurchaseCheckbox(oCheckboxElement_Periodical){
	// set object variables used below
	f = oCheckboxElement_Periodical.form;
	
	// if not periodical checkbox, then exit function
	iPeriodical_ProductTypeID = 6;
	if (oCheckboxElement_Periodical.value != iPeriodical_ProductTypeID) return false;
	
	// determine if periodical checkbox is checked
	bIsPeriodical = oCheckboxElement_Periodical.checked;
	
	// set B_PURCHASABLE field status based on whether product is a periodical (periodicals cannot currently be purchased in store)	
	f.B_PURCHASABLE.disabled = bIsPeriodical;
	if(f.B_PURCHASABLE.disabled) f.B_PURCHASABLE.checked = false;
}

function posFoundInArray(ary, val){
	iPos = -1;
	for (var i=0; i<ary.length; i++){
		if (ary[i] == val){
			bInArray = true;
			iPos = i;
		}
	}
	return iPos;
}
			
function toggleStateRegion(f, sFieldnameSuffix, sAction){
	theStateField = eval("f.S_STATE" + sFieldnameSuffix);
	theRegionField = eval("f.S_STATE_TEXT_FIELD" + sFieldnameSuffix);
	theCountryField = eval("f.S_COUNTRY" + sFieldnameSuffix);
	bUSAIsSelected = false;
	bCanadaIsSelected = false;
	determineSelectedCountry(theCountryField);
	
	if(bUSAIsSelected || bCanadaIsSelected){
		if(sAction == "testfocus"){
			toggleFocus(theStateField, 1);
			toggleFocus(theRegionField, 0);
		} else {
			theStateField.className = "shared-form-enabled-field";
			theRegionField.className = "shared-form-disabled-field";
			theRegionField.value = "";
		}
	} else{
		if(sAction == "testfocus"){
			toggleFocus(theStateField, 0);
			theStateField.selectedIndex = 0;
			toggleFocus(theRegionField, 1);
		} else {
			theStateField.className = "shared-form-disabled-field";
			theRegionField.className = "shared-form-enabled-field";
			theStateField.selectedIndex = 0;
		}
	}
}

function toggleFocus(sFld, bAllowFocus){
	if(!bAllowFocus){
		sFld.blur();
	}
}

function determineSelectedCountry(theCountryField){
	if(theCountryField.options[theCountryField.selectedIndex].value == "USA"){
		bUSAIsSelected = true;
	} else if(theCountryField.options[theCountryField.selectedIndex].value == "Canada"){
		bCanadaIsSelected = true;
	}
}


function toggleProductEntityProfileFields(cbx){
	f = cbx.form;

	// Create array to hold fields that are only allowed under a certain product format
	aProfileEntityFields = new Array();
	
	// Set fields used for Profile info
	i = aProfileEntityFields.length;
	aProfileEntityFields[i] = new Array();
	aProfileEntityFields[i]["fld"] = f.S_ENTITY_PROFILE_ID_LIST;
	aProfileEntityFields[i]["heading"] = "Entity Profile";
	
	for(i=0; i<aProfileEntityFields.length; i++){
		fld = aProfileEntityFields[i]["fld"];
		if(cbx.checked){
			// don't assign a class when field is enabled
			fld.className = "";
			// reassign stored value based on field type
			if (fld.type == "select-one"){
				// With select lists, the 'removed_value' variable holds "SELECT_LIST" by default, which triggers this code
				// to replace it with the originally selected value.
				if (fld.removed_value == "SELECT_LIST") fld.removed_value = fld.selectedIndex;
				fld.selectedIndex = fld.removed_value;
			} else {
				fld.value = fld.removed_value;
			}
			// enable field
			fld.disabled = false;
		} else{
			// assign a class to this field so it looks disabled
			fld.className = "disabled-input-field";
			// store current value based on field type
			if (fld.type == "select-one"){
				fld.removed_value = fld.selectedIndex;
				fld.selectedIndex = 0;
			} else {
				fld.removed_value = fld.value;
				fld.value = "";
			}
			// disable field
			fld.disabled = true;
		}
	}
}


function toggleEntityProfileFields(cbx){
	f = cbx.form;

	// get array of entity profile fields
	aProfileFields = setEntityProfileFields();
	
	for(i=0; i<aProfileFields.length; i++){
		fld = aProfileFields[i]["fld"];
		if(cbx.checked){
			// don't assign a class when field is enabled
			fld.className = "";
			// reassign stored value based on field type
			if (fld.type == "select-one"){
				// With select lists, the 'removed_value' variable holds "SELECT_LIST" by default, which triggers this code
				// to replace it with the originally selected value.
				if (fld.removed_value == "SELECT_LIST") fld.removed_value = fld.selectedIndex;
				fld.selectedIndex = fld.removed_value;
			} else {
				fld.value = fld.removed_value;
			}
			// enable field
			fld.disabled = false;
		} else{
			// assign a class to this field so it looks disabled
			fld.className = "disabled-input-field";
			// store current value based on field type
			if (fld.type == "select-one"){
				fld.removed_value = fld.selectedIndex;
				fld.selectedIndex = 0;
			} else {
				fld.removed_value = fld.value;
				fld.value = "";
			}
			// disable field
			fld.disabled = true;
		}
	}
}

function setEntityProfileFields(){
	// Create array to hold fields that are only allowed under a certain product format
	ary = new Array();
	
	// Set fields used for Profile info
	i = ary.length;
	ary[i] = new Array();
	ary[i]["fld"] = f.S_PROFILE_TITLE;
	ary[i]["heading"] = "Entity Title";
	i = ary.length;
	ary[i] = new Array();
	ary[i]["fld"] = f.S_PROFILE_HEADING;
	ary[i]["heading"] = "Entity Heading";
	i = ary.length;
	ary[i] = new Array();
	ary[i]["fld"] = f.S_PROFILE_DSCT_TEXT;
	ary[i]["heading"] = "Discount Text";
	i = ary.length;
	ary[i] = new Array();
	ary[i]["fld"] = f.S_PROFILE_HREF_HOME;
	ary[i]["heading"] = "Link to Home";
	i = ary.length;
	ary[i] = new Array();
	ary[i]["fld"] = f.S_PROFILE_HREF_JOIN;
	ary[i]["heading"] = "Link to Join";
	i = ary.length;
	ary[i] = new Array();
	ary[i]["fld"] = f.S_PROFILE_LOGO_PATH;
	ary[i]["heading"] = "Entity Logo Path";
	
	return ary;

}
