/*
@@@BUILDINFO@@@ st14ShoppingCart.jsx 466 16-March-2007
*/

/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
*  Copyright 2005 Adobe Systems Incorporated
*  All Rights Reserved.
*
* NOTICE:  All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any.  The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/

if( ( stockphoto.timeKeeperOn != undefined )&&( stockphoto.timeKeeperOn ) )
{
	stockphoto.timeKeeper.st14ShoppingCart        = {};
	stockphoto.timeKeeper.st14ShoppingCart.StTime = new Date();
}

// ShoppingCart namespace and zstringCache instance
stockphoto.shoppingCart = {};
stockphoto.shoppingCart.zc = new stockphoto.zstringCache("st14ShoppingCart");
stockphoto.shoppingCart.zc.dict = "ShoppingCart.txt";
stockphoto.shoppingCart.locale = "";

//--------------------------------------------------------------------
// GLOBAL VARIABLES
//--------------------------------------------------------------------

stockphoto.shoppingCart.standardCntTab = 
{
	TBL_TD1_WIDTH		: "25%",
	TBL_TD2_WIDTH		: "45%",
	TBL_TD3_WIDTH		: "18%",
	TBL_TD4_WIDTH		: "12%",

	EVEN_COLOR			: "#fff9cf",
	ODD_COLOR			: "#FFFFFF",

	SUB_TOTAL_WIDTH1	: "53%",
	SUB_TOTAL_WIDTH2	: "17%",
	MAIN_HDR_TOP 		: "10px",
	MAIN_HDR_LEFT 		: "10px",
	MAIN_HDR_WIDTH 		: "143px",
	MAIN_HDR_HEIGHT 	: "17px",

	MAIN_LINKS_TOP 		: "15px",
	MAIN_LINKS_LEFT 	: "405px",
	MAIN_LINKS_WIDTH 	: "180px",
	MAIN_LINKS_HEIGHT 	: "12px",

	MAIN_TBL_TOP 		: "47px",
	MAIN_TBL_LEFT 		: "10px",
	MAIN_TBL_WIDTH		: "580px",
	MAIN_TBL_HEIGHT 	: "auto",
	MAIN_TBL_OF 		: "auto",

	MAIN_FTR_BGCOLOR 	: "#E3E2e2",
	TBL_PRINT_W 		: "25%",
	TBL_BUTTON_W 		: "20%",
	TBL_BUTTON2_W		: "20%",
	TBL_BUTTON_SP 		: "35%",
	BUTTON_WIDTH		: "110px",
	BUTTON2_CLASS		: "button100",

/*  Watson   Number: 1256703 */
    TTP_FONT_MAC 		: "'Lucida Grande'",
    TTP_FONT_PC  		: "tahoma",
	TTP_FONTSIZE		: "10px",
	TTP_WIDTH			: "130",
	HELP_TOOLTIP_YPOS	: "16",

	THUMBNAIL_WIDTH		: "50",
	THUMBNAIL_HEIGHT	: "50",
	MAIN_TOP_HEIGHT		: "27",
	FOOTER_MARGIN_L		: "-10px",
	FOOTER_MARGIN_R		: "-8px",
	FOOTER_PADDING		: "0px"
};




stockphoto.shoppingCart.setStandardCnvTab=function() 
{
	if ( stockphoto.shoppingCart.locale != stockphoto.core.getValidLocale() ) 
	{
		if ( stockphoto.core.util.loadLocaleData( "st14ShoppingCart.par" ) )
			stockphoto.shoppingCart.locale = stockphoto.core.getValidLocale();
	};
}

stockphoto.shoppingCart.setStandardCnvTab();

with (stockphoto.shoppingCart)
{
	stockphoto.shoppingCart.stringTab = 
	{
		MAIN_FTR_PRINT		: zc.get("$$$/ShoppingCart/Text/main_ftr_print=Print"),
		MAIN_FTR_CBROW		: zc.get("$$$/ShoppingCart/Text/main_ftr_cbrow=Continue Browsing"),
		MAIN_FTR_CHKOUT		: zc.get("$$$/ShoppingCart/Text/main_ftr_chkout=Check Out"),
		MAIN_TITLE			: zc.get("$$$/ShoppingCart/Text/main_title=Shopping Cart"),
		MAIN_ABOUT_YSC		: zc.get("$$$/ShoppingCart/Text/main_about_ysc=About Your Shopping Cart"),
		MAIN_HELP			: zc.get("$$$/ShoppingCart/Text/main_help=Help"),
		
				
/* Watson   Number: 1256703 */
		MAIN_HELP_LINK_TOOLTIP: zc.get("$$$/ShoppingCart/Text/main_help_link_text=Adobe Stock Photos Help"),
		
		
		MAIN_FTR_CSERVICE	: zc.get("$$$/ShoppingCart/Text/main_ftr_cservice=Customer Service"),
		MAIN_FTR_PPOLICY	: zc.get("$$$/ShoppingCart/Text/main_ftr_ppolicy=Privacy Policy"),
		MAIN_FTR_TOSERVICE	: zc.get("$$$/ShoppingCart/Text/main_ftr_toservice=Terms of Service"),
		ESTIMATEDTOTAL		: zc.get("$$$/ShoppingCart/Text/EstimatedTotal=Estimated Total:"),
		TAXINFO				: zc.get("$$$/ShoppingCart/Text/TaxInfo=Note: Tax and Promotion Code will be calculated at checkout"),
		NEWPRICE			: zc.get("$$$/ShoppingCart/Text/NewPrice=New Price!"),
		ITEMREMOVED			: zc.get("$$$/ShoppingCart/Text/ItemRemoved=Not Available!"),
		CARTSTATUS1			: zc.get("$$$/ShoppingCart/Text/CartStatus1=Following items are in your shopping cart but have not yet been purchased."),
		CARTSTATUS2			: zc.get("$$$/ShoppingCart/Text/CartStatus2=Some of the images have new pricing, as noted in the Price column. Please review your order before clicking Check Out."),
		CARTSTATUS3			: zc.get("$$$/ShoppingCart/Text/CartStatus3=Your shopping cart is empty."),
		MAIN_TH_IMAGE		: zc.get("$$$/ShoppingCart/Text/main_th_image=Image"),
		MAIN_TH_RESOLUTION	: zc.get("$$$/ShoppingCart/Text/main_th_resolution=Description"),
		MAIN_TH_PRICE		: zc.get("$$$/ShoppingCart/Text/main_th_price=Price"),
		MAIN_TH_DELETE		: zc.get("$$$/ShoppingCart/Text/main_th_delete=Delete"),
		MAIN_EMPTY_CART_HELP: zc.get("$$$/ShoppingCart/Text/main_empty_cart_help=To add to it, first search for images. Or go to the Favorites tab and open a folder of previous search results, or a folder of saved comps. Then, select the images you want, and click Add to Cart."),
		ERROR_CREATE_HTML	: zc.get("$$$/ShoppingCart/Text/error_create_html=Can not create shopping cart html page."),
		MAIN_PROGRESS		: zc.get("$$$/ShoppingCart/Text/Progress=Processing your order..."),
		LOCAL_SHOPCART		: zc.get("$$$/ShoppingCart/Text/localShopCart=Local Shopping Cart"),
		CUSTOMER_SERVICE	: zc.get("$$$/ShoppingCart/Text/customerService=Customer Service"),
		PRIVACY_POLICY		: zc.get("$$$/ShoppingCart/Text/privacyPolicy=Privacy Policy"),
		TERMS_OF_SERVICE	: zc.get("$$$/ShoppingCart/Text/termsOfService=Terms of Service"),

		tableBegin1			: "<table width='" + standardCntTab.MAIN_TBL_WIDTH + "' border='0' cellspacing='0' cellpadding='0'  BGCOLOR=",
		tableBegin2			: ">",
		tableEnd			: "</table>",
		tableBegin3			: "<table width='" + standardCntTab.MAIN_TBL_WIDTH + "' border='0' cellspacing='0' cellpadding='0'>",
		tableBegin4			: "<table width='" + standardCntTab.THUMBNAIL_WIDTH + "' height='" + standardCntTab.THUMBNAIL_WIDTH + "' border='0' cellspacing='0' cellpadding='0'>",

		himage				: "<tr> <td colspan=4 valign='top' class='line'>&nbsp; </td> </tr>",

		trBegin				: "<tr>",
		trEnd				: "</tr>",

		tdBegin				: "<td align=LEFT>",
		tdBegin1			: "<td class='bold_body' width=" + standardCntTab.TBL_TD1_WIDTH + " align=LEFT>",
		tdBegin2			: "<td class='body' width=" + standardCntTab.TBL_TD2_WIDTH + " align=LEFT>",
		tdBegin3			: "<td class='body' width=" + standardCntTab.TBL_TD3_WIDTH + " align=LEFT>",
		tdBegin4			: "<td class='body' width=" + standardCntTab.TBL_TD4_WIDTH + " align=CENTER>",
		tdBegin_nprice		: "<td class='note' width=" + standardCntTab.TBL_TD3_WIDTH + " align=LEFT> " ,
		tdBegin_body		: '<td class="body" ',
		tdBegin_body_note	: '<td class="note" ',
		tdBegin_bold_small	: '<td class="bold_small" ',
		tdEnd				: "</td>",
		tdBegin6			: "<td align=LEFT rowspan=",
		tdBegin7			: "<td align=CENTER>",

		trEmpty				: "<tr> <td class='body' colspan=3>&nbsp;&nbsp;</td> </tr>",

		boldBegin			: "<b>",
		boldEnd				: "</b>",
		radioBtn			: "<INPUT TYPE=RADIO onKeyUp='ChangePrice()' onClick='ChangePrice()' NAME='SelectImage",
		value				: "VALUE='",
		deleteBtn			: "<A ",
		mouseOvr			: " onMouseOver = \"MouseOver('",
		mouseOut			: " onMouseOut = \"MouseOut('",
		mouseDwn			: " onMouseDown = \"MouseDown('",
		deleteAct			: " onClick='DeleteItem(",
		btnImage			: " <img src='trash_N.gif' border=0 name='",
		imgName				: "img_",

		space				: "&nbsp;",

		odd					: "'" + standardCntTab.ODD_COLOR + "'",
		even				: "'" + standardCntTab.EVEN_COLOR + "'",
		br					: "<br>",
		checked				: " CHECKED",

		refBegin			: "<A class='d' HREF='#' onClick='ImageDetail( ",
		refEnd				: "</A>",

		widthTaxInfo		: ' width=' + standardCntTab.SUB_TOTAL_WIDTH1	+ ' align=LEFT style="padding-right:10px">',
		widthSubTotal		: ' width=' + standardCntTab.SUB_TOTAL_WIDTH2 + ' align=LEFT>',
		widthSubTotalValue	: ' width=' + standardCntTab.TBL_TD3_WIDTH + ' align=LEFT>',

		subtotalDiv			: '<span id="subtotal">  </span>',
		scriptBegin1		: '<SCRIPT type="text/javascript">',
		scriptBegin2		: '<!--',
		currencyLn2			: '    currency =',
		currencyLn3			: '    ChangePrice()',
		scriptEnd1			: '-->',
		scriptEnd2			: '</SCRIPT>',

		rowSpanI			: 3,
		statusLine			: '    ChangeStatus("',
		LF			: '\n'
	}
}

stockphoto.shoppingCart.buildShoppingCartHtmlHeader = function(lscHtmlFile, doc_id)
{
	try
	{
		var doc = stockphoto.documents[doc_id].document;
		var lscHeaderCnv;

		// 1256703
		if( "Windows" == File.fs )
		{
			stockphoto.shoppingCart.standardCntTab.TTP_FONT = stockphoto.shoppingCart.standardCntTab.TTP_FONT_PC;
		}
		else
		{
			stockphoto.shoppingCart.standardCntTab.TTP_FONT = stockphoto.shoppingCart.standardCntTab.TTP_FONT_MAC;
		}
		
		with (stockphoto.shoppingCart)
		{
			lscHeaderCnv =
			{
				MAIN_HDR_TOP : standardCntTab.MAIN_HDR_TOP,
				MAIN_HDR_LEFT : standardCntTab.MAIN_HDR_LEFT,
				MAIN_HDR_WIDTH : standardCntTab.MAIN_HDR_WIDTH,
				MAIN_HDR_HEIGHT : standardCntTab.MAIN_HDR_HEIGHT,

				MAIN_LINKS_TOP : standardCntTab.MAIN_LINKS_TOP,
				MAIN_LINKS_LEFT : standardCntTab.MAIN_LINKS_LEFT,
				MAIN_LINKS_WIDTH : standardCntTab.MAIN_LINKS_WIDTH,
				MAIN_LINKS_HEIGHT : standardCntTab.MAIN_LINKS_HEIGHT,
				
				MAIN_TOP_HEIGHT : standardCntTab.MAIN_TOP_HEIGHT,
				MAIN_TBL_TOP : standardCntTab.MAIN_TBL_TOP,
				MAIN_TBL_LEFT : standardCntTab.MAIN_TBL_LEFT,
				MAIN_TBL_WIDTH : standardCntTab.MAIN_TBL_WIDTH,
				MAIN_TBL_HEIGHT : standardCntTab.MAIN_TBL_HEIGHT,
				MAIN_TBL_OF : standardCntTab.MAIN_TBL_OF,

				MAIN_TITLE : stringTab.MAIN_TITLE,
				MAIN_ABOUT_YSC : stringTab.MAIN_ABOUT_YSC,
				MAIN_HELP : stringTab.MAIN_HELP,

				// Watson   Number: 1256703 
				MAIN_HELP_LINK_TOOLTIP : stringTab.MAIN_HELP_LINK_TOOLTIP,


				MAIN_TH_IMAGE : stringTab.MAIN_TH_IMAGE,
				MAIN_TH_RESOLUTION : stringTab.MAIN_TH_RESOLUTION,
				MAIN_TH_PRICE : stringTab.MAIN_TH_PRICE,
				MAIN_TH_DELETE : stringTab.MAIN_TH_DELETE,

				TBL_TD1_W : standardCntTab.TBL_TD1_WIDTH,
				TBL_TD2_W : standardCntTab.TBL_TD2_WIDTH,
				TBL_TD3_W : standardCntTab.TBL_TD3_WIDTH,
				TBL_TD4_W : standardCntTab.TBL_TD4_WIDTH,

				// 1256703
				TOOL_TIP_FONTSIZE : standardCntTab.TTP_FONTSIZE,
				TOOL_TIP_WIDTH : standardCntTab.TTP_WIDTH,
				TOOL_TIP_FONT :	standardCntTab.TTP_FONT,
				HELP_TOOLTIP_YPOS: standardCntTab.HELP_TOOLTIP_YPOS,					
				
				THUMBNAIL_WIDTH : standardCntTab.THUMBNAIL_WIDTH,
				THUMBNAIL_HEIGHT : standardCntTab.THUMBNAIL_HEIGHT,
				PROGRESS_TEXT : stringTab.MAIN_PROGRESS,
				FOOTER_MARGIN_L : standardCntTab.FOOTER_MARGIN_L,
				FOOTER_MARGIN_R : standardCntTab.FOOTER_MARGIN_R,
				FOOTER_PADDING : standardCntTab.FOOTER_PADDING
			}
		}

		var tempDir		= stockphoto.core.folder.getTempFolder();
		var fileName	= "st14ShoppingCartHeader.htm";
		var headerFile	= File(stockphoto.core.folder.getTemplateFolder() + "/" + fileName);
		
		if (!stockphoto.DL.HTMLUtil.LocalHTMLbyDoc( headerFile, lscHeaderCnv,  fileName,  tempDir, false, doc ) )
		{
			throw("error when converting shopping cart html header");
		}

		var htmHeaderFile = File(tempDir + "/" + fileName);
		htmHeaderFile.open("r");
		htmHeaderFile.encoding = "UTF-8";
		var lineBuf = htmHeaderFile.readln();
		while (!htmHeaderFile.eof)
		{
			lscHtmlFile.writeln(lineBuf);
			lineBuf = htmHeaderFile.readln();
		}
		htmHeaderFile.close();	
	}
	catch (e)
	{
		stockphoto.core.log.logString( 2,"Exception in buildShoppingCartHtmlHeader: " + e );
	}
}

stockphoto.shoppingCart.radioButtonTD = function(lscHtmlFile, cartObject, index, resolutionIndex)
{
	var ret = {};
	ret.checked = false;
	ret.radioTDStr = "";
	
	with (stockphoto.shoppingCart.stringTab)
	{
		ret.radioTDStr += tdBegin2;

		ret.radioTDStr += radioBtn + index + "' " + value + escape(cartObject.resolutionXMLPrice[resolutionIndex]);
		ret.radioTDStr += "+" + escape(cartObject.resolutionXMLPurchaseID[resolutionIndex]) + "'";
		if (cartObject.resolutionXMLPurchaseID[resolutionIndex] == cartObject.selectedPurchaseID)
		{
			ret.radioTDStr += checked;
			ret.checked = true;
		}
		ret.radioTDStr += "> " + cartObject.resolutionXMLDescription[resolutionIndex];
		ret.radioTDStr += tdEnd + LF;
	}
	return ret;
}


stockphoto.shoppingCart.priceTD = function(lscHtmlFile, cartObject, resolutionIndex)
{
	var priceTDStr = "";
	with (stockphoto.shoppingCart.stringTab)
	{
		if (stockphoto.DL.getCurrencyType() != cartObject.selectedCurrency)
		{
			return priceTDStr;
		}
		priceTDStr += tdBegin3;
		var BoxCarPrice = stockphoto.DL.HTMLUtil.ConvertToPriceString( cartObject.resolutionXMLPrice[resolutionIndex], false );
		if( BoxCarPrice != undefined )
		{
			priceTDStr += ( BoxCarPrice.v1 + BoxCarPrice.v2 );
	 	}
		else
		{
			priceTDStr += ( stockphoto.DL.getCurrencySymbol() + " " );
			if (cartObject.selectedCurrency == "JPY")
			{
				var v = parseFloat(cartObject.resolutionXMLPrice[resolutionIndex]);
				priceTDStr += Math.floor(v);
			}
			else
			{
				priceTDStr += cartObject.resolutionXMLPrice[resolutionIndex];
			}
		}
		priceTDStr += tdEnd + LF;
	}
    return priceTDStr;
}

stockphoto.shoppingCart.buildShoppingCartHtmlTableItem = function(lscHtmlFile, cartObject, index)
{
	try
	{
		var resolutions = cartObject.resolutionXMLPurchaseID.length;
		var resolutionIndex = 0;
		var fileName;
		var priceValue = 0;
		var noPrice = false;
		var radioTDObj;
		var tbItemStr = "";
		var priceTDStr = "";
		var script, bAlt, resetR, resetRet={};

		if (resolutions == 0)
		{
			return tbItemStr;
		}

		with (stockphoto.shoppingCart.stringTab)
		{
			// table begin line
			tbItemStr += tableBegin1;
			if ((index % 2) == 0)
			{
				tbItemStr += even;
			}
			else
			{
				tbItemStr += odd;
			}
			tbItemStr += tableBegin2 + LF;

			tbItemStr += himage + LF;

			// First table row
			tbItemStr += trBegin + LF;
			  /* Changes added to show ImageId/ASPRefId */
			if ((stockphoto.core.ImageID.ID == stockphoto.core.ImageIDs.MediaID)|| (cartObject.mediaXMLASPRefID == undefined)
							|| (cartObject.mediaXMLASPRefID == "") || (cartObject.mediaXMLASPRefID == cartObject.mediaXMLMediaID))
			{
				tbItemStr += tdBegin1 + cartObject.mediaXMLMediaID + tdEnd + LF;
			}
			else
			{
				tbItemStr += tdBegin1 + stockphoto.core.getASPRefFromPartner(cartObject.mediaXMLPartnerID,cartObject.mediaXMLMediaID) + tdEnd + LF;
			}		

			if (cartObject.flag == stockphoto.addToCart.LSCKeywords.NewPrice)
			{
				tbItemStr += tdBegin2 + tdEnd + LF;
				tbItemStr += tdBegin_nprice + NEWPRICE + tdEnd + LF;
			}
			else if (cartObject.flag == stockphoto.addToCart.LSCKeywords.ItemRemoved)
			{
				tbItemStr += tdBegin2 + tdEnd + LF;
				tbItemStr += tdBegin_nprice + ITEMREMOVED + tdEnd + LF;
				noPrice = true;
			}		
			tbItemStr += trEnd + LF;
			
			
			// Second table row
			fileName = File(cartObject.thumbnailPath);

			tbItemStr += trBegin + LF;

			tbItemStr += tdBegin6 + rowSpanI + ">" + LF;
			tbItemStr += tableBegin4 + LF;
			tbItemStr += tdBegin7 + LF;
			tbItemStr += scriptBegin1 + LF;
			tbItemStr += scriptBegin2 + LF;
			bAlt       = false;
			resetRet   = stockphoto.core.util.resetFileName( fileName.name );
			// fileName:     ZE_'29'700000736.jpg
			// resetRet.bs:  ZE_\x2729\x27700000736.jpg
			// resetRet.alt: _tmpJpg_ZE__29_700000736.jpg
			if( resetRet.bNeed )
			{
				resetR = new File( stockphoto.core.folder.getMyShoppingCartFolder()+"/"+resetRet.alt );
				if( resetR.exists )
					resetR.remove();
				if( fileName.exists )
				{
					if( fileName.copy( resetR.fsName ) )
					{
						bAlt = true;
					} 
				}				
			}
			if( bAlt )
			{
				script = "CreateImageTag('"+escape( fileName.name )+"','"+escape( resetRet.bs )+"',\""+( resetRet.alt )+"\",true);";
			}
			else
			{
				script = "CreateImageTag('"+escape( fileName.name )+"','"+escape( fileName.name )+"',\""+( fileName.name )+"\",false);";
			}
			tbItemStr += ( script + LF );

			// Add format control
			stockphoto.DL.HTMLUtil.ConvertToPriceString( "1", true );
			if( ( stockphoto.HTMLUtil != undefined )&&
			    ( stockphoto.HTMLUtil.ConvertToPriceStringObj != undefined )&&
			    ( stockphoto.HTMLUtil.ConvertToPriceStringObj.initialized ) )
			{
				tbItemStr += ( '\011CTPobj.p0 = '+stockphoto.HTMLUtil.ConvertToPriceStringObj.p0+';'+ LF );
				tbItemStr += ( '\011CTPobj.p1 = "'+stockphoto.HTMLUtil.ConvertToPriceStringObj.p1+'";'+ LF );
				tbItemStr += ( '\011CTPobj.p2 = '+stockphoto.HTMLUtil.ConvertToPriceStringObj.p2+';'+ LF );
				tbItemStr += ( '\011CTPobj.p3 = '+stockphoto.HTMLUtil.ConvertToPriceStringObj.p3+';'+ LF );
				tbItemStr += ( '\011CTPobj.p4 = "'+stockphoto.HTMLUtil.ConvertToPriceStringObj.p4+'";'+ LF );
			    tbItemStr += ( '\011CTPobj.p5 = "'+stockphoto.HTMLUtil.ConvertToPriceStringObj.p5+'";'+ LF );
				tbItemStr += ( '\011CTPobj.justify = "'+stockphoto.HTMLUtil.ConvertToPriceStringObj.justify+'";'+ LF );
				tbItemStr += ( '\011CTPobj.ScriptSymbol = "'+stockphoto.HTMLUtil.ConvertToPriceStringObj.ScriptSymbol+'";'+ LF );
			};
			tbItemStr += scriptEnd1 + LF;
			tbItemStr += scriptEnd2 + tableEnd + tdEnd + LF;
			
			if (!noPrice)
			{
				radioTDObj = stockphoto.shoppingCart.radioButtonTD(lscHtmlFile, cartObject, index, resolutionIndex);
				if (radioTDObj.radioTDStr == "")
				{
					stockphoto.core.log.logString( 2," Exception in buildShoppingCartHtmlTableItem Radio TD");
					return "";
				}
				tbItemStr += radioTDObj.radioTDStr;
				if (radioTDObj.checked)
				{
					priceValue = cartObject.resolutionXMLPrice[resolutionIndex];
				}
				priceTDStr = stockphoto.shoppingCart.priceTD(lscHtmlFile, cartObject, resolutionIndex);
				if (priceTDStr == "")
				{
					stockphoto.core.log.logString( 2," Exception in buildShoppingCartHtmlTableItem Price TD");
					return "";
				}
				tbItemStr += priceTDStr;
			}
			else
			{
				tbItemStr += tdBegin2 + tdEnd + LF;
				tbItemStr += tdBegin3 + tdEnd + LF;
			}
	              
			tbItemStr += tdBegin4;
			tbItemStr += deleteBtn + mouseOvr + imgName + index + "')\"" + mouseOut + imgName + index + "')\"" + mouseDwn + imgName + index + "')\"" ;
			tbItemStr += deleteAct + index + ")'>" + LF;
			tbItemStr += btnImage + imgName + index  + "'>" + refEnd + LF;
			tbItemStr += tdEnd + LF;
				
			tbItemStr += trEnd + LF;
			
			if (!noPrice)
			{
				// Third to all table rows
				for (var i = 1; i < resolutions; i++)
				{
					resolutionIndex += 1;
					tbItemStr += trBegin + LF;
					if ((i +1) > rowSpanI)
					{
						tbItemStr += tdBegin1 + space + tdEnd + LF;
					}

					radioTDObj = stockphoto.shoppingCart.radioButtonTD(lscHtmlFile, cartObject, index, resolutionIndex);
					if (radioTDObj.radioTDStr == "")
					{
						stockphoto.core.log.logString( 2," Exception in buildShoppingCartHtmlTableItem Radio TD");
						return "";
					}

					tbItemStr += radioTDObj.radioTDStr;
					if (radioTDObj.checked)
					{
						priceValue = cartObject.resolutionXMLPrice[resolutionIndex];
					}
					priceTDStr = stockphoto.shoppingCart.priceTD(lscHtmlFile, cartObject, resolutionIndex);
					if (priceTDStr == "")
					{
						stockphoto.core.log.logString( 2," Exception in buildShoppingCartHtmlTableItem Price TD");
						return "";
					}
					
					tbItemStr += priceTDStr;
					tbItemStr += trEnd + LF;
				}
			
				// fill empty table rows
				if (resolutions < rowSpanI )
				{
					for (var i = resolutions; i < rowSpanI ; i++)
					{
						tbItemStr += trEmpty + LF;
					}
				}	
			}
			// table end line
			tbItemStr += tableEnd + LF;
		}
		
		tbItemStr += " \n";
		return tbItemStr;
		
	}
	catch (e)
	{
		stockphoto.core.log.logString( 2,"Exception in buildShoppingCartHtmlTableItem " + e);
		return "";
	}
}

stockphoto.shoppingCart.buildShoppingCartHtmlItems = function(lscHtmlFile, cartItems)
{
	try
	{
		var hasNewPrice = false;
		var tableStr = "";
		var currencySymbol = stockphoto.DL.getCurrencySymbol();
		for (var i = 0; i < cartItems.length; i++)
		{
			tableStr = stockphoto.shoppingCart.buildShoppingCartHtmlTableItem(lscHtmlFile, cartItems[i], i);
			if (tableStr == "")
				continue;
				
			lscHtmlFile.write(tableStr);
				
			stockphoto.shoppingCart.buildShoppingCartHtmlTableItem(lscHtmlFile, cartItems[i], i);

			if (cartItems[i].flag == stockphoto.addToCart.LSCKeywords.NewPrice)
			{
				hasNewPrice = true;
			}
		}
		
		with (stockphoto.shoppingCart.stringTab)
		{
			// sub total table
			lscHtmlFile.writeln(tableBegin3);
			lscHtmlFile.writeln(himage);

			lscHtmlFile.writeln(trBegin);

//			tdBegin_body_note	<td class="note"
//			widthTaxInfo		width=53% align=LEFT>	
//			TAXINFO				Note: Tax and Promotion Code will be calculated at checkout
//			tdEnd				</td>	
//			
//			tdBegin_bold_small	<td class="bold_small"
//			widthSubTotal		width=17% align=LEFT>
//			ESTIMATEDTOTAL		Estimated Total:
//			tdEnd				</td>
//			
//			tdBegin_body		<td class="body"
//			widthSubTotalValue	width=18% align=LEFT>
//			currencySymbol		&yen;
//			subtotalDiv			<span id="subtotal">  </span>
//			tdEnd				</td>
//			
//			tdBegin4			<td class='body' width=12% align=CENTER>
//			space				&nbsp;
//			tdEnd				</td>
	
			lscHtmlFile.writeln(tdBegin_body_note + widthTaxInfo + TAXINFO + tdEnd);
			lscHtmlFile.writeln(tdBegin_bold_small + widthSubTotal + ESTIMATEDTOTAL + tdEnd);
//			lscHtmlFile.writeln(tdBegin_body + widthSubTotalValue + currencySymbol + subtotalDiv + tdEnd);
			lscHtmlFile.writeln(tdBegin_body + widthSubTotalValue +                  subtotalDiv + tdEnd);
			lscHtmlFile.writeln(tdBegin4 + space + space + tdEnd);

			lscHtmlFile.writeln(trEnd);
			lscHtmlFile.writeln(tableEnd);

			lscHtmlFile.writeln(scriptBegin1);
			lscHtmlFile.writeln(scriptBegin2);

			lscHtmlFile.write(statusLine);
			if (!hasNewPrice)
			{
				lscHtmlFile.writeln(CARTSTATUS1 + '");');
			}
			else
			{
				lscHtmlFile.writeln(CARTSTATUS2 + '");');
			}

			lscHtmlFile.write(currencyLn2);
			if (cartItems.length > 0)
			{
				lscHtmlFile.writeln(" '" + cartItems[0].selectedCurrency + "';");
			}
			else
			{
				lscHtmlFile.writeln(" ;");
			}
			lscHtmlFile.writeln(currencyLn3);

			lscHtmlFile.writeln(scriptEnd1);
			lscHtmlFile.writeln(scriptEnd2);
		}
	}
	catch (e)
	{
		stockphoto.core.log.logString( 2,"Exception in stockphoto.shoppingCart.buildShoppingCartHtmlItems" );
	}
} // currencySymbol

stockphoto.shoppingCart.buildShoppingCartHtmlFooter = function(lscHtmlFile, doc_id)
{
	try
	{
		var doc = stockphoto.documents[doc_id].document;
		var lscFooterCnv;
		with (stockphoto.shoppingCart)
		{
			lscFooterCnv =
			{
				MAIN_FTR_PRINT : stringTab.MAIN_FTR_PRINT,
				MAIN_FTR_CBROW : stringTab.MAIN_FTR_CBROW,
				MAIN_FTR_CHKOUT : stringTab.MAIN_FTR_CHKOUT,

				MAIN_FTR_BGCOLOR : standardCntTab.MAIN_FTR_BGCOLOR,
				MAIN_FTR_CSERVICE : stringTab.MAIN_FTR_CSERVICE,
				MAIN_FTR_PPOLICY : stringTab.MAIN_FTR_PPOLICY,
				MAIN_FTR_TOSERVICE : stringTab.MAIN_FTR_TOSERVICE,

				TBL_PRINT_W : standardCntTab.TBL_PRINT_W,
				TBL_BUTTON_W : standardCntTab.TBL_BUTTON_W,
				TBL_BUTTON_SP : standardCntTab.TBL_BUTTON_SP,

				MAIN_TBL_WIDTH : standardCntTab.MAIN_TBL_WIDTH,
				TBL_BUTTON2_W : standardCntTab.TBL_BUTTON2_W,
				BUTTON2_CLASS : standardCntTab.BUTTON2_CLASS
			}
		}

		// Add hRef URL
		lscFooterCnv.HREF_CSERV = '\"#\" onClick = \"FooterCallback(\'shoppingCart.customerService\')\"';
		lscFooterCnv.HREF_PRIV  = '\"#\" onClick = \"FooterCallback(\'shoppingCart.privacyPolicy\')\"';
		lscFooterCnv.HREF_TERM  = '\"#\" onClick = \"FooterCallback(\'shoppingCart.termsOfService\')\"';
		if( ( stockphoto.core.BoxCar.AnalyzeXmlFileObj != undefined )&&
		    ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners != undefined )&&
		    ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0] != undefined )&&
		    ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners != undefined )&&
		    ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0] != undefined ) )
		{
			var lcb    = stockphoto.core.html.GetLanguageCountryBilling();
			var szTail = "?language="+(lcb.szLanguage)+"&country="+(lcb.szCountry)+"&billing="+(lcb.szBilling)+"&version="+stockphoto.core.BM_3Version;
		    if( ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0].CustomerServiceURL != undefined )&&
		        ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0].CustomerServiceURL.Value != undefined ) )
				lscFooterCnv.HREF_CSERV = '\"'+stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0].CustomerServiceURL.Value+szTail+'\"';
		    if( ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0].PrivacyPolicyURL != undefined )&&
		        ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0].PrivacyPolicyURL.Value != undefined ) )
				lscFooterCnv.HREF_PRIV  = '\"'+stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0].PrivacyPolicyURL.Value+szTail+'\"';
		    if( ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0].TermsOfServiceURL != undefined )&&
		        ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0].TermsOfServiceURL.Value != undefined ) )
				lscFooterCnv.HREF_TERM  = '\"'+stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0].TermsOfServiceURL.Value+szTail+'\"';
		}
		
		var tempDir    = stockphoto.core.folder.getTempFolder();
		var fileName   = "st14ShoppingCartFooter.htm";
		var footerFile = File(stockphoto.core.folder.getTemplateFolder() + "/" + fileName);

		if (!stockphoto.DL.HTMLUtil.LocalHTMLbyDoc( footerFile, lscFooterCnv,  fileName,  tempDir, false, doc ) )
		{
			throw("error when converting shopping cart html footer");
		}

		var htmFooterFile = File(tempDir + "/" + fileName);
		htmFooterFile.open("r");
		htmFooterFile.encoding = "UTF-8";
		var lineBuf = htmFooterFile.readln();
		while (!htmFooterFile.eof)
		{
			lscHtmlFile.writeln(lineBuf);
			lineBuf = htmFooterFile.readln();
		}
		htmFooterFile.close();	
	}
	catch (e)
	{
		stockphoto.core.log.logString( 2,"Exception in buildShoppingCartHtmlFooter: " + e );
	}
}

stockphoto.shoppingCart.setupEnvironment = function(doc_id)
{
	stockphoto.shoppingCart.copyStyleSheet(doc_id);
	
	var sourceFolder = Folder(stockphoto.core.folder.getTemplateFolder() + "/images/ShopCart/");
	var sourceFiles = sourceFolder.getFiles("*.*");
	for (var i = 0; i < sourceFiles.length; i++)
	{
		var destFile = File( stockphoto.core.folder.getMyShoppingCartFolder() + "/" + sourceFiles[i].name);
		sourceFiles[i].copy(destFile);
	}
}

stockphoto.shoppingCart.buildShoppingCartHtml = function(cartItems, lscHtmlFile, doc_id)
{
	try
	{
		with (stockphoto.shoppingCart)
		{
			setupEnvironment(doc_id);
			lscHtmlFile.open("w");
			buildShoppingCartHtmlHeader(lscHtmlFile, doc_id);
			buildShoppingCartHtmlItems(lscHtmlFile, cartItems);
			buildShoppingCartHtmlFooter(lscHtmlFile, doc_id);
		}
	
		lscHtmlFile.close();
		return true;
	}
	catch (e)
	{
		stockphoto.core.log.logString( 2,"Exception in buildShoppingCartHtml" );
		return false;
	}
}

stockphoto.shoppingCart.buildEmptyShoppingCartHtml = function(lscHtmlFile, doc_id)
{
	try
	{
		var doc = stockphoto.documents[doc_id].document;
		var lscHeaderCnv;
		
		// Watson Bug No. 1256703
		if( "Windows" == File.fs )
		{
			stockphoto.shoppingCart.standardCntTab.TTP_FONT = stockphoto.shoppingCart.standardCntTab.TTP_FONT_PC;
		}
		else
		{
			stockphoto.shoppingCart.standardCntTab.TTP_FONT = stockphoto.shoppingCart.standardCntTab.TTP_FONT_MAC;
		}

		with (stockphoto.shoppingCart)
		{
			lscHeaderCnv = 
			{
				MAIN_HDR_TOP : standardCntTab.MAIN_HDR_TOP,
				MAIN_HDR_LEFT : standardCntTab.MAIN_HDR_LEFT,
				MAIN_HDR_WIDTH : standardCntTab.MAIN_HDR_WIDTH,
				MAIN_HDR_HEIGHT : standardCntTab.MAIN_HDR_HEIGHT,

				MAIN_LINKS_TOP : standardCntTab.MAIN_LINKS_TOP,
				MAIN_LINKS_LEFT : standardCntTab.MAIN_LINKS_LEFT,
				MAIN_LINKS_WIDTH : standardCntTab.MAIN_LINKS_WIDTH,
				MAIN_LINKS_HEIGHT : standardCntTab.MAIN_LINKS_HEIGHT,

				MAIN_TBL_TOP : standardCntTab.MAIN_TBL_TOP,
				MAIN_TBL_LEFT : standardCntTab.MAIN_TBL_LEFT,
				MAIN_TBL_WIDTH : standardCntTab.MAIN_TBL_WIDTH,
				MAIN_TBL_HEIGHT : standardCntTab.MAIN_TBL_HEIGHT,
				MAIN_TBL_OF : standardCntTab.MAIN_TBL_OF,

				MAIN_TITLE : stringTab.MAIN_TITLE,
				MAIN_ABOUT_YSC : stringTab.MAIN_ABOUT_YSC,
				MAIN_HELP : stringTab.MAIN_HELP,
				
				// Watson    Number: 1256703 
				MAIN_HELP_LINK_TOOLTIP : stringTab.MAIN_HELP_LINK_TOOLTIP,
				MAIN_FTR_CBROW : stringTab.MAIN_FTR_CBROW,

				MAIN_FTR_BGCOLOR : standardCntTab.MAIN_FTR_BGCOLOR,
				MAIN_FTR_CSERVICE : stringTab.MAIN_FTR_CSERVICE,
				MAIN_FTR_PPOLICY : stringTab.MAIN_FTR_PPOLICY,
				MAIN_FTR_TOSERVICE : stringTab.MAIN_FTR_TOSERVICE,

				TBL_BUTTON_W : standardCntTab.TBL_BUTTON_W,
				MAIN_EMPTY_CART : stringTab.CARTSTATUS3,
				MAIN_EMPTY_CART_HELP : stringTab.MAIN_EMPTY_CART_HELP,
				MAIN_TOP_HEIGHT : standardCntTab.MAIN_TOP_HEIGHT,
				
				// 1256703
				TOOL_TIP_FONTSIZE: standardCntTab.TTP_FONTSIZE,
				TOOL_TIP_WIDTH: standardCntTab.TTP_WIDTH,
				TOOL_TIP_FONT : standardCntTab.TTP_FONT,
				HELP_TOOLTIP_YPOS: standardCntTab.HELP_TOOLTIP_YPOS,					

				
				FOOTER_MARGIN_L : standardCntTab.FOOTER_MARGIN_L,
				FOOTER_MARGIN_R : standardCntTab.FOOTER_MARGIN_R,
				FOOTER_PADDING : standardCntTab.FOOTER_PADDING
			}
		}
		
		lscHeaderCnv.HREF_CSERV = '\"#\" onClick = \"FooterCallback(\'shoppingCart.customerService\')\"';
		lscHeaderCnv.HREF_PRIV  = '\"#\" onClick = \"FooterCallback(\'shoppingCart.privacyPolicy\')\"';
		lscHeaderCnv.HREF_TERM  = '\"#\" onClick = \"FooterCallback(\'shoppingCart.termsOfService\')\"';
		if( ( stockphoto.core.BoxCar.AnalyzeXmlFileObj != undefined )&&
		    ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners != undefined )&&
		    ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0] != undefined )&&
		    ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners != undefined )&&
		    ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0] != undefined ) )
		{
			var lcb    = stockphoto.core.html.GetLanguageCountryBilling();
			var szTail = "?language="+(lcb.szLanguage)+"&country="+(lcb.szCountry)+"&billing="+(lcb.szBilling)+"&version="+stockphoto.core.BM_3Version;
		    if( ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0].CustomerServiceURL != undefined )&&
		        ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0].CustomerServiceURL.Value != undefined ) )
				lscHeaderCnv.HREF_CSERV = '\"'+stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0].CustomerServiceURL.Value+szTail+'\"';
		    if( ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0].PrivacyPolicyURL != undefined )&&
		        ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0].PrivacyPolicyURL.Value != undefined ) )
				lscHeaderCnv.HREF_PRIV  = '\"'+stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0].PrivacyPolicyURL.Value+szTail+'\"';
		    if( ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0].TermsOfServiceURL != undefined )&&
		        ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0].TermsOfServiceURL.Value != undefined ) )
				lscHeaderCnv.HREF_TERM  = '\"'+stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].EComPartners[0].TermsOfServiceURL.Value+szTail+'\"';
		}

		var tempDir    = stockphoto.core.folder.getTempFolder();
		var fileName   = "st14EmptyCart.htm";
		var headerFile = File(stockphoto.core.folder.getTemplateFolder() + "/" + fileName);
		
		if (!stockphoto.DL.HTMLUtil.LocalHTMLbyDoc( headerFile, lscHeaderCnv,  fileName,  tempDir, false, doc ) )
		{
			throw("error when converting shopping cart html header");
		}

		var supportFile = File(tempDir + "/" + fileName);
		supportFile.copy(lscHtmlFile);
		stockphoto.shoppingCart.setupEnvironment(doc_id);
		return true;
	}
	catch (e)
	{
		stockphoto.core.log.logString( 2,"Exception in st14_BuildEmptyShoppingCartHtml" );
		return false;
	}
}

stockphoto.shoppingCart.getShoppingCartData = function()
{
	try 
	{
		var itemCount = stockphoto.addToCart.LSCGetItemCount();
		var cartItems = new Array(itemCount);

		var cartItem;
		for (var i = 0; i < itemCount; i++)
		{
			cartItem = stockphoto.addToCart.LSCGetItem(i);
			cartItems[i] = stockphoto.addToCart.LSCConvertItem2Object(cartItem);
		}
		return cartItems;

	}
	catch (e)
	{
		stockphoto.core.log.logString( 2,"Exception in stockphoto.shoppingCart.getShoppingCartData" );
		return null;
	}
}

stockphoto.shoppingCart.refreshExpiredPrice = function (cartItems, FirstTime, doc_id)
{
	var currentDate = new Date();
	var currentTime = Math.floor(currentDate.getTime() /1000); 
	var numOfExpiredItems = 0;
	var expiredItems = new Array(cartItems.length);

	for (var i = 0; i < cartItems.length; i++)
	{
		expiredItems[i] = undefined;
		for (var j = 0; j < cartItems[i].expirationDate.length; j++)
		{
			if (cartItems[i].expirationDate[j] == "undefined")
			{
				continue;
			}
			if ( cartItems[i].expirationDate[j] < currentTime)  // change this line to test
			{
				stockphoto.core.log.logString( 0,"[SHOPPING CART]  RefreshExpiredPrice CurrentTime= " + currentTime + "     Image Time = "  + cartItems[i].expirationDate[j] );
				var d = new Date(cartItems[i].expirationDate[j] * 1000);
				stockphoto.core.log.logString( 0,"[SHOPPING CART]  GMTString = " + d.toGMTString() );
				stockphoto.core.log.logString( 0,"[SHOPPING CART]  LocaleString = " + d.toLocaleString() );

				numOfExpiredItems ++;
				expiredItems[i] = cartItems[i].thumbnailPath;
				break;
			}
		}
	}

	if (numOfExpiredItems > 0)
	{
		stockphoto.addToCart.RefreshCartItemsPrice(expiredItems, numOfExpiredItems, 0, FirstTime, doc_id);
		return true;
	}
	
	return false;
}

stockphoto.shoppingCart.shoppingCart_Body = function( FirstTime, doc_id )
{
	stockphoto.core.log.logString( 0,"[SHOPPING CART]  Enter st14_ShoppingCart_Body, doc_id : " + doc_id );
	if (stockphoto.documents[doc_id] == undefined)
	{
		stockphoto.core.log.logString( 2,"[SHOPPING CART]  Doc Id is not defined -- stockphoto.shoppingCart.shoppingCart_Body" );
		return;	
	}

	var doc = stockphoto.documents[doc_id].document;

	if (FirstTime)
	{
		var shoppingCart = {};

		// don't save location unless it is one to which we wish to return. - rwe
		stockphoto.core.log.logString( 0,"[SHOPPING CART] path = " + doc.thumbnail.path + "\n");
		var root = doc.thumbnail.path.split(":");
		stockphoto.core.log.logString( 0,"[SHOPPING CART] root = " + root[0] +"\n");

		var lscHtmlFile = new File(stockphoto.core.folder.getMyShoppingCartFolder() + "/" + stockphoto.core.consts.ShoppingCartName);
//		if (doc.thumbnail.displayPath != lscHtmlFile.fsName)
		if ( ! stockphoto.core.util.isDisplayPathEqual( stockphoto.core.util.getDisplayPath( doc.thumbnail, "shoppingCart_Body()" ), lscHtmlFile.fsName ) )
		{
            // Catch 'bridge://...', 'stockphoto://...', and any ASP search folder
			if ((root[0] == "bridge") || ((root[0] == "stockphoto") && (root[1] != "//checkout")) ||
			   (doc.thumbnail.path.indexOf(stockphoto.core.folder.getMyFolder()) >=0) )
			{
				stockphoto.documents[doc_id].shoppingCart = shoppingCart;	
				stockphoto.documents[doc_id].shoppingCart.savedThumbnail = doc.thumbnail;
			}
		}
	}

	stockphoto.core.log.logString( 0,"[SHOPPING CART]  Enter stockphoto.shoppingCart.shoppingCart_Body\n" );
	var cartItems = stockphoto.shoppingCart.getShoppingCartData();

	stockphoto.addToCart.LSCClearAllItemFlag(stockphoto.addToCart.NewPrice);
	// FirstTime will be eventually passed into shoppingCartNewPrice.
	if (stockphoto.shoppingCart.refreshExpiredPrice(cartItems, FirstTime, doc_id))
	{
		return;
	}
	stockphoto.shoppingCart.createNShowHtmlPage(cartItems, FirstTime, doc_id);
}

stockphoto.shoppingCart.shoppingCartNewPrice = function(FirstTime, doc_id)
{
	if (stockphoto.documents[doc_id] == undefined)
	{
		stockphoto.core.log.logString( 2,"[SHOPPING CART]  Doc Id is not defined -- shoppingCartNewPrice" );
		return;	
	}

	var doc = stockphoto.documents[doc_id].document;

	var cartItems = stockphoto.shoppingCart.getShoppingCartData();
	stockphoto.shoppingCart.createNShowHtmlPage(cartItems, FirstTime, doc_id);
}

stockphoto.shoppingCart.createEmptyHtmlPage = function(doc_id)
{
	stockphoto.core.log.logString( 0,"[SHOPPING CART] Enter stockphoto.shoppingCart.createEmptyHtmlPage\n" );
	var lscHtmlFile = new File(stockphoto.core.folder.getMyShoppingCartFolder() + "/" + stockphoto.core.consts.ShoppingCartName);
	stockphoto.shoppingCart.buildEmptyShoppingCartHtml(lscHtmlFile, doc_id);
}

stockphoto.shoppingCart.createNShowHtmlPage = function(cartItems, FirstTime, doc_id)
{
	stockphoto.core.log.logString( 0,"[SHOPPING CART] Enter stockphoto.shoppingCart.createNShowHtmlPage\n" );
	var lscHtmlFile = new File(stockphoto.core.folder.getMyShoppingCartFolder() + "/" + stockphoto.core.consts.ShoppingCartName);
	var doc = stockphoto.documents[doc_id].document;

	// Add to prohibit displaying the second shopping cart -BEG-
	{
		var ii;
		for( ii=0; ii<app.documents.length; ii++ )
		{
			if( ( app.documents[ii].document != undefined )&&
			    ( app.documents[ii].document.id != ii )&&
			    ( app.documents[ii].document.thumbnail != undefined ) )
			{

//				if( ( app.documents[ii].document.thumbnail.displayPath.indexOf( stockphoto.core.consts.ShoppingCartName ) > 0 )&&
				if( ( ( stockphoto.core.util.getDisplayPath( app.documents[ii].document.thumbnail, "createNShowHtmlPage()-1" ) ).indexOf( stockphoto.core.consts.ShoppingCartName ) > 0 )&&
				    ( app.documents[ii].document.thumbnail.displayMode == "web") )
				{
					stockphoto.core.log.logString( 0, "14 #1.->Home" );
					stockphoto.displayStartPage( doc_id ); // redirect to Home page
					return;
				}
			}
		}
	}
	// Add to prohibit displaying the second shopping cart -END-
	
	lscHtmlFile.encoding = "UTF-8";
	var retVal = true;

	if (cartItems.length != 0)
	{
		retVal = stockphoto.shoppingCart.buildShoppingCartHtml(cartItems, lscHtmlFile, doc_id);
	}
	else 
	{
		retVal = stockphoto.shoppingCart.buildEmptyShoppingCartHtml(lscHtmlFile, doc_id);
	}
	
	if (retVal)
	{
		stockphoto.eventHandler.pathAnalyzer.ChangeContentPaneMode( doc, "web" );
	
		if (FirstTime)
		{
			stockphoto.core.html.HtmlScriptReadyStatus = false;
		}

//		if ((doc.thumbnail.displayPath.indexOf(stockphoto.core.consts.ShoppingCartName) > 0) &&
		if (( ( stockphoto.core.util.getDisplayPath( doc.thumbnail, "createNShowHtmlPage()-2" ) ).indexOf(stockphoto.core.consts.ShoppingCartName) > 0) &&
		   (doc.thumbnail.displayMode == "web"))
		{
			stockphoto.core.html.HtmlScriptReadyStatus = true;	
		}
		//the conditions have been added to make sure that we do not reload an expired shopping cart page
		if( ( ( stockphoto.core.html.HtmlScriptReadyStatus ) && (cartItems.length != 0) )||
		( ( !FirstTime ) && (cartItems.length == 0) ) ) 
		{
			stockphoto.core.log.logString( 0,"[SHOPPING CART] Reload html page from st14_CreateNShowHtmlPage\n" );
			doc.execJS( "window.location.reload( true );" );
		}

		stockphoto.core.NavBar.SwitchNavBar( "st14_ShoppingCart", 0, 0, doc );
		stockphoto.core.html.doLocalHtm(stockphoto.shoppingCart.stringTab.LOCAL_SHOPCART, lscHtmlFile, FirstTime, doc_id, "stockphoto://shoppingcart");
	}
	else
	{
		stockphoto.DL.generalAlertBox(ERROR_CREATE_HTML, 2);
	}
}

// HTML call back 
// args.DeleteLSCItem - index to the shopping cart item need to be deleted
stockphoto.shoppingCart.deleteShoppingCartItem = function(args)
{
	stockphoto.core.html.HtmlScriptReadyStatus = true;

	stockphoto.core.log.logString( 0,"[SHOPPING CART]  Enter stockphoto.shoppingCart.deleteShoppingCartItem\n" );
	stockphoto.shoppingCart.updateShoppingCart(args);
	var DeleteLSCItem = -1;
	var j = 0;
	if (!isNaN(args.DeleteLSCItem))
	{
		DeleteLSCItem = args.DeleteLSCItem;
	}

	try 
	{
		var itemCount = stockphoto.addToCart.LSCGetItemCount();
		var cartItems = new Array(itemCount);

		for (var i = 0; i < itemCount; i++)
		{
			if (DeleteLSCItem == i)
			{
				stockphoto.addToCart.LSCRemoveItem(i, true);
				continue;
			}
			cartItems[j] = stockphoto.addToCart.LSCGetItem(i);
			j++;
		}

		// stockphoto.addToCart.LSCRemoveAll();
		app.preferences.bm_ShoppingCartCount = 0;

		for (var i = 0; i < j; i++)
		{
			stockphoto.addToCart.LSCReplaceItem(cartItems[i]);
		}
		
		for (var i = j; i < itemCount; i++)
		{
			stockphoto.addToCart.LSCRemoveItem(i, false);
		}
		
		stockphoto.shoppingCart.shoppingCart_Body( false, args.doc_id ); // it is already loaded
	
	}
	catch (e)
	{
		stockphoto.core.log.logString( 2,"Exception in stockphoto.shoppingCart.deleteShoppingCartItem" );
		return null;
	}
}

//	// HTML call back 
//	// args.item - index to the shopping cart item
//	stockphoto.shoppingCart.showDetail = function(args)
//	{
//		var cartItem = stockphoto.addToCart.LSCGetItem(args['item']);
//		var cartObj  = stockphoto.addToCart.LSCConvertItem2Object(cartItem);
//		var pathArray = new Array(1);
//		pathArray[0] = cartObj.thumbnailPath;	
//	
//		var defaultImg = "img_not_avail_50x50.jpg";
//		var isDefaultImg = (pathArray[0].indexOf(defaultImg) >= 0);
//	
//		if (isDefaultImg)
//		{
//			stockphoto.DL.generalAlertBox(stockphoto.alertBox.localizedStr4ErrMsg.MESSAGE_ES_COMP_NO_IMG_RES, 2);
//		}
//		else
//		{
//			stockphoto.shoppingCart.updateShoppingCart(args);
//			stockphoto.pathArray = pathArray;
//			app.scheduleTask("stockphoto.DL.imgDetail.getPriceForPathArray( stockphoto.pathArray )", 0, false);
//		}
//	}

stockphoto.shoppingCart.updateShoppingCart = function(args)
{
	try 
	{
		var itemCount = stockphoto.addToCart.LSCGetItemCount();
		var cartItems = new Array(itemCount);
		var doUpdate = true;

		for (var i = 0; i < itemCount; i++)
		{
			var p = "SelectImage" + i;
			var priceNpurchaseID = new Array(2);
			
			if (args[p] == undefined)
			{
				doUpdate = false;
				break;
			}
			var pIndex = args[p].indexOf("+");
			priceNpurchaseID[0] = unescape(args[p].slice(0, pIndex));
			priceNpurchaseID[1] = unescape(args[p].slice(pIndex + 1, args[p].length));
			cartItems[i] = stockphoto.addToCart.LSCGetItem(i);
			var cartObject = stockphoto.addToCart.LSCConvertItem2Object(cartItems[i]);
			cartObject.selectedPurchaseID = priceNpurchaseID[1];
			cartObject.selectedPrice = priceNpurchaseID[0];
			cartItems[i] = stockphoto.addToCart.LSCConvertObject2Item(cartObject);
		}
		
		if (doUpdate == false)
		{
			return false;
		}

		app.preferences.bm_ShoppingCartCount = 0;

		for (var i = 0; i < itemCount; i++)
		{
			stockphoto.addToCart.LSCReplaceItem(cartItems[i]);
		}
		return true;
		
	}
	catch (e)
	{
		stockphoto.core.log.logString( 2,"Exception in stockphoto.shoppingCart.deleteShoppingCartItem" );
		return false;
	}
}

// HTML call back 
stockphoto.shoppingCart.printShoppingCart = function(args)
{
	if (stockphoto.isMac)
	{
		stockphoto.DL.generalAlertBox("Under development...", 1);
		return;
	}

	var doc = stockphoto.documents[args.doc_id].document;

	stockphoto.shoppingCart.updateShoppingCart(args);
	stockphoto.shoppingCart.shoppingCartNewPrice(false, args.doc_id);
	doc.print();
	stockphoto.core.html.HtmlScriptReadyStatus = true;        //  NEED to change
	doc.execJS( "window.setTimeout('window.location.reload( true );', 500);" );

}

// HTML call back 
stockphoto.shoppingCart.continueBrowsing = function(args)
{
	stockphoto.core.log.logString( 0,"[SHOPPING CART] Enter stockphoto.shoppingCart.continueBrowsing, doc_id = " + args.doc_id);

	var doc = stockphoto.documents[args.doc_id].document;
	if (doc == undefined)
	{
		doc = stockphoto.core.findDoc( args.doc_id );
	}

	if (doc == undefined)
	{
		stockphoto.core.log.logString( 0,"[SHOPPING CART] Cound not find document, doc_id = " + args.doc_id);
	}

	stockphoto.shoppingCart.updateShoppingCart(args);
	if ((stockphoto.documents[args.doc_id].shoppingCart != undefined) &&
		(stockphoto.documents[args.doc_id].shoppingCart.savedThumbnail != undefined))
	{
		doc.thumbnail = stockphoto.documents[args.doc_id].shoppingCart.savedThumbnail;
		stockphoto.core.log.logString( 0,"[SHOPPING CART] Continue Browsing Thumbnail : " + stockphoto.core.util.getDisplayPath(doc.thumbnail,""));
	}
	else
	{
		doc.thumbnail = stockphoto.places.recentSearches;
		stockphoto.core.log.logString( 0,"[SHOPPING CART] Continue Browsing recent search Thumbnail : " + stockphoto.core.util.getDisplayPath(doc.thumbnail,""));
	}
}

// HTML call back 
stockphoto.shoppingCart.help = function(args)
{
    stockphoto.DL.MiscDlgs.HelpTopic( stockphoto.core.helpTopicBase );
}

// HTML call back
stockphoto.shoppingCart.aboutCart = function(args)
{
	stockphoto.core.log.logString( 0,"[SHOPPING CART] Enter stockphoto.shoppingCart.aboutCart, doc_id = " + args.doc_id);
	stockphoto.DL.MiscDlgs.HelpTopic( stockphoto.core.helpTopicBase );
}

stockphoto.shoppingCart.getFooterURLParams = function()
{
	var countryCode = stockphoto.prefs.default_countryCode;
	var languageCode = stockphoto.prefs.default_languageCode;
	var currLocale = stockphoto.core.getValidLocale(true);
	if (currLocale.length == 5)
	{
		languageCode = currLocale.substr(0,2);
		countryCode = currLocale.substr(3,2);
	}
	var urlParams = '?language=' + languageCode.toLowerCase() + '&country=' + countryCode.toLowerCase() +"&version="+stockphoto.core.BM_3Version;
	return urlParams
}

stockphoto.shoppingCart.footerThumbnail = function(title, url)
{
	var t = new Thumbnail("stockphoto://scFooter");
	t.name = title;
	t.displayMode = "web";
	t.displayPath = unescape(url);
	a = stockphoto.core.html.setUrlFilter( app.document );
	if( a ) 
	{ // do it once more
		stockphoto.core.html.setUrlFilter( app.document );
	}
	app.document.thumbnail = t;	
}	

stockphoto.shoppingCart.customerService = function(args)
{
	var onCompleteObj = {};
	onCompleteObj.urlReceived = function(urlString)
	{
		with (stockphoto.shoppingCart)
		{
			var urlParams = getFooterURLParams();
			updateShoppingCart(args);
			if (urlString != undefined)
			{
				urlString += urlParams;
			}
			else
			{
				urlString = "http://www.adobe.com";
			}
			footerThumbnail (stringTab.CUSTOMER_SERVICE, urlString);
		}	
	}
	
	stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_MiscDlgs );
	var doc = app.document;
	var request = 
	{
		group: "EComPartners",	
		xmlPath: "",
		keyword: "CustomerServiceURL",
		iteration: 1,
		eventHandler: stockphoto.MiscDlgs.getPartnersXMLItem_EventHandler,
		onComplete: onCompleteObj
	};
	
	stockphoto.MiscDlgs.getPartnersXMLItem(onCompleteObj, request, doc);
}

stockphoto.shoppingCart.privacyPolicy = function(args)
{
	var onCompleteObj = {};
	onCompleteObj.urlReceived = function(urlString)
	{
		with (stockphoto.shoppingCart)
		{
			var urlParams = getFooterURLParams();
			updateShoppingCart(args);
			if (urlString != undefined)
			{
				urlString += urlParams;
			}
			else
			{
				urlString = "http://www.adobe.com";
			}
			footerThumbnail (stringTab.PRIVACY_POLICY, urlString);
		}	
	}
	
	stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_MiscDlgs );
	var doc = app.document;
	var request = 
	{
		group: "EComPartners",	
		xmlPath: "",
		keyword: "PrivacyPolicyURL",
		iteration: 1,
		eventHandler: stockphoto.MiscDlgs.getPartnersXMLItem_EventHandler,
		onComplete: onCompleteObj
	};
	
	stockphoto.MiscDlgs.getPartnersXMLItem(onCompleteObj, request, doc);
}

stockphoto.shoppingCart.termsOfService = function(args)
{
	var onCompleteObj = {};
	onCompleteObj.urlReceived = function(urlString)
	{
		with (stockphoto.shoppingCart)
		{
			var urlParams = getFooterURLParams();
			updateShoppingCart(args);
			if (urlString != undefined)
			{
				urlString += urlParams;
			}
			else
			{
				urlString = "http://www.adobe.com";
			}
			footerThumbnail (stringTab.TERMS_OF_SERVICE, urlString);
		}	
	}
	
	stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_MiscDlgs );
	var doc = app.document;
	var request = 
	{
		group: "EComPartners",	
		xmlPath: "",
		keyword: "TermsOfServiceURL",
		iteration: 1,
		eventHandler: stockphoto.MiscDlgs.getPartnersXMLItem_EventHandler,
		onComplete: onCompleteObj
	};
	
	stockphoto.MiscDlgs.getPartnersXMLItem(onCompleteObj, request, doc);
}

stockphoto.shoppingCart.copyStyleSheet=function(doc_id) 
{
	if( ( stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_NavBar ) )&&( stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_HTMUtil ) ) ) 
	{
		var inFile, outFile;
		var doc = stockphoto.documents[doc_id].document;
		stockphoto.NavExtFnc.SetStandardCnvTable( doc_id );
		inFile  = unescape( stockphoto.core.folder.getTemplateFolder()+"/stylesheets/nStockPhoto.css" );
		outFile = unescape( stockphoto.core.folder.getMyShoppingCartFolder() );
		convertTable = stockphoto.NavExtFnc.GetStandardVonversionTable();
		convertTable.BUTTON_WIDTH = stockphoto.shoppingCart.standardCntTab.BUTTON_WIDTH;
		if(stockphoto.DL.HTMLUtil.LocalHTMLbyDoc( inFile, convertTable, "StockPhoto.css", outFile, false, doc ) ) 
		{
			return( true );
		};
	};
	return( false );
}

if( ( stockphoto.timeKeeperOn != undefined )&&( stockphoto.timeKeeperOn ) )
{
	stockphoto.core.util.edTime( stockphoto.DL.jsx_ShoppingCart );
}

