home *** CD-ROM | disk | FTP | other *** search
/ Your Business Pak / BusinessPak2.iso / Netscape / CD / as.z / asw.jar / util.js < prev   
Text File  |  1998-10-15  |  8KB  |  322 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. <!--  to hide script contents from old browsers
  19.  
  20. function cancelEvent( e )
  21. {
  22.     var retVal = false;
  23.  
  24.     if ( ( e.which < 2 ) && ( e.type != "dragdrop" ) && ( e.type != "dblclick" ) )
  25.         retVal = routeEvent( e );
  26.  
  27.     return retVal;
  28. }
  29.  
  30. function debug( theString )
  31. {
  32.     java.lang.System.out.println( theString );
  33. }
  34.  
  35. function GetNameValuePair( file, section, variable )
  36. {
  37.     netscape.security.PrivilegeManager.enablePrivilege( "AccountSetup" );
  38.  
  39.     var value = parent.globals.document.setupPlugin.GetNameValuePair( file, section, variable );
  40.     if ( value == null )
  41.         value = "";
  42.     return value;
  43. }
  44.  
  45. function SetNameValuePair( file, section, variable, data )
  46. {
  47.     netscape.security.PrivilegeManager.enablePrivilege( "AccountSetup" );
  48.  
  49.     parent.globals.document.setupPlugin.SetNameValuePair( file, section, variable, data );
  50.     //debug( "\tSetNameValuePair: [" + section + "] " + variable + "=" + data );
  51. }
  52.  
  53.  
  54. function getPlatform()
  55. {
  56.     var platform = new String( navigator.userAgent );
  57.     var x = platform.indexOf( "(" ) + 1;
  58.     var y = platform.indexOf( ";", x + 1 );
  59.     platform = platform.substring( x, y );
  60.     return platform;
  61. }
  62.  
  63. // * returns a canoncial path to the folder containing the document representing the current contents of "window"
  64. function getFolder( window )
  65. {
  66.     platform = getPlatform();
  67.     var path = unescape( window.location.pathname );
  68.  
  69.     if ( platform == "Macintosh" )
  70.     {                // Macintosh support
  71.         if ( ( x = path.lastIndexOf( "/" ) ) > 0 )
  72.             path = path.substring( 0, x + 1 );
  73.  
  74.         //var fileArray = path.split( "/" );
  75.         //var newpath = fileArray.join( ":" ) + ":";
  76.  
  77.         //if ( newpath.charAt( 0 ) == ':' )
  78.         //    newpath = newpath.substring( 1, newpath.length );
  79.  
  80.         newpath = path;
  81.     }
  82.     else    
  83.     {                                        // Windows support
  84.  
  85.         // note: JavaScript returns path with '/' instead of '\'
  86.         var drive = "|";
  87.  
  88.         // gets the drive letter and directory path
  89.         if ( ( x = path.lastIndexOf( "|" ) ) > 0 )
  90.         {
  91.             slash = path.indexOf( '/' );
  92.             bar = path.indexOf( '|' );
  93.         
  94.             if ( slash < bar )
  95.                 drive = path.substring( slash + 1, bar );
  96.             else
  97.                 drive = path.substring( bar - 1, bar );
  98.             
  99.             path = path.substring( bar + 1, path.lastIndexOf( '/' ) + 1 );
  100.         }
  101.  
  102.         var pathArray = path.split( "/" );
  103.         path = pathArray.join( "\\" );
  104.         if ( path.charAt( path.length - 1 ) != '\\' )
  105.             path = path + "\\";
  106.  
  107.         //debug( "drive: " + drive + " path: " + path );
  108.  
  109.         // construct newpath        
  110.         newpath = drive + ":" + path;
  111.         debug( "path: " + newpath );
  112.     }
  113.     return newpath;
  114. }
  115.  
  116. // * returns a string representing the path to the folder named "Config" inside the folder "Data" that
  117. //    is installed in the Communicator's home directory
  118. function getConfigFolder( object )
  119. {
  120.     var    pathName;
  121.     pathName = getFolder( object ) + "Config" + "\\";
  122.  
  123.     //debug( "getConfigFolder: " + pathName );
  124.  
  125.     return pathName;
  126. }
  127.  
  128. // * returns a string representing the path to the file "ACCTSET.INI" inside the folder
  129. //    returned from getConfigFolder
  130. function getAcctSetupFilename( object )
  131. {
  132.     var file;
  133.     file = getConfigFolder( object ) + "ACCTSET.INI";
  134.  
  135.     //debug( "getAcctSetupFilename: " + file );
  136.     return file;
  137. }
  138.  
  139. function getBrowserVersionNumber()
  140. {
  141.     var agent = navigator.userAgent;
  142.     var x = agent.indexOf( "/" );
  143.     var version = "unknown";
  144.     if ( x >= 0 )
  145.         version = agent.substring( x + 1, agent.length );
  146.     return version;
  147. }
  148.  
  149. function getBrowserMajorVersionNumber()
  150. {
  151.     var    version = getBrowserVersionNumber();
  152.     if ( version != "unknown" )
  153.     {
  154.         var x = version.indexOf( "." );
  155.         if ( x > 0 )
  156.             version = version.substring( 0, x );    
  157.     }
  158.     return version;
  159. }
  160.  
  161. function setFocus( theObject )
  162. {
  163.     theObject.focus();
  164.     theObject.select();
  165. }
  166.  
  167. function setMessage( txt )
  168. {
  169.     window.status = txt;
  170.     setTimeout( "clearMessage()", 10000 );
  171. }
  172.  
  173. function clearMessage()
  174. {
  175.     window.status = "";
  176. }
  177.  
  178. function checkPluginExists( name, generateOutputFlag )
  179. {
  180.     /*
  181.     var myPlugin = navigator.plugins["name"];
  182.     if (myPlugin)    {
  183.         // do something here
  184.         }
  185.     else    {
  186.         document.writeln("<CENTER><STRONG>Warning! The '" +name+ "' plug-in is not installed!</STRONG></CENTER>\n");
  187.         }
  188.     */
  189.     
  190.     if ( navigator.javaEnabled() )
  191.     {
  192.         var myMimetype = navigator.mimeTypes[ name ]
  193.         if ( myMimetype )
  194.             return true;
  195.         else
  196.         {
  197.             if ( generateOutputFlag == true )
  198.             {
  199.                 document.writeln( "<CENTER><STRONG>The 'Account Setup Plugin' is not installed!<P>\n" );
  200.                 document.writeln( "Please install the plugin, then run 'Account Setup' again.</STRONG></CENTER>\n" );
  201.             }
  202.             return false;
  203.         }
  204.     }
  205.     else
  206.     {
  207.         if ( generateOutputFlag==true )
  208.         {
  209.             document.writeln( "<CENTER><STRONG>Java support is disabled!<P>\n" );
  210.             document.writeln( "Choose Options | Network Preferences and enable Java, then try again.</STRONG></CENTER>\n" );
  211.         }
  212.          return false;
  213.     }
  214. }
  215.  
  216. function verifyIPaddress( address )
  217. {
  218.     var dotCount = 0, dotIndex = 0, net, validFlag = false;
  219.  
  220.     while ( dotIndex >= 0 )
  221.     {
  222.         net = "";
  223.         dotIndex = address.indexOf( "." );
  224.         if ( dotIndex >=0 )
  225.         {
  226.             net = address.substring( 0, dotIndex );
  227.             address = address.substring( dotIndex + 1 );
  228.             ++dotCount;
  229.         }
  230.         else
  231.         {
  232.             net = address;
  233.             if ( net=="" )
  234.                 break;
  235.         }
  236.  
  237.         netValue = parseInt( net );
  238.         if ( isNaN( netValue ) )
  239.             break;
  240.         if ( netValue < 0 || netValue > 255 )
  241.             break;
  242.  
  243.         if ( dotCount == 3 && dotIndex < 0 )
  244.             validFlag = true;
  245.     }    
  246.     return validFlag;
  247. }
  248.  
  249. function verifyZipCode( zipCode )
  250. {
  251.     var    validFlag = false;
  252.  
  253.     if ( zipCode.length >= 5 )
  254.     {
  255.         validFlag = true;
  256.         for ( var x = 0; x < zipCode.length; x++ )
  257.         {
  258.             if ( "0123456789-".indexOf( zipCode.charAt( x ) ) < 0 )
  259.             {
  260.                 validFlag = false;
  261.                 break;
  262.             }
  263.         }
  264.     }
  265.     return validFlag;
  266. }
  267.  
  268. function verifyPhoneNumber( phoneNum, minLength )
  269. {
  270.     var    validFlag = false;
  271.  
  272.     if ( phoneNum.length >= minLength )
  273.     {
  274.         validFlag = true;
  275.         for ( var x = 0; x < phoneNum.length; x++ )
  276.         {
  277.             if ( "0123456789().,-+ ".indexOf( phoneNum.charAt( x ) ) < 0 )
  278.             {
  279.                 validFlag = false;
  280.                 break;
  281.             }
  282.         }
  283.     }
  284.     return validFlag;
  285. }
  286.  
  287. function verifyAreaCode( areaCode )
  288. {
  289.     var    validFlag = false;
  290.  
  291.     if ( areaCode.length >= 3 )
  292.     {
  293.         validFlag = true;
  294.         for ( var x = 0; x < areaCode.length; x++ )
  295.         {
  296.             if ( "0123456789".indexOf( areaCode.charAt( x ) ) < 0 )
  297.             {
  298.                 validFlag = false;
  299.                 break;
  300.             }
  301.         }
  302.     }
  303.     return validFlag;
  304. }
  305.  
  306. function getAreaCode( tapiPhoneNumber )
  307. {
  308.     var x = tapiPhoneNumber.indexOf( "(" );
  309.     var y = tapiPhoneNumber.indexOf( ")" );
  310.     var    temp = "";
  311.     if ( x >= 0 && y >= 0 )
  312.     {
  313.         temp = tapiPhoneNumber.substring( x + 1, y );
  314.         if ( verifyAreaCode( temp ) == false )
  315.             temp = "";
  316.     }
  317.     return temp;
  318. }
  319.  
  320. // end hiding contents from old browsers  -->
  321.  
  322.