//
//  Copyright Manta Technologies Inc., 2008, 2009.  All rights reserved.  
//
//

// Sale Definition
// 0.00 is list price.
var seriesDiscount  = 0.0;
var comboDiscount   = 0.4;
var libraryDiscount = 0.4;
var courseDiscount  = 0.0;
var seminarDiscount = 0.0;

//target server
//var myUrl = "http://www.mantatech.com/manta/product_files/";
var myUrl = "product_files/";

//Data from product record
var sessionNode;
var productName   = "";
var productNumber = "";
var productType   = "";
var priceCD       = "";
var priceMantaNow = "";
var priceSRG      = "";
var sampleSession = "";
var overview      = "";
var objectives    = "";
var outline       = "";
var audience      = "";
var prerequisites = "";
var related       = "";
var uses          = "";
var evaluation    = "";

//Global variables
var discount        = 0;
var affiliate      = "";
var product        = "";
var samples        = "";
var pathArray      = new Array();
var tabArray       = new Array();
var pathArrayIndex = 0;
var userLevel      = 0;
var boughtSeminar  = false;
var boughtCourse   = false;
var lastTab        = 1;

function displayProduct() {
 //Entry point from other pages
 //Parse input string and display product description
 //Input assumed to be in form #xxxx or #xxxx&AFFILIATE=yyyy
 
    var passedData = self.location.hash.substr(1);
    var index1 = passedData.indexOf("Affiliate=");
    
    if ( index1 == -1) {
       product = passedData.toUpperCase();
    } else {
       affiliate = passedData.substring(index1+10).toUpperCase(); 
       product = passedData.substring(0,index1).toUpperCase();     
    }
    //alert("product='" + product + "' and affiliate='" + affiliate +"'")
    setAffiliate(affiliate);
   
    if ((product == null) || (product == "")) alert("Invalid product request.");
    if (product == 'CART_RESTORE') {
       self.location = "../index.htm";
    } else {
       displayProd(product);
    }   
}

function setAffiliate(x) {
   //alert("Entry bookmark:\n" + document.cookie);
   if (isNull(x)) {  
	   if (isNull(getBookmark("Affiliate"))) {	
		   affiliate = "";
	   } else { 
		   affiliate=getBookmark("Affiliate");			   
	   }
   } else {		   
      if (isNull(getBookmark("Affiliate"))) {
	       writeBookmark("Affiliate",affiliate,"30");	
      } else { 		       
         //alert("Replacing affiliate " + getBookmark("Affiliate") + " with " + x);
         deleteBookmark("Affiliate"); 
         writeBookmark("Affiliate",affiliate,"30");
      }
   }
   //alert("Exit bookmark:\n" + document.cookie);
}

function displayProd(x) {
  //Entry point from other products
  //Display the data for product x.

  //save product ID
    pushProduct(x);
  // clear variables from previous product
    productName   = "";
    productNumber = "";
    productType   = "";
    priceCD       = "";
    priceMantaNow = "";
    priceSRG      = "";
    sampleSession = "";
    overview      = "";
    objectives    = "";
    outline       = "";
    audience      = "";
    prerequisites = "";
    related       = "";
    lastTab       = 1;
    boughtSeminar = false;
    boughtCourse  = false;
    userLevel = 0;
    
  //get product data from server
    var myUrl2 = myUrl + x + ".xml";
  //alert("Getting " + myUrl2);
    callAjax(myUrl2,parseProduct,'A');
}

function  parseProduct(xmlHttp) {
    //Return from getting XML for product
    //Converts into variables for later use.
    
    sessionNode = xmlHttp.responseXML;

    //Extract Product components
    productName   = getElementAsString("productName");
    productNumber = getElementAsString("productNumber");
    productType   = getElementAsString("productType");
    priceCD       = getElementAsString("priceCD");
    priceMantaNow = getElementAsString("priceMantaNow");
    priceSRG      = getElementAsString("priceSRG");
    sampleSession = getElementAsString("sampleSession");
    overview      = getElementAsString("overview");
    objectives    = getElementAsString("objectives");
    outline       = getElementAsString("outline");
    audience      = getElementAsString("audience");
    prerequisites = getElementAsString("prerequisites");
    related       = getElementAsString("related");
    uses          = getElementAsString("uses");
    evaluation    = getElementAsString("evaluation");

    document.title = "Manta Technologies Inc. - " + productName;
    var titleBar  = "<TABLE style='margin-top:-12;margin-left:0' bgColor='#ffffff' border='0' cellPadding='0' width='100%'><TR>";
        titleBar += "<TD class='title'><BR /><BR /><H1>" + productName + "</H1><BR></TD></TR></TABLE>";
 
    var productNameBar = document.getElementById("productNameBar");
    productNameBar.innerHTML = titleBar;
 
    buildSampleMessage(productType);

    displayTabBar(productType);

    gotoTab(lastTab);
}
 
 function buildSampleMessage(x) {
    //Builds the "Sample Session" page depending on the product type.
    
    samples = "";
    
    switch (x.toUpperCase()) {
      case ("COURSE"):
         if (demoAvailable()) {
            samples =  '<h2>Sample Session</h2>';       
            samples += '<p>The first session of every Manta course and Competency Exam is ';
            samples += 'available for viewing.  To take the sample for this course, ';
            samples += 'simply click the link below.  You will be asked for your ';
            samples += 'contact information the first time you take a sample session.  ';
            samples += 'For subsequent sessions, this information will be filled in for you.</p>';
            samples += '<center><p><IMG height=21 src="images/binoc.gif" width=22 align=absmiddle border=0 margin=0><B>';
            samples += '<A href="javascript:writeQuestion()">Take the first session for free!</A></B></p></center>';
            samples += '<p>WARNING: To view a sample session, you must use Internet Explorer and '
            samples += 'allow pop-ups from our site.</p>'
         } else {
            samples = "<p>No sample sesion is available for this product.</>";
         }        
         break;  
      case ("COMPETENCY EXAM"):
         if (demoAvailable()) {
            samples =  '<h2>Sample Session</h2>';    
            samples += '<p>The first session of every Manta course and Competency Exam is ';
            samples += 'available for viewing.  To take the sample for this exam, ';
            samples += 'simply click the link below.  You will be asked for your ';
            samples += 'contact information the first time you take a sample session.  ';
            samples += 'For subsequent sessions, this information will be filled in for you.</p>';
            samples += '<center><p><IMG height=21 src="images/binoc.gif" width=22 align=absmiddle border=0 margin=0><B>';
            samples += '<A href="javascript:writeQuestion()">Take the first session for free!</A></B></p></center>';
            samples += '<p>WARNING: To view a sample session, you must use Internet Explorer and '
            samples += 'allow pop-ups from our site.</p>'
         } else {
            samples =  '<h2>Sample Session</h2>';    
            samples += "<p>No sample sesion is available for this product.</>";
         }        
         break;          
      case ("SERIES"):
         samples =  '<h2>Sample Session</h2>';    
         samples += '<p>The courses in this series are listed under the outline tab.<br/>';
	 samples += 'You can select any course to view the corresponding <b>sample session.</b></p>';
         break;    
      case ("COMBINATION PACK"):
         break;  
      case ("LIBRARY"):
         break;  
      case ("SEMINAR"):
         break; 
      case ("SEMINAR SERIES"):
         break; 
   }  
 }
 
 function displayTabBar(productType) {
    //Displays the tabs depending on the tags defiined within the product.
    
    var  tabNode = document.getElementById("productTabBar");
    var  numberOfButtons = 2;
    var  tabBar =  '<p style="text-align:left;">';
         tabBar += '<table cellSpacing="0" cellPadding="10" align="left" border="0"><tbody><tr>';
    
    //Add Back button if this is not the first product visited.
    if (pathArrayIndex > 1) {
         tabBar += '<td style="width:20px;padding:0;border:0"><img id="tabimg0" onClick="goBack()" src="images/productTabUp.png"/></td>';
    }
    
    //Every product has an overview
    tabBar += '<td style="padding:0;border:0"><img id="tabimg1" onClick="gotoTab(1)" src="images/productTab1G.png"/></td>';

    if (!isNull(uses)) {
         tabBar += '<td style="padding:0;border:0"><img id="tabimg9" onClick="gotoTab(9)" src="images/productTab9G.png"/></td>';
         numberOfButtons += 1;
    }
    if (!isNull(objectives)) {
         tabBar += '<td style="padding:0;border:0"><img id="tabimg2" onClick="gotoTab(2)" src="images/productTab2G.png"/></td>';
         numberOfButtons += 1;
    }
    if (!isNull(evaluation)) {
         tabBar += '<td style="padding:0;border:0"><img id="tabimg10" onClick="gotoTab(10)" src="images/productTab10G.png"/></td>';
         numberOfButtons += 1;
    }
    if (!isNull(outline)) {
         tabBar += '<td style="padding:0;border:0"><img id="tabimg3" onClick="gotoTab(3)" src="images/productTab3G.png"/></td>';
         numberOfButtons += 1;
    }
    if (!isNull(audience)) {
         tabBar += '<td style="padding:0;border:0"><img id="tabimg4" onClick="gotoTab(4)" src="images/productTab4G.png"/></td>';
         numberOfButtons += 1;
    }
    if (!isNull(prerequisites)) {
         tabBar += '<td style="padding:0;border:0"><img id="tabimg5" onClick="gotoTab(5)" src="images/productTab5G.png"/></td>';
         numberOfButtons += 1;
    }
    if (!isNull(related)) {
         tabBar += '<td style="padding:0;border:0"><img id="tabimg6" onClick="gotoTab(6)" src="images/productTab6G.png"/></td>';
          numberOfButtons += 1;
    }
    if (!isNull(samples)) {
         tabBar += '<td style="padding:0;border:0"><img id="tabimg7" onClick="gotoTab(7)" src="images/productTab7G.png"/></td>';
         numberOfButtons += 1;
    }
    //Every product has a price
    tabBar += '<td style="padding:0;border:0"><img id="tabimg8" onClick="gotoTab(8)" src="images/productTab8G.png"/></td>';
    
    //Fill unused spots in the tab bar with the underscore graphic
    for (var i=numberOfButtons + 1; i < 9;i++) {
         tabBar += '<td style="padding:0;border:0"><img src="images/productTabFiller.png"/></td>';
    }
    
    tabBar += '</tr></tbody></table><br clear="all" />';

    var productTabBar = document.getElementById("productTabBar"); 
    productTabBar.innerHTML = tabBar;
 }
 
 function gotoTab(n) {
     //Displays the page that was selected from the tabs at the top.
     
     //Save the old product and tab in push-down stacks.
     lastTab = n; 
     tabArray[pathArrayIndex-1] = lastTab;

     //Clear the highlighted tab
     displayTabBar(productType);     

     var pageBody = document.getElementById("pageBody");
     
     switch (n) {
       case (1):
          var tabimg1 = document.getElementById("tabimg1");
          tabimg1.src = "images/productTab1B.png";
          var outHTML = "<P><STRONG><B>Order  Number:</B></STRONG>&nbsp;";
              outHTML += productNumber; + "</P>";
              outHTML += "<P><STRONG><B>Product Type:</B></STRONG>&nbsp;";
              outHTML +=  productType + "</P>";
          pageBody.innerHTML = overview + outHTML;
          break;    
       case (2):
          var tabimg2 = document.getElementById("tabimg2");
          tabimg2.src = "images/productTab2B.png";
          pageBody.innerHTML = objectives;
          break;    
       case (3):
          var tabimg3 = document.getElementById("tabimg3");
          tabimg3.src = "images/productTab3B.png";
          pageBody.innerHTML = outline;
          break;    
       case (4):
          var tabimg4 = document.getElementById("tabimg4");
          tabimg4.src = "images/productTab4B.png";
          pageBody.innerHTML = audience;
          break;    
       case (5):
          var tabimg5 = document.getElementById("tabimg5");
          tabimg5.src = "images/productTab5B.png";
          pageBody.innerHTML = prerequisites;
          break;    
       case (6):
          var tabimg6 = document.getElementById("tabimg6");
          tabimg6.src = "images/productTab6B.png";
          pageBody.innerHTML = related;
          break;    
       case (7):
          var tabimg7 = document.getElementById("tabimg7");
          tabimg7.src = "images/productTab7B.png";
          var outHTML = samples;
          pageBody.innerHTML = outHTML;
          break;   
       case (8):
          var tabimg8 = document.getElementById("tabimg8");
          tabimg8.src = "images/productTab8B.png";
          pageBody.innerHTML = buildPrices();
          break; 
       case (9):
          var tabimg9 = document.getElementById("tabimg9");
          tabimg9.src = "images/productTab9B.png";
          pageBody.innerHTML = uses;
          break; 
       case (10):
          var tabimg10 = document.getElementById("tabimg10");
	  tabimg10.src = "images/productTab10B.png";
	  pageBody.innerHTML = evaluation;
          break; 
    }
 }   
 
 function buildPrices() {
    //Displays the first Ordering page, depending on whether the product is
    //  a traditional product or a seminar-related product.
    var priceDisplayType = orderType(productType);
    userLevel = 1;
    if (priceDisplayType == 1) {
        //Traditional product
        return displayPricePage(1);
    } else {
        //Seminar
        return displayPricePage(5);    
    }
 }
 
 function orderType(x) {
   //Returns 1 or 2 depending on whether the product is a traditional product or a seminar-related product.
   switch (x.toUpperCase()) {
     case ("COURSE"):
        return 1;
        break;    
     case ("SERIES"):
        return 1;
        break;    
     case ("COMBINATION PACK"):
        return 1;
        break;  
     case ("LIBRARY"):
        return 1;
        break;  
     case ("COMPETENCY EXAM"):
        return 1;
        break;  
     case ("SEMINAR"):
        return 2;
        break; 
     case ("SEMINAR SERIES"):
        return 2;
        break; 
   }  
 }
  
 function displayPricePage(n) { 
   //Displays one of five ordering pages, depending on n.
   var pricePage = n;
   var pageHTML = '';
   
   switch (pricePage) {
     case (1):;  
     //Page 1 selects Local or MantaNow delivery
       pageHTML +=  "<p><img src='images/progress1of2.gif' /></p>"
       pageHTML += '<form id=form1 ><p>To order this product, first select the delivery method';
       pageHTML += " and, <br/>if you select Internet delivery, the license duration.</p>"; 
       pageHTML += '<p style="text-align:right;margin-top:-12pt;">';
       pageHTML += '<span class="popup" onClick="displayPopup(';
       pageHTML += "'METHOD')"
       pageHTML += '">Delivery Method Comparison</span></p>';	
       pageHTML += '<p><input type="radio" name="delivery" ';
       pageHTML += 'value="CD"/>Local Delivery (CD): ' + userPrice("1") + '</p><p>';
       pageHTML += '<input type="radio" name="delivery" ';
       pageHTML += 'value="MN1"/>Internet Delivery (MantaNow) 1 year: ' + mantaNowPrice("1") + '</p><p>';
       pageHTML += '<input type="radio" name="delivery" checked="checked" ';
       pageHTML += 'value="MN2"/>Internet Delivery (MantaNow) 2 years: ' + mantaNowPrice2("1") + '</p><p>';
       pageHTML += '<br/><img alt="Continue" src="images/Continue.png" onClick="setDelivery()"/></p></form>'; 
       break;
       
     case (2):
     //Page 2 - local delivery user selection       
       pageHTML =  "<p><img src='images/progress2of2.gif' /></p>";
       pageHTML += '<table><tbody><tr><td width=370px>';
       pageHTML += '<form id=form2><p>Then select the number of concurrent users:<br/>';
       pageHTML += '<span class="popup" onClick="displayPopup(';
       pageHTML += "'USERS')";
       pageHTML += '">Multiple User Pricing</span>';
       pageHTML += '<div id="CD" class="product">';
       pageHTML += '<span class="product-title" style="visibility:hidden;">' + productName + ' (' + productNumber + ')</span>';
       pageHTML += '<span class="product-price" style="visibility:hidden;">' + saleUserPrice("1") + '</span>';
       pageHTML += addAffiliate();
       pageHTML += '<span class="product-shipping-first" style="visibility:hidden;">$10</span>';
       pageHTML += '<span class="product-shipping" style="visibility:hidden;">$0</span>';
       pageHTML += '</p><p><input class="product-attr-users" type="radio" name="users" onClick="fixMaintPrice()" ';
       pageHTML += '    value="Local Delivery - 1 user"  googlecart-set-product-price="' + saleUserPrice("1") + '" checked="checked"/>Local Delivery - 1 user: ' + userPrice("1") + '</p><p>';
       pageHTML += '<input class="product-attr-users" type="radio" name="users" onClick="fixMaintPrice()" ';
       pageHTML += '    value="Local Delivery - 5 users" googlecart-set-product-price="' + saleUserPrice("5") + '"/>Local Delivery - 5 users: ' + userPrice("5") + '</p><p>';
       pageHTML += '<input class="product-attr-users" type="radio" name="users" onClick="fixMaintPrice()" ';
       pageHTML += '    value="Local Delivery - 10 users" googlecart-set-product-price="' + saleUserPrice("10") + '"/>Local Delivery - 10 users: ' + userPrice("10") + '</p>';
       pageHTML += '<br/><img alt="Back" src="images/Back.png" onClick="userLevel = 1;pageBody.innerHTML = displayPricePage(1)"/>&nbsp;';
       pageHTML += '<img alt="Add to cart" src="images/AddToCart.png" onClick="buyCourse(1)"/></div>';
       pageHTML += '</form></td><td width=350px>'
       if (!isNull(priceSRG)) { 
          pageHTML += displaySRGOption(productNumber,1);
       }
       if (productType.toUpperCase() == "LIBRARY") {
           pageHTML += '<p>Optionally, keep your library up to date with the ';
           pageHTML += 'Library Maintenance Plan.  ';       
           pageHTML += '<span class="popup" onClick="displayPopup(';
           pageHTML += "'MAINT')";
           pageHTML += '">What is the Maintenance Plan?</span></p><br/><br/>';    
           pageHTML += '<div id="MP" class="product">';
           pageHTML += '<span class="product-title"><i>Library Maintenance Plan</i></span>: ';
           pageHTML += '<span id="maintPrice" class="product-price">' + priceMaint() + '</span><br/><br/>';
           pageHTML += '<img alt="Add to cart" src="images/AddToCart.png" onClick="buyMaint()"/>';
           pageHTML += '</div>';
      }      
      pageHTML += '</td></tr></table><br/>';
      break; 
      
    case (3):
    //Page 3 - MantaNow one-year user selection       
       pageHTML =  "<p><img src='images/progress2of2.gif' /></p>";
       pageHTML += '<table><tbody><tr><td width="370px">';
       pageHTML += '<div id="MN" class="product product-digital"><form id=form2><p>Then select the number of concurrent users:<br/>';
       pageHTML += '<span class="popup" onClick="displayPopup(';
       pageHTML += "'USERS')";
       pageHTML += '">Multiple User Pricing</span>';	
       pageHTML += '<span class="product-title" style="visibility:hidden;">' + productName + ' (' + productNumber + ')</span>';
       pageHTML += '<span class="product-price" style="visibility:hidden;">' + saleMantaNowPrice("1") + '</span>';
       pageHTML += addAffiliate();
       pageHTML += '</p><p><input class="product-attr-users" type="radio" name="users"';
       pageHTML += '    value="MantaNow - 1 year, 1 user"  googlecart-set-product-price="' + saleMantaNowPrice("1") + '" checked="checked"/>MantaNow - 1 year, 1 user: ' + mantaNowPrice("1") + '</p><p>';
       pageHTML += '<input class="product-attr-users" type="radio" name="users"';
       pageHTML += '    value="MantaNow - 1 year, 5 users" googlecart-set-product-price="' + saleMantaNowPrice("5") + '"/>MantaNow - 1 year, 5 users: ' + mantaNowPrice("5") + '</p><p>';
       pageHTML += '<input class="product-attr-users" type="radio" name="users"';
       pageHTML += '    value="MantaNow - 1 year, 10 users" googlecart-set-product-price="' + saleMantaNowPrice("10") + '"/>MantaNow - 1 year, 10 users: ' + mantaNowPrice("10") + '</p>';
       pageHTML += '<br/><img alt="Back" src="images/Back.png" onClick="pageBody.innerHTML = displayPricePage(1)"/>&nbsp;';
       pageHTML += '<img alt="Add to cart" src="images/AddToCart.png" onClick="buyCourse(2)"/>';
       pageHTML += '</form></td><td width="350px">'
       if (!isNull(priceSRG)) { 
          pageHTML += displaySRGOption(productNumber,1);
       }
       pageHTML += '</div></td></tr></table><br/>';
       break;  

     case (4):
     //Page 4 - MantaNow two-year user selection         
       pageHTML =  "<p><img src='images/progress2of2.gif' /></p>";
       pageHTML += '<table><tbody><tr><td width=370px>';
       pageHTML += '<form id=form2><p>Then select the number of concurrent users:<br/>';
       pageHTML += '<span class="popup" onClick="displayPopup(';
       pageHTML += "'USERS')";
       pageHTML += '">Multiple User Pricing</span>';	
       pageHTML += '<div id="MN" class="product product-digital">';
       pageHTML += '<span class="product-title" style="visibility:hidden;">' + productName + ' (' + productNumber + ')</span>';
       pageHTML += '<span class="product-price" style="visibility:hidden;">' + saleMantaNowPrice2("1") + '</span>';
       pageHTML += addAffiliate();
       pageHTML += '</p><p><input class="product-attr-users" type="radio" name="users"';
       pageHTML += '    value="MantaNow - 2 years, 1 user"  googlecart-set-product-price="' + saleMantaNowPrice2("1") + '" checked="checked"/>MantaNow - 2 years, 1 user: ' + mantaNowPrice2("1") + '</p><p>';
       pageHTML += '<input class="product-attr-users" type="radio" name="users"';
       pageHTML += '    value="MantaNow - 2 years, 5 users" googlecart-set-product-price="' + saleMantaNowPrice2("5") + '"/>MantaNow - 2 years, 5 users: ' + mantaNowPrice2("5") + '</p><p>';
       pageHTML += '<input class="product-attr-users" type="radio" name="users"';
       pageHTML += '    value="MantaNow - 2 years, 10 users" googlecart-set-product-price="' + saleMantaNowPrice2("10") + '"/>MantaNow - 2 years, 10 users: ' + mantaNowPrice2("10") + '</p>';
       pageHTML += '<br/><img alt="Back" src="images/Back.png" onClick="pageBody.innerHTML = displayPricePage(1)"/>&nbsp;';
       pageHTML += '<img alt="Add to cart" src="images/AddToCart.png" onClick="buyCourse(2)"/></div>';
       pageHTML += '</form></td><td width="350px">'
       if (!isNull(priceSRG)) { 
          pageHTML += displaySRGOption(productNumber,1);
       }
       pageHTML += '</td></tr></table><br/>';
       break;

     case (5):
     //Page 5 - Seminar   
       pageHTML =  "<br/>";
       pageHTML += '<div id="Sem" class="product product-digital">';
       pageHTML += '<span class="product-title">' + productName + ' (' + productNumber + ')</span>:&nbsp;';
       pageHTML += '<span>' + mantaNowPrice("1") + '</span><br/><br/>';
       pageHTML += '<span class="product-price" style="visibility:hidden;">' + saleMantaNowPrice("1") + '</span>';
       pageHTML += '<img alt="Add to cart" src="images/AddToCart.png" onClick="buySeminar()"/></div>';
       if (!isNull(priceSRG)) {    
         pageHTML += '<br/><div id="SRG" class="product product-digital">';
         pageHTML += '<span class="product-title">' + SRGname() + '</span> ';
         pageHTML += '<span class="product-price"> ' + getPriceSRG() + '</span><br/>';
         pageHTML += '<span class="popup" onClick="displayPopup(';
         pageHTML += "'HANDOUT')";
         pageHTML += '">What is a handout?</span></p><br/>';
         pageHTML += '<img alt="Add to cart" src="images/AddToCart.png" onClick="buyHandout()"/>';
         pageHTML += '</div>'; 
       }
   } 
   return pageHTML;
}

function displayPopup(x) {
   //Displays pop-up help boxes over order pages
   //These are not detected as pop-ups and work much faster
   //An onClick is used to call this routine and passs the pop-up name.
   
   var popDiv = document.getElementById("popup");
   var outHTML = '<div class="mypop">';
   
   switch (x.toUpperCase()) {
     case ("METHOD"): 
        outHTML += '<table border=1 bgcolor="white" cellpadding="2" cellspacing="0" width="750">';
        outHTML += '<tr><td class="style4">&nbsp;</td>';
        outHTML += '<td class="style5" style="text-align:center"><b>MantaNow!</b></td>';
        outHTML += '<td class="style5" style="text-align:center"><b>Local Delivery</b></td></tr><tr>';
        outHTML += '<td><b>License Duration and Pricing</b></td>';
        outHTML += '<td>The MantaNow license is an annual, renewable license.<br/><br/>';
        outHTML += 'The price for a one-year license is 62% of the corresponding ';
        outHTML += 'CD delivery price.  The price for a two-year license is the ';
        outHTML += 'same as the price for CD delivery.  After the second year, ';
        outHTML += "you pay only a maintenance fee (equal to 15% of the product's CD list price).</td><td>";
        outHTML += 'The license for a product purchased for local delivery is perpetual.';
        outHTML += ' (It never expires.)  Therefore, you pay once and can use the product forever.<br/><br/>';
        outHTML += 'Future product and software updates must be purchased separately.</td></tr><tr>';
        outHTML += '<td><b>Maintenance (Course Updates and New Courses)</b></td><td>';
        outHTML += 'Course updates are immediately available to students. ';
        outHTML += 'In other words, you receive <b>free, immediate maintenance.</b>';
        outHTML += '<br/><br/>';
        outHTML += 'If we add a course to a product you purchased (such as a ';
        outHTML += 'combination pack), you have immediate access to the new ';
        outHTML += 'course <b>at no extra charge.</b></td><td>';
        outHTML += 'If Manta updates a product you have purchased, you can buy ';
        outHTML += 'an upgrade at that time.<br/><br/>';
        outHTML += 'Customers who purchase the entire Manta <i>IBM i Training ';
        outHTML += 'Library</i> can enroll in the <b>Library Maintenance Plan</b> ';
        outHTML += 'to receive all new courses and course updates for a fixed ';
        outHTML += 'annual fee.</td></tr><tr>';
        outHTML += '<td><b>Installation and Setup</b></td><td>';
        outHTML += 'We perform the setup work and email you the URL to access the training.<br/><br/>';
        outHTML += 'This means that your students need not be at a particular location ';
        outHTML += 'or have access to a particular system to take the training. ';
        outHTML += 'Students can take the training at the office, at home, or on the road. ';
        outHTML += 'And, you can support students who are at multiple offices.<br/><br/>';
        outHTML += 'Be aware the performance of MantaNow! delivery depends on the speed of ';
        outHTML += 'your Internet connection.</td><td>';
        outHTML += 'Installation is performed using <i>InstallShield.</i>  The course ';
        outHTML += 'presentation software requires 8 megabytes of available hard disk ';
        outHTML += 'space. Each course needs additional space (typically, 1-2 megabytes).<br/><br/>';
        outHTML += 'A single-user license lets you install the purchased product(s) on ';
        outHTML += 'one computer.  This may be a stand-alone PC or a network file server. ';
        outHTML += 'The courseware can be moved from one computer to ';
        outHTML += 'another, as long as it is uninstalled from the first system before ';
        outHTML += 'it is installed on the second system.   With a multiple-user license, ';
        outHTML += 'you can install the courseware on a server or on independent systems ';
        outHTML += 'up to the license limit.</td></tr><tr><td><b>Student Administration</b></td><td>';
        outHTML += 'Basic student ID/password management is provided at no charge.  Complete ';
        outHTML += 'functionality is available for an annual fee.  (For a single-user license, ';
        outHTML += 'the price is $50 for a course, $100 for a series, $150 for a combo pack, ';
        outHTML += 'and $200 or the complete library.)</td><td>';
        outHTML += 'The Student Administration option is not available with local delivery.</td>';
        outHTML += '</tr><tr><td><b>Audio</b></td>';
        outHTML += '<td>Audio is available with selected courses. ';
        outHTML += '</td><td>Audio (other than sound effects) is not available with local delivery.</td>';
        outHTML += '</tr></table>   ';     
        break;
     case ("USERS"): 
        outHTML += ' <p align="center">';
        outHTML += '<img hspace="10" src="images/3d_multiusers.gif" width="333"></p>';
        outHTML += '<table style="width: 90%" align="center"><tr>';
        outHTML += '<td><p>Individuals and most small organizations prefer the <b>single-user</b> ';
        outHTML += 'license. The single-user license does not limit the number of students ';
        outHTML += 'who can use a product, only the number who can be using it at the same time. </p>';
        outHTML += '<p>If your organization prefers to train students in groups, rather ';
        outHTML += 'than one at a time, consider a <b>multiple-user</b> license. Unlike ';
        outHTML += 'the single-user license, the multiple-user license lets more than one ';
        outHTML += 'student at a time use the same product. The price of a multiple-user ';
        outHTML += 'license is computed as follows: <ul>';
        outHTML += '<li>5-user license: 1.5 times the product price </li>';
        outHTML += '<li>10 user license: 2 times the product price </li>';
        outHTML += '<li>For each user over 10: 20% of the product price </li></ul>';
        outHTML += '<p>Keep in mind that the price depends on the maximum number of <i>concurrent</i> ';
        outHTML += 'users, not the total number of users. For example, if you want 50 students ';
        outHTML += 'to take a course in a given week, a 10-student license should be sufficient.</p>';
        outHTML += '<p>The user limit applies to whatever product(s) you order within the ';
        outHTML += '<b>IBM i Training Library.</b> If you buy a one-user license for ';
        outHTML += 'the entire library, for example, only one student can use the library ';
        outHTML += 'at a time. To increase the number of students who can train simultaneously, ';
        outHTML += 'you can move to a five-user license for the library or buy additional ';
        outHTML += 'user capabilities for only those products used by multiple students. ';
        outHTML += 'A popular combination is a single-user license for the library and a ';
        outHTML += 'five-user license for the <b>Program Development Combination Pack.</b>';
        outHTML += '</p></td></tr></table>';
        break;
     case ("SRG"): 
	outHTML += '<p align="center">';
	outHTML += '<img alt="Student Reference Guides" src="images/3d_srgs.jpg" width="300px" border="0">';
	outHTML += '</p><table style="width: 90%" align="center"><tr><td>';
	outHTML += '<p>Student Reference Guides are available for all Manta series and stand-alone ';
	outHTML += 'courses. Each Student Reference Guide includes a summary of all major ';
	outHTML += 'topics covered in the courses. A detailed IBM i glossary is also ';
	outHTML += 'included. As a result, the guides make an excellent reference when students ';
	outHTML += 'have finished their studies and are back on the job.</p><p>';
	outHTML += 'The Student Reference Guides are optional additions to the Manta ';
	outHTML += 'course materials. Because each guide also provides a place to take ';
	outHTML += 'notes, we recommended that each student acquire his or her own copy.</p><p>';
	outHTML += 'The Student Reference Guides are not sold by themselves.  To purchase a ';
	outHTML += 'guide, you must also purchase at least one copy of the corresponding ';
	outHTML += 'course or series.</p><p>';
	outHTML += 'You will receive a 20% discount by ordering 10 or more copies of a ';
	outHTML += 'given SRG.  We offer free shipping for 5 or more copies of a given SRG.	</p><p>';
	outHTML += 'If you order a combination pack or the complete library, you will ';
	outHTML += 'receive a similar discount on the corresponding SRG set.  With the ';
	outHTML += 'complete library, for example, you can get a complete set of the 26 ';
	outHTML += 'available Student Reference Guides for only $840.  That’s a ';
	outHTML += '<b>savings of $240</b> off the price of the individual SRGs.</p></td></tr></table>';
        break;
     case ("HANDOUT"): 
	outHTML += '<p align=center>'
	outHTML += '<IMG alt="Seminar Handouts" src="images/3d_handouts.gif"  border=0></p>';
	outHTML += '<table style="width: 90%" align="center"><tr><td>';
	outHTML += '<p>Each instructor has the option of including a <b>handout</b> with ';
	outHTML += 'his or her seminar. Most handouts are in PDF format. When a handout is ';
	outHTML += 'available, it costs an additional $10. (For multiple students in the ';
	outHTML += 'same seminar, the organization must decide whether to purchase a handout ';
	outHTML += 'for all students or for none.) PDF handouts are delivered automatically ';
	outHTML += 'to the student&#39;s browser when he or she accesses the seminar.</p></td></tr></table>';       
        break;
     case ("MAINT"): 
	outHTML += '<p align="center"><img alt="Maintenance Plan" src="images/3d_maintenance.jpg" width=300 border="0"></p>';
	outHTML += '<table style="width: 90%" align="center"><tr><td>';
	outHTML += '<p>Customers who purchase the entire Manta <i>IBM i Training Library</i> ';
	outHTML += 'for local delivery can enroll in our Library Maintenance Plan.  By enrolling ';
	outHTML += 'in the plan, you will receive all new courses and all course updates.  Typically,';
	outHTML += 'you will get a new CD twice a year.</p><p>';
	outHTML += 'The cost of the program is $1500 per year for a single-user license, $2250 for ';
	outHTML += '5 users, and $3000 for 10 users.</p><p>';
	outHTML += 'The library maintenance plan applies only to local delivery.  Customers ';
	outHTML += 'who purchase products for MantaNow! delivery receive free product and ';
	outHTML += 'software updates for the duration of their MantaNow! license.</p></td></tr></table>';
        break;
   }
   
   outHTML += '<br/><center><input type="button" onClick="closePopup()" value="Exit" /></center><br/></div>';
   
   var mynode = document.getElementById("headline");
   popDiv.style.top  = 50;
   popDiv.style.left = mynode.style.left;
   popDiv.innerHTML = outHTML;
}

function closePopup() {
   //Receives control from the pop-up Exit button to close the window.
   var popDiv = document.getElementById("popup");
   popDiv.innerHTML = "";
}

function displaySRGOption(productNumber,shippingMethod) {
   //Returns HTML describing the SRG option.
   //Has to get the price from the product XML and compute the shipping.
   //Shipping method 1=standard, shipping method 2 = overnight
   
   var baseShipping = 0;
   var firstShipping = 0;

   //first determine base shipping
   switch (productNumber.toUpperCase()) {
     case ("LIBRARY"):
        baseShipping = 26;
        break;
     case ("CIAW0A"):
        baseShipping = 2;
        break;
     case ("WEBCUR"):
	baseShipping = 5;
        break;
     case ("RPGCUR"):
	baseShipping = 7;
        break;
     case ("PGMCUR"):
	baseShipping = 10;
        break;
     case ("SYSOPR"):
	baseShipping = 12;
        break;
     case ("ADMCUR"):
	baseShipping = 8;
        break;
     case ("OPRCUR"):
	baseShipping = 5;
        break;
     default:
	baseShipping = 1;
   }
   //alert(productNumber+" costs " + baseShipping)
      
   //Then set rate based on delivery method and whether first product.
   //Overnight (option 2) is twice as much.
   //Can expand this for international
   switch (shippingMethod) {
      case (1):
         firstShipping = 10 + baseShipping;
         break; 
      case (2):
         baseShipping  = 2 * baseShipping;
         firstShipping = 25 + baseShipping;
         break; 
   }

   //finally, build HTML insert
   var pageHTML  = '<p>Optionally, purchase the companion Student Reference Guide.  '       
       pageHTML += '<span class="popup" onClick="displayPopup(';
       pageHTML += "'SRG')"
       pageHTML += '">What is an SRG?</span></p><br/>';
       pageHTML += '<div id="SRG" class="product">';
       pageHTML += '<span class="product-title"><i>' + SRGname() + '</i></span>: ';
       pageHTML += '<span class="product-price">' + getPriceSRG() + '</span><br/><br/>';
       pageHTML += '<span class="product-shipping-first" style="visibility:hidden;">' + dollarize(firstShipping) + '</span>';
       pageHTML += '<span class="product-shipping"style=" visibility:hidden;">' + dollarize(baseShipping) + '</span><br/>';
       pageHTML += '<img alt="Add to cart" src="images/AddToCart.png" onClick="buySRG()"/></div>';
   return pageHTML;
}

function buyCourse(d){ 
   //Gets control when "Add to cart" is selected for a product.
   //D=1 if came from a CD page; D=2 if came from a MantaNow page
   //Whole purpose of this is to set a flag to force customers to buy a product
   //  before buying an SRG.
   
   boughtCourse = true;
   
   //Add product to the cart
   if (d == 1) {
      googlecart.addItem(googlecart.makeItemFromNode(document.getElementById("CD")));
   } else {
      googlecart.addItem(googlecart.makeItemFromNode(document.getElementById("MN")));
   }   
}

function fixMaintPrice() {
   //Adjusts the maintenance plan price dynamically as the customer selects the user level.
   f = document.getElementById("form2");
   if (f.users[0].checked) {
       userLevel = 1;
   } else {
      if (f.users[1].checked) {
         userLevel = 5;
      } else {
         userLevel = 10;
      }
   }
   if ((productType.toUpperCase() == "LIBRARY")) {
       priceNode = document.getElementById("maintPrice");
       priceNode.innerHTML = priceMaint();
   }
}

function buySRG() {
   //Gets control when "Add to cart" is selected for an SRG.
   if (boughtCourse) {
       googlecart.addItem(googlecart.makeItemFromNode(document.getElementById("SRG")));
   } else {
       alert("You must buy the training product before you can buy the SRG.");
   }
}

function buyMaint() {
   //Gets control when "Add to cart" is selected for the maint. plan.
   if (boughtCourse) {
       googlecart.addItem(googlecart.makeItemFromNode(document.getElementById("MP")));
   } else {
       alert("You must buy the library before you can buy the Maintenace Plan.");
   }
}

function buySeminar() {
   //Gets control when "Add to cart" is selected for a seminar.
   boughtSeminar = true;
   googlecart.addItem(googlecart.makeItemFromNode(document.getElementById("Sem")));
}

function buyHandout() {
   //Gets control when "Add to cart" is selected for a seminar handout.
   if (boughtSeminar) {
      googlecart.addItem(googlecart.makeItemFromNode(document.getElementById("SRG")));
   } else {
      alert("You must buy the seminar before you can buy the handout.");
   }
}

function priceMaint() {
   //Returns the price of the maint. plan based on user level.
   //Price should go to $1500 as of 8/1/09.
   
   var baseMaint = 1500;
   
   if (userLevel == 1) {
        return dollarize(baseMaint);
   } else {
      if (userLevel == 5) {
        return dollarize(1.5 * baseMaint);
      } else {
        return dollarize(2 * baseMaint);
      }
   }   
}
  
function getPriceSRG() {
   return "$" + priceSRG;
}

function setDelivery() {
   //Invoked by "Continue" button after customer selects CD, MN 1 yr, or MN 2 years
   //It displays the next page which includes the user level selection and options.
   
   var form = document.getElementById("form1");
   var pageBody = document.getElementById("pageBody");
   
   if (form.delivery[0].checked) {
       pageBody.innerHTML = displayPricePage(2);
   } else {
      if (form.delivery[1].checked) {
         pageBody.innerHTML = displayPricePage(3);
      } else {
         pageBody.innerHTML = displayPricePage(4);
      }
   }   
}

function SRGname() {
   //Returns the name of the SRG, SRG Set, or Handout, depending on the product type
   //The order number is included.
   
   var outName = productName;
   
   switch (productType.toUpperCase()) {
     case ("COURSE"):
        outName += " Student Reference Guide (" + productNumber + "H)";
        break;    
     case ("SERIES"):
        outName += " Student Reference Guide (" + productNumber + "H)";
        break;    
     case ("COMBINATION PACK"):
        outName += " Student Reference Guide Set (" + productNumber + "H)";
        break;  
     case ("LIBRARY"):
        outName += " Student Reference Guide Set (SRGSET)";
        break;  
     case ("SEMINAR"):
        outName += " Handout (" + productNumber + "H)";
        break; 
     case ("SEMINAR SERIES"):
        outName += " Handout Set (" + productNumber + "H)";
        break; 
   }
   return outName;
}

function demoAvailable() {
   //This function returns true if a demo is available for this product
   if (sampleSession.length > 0) {
      return true;
   } else {
      return false;
   }
}
 
function addAffiliate() {
    if (isNull(affiliate)) {
       return "";
    } else {
       return '<span class="product-sku" style="visibility:hidden;">Affiliate=' + affiliate + '</span>';
    }
}

function onSale() {
   //This function sets the discount, depending on the product type and sale in effect.
 
   switch(productType.toLowerCase()) {
   case "course":
       if (courseDiscount == "0") {
          discount = 0;
          return false; 
       } else {
          discount = courseDiscount;
          return true;
       }
       break;   
      case "series":
         if (seriesDiscount == "0") {
            discount = 0;
            return false; 
         } else {
            discount = seriesDiscount;
            return true;
         }
         break;
      case "combination pack":
         if (comboDiscount == 0) {
            discount = 0;
            return false;          
         } else {
            discount = comboDiscount;
            return true;         
         }
         break;
      case "library":
         if (libraryDiscount == 0) {
            discount = 0;
            return false;          
         } else {
            discount = libraryDiscount;
            return true;         
         }
         break;
      default:
         discount = 0;
         return false;       
    }
 }
 
 function studentMultiplier(licLevel) {
    //This function computes the multiplier for multiple-user licenses.
    switch (licLevel) {
       case "1": return 1;
       case "5": return 1.5;
       case "10": return 2;
       default:
         if (licLevel > 10) {
            return licLevel/5;
         } else {
            alert("Invalid license level = " + licLevel);
         }
    }
 }
 
 function rounder(n,r) {
    //This function rounds to the nearest multiple of r.
    return Math.round(eval(n)/r) * r;
 }
 
 function dollarize(n) {
 //This function converts an integer to the form $xx,xxx.00.
    var str = "" + n;
    var len = str.length;
    if (len > 3) {
       var commapsn = len - 3;
       return "$" + str.substring(0,commapsn) + "," + str.substring(commapsn) + ".00";
    } else {
       return "$" + str + ".00";
    }
 }
 
function userPrice(licLevel) {
   //Generates the HTML string containing the CD price plus the sale price or COMMON member price.
   if (commonMember()) {
       return "<strike>" + dollarize(priceCD * studentMultiplier(licLevel)) + "</strike>&nbsp;" + 
       '<b>COMMON Member Price:</b> ' + 
      '<span style="color:red;">'+dollarize(rounder(rounder(priceCD * (1 - discount),2) * studentMultiplier(licLevel),1)) + '</span>';	   
   } else {
      if (onSale()) {
         return "<strike>" + dollarize(priceCD * studentMultiplier(licLevel)) + "</strike>&nbsp;" + 
         '<b>Sale:</b> ' + 
         '<span style="color:red;">' + dollarize(rounder(rounder(priceCD * (1 - discount),2) * studentMultiplier(licLevel),1)) + '</span>';
      } else {
         return dollarize(rounder(priceCD * studentMultiplier(licLevel),1)); 
      }
   }
}
 
function saleUserPrice(licLevel) {
   //Generates the HTML string containing the CD sale price.
   if (commonMember()) {
	   return dollarize(rounder(rounder(priceCD * (1 - discount),2) * studentMultiplier(licLevel),1));	
   } else {
	  if (onSale()) {
         return dollarize(rounder(rounder(priceCD * (1 - discount),2) * studentMultiplier(licLevel),1));
      } else {
         return dollarize(rounder(priceCD * studentMultiplier(licLevel),1)); 
      }
   }
}
 
function mantaNowPrice(licLevel) {
   //Generates the HTML string containing the 1-year MantaNow price plus the sale price or COMMON member price.
   if (commonMember()) {
       return "<strike>" + dollarize(priceMantaNow * studentMultiplier(licLevel)) + "</strike>&nbsp;" + 
       '<b>COMMON member price:</b> ' + 
       '<span style="color:red;">'+ dollarize(rounder(rounder(priceMantaNow * (1 - discount),2) * studentMultiplier(licLevel),1)) + '</span>';
   } else {
	  if (onSale()) {
         return "<strike>" + dollarize(priceMantaNow * studentMultiplier(licLevel)) + "</strike>&nbsp;" + 
         '<b>Sale:</b> ' + 
         '<span style="color:red;">' + dollarize(rounder(rounder(priceMantaNow * (1 - discount),2) * studentMultiplier(licLevel),1)) + '</span>';
      } else {
         return dollarize(rounder(priceMantaNow * studentMultiplier(licLevel),1)); 
      }
   }
}

function saleMantaNowPrice(licLevel) {
   //Generates the HTML string containing the 1-year MantaNow sale price.
   if (commonMember()) {
	   return dollarize(rounder(rounder(priceMantaNow * (1 - discount),2) * studentMultiplier(licLevel),1));	   
   } else {
	   if (onSale()) {
         return dollarize(rounder(rounder(priceMantaNow * (1 - discount),2) * studentMultiplier(licLevel),1));
       } else {
         return dollarize(rounder(priceMantaNow * studentMultiplier(licLevel),1)); 
       }
   }
}
 
function mantaNowPrice2(licLevel) {
   //Generates the HTML string containing the 2-year MantaNow price plus the sale price or COMMON member price.
   if (commonMember()) {
       return "<strike>" + dollarize(priceCD * studentMultiplier(licLevel)) + "</strike>&nbsp;" + 
       '<b>COMMON member price:</b> ' + 
       '<span style="color:red;">' + dollarize(rounder(rounder(priceCD * (1 - discount),2) * studentMultiplier(licLevel),1)) + '</span>';	   
   } else {
   	   if (onSale()) {
          return "<strike>" + dollarize(priceCD * studentMultiplier(licLevel)) + "</strike>&nbsp;" + 
          '<b>Sale:</b> ' + 
          '<span style="color:red;">' + dollarize(rounder(rounder(priceCD * (1 - discount),2) * studentMultiplier(licLevel),1)) + '</span>';
      } else {
         return dollarize(rounder(priceCD * studentMultiplier(licLevel),1));
      }
   }
}
 
function saleMantaNowPrice2(licLevel) {
   //Generates the HTML string containing the 2-year MantaNow sale price.
   if (commonMember()) {
	  return dollarize(rounder(rounder(priceCD * (1 - discount),2) * studentMultiplier(licLevel),1));	   
   } else {
	   if (onSale()) {
          return dollarize(rounder(rounder(priceCD * (1 - discount),2) * studentMultiplier(licLevel),1));
       } else {
          return dollarize(rounder(priceCD * studentMultiplier(licLevel),1));
       }
   }
}

function xwriteQuestion() {
   //Called when a customer selects a sample session
   //This is the test version, which  bypasses the questionaire
    var sampleURL = "http://www.mantanow.com/samples.html#session=" + sampleSession;
    var sampleWindow = window.open(sampleURL,"_blank");
}

function writeQuestion() {
   //Called when a customer selects a sample session
   self.document.location = "questions.html#" + sampleSession;
} 
 
function writeBookmark(name,value,retention) {
    document.cookie = name + "=" + escape(value) + "; expires=" + GMTDate(retention);
}
 
 function getBookmark(name)  {
    var arg = name + "=";
    var argLength = arg.length;
    var cLength  = document.cookie.length;
    var i = 0;
    //alert("Searching for '" + arg + "' of length " + argLength + " in cookie of length " + cLength)
    //alert("in getBookmark. "+document.cookie);
    while (i < cLength) {
       var j = i + argLength;
       if (document.cookie.substring(i,j) == arg) {
          var endstr = document.cookie.indexOf(";",j);
          if (endstr == -1)
            endstr = document.cookie.length;
          return unescape(document.cookie.substring(j, endstr));
       }
       i = document.cookie.indexOf(" ", i) + 1;
       if (i == 0) break;
    }
    return null;
 }
 function deleteBookmark(name) {
    if (getBookmark(name)) {
      document.cookie = name + "=" + "; expires=" + GMTDate(-2);
    }
}
 function GMTDate(n) {
    var today = new Date();
    var expDate = today.getTime() + (n * 24 * 60 * 60 * 1000);
    today.setTime(expDate);
    return today.toGMTString();
 }
 

 function encodeMe(value)  {
    //Encode parameters for placement on a URL.
    if (encodeURIComponent) return encodeURIComponent(value);
    if (escape) return escape(value);
    return value;
}

function pushProduct(s) {
   //Add a product s and the current tab selection to the push-down stack.
   pathArray[pathArrayIndex] = s;
   tabArray[pathArrayIndex] = lastTab;
   pathArrayIndex += 1;
}

function popProduct() {
   //Return the PREVIOUS entry from the stack and clear the last one.
   if (pathArrayIndex < 1) {
      return "";
   } else {
      pathArrayIndex -= 1;
      pathArray[pathArrayIndex] = "";
      tabArray[pathArrayIndex] = "";
      lastTab = tabArray[pathArrayIndex-1];
      return pathArray[pathArrayIndex-1];
   }
}

function goBack() {
   //Gets control when the user clicks the "Back" button on a product page.
   //alert ("at start.\nindex="+pathArrayIndex+"\narray:\n"+dumpTable(pathArray)
   //     + "lastTab=" + lastTab + "\ntabArray:\n" + dumpTable(tabArray));
   if (pathArrayIndex == 0) {
      alert("Progamming error: No products on stack.");
   } else {
   //get product data from server
      var myUrl2 = myUrl + popProduct() + ".xml";
      callAjax(myUrl2,parseProduct,'A');
   //alert ("at end.\nindex="+pathArrayIndex+"\narray:\n"+dumpTable(pathArray)
   //        + "lastTab=" + lastTab + "tabArray:\n" + dumpTable(tabArray));
   }
}

function dumpTable(x) {
    //For debuggin to put a table into a pretty format.
    var j = x.length;
    var out="";
    for (i=0;i<j;i++) {
       out +=x[i] + "\n";  
    }
    return out;
}

//
// String functions
// 
 
 function getElementAsString(x) {
     var theNode = sessionNode.getElementsByTagName(x)[0];
     if ((theNode) && (theNode.hasChildNodes())) {     
        return removeLeadingCR(getChildrenAsText(theNode));
     } else {
        return "";
     }
 }
 
 function getChildrenAsText(topNode)  {
 // This function returns a text string that is built from the text
 // and child nodes of topNode
 //alert(topNode.nodeName + " " +topNode.nodeType+" "+topNode.nodeValue)
    var childList = topNode.childNodes;
    var NumberofChildren = childList.length;
    var nextNode;
    var childType;
    var textStr = "";
    var attrList;
    var nameOfNode;
    var numberofAttributes;
    var attrString = "";
    //alert("number of children = " +NumberofChildren);
    if (NumberofChildren == 0) {return}
    for (var i = 0; i < NumberofChildren; i++) {
       nextNode = childList[i];
       childType = nextNode.nodeType;
       //alert(childType + " " + nextNode.nodeValue)
       
       switch (childType) {
         case "ELEMENT_NODE":
         case 1:
           nameOfNode = nextNode.nodeName;
           //alert(nameOfNode)
           if ((nameOfNode != "ANSWER") &&
               (nameOfNode != "WRONG")  &&
               (nameOfNode != "UNEXPECTED")  &&
               (nameOfNode != "HINT")  &&
               (nameOfNode != "GIVEANS")) {
               attrList = nextNode.attributes;
               attrString = "";
               numberofAttributes = attrList.length;
               for (var j = 0; j <  numberofAttributes; j++) {
                  attrString = attrString + ' '+ attrList[j].nodeName + '="' + attrList[j].nodeValue + '"';
               }
               if (nextNode.hasChildNodes()) {
                  textStr = textStr + "<" + nameOfNode + " " + attrString + ">" + getChildrenAsText(nextNode)+ "</" + nameOfNode +">";
               } else {
                 textStr = textStr + "<" + nameOfNode + " " + attrString + "/>";
               }
           }
           break;
         case "ATTRIBUTE_NODE":
         case 2:
           alert("Attribute node");
           break;
         case "TEXT_NODE":
         case 3:
          textStr = textStr + nextNode.nodeValue;
          break;
       case "CDATA_SECTION_NODE":
       case 4:
          textStr = textStr + nextNode.nodeValue;
          break;
       case "ENTITY_NODE":
       case 6:
          alert("Entity node");
          textStr = textStr + getChildrenAsText(nextNode);
          break;
       }
    }
    return textStr;
 }

 function removeLeadingCR(x) {
 //  If string x starts with a carriage return, it is removed.
     if (x.substr(0,1) == '\n') x = x.substr(1);
     return x;
 }
 
 function rTrim(str) {
 //
 //        PURPOSE: Remove trailing blanks from our string.
 //        IN: str - the string we want to RTrim
 //
 //        RETVAL: An RTrimmed string!
 //    
    // We don't want to trip JUST spaces, but also tabs,
    // line feeds, etc.  Add anything else you want to
    // "trim" here in Whitespace
    var whitespace = new String(" \r\n\t");
    var s = new String(str);
 
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
       // We have a string with trailing blank(s)...
       var i = s.length - 1;       // Get length of string
       // Iterate from the far right of string until we
       // don't have any more whitespace...
       while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
          i--;
       // Get the substring from the front of the string to
       // where the last non-whitespace character is...
       s = s.substring(0, i+1);
   }
   return s;
 }
 
 function lTrim(str)  {
 //
 //     PURPOSE: Remove leading blanks from our string.
 //     IN: str - the string we want to LTrim
 //
 //     RETVAL: An LTrimmed string!
 //
    var whitespace = new String(" \n\r\t");
    var s = new String(str);
 
    if (whitespace.indexOf(s.charAt(0)) != -1) {
    // We have a string with leading blank(s)...
        var j=0, i = s.length;
        // Iterate from the far left of string until we
        // don't have any more whitespace...
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
           j++;
        // Get the substring from the first non-whitespace
        // character to the } of the string...
        s = s.substring(j, i);
    }
 
    return s;
}

function isNull(x) {
//This utility function returns true if string x is null, undefined, or empty.
   if ((x == 'undefined') || (x == "") || (x == null) || (x == "null")) {
       return true;
   } else {
       return false;   
   }
}

//
//   AJAX Functions
//

function createXMLHttp() {
// This function instantiates a new Ajax object.
  if (typeof XMLHttpRequest != "undefined") {
      return new XMLHttpRequest();
  } else {
     if (window.ActiveXObject) {
        var aVersions = ["Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0",
                         "Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP",
                        "Microsoft.XMLHTTP"];
        for (var i = 0; i < aVersions.length; i++) {
           try {
              var oXmlHttp = new ActiveXObject(aVersions[i]);
              //log("Using XMLHTTP number " + i);
              return oXmlHttp; 
           } catch (e) {
           }
        }
     }
  }
  alert('XMLHTTP is not available.  You have an obsolete or damaged browser.');
}

function callAjax(url, objCallBack,syncMode) {
//This function sends the HTTP request to url and then calls objCallback upon the return.
   var xmlHttp = createXMLHttp();
   if (syncMode == "A") {
      xmlHttp.open('GET', url, true);
   } else {   
      xmlHttp.open('GET', url, false);     
   }
   xmlHttp.setRequestHeader("Cache-Control","nocache");
   xmlHttp.onreadystatechange = function() {
     //alert("getting URL=" + url);
     if (xmlHttp.readyState == 4) {
        //alert("callAjax.  readystatus="+ xmlHttp.status);
        if (xmlHttp.status == 200) {
            //alert(xmlHttp.getAllResponseHeaders());
            //alert("Returned text data in callAjax():" + xmlHttp.responseText)
            //alert(xmlHttp.responseText)
            //alert(xmlHttp.responseXML.documentElement)
            //alert(xmlHttp.responseXML.documentElement.firstChild.nodeValue)
            //alert("Returned XML data in callAjax():" + xmlHttp.responseXML.documentElement.nodeValue)
            
            //Test if timed out or fatal error.

            if (xmlHttp.responseXML.documentElement) {
               var ajaxReturnCode = parseInt(xmlHttp.responseXML.documentElement.getAttribute("RETURNCODE"));
               //alert("ReturnCode="+ ajaxReturnCode);
            }
               
            //Call specified return handler
            objCallBack(xmlHttp);
        } else {
            //alert("Cannot contact the Manta server.\nPlease check your Internet connection and then try again.")
        }
      }
   }
   xmlHttp.send(null);
}

function commonMember() {
//This function sets the discount for COMMON members, depending on the product type and sale in effect.
    if (affiliate != "COMMON") {
    	return false;
    } else {
	   switch(productType.toLowerCase()) {
	      case "course":
	         discount = .10;
	         break; 
	      case "competency exam":
			 discount = .10;
			 break;
	      case "seminar":
		     discount = .10;
		     break; 
	      case "seminar series":
			 discount = .10;
			 break; 
	      case "series":
             discount = Math.max(seriesDiscount,.25);
	         break;
	      case "combination pack":
	    	 discount = Math.max(comboDiscount,.25);
	         break;
	      case "library":
	    	 discount = Math.max(libraryDiscount,.25);       
	         break;
	      default:
	         discount = 0;
	    }
		return true;	   
	 }
}
