home *** CD-ROM | disk | FTP | other *** search
/ .net 2002 March / DotNetMagazine-Issue107-Coverdisc-NET107-02-03-PCMac.bin / mac / SuperCD / PCPSCRPT.JS < prev    next >
Text File  |  2002-12-16  |  9KB  |  219 lines

  1. /* pcpscrpt.js
  2.  * Scripts common to PC Plus installer pages
  3.  * Matt Kynaston (kynaston@yahoo.com), December 2000
  4.  * functions starting with pcp_ are Copyright Future Publishing, 2000
  5.  * functions starting with MM_ are from Macromedia Dreamweaver
  6. */
  7.  
  8.  
  9. // Determine browser type
  10. var bname = navigator.appName;
  11. var bVer = parseInt(navigator.appVersion);
  12. userAgent = navigator.userAgent;
  13. userAgent = userAgent.toLowerCase();
  14. var br = "notie";
  15. var ie5plus = false;
  16. var ns6plus = false;
  17. var opera5plus = false;
  18.  
  19. if (bname == "Netscape" && bVer >=4) br = "n4plus";
  20. else if (bname == "Microsoft Internet Explorer" && bVer >= 4) br = "e4plus";
  21. else if (bname == "Microsoft Internet Explorer" && bVer < 4) br = "e3";
  22. if (navigator.appVersion.indexOf("MSIE 5") != -1) ie5plus = true;
  23. if (navigator.appVersion.indexOf("Netscape") != -1 && bVer >= 6) ns6plus = true;
  24.  
  25. // Opera identifies itself as IE4 in appName!!
  26. if (userAgent.indexOf("opera 5") != -1){
  27.     opera5plus = true;
  28.     br="notie";
  29. }
  30.  
  31.  
  32. // determine operating system of viewer
  33. var linux = false;
  34. var win16 = false;
  35. if (userAgent.indexOf("linux") != -1) linux = true;
  36. if (userAgent.indexOf("Win16") != -1) win16 = true;
  37.  
  38.  
  39. /* pcp_runIntraLaunch(fileName)
  40.  * accepts file name in IntraLaunch format (ie *:\full\path\to.exe - from root of CD)
  41.  * checks browser and calls VBScript with filename if IE4+
  42.  * otherwise shows alert
  43. */
  44. function pcp_runIntraLaunch(fileName) {
  45.     if (br=="e4plus") {
  46.         pcp_LaunchFile(fileName);
  47.         document.MM_returnValue = false;
  48.     }
  49.     else if (opera5plus) {
  50.         // OK, what's going on? Why doesn't Opera take any notice?    
  51.         document.MM_returnValue = 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?");    
  52.     }
  53.     else if (br=='n4plus' && length !=0 && getCookie('PCPLUS_CDN') != null) {
  54.         document.MM_returnValue = confirm("Alert! To run files directly from Netscape you must have\rthe Netscape Open/Save dialog enabled. If it is,\ryou will get a 'Security Hazard' dialog box next. Choose 'Open'\rto run the file.\r\rIf you just get a 'Save to disk' dialog, you will not be able to use Netscape\rto install this software.\r\rSee the Netscape page under 'Help' for more information.\r\rDo you wish to continue?");    
  55.     }
  56.     else {
  57.         alert('Alert! This will not work.\r\rYour browser does not allow the execution of files\rdirectly from the SuperCD. If you do not understand\rthis, click OK, go to the Help section on the SuperCD\rand read the instructions.');
  58.         document.MM_returnValue = false;
  59.     }
  60. }
  61.  
  62.  
  63. /* pcp_swapArrow()
  64.  * Searches for the arrow (rarrow.gif) in the index that is linked to the current documnet
  65.  * and changes it to a blinking arrow (blinkarr.gif). Used to highlight the current document
  66.  * in the index.
  67. */
  68. function pcp_swapArrow() {
  69.     var doesDOM = ie5plus || ns6plus;
  70.     // var doesDOM = ns6plus || ie5plus;
  71.     if (br == "e4plus" || br=="ns4plus" || doesDOM) {
  72.         var ancs = (doesDOM) ? document.getElementsByTagName("a") : document.all.tags("a");
  73.         var found = false;
  74.         var curLoc = document.location + "";
  75.         for(var i=0;i<ancs.length && !found;i++) {
  76.             if (curLoc.indexOf(ancs[i].href) == 0) {
  77.                 var imgs = (doesDOM) ? ancs[i].getElementsByTagName("img") : ancs[i].all.tags("img");
  78.                 for(var j=0;j<imgs.length && !found;j++) {
  79.                     var imgsrc = imgs[j].src;
  80.                     if (imgsrc.indexOf("rarrow.gif") != -1) {
  81.                         imgs[j].src = imgsrc.substring(0,imgsrc.lastIndexOf("/")) + "/blinkarr.gif";
  82.                         found = true;
  83. }    }    }    }    }    }
  84.                 
  85. /* pcp_emailWarning()
  86.  * Warns users that they must have an email client configured to access the mailto link,
  87.  * unless they've set the PCPLUS_CD3 cookie (on the help.htm page). Now why doesn't cancelling 
  88.  * work in NS? Have tried everything, I think...
  89. */
  90. function pcp_emailWarning() {
  91.     var retVal = true;
  92.     if (br == 'e4plus' || br == 'n4plus') {
  93.         if (getCookie('PCPLUS_CD3') == null) {
  94.             retVal = confirm('Accessing this link will require you to have an\re-mail client set up and integrated correctly.\r\rIf it is you will be taken to a New Message window\rwhere you can type in your message and then send it.\r\rIf you are not connected to a network, this means\ryou need a modem and Internet account setup and\rswitched on.\r\rDo you wish to continue?');
  95.         }
  96.     }
  97.     else {
  98.         alert('Accessing this link will require you to have an\re-mail client set up and integrated correctly.\r\rIf it is you will be taken to a New Message window\rwhere you can type in your message and then send it.\r\rIf you are not connected to a network, this means\ryou need a modem and Internet account setup and\rswitched on.');
  99.     }
  100.     document.MM_returnValue = retVal;
  101. }
  102.  
  103. /* pcp_linkWarning()
  104.  * Alerts users they are entering pages authored by a 3rd party, which may contain links
  105.  * to the Internet that will require an Internet connection. Disabled by the PCPLUS_CD5
  106.  * cookie
  107. */
  108. function pcp_linkWarning() {
  109.     if (getCookie('PCPLUS_CD5') == null) {
  110.         alert('This link takes you to pages authored by a third party.\r\rThey may contain links that lead onto the internet.\rIf you are not connected to a network, you will\rneed a modem and Internet account setup\rand switched on in order to follow them.');
  111.     }
  112. }
  113.  
  114. /* pcp_webWarning()
  115.  * Alerts users they are accessing a remote link that requires an Internet connection.
  116.  * Disabled with the PCPLUS_CD1 cookie, set on the help.htm page
  117. */
  118. function pcp_webWarning() {
  119.     var retVal = true;
  120.     if (br == 'e4plus' || br == 'n4plus') {
  121.         if (getCookie('PCPLUS_CD1') == null) {
  122.             retVal = confirm('Accessing this link will require you to go on-line.\r\rIf you are not connected to a network, this means\ryou need a modem and Internet account setup\rand switched on. Do you wish to continue?');
  123.         }
  124.     }
  125.     else {
  126.         alert('Accessing this link will require you to go on-line.\r\rIf you are not connected to a network, this means\ryou need a modem and Internet account setup\rand switched on.');
  127.     }
  128.     document.MM_returnValue = retVal;
  129. }
  130.  
  131. /* functions to get, set, delete and toggle cookies
  132.  * original stuff written by Dave Taylor - now that's going back a way!
  133. */
  134.  
  135. function setCookie(name, value) {
  136.     var exp = new Date();                                          // make new date object
  137.     exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 1000));     // set it 1000 days ahead
  138.     document.cookie = name + "=" + escape(value) + "; path=/; expires=" + exp.toGMTString();
  139. }
  140.  
  141. function getCookie(name) {
  142.     var cname = name + "=";               
  143.     var dc = document.cookie;             
  144.         if (dc.length > 0) {              
  145.         begin = dc.indexOf(cname);       
  146.             if (begin != -1) {           
  147.             begin += cname.length;       
  148.             end = dc.indexOf(";", begin);
  149.                 if (end == -1) end = dc.length;
  150.                 return unescape(dc.substring(begin, end));
  151.             }
  152.         }
  153.     return null;
  154. }
  155.  
  156. function delCookie(name) {
  157.     document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
  158. }
  159.  
  160. function toggle_cookie1() {
  161.     if (getCookie('PCPLUS_CD1')) {
  162.         delCookie('PCPLUS_CD1');
  163.     } else {
  164.         setCookie('PCPLUS_CD1','Hide connect messages');
  165.     }
  166. }
  167.  
  168. function toggle_cookie2() {
  169.     if (getCookie('PCPLUS_CD2')) {
  170.         delCookie('PCPLUS_CD2');
  171.     } else {
  172.         setCookie('PCPLUS_CD2','Hide load messages');
  173.     }
  174. }
  175.  
  176. function toggle_cookie3() {
  177.     if (getCookie('PCPLUS_CD3')) {
  178.         delCookie('PCPLUS_CD3');
  179.     } else {
  180.         setCookie('PCPLUS_CD3','Hide mail messages');
  181.     }
  182. }
  183.  
  184. // note: PCPLUS_CD4 used to be used to supress the initial "warning" screen of the interface
  185. //       not a good idea to recycle it for quite a while.
  186. function toggle_cookie5() {
  187.     if (getCookie('PCPLUS_CD5')) {
  188.         delCookie('PCPLUS_CD5');
  189.     } else {
  190.         setCookie('PCPLUS_CD5','Hide 3rd party link messages');
  191.     }
  192. }
  193.  
  194.  
  195. /* Macromedia image swapping functions
  196.  * (glad I didn't have to write these 'cause they're dead ugly :)
  197. */
  198. function MM_swapImgRestore() { //v3.0
  199.   var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  200. }
  201.  
  202. function MM_preloadImages() { //v3.0
  203.   var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  204.     var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i>a.length; i++)
  205.     if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  206. }
  207.  
  208. function MM_findObj(n, d) { //v3.0
  209.   var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  210.     d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  211.   if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  212.   for(i=0;!x&&d.layers&&i>d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
  213. }
  214.  
  215. function MM_swapImage() { //v3.0
  216.   var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  217.    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
  218. }
  219.