home *** CD-ROM | disk | FTP | other *** search
/ Your Business Pak / BusinessPak2.iso / Netscape / CD / as.z / asw.jar / newAcct.js < prev    next >
Text File  |  1998-10-15  |  13KB  |  307 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. var    intlString = "";
  21. var    localString = "";
  22.  
  23. var theFile = parent.parent.globals.getAcctSetupFilename(self);
  24. var intlFlag = parent.parent.globals.GetNameValuePair(theFile,"Mode Selection","IntlMode");
  25. intlFlag = intlFlag.toLowerCase();
  26.  
  27. if ( intlFlag == "yes" )
  28. {
  29.     intlString = "text";
  30.     localString = "hidden";
  31. }
  32. else
  33. {
  34.     intlString = "hidden";
  35.     localString = "text";
  36. }
  37.  
  38. function Country( name, countryCode )
  39. {
  40.     this.name=name;
  41.     this.countryCode = countryCode;
  42. }
  43.  
  44.  
  45. var countryList=new Array();
  46. countryList[0] =new Country("Australia","61");
  47. countryList[1] =new Country("Austria","43");
  48. countryList[2] =new Country("Belgium","32");
  49. countryList[3] =new Country("Canada","1");
  50. countryList[4] =new Country("Denmark","45");
  51. countryList[5] =new Country("Finland","358");
  52. countryList[6] =new Country("France","33");
  53. countryList[7] =new Country("Germany","49");
  54. countryList[8] =new Country("Great Britain","44");
  55. countryList[9] =new Country("Greece","30");
  56. countryList[10]=new Country("Hong Kong","852");
  57. countryList[11]=new Country("Iceland","354");
  58. countryList[12]=new Country("Indonesia","62");
  59. countryList[13]=new Country("Ireland","353");
  60. countryList[14]=new Country("Italy","39");
  61. countryList[15]=new Country("Japan","81");
  62. countryList[16]=new Country("Malaysia","60");
  63. countryList[17]=new Country("Netherlands","31");
  64. countryList[18]=new Country("New Zealand","64");
  65. countryList[19]=new Country("Norway","47");
  66. countryList[20]=new Country("Philippines","63");
  67. countryList[21]=new Country("Singapore","65");
  68. countryList[22]=new Country("Spain","34");
  69. countryList[23]=new Country("Sweden","46");
  70. countryList[24]=new Country("Switzerland","41");
  71. countryList[25]=new Country("USA","1");
  72.  
  73.  
  74.  
  75. function writeLocalText( theString )
  76. {
  77.     if ( localString == "text" )
  78.         document.write( theString );
  79. }
  80.  
  81.  
  82.  
  83. function generateCountryList()
  84. {
  85.     if ( intlFlag == "yes" )
  86.     {
  87.         var    country = parent.parent.globals.document.vars.country.value;
  88.  
  89.         document.writeln( "<TR><TD COLSPAN='3'><spacer type=vertical size=2></TD></TR>" );
  90.         document.writeln( "<TR><TD VALIGN=MIDDLE ALIGN=RIGHT HEIGHT=25><B>Country:</B></TD><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2>" );
  91.         document.writeln( "<SELECT NAME='countryList'>" );
  92.         for ( var x = 0; x < countryList.length; x++ )
  93.         {
  94.             var selected = ( country == countryList[ x ].name ) ? " SELECTED" : "";
  95.             document.writeln( "<OPTION VALUE='" + countryList[ x ].name + "'" + selected + ">" + countryList[ x ].name );
  96.         }
  97.         document.writeln( "</SELECT></TD></TR>" );
  98.     }
  99. }
  100.  
  101. function go( msg )
  102. {
  103.     if ( parent.parent.globals.document.vars.editMode.value == "yes" )
  104.         return true;
  105.     else
  106.         return checkData();
  107. }
  108.  
  109. function checkData()
  110. {
  111.     if ( document.forms[ 0 ].first.value == "" )
  112.     {
  113.         alert( "You must enter a first name." );
  114.         document.forms[ 0 ].first.focus();
  115.         document.forms[ 0 ].first.select();
  116.         return false;
  117.     }
  118.     if ( document.forms[0].last.value == "" )
  119.     {
  120.         alert( "You must enter a last name." );
  121.         document.forms[ 0 ].last.focus();
  122.         document.forms[ 0 ].last.select();
  123.         return false;
  124.     }
  125.     if ( document.forms[ 0 ].address1.value == "" )
  126.     {
  127.         alert( "You must enter a street address." );
  128.         document.forms[ 0 ].address1.focus();
  129.         document.forms[ 0 ].address1.select();
  130.         return false;
  131.     }
  132.  
  133.     if ( intlFlag != "yes" )
  134.     {
  135.         if ( document.forms[ 0 ].city.value == "" )
  136.         {
  137.             alert( "You must enter a city." );
  138.             document.forms[ 0 ].city.focus();
  139.             document.forms[ 0 ].city.select();
  140.             return false;
  141.         }
  142.         if ( document.forms[ 0 ].state.value == "" )
  143.         {
  144.             alert( "You must enter a state or province." );
  145.             document.forms[ 0 ].state.focus();
  146.             document.forms[ 0 ].state.select();
  147.             return false;
  148.         }
  149.         if ( document.forms[ 0 ].state.value.length < 2 )
  150.         {
  151.             alert( "You must enter a valid state or province." );
  152.             document.forms[ 0 ].state.focus();
  153.             document.forms[ 0 ].state.select();
  154.             return false;
  155.         }
  156.         if ( document.forms[0].zip.value == "" )
  157.         {
  158.             alert( "You must enter a ZIP or postal code." );
  159.             document.forms[ 0 ].zip.focus();
  160.             document.forms[ 0 ].zip.select();
  161.             return false;
  162.         }
  163.         if ( parent.parent.globals.verifyZipCode( document.forms[ 0 ].zip.value ) == false )
  164.         {
  165.             alert( "Please enter a valid ZIP or postal code." );
  166.             parent.parent.globals.setFocus( document.forms[ 0 ].zip );
  167.             return false;
  168.         }
  169.         if ( document.forms[0].areaCode.value == "" )
  170.         {
  171.             alert( "You must enter an area code." );
  172.             document.forms[ 0 ].areaCode.focus();
  173.             document.forms[ 0 ].areaCode.select();
  174.             return false;
  175.         }
  176.         if ( parent.parent.globals.verifyAreaCode( document.forms[ 0 ].areaCode.value ) == false )
  177.         {
  178.             alert( "Please enter a valid area code." );
  179.             parent.parent.globals.setFocus( document.forms[ 0 ].areaCode);
  180.             return false;
  181.         }
  182.     }
  183.     if ( document.forms[ 0 ].phoneNumber.value == "" )
  184.     {
  185.         alert( "You must enter a telephone number." );
  186.         document.forms[ 0 ].phoneNumber.focus();
  187.         document.forms[ 0 ].phoneNumber.select();
  188.         return false;
  189.     }
  190.     if ( parent.parent.globals.verifyPhoneNumber(  document.forms[ 0 ].phoneNumber.value, 7 ) == false )
  191.     {
  192.         alert( "Please enter a valid telephone number." );
  193.         parent.parent.globals.setFocus( document.forms[ 0 ].phoneNumber );
  194.         return false;
  195.     }
  196.     return true;
  197. }
  198.  
  199. function loadData()
  200. {
  201.     // make sure all form element are valid objects, otherwise reload the page!
  202.     if (((document.forms[0].first == "undefined") || (document.forms[0].first == "[object InputArray]")) ||
  203.         ((document.forms[0].last == "undefined") || (document.forms[0].last == "[object InputArray]")) ||
  204.         ((document.forms[0].company == "undefined") || (document.forms[0].company == "[object InputArray]")) ||
  205.         ((document.forms[0].address1 == "undefined") || (document.forms[0].address1 == "[object InputArray]")) ||
  206.         ((document.forms[0].address2 == "undefined") || (document.forms[0].address2 == "[object InputArray]")) ||
  207.         ((document.forms[0].address3 == "undefined") || (document.forms[0].address3 == "[object InputArray]")) ||
  208.         ((document.forms[0].city == "undefined") || (document.forms[0].city == "[object InputArray]")) ||
  209.         ((document.forms[0].state == "undefined") || (document.forms[0].state == "[object InputArray]")) ||
  210.         ((document.forms[0].zip == "undefined") || (document.forms[0].zip == "[object InputArray]")) ||
  211.         ((document.forms[0].areaCode == "undefined") || (document.forms[0].areaCode == "[object InputArray]")) ||
  212.         ((document.forms[0].phoneNumber == "undefined") || (document.forms[0].phoneNumber == "[object InputArray]")))
  213.     {
  214.         top.globals.debug("FORM ELEMENT: " + document.forms[0].first);
  215.         top.globals.debug("FORM ELEMENT: " + document.forms[0].last);
  216.         top.globals.debug("FORM ELEMENT: " + document.forms[0].company);
  217.         top.globals.debug("FORM ELEMENT: " + document.forms[0].address1);
  218.         top.globals.debug("FORM ELEMENT: " + document.forms[0].address2);
  219.         top.globals.debug("FORM ELEMENT: " + document.forms[0].address3);
  220.         top.globals.debug("FORM ELEMENT: " + document.forms[0].city);
  221.         top.globals.debug("FORM ELEMENT: " + document.forms[0].state);
  222.         top.globals.debug("FORM ELEMENT: " + document.forms[0].zip);
  223.         top.globals.debug("FORM ELEMENT: " + document.forms[0].areaCode);
  224.         top.globals.debug("FORM ELEMENT: " + document.forms[0].phoneNumber);
  225.         parent.controls.reloadDocument();
  226.         return;
  227.     }
  228.  
  229.     document.forms[0].first.value = parent.parent.globals.document.vars.first.value;
  230.     document.forms[0].last.value = parent.parent.globals.document.vars.last.value;
  231.     document.forms[0].company.value = parent.parent.globals.document.vars.company.value;
  232.     document.forms[0].address1.value = parent.parent.globals.document.vars.address1.value;
  233.     document.forms[0].address2.value = parent.parent.globals.document.vars.address2.value;
  234.     document.forms[0].address3.value = parent.parent.globals.document.vars.address3.value;
  235.     document.forms[0].city.value = parent.parent.globals.document.vars.city.value;
  236.     document.forms[0].state.value = parent.parent.globals.document.vars.state.value;
  237.     document.forms[0].zip.value = parent.parent.globals.document.vars.zip.value;
  238.     document.forms[0].areaCode.value = parent.parent.globals.document.vars.areaCode.value;
  239.     document.forms[0].phoneNumber.value = parent.parent.globals.document.vars.phoneNumber.value;
  240.     parent.parent.globals.setFocus(document.forms[0].first);
  241.     if (parent.controls.generateControls)    parent.controls.generateControls();
  242. }
  243.  
  244.  
  245.  
  246. function saveData()
  247. {
  248.     // make sure all form element are valid objects, otherwise just skip & return!
  249.     if (((document.forms[0].first == "undefined") || (document.forms[0].first == "[object InputArray]")) ||
  250.         ((document.forms[0].last == "undefined") || (document.forms[0].last == "[object InputArray]")) ||
  251.         ((document.forms[0].company == "undefined") || (document.forms[0].company == "[object InputArray]")) ||
  252.         ((document.forms[0].address1 == "undefined") || (document.forms[0].address1 == "[object InputArray]")) ||
  253.         ((document.forms[0].address2 == "undefined") || (document.forms[0].address2 == "[object InputArray]")) ||
  254.         ((document.forms[0].address3 == "undefined") || (document.forms[0].address3 == "[object InputArray]")) ||
  255.         ((document.forms[0].city == "undefined") || (document.forms[0].city == "[object InputArray]")) ||
  256.         ((document.forms[0].state == "undefined") || (document.forms[0].state == "[object InputArray]")) ||
  257.         ((document.forms[0].zip == "undefined") || (document.forms[0].zip == "[object InputArray]")) ||
  258.         ((document.forms[0].areaCode == "undefined") || (document.forms[0].areaCode == "[object InputArray]")) ||
  259.         ((document.forms[0].phoneNumber == "undefined") || (document.forms[0].phoneNumber == "[object InputArray]")))
  260.     {
  261.         top.globals.debug("SAVE DATA....");
  262.         top.globals.debug("FORM ELEMENT: " + document.forms[0].first);
  263.         top.globals.debug("FORM ELEMENT: " + document.forms[0].last);
  264.         top.globals.debug("FORM ELEMENT: " + document.forms[0].company);
  265.         top.globals.debug("FORM ELEMENT: " + document.forms[0].address1);
  266.         top.globals.debug("FORM ELEMENT: " + document.forms[0].address2);
  267.         top.globals.debug("FORM ELEMENT: " + document.forms[0].address3);
  268.         top.globals.debug("FORM ELEMENT: " + document.forms[0].city);
  269.         top.globals.debug("FORM ELEMENT: " + document.forms[0].state);
  270.         top.globals.debug("FORM ELEMENT: " + document.forms[0].zip);
  271.         top.globals.debug("FORM ELEMENT: " + document.forms[0].areaCode);
  272.         top.globals.debug("FORM ELEMENT: " + document.forms[0].phoneNumber);
  273.  
  274.         parent.controls.reloadDocument();
  275.         return;
  276.     }
  277.  
  278.     parent.parent.globals.document.vars.first.value = document.forms[0].first.value;
  279.     parent.parent.globals.document.vars.last.value = document.forms[0].last.value;
  280.     parent.parent.globals.document.vars.company.value = document.forms[0].company.value;
  281.     parent.parent.globals.document.vars.address1.value = document.forms[0].address1.value;
  282.     parent.parent.globals.document.vars.address2.value = document.forms[0].address2.value;
  283.     parent.parent.globals.document.vars.address3.value = document.forms[0].address3.value;
  284.     parent.parent.globals.document.vars.city.value = document.forms[0].city.value;
  285.     parent.parent.globals.document.vars.state.value = document.forms[0].state.value;
  286.     parent.parent.globals.document.vars.zip.value = document.forms[0].zip.value;
  287.     parent.parent.globals.document.vars.areaCode.value = document.forms[0].areaCode.value;
  288.     parent.parent.globals.document.vars.phoneNumber.value = document.forms[0].phoneNumber.value;
  289.  
  290.     if (intlFlag == "yes")    {
  291.         var theCountry = document.forms[0].countryList.options[document.forms[0].countryList.selectedIndex].text;
  292.         for (var x=0; x<countryList.length; x++)    {
  293.             if (theCountry == countryList[x].name)    {
  294.                 parent.parent.globals.document.vars.country.value = countryList[x].name;
  295.                 parent.parent.globals.document.vars.countryCode.value = countryList[x].countryCode;
  296.                 break;
  297.                 }
  298.             }
  299.         }
  300.     else    {
  301.         parent.parent.globals.document.vars.country.value = "USA";
  302.         parent.parent.globals.document.vars.countryCode.value = "1";
  303.         }
  304. }
  305.  
  306. // end hiding contents from old browsers  -->
  307.