/* --------------- STUDIO CONNECTIONS EXTERNAL JAVASCRIPT FILE -------------- */
/*                                                                            */
/*    Description: Display shopping items, goods total and shopping buttons   */
/*                 Includes error detection and auto-generated email report   */
/*         Client: Cloud Studios - info@cloudstudios.com                      */
/*        Website: www.cloudstudios.com                                       */
/*         Author: Colin Abrahams - colin@studioconnections.net.au            */
/*      Copyright: 2008 Colin Abrahams, Studio Connections                    */
/*       Location: Wyong, NSW, Australia                                      */
/*        Version: SC-5.8                                                     */
/*   Last Updated: 2008-11-25                                                 */


if (top.ShopList && top.ShopAdd && top.SiteInit && document.forms) {
  document.write('<h2>Available Items</h2><form name = "ShopCentre">\n');

  // Display shopping items
  for (var i = 0; i < top.ShopList.length; i++) {
    document.write('<table border="0" cellspacing="0" cellpadding="0"><tr>'

                 + '<td width="150" valign="top"><img '
                 + 'src="../../' + top.ShopList[i].Pict + '" '
                 + 'alt="' + top.ShopList[i].Desc + '" '
                 + 'width="150" height="150" border="0" /></td>'

                 + '<td width="15"><img src="../../Styles/Blank.gif" alt="" '
                 + 'width="15" height="1" border="0" /></td>'

                 + '<td class="Feature" width="558" valign="top">'
                 + '<h3>' + top.ShopList[i].Desc + '</h3><br />'
                 + '<div class="Norm"><b>Price:</b>&nbsp; '
                 + top.ShopFmtC(top.ShopList[i].Cost) + '</div><br />'
                 + '<table border="0" cellspacing="0" cellpadding="0"><tr>'
                 + '<td class="Hilite"><b>Quantity:</b></td>'
                 + '<td width="10"><img src="../../Styles/Blank.gif" alt="" '
                 + 'width="10" height="1" border="0" /></td>'
                 + '<td><input type="text" name="Qty' + i + '" size="1" '
                 + 'value="' + top.ShopList[i].Quan + '" '
                 + 'onkeyup="top.ShopUpdt? top.ShopUpdt(this) : null" '
                 + 'onblur="top.ShopUpdt? top.ShopUpdt(this) : null" /></td>'
                 + '</tr></table></td>'

                 + '</tr></table><br />\n');
  }

  // Display goods total
  document.write('<table border="0" cellspacing="0" cellpadding="0"><tr>'

               + '<td width="165"><img src="../../Styles/Blank.gif" alt="" '
               + 'width="165" height="1" border="0" /></td>'

               + '<td class="Feature" width="558">'
               + '<table border="0" cellspacing="0" cellpadding="0"><tr>'
               + '<td class="Hilite"><b>Goods Total (AUD):</b></td>'
               + '<td width="10"><img src="../../Styles/Blank.gif" alt="" '
               + 'width="10" height="1" border="0" /></td>'
               + '<td><input type="text" name="SubT" size="12" '
               + 'value="' + top.ShopFmtC(top.SCSubTotal) + '" '
               + 'readonly="readonly" /></td></tr></table></td>'

               + '</tr></table></form><br />\n');

  // Display Shopping Centre buttons
  document.write('<table align="center" border="0" cellspacing="0" '
               + 'cellpadding="0"><tr>'

               + '<td><div class="Button"><a '
               + 'href="javascript:void(0)" '
               + 'title="Reset all order quantities to 0" '
               + 'onmouseout ="window.BTOut ? BTOut(this) : null" '
               + 'onmouseover="window.BTSel ? BTSel(this) : null" '
               + 'onmousedown="window.BTDep ? BTDep(this) : null" '
               + 'onclick="window.BTClick ? BTClick(this) : null; '
               + 'top.ShopClear ? top.ShopClear(this) : null; return false">'
               + '<span class="Span1"><span '
               + 'class="Span2">Clear all</span></span></a></div></td>'

               + '<td width="50"></td>'

               + '<td><div class="Button"><a '
               + 'href="javascript:void(0)" '
               + 'title="Proceed to Check Order page" '
               + 'onmouseout ="window.BTOut ? BTOut(this) : null" '
               + 'onmouseover="window.BTSel ? BTSel(this) : null" '
               + 'onmousedown="window.BTDep ? BTDep(this) : null" '
               + 'onclick="window.BTClick ? BTClick(this) : null; '
               + 'top.ShopCheck(); return false">'
               + '<span class="Span1"><span '
               + 'class="Span2">Checkout &gt;&gt;</span></span></a></div></td>'

               + '</tr></table>\n');
}

// Page running outside website
else if (!top.Main) {
  document.write('<p>This page must be viewed from within the full site '
               + 'to use the Shopping Centre.</p>');
}

// Website error detection
else {
  ESubj = "Problem with the Cloud Studios website";
  EBody = "Module: Shopping Centre%0A%0A";
  ALoad = top.ShopList ? "Yes" : "No";
  EBody += "Shopping arrays loaded: " + ALoad + "%0A%0A";
  FLoad = top.ShopAdd ? "Yes" : "No";
  EBody += "Shopping functions loaded: " + FLoad + "%0A%0A";
  SLoad = top.SiteInit ? "Yes" : "No";
  EBody += "Site initialised: " + SLoad + "%0A%0A";
  DForm = document.forms ? "Yes" : "No";
  EBody += "Forms array support: " + DForm + "%0A%0A";
  EBody += "Browser: " + navigator.userAgent + "%0A";
  document.write('<p>This website does not seem to have loaded properly.&nbsp; '
               + 'The Shopping Centre cannot function.&nbsp; '
               + 'You could try reloading the full site.&nbsp; '
               + 'If you continue to encounter this problem, please <a '
               + 'href="mailto:info@cloudstudios.com?subject=' + ESubj
               + '&body=' + EBody + '" '
               + 'title="Email Cloud Studios with auto-generated fault report" '
               + 'onclick="this.blur ? this.blur() : null">report this</a> '
               + 'to Cloud Studios.&nbsp; We are committed to making a better '
               + 'website and your help would be much appreciated.&nbsp; '
               + 'Thankyou.</p>');
}
