var product  = new Array();
var category = new Array();

function displayProduct(SKU) {
  myProduct = getProduct(SKU);
  if (myProduct) {
	  document.write("<table cellpadding=0 cellspacing=0 border=0>");
	  
	  // product name / product price
	  document.write("  <tr>");
	  document.write("    <td colspan=2 >");
	  document.write("      <table width=100% class='productHeader'>");
	  document.write("        <tr>");
	  document.write("          <td class='productName'>");
	  document.write("            " + myProduct.name);
	  document.write("          </td>");
	  document.write("          <td class='productPrice'>$");
	  document.write("            " + myProduct.price);
	  document.write("          </td>");
	  document.write("        </tr>");
	  document.write("      </table>");
	  document.write("    </td>");
	  document.write("  </tr>");
	  
	  // product thumbnail / learn more button / add to cart button
	  document.write('  <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">');
	  document.write('  <input type="hidden" name="bn" value="AMPPFPWZ.200">');
	  document.write('  <input type="hidden" name="cmd" value="_cart">');
	  document.write('  <input type="hidden" name="add" value="1">');
	  document.write('  <input type="hidden" name="business" value="' + paypalEmail + '">'); 
	  document.write('  <input type="hidden" name="item_name" value="' + myProduct.name + '">');
	  document.write('  <input type="hidden" name="item_number" value="' + myProduct.sku + '">');
	  document.write('  <input type="hidden" name="amount" value="' + myProduct.price + '">');
	  document.write('  <input type="hidden" name="currency_code" value="USD">');
	  document.write('  <input type="hidden" name="no_note" value="1">');
	  document.write('  <input type="hidden" name="no_shipping" value="0">');
	  document.write("  <tr>");
	  document.write("    <td valign=top>");
	  document.write('       <a style="cursor: hand" onClick="javascript:info(760,450,0,0,\''+ myProduct.detailsURL+'\')">');
	  document.write('        <img align=left  border=1 style="border-color:black" align=middle src="' + myProduct.thumbURL+ '" width=100 height=80></a>');
	 
	  document.write('      <div align=center><a href="#" onClick="javascript:info(760,450,0,0,\''+ myProduct.detailsURL+'\')"><img border=0 src="../images/catalog/learn_more.gif"></a>');
	  document.write('      <input type="image" src="../images/catalog/add_to_cart.gif" border="0" name="submit" title="Make payments with PayPal - it\'s fast, free and secure!">');
		  
	  document.write("    </div><span class='productDescription'>");
	  document.write('     '+myProduct.description);
	  document.write("    </span></form>");

	  document.write("  </tr>");
	  document.write("</table>");
	  
  }
}


function displayCategory(CAT) {
  myCategory = getCategory(CAT);
  if (myCategory) {
	  document.write("<table width=100% cellpadding=0 cellspacing=0 border=0>");
	  
	  // category name / price range
	  document.write("  <tr>");
	  document.write("    <td>");
	  document.write("      <table width=100% class='productHeader'>");
	  document.write("        <tr>");
	  document.write("          <td class='productName'>");
	  document.write("            <a class='categoryLink' href='" + myCategory.categoryPageURL + "'>" + myCategory.name + "</a>");
	  document.write("          </td>");
	  document.write("          <td class='productPrice'>$");
	  document.write("            " + myCategory.priceRange);
	  document.write("          </td>");
	  document.write("        </tr>");
	  document.write("      </table>");
	  document.write("    </td>");
	  document.write("  </tr>");
	  
	  // product thumbnail / learn more button / add to cart button
	  document.write("  <tr>");
	  document.write("    <td valign=top>");
	  document.write('       <a href="' + myCategory.categoryPageURL + '">');
	  document.write('         <img align=left  border=1 style="border-color:black" align=middle src="' + myCategory.thumbURL+ '" width=100 height=80></a>');
	  
	  document.write("    <span class='productDescription'>");
	  document.write('     '+myCategory.description);
	  document.write("    </span>");

	  document.write("  </tr>");
	  document.write("</table>");
	  
  }
}




function printViewCartButton() {
  document.write('<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">');
  document.write('<input type="hidden" name="cmd" value="_cart">');
  document.write('<input type="hidden" name="business" value="' + paypalEmail + '">');
  document.write('<input type="image" src="../images/catalog/view_cart.gif" border="0" name="submit" title="Make payments with PayPal - it\'s fast, free and secure!">');
  document.write('<input type="hidden" name="display" value="1">');
  document.write('</form>');
}


function getProduct(SKU) {
  for (i = 0; i < product.length; i++) {
    if (product[i].sku == SKU) {
      return product[i];
    }
  }
  
  return null;
}

function getCategory(CAT) {
  for (i = 0; i < category.length; i++) {
    if (category[i].id == CAT) {
      return category[i];
    }
  }
  return null;
}

function displayCategoryLinks() {
  for (i = 0; i < category.length; i++) {
    if (i > 0) {
      document.write(' &middot; ');
    }
    document.write('<a class="categoryLink" href="' + category[i].categoryPageURL + '">' + category[i].name + '</a>');
  }
}

function addProduct(SKU, productName, productDetailPageURL, productThumbURL, price, description) {
  var productNum = product.length;
  
  product[productNum]               = new Array();
  product[productNum]['sku']        = SKU;
  product[productNum]['name']        = productName;
  product[productNum]['detailsURL']  = productDetailPageURL;
  product[productNum]['thumbURL']    = productThumbURL;
  product[productNum]['price']       = price;
  product[productNum]['description'] = description;
}

function addCategory(CAT, categoryName, categoryPageURL, categoryThumbURL, priceRange, description) {
  var categoryNum = category.length;
  
  category[categoryNum]                = new Array();
  category[categoryNum]['id']         = CAT;
  category[categoryNum]['name']        = categoryName;
  category[categoryNum]['categoryPageURL']  = categoryPageURL;
  category[categoryNum]['thumbURL']         = categoryThumbURL;
  category[categoryNum]['priceRange']       = priceRange;
  category[categoryNum]['description']      = description;
}
