// Copyright (c) Stephen Huneck Gallery


// JavaScript Document
// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function initializeProductDisplay(pricingMode) {
	var dbg=false;
	var msg = '';

	setPricing(pricingMode);

	tableRow = getTableRow();
	var url = document.URL;
	if(dbg) alert(url);
	var productIdList = document.getElementsByName('product-id');
	var productIdArray = new Array();
	var i=0;
	var productCount = 0;
	for (i=0; i < productIdList.length; ++i) {
		++productCount;
		productId = productIdList[i].value;
		categoryId = document.getElementById('CATEGORY-ID-' + productId).value;
		msg += '\n' + i + ' p_id: ' + productId + '  c_id: ' +  categoryId;
		productIdArray.push(productId);
	}
	if(dbg) alert(Date() + msg);

	// This applies when ppc=print
	var optionList = new Array();
	for (i in productIdArray) {
		productId = productIdArray[i];
		categoryId = document.getElementById('CATEGORY-ID-' + productId).value;
		msg = '\n' + i + ' p_id: ' + productId + '  c_id: ' +  categoryId;
		if(dbg) alert(Date() + msg);
		// Handle inventory
		inventory = document.getElementById('INVENTORY-' + productId).value;
		if (inventory >= 0 && categoryId != 'promotion') {
			e = document.getElementById('ADD-TO-CART-' + productId)
			if (e != null)
			if ( (categoryId != "nonprofit") && (categoryId != "onsale") ) 
					e.style.visibility="visible";
				//alert(inventory);
		}

		if (productCount == 1 && (categoryId == "print" || categoryId == "crayon")) {
			switch (categoryId) {
			case 'crayon':
					// document.getElementById('DOG-NAME-' + productId).style.display = tableRow;
					// document.getElementById('DOG-NAME-TEXT-' + productId).style.display = tableRow;
			case 'print':
			case 'woodcut':

				var dogs = document.getElementById('DOGS-' + productId).value;

				var format = document.getElementById('FORMAT-' + productId).value;
				if ((format == "giclee") || (format == 'giclee-full-edition')) {
					optionList = document.getElementsByName('option|printtype|' + productId);
					optionList[1].disabled = true;
				}
				if ((format == "large-giclee")) {
					optionList = document.getElementsByName('option|printtype|' + productId);
					optionList[1].disabled = true;
				}

				var optionMessage = "";
				switch (dogs)  {
				case '':
					break;
				case 'lab':
					document.getElementById('LAB1-COLOR-FIELDS-' + productId).style.display = tableRow;
					optionList = document.getElementsByName('option|lab1color|' + productId);
					optionList[0].checked = true;
					break;
				case 'lab-lab':
					document.getElementById('LAB1-COLOR-FIELDS-' + productId).style.display = tableRow;
					document.getElementById('LAB2-COLOR-FIELDS-' + productId).style.display = tableRow;
					optionList = document.getElementsByName('option|lab1color|' + productId);
					optionList[0].checked = true;
					optionList = document.getElementsByName('option|lab2color|' + productId);
					optionList[0].checked = true;
					break;
				case 'golden':
					document.getElementById('GR1-COLOR-FIELDS-' + productId).style.display = tableRow;
					optionList = document.getElementsByName('option|gr1color|' + productId);
					optionList[0].checked = true;
					break;
				case 'golden-golden':
					document.getElementById('GR1-COLOR-FIELDS-' + productId).style.display = tableRow;
					document.getElementById('GR2-COLOR-FIELDS-' + productId).style.display = tableRow;
					optionList = document.getElementsByName('option|gr1color|' + productId);
					optionList[0].checked = true;
					optionList = document.getElementsByName('option|gr2color|' + productId);
					optionList[0].checked = true;
					break;
				case 'dachshund':
					document.getElementById('DACH1-COLOR-FIELDS-' + productId).style.display = tableRow;
					optionList = document.getElementsByName('option|dach1color|' + productId);
					optionList[0].checked = true;
					break;
				}
				setPrintOptions(productId);
				displayPrint(productId);
				calculatePrice(productId);
				break;
			}
		}
		// This applies when we are on a search page

		else if ( (url.search("ppinc=4up") > 0) || (url.search("ppinc=nonprofit") > 0) || (url.search("ppinc=search") > 0) /*|| (url.search("ppinc") < 0)*/  ) {
			for (i in productIdArray) {
				productId = productIdArray[i];
				inventory = document.getElementById('INVENTORY-' + productId).value;
				discountPct = getDiscountPercent(productId);
				// discountPct = document.getElementById('DISCOUNT-' + productId).value;
				if (inventory < 0) {
					discountPct = 0;
					html = "<br>Out of stock";
					document.getElementById('DISCOUNT-TEXT-' + productId).innerHTML = html;
				}
				if (validateInt(discountPct) && discountPct > 0) {
					html = "<br>" + discountPct + "% off";
					document.getElementById('DISCOUNT-TEXT-' + productId).innerHTML = html;
				}
				else if (discountPct > 0) {
					html = "<br>" + "On sale";
					document.getElementById('DISCOUNT-TEXT-' + productId).innerHTML = html;
				}
			}
		}
		// default product page
		else if (categoryId != 'nonprofit') {
			switch (categoryId) {
			case 'tee-shirt-jm':
				var optionShirtSizeList = document.getElementsByName('option|shirtsize|' + productId);
				optionShirtSizeList[3].disabled = true;
				optionShirtSizeList[4].disabled = true;
				break;
			}
			setNonPrintOptions(productId);
			displayProduct(productId);
			calculatePrice(productId);
		}
	}

	return;
}


// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function changeDogColor(productId)	{
	setPrintOptions(productId);
	displayPrint(productId);
	calculatePrice(productId);
}

// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function changePrintFrame(productId)	{
	setPrintOptions(productId);
	displayPrint(productId);
	calculatePrice(productId);
}

// function to change print of diaplayed image
// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function changePrintType(productId) {
	setPrintOptions(productId);
	displayPrint(productId);
	calculatePrice(productId);
}

// function to change size of diaplayed image
// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function changePrintSize(productId) {
	setPrintOptions(productId);
	displayPrint(productId);
	calculatePrice(productId);
}

// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function changeLithographFrame(productId)	{
//	displayPrint(productId);
	calculatePrice(productId);
}

// function to change size of diaplayed image
// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function changeTeeShirtSize(productId) {
	calculatePrice(productId);
}

// function to change size of diaplayed image
// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function changeItemSize(productId) {
	calculatePrice(productId);
}


// function to set the print options based upon availability
// woodcut - one size, all frames
// giclee - two sizes
// large giclee - 
// dogs
// lab
// lab-lab
// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function setPrintOptions(productId) {

	// Get print type info
	dbg = false;

	printType = getCheckedOptionAlt(productId, 'printtype');
	printSize = getCheckedOptionAlt(productId, 'printsize');
	dogColor = getCheckedOptionAlt(productId, 'lab1color');
	frameType = getCheckedOptionAlt(productId, 'frametype');
	categoryId = document.getElementById('CATEGORY-ID-' + productId).value;

// Set printType to full edition as special case
	format = document.getElementById('FORMAT-' + productId).value;
	priceOverride = document.getElementById('PRICE-OVERRIDE-' + productId).value;
	if (format == 'giclee-full-edition') {
		printType = format;
	}
	if (format == 'large-giclee') {
		printType = format;
	}
	if (printType == 'woodcut') {
		printSize = 'large';
	}
	if (categoryId == 'crayon') {
		printType = 'crayon';
	}

	if(dbg) alert ( ''
		+ '\n' + 'printType:  ' + printType
		+ '\n' + 'printSize:  ' + printSize
		+ '\n' + 'dogColor:   ' + dogColor
		);

	optionPrintTypeList = document.getElementsByName('option|printtype|' + productId);
	optionPrintSizeList = document.getElementsByName('option|printsize|' + productId);
	optionDog1ColorList = document.getElementsByName('option|lab1color|' + productId);

	// Availability - if code is present, print is NOT available
	availability = document.getElementById('AVAILABILITY-' + productId).value;
	dogs = document.getElementById('DOGS-' + productId).value;
	switch (printType) {
	case 'woodcut':
		optionPrintSizeList[0].disabled = true;
		optionPrintSizeList[1].disabled = false;
		optionPrintSizeList[2].disabled = true;
		optionPrintSizeList[1].checked = true;
		break;
	case 'giclee':
		optionPrintSizeList[0].disabled = false;
		optionPrintSizeList[1].disabled = false;
		optionPrintSizeList[2].disabled = false;
		break;
	case 'large-giclee':
		optionPrintSizeList[0].disabled = true;
		optionPrintSizeList[1].disabled = false;
		optionPrintSizeList[1].checked = true;
		break;
	case 'giclee-full-edition':
		optionPrintSizeList[0].disabled = true;
		optionPrintSizeList[1].disabled = false;
		optionPrintSizeList[2].disabled = true;
		optionPrintSizeList[1].checked = true;
		break;
	case 'crayon':
		optionPrintTypeList[1].disabled = true;
		break;
	default:
		break;
	}
		// Handle availability

	switch (dogs) {
	case 'lab':
		optionDog1ColorList[0].disabled = false;
		optionDog1ColorList[1].disabled = false;
		optionDog1ColorList[2].disabled = false;
		if ((printSize == 'large') || (printType == 'woodcut') || (printType == 'giclee-full-edition')) {
			switch (printType) {
			case 'woodcut':
				formatToken = 'wc';
				break;
			case 'giclee':
				formatToken = 'lg';
				break;
			case 'giclee-full-edition':
				formatToken = 'se';
				break;
			}
			count = 0;
			if (availability.search(formatToken+'-blk') >=0 ) { 
				optionDog1ColorList[0].disabled = true; 
				count +=1; 
			}
			if (availability.search(formatToken+'-yel') >=0 ) { 
				optionDog1ColorList[1].disabled = true; 
				count +=2; 
			}
			if (availability.search(formatToken+'-choc') >=0 ) { 
				optionDog1ColorList[2].disabled = true; 
				count +=4; 
			}
			switch (count) {
			case 7:
				optionPrintSizeList[0].checked = true;
				optionDog1ColorList[0].disabled = false;
				optionDog1ColorList[1].disabled = false;
				optionDog1ColorList[2].disabled = false;
				break;
			case 6:
				optionDog1ColorList[2].checked = true;
				break;
			case 5:
				optionDog1ColorList[1].checked = true;
				break;
			case 3:
				optionDog1ColorList[0].checked = true;
				break;
			case 1:
				if (dogColor == 'blk') optionDog1ColorList[1].checked = true;
				break;
			case 2:
				if (dogColor == 'yel') optionDog1ColorList[2].checked = true;
				break;
			case 4:
				if (dogColor == 'choc') optionDog1ColorList[0].checked = true;
				break;
			}
		}
		else if (printSize == 'small') {
			optionDog1ColorList[0].disabled = false;
			optionDog1ColorList[1].disabled = false;
			optionDog1ColorList[2].disabled = false;
		}
		break;
		case '':
			if (availability.search('lg') >=0 ) { 
				optionPrintSizeList[1].disabled = true;
			}
			if (availability.search('wc') >=0 ) { 
				optionPrintTypeList[1].disabled = true;
			}
			break;
		}

	smallSizePrice = 0 ;
	largeSizePrice = 0 ;
	deluxeSizePrice = 0 ;
	smallFramePrice = 0 ;
	largeFramePrice = 0 ;
	deluxeFramePrice = 0 ;
	largeTigerMapleFramePrice = 0 ;
	deluxeTigerMapleFramePrice = 0 ;

	smallSizePriceD = '' ;
	largeSizePriceD = '' ;
	deluxeSizePriceD = '' ;

	// Override global pricing as set in agoracart variable PRICE-OVERRIDE

	eval(priceOverride) ;

	discountPct = getDiscountPercent(productId);
	var inventory = document.getElementById('INVENTORY-' + productId).value;

	//discountPct = 0;
	if (inventory < 0) discountPct = 0;
	if (discountPct == "") (+discountPct);
	
	discountFactor = (1-discountPct/100);

	// set discounts
	switch (printType) {

	case 'giclee':
	case 'crayon':
	case 'large-giclee':

		smallSizePrice = SmallGicleePrice ;
		largeSizePrice = LargeGicleePrice ;
		deluxeSizePrice = DeluxeGicleePrice ;

		smallSizePriceD = (SmallGicleePrice - SmallGicleePriceDiscountAmount) * discountFactor ;
		largeSizePriceD = (LargeGicleePrice - LargeGicleePriceDiscountAmount) * discountFactor ;;
		deluxeSizePriceD = (DeluxeGicleePrice - DeluxeGicleePriceDiscountAmount) * discountFactor ;;

		smallFramePrice = SmallGicleeFramePrice ;
		largeFramePrice = LargeGicleeFramePrice ;
		deluxeFramePrice = DeluxeGicleeFramePrice ;
		largeTigerMapleFramePrice = LargeGicleeTigerMapleFramePrice ;
		deluxeTigerMapleFramePrice = DeluxeGicleeTigerMapleFramePrice ;

		smallFramePriceD = SmallGicleeFramePrice * discountFactor;
		largeFramePriceD = LargeGicleeFramePrice * discountFactor;
		deluxeFramePriceD = DeluxeGicleeFramePrice * discountFactor;
		largeTigerMapleFramePriceD = LargeGicleeTigerMapleFramePrice * discountFactor;
		deluxeTigerMapleFramePriceD = DeluxeGicleeTigerMapleFramePrice * discountFactor;

		break;

	case 'giclee-full-edition':
		largeSizePrice = LargeGicleeFEPrice ;
		largeSizePriceD = (LargeGicleeFEPrice - LargeGicleeFEPriceDiscountAmount) * discountFactor ;;

		largeFramePrice = LargeGicleeFEFramePrice ;
		largeTigerMapleFramePrice = LargeGicleeFETigerMapleFramePrice ;

		largeFramePriceD = LargeGicleeFEFramePrice * discountFactor;
		largeTigerMapleFramePriceD = LargeGicleeFETigerMapleFramePrice * discountFactor;

		break;

	case 'woodcut':
		largeSizePrice = LargeWoodcutPrice ;
		largeFramePrice = LargeWoodcutFramePrice ;
		largeTigerMapleFramePrice = LargeWoodcutTigerMapleFramePrice ;
		
		largeSizePriceD = (LargeWoodcutPrice - LargeWoodcutPriceDiscountAmount) * discountFactor ;
		largeTigerMapleFramePriceD = LargeWoodcutTigerMapleFramePrice * discountFactor ;

		break;
	}

	// Set the print options
	switch (printType) {
	case 'woodcut':
	case 'giclee':
	case 'crayon':
	case 'large-giclee':
	case 'giclee-full-edition':
		printSize = getCheckedOptionAlt(productId, 'printsize');
		var optionPrintSizeList = document.getElementsByName('option|printsize|' + productId);
		optionPrintSizeList[0].value = 'Small|' + formatNumber(smallSizePrice,2) * (1-ArtworkContributionPct) ;
		document.getElementById('SMALL-GICLEE-TEXT-' + productId).innerHTML = 'Small $' + formatNumber(smallSizePriceD,2);
		optionPrintSizeList[1].value = 'Large|' + formatNumber(largeSizePrice,2) * (1-ArtworkContributionPct) ;
		document.getElementById('LARGE-GICLEE-TEXT-' + productId).innerHTML = 'Large $' + formatNumber(largeSizePriceD,2);
		optionPrintSizeList[2].value = 'Deluxe|' + formatNumber(deluxeSizePrice,2) * (1-ArtworkContributionPct) ;
		document.getElementById('DELUXE-GICLEE-TEXT-' + productId).innerHTML = 'Deluxe $' + formatNumber(deluxeSizePriceD,2);

		// apply price to frame options
		// special case is tiger maple, which is available in large and deluxe only.
		var optionFrameTypeList = document.getElementsByName('option|frametype|' + productId);
		if(printSize == 'small') {
			optionFrameTypeList[1].value = 'Maple Frame|' + formatNumber(smallFramePrice,2) * (1-NonArtworkContributionPct);
			document.getElementById('MAPLE-FRAME-TEXT-' + productId).innerHTML = 'Maple + $' + formatNumber(smallFramePrice,2);
			optionFrameTypeList[2].value = 'Black Ash Frame|' + formatNumber(smallFramePrice,2) * (1-NonArtworkContributionPct);
			document.getElementById('BLACK-FRAME-TEXT-' + productId).innerHTML = 'Black + $' + formatNumber(smallFramePrice,2);
			if (optionFrameTypeList[3].checked == true) {
				optionFrameTypeList[0].checked = true;
			}
			optionFrameTypeList[3].disabled = true;
		}

		if(printSize == 'large') {
			optionFrameTypeList[1].value = 'Maple Frame|' + formatNumber(largeFramePrice,2) * (1-NonArtworkContributionPct);
			document.getElementById('MAPLE-FRAME-TEXT-' + productId).innerHTML = 'Maple + $' + formatNumber(largeFramePrice,2);
			optionFrameTypeList[2].value = 'Black Ash Frame|' + formatNumber(largeFramePrice,2) * (1-NonArtworkContributionPct);
			document.getElementById('BLACK-FRAME-TEXT-' + productId).innerHTML = 'Black + $' + formatNumber(largeFramePrice,2);
			optionFrameTypeList[3].value = 'Tiger Maple Frame|' + formatNumber(largeTigerMapleFramePrice,2) * (1-NonArtworkContributionPct);
			document.getElementById('TIGER-MAPLE-FRAME-TEXT-' + productId).innerHTML = 'Tiger Maple + $' + formatNumber(largeTigerMapleFramePrice,2);
			optionFrameTypeList[3].disabled = false;
		}

		if(printSize == 'deluxe') {
			optionFrameTypeList[1].value = 'Maple Frame|' + formatNumber(deluxeFramePrice,2) * (1-NonArtworkContributionPct);
			document.getElementById('MAPLE-FRAME-TEXT-' + productId).innerHTML = 'Maple + $' + formatNumber(deluxeFramePrice,2);
			optionFrameTypeList[2].value = 'Black Ash Frame|' + formatNumber(deluxeFramePrice,2) * (1-NonArtworkContributionPct);
			document.getElementById('BLACK-FRAME-TEXT-' + productId).innerHTML = 'Black + $' + formatNumber(deluxeFramePrice,2);
			optionFrameTypeList[3].value = 'Tiger Maple Frame|' + formatNumber(deluxeTigerMapleFramePrice,2) * (1-NonArtworkContributionPct);
			document.getElementById('TIGER-MAPLE-FRAME-TEXT-' + productId).innerHTML = 'Tiger Maple + $' + formatNumber(deluxeTigerMapleFramePriceS,2);
			optionFrameTypeList[3].disabled = false;
		}
	break;
	}

	optionSizeAlt = getCheckedOptionAlt (productId, 'printsize');
	optionFrameAlt = getCheckedOptionAlt (productId, 'frametype');
	optionPrintAlt = getCheckedOptionAlt (productId, 'printtype');
	contributionAmount = 0;
	productAmount = 0;
	if ( (optionPrintAlt == 'giclee') || (optionPrintAlt == 'crayon') ) {
		if (optionSizeAlt == 'small') {
			contributionAmount = (smallSizePriceD) * ArtworkContributionPct ;
			productAmount = (smallSizePriceD) * (1-ArtworkContributionPct) ;
			optionFrameAlt = getCheckedOptionAlt (productId, 'frametype');
			if (optionFrameAlt == 'maple' || optionFrameAlt == 'black') {
				contributionAmount += SmallGicleeFramePrice * NonArtworkContributionPct;
				productAmount += SmallGicleeFramePrice * (1-NonArtworkContributionPct) ;
			}
		}
		if (optionSizeAlt == 'large') {
			contributionAmount = largeSizePriceD * (ArtworkContributionPct) ;
			productAmount = largeSizePriceD * (1-ArtworkContributionPct) ;
			if (optionFrameAlt == 'maple' || optionFrameAlt == 'black') {
				contributionAmount = +contributionAmount + LargeGicleeFramePrice * NonArtworkContributionPct;
				productAmount += LargeGicleeFramePrice * (1-NonArtworkContributionPct) ;
			}
			if (optionFrameAlt == 'tigermaple') {
				contributionAmount = +contributionAmount + largeTigerMapleFramePrice * NonArtworkContributionPct;
				productAmount += largeTigerMapleFramePrice * (1-NonArtworkContributionPct) ;
			}
		}
	}
	if (optionPrintAlt == 'woodcut') {
		contributionAmount = largeSizePriceD * (ArtworkContributionPct) ;
		productAmount = largeSizePriceD * (1-ArtworkContributionPct) ;
		if (optionFrameAlt == 'maple' || optionFrameAlt == 'black') {
			contributionAmount = +contributionAmount + LargeWoodcutFramePrice * NonArtworkContributionPct;
			productAmount += LargeWoodcutFramePrice * (1-NonArtworkContributionPct) ;
		}
		if (optionFrameAlt == 'tigermaple') {
			contributionAmount = +contributionAmount + LargeWoodcutTigerMapleFramePrice * NonArtworkContributionPct;
			productAmount += LargeWoodcutTigerMapleFramePrice * (1-NonArtworkContributionPct) ;
		}
	}

	var productCostList = document.getElementsByName('product-cost|' + productId);
	productCostList[0].checked = true;
	//productCostList[0].value = 'Product-Cost|' + '+' + productAmount;
	html = '<span style="color:green; font-weight:bold;">' + '+$' + formatNumber(productAmount, 2) + '</span>';
	document.getElementById('PRODUCT-COST-TEXT-' + productId).innerHTML = html;

	if (PricingMode == 'nonprofit') {
		var optionContributionList = document.getElementsByName('option|contribution|' + productId);
		optionContributionList[0].checked = true;
		optionContributionList[0].value = 'Contribution|' + '+' + contributionAmount;
		html = '<span style="color:green; font-weight:bold;">' + '+$' + formatNumber(contributionAmount,2) + '</span>';
		document.getElementById('CONTRIBUTION-TEXT-' + productId).innerHTML = html;
	}

		// disable tigermaple for wholesale site
	var url = document.URL;
	if (url.search("wholesale") > 0) {
		optionFrameTypeList[3].disabled = true;
	}
	return;
}


function setNonPrintOptions(productId) {

	// Get print type info
	dbg = false;

	itemPrice = document.getElementById('PRODUCT-PRICE-' + productId).value.replace('$', '');
	optionPrice = getCheckedOptionValue (productId, 'itemsize');

	totalPrice = itemPrice + optionPrice;
	contributionAmount = totalPrice * NonArtworkContributionPct;
	productAmount = totalPrice * (1-NonArtworkContributionPct);

	if (PricingMode == 'nonprofit') {
		var priceOffList = document.getElementsByName('option|priceoff|' + productId);
		priceOffList[0].checked = true;
		priceOffList[0].value = 'PriceOff|' + '-' + formatNumber(contributionAmount,2);
		html = '<span style="color:green; font-weight:bold;">' + '-$' + formatNumber(contributionAmount,2) + '</span>';
		document.getElementById('PRICEOFF-TEXT-' + productId).innerHTML = html;

		var optionContributionList = document.getElementsByName('option|contribution|' + productId);
		optionContributionList[0].checked = true;
		optionContributionList[0].value = 'Contribution|' + '+' + contributionAmount;
		html = '<span style="color:green; font-weight:bold;">' + '+$' + formatNumber(contributionAmount,2) + '</span>';
		document.getElementById('CONTRIBUTION-TEXT-' + productId).innerHTML = html;
	}
}

// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function calculatePrice(productId) {

	var dbg=false;
	
	var optionSizePrice;
	var optionFramePrice;
	var checked;
	var salePrice;
	var discountAmount;
	var contributionAmount;

	var categoryId = document.getElementById('CATEGORY-ID-' + productId).value;

	discountPct = getDiscountPercent(productId);
	// var discountPct = document.getElementById('DISCOUNT-' + productId).value;
	var inventory = document.getElementById('INVENTORY-' + productId).value;
	if (inventory < 0) discountPct = 0;

	if (discountPct == "") (+discountPct);
	switch (categoryId) {
	case 'print':
	case 'crayon':
	case 'woodcut':
	case 'lithograph':
		optionSizePrice = getCheckedOptionValue (productId, 'printsize');
		optionFramePrice = getCheckedOptionValue (productId, 'frametype');
		//dogNamePrice = getCheckedOptionValue (productId, 'dog-name');
		contributionAmount = getCheckedOptionValue (productId, 'contribution');
		productAmount = getCheckedOptionValue (productId, 'product-cost');
		/* remove $ and convert to numeric */
		//	productPrice = document.getElementById('PRODUCT-PRICE-' + productId).value.replace('$', '');
		//	productPriceN = (+productPrice);
		MSRPrice = optionSizePrice + optionFramePrice + contributionAmount;
		//MSRPrice = productAmount + contributionAmount;
		if (validateInt (discountPct) && discountPct > 0) {
			discountAmount = MSRPrice * discountPct / 100;
			salePrice = MSRPrice - discountAmount;
		}
		else if (discountPct != undefined){
			discountAmount = getDiscountAmount(productId, discountPct) ;
			salePrice = MSRPrice - discountAmount;
		}
		//salePrice = MSRPrice;
		break;

	case 'tee-shirt':
		MSRPrice = document.getElementById('PRODUCT-PRICE-' + productId).value.replace('$', '');
		optionSizePrice = getCheckedOptionValue (productId, 'shirtsize');
		MSRPrice = (+MSRPrice) + optionSizePrice;
		discountAmount = (+MSRPrice) * discountPct / 100;
		salePrice = (+MSRPrice) - discountAmount;
		break;

	case 'nonprfit':
		break;

	default:
		MSRPrice = document.getElementById('PRODUCT-PRICE-' + productId).value.replace('$', '');
		optionSizePrice = getCheckedOptionValue (productId, 'itemsize');
		MSRPrice = (+MSRPrice) + optionSizePrice;
		discountAmount = (+MSRPrice) * discountPct / 100;
		salePrice = (+MSRPrice) - discountAmount;
		break;
	}

	html = '';
	if (salePrice != undefined) {
		html += '$' + formatNumber(salePrice,2);
		if (discountPct != 0 && discountPct != 'X') {
			html += '&nbsp;&nbsp;&nbsp;<span style="text-decoration: line-through;">$' + formatNumber(MSRPrice,2) + '</span>';
		}
	}
	document.getElementById('DISPLAY-PRICE-' + productId).innerHTML = html;
	tableRow = getTableRow();

	var optionDiscountList = document.getElementsByName('option|discount|' + productId);
	optionDiscountList[0].checked = true;
	optionDiscountList[0].value = 'Discount|' + '-' + 0;
	if ( (discountPct != 0 || discountAmount != 0) && salePrice > 0 && discountPct != 'X') {
		var optionDiscountList = document.getElementsByName('option|discount|' + productId);
		optionDiscountList[0].checked = true;
		optionDiscountList[0].value = 'Discount|' + '-' + discountAmount;
		html = '<span style="color:red;">' + '-$' + formatNumber(discountAmount,2) + '</span>';
		document.getElementById('DISCOUNT-TEXT-' + productId).innerHTML = html;
		document.getElementById('DISCOUNT-OPTION-' + productId).style.display = tableRow;
	}
	else {
		document.getElementById('DISCOUNT-OPTION-' + productId).style.display = "none";
	}

	if(dbg) alert (''
					+ '\n salePrice: ' + salePrice 
					+ '\n discountPct: ' + discountPct 
					+ '\n discountAmount: ' + discountAmount 
					+ '\n contributionAmount: ' + contributionAmount
					+ '\n optionSizePrice: ' + optionSizePrice
					+ '\n optionFramePrice: ' + optionFramePrice
	 );

}





// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function getDiscountAmount(productId, discountCode) {

	var categoryId = document.getElementById('CATEGORY-ID-' + productId).value;
	discountAmount = 0;

	switch (categoryId) {
	case 'print':
	case 'crayon':
	case 'woodcut':
//	case 'lithograph':

		optionPrintType = getCheckedOptionAlt (productId, 'printtype');
		optionPrintSize = getCheckedOptionAlt (productId, 'printsize');
		optionFrameType = getCheckedOptionValue (productId, 'frametype');
		// giclee
		if (optionPrintType == 'giclee' && optionPrintSize == 'small') discountAmount =+ SmallGicleePriceDiscountAmount ;
		if (optionPrintType == 'giclee' && optionPrintSize == 'large') discountAmount =+ LargeGicleePriceDiscountAmount ;
		if (optionPrintType == 'woodcut' && optionPrintSize == 'large') discountAmount =+ LargeWoodcutPriceDiscountAmount ;
		//alert(discountAmount);
		if (optionSizePrice == LargeGicleeFEPrice) discountAmount =+ LargeGicleeFEPriceDiscountAmount ;

		break;
	}

	return(discountAmount);
}

	
// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function getDiscountPercent(productId) {

	var categoryId = document.getElementById('CATEGORY-ID-' + productId).value;

	switch (categoryId) {
	case 'print':
	case 'crayon':
	case 'woodcut':
//	case 'lithograph':

//	discountPct = document.getElementById('DISCOUNT-' + productId).value;
		optionSizePrice = getCheckedOptionValue (productId, 'printsize');
		optionFramePrice = getCheckedOptionValue (productId, 'frametype');
		// giclee
		discountPercent = 0;
		if (optionSizePrice == SmallGicleePrice) discountPercent = SmallGicleePriceDiscountAmount / SmallGicleePrice ;
		else if (optionSizePrice == LargeGicleePrice) discountPercent = LargeGicleePriceDiscountAmount / LargeGicleePrice ;
		else if (optionSizePrice == LargeWoodcutPrice) discountPercent = LargeWoodcutPriceDiscountAmount / LargeWoodcutPrice ;
		//else discountPercent = 'X';
		break;

	default:
	discountPercent = document.getElementById('DISCOUNT-' + productId).value;
	break;
	}
	return(discountPercent);
}




// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function displayPrint(productId) {
	var html = '';
	var frameDir = '/images/frame/';
	var imageFileExt = '.jpg';
	var dbg=0;

	// get the checked options
	var dog1Color = '';
	var dog2Color = '';
	var c;
	c = getCheckedOptionAlt(productId, 'lab1color');
	if (c != null) dog1Color = c;
	c = getCheckedOptionAlt(productId, 'gr1color');
	if (c != null) dog1Color = c;
	c = getCheckedOptionAlt(productId, 'dach1color');
	if (c != null) dog1Color = c;

	c = getCheckedOptionAlt(productId, 'lab2color');
	if (c != null) dog2Color = c;
	c = getCheckedOptionAlt(productId, 'gr2color');
	if (c != null) dog2Color = c;

	var printSize = getCheckedOptionAlt(productId, 'printsize');
	var frameType = getCheckedOptionAlt(productId, 'frametype');

	// process the image file name
	var imageFile = document.getElementById('IMAGE-FILE-' + productId).value;
	var imageName = imageFile.replace('.jpg', '');
	if (dog1Color == '') {separator1 = '';} else {separator1 = '-';}
	if (dog2Color == '') {separator2 = '';} else {separator2 = '-';}

	// Swap certain color combinations
	if ((dog1Color == 'yel') && (dog2Color == 'red')) {
		dog1Color = 'red';	dog2Color = 'yel';
	}
	if ((dog1Color == 'choc') && (dog2Color == 'blk')) {
		dog1Color = 'blk';	dog2Color = 'choc';
	}
	if ((dog1Color == 'yel') && (dog2Color == 'choc')) {
		dog1Color = 'choc';	dog2Color = 'yel';
	}
	if ((dog1Color == 'yel') && (dog2Color == 'blk')) {
		dog1Color = 'blk';	dog2Color = 'yel';
	}

	imageFile = imageName + separator1 + dog1Color + separator2 + dog2Color + imageFileExt;

	// process image diretory
	categoryId = document.getElementById('CATEGORY-ID-' + productId).value; 

	var imageDir = '';
	var imageDirVar = '';
	if (frameType != "none") {
		imageDirVar += '-framed-' + frameType;
	}

	imageDir = '/images/' + categoryId + '/300'+ imageDirVar + '/';
	imageLargeDir = '/images/' + categoryId + '/600'+ imageDirVar + '/';
	imageDirDefault = '/images/' + categoryId + '/default/';

	discountPct = getDiscountPercent(productId);
	// var discountPct = document.getElementById('DISCOUNT-' + productId).value;
	var inventory = document.getElementById('INVENTORY-' + productId).value;
	if (inventory < 0) discountPct = 0;

	// check if image exists and put out default file if it does not
	var img = new Image(); //document.getElementById('PRODUCT-IMAGE-' + productId);
	img.src = imageDir + imageFile;

	var imageExists = false;
	imageFilePath = imageDir + imageFile;
	imageExists = checkImg(imageFilePath);

	var html = "";
	html = '';
	html += AvailableFormatsMsg;
	if (!imageExists) {
		// Change to default image
		imageFile = document.getElementById('IMAGE-FILE-' + productId).value;
		imageDir = imageDirDefault;
		// Hide click on message
		document.getElementById('CLICK-ON-IMAGE-' + productId).style.visibility = "hidden";

		// Add explanation message
		html += ImageNotAvailableMsg;
	}
	else {
		document.getElementById('CLICK-ON-IMAGE-' + productId).style.visibility = "visible";
		//html = '<span style="background:none; color:green; font-weight:bold; text-align:left; font-size:6pt">' + 'Debug: File found: ' + imageDir + imageFile + ' ' + '</span>';
	}
	document.getElementById('OPTION-MESSAGE-' + productId).innerHTML = html;

	if (dbg) alert(''
		  + '\n ' + '  img.name: ' + img.name 
		  + '\n ' + '  img.src: ' + img.src 
		  + '\n ' + '  img.width: ' + img.width
		  + '\n ' + '  img.onLoad: ' + img.onLoad
	);

	if (validateInt(discountPct) && discountPct > 0  && categoryId != 'promotion') {
		html = '<div style="color:red; font-size:9pt">Buy Today and Save ' + discountPct + '%</div>';
		document.getElementById('PRODUCT-DISCOUNT-'+productId).innerHTML = html;
	}
/*	else if (discountPct != undefined) {
		html = '<div style="color:red; font-size:9pt">xBuy Today and Save $' + getDiscountAmount(productId, discountPct) + '</div>';
		document.getElementById('PRODUCT-DISCOUNT-'+productId).innerHTML = html;
	}
*/
	// Generate html for the image
	html='';
	html+='<span style="font-size:7px; text-align:center;">';
	if (document.getElementById('IMAGE-DISPLAY-SIZE-' + productId).value == '_large') {
		// Make it a link only if the inage exists
		// <a href="%%scripturl%%?cart_id=&p_id=%%ProductID%%&xm=on&ppinc=%%CategoryId%%">
    // <img src="/images/%%CategoryID%%/%%image%%" alt = "%%image%%"></a>

		if (imageExists) {
			html += '<a href="';
			html += '/display-image.php?image=' + imageLargeDir + imageFile;
			//html += imageLargeDir + imageFile;
			html += '">';
			html += '<img  src="' + imageDir + imageFile + '"' + ' alt="' + imageFile + '"' + ' class="ac_product_image">';
			html += '</a>';
		}
		else {
			html+='<img  src="' + imageDir + imageFile + '"' + ' alt="' + imageFile + '"' + ' class="ac_product_image">';
		}
	}
	else {
		html+='<img style="max-width:225px; padding:0px;" src="' + imageDir + imageFile + '"' + ' alt="' + imageFile + '"' ; //+ ' class="ac_product_image">'
	}
	html+='</span>';
	document.getElementById('PRODUCT-IMAGE-SPAN-' + productId).innerHTML = html;

	if (dbg>1) alert(html);

	// Write the info information
	var categoryId = document.getElementById('CATEGORY-ID-' + productId).value;
	if(dbg) alert('productId: ' + productId + '  categoryId: ' + categoryId + '  imageFile: ' + imageFile);

	info = '';
	switch (printType) {
		case 'giclee':
			switch (printSize){
			case "small":
				info += 'Image size: 6" x 7"';
				info += '<br>Paper size: 8 1/2" x 11"';
				switch (frameType){
					case "maple":
						info += '<br>Frame size: 12" x 14"';
						//info += '<br>Vermont maple frame';
						break;
					case "black":
						info += '<br>Frame size: 12" x 14"';
						//info += '<br>Vermont ash frame painted black';
						break;
				}
				break;
			case "large":
				info += '<strong>Limited Edition</strong>';
				info += '<br>Image size: 10" x 13 1/2"';
				info += '<br>Paper size: 13" x 19"';
				switch (frameType){
					case "maple":
						info += '<br>Frame size: 19" x 22"';
						//info += '<br>Vermont maple frame';
						break;
					case "black":
						info += '<br>Frame size: 18" x 21"';
						//info += '<br>Vermont ash frame painted black';
						break;
					case "tigermaple":
						info += '<br>Frame size: 18" x 21"';
						//info += '<br>Vermont tiger maple frame';
						break;
					case "none":
						info += '';
						break;
				}
				break;
			case "deluxe":
				info += '<strong>Limited Edition</strong>';

				info += '<br>Image size: 14" x 17 3/4"';
				switch (frameType){
					case "maple":
						info += '<br>Frame size: 27" x 31"';
						//info += '<br>Vermont maple frame';
						break;
					case "black":
						info += '<br>Frame size: 27" x 31"';
						//info += '<br>Vermont tiger maple frame';
						break;
					case "tigermaple":
						info += '<br>Vermont tiger maple frame';
						//info += '<br>Frame size: 27" x 31"';
						break;
					case "none":
						info += '';
						break;
				}
				break;
			}
		break;
		case 'woodcut':
			info += '<strong>Limited Edition</strong>';
			info += '<br>Image size: 16" x 20"';
			info += '<br>Paper size: 17 1/2" x 25 1/2"';
			switch (frameType){
				case "maple":
					info += '<br>Mat size: 23" x 27"';
					info += '<br>Frame size: 27" x 31"';
					//info += '<br>Vermont maple frame';
					break;
				case "black":
					info += '<br>Mat size: 23" x 27"';
					info += '<br>Frame size: 27" x 31"';
					//info += '<br>Vermont ash frame painted black';
					break;
				case "tigermaple":
					info += '<br>Mat size: 23" x 27"';
					info += '<br>Frame size: 27" x 31"';
					//info += '<br>Vermont tiger maple frame';
					break;
				case "none":
					info += '';
					break;
			}
		break;
		case 'giclee-full-edition':
			info += '<strong>Limited Edition</strong>';
			info += '<br>Image size: 17" x 7"';
			switch (frameType){
				case "maple":
					info += '<br>Mat size: 22" x 12"';
					info += '<br>Frame size: 26" x 16"';
					//info += '<br>Vermont maple frame';
					break;
				case "black":
					info += '<br>Mat size: 22" x 12"';
					info += '<br>Frame size: 26" x 16"';
					//info += '<br>Vermont ash frame painted black';
					break;
				case "tigermaple":
					info += '<br>Mat size: 22" x 12"';
					info += '<br>Frame size: 26" x 16"';
					//info += '<br>Vermont tiger maple frame';
					break;
				case "none":
					info += '';
					break;
			}
		break;
	}
	e = document.getElementById('PRODUCT-INFO-' + productId);
	e.innerHTML = info;

	dbg = false;
	if(dbg>0) alert( ''
		+ 'Dog Mountain Test System '
		+ '\n '
		+ '\n '	+ 'Function: displayPrint: '
		+ '\n '
		+ '\n ' + 'The print has the following characteristics:'
		+ '\n '
		+ '\n ' + 'imageName: ' + imageName + '  '
		+ '\n ' + 'productId: ' + productId + '  '
		+ '\n ' + 'dog1Color: ' + dog1Color + '  '
		+ '\n ' + 'dog2Color: ' + dog2Color + '  '
		+ '\n ' + 'printSize: ' + printSize + '  '
		+ '\n ' + 'frameType: ' + frameType + '  '
		+ '\n ' + 'imageFile: ' + imageFile + '  '
		+ '\n ' + 'imageExists:  ' + imageExists
		+ '\n ' + 'imageDir:  ' + imageDir
		+ '\n ' + 'discountPct:  ' + discountPct
		+ '\n '
	);
	dbg = false;
	
	//enableCustomizeText=false;
	//if (enableCustomizeText) {
	//if(printSize == 'large' && frameType != 'none') {
	//	document.getElementById('SH-CUSTOMIZE-' + productId).style.display = tableRow;
	//	document.getElementById('SH-CUSTOMIZE-TEXT-' + productId).style.display = tableRow;
	//}
	//else {
	//	document.getElementById('SH-CUSTOMIZE-' + productId).style.display = "none";
	//	document.getElementById('SH-CUSTOMIZE-TEXT-' + productId).style.display = "none";
	//}
	//}

	return;
}

// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function displayProduct(productId) {
	var dbg = false;
	// process image diretory
	var imageFile = document.getElementById('IMAGE-FILE-' + productId).value;
	var categoryId = document.getElementById('CATEGORY-ID-' + productId).value;
	var imageDir = '/images/' + categoryId + '/';

// check if image exists and put out default file if it does not
	var img = new Image(); //document.getElementById('PRODUCT-IMAGE-' + productId);
	img.src = imageDir + imageFile;

	var imageExists = false;
	imageExists = checkImg(imageDir + imageFile);

	//alert('exists: ' + imageExists + '  ' + imageDir + imageFile);

	if (!imageExists) {
		html = '<span style="background:none; color:red; font-weight:bold; text-align:left; font-size:6pt">' + 'Debug: Missing file: ' + imageDir + imageFile + ' ' + '</span>';
		document.getElementById('PRODUCT-DEBUG-' + productId).innerHTML = html;
		// Change to default image
		imageFile = document.getElementById('IMAGE-FILE-' + productId).value;
	}
	else {
		if (dbg) {
			html = '<span style="background:none; color:green; font-weight:bold; text-align:left; font-size:6pt">' + 'Debug: File found: ' + imageDir + imageFile + ' ' + '</span>';
			document.getElementById('PRODUCT-DEBUG-' + productId).innerHTML = html;
		}
	}

	// Generate html for discount
	var price = document.getElementById('PRODUCT-PRICE-' + productId).value.replace('$', '');
	discountPct = getDiscountPercent(productId);
	// discountPct = document.getElementById('DISCOUNT-' + productId).value;
	var inventory = document.getElementById('INVENTORY-' + productId).value;
	if (inventory < 0) discountPct = 0;
	if (validateInt(discountPct) && discountPct > 0 && categoryId != 'promotion' && discountPct != 'X') {
		html = '<div style="color:red; font-size:9pt">Buy Today and Save ' + discountPct + '%</div>';
		document.getElementById('PRODUCT-DISCOUNT-'+productId).innerHTML = html;
	}
}


// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function imgIsGood() {
    alert('That image exists!');
}

// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function imgIsBad() {
    alert('That image does no exist!');
}


// Name:	Set price




// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function checkImg (imgURL) {
	var dbg=0;
 	var req = null;
	var resp = false;
 	if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (req != null) {
		req.open("GET",imgURL,false);
		req.send(null);
		if (req.status == 200) {
		// use xmlhttp.responseText or responseXML here
			if(dbg) alert('image ' + imgURL + ' found');
			resp = true;
		}
		else {
			if(dbg) alert('image ' + imgURL + ' not found');
		// handle different response status here
		}
	}
	return(resp);
}


// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function getCheckedOptionValue (productId, option) {
	var checked = -1;
	var optionValue = "";
	dbg=0;

	var optionList = document.getElementsByName('option|' + option + '|' + productId);
	if(dbg) alert(option);
	for (i=0; i < optionList.length; ++i) {
		if (optionList[i].checked) {
			checked = i; break;
		}
	}
	if (checked != -1) 
		optionValue = (+optionList[checked].value.substring(optionList[checked].value.indexOf('|') + 1, optionList[checked].value.length));
	else 
		optionValue = 0;
	return optionValue;
}

// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function getCheckedOptionAlt (productId, option) {
	dbg=0;
	var checked = -1;
	var optionValue = '';
	var optionName = '';
	optionName = 'option|' + option + '|' + productId;
	var optionList = document.getElementsByName(optionName);
	for (i=0; i < optionList.length; ++i) {
		if (optionList[i].checked) {
			checked = i; break;
		}
	}
	if (checked != -1) {
		optionValue = optionList[checked].alt;
	}
	else 
		optionValue = null;
	if(dbg) alert(''
				+ ' option: ' + option
				+ ' optionName: ' + optionName
				+ ' optionValue: ' + optionValue
				);
	return optionValue;
}


// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function setBGColor(color) {
	document.bgColor = color;
}

// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function formatNumber(pnumber,decimals){
	if (isNaN(pnumber)) { return 0};
	if (pnumber=='') { return 0};
	
	var snum = new String(pnumber);
	var sec = snum.split('.');
	var whole = parseFloat(sec[0]);
	var result = '';
	
	if(sec.length > 1){
		var dec = new String(sec[1]);
		dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals)));
		dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals));
		var dot = dec.indexOf('.');
		if(dot == -1){
			dec += '.'; 
			dot = dec.indexOf('.');
		}
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	} else{
		var dot;
		var dec = new String(whole);
		dec += '.';
		dot = dec.indexOf('.');		
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	}	
	return result;
}



// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function limitSize(obj, size) {
	dbg = false;
	if (dbg) { alert (" name: " + obj.name +
			 " rows: " + obj.rows +
			 " size: " + size);
		alert("length: " + obj.value.length);
	}
	if (obj.value.length > size) {
		obj.value=obj.value.substr(0, size);
	// alert ("Exceeded limit");
		return(false);
	}
}







/*
		var img = new Image();
		img.src = print_dir + imageFile;
		if(dbg) alert(
			'src: ' + img.src 
			+ ' width: ' + img.width
		);
*/



/*
var propup = function(o) {
    o.url = (typeof o.url == 'undefined') ? 'http://www.emanueleferonato.com/2007/09/21/complete-javascript-popup-opener/' : o.url;
    o.width = (typeof o.width == 'undefined') ? screen.width/2 : o.width;
    o.height = (typeof o.height == 'undefined') ? screen.height/2 : o.height;
    if((o.width<=1)&&(o.width>0)){o.width*=screen.width}
    if((o.height<=1)&&(o.height>0)){o.height*=screen.height}
    o.xpos = (typeof o.xpos == 'undefined') ? (screen.width/2)-(o.width/2) : o.xpos;
    o.ypos = (typeof o.ypos == 'undefined') ? (screen.height/2)-(o.height/2) : o.ypos;
    o.xoffset = (typeof o.xoffset == 'undefined') ? 0 : o.xoffset;
    o.yoffset = (typeof o.yoffset == 'undefined') ? 0 : o.yoffset;
    o.name = (typeof o.name == 'undefined') ? 'propup' : o.name;
    o.scrollbars = (typeof o.scrollbars == 'undefined') ? 'no' : o.scrollbars;
    o.resizable = (typeof o.resizable == 'undefined') ? 'no' : o.resizable;
    o.status = (typeof o.status == 'undefined') ? 'no' : o.status;
    o.locat = (typeof o.locat == 'undefined') ? 'no' : o.locat;
    o.toolbar = (typeof o.toolbar == 'undefined') ? 'no' : o.toolbar;
 
    if(o.xpos == "left"){o.xpos=0;}
    if(o.xpos == "right"){o.xpos = screen.width-o.width;}
    
    if(o.ypos == "top"){o.ypos=0;}
    if(o.ypos == "bottom"){o.ypos = screen.height-o.height;}
    
    o.xpos += o.xoffset
    o.ypos += o.yoffset
 
    var scrollbarstext = 'scrollbars = '+o.scrollbars+",";
    var resizabletext = 'resizable = '+o.resizable+",";
    var statustext = 'status = '+o.status+",";
    var locationtext = 'location = '+o.locat+",";
    var toolbartext = 'toolbar = '+o.toolbar+",";
 
    features = scrollbarstext+resizabletext+statustext;
    features = features + locationtext+toolbartext;
    features = features + 'width = '+o.width+',height = '+o.height;
    features = features + ',top = ' + o.ypos;
    features = features + ',left = ' + o.xpos;
        
    var win = null;
    win = window.open(o.url, o.name, features);
}
 
*/

// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function getTableRow() {
	//alert(BrowserDetect.browser);
	tableRow='table-row';
	switch(BrowserDetect.browser) {
		case 'Explorer':
		case 'Opera':
			tableRow='block';
		break;
		case 'Firefox':
		case 'Safari':
			tableRow='table-row';
		break;
	}
	return (tableRow);
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();







// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function loadXMLDoc(url) 
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}



// --------------------------------------------------------------------------------------
// Name: 
// --------------------------------------------------------------------------------------
function validateInt(iString) {
    // no leading 0s allowed
    return (("" + parseInt(iString)) == iString);
}



/*		
	// Determine whether image is landscape of portrait
	img.src =  imageDir + imageFile;
	if (dbg) alert(''
		  + '\n ' + '  img.name: ' + img.name 
		  + '\n ' + '  img.src: ' + img.src 
		  + '\n ' + '  img.width: ' + img.width
		  + '\n ' + '  img.height: ' + img.height
	);
	var orientation = 'land';
	if (img.height > img.width) {
		orientation = 'port';
	}
	if (img.height < img.width) {
		orientation = 'land';
	}

	// Set the frame file
	var frameFile = 'frame-' + frameType + '-' + orientation + '.jpg';
	var frameStyle = '';

	var landFramedLoresImageStyle = 'position: absolute;	top: 56px;	left: 87px;	width: 120px;	height :92px;';
	var portFramedLoresImageStyle = 'position: absolute;	top: 56px;	left: 94px;	width: 100px;	height: 120px';

	var landFramedMedresImageStyle = 'position: absolute;	top: 99px;	left: 96px;	width: 216px;	height :166px;';
	var portFramedMedresImageStyle = 'position: absolute;	top: 107px;	left: 110px; width: 186px;	height: 240px';

html='';
	switch (frameType)	{
	case "none" :
		html+='<span style="font-size:7px; text-align:center;">';
			if (document.getElementById('IMAGE-DISPLAY-SIZE-' + productId).value == '_large') {
		html+='<img style="width:600px;" src="' + imageDir + imageFile + '"' + ' alt="' + imageFile + '"' + ' class="ac_product_image">';
		}
		else {
			html+='<img style="max-width:225px; padding:0px;" src="' + imageDir + imageFile + '"' + ' alt="' + imageFile + '"' + ' class="ac_product_image">';
		}
		html+='</span>';
		document.getElementById('PRODUCT-IMAGE-SPAN-' + productId).innerHTML = html;
		break;

	case "maple" :
	case "black" :
	case "tigermaple" :
		frameClass = 'xac_framed_print' + document.getElementById('IMAGE-DISPLAY-SIZE-' + productId).value + '_frame';
		imageClass = 'xac_framed_print' + document.getElementById('IMAGE-DISPLAY-SIZE-' + productId).value + '_image';
		/* hack to get around cascading * /
		if (imageDisplaySize == '_large') {
			if (orientation == 'land') {
				imageStyle = landFramedMedresImageStyle;
				frameStyle = 'width:500px';
			}
			if (orientation == 'port') {
				imageStyle = portFramedMedresImageStyle;
				frameStyle = 'width:500px';
			}
		}
		else {
			if (orientation == 'land') {
				imageStyle = landFramedLoresImageStyle;
				frameStyle = 'width:225px';
			}
			if (orientation == 'port') {
				imageStyle = portFramedLoresImageStyle;
				frameStyle = 'width:225px';
			}
		}

		html+='<div style="position:relative">';
		html+='<img src="' + frameDir + frameFile + '"' + ' class="' + frameClass + '"' + 'style="' + frameStyle + '"' + ' />';
		html+='<span style="font-size:7px; text-align:center;">';
		html+='<img id="PRODUCT-IMAGE-SPAN-"' + productId + ' src="' + imageDir + imageFile + '"' + ' alt="' + imageFile + '"' + ' class="' + imageClass + '"' + 'style="' + imageStyle + '"' + ' />';
		html+='</span>';
		html+='</div>';
		break;
	}
*/


/* 
contributionReport
*/

function initializeContributionReport() {

	var dbg = false;
	if (window.location.href.indexOf("detail") > 0) return;
	var baseurl = document.getElementById('contributionReportBaseURL').value;
/*
	document.getElementById('contributionReportBaseURL') = 'x'+baseurl;
*/
	var d = new Date();
	var monthIndex = d.getMonth();
	var year = d.getFullYear();
	var organization = "";
	var detail = "no";
	var key = "";

	if (dbg) alert(window.location.href + "   " + window.location.href.indexOf("detail"));

	var monthName = "";
	if (monthIndex == 0) monthName = "January";
	if (monthIndex == 1) monthName = "February";
	if (monthIndex == 2) monthName = "March";
	if (monthIndex == 3) monthName = "April";
	if (monthIndex == 4) monthName = "May";
	if (monthIndex == 5) monthName = "June";
	if (monthIndex == 6) monthName = "July";
	if (monthIndex == 7) monthName = "August";
	if (monthIndex == 8) monthName = "September";
	if (monthIndex == 9) monthName = "October";
	if (monthIndex == 10) monthName = "November";
	if (monthIndex == 11) monthName = "December";

	newurl = baseurl + '&year=' + year + '&month=' + monthName + '&detail=' + detail ;
	monthName = monthName.toLowerCase();

	// alert(newurl);
	// e = document.getElementById(monthName);
	// e.selected = true;

	//window.location.href = newurl;

}

function contributionReportLogin() {
	
	user = document.getElementById('user').value;
	key = document.getElementById('password').value;
	organization = "";
	monthName = "";
	year = 0;
	detail = 'no';

	baseurl = document.getElementById('contributionReportBaseURL').value;
	newurl = location.href + '&user=' + user + '&key=' + key ;
	window.location.href = newurl;
}

function contributionReportMonthChange() {
	key = document.getElementById('key').value;
	user = document.getElementById('user').value;
	organization = document.getElementById('organization').value;
	monthName = document.getElementById('month').value;
	year = document.getElementById('year').value;
	detail = "no";
	optionList = document.getElementsByName('detail');
	if (optionList[0].checked == true) detail = optionList[0].value;
	if (optionList[1].checked == true) detail = optionList[1].value;

	baseurl = document.getElementById('contributionReportBaseURL').value;
	newurl = baseurl + '&organization=' + organization + '&year=' + year + '&month=' + monthName + '&detail=' + detail + '&user=' + user + '&key=' + key ;
	window.location.href = newurl;	
}

function contributionReportOrganizationChange() {
	key = document.getElementById('key').value;
	user = document.getElementById('user').value;
	monthName = document.getElementById('month').value;
	year = document.getElementById('year').value;
	detail = "no";
	optionList = document.getElementsByName('detail');
	if (optionList[0].checked == true) detail = optionList[0].value;
	if (optionList[1].checked == true) detail = optionList[1].value;

	if (user='dogmt') organization = document.getElementById('organizationList').value;
	else 	organization = document.getElementById('organization').value;

	baseurl = document.getElementById('contributionReportBaseURL').value;
	newurl = baseurl + '&organization=' + organization + '&year=' + year + '&month=' + monthName + '&detail=' + detail + '&user=' + user + '&key=' + key ;
	window.location.href = newurl;	
}

function contributionReportDetailChange() {
	key = document.getElementById('key').value;
	user = document.getElementById('user').value;
	organization = document.getElementById('organization').value;
	monthName = document.getElementById('month').value;
	year = document.getElementById('year').value;
	optionList = document.getElementsByName('detail');
	if (optionList[0].checked == true) detail = optionList[0].value;
	if (optionList[1].checked == true) detail = optionList[1].value;

	baseurl = document.getElementById('contributionReportBaseURL').value;
	newurl = baseurl + '&organization=' + organization + '&year=' + year + '&month=' + monthName + '&detail=' + detail + '&user=' + user + '&key=' + key ;
	window.location.href = newurl;	
}

