var bOnOff = false;

function updatesubtotal() {
	var intTotalProducts = document.getElementById( "totalproducts" ).value;
	var dblPricePerPack;
	var intQuantity;
	var dblSubTotal = 0.00;

	for ( var i = 1; i <= intTotalProducts; i++ ) {
		dblPricePerPack = document.getElementById( "price" + i ).value;
		intQuantity = document.getElementById( "qty" + i ).value;
		if ( intQuantity > 0 ) {
		    dblSubTotal = dblSubTotal + ( intQuantity * dblPricePerPack );
		}
		else
		{
			//alert("数量只能输入数字!");
			if (intQuantity != null || intQuantity != "")
			{			
			if ((checknumber(intQuantity)))
			{
				alert("数量只能输入数字!");
			}
			}
		}
	}

	document.getElementById( "subtotal" ).innerHTML = "<span class='price'>RMB:" + formatSubTotal( dblSubTotal ) + "</span>";
}

function checknumber(str)
{
	var i=0;
	
	while (i<str.length)
	{
		if (!((str.charAt(i)>='0' && str.charAt(i)<='9') ))
		{
				return true;
		}
		i++;
	}
	return false;
}

function formatSubTotal(n) {
	var s = "" + Math.round(n * 100) / 100;
	var i = s.indexOf('.');
	if (i < 0) return s + ".00";
	var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3);
	if (i + 2 == s.length) t += "0";
	return t;
}

function swapOnOff( strBaseHref, strProductID ) {
    var objOnOffButton = document.getElementById("onoffbutton");

    if ( bOnOff == true ) {
        swapProduct( strBaseHref + "media/product-images/large/" + strProductID + "_0.jpg", 440, 440 )
        objOnOffButton.src = strBaseHref + "media/images/button-off.gif";
        bOnOff = false;
    } else {
        swapProduct( strBaseHref + "media/product-images/large/" + strProductID + "_10.jpg", 440, 440 )
        objOnOffButton.src = strBaseHref + "media/images/button-on.gif";
        bOnOff = true;
    }
}

function swapProduct( strFilename, strHeight, strWidth, Pd_Name ) {
    var objProductLarge = document.getElementById("large");
    
    objProductLarge.innerHTML = "<a href='"+strFilename+"' title='"+Pd_Name+"' target='_blank'><img src='" + strFilename + "' height='" + strHeight + "' width='" + strWidth + "' border='0' / /></a>"
}
