home *** CD-ROM | disk | FTP | other *** search
/ Datatid 1999 #6 / Datatid_1999-06.iso / internet / Tango352Promo / Tango / data.z / AdminScripts.txt < prev    next >
Encoding:
Text File  |  1999-02-05  |  9.6 KB  |  306 lines

  1. <SCRIPT language="JavaScript">
  2. <!-- Begin JavaScript 
  3. var gValidationErr = 0;  // globals
  4. var FieldName;
  5. var IsError = 0;
  6. var PageName;
  7.  
  8. function CheckError ( ErrorNo, FormNo, FieldName ) {
  9.   if (ErrorNo > 0) { 
  10.     if (ErrorNo == 1) {
  11.          alert( "Invalid value:  cannot be empty (" + FieldName + ")");
  12.       }
  13.       else if (ErrorNo == 2) {
  14.          alert( "Invalid value:  must be a positive integer (" + FieldName + ")");      
  15.       }
  16.       else if (ErrorNo == 3) {
  17.          alert( "Invalid value:  must be a positive number (" + FieldName + ")");      
  18.       }
  19.     document.forms[FormNo].elements[FieldName].focus();
  20.     document.forms[FormNo].elements[FieldName].select();
  21.     IsError = 0;
  22.     return false;
  23.   }  
  24.   IsError = 0;
  25.   return true;
  26.  
  27. }
  28.  
  29. function CheckIntegerVal( IntStr )
  30. {
  31.   var    validDigits    =    "0123456789",
  32.           i            =    0, 
  33.           thisChar;
  34.  
  35.   if ( IntStr.length == 0 ) 
  36.         return false;    // blank entry is not an integer!
  37.   else {
  38.           for( i = 0; i < IntStr.length; i++ )    {  // check each character
  39.              thisChar    = IntStr.charAt(i);
  40.              if ( validDigits.indexOf( thisChar ) == -1 ) 
  41.               return false;
  42.           } 
  43.     } 
  44.   return true;
  45. } // CheckIntegerVal()
  46.  
  47. function CheckDecimalVal( IntStr )
  48. {
  49.   var    validDigits    =    "0123456789.",
  50.           i            =    0, 
  51.           thisChar;
  52.  
  53.   if ( IntStr.length == 0 ) 
  54.         return false;    // blank entry is not an integer!
  55.   else {
  56.           for( i = 0; i < IntStr.length; i++ )    {  // check each character
  57.              thisChar    = IntStr.charAt(i);
  58.              if ( validDigits.indexOf( thisChar ) == -1 ) 
  59.               return false;
  60.           } 
  61.     } 
  62.   return true;
  63. } // CheckIntegerVal()
  64.  
  65. function CheckLen ( theVal ) {
  66.  
  67.   indx = theVal.indexOf( " " ); 
  68.   cleng = theVal.length;
  69.   
  70.   while ( indx > -1 ) {    //strip out any spaces
  71.      if ( indx == 0 ) 
  72.        theVal = theVal.substring( 1, cleng );
  73.      else 
  74.        theVal = theVal.substring( 0, indx ) + theVal.substring( indx + 1 , cleng );
  75.      indx=theVal.indexOf( " " );
  76.      cleng=theVal.length;
  77.   }
  78.   
  79.   return theVal.length;
  80. }
  81.  
  82. function ConfirmDelete () {
  83.   // lvFlag = window.confirm ("Are you sure you want to delete this item?");
  84.   return true;
  85. }
  86.  
  87. <@IFEQUAL <@VAR uPage> "AdminLogin">
  88. function SetJS_Flag () { 
  89.   document.forms[0].jsFlag.value = 1;
  90.   // document.forms[0].jsFlagTest.value = 1;
  91.   return true;
  92. } // SetJS_Flag ()
  93. </@IF>
  94.  
  95.  
  96. <@IFEQUAL <@LOCATE <@VAR uPage> 'Cat'> 1>
  97. function RedrawListFrame ( frameName ) { 
  98.   if ( "<@POSTARG ActionArg>" == "Update" ) { 
  99.       if ( ( "<@COL 3>" != "<@POSTARG CatDescOrig>" ) <@IF "<@VAR uUseSubCats> > 0">|| ( "<@COL 8>" != "<@POSTARG CatMstrCdOrig>" ) </@IF>) 
  100.         parent.frames[frameName].location = "http://<@CGIPARAM SERVER_NAME><@CGI><@APPFILE>?<@userReferenceArgument>&function=search&loaditem=false"; 
  101.   } 
  102.   return true;
  103. } // RedrawListFrame ()
  104.  
  105. function  CheckCatEntry( theFormNo ) { 
  106.   IsError = 0;
  107.       
  108.   if ( ( document.forms[theFormNo].ActionArg.value == "Save" ) && ( CheckLen(document.forms[theFormNo].CatCd.value) == 0 ) ) { 
  109.      FieldName = "CatCd";
  110.      IsError = 1;
  111.   }
  112.   
  113.   else if (  CheckLen(document.forms[theFormNo].CatDesc.value) == 0 ) { 
  114.      FieldName = "CatDesc";
  115.      IsError = 1;
  116.   }
  117.  
  118.   else if ( document.forms[theFormNo].CatSortKey.value.length > 0 ) { 
  119.      if ( CheckIntegerVal(document.forms[theFormNo].CatSortKey.value) == false ) { 
  120.        FieldName = "CatSortKey";
  121.        IsError = 2;
  122.      }
  123.   } 
  124.  
  125.   return CheckError ( IsError,theFormNo , FieldName ) ;
  126. }
  127. </@IF>
  128.  
  129. <@IFEQUAL <@LOCATE <@VAR uPage> 'Cust'> 1>
  130.  
  131. <@INCLUDE <@VAR uUnivFolderPath>Scripts/CheckEmail.txt>
  132.  
  133. function CheckStateAbr( theAbr )
  134. {
  135.    var uspsStates = "AL,AK,AS,AZ,AR,CA,CO,CT,DE,DC,FM,FL,GA,GU,HI,ID,IL,IN,IA,KS,KY,LA,ME,MH,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,MP,OH,OK,OR,PW,PA,PR,RI,SC,SD,TN,TX,UT,VT,VI,VA,WA,WV,WI,WY,AE,AA,AE,AE,AE,AP,"; 
  136.      // Includes U.S. military and overseas possesions.  Source = http://www.usps.gov/ncsc/lookups/abbr_state.txt
  137.  
  138.   theAbr = theAbr + ","
  139.   if ( uspsStates.indexOf( theAbr ) == -1 ) { 
  140.      alert("Invalid state code");
  141.      return false;
  142.   }
  143.  
  144.   return true;
  145. } // CheckStateAbr()
  146.  
  147. function  CheckCustEntry( theFormNo ) { 
  148.   IsError = 0;
  149.   
  150.   if ( ( document.forms[theFormNo].BillName.value != document.forms[theFormNo].OrigCustName.value ) ||  ( document.forms[theFormNo].BillName2.value != document.forms[theFormNo].OrigCustName2.value ) ||  ( document.forms[theFormNo].BillCity.value != document.forms[theFormNo].OrigCustCity.value ) ||  ( document.forms[theFormNo].BillState.value != document.forms[theFormNo].OrigCustState.value ) ||  ( document.forms[theFormNo].Phone.value != document.forms[theFormNo].OrigCustPhone.value ) )  {  
  151.     document.forms[theFormNo].target = "Main";
  152.     document.forms[theFormNo].action = "<@CGI><@APPFILE>?<@userReferenceArgument>&loadlist=true&rowid=" + document.forms[theFormNo].CustRowid.value;
  153.     // alert( "TARGET='" + document.forms[theFormNo].target + "'; ACTION=" + document.forms[theFormNo].action + "'.");
  154.   }
  155.   
  156.   // return true;
  157.   
  158.   var i = 0;
  159.   var FldVal="";
  160.   var idx=0;
  161.   var lvFlag = true;
  162.   var notReq="TaxCd,<@IF '<@VAR uCorpOrIndividual>=1'>BillName2,<@ELSE>Contact,</@IF>Dept,BillAddress2,FaxNo<@IF '<@VAR uIsUpdate>=0'>,BillCountry</@IF>"; 
  163.       // Names of fields that do not require a value (BillCountry and ShipCountry are pop-ups if gIsUpdate = 1)
  164.  
  165.     
  166.   for ( i=1; i < 30; i++ )  { 
  167.     if ( (document.forms[theFormNo].elements[i].type == "text") || (document.forms[theFormNo].elements[i].type == "password") ) {   // || (document.forms[theFormNo].elements[i].type == "textarea")
  168.       FieldName = document.forms[theFormNo].elements[i].name;
  169.       // alert ("i=" + i + "; FieldName='" + FieldName + "'");
  170.     
  171.       // alert (document.forms[theFormNo].elements[i].type + "," + FieldName);
  172.  
  173.       FldVal = document.forms[theFormNo].elements[i].value;
  174.       idx=notReq.indexOf( FieldName );
  175.       if ( ( idx == -1 ) && ( FldVal.length == 0 ) ) { 
  176.           IsError = 1;
  177.           break;      
  178.       }
  179.     
  180.       if ( ( FieldName == "BillState" ) && ( ( document.forms[theFormNo].BillCountry.value == "USA" ) || ( document.forms[theFormNo].BillCountry.value == "US" ) ) ) { 
  181.           if ( CheckStateAbr( FldVal ) == false ) { 
  182.            IsError = 3;
  183.            break;
  184.           }
  185.       }
  186.       if ( FieldName == "Password" ) // last field to validate
  187.          break; 
  188.     } 
  189.   }   
  190.   
  191.   if ( IsError > 0 ) {     
  192.     return CheckError( IsError, theFormNo , FieldName );
  193.   } 
  194.   
  195.   else if ( !checkEmail(document.forms[theFormNo].EmailAddress.value) ) { 
  196.      lvFlag = window.confirm ("The email address you entered appears to be invalid, are you sure you want to use it?");
  197.      if ( lvFlag == false ) { 
  198.        document.forms[theFormNo].EmailAddress.focus();
  199.        document.forms[theFormNo].EmailAddress.select();
  200.        return false;
  201.      }
  202.   }
  203.   
  204.   return true;
  205.  
  206. }
  207. </@IF>
  208. <@IFEQUAL <@LOCATE <@VAR uPage> 'Item'> 1>
  209. function  CheckItemEntry( theFormNo ) { 
  210.   IsError = 0;
  211.   
  212.   return true;
  213.  
  214.   return CheckError ( IsError,theFormNo , FieldName ) ;
  215. }
  216. </@IF>
  217. <@IFEQUAL <@LOCATE <@VAR uPage> 'Order'> 1>
  218.  
  219. <@INCLUDE <@VAR uUnivFolderPath>Scripts/CheckEmail.txt>
  220.  
  221. function  CheckOrderEntry( theFormNo ) { 
  222.   IsError = 0;
  223.   
  224.   return true;
  225.  
  226.   return CheckError ( IsError,theFormNo , FieldName ) ;
  227. }
  228. </@IF>
  229.  
  230.  
  231.  
  232.  
  233. <@IFEQUAL <@LOCATE <@VAR uPage> 'Order'> 1>
  234.  
  235. <@INCLUDE <@VAR uUnivFolderPath>Scripts/CheckEmail.txt>
  236.  
  237. function  CheckOrderEntry( theFormNo ) { 
  238.   IsError = 0;
  239.   
  240.   var i = 0;
  241.   var FldVal="";
  242.   var idx=0;
  243.   var lvFlag = true;
  244.   var notReq="CustCode,CustName,CustName2,Password,Total,SpecialShipFees,SalesTax,SalesTaxPercent,OrderStatus,BillAddress2,BillCountry,ShipAddress2,ShipCountry,Freight,TaxCode,CardNo,Month,Year,PONo,ShipVia,Weight,Comments";
  245.    
  246.     
  247.   for ( i=1; i < 30; i++ )  { 
  248.     if ( (document.forms[theFormNo].elements[i].type == "text") || (document.forms[theFormNo].elements[i].type == "password") ) {   // || (document.forms[theFormNo].elements[i].type == "textarea")
  249.       FieldName = document.forms[theFormNo].elements[i].name;
  250.       // alert ("i=" + i + "; FieldName='" + FieldName + "'");
  251.     
  252.       // alert (document.forms[theFormNo].elements[i].type + "," + FieldName);
  253.  
  254.       FldVal = document.forms[theFormNo].elements[i].value;
  255.       idx=notReq.indexOf( FieldName );
  256.       if ( ( idx == -1 ) && ( FldVal.length == 0 ) ) { 
  257.           IsError = 1;
  258.           break;      
  259.       }
  260.           
  261.       // if ( ( FieldName == "BillState" ) && ( ( document.forms[theFormNo].BillCountry.value == "USA" ) || ( document.forms[theFormNo].BillCountry.value == "US" ) ) ) { 
  262.       //     if ( CheckStateAbr( FldVal ) == false ) { 
  263.       //      IsError = 3;
  264.       //      break;
  265.       //     }
  266.       // }
  267.       
  268.       if ( ( FieldName == "Freight" ) && ( FldVal.length != 0 ) && ( IsError == 0 ) ) {
  269.            if ( CheckDecimalVal( FldVal ) == false ) { 
  270.               IsError = 3;
  271.               break;
  272.         }
  273.       }    
  274.           
  275.     if ( FieldName == "Comments" ) // last field to validate
  276.        break; 
  277.     } 
  278.   }  
  279.   
  280.   
  281.   
  282.   if ( IsError > 0 ) {     
  283.     return CheckError( IsError, theFormNo , FieldName );
  284.   } 
  285.     
  286.   else if ( !checkEmail(document.forms[theFormNo].EmailAddress.value) ) { 
  287.      lvFlag = window.confirm ("The email address you entered appears to be invalid, are you sure you want to use it?");
  288.      if ( lvFlag == false ) { 
  289.        document.forms[theFormNo].EmailAddress.focus();
  290.        document.forms[theFormNo].EmailAddress.select();
  291.        return false;
  292.      }
  293.   }
  294.   
  295.   //check credit card number and use OK/Cancel message if it appears invalid
  296.   
  297.   
  298.   return true;
  299.  
  300. }
  301. </@IF>
  302.  
  303. //  -- End JavaScript -->
  304.  
  305. </SCRIPT>
  306.