//=================================================================================== // Pay Per Download //=================================================================================== // // Author: Jim Frey // Technology Manager // Section of Business Law // 312-988-5507 // freyj@staff.abanet.org // // Last Modified: 03/18/04 // - Made image optional, eliminates cell when absent // - Made product code optional, eliminates when absent // - Added ABA Member Free link // Last Modified: 02/13/04 // - Modified Business Law pointers to generic ABA // - Altered download folder // Last Modified: 06/17/03 // - Release of Version 1.1 // - Credit Card Verification // - Multiple copies for purchase // - Download link click counting based on purchase number // - Moved the 'Download' link to the top of the page // - Counts billing totals // - Addition of a contact email for problems // // Last Modified: 05/01/03 // - Release of Version 1.0 // //=================================================================================== // // This code is copyright and may not be reproduced in any format. //=================================================================================== // GLOBAL VARIABLES //=================================================================================== // The upper and lower limits for the credit card expiration year var ccyearlimits = { lowerlimit:2003, upperlimit:2020 }; // The amount of days the approval cookie should last var cookiedays = 7; //=================================================================================== // PROGRAMMER DEFINED GLOBAL VARIABLES //=================================================================================== // Customer Information var orderinfo = { firstname:{value:""}, lastname:{value:""}, firm:{value:""}, street1:{value:""}, street2:{value:""}, city:{value:""}, state:{value:""}, zip:{value:""}, country:{value:""}, phone:{value:""}, fax:{value:""}, emailaddy:{value:""}, numofcopies:{value:"1"}, cctype:{value:""}, ccnum:{value:""}, ccmonth:{value:""}, ccyear:{value:""} }; // Has the div statement been printed? var printdiv = false; // Have the terms been viewed at least once? var termsviewed = false; // This variable stores the credit card number displaying only the last four digits var displayccnum = ""; // This variable is used to display 'copy' or 'copies' depending on the quantity ordered var copytext = "copy"; // This is the total cost var totalcost = 0; // This is the language used for the multiple copies var multiplecopies = "These terms apply to each copy of the document you have purchased.

"; // Info pulled from cookie var cookienumofclicks = 0; var cookieapproval = false; //=================================================================================== // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX FUNCTIONS XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX //=================================================================================== //=================================================================================== // WriteDiv() // // DESCRIPTION: // This function is to write the div statement needed to alter the page // contents for the DHTML to work. // //=================================================================================== function WriteDiv() { document.write("

"+producttitle+"
"); document.write("

"); document.write("

"); document.write("

If you experience problems with this purchasing this download, please contact "+problemsemail+""); document.write("
developed by the American Bar Association"); } //=================================================================================== // PayPerDownload(pagetodisplay) // // DESCRIPTION: // This is the main function of the script. It decides what page is // to be dynamically displayed. If there is a cookie stored, it // automatically takes the surfer to the download page. If there is no // cookie and no page is defined, it defaults to the opening product page. // //=================================================================================== function PayPerDownload(pagetodisplay) { // Check for DOM if(!document.all) { document.write("





ERROR
You are using a browser that is not implementing the DOM standard. (Netscape)
"); document.write("Please revist this address with a browser compliant with DOM. (Internet Explorer)














"); return; } if (!printdiv) { WriteDiv(); printdiv = true; } if ((pagetodisplay == null) && (document.cookie)) { var allcookies = document.cookie; var pos = allcookies.indexOf("verified="); if (pos != -1) { var start = pos + 9; var end = allcookies.indexOf("|", start); if (end == -1) { end = allcookies.length; } cookieapproval = allcookies.substring(start,end); } var pos = allcookies.indexOf("numofcopies="); if (pos != -1) { var start = pos + 12; var end = allcookies.indexOf("|", start); if (end == -1) { end = allcookies.length; } orderinfo.numofcopies.value = allcookies.substring(start,end); if (orderinfo.numofcopies.value > 1) { copytext = "copies"; } } var pos = allcookies.indexOf("numofclicks="); if (pos != -1) { var start = pos + 12; var end = allcookies.indexOf("|", start); if (end == -1) { end = allcookies.length; } cookienumofclicks = allcookies.substring(start,end); } if (cookieapproval == "true") { pagetodisplay = "verifiedaccess"; } } window.scroll(0,0); switch(pagetodisplay) { case 'termsofagreement': TermsOfAgreement(); break; case 'orderinformation': OrderInformation(); break; case 'ordersummary': OrderSummary(); break; case 'orderconfirmation': OrderConfirmation(); break; case 'verifiedaccess': DownloadPage(); break; default: BookPage(); break; } } //=================================================================================== // BookPage() // // DESCRIPTION: // This function displays the opening page of the product to be sold through // DHTML. Via a button, it links to the Terms of Agreement. // //=================================================================================== function BookPage() { document.all.ppdbannernote.innerHTML = "Download this file NOW!

"; var toclinkdata = ""; if (toclink != "") { toclinkdata = "View Table of Contents
"; } var proddata = ""; if (productcode != "") { proddata = "Product Code: "+productcode+"
"; } var imgcell = ""; var blurbcell = "100%"; if (imagelink != "") { imgcell = ""; blurbcell = "400" } document.all.ppd.innerHTML = // Product Description ""+ " "+ imgcell+ " "+ " "+ "
"+ " Description:
"+description+ "

"+writertitle+": "+writername+"
"+ toclinkdata+ proddata+ " Format: Downloadable "+docformat+"
"+ " Pages: "+docsize+"
"+ " Copyright: "+docdate+"
"+ "

Non-Member Price: $"+price+"
"+ "
ABA Members: Click here for FREE instant access.

"+ "

"+ "   "+ "
"+ "
"; } //=================================================================================== // TermsOfAgreement() // // DESCRIPTION: // This function displays the Terms of the Agreement. There are two button // options on this page. If the surfer agrees to the terms, they are taken to // the page to input their order information. If they don't agree to the // terms, they are taken to the main product catalog via a link defined // by the global variables. If a user comes back to this page after another // DHTML page, they are given one button option that will bring them only to // the order information input page. // //=================================================================================== function TermsOfAgreement() { var iagree = ""; if (!termsviewed) { iagree = "

By clicking "I AGREE" below you acknowledge that you have "+ "read, understand, and agree to be bound by the terms above. If you "+ "reject the terms above by clicking "I DO NOT AGREE," you "+ "will be denied access to the "+producttitle+" that is available on this site."; } document.all.ppd.innerHTML = ""+ " "+ " "+ " "+ "
"+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ "

"+ " Terms of License Agreement"+ "

"+ multiplecopies + termsofagreement + iagree + "

"+ "
"+ "
"; if (!termsviewed) { document.all.ppd.innerHTML = document.all.ppd.innerHTML + "
"+ "   "+ ""+ "
"; termsviewed = true; } else { document.all.ppd.innerHTML = document.all.ppd.innerHTML + "
"+ "   "+ "
"; } } //=================================================================================== // GoToURL(urloflocation) // // DESCRIPTION: // This is a function that takes the surfer out of this script and onto another // web page. The page is specified as the function input. // //=================================================================================== function GoToURL(urloflocation) { location = urloflocation; } //=================================================================================== // OrderInformation() // // DESCRIPTION: // This function displays the input form needed to capture the surfer's contact // and billing information. Upon filling out the information and submitting // it on this page, the information is stored globally so it is recalled // if this page is left and revisited to be changed. // //=================================================================================== function OrderInformation() { var ccmonthselect = ""; for( x=1 ; x<=12; x++) { ccmonthselect = ccmonthselect + ""; } var ccyearselect = ""; for( x=ccyearlimits.lowerlimit ; x<=ccyearlimits.upperlimit; x++) { ccyearselect = ccyearselect + ""; } var ccnumentered = "text"; if (orderinfo.ccnum.value) { ccnumentered = "password"; } document.all.ppd.innerHTML = " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ "
  "+ " "+ " Order Information "+ " "+ "
"+ " "+ " "+ " "+ " "+ "
"+ "
"+ " "+ " "+ " "+ " "+ " "+ "
  "+ " "+ "
"+ " "+ " Please enter your billing information:
"+ " * = required field "+ " "+ " "+ " "+ " "+ " "+ "
"+ " "+ " "+ " "+ " "+ "
"+ "
"+ " "+ "
"+ " "+ " "+ " "+ " "+ " "+ " "+ "
"+ " "+ " First Name*
"+ " "+ "
"+ "
  "+ " "+ " Last Name*
"+ " "+ "
"+ "
"+ " "+ " Firm/Company
"+ "
"+ " Street Address*
"+ "
"+ "
"+ " City*
"+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ "
"+ " "+ " State/Province*
"+ " "+ "
"+ "
  "+ " "+ " Zip/Postal Code*
"+ " "+ "
"+ "
"+ " "+ " Country*
"+ " "+ "
"+ " "+ " "+ " "+ " "+ " "+ " "+ "
"+ " "+ " Business Phone*
"+ " "+ "
"+ "
  "+ " "+ " Fax Number
"+ " "+ "
"+ "
"+ " "+ " E-mail Address*
"+ "
"+ "
"+ " Purchase Options
"+ " "+ " "+ " "+ " "+ " "+ "
  "+ " "+ " Number of Copies* "+ " "+ " at $"+price+" each" + " "+ "
"+ "
"+ " Payment Information
"+ " "+ " "+ " "+ " "+ " "+ "
  "+ " "+ " "+ " Card Number*
"+ " "+ "
"+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ "
"+ " "+ " Credit Card Type*

"+ "
"+ " "+ " Exp. Month*
"+ "
"+ "
  "+ " "+ " Exp. Year*
"+ "
"+ "
"+ "
"+ "
"+ "
"+ "
"+ "   "+ " "+ "
"+ "
"+ "
"+ "
"+ "
"+ "
"+ "
"+ ""; } //=================================================================================== // StoreInfoGlobally(objectin) // // DESCRIPTION: // This function takes the refrence to the object in and stores it in a global // object variable so it can be used throught the rest of the script. // //=================================================================================== function StoreInfoGlobally(objectin) { // User Contact Information orderinfo.firstname.value = objectin.firstname.value; orderinfo.lastname.value = objectin.lastname.value; orderinfo.firm.value = objectin.firm.value; orderinfo.street1.value = objectin.street1.value; orderinfo.street2.value = objectin.street2.value; orderinfo.city.value = objectin.city.value; orderinfo.state.value = objectin.state.value; orderinfo.zip.value = objectin.zip.value; orderinfo.country.value = objectin.country.value; orderinfo.phone.value = objectin.phone.value; orderinfo.fax.value = objectin.fax.value; orderinfo.emailaddy.value = objectin.emailaddy.value; // Purchase Options orderinfo.numofcopies.value = objectin.numofcopies.value; // User Credit Card Information orderinfo.cctype.value = objectin.cctype.value; orderinfo.ccnum.value = objectin.ccnum.value; orderinfo.ccmonth.value = objectin.ccmonth.value; orderinfo.ccyear.value = objectin.ccyear.value; } //=================================================================================== // VerifyInput() // // DESCRIPTION: // This function checks the inputted information for validity // //=================================================================================== function VerifyInput() { var goodinput = true; if (orderinfo.firstname.value == "") { alert("You must input a first name."); goodinput = false; } else { if (orderinfo.lastname.value == "") { alert("You must input a last name."); goodinput = false; } else { if (orderinfo.street1.value == "") { alert("You must input a street address."); goodinput = false; } else { if (orderinfo.city.value == "") { alert("You must input a city name."); goodinput = false; } else { if (orderinfo.state.value == "") { alert("You must input a state or province.") goodinput = false; } else { if (orderinfo.zip.value == "") { alert("You must input a zip code."); goodinput = false; } else { if (orderinfo.country.value == "") { alert("You must input a country name."); goodinput = false; } else { if (orderinfo.phone.value == "") { alert("You must input a phone number."); goodinput = false; } else { if (orderinfo.emailaddy.value == "") { alert("You must enter a valid email address."); goodinput = false; } else { if (orderinfo.cctype.value == "") { alert("You must enter a credit card type."); goodinput = false; } else { if (orderinfo.ccnum.value == "") { alert("You must input a credit card number."); goodinput = false; } else { if (orderinfo.ccmonth.value == "") { alert("You must enter a credit card expiration month."); goodinput = false; } else { if (orderinfo.ccyear.value == "") { alert("You must enter a credit card expiration year."); goodinput = false; } else { if (orderinfo.numofcopies.value == "") { alert("You must input the number of copies you are ordering."); goodinput = false; } } } } } } } } } } } } } } if (goodinput && CreditCardValid()) { PayPerDownload('ordersummary'); } } //=================================================================================== // CreditCardValid() // // DESCRIPTION: // This function checks the inputted credit card number for validity. The // applied tests are on the length of the inputted number matching the // specified card length and the Luhn formula. // //=================================================================================== function CreditCardValid() { var isvalid = false; var ccnumlengthvalid = false; var ccnumexpvalid = false; var numonlyexpression = /[^\d]/; var cardnumbersonly = orderinfo.ccnum.value.replace(/ /g,""); var cardnumberslength = cardnumbersonly.length; var ccnumexpression; isvalid = !numonlyexpression.test(cardnumbersonly); // This is the check to match the length of the input numbers to the right card // This also sets the regular expression format depending on the card if (isvalid) { switch (orderinfo.cctype.value) { case "MasterCard": ccnumlengthvalid = (cardnumberslength == 16); ccnumexpression = /^5[1-5]/; break; case "Visa": ccnumlengthvalid = (cardnumberslength == 16 || cardnumberslength == 13); ccnumexpression = /^4/; break; case "American Express": ccnumlengthvalid = (cardnumberslength == 15); ccnumexpression = /^3(4|7)/; break; } ccnumexpvalid = ccnumexpression.test(cardnumbersonly); isvalid = ccnumexpvalid && ccnumlengthvalid; } // This checks the regular expression for the card based upon the Luhn formula if (isvalid) { var numberproduct; var numberproductdigitindex; var checksumtotal = 0; for (var digitcounter = cardnumberslength-1; digitcounter >= 0; digitcounter--) { checksumtotal += parseInt(cardnumbersonly.charAt(digitcounter)); digitcounter--; numberproduct = String((cardnumbersonly.charAt(digitcounter) * 2)); for (var productdigitcounter = 0; productdigitcounter < numberproduct.length; productdigitcounter++) { checksumtotal += parseInt(numberproduct.charAt(productdigitcounter)); } } isvalid = (checksumtotal % 10 == 0); } if (!isvalid) { alert("There is a problem with your credit card number. Please check the number and try again."); } return isvalid; } //=================================================================================== // OrderSummary() // // DESCRIPTION: // This function displays the surfer's inputted information and gives them the option // to go back and change any of the input. // //=================================================================================== function OrderSummary() { // Change the Credit Card number to only display the last 4 digits var ccnum = orderinfo.ccnum.value; displayccnum = ""; for ( x=0 ; x<(ccnum.length-4); x++) { displayccnum = displayccnum + "X"; } for ( x=x ; x 1) { copytext = "copies"; } totalcost = orderinfo.numofcopies.value * price; // global if (( (totalcost*100) % 100) == 0) { // Add on a zero if there are no pennies totalcost = totalcost+".00"; } else { if (( (totalcost*100) % 10) == 0) { totalcost = totalcost+"0"; } } document.all.ppd.innerHTML = " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ "
  "+ " "+ " Order Summary "+ " "+ "
"+ " "+ " "+ " "+ " "+ "
"+ "
"+ " "+ " "+ " "+ " "+ " "+ "
  "+ " "+ "
"+ " "+ " Please verify your billing information: "+ " "+ " "+ " "+ " "+ " "+ "
"+ " "+ " "+ " "+ " "+ "
"+ "
"+ " "+ "
"+ " "+ " "+ " "+ " "+ " "+ " "+ "
"+ " "+ " First Name
"+orderinfo.firstname.value+ "
"+ "
  "+ " "+ " Last Name
"+orderinfo.lastname.value+ "
"+ "
"+ " "+ "
Firm/Company
"+orderinfo.firm.value+"
"+ "
Street Address
"+orderinfo.street1.value+"
"+orderinfo.street2.value+"
"+ "
City
"+orderinfo.city.value+"

"+ " "+ " "+ " "+ " "+ " "+ " "+ "
"+ " "+ " State/Province
"+orderinfo.state.value+ "
"+ "
  "+ " "+ " Zip/Postal Code
"+orderinfo.zip.value+ "
"+ "
"+ " "+ "
Country
"+orderinfo.country.value+ "

"+ " "+ " "+ " "+ " "+ " "+ " "+ "
"+ " "+ " Business Phone
"+orderinfo.phone.value+ "
"+ "
  "+ " "+ " Fax Number
"+orderinfo.fax.value+ "
"+ "
"+ "
"+ " E-mail Address
"+orderinfo.emailaddy.value+"
"+ "
"+ " "+ " "+ " "+ " "+ " "+ "
  "+ " "+ " "+ " Card Number
 "+displayccnum+ "

"+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ "
"+ " "+ " Credit Card Type
 "+orderinfo.cctype.value+ "
  "+ " "+ " Exp. Month
    "+orderinfo.ccmonth.value+ "
"+ "
  "+ " "+ " Exp. Year
  "+orderinfo.ccyear.value+ "
"+ "
"+ "
"+ "
"+ "
"+ " You will be billed for "+orderinfo.numofcopies.value+" "+copytext+" at $"+price+" each totaling $"+totalcost+""+ "

"+ "
"+ "   "+ " "+ "
"+ "
"+ "
"+ "
"+ "
"+ "
"+ "
"+ ""; } //=================================================================================== // OrderConfirmation() // // DESCRIPTION: // This function is the final verification page. Upon submitting this page, // a cookie is set so that the surfer will be taken directly to the download page // the next time the script is run. Upon submitting this page, the function // submits the surfer's information via email to staff. // //=================================================================================== function OrderConfirmation() { cookieapproval = true; cookienumofclicks = 0; var dashlines = ""; for (x=0;x<15;x++) { dashlines = dashlines + ""; } var proddata = ""; if (productcode != "") { proddata = "Product Code: "+productcode+"
"; } document.all.ppd.innerHTML = "

"+ "

"+ ""+ ""+ ""+ // ""+ ""+ ""+ ""+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ dashlines + ""+ " "+ " "+ " "+ "
"+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ "

"+ " Order Confirmation     Please print this page for your records."+ "

"+Date()+ "

"+ " "+orderinfo.numofcopies.value+" "+copytext+" at $"+price+" each totaling $"+totalcost+"

"+ " Sold to:
"+ orderinfo.firstname.value+" "+ orderinfo.lastname.value+"
"+ orderinfo.firm.value+"
"+ orderinfo.street1.value+"
"+ orderinfo.street2.value+"
"+ orderinfo.city.value+", "+ orderinfo.state.value+" "+ orderinfo.zip.value+"

"+ " Credit Card: "+displayccnum+ "

"+ " "+producttitle+"
"+ proddata+ "
Non-Member Price: $"+price+"
"+ "
ABA Members: Click here for FREE instant access.

"+ "
"+ "

"+ "
"+ ""+ " "+ " "+ " "+ "
"+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ "

"+ " Terms"+ "

"+ multiplecopies + termsofagreement+ "

"+ "
"+ "
"+ "
"; } //=================================================================================== // SetVerifiedCookie() // // DESCRIPTION: // This function sets a cookie that allows the surfer to bypass all the input // pages and takes them directly to the download page for the diration of the // cookie. // //=================================================================================== function SetVerifiedCookie() { var exp = new Date() var nowpluscookiedays = exp.getTime() + (cookiedays * 24 * 60 * 60 * 1000) exp.setTime(nowpluscookiedays) document.cookie = "verified="+cookieapproval+"|numofcopies="+orderinfo.numofcopies.value+"|numofclicks="+cookienumofclicks+"|;expires="+exp.toGMTString(); } //=================================================================================== // DownloadPage() // // DESCRIPTION: // This page displays a link for the product download. // //=================================================================================== function DownloadPage() { document.all.ppdbannernote.innerHTML = "   You are now authorized for "+orderinfo.numofcopies.value+" "+copytext+" of this publication.

Click here to purchase additional copies.

"; var toclinkdata = ""; if (toclink != "") { toclinkdata = "View Table of Contents
"; } var proddata = ""; if (productcode != "") { proddata = "Product Code: "+productcode+"
"; } var imgcell = ""; var blurbcell = "100%"; if (imagelink != "") { imgcell = ""; blurbcell = "400" } document.all.ppd.innerHTML = ""+ " "+ imgcell+ " "+ " "+ "
"+ " DOWNLOAD NOW
"+ " Description:
"+description+ "

"+writertitle+": "+writername+"
"+ toclinkdata+ proddata+ " Format: Downloadable "+docformat+"
"+ " Pages: "+docsize+"
"+ " Copyright: "+docdate+"
"+ "

Non-Member Price: $"+price+"
"+ "
ABA Members: Click here for FREE instant access.

"+ "

"; } //=================================================================================== // PopUpDownload() // // DESCRIPTION: // This creates a pop-up with a frameset to hide the location of the file // from the title tag of the pop-up window. // //=================================================================================== function PopUpDownload() { cookienumofclicks++; SetVerifiedCookie(); var amountordered = orderinfo.numofcopies.value; amountordered++; if (cookienumofclicks <= amountordered) { var popwin = window.open("","ppddl","titlebar=no,menubar=no,toolbar=no,resizable=yes"); popwin.document.write(""+producttitle+"You need a browser that allows the use of frames to download this document."); } else alert("You have already clicked on this link "+cookienumofclicks+" times and only have purchased "+orderinfo.numofcopies.value+" "+copytext+". To purchase more copies, please follow the link on the web page. If you have experienced a problem in downloading this file, please contact "+problemsemail); }