var template='<table><tr><td><div class="itemThumb"></div></td><td><a class="itemTitle" href="javascript:void(0);"></a><div class="templateDescription"></div><div class="templateMedium"></div><div class="itemDetail"></div><div class="itemRemove"></div></td><td class="nowrap"><span class="itemPrice"></span></td><td class="nowrap"><span>x</span><input class="itemQuantity" type="text" size="1" value=""></td><td class="nowrap"><span>=</span><span class="itemTotal"></span></td></tr></table>';var currentItem=null;var cartItems;var nextItem,previousItem;window.addEvent("pageload",function(){cartBody=$("Cart").getElement(".cartTable tbody");cartFoot=$("Cart").getElement(".cartTable tfoot");var E=new Jx.Dialog({move:false,collapse:false,close:false,modal:true,resize:false,hideTitle:true,width:775,height:450,content:'<div id="Details"><h1 id="MapTitle"></h1><p id="MapDescription"></p><dl><dt>Base Map</dt><dd id="BaseMap"></dd><dt>User Features<dd id="NumberOfFeatures"></dd></dl><dl><dt>Map Area</dt><dd id="MapArea"></dd><dt>Map Dimensions<dd id="MapDimensions"></dd><dt>Map Center<dd id="MapCenter"></dd></dl><dl><dt>Layout</dt><dd id="TemplateDescription"></dd><dt>Medium</dt><dd id="TemplateMedium"></dd><dt>Size</dt><dd id="TemplateSize"></dd></dl></div><div id="Map"><img id="MapImage" alt="Preview of Map"><div id="Overview"><img id="OverviewImage" width="120" height="120" alt="Entire Area"></div></div><div id="Controls"><div id="Navigation"><span id="PreviousItem"></span><span id="CurrentItem"></span><span id="NextItem"></span></div><div id="Close"></div></div>',onContentLoaded:function(){this.needsLayout=true},onOpen:function(){if(this.needsLayout){new Jx.Layout($("Details"),{width:300,bottom:38}).resize();new Jx.Layout($("Map"),{left:300,bottom:38}).resize();new Jx.Layout($("Controls"),{top:null,height:38}).resize();new Jx.Button({label:"Close",image:themeUrl+"/images/icons/close.png",onClick:function(){E.close()}}).addTo($("Close"));previousItem=new Jx.Button({image:themeUrl+"/images/icons/arrow_left.png",onClick:function(){currentItem--;displayItem()}}).addTo($("PreviousItem"));nextItem=new Jx.Button({image:themeUrl+"/images/icons/arrow_right.png",onClick:function(){currentItem++;displayItem()}}).addTo($("NextItem"));this.needsLayout=false}displayItem()}});var A=new Jx.Toolbar({scroll:false,position:"bottom"});var C="<p>Your map is being generated.  This process takes up to 30 seconds.</p><p>When the map is ready to be downloaded, this message will be replaced with a link that you can click to download the map with.</p>";var B=new Jx.Dialog({label:"PDF Generation",content:C,move:false,modal:true,close:false,resize:false,collapse:false,width:400,height:300,toolbars:[A],onClose:function(){this.content.set("html",C);D.setEnabled(false)}});var D=new Jx.Button({label:"Close",enabled:false,onClick:function(){B.close()}});A.add(D);new Request.JSON({url:themeUrl+"/php/cart_content.php",onComplete:function(F){new Jx.Button({label:"Continue Shopping",onClick:function(){(function(){window.location.href=siteUrl+"/map-maker"}).delay(1)}}).addTo(cartFoot.getElement(".continueShopping"));new Jx.Button({label:"Checkout",onClick:function(){(function(){window.location=siteUrl+"/checkout/billing.php"}).delay(1)}}).addTo(cartFoot.getElement(".checkout"));cartBody.empty();cartItems=F.values.cart.items;cartItems.each(function(L,H){var N=new Element("div",{html:template});var M=N.getElement("table tr");M.inject(cartBody);var K=100;var J=100;if(L.mapaspect>1){J/=L.mapaspect}else{K*=L.mapaspect}var I=M.getElement(".itemThumb");I.adopt(new Element("img",{width:K,height:J,src:themeUrl+"/php/cart_thumbnail.php?basemap="+L.basemap+"&itemid="+L.id+"&userid="+L.userid+"&extent="+L.extent+"&width="+(K*2)+"&height="+(J*2)}));I.addEvent("click",function(){currentItem=H;E.open()});M.getElement(".itemTitle").set("html",L.title);M.getElement(".itemTitle").addEvent("click",function(){currentItem=H;E.open()});M.getElement(".itemDetail");M.getElement(".templateDescription").set("html",L.size+" "+L.family);var G=L.medium=="pdf"?"Downloadable PDF":"Printed on "+L.medium;M.getElement(".templateMedium").set("html",G);M.getElement(".itemPrice").set("html","$"+L.price);M.getElement(".itemQuantity").set("value",L.quantity);M.getElement(".itemQuantity").store("previousValue",L.quantity);M.getElement(".itemQuantity").addEvent("change",function(){var O=parseInt(this.value);if(isNaN(O)){O=this.retrieve("previousValue")}else{this.store("previousValue",O)}if(O===0){M.addClass("error");if(window.confirm("Are you sure you want to remove this item from your cart?")){new Request.JSON({url:themeUrl+"/php/cart_remove.php",data:{id:L.id},onComplete:function(P){cartItems.erase(L);M.dispose();updateTotals()}}).send()}else{M.removeClass("error")}}else{L.quantity=O;this.value=O;M.addClass("notice");new Request.JSON({url:themeUrl+"/php/cart_update.php",data:{id:L.id,quantity:O},onComplete:function(P){M.getElement(".itemTotal").set("html","$"+(L.price*L.quantity).toFixed(2));updateTotals();M.removeClass("notice")}}).send()}});M.getElement(".itemTotal").set("html","$"+(L.price*L.quantity).toFixed(2));new Jx.Button({label:"Remove",onClick:function(){M.addClass("error");if(window.confirm("Are you sure you want to remove this item from your cart?")){new Request.JSON({url:themeUrl+"/php/cart_remove.php",data:{id:L.id},onComplete:function(O){cartItems.erase(L);M.dispose();updateTotals()}}).send()}else{M.removeClass("error")}}}).addTo(M.getElement(".itemRemove"))});updateTotals()}}).send()});function updateTotals(){var D=0;var B=0;cartItems.each(function(E){D+=E.quantity;B+=E.quantity*E.price});if(D>0){cartFoot.getElement(".totalRow").setStyle("visibility","visible");var A=D>1?" Maps":" Map";cartFoot.getElement(".totalItems").set("html",D+A);cartFoot.getElement(".totalPrice").set("html","$"+B.toFixed(2))}else{cartFoot.getElement(".totalRow").setStyle("visibility","hidden")}$("CartContents").set("html",D+" maps in your cart");if(cartItems.length===0){var C=new Element("tr");new Element("td",{colspan:5,html:"There are no items in your cart"}).inject(C);cartBody.adopt(C)}}function displayItem(){var H=cartItems[currentItem];$("CurrentItem").set("html",H.title);previousItem.setEnabled(currentItem>0);nextItem.setEnabled(currentItem<cartItems.length-1);$("MapTitle").set("html",H.title);$("MapDescription").set("html",H.description);$("BaseMap").set("html",H.baseMapName);$("NumberOfFeatures").set("html",H.numberOfFeatures);$("MapArea").set("html",H.mapArea);$("MapCenter").set("html",H.mapCenter);$("MapDimensions").set("html",H.mapDimensions);$("TemplateDescription").set("html",H.family);$("TemplateSize").set("html",H.size);$("TemplateMedium").set("html",H.medium.capitalize());var G=120;var F=120;if(H.mapaspect>1){F/=H.mapaspect}else{G*=H.mapaspect}$("OverviewImage").setStyles({width:G,height:F});var E=(parseFloat(H.extent[2])+parseFloat(H.extent[0]))/2;var D=(parseFloat(H.extent[3])+parseFloat(H.extent[1]))/2;var C=(parseFloat(H.extent[2])-parseFloat(H.extent[0]))/G;var A=themeUrl+"/php/cart_thumbnail.php?";A+="basemap="+H.basemap;A+="&userid="+H.userid;A+="&itemid="+H.id;A+="&height="+F;A+="&width="+G;A+="&extent="+H.extent.toString();$("OverviewImage").set("src",A);var I=$("Map").getDimensions();$("MapImage").setStyles(I);B(E,D);function B(J,K){A=themeUrl+"/php/fullpreview.php?";A+="basemap="+H.basemap;A+="&userid="+H.userid;A+="&itemid="+H.id;A+="&height="+I.height;A+="&width="+I.width;A+="&map_width_inches="+H.mapwidth;A+="&map_height_inches="+H.mapheight;A+="&extent="+H.extent.toString();A+="&center_x="+J;A+="&center_y="+K;$("MapImage").set("src",A)}};