﻿//
// funcionality for client-side GoopSite pages
//

// is the site is opened in preview mode
function isSkinPreview() {
    return window.name == 'frmMiddle';
}

// When the site is opened in preview mode, it uses the temporary stylesheet
function includeSiteCss() {
    if (isSkinPreview())
        document.write("<link rel='stylesheet' type='text/css' href='" + siteSysPath + "temp.css' />");
    else
        document.write("<link rel='stylesheet' type='text/css' href='" + siteSkinPath + "/style.css' />");
}
includeSiteCss();


// Web/Catalog/CatalogItem.aspx
//
// called on selection of extra and on page load
// updates the total price and also sets a hidden CSV field of every item extra that's selected. 
// the CSV is in format: itemExtra_4,itemExtra_5,itemExtra_7,
// where each number is the priority of an extra that's selected
function updateTotalPriceFromExtras() {
    // reset
    hdn.value = '';
    var price = basePrice;
    
	// iterate controls, add the price of checked items
	for (i=0; i<document.forms[0].elements.length; i++) 
	{
		var el = document.forms[0].elements[i];
		
		// drop-down list
		if (el.tagName == 'SELECT' && el.getAttribute('name') != null && el.getAttribute('name').indexOf('itemExtra_') > -1)
		{
			if (el.selectedIndex != null && el.options[el.selectedIndex] != null) 
			{
				// add up the price
			    price += eval(el.options[el.selectedIndex].value);

			    // to find the priority of the selected option, get the priority of the ddl and add the selected index
			    var ddlPriority = el.getAttribute('name').substring(el.getAttribute('name').indexOf('itemExtra_') + 'itemExtra_'.length);
			    var extraPriority = eval(ddlPriority) + el.selectedIndex;
			    hdn.value += 'itemExtra_' + extraPriority+ ',';
			}
		}
		
		// checkbox and radio
		var node = el.parentNode;
		if (node != null && node.getAttribute('name') != null && node.getAttribute('name').indexOf('itemExtra_') > -1 && el.checked) 
		{
			// add up the price
		    price += eval(node.getAttribute('price'));
			
			// add name to hidden field
			hdn.value += node.getAttribute('name') + ',';
		}
	}

	span.innerHTML = price.toFixed(2) + ' ' + currencySymbol;
}
