//==================================================================
function ShopParseOrder(pQuantity, pName, pPrice, pWeight, pSignature, pTotal, pTotalWeight)
{
var theHTML;
var theValue;

	theHTML = '';
	theValue = new Number(pQuantity.value);
	theValue = theValue.toFixed(0);			// Remove the decimal crap.

	if (theValue > 0)
	{
		theHTML = '<tr><td width=\"20\">';
		theHTML += theValue;

		theHTML += '</td><td width=\"75\">';
		theHTML += ' @ $' + pPrice.toFixed(2);
		
		theHTML += '</td><td width=\"100\">';
		
		if (pSignature)
		{
			theHTML += ' SIGNED ';
		}
		else
		{
			theHTML += '&nbsp;';
		}
		theHTML += '</td><td width=\"300\">';
		theHTML +=  pName;
		
		theHTML += '</td><td align=\"right\" width=\"75\">';
		theHTML += '$' + Number(theValue * pPrice).toFixed(2);
		pTotal[0] += theValue * pPrice;
		
		theHTML += '</td><td align=\"right\" width=\"75\">';
		theHTML += Number(theValue * pWeight).toFixed(1) + ' oz';
		pTotalWeight[0] += theValue * pWeight;
		
		theHTML += '</td></tr>';
		//alert(theHTML);
	}

	return theHTML;
}

//==================================================================
function ShopTest()
{
}

//==================================================================
function ShopViewOrder()
{
var theError;
var theHTML;
var theTotal;
var theWeight;
var theWindow;

	/* I want a number to be passed by reference and the only way I can
		do this is to create an object.
	*/
	theTotal = new Array(1);
	theTotal[0] = 0;

	theWeight = new Array(1);
	theWeight[0] = 0;

	theHTML  = '<html>';
	theHTML += '<head>';
	theHTML += '<link type=\"text/css\" rel=\"stylesheet\" href=\"style_normal.css\" media=\"screen\">';
	theHTML += '<script type=\"text/javascript\" language=\"javascript\">';
	theHTML += 'function CreateEmail(){}';
	theHTML += '</script>';
	theHTML += '</head>';
	theHTML += '<body>';
	
	theHTML += '<font size=\"5\"><b>Spilled Milk Order</b></font><br>';
	
	theHTML += '<table>';
	theHTML += ShopParseOrder(CiCiPreview,		'CiCi Miniseries Preview', 2.50, 2.9, false, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCiPreviewSig,	'CiCi Miniseries Preview', 2.50, 2.9, true, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCiSampler,		'CiCi Color Sampler', 2.50, 1.0, false, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCiSamplerSig,	'CiCi Color Sampler', 2.50, 1.0, true, theTotal, theWeight);
	
	theHTML += ShopParseOrder(CiCi01Finch,		'CiCi Miniseries #1 (Dave Finch Cover)', 2.99, 2.5, false, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi01FinchSigned,'CiCi Miniseries #1 (Dave Finch SIGNED)', 7.49, 2.5, false, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi01FinchSig,	'CiCi Miniseries #1 (Dave Finch Cover)', 2.99, 2.5, true, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi01FinchSignedSig,'CiCi Miniseries #1 (Dave Finch SIGNED)', 7.49, 2.5, true, theTotal, theWeight);
	
	theHTML += ShopParseOrder(CiCi01Moore,		'CiCi Miniseries #1 (Monte Moore Cover)', 2.99, 2.5, false, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi01MooreSigned,'CiCi Miniseries #1 (Monte Moore SIGNED)', 7.49, 2.5, false, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi01MooreSig,	'CiCi Miniseries #1 (Monte Moore Cover)', 2.99, 2.5, true, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi01MooreSignedSig,'CiCi Miniseries #1 (Monte Moore SIGNED)', 7.49, 2.5, true, theTotal, theWeight);
	
	theHTML += ShopParseOrder(CiCi02Benitez,	'CiCi Miniseries #2 (Joe Benitez Cover)', 2.50, 2.2, false, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi02BenitezSigned,'CiCi Miniseries #2 (Joe Benitez SIGNED)', 7.00, 2.2, false, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi02BenitezSig,	'CiCi Miniseries #2 (Joe Benitez Cover)', 2.50, 2.2, true, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi02BenitezSignedSig,	'CiCi Miniseries #2 (Joe Benitez SIGNED)', 7.00, 2.2, true, theTotal, theWeight);
	
	theHTML += ShopParseOrder(CiCi02Moore,		'CiCi Miniseries #2 (Monte Moore Cover)', 2.50, 2.2, false, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi02MooreSigned,'CiCi Miniseries #2 (Monte Moore SIGNED)', 7.00, 2.5, false, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi02MooreSig,	'CiCi Miniseries #2 (Monte Moore Cover)', 2.50, 2.2, true, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi02MooreSignedSig,'CiCi Miniseries #2 (Monte Moore SIGNED)', 7.00, 2.5, true, theTotal, theWeight);
	
	theHTML += ShopParseOrder(CiCi03Cha,		'CiCi Miniseries #3 (Keu Cha Cover)', 2.50, 2.2, false, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi03ChaSigned,	'CiCi Miniseries #3 (Keu Cha SIGNED)', 7.00, 2.2, false, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi03ChaSig,		'CiCi Miniseries #3 (Keu Cha Cover)', 2.50, 2.2, true, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi03ChaSignedSig,'CiCi Miniseries #3 (Keu Cha SIGNED)', 7.00, 2.2, true, theTotal, theWeight);
	
	theHTML += ShopParseOrder(CiCi03Moore,		'CiCi Miniseries #3 (Monte Moore Cover)', 2.50, 2.2, false, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi03MooreSigned,'CiCi Miniseries #3 (Monte Moore SIGNED)', 7.00, 2.5, false, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi03MooreSig,	'CiCi Miniseries #3 (Monte Moore Cover)', 2.50, 2.2, true, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi03MooreSignedSig,'CiCi Miniseries #3 (Monte Moore SIGNED)', 7.00, 2.5, true, theTotal, theWeight);
	
	theHTML += ShopParseOrder(CiCi04Moore,		'CiCi Miniseries #4 (Monte Moore Cover)', 2.50, 2.2, false, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi04MooreSigned,'CiCi Miniseries #4 (Monte Moore SIGNED)', 7.00, 2.5, false, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi04MooreSig,	'CiCi Miniseries #4 (Monte Moore Cover)', 2.50, 2.2, true, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi04MooreSignedSig,'CiCi Miniseries #4 (Monte Moore SIGNED)', 7.00, 2.5, true, theTotal, theWeight);

	theHTML += ShopParseOrder(CiCi04Park,		'CiCi Miniseries #4 (Andy Park Cover)', 2.50, 2.2, false, theTotal, theWeight);
	theHTML += ShopParseOrder(CiCi04ParkSig,	'CiCi Miniseries #4 (Andy Park Cover)', 2.50, 2.2, true, theTotal, theWeight);

	theHTML += ShopParseOrder(SMsticker,		'Spilled Milk Sticker', 0.25, 0.1, false, theTotal, theWeight);
	theHTML += ShopParseOrder(SMstickerSig,		'Spilled Milk Sticker', 0.25, 0.1, true, theTotal, theWeight);
	theHTML += ShopParseOrder(SMpostcard,		'Spilled Milk Promotional Postcard', 1.00, 0.2, false, theTotal, theWeight);
	theHTML += ShopParseOrder(SMpostcard,		'Spilled Milk Promotional Postcard', 1.00, 0.2, true, theTotal, theWeight);

	theHTML += '<tr><td></td><td></td><td></td><td align=\"right\">Total</td><td align=\"right\">$' + theTotal[0].toFixed(2) + '</td>'
	theHTML += '<td align=\"right\" width=\"75\">' + theWeight[0].toFixed(1) + ' oz</td></tr>';

	if (theTotal[0] > 10.00)
	{
		theHTML += '<tr><td></td><td></td><td></td><td align=\"right\">Envelope & Packaging</td><td align=\"right\">$ 1.00</td>';
		theHTML += '<td align=\"right\" width=\"75\">8.0 oz</td>';
		theWeight[0] += 8.0;
	}
	else
	{
		theHTML += '<tr><td></td><td></td><td></td><td align=\"right\">Envelope & Packaging</td><td align=\"right\">$ 0.50</td>';
		theHTML += '<td align=\"right\" width=\"75\">5.0 oz</td>';
		theWeight[0] += 5.0;
	}

	theHTML += '<tr><td></td><td></td><td></td><td align=\"right\">Shipping</td><td align=\"right\">$ ?.??</td>';
	theHTML += '<td>';
	if (CustZipcode.value)
	{
		if (String(CustCountry.value).toUpperCase() == "CANADA"
		 || String(CustCountry.value).toUpperCase() == "IRELAND"
		 || String(CustCountry.value).toUpperCase() == "ENGLAND")
		{
			theHTML += '<a href=\"http://ircalc.usps.gov/speed.asp?Country=';
			theHTML += StringTitleCase(CustCountry.value);
			theHTML += '&Pounds=0&Ounces=' + theWeight[0].toFixed(1);
			theHTML += '&cmdSubmit=Continue&Contents=0\"';
		}
		else
		{
			theHTML += '<a href=\"http://postcalc.usps.gov/speed.asp?MT=0&OZ=80163';
			theHTML += '&DZ=' + CustZipcode.value;
			theHTML += '&P=&O=' + theWeight[0].toFixed(1);
			theHTML += '&image1.x=2&image1.y=2\"';
		}
		theHTML += ' target=\"_blank\">Calc. Postage</a>';
	}
	theHTML += '</td>';
	theHTML += '<tr><td></td><td></td><td></td><td align=\"right\">Grand Total</td><td align=\"right\">$ ?.??</td>';
	theHTML += '<td align=\"right\" width=\"75\">' + theWeight[0].toFixed(1) + ' oz</td></tr>';
	theHTML += '</tr>';
	
	theHTML += '</table>';
	
	if (OriginalArt.checked)
	{
		theHTML += '<p>I am interested in purchasing original artwork.</p>';
	}

	theHTML += '<p><b>Please send payment to:</b>';
	theHTML += '<br>Parker Smart';
	theHTML += '<br>PO Box 260258';
	theHTML += '<br>Highlands Ranch, CO 80163-0258';
	theHTML += '</p>';
	
	if (PayPal.checked)
	{
		theHTML += '<p>You may send payment via <b>PayPal.com</b> using my e-mail address: psmart@SpilledMilk.com</p>';
	}
	
	if (CustZipcode.value && CustName.value && CustAddr.value && CustCity.value && CustState.value)
	{
		theHTML += '<p><b>Please send the order to the following address:</b>';
		theHTML += '<br>' + StringTitleCase(CustName.value);
		theHTML += '<br>' + StringTitleCase(CustAddr.value);
		theHTML += '<br>' + StringTitleCase(CustCity.value) + ', '
				+ String(CustState.value).toUpperCase() 
				+ ' ' + String(CustZipcode.value).toUpperCase();
	}
	else
	{
		theError = 'The address is incomplete';
	}
	if (CustZipcode.value)
	{
		theHTML += '<br>' + String(CustCountry.value).toUpperCase();
	}
	
	theHTML += '<p>For now you\'re going to have to cut and paste this into an e-mail and send it to: ';
	theHTML += '<a href=\"mailto:psmart@spilledmilk.com\?subject=Spilled Milk Order">psmart@spilledmilk.com</a>.</p>';
	
	
	//theHTML += '<input type=\"button\" value=\"Create E-Mail\" onClick=\"CreateEmail();\">';
	//theHTML += '<input type=\"button\" value=\"Create E-Mail\" onClick=\"CreateEmail();\">';
	
	theHTML += '</body></html>';
	//alert(theHTML);
	
	//theWindow = new Window();
	//theWindow = window.open('about:blank');
	//alert(theWindow);
	//theWindow.document.innerHTML = theHTML;

	if (theError)
	{
		alert(theError);
	}
	else
	{
		window.document.writeln(theHTML);
	}
}
