//=========================
function AddEvent(oElement, sEventName, fnFunction)
//=========================
// for example:  AddEvent(window, 'load', jsExtLinks);
{

	if (oElement)
	{
		if (oElement.attachEvent)
		{
			oElement.attachEvent('on' + sEventName, fnFunction);
		}
		else
		{
			oElement.addEventListener(sEventName, fnFunction, true);
		}
	}
}


var bDebugFlag = false;
//=========================
function debugAlert(sMsg)
//=========================
{
		if (bDebugFlag) alert(sMsg);
}



/*		externallinks.js
		by Paul Novitski - www.juniperwebcraft.com
		February 2007

This script converts all absolute URL hyperlinks to open in a new window.
19 April 2007 - also any link with the class "external"
*/
//=========================
function jsExtLinks()
//=========================
{
	//debugAlert("function jsExtLinks()");

	var sPrompt = "(Opens in a new window)";

	var aLinks = document.getElementsByTagName("A");
	
	//debugAlert("aLinks.length = " + aLinks.length);
	
	for (var iLink = 0; iLink < aLinks.length; iLink++)
	{
		var bExternal = false;
		var bPopup = false;
		
		var sClass = aLinks[iLink].className;		
		//var sClass = aLinks[iLink].getAttribute("class");
			if (sClass && sClass == 'popup')
			{
				bPopup = true;
			}
			else if (sClass && sClass == 'external')
			{
				bExternal = true;
			}
			else
			{		
				var sHref = aLinks[iLink].getAttribute("href");
				//debugAlert(iLink + ": " + sHref);
				
					if (!sHref) continue;
					if (sHref == "") continue;

					if (sHref.substring(0, 4) == "http") bExternal = true;
					
					// don't open new window for any page in this website family
					if (sHref.indexOf("//mirviss.com") >= 0
					 || sHref.indexOf("//www.mirviss.com") >= 0
					) bExternal = false;
			}
		
			if (!bExternal && !bPopup) continue;
		
			if (bExternal)
			{
				var sClickFunction = jsExtLinksClick;
			}
			else if (bPopup)
			{
				var sClickFunction = jsPopupLinksClick;
			}
			else
			{
				continue;
			}
		
		aLinks[iLink].onclick = sClickFunction;

		var sTitle = aLinks[iLink].getAttribute("title");
		
			if (!sTitle) sTitle = '';
			if (sTitle.indexOf("new window") >= 0) continue;

			if (sTitle == "")
			{
				sTitle = sPrompt;
			}
			else
			{
				sTitle = sTitle + " " + sPrompt;
			}
		
		aLinks[iLink].setAttribute("title", sTitle);
		//debugAlert("title: " + iLink + ": " + sTitle);
	}
}


//=========================
function jsExtLinksClick(evt)
//=========================
{
	// cancel event-bubbling
		if (evt) { event = evt; }
	event.cancelBubble = true;

	var sHref = this.getAttribute("href");

	window.open (sHref, "_blank");	

	return false;
}



//=========================
function jsPopupLinksClick(evt)
//=========================
{
	// cancel event-bubbling
		if (evt) { event = evt; }
	event.cancelBubble = true;
	
	// see if it's an image
	var rCheckImage = /\.(jpg|jpeg|gif|png)$/i;
	var rGetDims = /-(\d+)x(\d+)\.(jpg|jpeg|gif|png)$/i;
	
	var sPopupHref = 'popupImage.php?img=';
	
	var sHref = this.getAttribute("href");

	var bIsImage = rCheckImage.test(sHref);
	
	//debugAlert((bIsImage) ? 'An image' : 'Not an image');

		if (bIsImage)
		{
			var aMatches = rGetDims.exec(sHref);
			//debugAlert(aMatches.join('\n'));
			sHref = sPopupHref + encodeURIComponent(sHref);
			var sWindowName = "Image Pop-up";
			var sFeatures = "menubar=no,toolbar=no,directories=no,personalbar=no,scrollbars=no";
				if (aMatches) sFeatures += ",width=" + aMatches[1] + ",height=" + aMatches[2];
		}
		else
		{
			var sWindowName = "New Window";
			var sFeatures = '';
		}

	window.open(sHref, sWindowName, sFeatures);

	return false;
}


/*
		validate-input.js		
		by Paul Novitski www.juniperwebcraft.com
		last revised November 2007
		
		This script validates an input form based on input field class names:
			vReq			validateRequired()		numeric
			vEmail			validateEmail()			email address
			vPostalCode		validatePostalCode()	Canadian postal code
			vPhone			validatePhone()			phone number (digits + -().)
			vNums			validateNums()			numeric digits only

*/

//=========================
// execute on page load
//=========================
//AddEvent(window, "load", validateFormInit);

// set behaviors
//=========================
function validateFormInit()
//=========================
{
		if (!document.getElementById) return;
		if (!document.getElementsByTagName) return;

	// look for the form
	var aForms = document.getElementsByTagName('form');
		if (!aForms) return;

	for (var iForm=0; iForm < aForms.length; iForm++)
	{
		aForms[iForm].onsubmit = ValidateForm;
	}
}


//=========================
function ValidateForm(evt)
//=========================
{
	// cancel event-bubbling
		if (evt) { event = evt; }
	event.cancelBubble = true;

//debugAlert('validating form');

	// default status is OK
	bStatus = true;
	
	// regular expression to collect class names
	var rClasses = /\b\w+\b/g;

	// collection of controls in this form
	var aControls = this.elements;
	
	for (var iCtl = 0; iCtl < aControls.length; iCtl++)
	{
		var oControl = aControls[iCtl];
//debugAlert('oControl.style.display = ' + oControl.style.display);
			if (oControl.style.display == 'none') continue;
		
		var sClass = oControl.className;
		
			if (sClass && sClass > '')
			{
				
				var aMatches = sClass.match(rClasses);
				
				for (var iMatch = 0; iMatch < aMatches.length; iMatch++)
				{
					//debugAlert(sClass + '\n' + aMatches[iMatch]);
					switch (aMatches[iMatch])
					{
						case 'vReq':		[bStatus, sMsg] = validateRequired(oControl);		break;
						case 'vEmail':		[bStatus, sMsg] = validateEmail(oControl);			break;
						case 'vPostalCode':	[bStatus, sMsg] = validatePostalCode(oControl);		break;
						case 'vPhone':		[bStatus, sMsg] = validatePhone(oControl);			break;
						case 'vNums':		[bStatus, sMsg] = validateNums(oControl);			break;
					}

//debugAlert('bStatus = ' + bStatus);

						if (!bStatus)
						{
//debugAlert('Displaying error because bStatus = ' + bStatus);
							displayErrorMessage(oControl, sMsg);
							oControl.focus();
							return bStatus;
							break;
						}
				}//for
					if (!bStatus) break;
			}//if

			if (!bStatus) break;
	}

	return bStatus;
}


//=========================
function validateRequired(oControl)
//=========================
{
	//debugAlert('validateRequired(): ' + oControl.tagName + '.value = ' + oControl.value);

	switch (oControl.tagName)
	{
		case 'INPUT':
			bStatus = (oControl.value > '');
			break;

		case 'SELECT':
//debugAlert('SELECT #' + oControl.id + ' selectedIndex = ' + oControl.selectedIndex);
			bStatus = (oControl.selectedIndex >= 0);
//debugAlert('bStatus = ' + bStatus);
			break;
	}
	return [bStatus, "'@' is required"];
}



//=========================
function validateEmail(oControl)
//=========================
{
	var rEmail = /^[a-z0-9._-]+@[a-z0-9._-]+(\.[a-z]+)+$/i;

		// blank?
		if (oControl.value == '') return [true, ''];

	return [rEmail.test(oControl.value), "Invalid '@'"];
}


//=========================
function validatePostalCode(oControl)
//=========================
{
	var rPCCA = /^[a-z][0-9][a-z] *[0-9][a-z][0-9]$/i;

		// blank?
		if (oControl.value == '') return [true, ''];

	return [rPCCA.test(oControl.value), "Invalid '@'"];
}


//=========================
function validatePhone(oControl)
//=========================
{
	var rPhone = /^[- 0-9()]+$/;

		// blank?
		if (oControl.value == '') return [true, ''];

	return [rPhone.test(oControl.value), "Invalid '@'"];
}


//=========================
function validateNums(oControl)
//=========================
{
	var rNums = /^[- 0-9]+$/;

		// blank?
		if (oControl.value == '') return [true, ''];

	return [rNums.test(oControl.value), "Invalid '@'"];
}


//=========================
function displayErrorMessage(oControl, sMsgTemplate)
//=========================
{
//debugAlert('function displayErrorMessage(' + oControl + ', ' + sMsgTemplate + ')');

	// find label for this input control
	var oLabel = null;

		if (oControl.id)
		{
			var aLabels = document.getElementsByTagName('label');
			
			for (var iLabel = 0; iLabel < aLabels.length; iLabel++)
			{
				sFor = aLabels[iLabel].getAttribute('for');
					if (sFor && sFor == oControl.id)
					{
						oLabel = aLabels[iLabel];
						break;
					}
			}
		}


		if (oLabel)
		{
//debugAlert('Using the label ' + oLabel.textContent);
			var sId = oLabel.textContent;
			sId = sId.replace('* ', '');
			sId = sId.replace(':', '');
		}
		else if (oControl.id)
		{
//debugAlert('Using the control id ' + oControl.id);
			var sId = oControl.id.replace(/[_-]/, ' ');
		}
		else if (oControl.name)
		{
//debugAlert('Using the control name ' + oControl.name);
			var sId = oControl.name.replace(/[_-]/, ' ');
		}
		else
		{
//debugAlert('Using the control tagName ' + oControl.tagName);
			var sId = oControl.tagName;
		}
		
	var sMsg = sMsgTemplate.replace('@', sId);
	alert(sMsg);
}

/*

	
	var oPrevObj = oControl.previousSibling;
	var oLabel = null;
	
	while (oPrevObj)
	{
			if (oPrevObj.tagName && oPrevObj.tagName == 'LABEL')
			{
				oLabel = oPrevObj;
				break;
			}
		oPrevObj = oPrevObj.previousSibling;
	}
*/




// Cigarette Brand & Type Selector Logic

//=========================
// global variables
//=========================
var sBrandNotListedLink = 'brand-not-listed';

var sChangeBrandLink = 'change-brand';
var sBrandSelector = 'brand-selector';
var sBrandSelectId = 'brandselect';
var sBrandDetailsId = 'brand-details';

var sBrandListBlockId = 'brandlistblock';
var sTypeListBlockId = 'typelistblock';

var sLighterBrandSelectId = 'lighter-brandselect';
var sLighterBrandDetailsId = 'lighter-brand-details';
var sLighterBrandListBlockId = 'lighter-brandlistblock';
var sLighterTypeListBlockId = 'lighter-typelistblock';

//var sSelectedBrand;
var oSelectedType = null;

//=========================
function brandSelectInit()
//=========================
{
		if (!document.getElementById) return;
		if (!document.getElementsByTagName) return;

	brandSelectInitNormal();
	brandSelectInitLighter();
}


//=========================
function brandSelectInitNormal()
//=========================
{
	// make sure we can find all the crucial parts
	var oBrandSelect = document.getElementById(sBrandSelectId);
		if (!oBrandSelect) return; // debugAlert("Can't find " + sBrandSelectId);

	var oDetails = document.getElementById(sBrandDetailsId);
		if (!oDetails) return; // debugAlert("Can't find " + sBrandDetailsId);
	
	// apply behavior to brand list
	oBrandSelect.onchange = jsBrandSelectChange;
	oBrandSelect.onclick = jsBrandSelectChange;

	//-------------------------
	// apply behavior to change-brand link
	//-------------------------
	var oLink = document.getElementById(sChangeBrandLink);
	var oBrandSelector = document.getElementById(sBrandSelector);

		if (oLink && oBrandSelector)
		{
			oBrandSelector.style.display = 'none';
			oLink.onclick = jsChangeBrand;
		}
 
	//-------------------------
	// apply behavior to brand-not-listed link
	//-------------------------
	var oLink = document.getElementById(sBrandNotListedLink);
		if (oLink) oLink.onclick = jsInputNewBrand;


debugAlert('display type if a brand is pre-selected');
	// display type if a brand is pre-selected
	jsBrandSelectChangeSub(oBrandSelect);
}



//=========================
function jsChangeBrand(evt)
//=========================
{
	// cancel event-bubbling
		if (evt) { event = evt; }
	event.cancelBubble = true;

	var oBrandSelector = document.getElementById(sBrandSelector);
	oBrandSelector.style.display = 'block';
	
	return false;
}


//=========================
function jsInputNewBrand(evt)
//=========================
{
	// cancel event-bubbling
		if (evt) { event = evt; }
	event.cancelBubble = true;
	
	jsToggleBrandDetailsDisplay('input');
	
	return false;
}


//=========================
function jsBrandSelectChange(evt)
//=========================
{
	// cancel event-bubbling
		if (evt) { event = evt; }
	event.cancelBubble = true;

	jsBrandSelectChangeSub(this);
}



//=========================
function jsBrandSelectChangeSub(oBrandList)
//=========================
{
debugAlert('function jsBrandSelectChangeSub(oBrandList)');

		// first de-select previous type
		if (oSelectedType) oSelectedType.className = '';

debugAlert('oBrandList.selectedIndex = ' + oBrandList.selectedIndex);
		if (oBrandList.selectedIndex < 0) return;

	var sSelectionClass = oBrandList.options[oBrandList.selectedIndex].className;
	
debugAlert('sSelectionClass = ' + sSelectionClass);

	var oTypeSelect = document.getElementById(sSelectionClass);
		if (!oTypeSelect) return debugAlert("Can't find " + sSelectionClass);

		if (oSelectedType)
		{
			oSelectedType.className = '';
debugAlert("De-selecting previous type '" + oSelectedType.id + "'");
		}

debugAlert("Selecting new type '" + oTypeSelect.id + "'");
	
	// remember selected brand's type list
	oSelectedType = oTypeSelect;

	// make this type list required for input validation
	oTypeSelect.className = 'vReq';

debugAlert("oTypeSelect.className = '" + oTypeSelect.className + "'");

	// set to 'for' attribute of the Type label
	var oTypeListBlock = document.getElementById(sTypeListBlockId);
	var aLabels = oTypeListBlock.getElementsByTagName('label');
	aLabels[0].setAttribute('for', oTypeSelect.id);
	
	//oTypeSelect.setAttribute('size', oTypeSelect.options.length);
	
	// set behavior
	oTypeSelect.onchange = jsTypeSelectChange;
	oTypeSelect.onclick = jsTypeSelectChange;
	
	// clear type details display
	jsClearTypeDetails();
	
		// if this list already has a selected item, act on it (display details)
		if (oTypeSelect.selectedIndex >= 0)
		{
			jsTypeSelectChangeSub(oTypeSelect);
		}
	
	// ensure that the details are displaying and not accepting input
	jsToggleBrandDetailsDisplay('display');
	
	return false;
}


//=========================
function jsToggleBrandDetailsDisplay(sState)
//=========================
// sState = 'input' or 'display'
{
debugAlert('function jsToggleBrandDetailsDisplay(' + sState + ')');

	var oDetails = document.getElementById(sBrandDetailsId);
	oDetails.className = sState;
	
	//var sLinkVisibility = (sState == 'display') ? 'visible' : 'hidden';
	
		if (sState == 'display')
		{
			var sLinkVisibility = 'visible';
			var sListBlockClass = 'visible';
			var sListClass = 'vReq';
			var sInputClass = '';
		}
		else	// sState == 'input'
		{
			var sLinkVisibility = 'hidden';
			var sListBlockClass = 'hidden';
			var sListClass = '';
			var sInputClass = 'vReq';
		}
	
	var oLink = document.getElementById(sBrandNotListedLink);
	oLink.parentNode.style.visibility = sLinkVisibility;
	
	// toggle brand & type list visibility & validation requirements
/*
	var oBrandListBlock = document.getElementById(sBrandListBlockId);
	oBrandListBlock.className = sListBlockClass;

	var oTypeListBlock = document.getElementById(sTypeListBlockId);
	oTypeListBlock.className = sListBlockClass;
*/
	var oBrandSelect = document.getElementById(sBrandSelectId);
	oBrandSelect.className = sListClass;

		if (oSelectedType) oSelectedType.className = sListClass;
	
	var oDetails = document.getElementById(sBrandDetailsId);
	var aInputs = oDetails.getElementsByTagName('input');
	
	for (var item = 0; item < aInputs.length; item++)
	{
		aInputs[item].className = sInputClass;
	}
	
		if (sState == 'input')
		{
			aInputs[0].focus();
		}
}


//=========================
function jsClearTypeDetails()
//=========================
{
	var oDetails = document.getElementById(sBrandDetailsId);
	var aDetails = oDetails.getElementsByTagName('dd');
	
	for (var iDD = 0; iDD < aDetails.length; iDD++)
	{
		var aSpans = aDetails[iDD].getElementsByTagName('span');
			if (aSpans && aSpans.length > 0) aSpans[0].innerHTML = '';
	}

}


//=========================
function jsTypeSelectChange(evt)
//=========================
// When type is selected, populate the brand type details list.
{
	// cancel event-bubbling
		if (evt) { event = evt; }
	event.cancelBubble = true;

	jsToggleBrandDetailsDisplay('display');

	jsTypeSelectChangeSub(this);
}


//=========================
function jsTypeSelectChangeSub(oTypeList)
//=========================
{
debugAlert('function jsTypeSelectChangeSub(' + oTypeList.id + ')');

	var oDetails = document.getElementById(sBrandDetailsId);
	var oBrandSelect = document.getElementById(sBrandSelectId);
	var sBrand = oBrandSelect.options[oBrandSelect.selectedIndex].value;
		if (!sBrand) sBrand = oBrandSelect.options[oBrandSelect.selectedIndex].innerHTML;

	var sType = oTypeList.options[oTypeList.selectedIndex].value;
		if (!sType) sType = oTypeList.options[oTypeList.selectedIndex].innerHTML;
	
	var sTypeDetails = oTypeList.options[oTypeList.selectedIndex].className;
	var aRawDetails = sTypeDetails.split(',');
	var aTypeDetails = {
						'brand' : sBrand
					   ,'type' : sType
					   ,'tar' : aRawDetails[0]
					   ,'nicotine' : aRawDetails[1]
					   ,'co' : aRawDetails[2]
					   ,'harm' : aRawDetails[3]
					   ,'category' : aRawDetails[4]
					};

	var aHarmCategory = new Array(
		'No Category'
		,'Ultralight'
		,'Very light'
		,'Light'
		,'Medium'
		,'Heavy'
		,'Very Heavy'
		,'Ultraheavy'
		);

	iPos = aTypeDetails['type'].indexOf(' (');
	aTypeDetails['type'] = aTypeDetails['type'].substr(0, iPos);
	aTypeDetails['category'] = 'Category ' + aTypeDetails['category'] + ' (' + aHarmCategory[aTypeDetails['category']] + ')';
	aTypeDetails['harm'] += '%';


	var aDetails = oDetails.getElementsByTagName('dd');
	
	for (var iDD = 0; iDD < aDetails.length; iDD++)
	{
		var aSpans = aDetails[iDD].getElementsByTagName('span');
			if (aSpans && aSpans.length > 0)
			{
				aSpans[0].innerHTML = aTypeDetails[aDetails[iDD].className];
			}
	}

	return false;
}


//=========================
function brandSelectInitLighter()
//=========================
{
	// make sure we can find all the crucial parts
	var oBrandSelect = document.getElementById(sLighterBrandSelectId);
		if (!oBrandSelect) return debugAlert("Can't find " + sLighterBrandSelectId);

	var oDetails = document.getElementById(sLighterBrandDetailsId);
		if (!oDetails) return debugAlert("Can't find " + sLighterBrandDetailsId);
	
	// apply behavior to brand list
	oBrandSelect.onchange = sLighterBrandSelectChange;
	oBrandSelect.onclick = sLighterBrandSelectChange;

debugAlert('display type if a brand is pre-selected');
	// display type if a brand is pre-selected
	sLighterBrandSelectChangeSub(oBrandSelect);
}



//=========================
function sLighterBrandSelectChange(evt)
//=========================
{
	// cancel event-bubbling
		if (evt) { event = evt; }
	event.cancelBubble = true;

	sLighterBrandSelectChangeSub(this);
}



//=========================
function sLighterBrandSelectChangeSub(oBrandList)
//=========================
{
debugAlert('function sLighterBrandSelectChangeSub(oBrandList)');

		// first de-select previous type
		if (oSelectedType) oSelectedType.className = '';

debugAlert('oBrandList.selectedIndex = ' + oBrandList.selectedIndex);
		if (oBrandList.selectedIndex < 0) return;

	var sSelectionClass = oBrandList.options[oBrandList.selectedIndex].className;
	
debugAlert('sSelectionClass = ' + sSelectionClass);

	var oTypeSelect = document.getElementById(sSelectionClass);
		if (!oTypeSelect) return debugAlert("Can't find " + sSelectionClass);

		if (oSelectedType)
		{
			oSelectedType.className = '';
debugAlert("De-selecting previous type '" + oSelectedType.id + "'");
		}

debugAlert("Selecting new type '" + oTypeSelect.id + "'");
	
	// remember selected brand's type list
	oSelectedType = oTypeSelect;

	// make this type list required for input validation
	oTypeSelect.className = 'vReq';

debugAlert("oTypeSelect.className = '" + oTypeSelect.className + "'");

	// set to 'for' attribute of the Type label
	var oTypeListBlock = document.getElementById(sLighterTypeListBlockId);
	var aLabels = oTypeListBlock.getElementsByTagName('label');
	aLabels[0].setAttribute('for', oTypeSelect.id);
	
	//oTypeSelect.setAttribute('size', oTypeSelect.options.length);
	
	// set behavior
	oTypeSelect.onchange = jsLighterTypeSelectChange;
	oTypeSelect.onclick = jsLighterTypeSelectChange;
	
	// clear type details display
	jsClearTypeDetails();
	
		// if this list already has a selected item, act on it (display details)
		if (oTypeSelect.selectedIndex >= 0)
		{
			jsLighterTypeSelectChangeSub(oTypeSelect);
		}
	
	// ensure that the details are displaying and not accepting input
	jsToggleLighterBrandDetailsDisplay('display');
	
	return false;
}


//=========================
function jsToggleLighterBrandDetailsDisplay(sState)
//=========================
// sState = 'input' or 'display'
{
debugAlert('function jsToggleLighterBrandDetailsDisplay(' + sState + ')');

	var oDetails = document.getElementById(sLighterBrandDetailsId);
	oDetails.className = sState;
	
	//var sLinkVisibility = (sState == 'display') ? 'visible' : 'hidden';
	
		if (sState == 'display')
		{
			var sLinkVisibility = 'visible';
			var sListBlockClass = 'visible';
			var sListClass = 'vReq';
			var sInputClass = '';
		}
		else	// sState == 'input'
		{
			var sLinkVisibility = 'hidden';
			var sListBlockClass = 'hidden';
			var sListClass = '';
			var sInputClass = 'vReq';
		}
	
	var oLink = document.getElementById(sBrandNotListedLink);
	oLink.parentNode.style.visibility = sLinkVisibility;
	
	// toggle brand & type list visibility & validation requirements
/*
	var oBrandListBlock = document.getElementById(sLighterBrandListBlockId);
	oBrandListBlock.className = sListBlockClass;

	var oTypeListBlock = document.getElementById(sLighterTypeListBlockId);
	oTypeListBlock.className = sListBlockClass;
*/
	var oBrandSelect = document.getElementById(sLighterBrandSelectId);
	oBrandSelect.className = sListClass;

		if (oSelectedType) oSelectedType.className = sListClass;
	
	var oDetails = document.getElementById(sLighterBrandDetailsId);
	var aInputs = oDetails.getElementsByTagName('input');
	
	for (var item = 0; item < aInputs.length; item++)
	{
		aInputs[item].className = sInputClass;
	}
	
		if (sState == 'input')
		{
			aInputs[0].focus();
		}
}


//=========================
function jsClearTypeDetails()
//=========================
{
	var oDetails = document.getElementById(sLighterBrandDetailsId);
	var aDetails = oDetails.getElementsByTagName('dd');
	
	for (var iDD = 0; iDD < aDetails.length; iDD++)
	{
		var aSpans = aDetails[iDD].getElementsByTagName('span');
			if (aSpans && aSpans.length > 0) aSpans[0].innerHTML = '';
	}

}


//=========================
function jsLighterTypeSelectChange(evt)
//=========================
// When type is selected, populate the brand type details list.
{
	// cancel event-bubbling
		if (evt) { event = evt; }
	event.cancelBubble = true;

	jsToggleLighterBrandDetailsDisplay('display');

	jsLighterTypeSelectChangeSub(this);
}


//=========================
function jsLighterTypeSelectChangeSub(oTypeList)
//=========================
{
debugAlert('function jsLighterTypeSelectChangeSub(' + oTypeList.id + ')');

	var oDetails = document.getElementById(sLighterBrandDetailsId);
	var oBrandSelect = document.getElementById(sLighterBrandSelectId);
	var sBrand = oBrandSelect.options[oBrandSelect.selectedIndex].value;
		if (!sBrand) sBrand = oBrandSelect.options[oBrandSelect.selectedIndex].innerHTML;

	var sType = oTypeList.options[oTypeList.selectedIndex].value;
		if (!sType) sType = oTypeList.options[oTypeList.selectedIndex].innerHTML;
	
	var sTypeDetails = oTypeList.options[oTypeList.selectedIndex].className;
	var aRawDetails = sTypeDetails.split(',');
	var aTypeDetails = {
						'brand' : sBrand
					   ,'type' : sType
					   ,'tar' : aRawDetails[0]
					   ,'nicotine' : aRawDetails[1]
					   ,'co' : aRawDetails[2]
					   ,'harm' : aRawDetails[3]
					   ,'category' : aRawDetails[4]
					};

	var aHarmCategory = new Array(
		'No Category'
		,'Ultralight'
		,'Very light'
		,'Light'
		,'Medium'
		,'Heavy'
		,'Very Heavy'
		,'Ultraheavy'
		);

	iPos = aTypeDetails['type'].indexOf(' (');
	aTypeDetails['type'] = aTypeDetails['type'].substr(0, iPos);
	aTypeDetails['category'] = 'Category ' + aTypeDetails['category'] + ' (' + aHarmCategory[aTypeDetails['category']] + ')';
	aTypeDetails['harm'] += '%';


	var aDetails = oDetails.getElementsByTagName('dd');
	
	for (var iDD = 0; iDD < aDetails.length; iDD++)
	{
		var aSpans = aDetails[iDD].getElementsByTagName('span');
			if (aSpans && aSpans.length > 0)
			{
				aSpans[0].innerHTML = aTypeDetails[aDetails[iDD].className];
			}
	}

	return false;
}


