//
//  Copyright Manta Technologies Inc., 2008, 2009, 2010, 2011.  All rights reserved.  
//
//

// Sale Definition
// 0.00 is list price.
var seriesDiscount  = 0.0;
var comboDiscount   = 0.25;
var libraryDiscount = 0.0;
var courseDiscount  = 0.0;
var seminarDiscount = 0.0;
var comboOnSale = "PGMCUR";

//Global variables
var discount       = 0;
var affiliate      = "";
var product        = "";
var samples        = "";
var saleText       = "";
var userLevel      = 0;
var boughtSeminar  = false;
var boughtCourse   = false;
var multipleUsersActive = false;
var hasSRG = false;
var pageBody;
var productID;
var box1;
var box2;
var box3;
var box4;
var box5;
var box6;
var box7;
var box8;
var box9;
var box10;
var box11;

if (isNull(priceSRG)) {
	hasSRG = false;
} else {
	hasSRG = true;
}

function displayProduct() {
 //	
 // Entry point from other pages
 // Parse input string and save affiliate
 // If present, input assumed to be in form ?Affiliate=yyyy
 //
 
    var url = self.location.href;
    var index1 = url.indexOf("Affiliate=");
    if (index1 > -1) {
       affiliate = url.substring(index1+10).toUpperCase(); 
    }
    //alert("Affiliate='" + affiliate + "'");
    setAffiliate(affiliate);
    document.title = "Manta Technologies Inc. - " + productName;
    var titleBar  = "<h1>" + productName + "</h1>";
    document.getElementById("productNameBar").innerHTML = titleBar;
    clearDisplay();
    buildSampleMessage(productType);
    displayTabBar(productType);
    gotoTab(1);
}
function clearDisplay() {
    pageBody = document.getElementById("pageBody");
    pageBody.style.display = "none";
    productID = document.getElementById("productID");
    productID.style.display = "none";
    if (overview) {
        box1 = document.getElementById("overview");
        box1.style.display = "none";
    }
    if (objectives) {
        box2  = document.getElementById("objectives");
        box2.style.display = "none";
    }
    if (outline) {
        box3  = document.getElementById("outline");
        box3.style.display = "none";
    }
    if (audience) {
        box4  = document.getElementById("audience");
        box4.style.display = "none";
    }
    if (prerequisites) {
        box5  = document.getElementById("prerequisites");
        box5.style.display = "none";
    }
    if (related) {
        box6  = document.getElementById("related");
        box6.style.display = "none";
    }
    if (!isNull(samples)) {
        box7  = document.getElementById("samples");
        box7.style.display = "none";
    }
    box8  = document.getElementById("prices");
    box8.style.display = "none";

    if (uses) {
        box9  = document.getElementById("uses");
        box9.style.display = "none";
    }
    if (evaluation) { 
        box10 = document.getElementById("evaluation");
        box10.style.display = "none";
    }
    if (schedule) {
        box11 = document.getElementById("schedule");
        box11.style.display = "none";
    }
}
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 buildSampleMessage(x) {
    // Builds the "Sample Session" page depending on the product type.
    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="21px" src="images/binoc.gif" width="22px" 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 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="21px" src="images/binoc.gif" width="22px" 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 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; 
      case ("ILT"):
          break;       
   }  
}
 
 function displayTabBar(productType) {
    // Displays the tabs depending on the tags defined within the product.

    var  numberOfButtons = 2;
    var  tabBar =  '<p style="text-align:left;">';
         tabBar += '<table cellSpacing="0" cellPadding="10" align="left" border="0"><tbody><tr>';
    
    //Every product has an overview
    tabBar += '<td style="padding:0;border:0;cursor:pointer;"><img id="tabimg1" onClick="gotoTab(1)"  title="View course overview and duration." src="images/productTab1G.png"/></td>';

    if (uses) {
         tabBar += '<td style="padding:0;border:0;cursor:pointer;"><img id="tabimg9" onClick="gotoTab(9)"  title="View recommended exam uses." src="images/productTab9G.png"/></td>';
         numberOfButtons += 1;
    }
    if (objectives) {
         tabBar += '<td style="padding:0;border:0;cursor:pointer;"><img id="tabimg2" onClick="gotoTab(2)" title="View course objectives." src="images/productTab2G.png"/></td>';
         numberOfButtons += 1;
    }
    if (evaluation) {
         tabBar += '<td style="padding:0;border:0;cursor:pointer;"><img id="tabimg10" onClick="gotoTab(10)"  title="View evaluation criteria." src="images/productTab10G.png"/></td>';
         numberOfButtons += 1;
    }
    if (outline) {
         tabBar += '<td style="padding:0;border:0;cursor:pointer;"><img id="tabimg3" onClick="gotoTab(3)"  title="View an outline." src="images/productTab3G.png"/></td>';
         numberOfButtons += 1;
    }
    if (audience) {
         tabBar += '<td style="padding:0;border:0;cursor:pointer;"><img id="tabimg4" onClick="gotoTab(4)"  title="View the audience description." src="images/productTab4G.png"/></td>';
         numberOfButtons += 1;
    }
    if (prerequisites) {
         tabBar += '<td style="padding:0;border:0;cursor:pointer;"><img id="tabimg5" onClick="gotoTab(5)"  title="View the prerequisites." src="images/productTab5G.png"/></td>';
         numberOfButtons += 1;
    }
    if (related) {
         tabBar += '<td style="padding:0;border:0;cursor:pointer;"><img id="tabimg6" onClick="gotoTab(6)"  title="View related products." src="images/productTab6G.png"/></td>';
          numberOfButtons += 1;
    }
    if (!isNull(samples)) {
         tabBar += '<td style="padding:0;border:0;cursor:pointer;"><img id="tabimg7" onClick="gotoTab(7)"  title="View a sample session." src="images/productTab7G.png"/></td>';
         numberOfButtons += 1;
    }
    if (schedule) {
        tabBar += '<td style="padding:0;border:0;cursor:pointer;"><img id="tabimg11" onClick="gotoTab(11)"  title="Workshop schedule" src="images/productTab11G.png"/></td>';
        numberOfButtons += 1;
   }    
    // Every product has a price
    tabBar += '<td style="padding:0;border:0;cursor:pointer;"><img id="tabimg8" onClick="gotoTab(8)" title="Determine price and order the product." 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" />';

    document.getElementById("productTabBar").innerHTML = tabBar;
 }
 
 function gotoTab(n) {
     // Displays the page that was selected from the tabs at the top.
     // Clear the highlighted tab
     displayTabBar(productType);     
     clearDisplay();
     switch (n) {
       case (1):
          var tabimg1 = document.getElementById("tabimg1");
          tabimg1.src = "images/productTab1B.png";
          box1.style.display = "block";
          var outHTML = "<P><STRONG><B>Order  Number:&nbsp;</B></STRONG>";
              outHTML += productNumber;
              outHTML += "</P><P><STRONG><B>Product Type:</B></STRONG>&nbsp;";
              outHTML +=  productType + "</P>";
          productID.innerHTML = outHTML;
          productID.style.display = "block";
          break;    
       case (2):
          var tabimg2 = document.getElementById("tabimg2");
          tabimg2.src = "images/productTab2B.png";
          box2.style.display = "block";
          break;    
       case (3):
          var tabimg3 = document.getElementById("tabimg3");
          tabimg3.src = "images/productTab3B.png";
          box3.style.display = "block";
          break;    
       case (4):
          var tabimg4 = document.getElementById("tabimg4");
          tabimg4.src = "images/productTab4B.png";
          box4.style.display = "block";
          break;    
       case (5):
          var tabimg5 = document.getElementById("tabimg5");
          tabimg5.src = "images/productTab5B.png";
          box5.style.display = "block";
          break;    
       case (6):
          var tabimg6 = document.getElementById("tabimg6");
          tabimg6.src = "images/productTab6B.png";
          box6.style.display = "block";
          break;    
       case (7):
          var tabimg7 = document.getElementById("tabimg7");
          tabimg7.src = "images/productTab7B.png";
          box7.innerHTML = samples;
          box7.style.display = "block";
          break;   
       case (8):
          var tabimg8 = document.getElementById("tabimg8");
          tabimg8.src = "images/productTab8B.png";
          box8.style.display = "block";
          box8.innerHTML = buildPrices();
          break; 
       case (9):
          var tabimg9 = document.getElementById("tabimg9");
          tabimg9.src = "images/productTab9B.png";
          box9.style.display = "block";
          break; 
       case (10):
          var tabimg10 = document.getElementById("tabimg10");
	      tabimg10.src = "images/productTab10B.png";
          box10.style.display = "block";
          break; 
       case (11):
          var tabimg11 = document.getElementById("tabimg11");
 	      tabimg11.src = "images/productTab11B.png";
          box11.style.display = "block";
          break; 
    }
     //Set height and width of screen area.
}   
 
 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 {
    	if (productType.toUpperCase() == "ILT") {
    		// Instructor-led class
            return displayPricePage(4);  
    	} 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; 
     case ("ILT"):
         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 - MantaNow one-year user selection 
       userLevel = 1;
       if (hasSRG) {
           pageHTML =  "<p><img src='images/progress1.gif' /></p>";
       } else {
           pageHTML =  "<p><img src='images/progress1of2.gif' /></p>";
       }    	  
       pageHTML += '<form name=form1><p><b>Select the number of <u>concurrent</u> users.</b></p>';
       pageHTML += '<p><span  class="popup" onClick="displayPopup(';
       pageHTML += "'USERS')";
       pageHTML += '">About Multiple User Pricing</span></p>';     
       pageHTML += '<form name=form1>';
       pageHTML += '<p><input type="radio" name="users" value="1" onClick="activateInput(1)" checked="checked"/>1 user: ' + mantaNowPrice(1) + '</p><p>';
       pageHTML += '<input type="radio" name="users" value="5"  onClick="activateInput(2)"/>5 users: ' + mantaNowPrice(5) + '</p><p>';
       pageHTML += '<div id="mybox" style="border-style:solid;background-color:#D0D0D0;border-width:1px;border-color:gray;padding3px;">';       
       pageHTML += '<input type="radio" name="users" value="m" onClick="activateInput(3)"/>';       
       pageHTML += '<span id="musers"><input id="mi" type="text" style="background-color:#D0D0D0;" size="1" maxLength="0" name="musers" onChange="computeUsers(this.form)" value="10"/> users: ' + mantaNowPrice(10) + '</span>';
       pageHTML += '&nbsp;&nbsp; (You can change the user count and press the <b>Tab</b> key to see the corresponding price.) </div></p>'
       pageHTML += '<br/><img alt="Continue" src="images/Continue.png" onClick="setUserCount()"/>';
       pageHTML += '</form>'
       break;  
    case (2):
       // Page 2 - MantaNow license term selection  
       if (hasSRG) {
          pageHTML =  "<p><img src='images/progress2.gif' /></p>";
       } else {
          pageHTML =  "<p><img src='images/progress2of2.gif' /></p>";
       }
       pageHTML += '<p><b>Select the duration of your license.</b></p>';
       pageHTML += '<p>The prices shown below include a discount for prepaying the second and third years. ';
       pageHTML += 'By prepaying, you also lock in the price based on the current number of courses that are in the ';
       pageHTML += 'the product you ordered.  While new courses are free during your current license term, they ';
       pageHTML += 'may cause a slight increase in later years when you renew.  Currently, customers who have purchased this '; 
       pageHTML += 'product are paying the following renewal rates:</p><br/>';  	   
       pageHTML += '<ul><li>Price for the second year: ' + secondYearPrice(userLevel) + '</li>';
       pageHTML += '<li>Price for the third and later years: ' + maintPrice(userLevel) + '</li></ul><br/>'; 
       pageHTML += '<form id=form2><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;">0</span>';  
       pageHTML += addAffiliate();
       pageHTML += '<p style="margin-top:-24px;"><input class="product-attr-users" type="radio" name="users" ';
       pageHTML += 'value="one year, ' + userText(userLevel) + '" googlecart-set-product-price="' + saleMantaNowPrice(userLevel);
       pageHTML += '"/>' + userText(userLevel) + ', one year: ' + saleMantaNowPrice(userLevel) + '</p>';          	
       pageHTML += '</p><p>';
       pageHTML += '<p><input class="product-attr-users" type="radio" name="users" value="two years, ' + userText(userLevel);
       pageHTML += '"  googlecart-set-product-price="' + twoYearPrice(userLevel);
       pageHTML += '"/>' + userText(userLevel) + ', two years: ' + twoYearPrice(userLevel) + '&nbsp;&nbsp;<b>You save ' + twoYearSavings(userLevel) + ' and lock in current prices.</b></p>';          	   
       pageHTML += '</p><p>';
       pageHTML += '<p><input class="product-attr-users" type="radio" name="users" value="three years, ' + userText(userLevel);
       pageHTML += '"  googlecart-set-product-price="' + threeYearPrice(userLevel);
       pageHTML += '"/>' + userText(userLevel) + ', three years: ' + threeYearPrice(userLevel) + '&nbsp;&nbsp;<b>You save ' + threeYearSavings(userLevel) + ' and lock in current prices.</b></p>';          	
       pageHTML += '<p><img alt="Back" src="images/Back.png" onClick="box8.innerHTML = displayPricePage(1)"/>&nbsp;';
       pageHTML += '<img alt="Add to cart" src="images/AddToCart.png" onClick="buyCourse(2)"/></p>';
       pageHTML += '</div>';
       pageHTML += '</form>';
       break;  
    case (3):
    	// Page 3 SRG selection
    	break;
    case (4):
        // Page 4 - Workshop  
          pageHTML =  '<br/><p>If you are ready to pay with a credit card, please click the "Add to Cart" button.  Otherwise, ';
          pageHTML += 'click the "Register" button and we will send you an invoice.  Complete payment is required ';
          pageHTML += 'before you will be admitted to the workshop.</p><p>';
          pageHTML += 'You will receive a full refund if you cancel 30 days or more before an event.</p><br/>';
          pageHTML += '<div id="Sem" class="product product-digital">';
          pageHTML += '<span class="product-title"><b>' + productName + ' </b>(' + productNumber + ')</span>:&nbsp;';
          pageHTML += '<span>' + mantaNowPrice(1) + '</span><br/><br/>';
          pageHTML += addAffiliate();
          pageHTML += '<span class="product-price" style="visibility:hidden;">' + saleMantaNowPrice(1) + '</span>';
          pageHTML += '<img alt="Add to cart" src="images/AddToCart.png" onClick="buySeminar()"/>&nbsp;&nbsp;&nbsp;&nbsp;';
          pageHTML += '<a href="register.shtml#' + productNumber +'"><img alt="Add to cart" src="images/Register.png" onClick="buySeminar()"/></a></div>';          
        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 += addAffiliate();
       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 computeUsers(form) {
	//Changes the price following the user level of the first form page.
	var inputSpan = document.getElementById("musers");
	var numberUsers = form.musers.value;	
	var outHTML = '<input type="text" name="musers" size="1" onChange="computeUsers(this.form)" value="'
	    outHTML += numberUsers + '"/> users: ' + mantaNowPrice(numberUsers);
    inputSpan.innerHTML = outHTML;
}

function activateInput(n) {
	// This function toggles the optional user level field between white and grey.
	var inputDiv = document.getElementById("mybox");   

	if (multipleUsersActive && (n==1 || n==2)) {
		 document.form1.elements[3].style.backgroundColor="#D0D0D0";
		 document.form1.elements[3].maxLength="0";
		 inputDiv.style.backgroundColor="#D0D0D0";
		 inputDiv.style.borderColor="#D0D0D0";		 
	     multipleUsersActive = false;
	} else {
		if (!multipleUsersActive && (n==3)) {	
			document.form1.elements[3].style.backgroundColor="white";
			document.form1.elements[3].maxLength="3";
			inputDiv.style.backgroundColor="white";	
			inputDiv.style.borderColor="white";
		    multipleUsersActive = true;	
		}
	}
}

function setUserCount() {
	// Sets userLevel to the number of users selected by the customer and displays page 2 of the order form.
	if (document.form1.elements[0].checked) {
		userLevel = 1;
	} else {
		if (document.form1.elements[1].checked) {
			userLevel = 5;
	    } else {
	    	userLevel = document.form1.elements[3].value;
	    }
	}
	box8.innerHTML = displayPricePage(2);
}

function userText(n) {
	// Returns a text description of the user count in the form 'single user' or '5 users'
	if (n==1) {
		return "single user"
	} else {
		return n + " users"
	}	
}

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 pass the pop-up name.
   
   var popDiv = document.getElementById("popup");
   var outHTML = '';
   
   switch (x.toUpperCase()) {
     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. </p><p> ';
        outHTML += 'You can move from a single-user license ';
        outHTML += 'to a 5-user license by multiplying the single-user price by 1.5.  ';
        outHTML += 'For each user over 5, add 10% of the product price to the 5-user price.</p>';
        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 ("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;
   }
   
   outHTML += '<br/><center><input type="button" onClick="closePopup()" value="Exit" /></center><br/>';
   
   //var mynode = document.getElementById("pageBody");
   //alert( mynode.style.top+"   " + mynode.style.left)
   //popDiv.style.top = mynode.style.top;
   //popDiv.style.left = mynode.style.left;
   popDiv.style.display = "block";
   popDiv.innerHTML = outHTML;
}

function closePopup() {
   // Receives control from the pop-up Exit button to close the window.
   var popDiv = document.getElementById("popup");
   popDiv.style.display = "none";
   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><img src='images/progress3.gif' /></p>";
       pageHTML += '<p><b>Order Student Reference Guides.</b></p>';  
   	   pageHTML += '<p>Student Reference Guides are available for all Manta series and stand-alone ';
	   pageHTML += 'courses. Each Student Reference Guide includes a summary of all major ';
	   pageHTML += 'topics covered in the courses. A detailed IBM i glossary is also ';
	   pageHTML += 'included. As a result, the guides make an excellent reference when students ';
	   pageHTML += 'have finished their studies and are back on the job. ';
	   pageHTML += 'Because each guide also provides a place to take ';
	   pageHTML += 'notes, we recommend that each student acquire his or her own copy.</p>';
	if ((productType.toUpperCase() == "COMBINATION PACK") || (productType.toUpperCase() == "LIBRARY")) {
	   pageHTML += '<p>The price below includes a discount for ordering the SRGs for all of the courses in this package.</p>';
	}
       pageHTML += '<br/><div id="SRGPRT" class="product"><form id="form2" name="form2">';
       pageHTML += 'Quantity:&nbsp;<input name="srgprt" class="googlecart-quantity" size="1" value="1"/>&nbsp;&nbsp;'+ SRGname() + ' at ' +  getPriceSRG() + ' each</p><p>';   
       pageHTML += '<span class="product-title" style="visibility:hidden;"><i>' + SRGname() + '</i></span>';
       pageHTML += '<span class="product-price" style="visibility:hidden;">' + getPriceSRG() + '</span>';
       pageHTML += '<span class="product-shipping-first" style="visibility:hidden;">' + dollarize(firstShipping) + '</span>';
       pageHTML += '<span class="product-shipping" style=" visibility:hidden;">' + dollarize(baseShipping) + '</span>';
       pageHTML += addAffiliate();
       pageHTML += '</div>';
       pageHTML += '<br/><img alt="Back" src="images/Back.png" onClick="box8.innerHTML = displayPricePage(2)"/>&nbsp;';
       pageHTML += '<img alt="Add to cart" src="images/AddToCart.png" onClick="buySRG()"/>';
       pageHTML += '</form>'
       pageHTML += '<br/>';   

   return pageHTML;
}

function buyCourse(d){ 
   // Gets control when "Add to cart" is selected for a product.
   // Whole purpose of this is to set a flag to force customers to buy a product before buying an SRG.
   var anySelected = false;
   var salesForm = document.getElementById("form2");
   for (var i=0; i < 3; i++) {
	   if (salesForm.users[i].checked) {
		   anySelected = true;
	   }
   }
   if (anySelected) {
      boughtCourse = true;
      googlecart.addItem(googlecart.makeItemFromNode(document.getElementById("MN")));
      if (hasSRG) {
         box8.innerHTML = displaySRGOption(productNumber,1);
      } else {
    	 gotoTab(1); 
      }
   } else {
	  alert("Please pick a license duration.");
   }
}

function buySRG() {
	// Gets called if the user clicks the "Add to  Cart" button for an SRG.
	var salesForm = document.getElementById("form2");
	if (salesForm.srgprt.value > 0) {
		googlecart.addItem(googlecart.makeItemFromNode(document.getElementById("SRGPRT")));
	}
	gotoTab(1);
}

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 getPriceSRG() {
   return "$" + priceSRG;
}

function getPdfPriceSRG() {
	//Sets price for PDF version of SRG.
	//For a single course, it is $10.  Else, it is 1/2 the printed price.
	if (isNull(priceSRG)) {
		return "$10.00";
	} else {
	   return "$" + rounder(priceSRG * .5,1) + ".00";
	}
}

function SRGname() {
   // Returns the name of the SRG, SRG Set, or Handout, depending on the product type.
   // The order number is included.
   
   var outName = '<i>' + productName;
   var suffix = "</i> (" + productNumber +  "H)";
   
   //var suffix = "";
   //if (type == "P") {
   //	   suffix = "PDF Version (" + productNumber +  "P)";
   //} else {
	//   suffix = "Printed Version (" + productNumber +  "H)";	   
   //}
   
   switch (productType.toUpperCase()) {
     case ("COURSE"):
        outName += " Student Reference Guide " + suffix;
        break;    
     case ("SERIES"):
        outName += " Student Reference Guide  " + suffix;
        break;    
     case ("COMBINATION PACK"):
        outName += " Student Reference Guide Set " + suffix;
        break;  
     case ("LIBRARY"):
        outName += " Student Reference Guide Set " + suffix;
        break;  
     case ("SEMINAR"):
        outName += " Handout " + suffix;
        break; 
     case ("SEMINAR SERIES"):
        outName += " Handout Set " + suffix;
        break; 
   }
   return outName;
}

function demoAvailable() {
   // This function returns true if a sample session is available for this product.
   if (sampleSession.length > 0) {
      return true;
   } else {
      return false;
   }
}
 
function addAffiliate() {
	// Adds the affiliate name, if present, to the order so that they can get a commission.
    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) || ((!isNull(comboOnSale)) && (comboOnSale != productNumber)))  {
            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 price multiplier for multiple-user licenses.
    switch (licLevel) {
       case 1: return 1;
       case 5: return 1.5;
       default:
         if (licLevel > 5) {
            return 1.5 + (licLevel-5)/10;
         } else {
            return 1.5;
         }
    }
 }
 
 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 maintPrice(licLevel) {
   // Generates the HTML string containing the maintenance price.
   return dollarize(rounder(priceMaint * studentMultiplier(licLevel),1)); 
}
function secondYearPrice(licLevel) {
   // Generates the HTML string containing the price for the second year.	
   if (mantaAffiliate()) {
	   return dollarize(rounder(rounder(priceMantaNow * (1 - discount),2) * studentMultiplier(licLevel) * .5,1));	   
   } else {
	   if (onSale()) {
         return dollarize(rounder(rounder(priceMantaNow * (1 - discount),2) * studentMultiplier(licLevel) * .5,1));
       } else {
         return dollarize(rounder(priceMantaNow * studentMultiplier(licLevel)* .5,1)); 
       }
   }
}

function twoYearPrice(licLevel) {
   // Generates the HTML string containing the price for a 2-year license.	
   // The 1.4 multiplier includes 20% off for the second year.
   if (mantaAffiliate()) {
	   return dollarize(rounder(rounder(priceMantaNow * (1 - discount),2) * studentMultiplier(licLevel) * 1.4,1));	   
   } else {
	   if (onSale()) {
         return dollarize(rounder(rounder(priceMantaNow * (1 - discount),2) * studentMultiplier(licLevel) * 1.4,1));
       } else {
         return dollarize(rounder(priceMantaNow * studentMultiplier(licLevel)* 1.4,1)); 
       }
   }
}
function twoYearSavings(licLevel) {
  // Generates the HTML string containing the savings attained by buying a 2-year license.	
	if (mantaAffiliate()) {
	   return dollarize(rounder(rounder(priceMantaNow * (1 - discount),2) * studentMultiplier(licLevel) * .1,1));	   
	} else {
	   if (onSale()) {
	      return dollarize(rounder(rounder(priceMantaNow * (1 - discount),2) * studentMultiplier(licLevel) * .1,1));
	   } else {
	      return dollarize(rounder(priceMantaNow * studentMultiplier(licLevel)* (.1),1)); 
	   }
   }
}

function threeYearPrice(licLevel) {
   // Generates the HTML string containing the price for a 3-year license.
   // The 1.6 multiplier includes 20% off for the second and third years.
   if (mantaAffiliate()) {
	   return dollarize(rounder(rounder(priceMantaNow * (1 - discount),2) * studentMultiplier(licLevel) * 1.6,1));	   
   } else {
	   if (onSale()) {
         return dollarize(rounder(rounder(priceMantaNow * (1 - discount),2) * studentMultiplier(licLevel) * 1.6,1));
       } else {
         return dollarize(rounder(priceMantaNow * studentMultiplier(licLevel)* 1.6,1)); 
       }
   }
}

function threeYearSavings(licLevel) {
	// Generates the HTML string containing the savings attained by buying a 2-year license.	
	if (mantaAffiliate()) {
	  return dollarize(rounder(rounder(priceMantaNow * (1 - discount),2) * studentMultiplier(licLevel) * .15,1));	   
	} else {
	   if (onSale()) {
	      return dollarize(rounder(rounder(priceMantaNow * (1 - discount),2) * studentMultiplier(licLevel) * .15,1));
	   } else {
	      return dollarize(rounder(priceMantaNow * studentMultiplier(licLevel)* (.15),1)); 
	   }
	}
}

function mantaNowPrice(licLevel) {
   // Generates the HTML string containing the 1-year MantaNow price plus the sale price or affiliate discount price.
   if (mantaAffiliate()) {
       return "<strike>" + dollarize(priceMantaNow * studentMultiplier(licLevel)) + "</strike>&nbsp;" + 
       '<b>' + saleText + '</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 (mantaAffiliate()) {
	   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 xwriteQuestion() {
   // Called when a customer selects a sample session.
   // This is the test version, which  bypasses the questionaire.
    var sampleURL = "http://mantatest/MantaNow/samples.html#session=" + sampleSession;
    var sampleWindow = window.open(sampleURL,"_blank");
}

function writeQuestion() {
   // Called when a customer selects a sample session.
   self.document.location = "questions.shtml#" + 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;
}



//
// 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 mantaAffiliate() {
   // This function sets the discount for affiliates, depending on the product type and sale in effect.

	// Only do something if there is an affiliate ID present.
    if (isNull(affiliate) || (affiliate == "MANTA")) {
	   return false;
    } 
    
	var affiliateIndex = 0;
	var affiliateFound = false;
	
	var affiliates         = new Array();
	var affiliateText      = new Array();  
	var discountCourse     = new Array();
	var discountCompExam   = new Array();
	var discountSeminar    = new Array();
	var discountSeminarSeries = new Array();
	var discountSeries    = new Array();
	var discountComboPack = new Array();
	var discountLibrary   = new Array();
    //COMMON
	    affiliates[0] = "COMMON";
	    affiliateText[0] = "COMMON member price:";
	    discountCourse[0]        = .10;
	    discountCompExam[0]      = .10;
	    discountSeminar[0]       = .10;
	    discountSeminarSeries[0] = .10;
	    discountSeries[0]        = .25;
	    discountComboPack[0]     = .25;
	    discountLibrary[0]       = .25;
	//MCPress
	    affiliates[1] = "MCSTORE";
	    affiliateText[1] = "MC Press price:";
	    discountCourse[1]        = .05;
	    discountCompExam[1]      = .05;
	    discountSeminar[1]       = .05;
	    discountSeminarSeries[1] = .05;
	    discountSeries[1]        = .05;
	    discountComboPack[1]     = .05;
	    discountLibrary[1]       = .05;	    
	//Model
	    affiliates[2] = "MODEL";
	    affiliateText[2] = "Affiliate price:";
	    discountCourse[2]        = .00;
	    discountCompExam[2]      = .00;
	    discountSeminar[2]       = .00;
	    discountSeminarSeries[2] = .00;
	    discountSeries[2]        = .00;
	    discountComboPack[2]     = .00;
	    discountLibrary[2]       = .00;	

    //Determine affiliate
	affiliateIndex = 0;
	while (!affiliateFound && (affiliateIndex < affiliates.length)) {
		if (affiliate != affiliates[affiliateIndex]) {
			affiliateIndex++;
		} else {
			affiliateFound = true;
			//alert("Found affiliate " + affiliate);
		}
	}
	if (!affiliateFound) {
		//alert("Affiliate " + affiliate + " not in table.");
        return false;
	}
    //Found affiliate.  Set price.
	switch(productType.toLowerCase()) {
	   case "course":
	      discount = discountCourse[affiliateIndex];
	      break; 
	   case "competency exam":
		  discount = discountCompExam[affiliateIndex];
		  break;
	   case "seminar":
		  discount = discountSeminar[affiliateIndex];
		  break; 
	   case "seminar series":
		  discount = discountSeminarSeries[affiliateIndex];
		  break; 
	   case "series":
         discount = Math.max(seriesDiscount,discountSeries[affiliateIndex]);
	     break;
	   case "combination pack":
	     discount = Math.max(comboDiscount,discountComboPack[affiliateIndex]);
	     break;
	   case "library":
	     discount = Math.max(libraryDiscount,discountLibrary[affiliateIndex]);       
	     break;
	   default:
	     discount = 0;
	}
    saleText = affiliateText[affiliateIndex];
	return true;	   
}

function displayMaintPrices(productNumber) {
	// Returns HTML describing the maintenance prices.
	// Has to get the price from the product XML.
	var pageHTML  = '<p>Current prices for maintenance:<br/>(This is the optional renewal price for each subsequent year.)<br/><br/></p>'       
        pageHTML += '<p style="margin-top:13px;">1 user: ' + maintPrice('1') + '</p>';
        pageHTML += '<p style="margin-top:13px;">5 users: ' + maintPrice('5') + '</p>';
        pageHTML += '<p style="margin-top:13px;">10 users: ' + maintPrice('10') + '</p>';
	return pageHTML;
}

