// prodinfo.js - Product Information Functions

//*******************************************//
//************ PRODUCT LIST FUNCTIONS *******//
//*******************************************//


// Product Image Mouse Over function
function ProdMouseOver(prodnum)
{
  // Get image name
  var iname = ProdInfoGet(prodnum, "iname");

  // MouseOver Image File
  var himg = "img/" + iname + "h.gif";

  // Swap Image function call
  MM_swapImage(iname,'',himg, 1);
}

// Get product info 
function ProdInfoGet(prodnum, type)
{
  // Product info array [prodname, slogan, iname, price, color, buylink, shipping]
  var parray = new Array();
  
  // Prices
  var pricecad = MoneyFormat(PerCopyGet("CAD"),"CAD");
  var priceusd = MoneyFormat(PerCopyGet("USD"),"USD");
  var price = pricecad + "<br />" + "(" + priceusd + ")";

  // number of products in menu
  var count = 3; 

  parray[0] = ["Mathamagica<br />Version 1.00<br /><span class='REDBOLD'>HOME<br/>EDITION</span>",
               "Hey Kids and Parents!<br /><br />" +
               "Sharpen your math skills <span class='REDBOLD'>at home</span> with the Mathamagica HOME EDITION!",
               "prodhome",
               price,
               "#FFFF80", 
               "ordmathhm.html",
               true];

   parray[1] = ["Mathamagica<br />Version 1.10<br /><span class='REDBOLD'>LIBRARY<br />EDITION</span>",
                "Hey Libraries!<br /><br />" +
                "Add the Mathamagica LIBRARY EDITION to your collection of Children's Software titles!<br/><br/>" +
                "<span class='REDBOLD'>NOTE: Runs from CD-ROM.</span>",
                "prodlib",
                price,
                "#C0FFFF",
		    "ordmathlib.html",
                true];

   parray[2] = ["Mathamagica<br />Version 1.10<br /><span class='REDBOLD'>SCHOOL<br />EDITION</span>",
                "Hey Teachers!<br /><br />" +
                "Spice up your classroom with the Mathamagica SCHOOL EDITION!",
                "prodsch",
                "<a href='mathbuysch.html'><span class='BIG'>SCHOOL<br />PRICES<br /></span></a>",
                "#COFFC0",
                "schnote.html",
                false];

   // Last entry for General Information
   parray[3] = ["Math Game<br />(ages 7 to 11)",
                "Fight Monsters!<br />Solve Riddles!<br />Meet Dragons<br />and Princesses!",
                "prodgen",
                "Available in HOME,<br />SCHOOL and<br />LIBRARY Editions.",
                "#FFE7E7",
                "products.html",
                false];


  // Return requested info for product
  switch(type)
  {
    case "prodname": return parray[prodnum][0]; break;
    case "slogan":   return parray[prodnum][1]; break;
    case "iname":    return parray[prodnum][2]; break;
    case "price":    return parray[prodnum][3]; break;
    case "color":    return parray[prodnum][4]; break;
    case "buylink":  return parray[prodnum][5]; break;
    case "shipping":  return parray[prodnum][6]; break;
    case "count": return count;
    default: return ""; break;
  }

}

// Buy Image Mouse Over function
function BuyMouseOver(prodnum)
{
  // Get image name
  var iname = "buynow";

  // MouseOver Image File
  var himg = "img/" + iname + "h.gif";

  // Swap Image function call
  MM_swapImage(iname + prodnum,'',himg, 1);
}

// Create Product Listing 
function ProdListAdd(prodnum, buynow)
{
  // Tag Write
  var tagwrite = "";

  // Get Product Info
  var prodname = ProdInfoGet(prodnum, "prodname");
  var slogan = ProdInfoGet(prodnum, "slogan");
  var iname = ProdInfoGet(prodnum, "iname");
  var price = ProdInfoGet(prodnum, "price");
  var color = ProdInfoGet(prodnum, "color");
  var buylink = ProdInfoGet(prodnum, "buylink");
  var shipping = ProdInfoGet(prodnum, "shipping");

  // Image file
  var imgfile = "img/" + iname + ".gif";

  // Start row
  tagwrite = tagwrite + "<tr bgcolor='" + color + "'>";
  
  // Product Image
  tagwrite = tagwrite + "<td valign='top'>";
  tagwrite = tagwrite + "<a href = 'mathinfo.html' ";
  tagwrite = tagwrite + "onMouseOut='MM_swapImgRestore()' "; 
  tagwrite = tagwrite + "onMouseOver='ProdMouseOver(" + prodnum + ")'"; 
  tagwrite = tagwrite + ">";
  tagwrite = tagwrite + "<img name='" + iname + "' src='" + imgfile + "' border='1'/>";
  tagwrite = tagwrite + "</a></td>";

  // Product Name + Target User
  tagwrite = tagwrite + "<td valign='top' width='130'>";
  tagwrite = tagwrite + "<div class='BIG'>" + prodname + "</div>";
  tagwrite = tagwrite + "<br />";

  // More Info link
  tagwrite = tagwrite + "<a href='mathinfo.html'>";
  tagwrite = tagwrite + "<span class='MEDIUM'>More Info and Online DEMO</span>";
  tagwrite = tagwrite + "</a>";
  tagwrite = tagwrite + "</td>";

  // Price 
  tagwrite = tagwrite + "<td valign = 'top' class='MEDIUM' width='150'>";
  tagwrite = tagwrite + price + "<br /><br />";

  // Shipping
  if (shipping)
  {
     tagwrite = tagwrite + "*<a href='mathship.html'>Shipping</a>";
     tagwrite = tagwrite + "<br /><br />";
  }

  if (buynow)
  {
     // Buy Now Button
     tagwrite = tagwrite + "<a href='" + buylink + "'";
     tagwrite = tagwrite + " onMouseOut='MM_swapImgRestore()'";
     tagwrite = tagwrite + " onMouseOver='BuyMouseOver(" + prodnum + ")'>"; 
     tagwrite = tagwrite + "<img name='buynow" + prodnum + "' src='img/buynow.gif' align='bottom'>";
     tagwrite = tagwrite + "</a>";
     tagwrite = tagwrite + "</td>";
  }


  // Slogan
  tagwrite = tagwrite + "<td valign='top'>";
  tagwrite = tagwrite + "<div class='MEDIUM'>" + slogan + "</div>";
  tagwrite = tagwrite + "</td>";

  // End row
  tagwrite = tagwrite + "</tr>";

  // Write image tag
  return tagwrite;
}

// Create Product List
function ProdListCreate()
{
  var tagwrite = "";
  var prodnum = 0;
  var buynow = true;

  // Individual buttons
  var count = ProdInfoGet(prodnum, "count"); 
  for (prodnum = 0; prodnum < count; prodnum++)
    tagwrite = tagwrite + ProdListAdd(prodnum, buynow); 

  // Write image tag
  document.write(tagwrite);
}

// Preload product button images
function ProdPreload()
{
  var bimg = new Array();
  var prodnum;
  var count;

  // Get number of buttons
  count = ProdInfoGet(0, "count");
 
  //Get all button images
  var count = ProdInfoGet(prodnum, "count"); 
  for (prodnum = 0; prodnum < count; prodnum++)
    bimg[prodnum] = "img/" + ProdInfoGet(prodnum, "iname") + "h.gif";

  MM_preloadImages(bimg[0], bimg[1], bimg[2], "img/buynow.gif", "img/buynowh.gif");
}

// Preload animations
function AnimPreload()
{
  MM_preloadImages("img/mathanim.gif", "img/mathanimh.gif");
}

// Preload buy buttons
function BuyPreload()
{
  MM_preloadImages("img/buyolh.gif", "img/buychkh.gif", "img/buysth.gif", "img/buyemailh.gif");
}

/******************************/
/**** SCHOOL PRICES ***********/
/******************************/

function SchoolPrices()
{
  var tagwrite="";
  var pid, currency, name, desc, price, pricecad, priceusd; // loop

  // Category Array [name, desc, price(CAD)]
  var parray = new Array();
  parray[0] = ["Teacher's Edition", "1-2 computers at one school site", 70];
  parray[1] = ["5-Pack", "5 computers at one school site", 155];
  parray[2] = ["10-Pack", "10 computers at one school site", 300];
  parray[3] = ["15-Pack", "15 computers at one school site", 420];
  parray[4] = ["Building Location License", "Unlimited computers at one school site", 500];
  var count = 5;
  
  // Table Heading 
  tagwrite = tagwrite + "<table class='TBBACK' align='top' border='1' bordercolor='black' cellspacing='0' cellpadding='5'>";
  tagwrite = tagwrite + "<caption align='top'><span class='BIG'>Mathamagica Version 1.10 School Edition Site Licensing Prices</span></caption>";
  tagwrite = tagwrite + "<tr class='TBHEAD'>"; 
  tagwrite = tagwrite + "<td>Package Name</td>";
  tagwrite = tagwrite + "<td>Number of Computers at School Site</td>";
  tagwrite = tagwrite + "<td align='right'>Price (CAD)</td>";
  tagwrite = tagwrite + "<td align='right'>Price (USD)</td>";
  tagwrite = tagwrite + "</tr>";

  // License Categories
  for (pid = 0; pid < count; pid++)
  {
     currency = "";
     name = parray[pid][0];
     desc = parray[pid][1];
     price = parray[pid][2];
     pricecad = MoneyFormat(price, currency);
     priceusd = MoneyFormat(ExchangeCalc(price), currency);

     tagwrite = tagwrite + "<tr>";
     tagwrite = tagwrite + "<td class='TBLFT'>" + name + "</td>";
     tagwrite = tagwrite + "<td>" + desc + "</td>";
     tagwrite = tagwrite + "<td align='right'>" + pricecad + "</td>";
     tagwrite = tagwrite + "<td align='right'>" + priceusd + "</td>";
     tagwrite = tagwrite + "</tr>";
  }

  // End table
  tagwrite = tagwrite + "</table>";

  // write tag
  document.write(tagwrite);
}
