home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD 64 / supercd64_1.iso / FP.JS < prev    next >
Text File  |  2001-09-07  |  10KB  |  229 lines

  1. /* fp.js
  2.  * Scripts common to Future Publishing installer pages
  3.  * Matt Kynaston (kynaston@yahoo.com), December 2000
  4.  * functions starting with MM_ are from Macromedia Dreamweaver
  5. */
  6.  
  7. /* fp_swapAnchors()
  8.  * if browser is IE4+ goes through document finding anchors pointing to executables
  9.  * and substitutes calls to launch() so IntraLaunch works
  10. */
  11. function fp_swapAnchors() { //v1.0
  12.     if (document.ie4plus) {
  13.         if (document.IntraLaunch) {
  14.             var lnks = document.links;
  15.             for(var i=0;i<lnks.length;i++) { 
  16.                 var href = lnks[i].href;
  17.                 if(href.toLowerCase().indexOf(".exe") == href.length-4) {
  18.                     lnks[i].href = "javascript:launch('"+fp_pathFromRoot(href)+"')";
  19.         }    }    }
  20.         else alert("Alert! The IntraLaunch object is missing from this page. Installing software by clicking links will not work.");
  21. }    }
  22.  
  23. /* fp_pathFromRoot(fileName)
  24.  * returns path from root of CD
  25. */
  26. function fp_pathFromRoot(fn) { //v1.0
  27.     return fn.substring(fn.lastIndexOf("//")+5,fn.length);
  28. }
  29.  
  30. /* launch(fileName)
  31.  * calls VBScript to run file (if IE4+)
  32. */
  33. function launch(fn) { //v1.0
  34.     if (document.ie4plus) {
  35.         fp_LaunchFile(fp_getILPath(fn)); // call to VBScript - make sure it's on doc!
  36. }    }
  37.  
  38. /* fp_getILPath(fileName)
  39.  * return IntraLaunch-style backslashed file path
  40. */
  41. function fp_getILPath(fn) { //v1.0
  42.     return "*:\\" + fp_forwardToBackSlash(fn);              
  43. }
  44.  
  45. /* fp_forwardToBackSlash(fileName)
  46.  * returns string with forward slashes converted to backslashes
  47. */
  48. function fp_forwardToBackSlash(fn) { //v1.0
  49.     return fn.split("/").join("\\");
  50. }
  51.  
  52. /* fp_swapArrow(origImage, newImage)
  53.  * Searches for origImage in the index that is linked to the current documnet
  54.  * and changes it to newImage. Used to highlight the current document
  55.  * in the index. newImage path must be relative to origImage (? - keep 'em in same dir).
  56. */
  57. function fp_swapArrow(origImage, newImage) { //v1.0
  58.     var doesDOM = document.getElementsByTagName;
  59.     if (document.ie4plus || doesDOM) {
  60.         var ancs = (doesDOM) ? document.getElementsByTagName("a") : document.all.tags("a");
  61.         var found = false;
  62.         for(var i=0;i<ancs.length && !found;i++) {
  63.             if (document.location.toString().indexOf(ancs[i].href) == 0) {
  64.                 var imgs = (doesDOM) ? ancs[i].getElementsByTagName("img") : ancs[i].all.tags("img");
  65.                 for(var j=0;j<imgs.length && !found;j++) {
  66.                     var imgsrc = imgs[j].src;
  67.                     if (imgsrc.indexOf(origImage) != -1) {
  68.                         imgs[j].src = imgsrc.substring(0,imgsrc.lastIndexOf("/")+1)+newImage;
  69.                         found = true; break;
  70. }    }    }    }    }    }
  71.  
  72. /* fp_checkBrowser()
  73.  * Determine browser and OS
  74.  * should be in body's onload
  75. */
  76. function fp_checkBrowser() { //v1.0
  77.     var bname = navigator.appName.toLowerCase();
  78.     var bVersion = navigator.appVersion.toLowerCase();
  79.     var bVer = parseInt(bVersion);
  80.     var userAgent = navigator.userAgent.toLowerCase();
  81.     
  82.     (bname == "netscape" && bVer >=4) ? document.ns4plus=true : document.ns4plus=false;
  83.     (bname == "microsoft internet explorer" && bVer >= 4) ? document.ie4plus = true : document.ie4plus = false;
  84.     (bVersion.indexOf("msie 5") != -1) ? document.ie5plus = true : document.ie5plus = false;
  85.     (bname.indexOf("netscape") != -1 && bVer >= 6) ? document.ns6plus = true : document.ns6plus = false;
  86.     
  87.     // Opera spoofs IE4 in appName!!
  88.     if (userAgent.indexOf("opera 5") != -1){
  89.         document.op5plus = true;
  90.         document.ie4plus = false;
  91.         document.ns4plus = false;
  92.     }
  93.     else document.op5plus = false;
  94.     
  95.     // Konqueror??
  96.     
  97.     // determine operating system of viewer
  98.     (userAgent.indexOf("linux") != -1) ? document.linux = true : document.linux = false;
  99.     (userAgent.indexOf("Win16") != -1) ? document.win16 = true : document.win16 = false;
  100. }
  101.  
  102. /* fp_runWarning()
  103.  * alerts browsers not capable of installing software to the fact
  104.  * and prevents them proceding
  105. */
  106. function fp_runWarning(){ //v1.0
  107.     var d = document, retVal = false
  108.     if (d.ie4plus) retVal = true;
  109.     else if (d.op5plus) {
  110.         retVal = confirm("Alert! To run files directly from Opera you must choose 'Run file'\nin the next dialog box. If you choose 'Save to disk' the installation\nwill not work.\n\nContinue?");    
  111.     }
  112.     else if (d.ns4plus && fp_getCookie('PCPLUS_CDN') != null) {
  113.         retVal = confirm("Alert! To run files directly from Netscape you must have\nthe Netscape Open/Save dialog enabled. If it is,\nyou will get a 'Security Hazard' dialog box next. Choose 'Open'\nto run the file.\n\nIf you just get a 'Save to disk' dialog, you will not be able to use Netscape\nto install this software.\n\nSee the Netscape page under 'Help' for more information.\n\nDo you wish to continue?");    
  114.     }
  115.     else {
  116.         alert('Alert! This will not work.\n\nYour browser does not allow the execution of files\ndirectly from the SuperDisc. If you do not understand\nthis, click OK, go to the Help section on the SuperDisc\nand read the instructions.');
  117.         retVal = false;
  118.     }
  119.     document.MM_returnValue = retVal;
  120. }
  121.  
  122. /* fp_emailWarning()
  123.  * Warns users that they must have an email client configured to access the mailto link,
  124.  * unless they've set the PCPLUS_CD3 cookie (on the help.htm page). Now why doesn't cancelling 
  125.  * work in NS? Have tried everything, I think...
  126. */
  127. function fp_emailWarning() { //v1.0
  128.     var d = document;
  129.     var retVal = true;
  130.     if (fp_getCookie('PCPLUS_CD3') == null) {
  131.          if (d.ie4plus || d.ns4plus || d.op5plus) {
  132.             retVal = confirm('Accessing this link will require you to have an\ne-mail client set up and integrated correctly.\n\nIf it is you will be taken to a New Message window\nwhere you can type in your message and then send it.\n\nIf you are not connected to a network, this means\nyou need a modem and Internet account setup and\nswitched on.\n\nDo you wish to continue?');
  133.         }
  134.         else {
  135.             alert('Accessing this link will require you to have an\ne-mail client set up and integrated correctly.\n\nIf it is you will be taken to a New Message window\nwhere you can type in your message and then send it.\n\nIf you are not connected to a network, this means\nyou need a modem and Internet account setup and\nswitched on.');
  136.         }
  137.     }
  138.     document.MM_returnValue = retVal;
  139. }
  140.  
  141. /* fp_webWarning()
  142.  * Alerts users they are accessing a remote link that requires an Internet connection.
  143.  * Disabled with the PCPLUS_CD1 cookie, set on the help.htm page
  144. */
  145. function fp_webWarning() { //v1.0
  146.     var d = document, retVal = true;
  147.     if (fp_getCookie('PCPLUS_CD1') == null) {
  148.         if (d.ie4plus || d.ns4plus || d.op5plus) {
  149.             retVal = confirm('Accessing this link will require you to go on-line.\n\nIf you are not connected to a network, this means\nyou need a modem and Internet account setup\nand switched on. Do you wish to continue?');
  150.         }
  151.         else {
  152.             alert('Accessing this link will require you to go on-line.\n\nIf you are not connected to a network, this means\nyou need a modem and Internet account setup\nand switched on.');
  153.         }
  154.     }
  155.     document.MM_returnValue = retVal;
  156. }
  157.  
  158. /* fp_linkWarning()
  159.  * Alerts users they are entering pages authored by a 3rd party, which may contain links
  160.  * to the Internet that will require an Internet connection. Disabled by the PCPLUS_CD5
  161.  * cookie
  162. */
  163. function fp_linkWarning() { //v1.0
  164.     if (fp_getCookie('PCPLUS_CD5') == null) {
  165.         alert('This link takes you to pages authored by a third party.\n\nThey may contain links that lead onto the internet.\nIf you are not connected to a network, you will\nneed a modem and Internet account setup\nand switched on in order to follow them.');
  166.     }
  167. }
  168.  
  169. /* functions to get, set, delete and toggle cookies
  170.  * original stuff written by Dave Taylor - now that's going back a way!
  171.  * Cookies PCPLUS_CD2 & PCPLUS_CD4 were used to supress warnings no longer used
  172.  *     - don't be tempted to use them in case they're still lurking around
  173. */
  174. function fp_setCookie(name, value) { //v1.0
  175.     var exp = new Date();                                          // make new date object
  176.     exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 1000));     // set it 1000 days ahead
  177.     document.cookie = name + "=" + escape(value) + "; path=/; expires=" + exp.toGMTString();
  178. }
  179.  
  180. function fp_getCookie(name) { //v1.0
  181.     var cname = name + "=";               
  182.     var dc = document.cookie;             
  183.         if (dc.length > 0) {              
  184.         begin = dc.indexOf(cname);       
  185.             if (begin != -1) {           
  186.             begin += cname.length;       
  187.             end = dc.indexOf(";", begin);
  188.                 if (end == -1) end = dc.length;
  189.                 return unescape(dc.substring(begin, end));
  190.             }
  191.         }
  192.     return null;
  193. }
  194.  
  195. function fp_delCookie(name) { //v1.0
  196.     document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
  197. }
  198.  
  199. function fp_toggle_cookie(num,value) { //v1.0
  200.     if (fp_getCookie('PCPLUS_CD'+num)) fp_delCookie('PCPLUS_CD'+num);
  201.     else fp_setCookie('PCPLUS_CD'+num,value);
  202. }
  203.  
  204.  
  205. /* Macromedia image swapping functions
  206.  * (glad I didn't have to write these 'cause they're dead ugly :)
  207. */
  208. function MM_swapImgRestore() { //v3.0
  209.   var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  210. }
  211.  
  212. function MM_preloadImages() { //v3.0
  213.   var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  214.     var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  215.     if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  216. }
  217.  
  218. function MM_findObj(n, d) { //v4.0
  219.   var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  220.     d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  221.   if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  222.   for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  223.   if(!x && document.getElementById) x=document.getElementById(n); return x;
  224. }
  225.  
  226. function MM_swapImage() { //v3.0
  227.   var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  228.    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
  229. }