home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / code / contr / setup.exe / Disk1 / data1.cab / Paypal_En / Configuration / Commands / Insert PayPal Subscriptions.js < prev    next >
Encoding:
JavaScript  |  2003-07-18  |  12.9 KB  |  440 lines

  1. /*-----------------------------------------------------------------------------
  2. -    File Name:
  3. -        Insert PayPal Subscriptions.js
  4. -
  5. -    Description:
  6. -        Functions for Subscriptions wizard.
  7. -
  8. -    This file contains proprietary and confidential information from WebAssist.com
  9. -    corporation.  Any unauthorized reuse, reproduction, or modification without
  10. -    the prior written consent of WebAssist.com is strictly prohibited.
  11. -
  12. -    Copyright 2002 WebAssist.com Corporation.  All rights reserved.
  13. ------------------------------------------------------------------------------*/
  14. var CURRENTPAGE=0;
  15.  
  16. function commandButtons()     {
  17.   return new Array();
  18. }
  19.  
  20. /* Initialize the UI.  First thing that's called on the body load event. */
  21. function initializeUI()     {
  22.   if (navigator.platform.toLowerCase().indexOf("mac") >= 0)     {
  23.         
  24.     document.cancel.style = "position:absolute; width:70px; height:20px; z-index:90; left: 245px; top: 397px; visibility: visible";
  25.     document.cancel.document.btnCancel.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
  26.         
  27.     document.help.style = "position:absolute; width:70px; height:20px; z-index:90; left: 175px; top: 397px; visibility: visible";
  28.     document.help.document.btnHelp.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
  29.         
  30.     document.next.style = "position:absolute; width:70px; height:20px; z-index:90; left: 385px; top: 397px; visibility: visible";
  31.     document.next.document.btnNext.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
  32.         
  33.     document.back.style = "position:absolute; width:70px; height:20px; z-index:90; left: 315px; top: 397px; visibility: visible";
  34.     document.back.document.btnBack.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
  35.         
  36.     document.finish.style = "position:absolute; width:70px; height:20px; z-index:90; left: 385px; top: 397px; visibility: visible";
  37.     document.finish.document.btnFinish.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
  38.   
  39.     document.walogo.top = 402;
  40.     document.pplogo.top = 403;
  41.   }
  42.   document.back.visibility = "visible";
  43.   document.next.visibility = "visible";
  44.   document.help.visibility = "visible";
  45.   document.cancel.visibility = "visible";
  46.   var theDOM = dreamweaver.getDocumentDOM();
  47.   var theParent = theDOM.getSelectedNode();
  48.   var inForm = false;
  49.   while (theParent.parentNode)  {
  50.     theParent = theParent.parentNode;
  51.     if (theParent.tagName=="FORM")  {
  52.         inForm = theParent;
  53.         break;
  54.     }
  55.     }
  56.   if (inForm)  {
  57.     if (inForm.innerHTML.search(/<input type="[^"]*"[^>]*\sname="cmd"[^>]*>/i)>=0)  
  58.     {
  59.         alert(MSG_AlreadyPayPalInForm);
  60.         window.close();
  61.     }
  62.   }
  63.   MM.setBusyCursor();
  64.    
  65.   showPageNum(0);
  66.   
  67.   getLastUID();  
  68.   enableDisableOtherImage();
  69.   enableDisableStopRecurring();
  70.   MM.clearBusyCursor();
  71. }
  72.  
  73. /******************************** support functions ******************/
  74. function buildSummaryText()     {
  75.   var retVal = "";
  76.   var myID       = findObject("ppUID").value;
  77.   var myImage    = findObject("subimage");
  78.   var myImageURL = "";
  79.   var myItemName = findObject("subscriptionName").value;
  80.   var myItemID = findObject("subscriptionID").value;
  81.   var myAmount = findObject("subscriptionPrice").value;
  82.   var myCurrency = findObject("itemCurrency").options[findObject("itemCurrency").selectedIndex].value;    
  83.   var myTrial1 = findObject("trial1Amount").value;
  84.   var myTrial2 = findObject("trial2Amount").value;
  85.   var myIncludeShipping = true;
  86.   var myBillRecurring = true; 
  87.   var myReattemptPayment = true;
  88.   if (findObject("includeShipping")[1].checked)
  89.   {
  90.     myIncludeShipping = false;
  91.   }
  92.   if (findObject("recurringBilling")[1].checked)
  93.   {
  94.     myBillRecurring = false;
  95.   }   
  96.   if (findObject("reattemptBilling")[1].checked)
  97.   {
  98.     myReattemptPayment = false;
  99.   }
  100.   var myLogoURL = findObject("ppLogo").value;
  101.   var mySuccessURL = findObject("successURL").value;
  102.   var myCancelURL = findObject("cancelURL").value;
  103.     
  104.   retVal += "PayPal Account: " + myID;
  105.   retVal += "\n";
  106.   retVal += "Button Image URL: ";
  107.   for (var n=0; n<myImage.length; n++)
  108.   {
  109.     if (myImage[n].checked)
  110.     {
  111.       if (myImage[n].value == "other")
  112.       {
  113.         retVal += findObject("othersubimage").value;      
  114.       }
  115.       else
  116.       {
  117.         retVal += "http://images.paypal.com/images/" + myImage[n].value;      
  118.       }
  119.     }
  120.   }
  121.   retVal += "\n";
  122.   
  123.   if (myItemName != "")
  124.   {
  125.     retVal += "Subscription Name: " + myItemName + "\n";
  126.   }
  127.   
  128.   if (myItemID != "")
  129.   {
  130.     retVal += "Subscription ID: " + myItemID + "\n";  
  131.   }
  132.   
  133.   retVal += "Currency: " + getCurrencyType(myCurrency) + "\n";    
  134.     
  135.   if (myAmount != "")
  136.   {
  137.     retVal += "Charge Customers: " + myAmount + " every " + findObject("billingValue").options[findObject("billingValue").selectedIndex].value + " " + displayTimePeriod(findObject("billingPeriod").options[findObject("billingPeriod").selectedIndex].value) + "\n";
  138.   } 
  139.   
  140.   if (myBillRecurring)
  141.   {
  142.     retVal += "\tBill on a recurring basis.\n";
  143.   }
  144.   else
  145.   {
  146.     retVal += "\tStop billing after " + findObject("stopRecurringValue").options[findObject("stopRecurringValue").selectedIndex].value + " payments.\n";
  147.   }
  148.  
  149.   if (isValidAmount(myTrial1))
  150.   {
  151.     retVal += "Trial Period: " + myTrial1 + " - " + findObject("trial1Value").options[findObject("trial1Value").selectedIndex].value + " " + displayTimePeriod(findObject("trial1Period").options[findObject("trial1Period").selectedIndex].value) + "\n";
  152.   }  
  153.        
  154.   retVal += "Reattempt failed payments: ";
  155.   if (myReattemptPayment)
  156.     retVal += "Yes";
  157.   else
  158.     retVal += "No";
  159.   retVal += "\n";
  160.       
  161.   retVal += "Request Customer Shipping Address: ";    
  162.   if (!myIncludeShipping)
  163.     retVal += "No";
  164.   else
  165.     retVal += "Yes";  
  166.   retVal +="\n";
  167.        
  168.   if (isValidURL(myLogoURL))
  169.   {
  170.     retVal += "Custom Logo URL: " + myLogoURL + "\n";
  171.   }
  172.   
  173.   if (isValidURL(mySuccessURL))
  174.   {
  175.     retVal += "Successful Payment URL: " + mySuccessURL + "\n";
  176.   }
  177.   
  178.   if (isValidURL(myCancelURL))
  179.   {
  180.     retVal += "Cancelled Payment URL: " + myCancelURL + "\n";
  181.   }
  182.         
  183.   return retVal;
  184. }
  185.  
  186. function enableDisableOtherImage()     {
  187.   var myImage = findObject("subimage");
  188.   for (var n=0; n<myImage.length; n++)
  189.   {
  190.     if (myImage[n].checked)
  191.     {
  192.       if (myImage[n].value == "other")
  193.       {
  194.         findObject("othersubimage").disabled = "enabled";
  195.         findObject("ImageBrowse").disabled = "enabled";
  196.       }
  197.       else
  198.       {
  199.         findObject("othersubimage").disabled = "disabled";
  200.         findObject("ImageBrowse").disabled = "disabled";
  201.       }
  202.     }
  203.   }
  204. }
  205.  
  206. function enableDisableStopRecurring()   {
  207.   if (findObject("recurringBilling")[1].checked)
  208.   {
  209.     findObject("stopRecurringValue").disabled = "enabled";
  210.   }
  211.   else
  212.   {
  213.     findObject("stopRecurringValue").disabled = "disabled";    
  214.   }
  215. }
  216.  
  217.  
  218. function openBrowseImageWindow()      {
  219.   var browseURL = "";
  220.   var LABEL_Select = "Select Single Item Purchase Image...";  // label for file window
  221.   browseURL = dreamweaver.browseForFileURL("select",LABEL_Select, false, true); // opens file window and returns file string as URL
  222.   if (browseURL)
  223.   {
  224.     //browseURL = WA_absoluteToRelativeURL(browseURL, docpath, false);          
  225.     findObject("othersubimage").value = browseURL;  //set the DataSource    
  226.   }
  227.   findObject("othersubimage").focus();
  228. }
  229.  
  230. function displayTimePeriod(thePeriod)
  231. {
  232.   var retVal = "";
  233.   switch (thePeriod.toLowerCase())
  234.   {
  235.     case "w":
  236.       retVal = "Week(s)";
  237.       break;
  238.  
  239.     case "m":
  240.       retVal = "Months(s)";
  241.       break;
  242.  
  243.     case "y":
  244.       retVal = "Years(s)";
  245.       break;
  246.                   
  247.     default:
  248.       retVal = "Day(s)";
  249.       break;
  250.   }
  251.   
  252.   return retVal;
  253. }
  254.  
  255. /****************************** page functions ****************************/
  256. function Pg0_load()
  257. {
  258.   document.UserIDWP.visibility = "visible";
  259.   findObject("btnBack").setAttribute("disabled", "disabled"); // disable the back button
  260.   findObject("next").visibility = "visible";                  // enable next button
  261.   findObject("finish").visibility = "hidden";                 // hide finish button
  262.  
  263.   // Set focus but this only seems to work if you delay the page loading by some amount of time (in msec)
  264.   setTimeout('findObject("ppUID").focus()',500);
  265.   return true;
  266. }
  267.  
  268. function Pg0_unLoad()
  269. {
  270.   document.UserIDWP.visibility = "hidden";
  271.   return true;
  272. }
  273.  
  274. function Pg1_canLoad()      {
  275.   var ppError = validatePPUID();
  276.   if (ppError != "")
  277.   {
  278.     alert ("Account " + ppError);
  279.     return false;
  280.   }
  281.   return true;
  282. }
  283.  
  284. function Pg1_load()
  285. {
  286.   document.ButtonImageWP.visibility = "visible";
  287.   findObject("btnBack").setAttribute("disabled", "enabled"); // disable the back button
  288.   findObject("next").visibility = "visible";                  // enable next button
  289.   findObject("finish").visibility = "hidden";                 // hide finish button
  290.     // Set focus but this only seems to work if you delay the page loading by some amount of time (in msec)
  291.   setTimeout('findObject("subimage")[0].focus()',500);
  292.   return true;
  293. }
  294.  
  295. function Pg1_unLoad()
  296. {
  297.   document.ButtonImageWP.visibility = "hidden";
  298.   return true;
  299. }
  300.  
  301. function Pg2_canLoad() 
  302. {
  303.   return true;
  304. }
  305.  
  306. function Pg2_load()
  307. {
  308.   document.itemWP.visibility = "visible";
  309.   findObject("btnBack").setAttribute("disabled", "enabled"); // disable the back button
  310.   findObject("next").visibility = "visible";                  // enable next button
  311.   findObject("finish").visibility = "hidden";                 // hide finish button
  312.  
  313.   // Set focus but this only seems to work if you delay the page loading by some amount of time (in msec)
  314.   setTimeout('findObject("subscriptionName").focus()',500);
  315.   return true;
  316. }
  317.  
  318. function Pg2_unLoad()
  319. {
  320.   document.itemWP.visibility = "hidden";
  321.   return true;
  322. }
  323.  
  324. function Pg3_canLoad() 
  325. {
  326.   var subsDetailError = validateSubsDetails();
  327.   if (subsDetailError != "")
  328.   {
  329.     alert (subsDetailError);
  330.     return false;
  331.   }
  332.   return true;
  333. }
  334.  
  335. function Pg3_load()
  336. {
  337.   document.shippingWP.visibility = "visible";
  338.   findObject("btnBack").setAttribute("disabled", "enabled"); // disable the back button
  339.   findObject("next").visibility = "visible";                  // enable next button
  340.   findObject("finish").visibility = "hidden";                 // hide finish button
  341.   // Set focus but this only seems to work if you delay the page loading by some amount of time (in msec)
  342.   setTimeout('findObject("reattemptBilling")[0].focus()',500);
  343.   return true;
  344. }
  345.  
  346. function Pg3_unLoad()
  347. {
  348.   document.shippingWP.visibility = "hidden";
  349.   return true;
  350. }
  351.  
  352. function Pg4_canLoad() 
  353. {
  354.   return true;
  355. }
  356.  
  357. function Pg4_load()
  358. {
  359.   document.logoWP.visibility = "visible";
  360.   findObject("btnBack").setAttribute("disabled", "enabled"); // disable the back button
  361.   findObject("next").visibility = "visible";                  // enable next button
  362.   findObject("finish").visibility = "hidden";                 // hide finish button
  363.  
  364.   // Set focus but this only seems to work if you delay the page loading by some amount of time (in msec)
  365.   setTimeout('findObject("ppLogo").focus()',500);
  366.   return true;
  367. }
  368.  
  369. function Pg4_unLoad()
  370. {
  371.   document.logoWP.visibility = "hidden";
  372.   return true;
  373. }
  374.  
  375. function Pg5_canLoad() 
  376. {
  377.   return true;
  378. }
  379.  
  380. function Pg5_load()
  381. {
  382.   document.customWP.visibility = "visible";
  383.   findObject("btnBack").setAttribute("disabled", "enabled"); // disable the back button
  384.   findObject("next").visibility = "visible";                  // enable next button
  385.   findObject("finish").visibility = "hidden";                 // hide finish button
  386.  
  387.   // Set focus but this only seems to work if you delay the page loading by some amount of time (in msec)
  388.   setTimeout('findObject("successURL").focus()',500);
  389.   return true;
  390. }
  391.  
  392. function Pg5_unLoad()
  393. {
  394.   document.customWP.visibility = "hidden";
  395.   return true;
  396. }
  397.  
  398. function Pg6_canLoad() 
  399. {
  400.   return true;
  401. }
  402.  
  403. function Pg6_load()
  404. {
  405.   document.SummaryWP.visibility = "visible";
  406.   findObject("btnBack").setAttribute("disabled", "enabled"); // disable the back button
  407.   findObject("next").visibility = "hidden";                  // enable next button
  408.   findObject("finish").visibility = "visible";                 // hide finish button
  409.  
  410.   findObject("summaryText").value = buildSummaryText();
  411.   return true;
  412. }
  413.  
  414. function Pg6_unLoad()
  415. {
  416.   document.SummaryWP.visibility = "hidden";
  417.   return true;
  418. }
  419.  
  420. function showNextPage()   {
  421.   var nextPage = CURRENTPAGE + 1;
  422.   if (eval("Pg"+nextPage+"_canLoad()"))
  423.   {
  424.     eval("Pg"+CURRENTPAGE+"_unLoad()");
  425.     CURRENTPAGE++;
  426.     eval("Pg"+CURRENTPAGE+"_load()");  
  427.   }
  428. }
  429.  
  430. function showPreviousPage()   {
  431.   eval("Pg"+CURRENTPAGE+"_unLoad()");
  432.   CURRENTPAGE--;
  433.   eval("Pg"+CURRENTPAGE+"_load()");
  434. }
  435.  
  436. function showPageNum(pageNum)  {
  437.   eval("Pg"+CURRENTPAGE+"_unLoad()");
  438.   CURRENTPAGE = pageNum;
  439.   eval("Pg"+CURRENTPAGE+"_load()");
  440. }