home *** CD-ROM | disk | FTP | other *** search
Wrap
<SCRIPT language="JavaScript"> <!-- Begin JavaScript var gValidationErr = 0; // globals var FieldName; var IsError = 0; var PageName; function CheckError ( ErrorNo, FormNo, FieldName ) { if (ErrorNo > 0) { if (ErrorNo == 1) { alert( "Invalid value: cannot be empty (" + FieldName + ")"); } else if (ErrorNo == 2) { alert( "Invalid value: must be a positive integer (" + FieldName + ")"); } else if (ErrorNo == 3) { alert( "Invalid value: must be a positive number (" + FieldName + ")"); } document.forms[FormNo].elements[FieldName].focus(); document.forms[FormNo].elements[FieldName].select(); IsError = 0; return false; } IsError = 0; return true; } function CheckIntegerVal( IntStr ) { var validDigits = "0123456789", i = 0, thisChar; if ( IntStr.length == 0 ) return false; // blank entry is not an integer! else { for( i = 0; i < IntStr.length; i++ ) { // check each character thisChar = IntStr.charAt(i); if ( validDigits.indexOf( thisChar ) == -1 ) return false; } } return true; } // CheckIntegerVal() function CheckDecimalVal( IntStr ) { var validDigits = "0123456789.", i = 0, thisChar; if ( IntStr.length == 0 ) return false; // blank entry is not an integer! else { for( i = 0; i < IntStr.length; i++ ) { // check each character thisChar = IntStr.charAt(i); if ( validDigits.indexOf( thisChar ) == -1 ) return false; } } return true; } // CheckIntegerVal() function CheckLen ( theVal ) { indx = theVal.indexOf( " " ); cleng = theVal.length; while ( indx > -1 ) { //strip out any spaces if ( indx == 0 ) theVal = theVal.substring( 1, cleng ); else theVal = theVal.substring( 0, indx ) + theVal.substring( indx + 1 , cleng ); indx=theVal.indexOf( " " ); cleng=theVal.length; } return theVal.length; } function ConfirmDelete () { // lvFlag = window.confirm ("Are you sure you want to delete this item?"); return true; } <@IFEQUAL <@VAR uPage> "AdminLogin"> function SetJS_Flag () { document.forms[0].jsFlag.value = 1; // document.forms[0].jsFlagTest.value = 1; return true; } // SetJS_Flag () </@IF> <@IFEQUAL <@LOCATE <@VAR uPage> 'Cat'> 1> function RedrawListFrame ( frameName ) { if ( "<@POSTARG ActionArg>" == "Update" ) { if ( ( "<@COL 3>" != "<@POSTARG CatDescOrig>" ) <@IF "<@VAR uUseSubCats> > 0">|| ( "<@COL 8>" != "<@POSTARG CatMstrCdOrig>" ) </@IF>) parent.frames[frameName].location = "http://<@CGIPARAM SERVER_NAME><@CGI><@APPFILE>?<@userReferenceArgument>&function=search&loaditem=false"; } return true; } // RedrawListFrame () function CheckCatEntry( theFormNo ) { IsError = 0; if ( ( document.forms[theFormNo].ActionArg.value == "Save" ) && ( CheckLen(document.forms[theFormNo].CatCd.value) == 0 ) ) { FieldName = "CatCd"; IsError = 1; } else if ( CheckLen(document.forms[theFormNo].CatDesc.value) == 0 ) { FieldName = "CatDesc"; IsError = 1; } else if ( document.forms[theFormNo].CatSortKey.value.length > 0 ) { if ( CheckIntegerVal(document.forms[theFormNo].CatSortKey.value) == false ) { FieldName = "CatSortKey"; IsError = 2; } } return CheckError ( IsError,theFormNo , FieldName ) ; } </@IF> <@IFEQUAL <@LOCATE <@VAR uPage> 'Cust'> 1> <@INCLUDE <@VAR uUnivFolderPath>Scripts/CheckEmail.txt> function CheckStateAbr( theAbr ) { 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,"; // Includes U.S. military and overseas possesions. Source = http://www.usps.gov/ncsc/lookups/abbr_state.txt theAbr = theAbr + "," if ( uspsStates.indexOf( theAbr ) == -1 ) { alert("Invalid state code"); return false; } return true; } // CheckStateAbr() function CheckCustEntry( theFormNo ) { IsError = 0; 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 ) ) { document.forms[theFormNo].target = "Main"; document.forms[theFormNo].action = "<@CGI><@APPFILE>?<@userReferenceArgument>&loadlist=true&rowid=" + document.forms[theFormNo].CustRowid.value; // alert( "TARGET='" + document.forms[theFormNo].target + "'; ACTION=" + document.forms[theFormNo].action + "'."); } // return true; var i = 0; var FldVal=""; var idx=0; var lvFlag = true; var notReq="TaxCd,<@IF '<@VAR uCorpOrIndividual>=1'>BillName2,<@ELSE>Contact,</@IF>Dept,BillAddress2,FaxNo<@IF '<@VAR uIsUpdate>=0'>,BillCountry</@IF>"; // Names of fields that do not require a value (BillCountry and ShipCountry are pop-ups if gIsUpdate = 1) for ( i=1; i < 30; i++ ) { if ( (document.forms[theFormNo].elements[i].type == "text") || (document.forms[theFormNo].elements[i].type == "password") ) { // || (document.forms[theFormNo].elements[i].type == "textarea") FieldName = document.forms[theFormNo].elements[i].name; // alert ("i=" + i + "; FieldName='" + FieldName + "'"); // alert (document.forms[theFormNo].elements[i].type + "," + FieldName); FldVal = document.forms[theFormNo].elements[i].value; idx=notReq.indexOf( FieldName ); if ( ( idx == -1 ) && ( FldVal.length == 0 ) ) { IsError = 1; break; } if ( ( FieldName == "BillState" ) && ( ( document.forms[theFormNo].BillCountry.value == "USA" ) || ( document.forms[theFormNo].BillCountry.value == "US" ) ) ) { if ( CheckStateAbr( FldVal ) == false ) { IsError = 3; break; } } if ( FieldName == "Password" ) // last field to validate break; } } if ( IsError > 0 ) { return CheckError( IsError, theFormNo , FieldName ); } else if ( !checkEmail(document.forms[theFormNo].EmailAddress.value) ) { lvFlag = window.confirm ("The email address you entered appears to be invalid, are you sure you want to use it?"); if ( lvFlag == false ) { document.forms[theFormNo].EmailAddress.focus(); document.forms[theFormNo].EmailAddress.select(); return false; } } return true; } </@IF> <@IFEQUAL <@LOCATE <@VAR uPage> 'Item'> 1> function CheckItemEntry( theFormNo ) { IsError = 0; return true; return CheckError ( IsError,theFormNo , FieldName ) ; } </@IF> <@IFEQUAL <@LOCATE <@VAR uPage> 'Order'> 1> <@INCLUDE <@VAR uUnivFolderPath>Scripts/CheckEmail.txt> function CheckOrderEntry( theFormNo ) { IsError = 0; return true; return CheckError ( IsError,theFormNo , FieldName ) ; } </@IF> <@IFEQUAL <@LOCATE <@VAR uPage> 'Order'> 1> <@INCLUDE <@VAR uUnivFolderPath>Scripts/CheckEmail.txt> function CheckOrderEntry( theFormNo ) { IsError = 0; var i = 0; var FldVal=""; var idx=0; var lvFlag = true; var notReq="CustCode,CustName,CustName2,Password,Total,SpecialShipFees,SalesTax,SalesTaxPercent,OrderStatus,BillAddress2,BillCountry,ShipAddress2,ShipCountry,Freight,TaxCode,CardNo,Month,Year,PONo,ShipVia,Weight,Comments"; for ( i=1; i < 30; i++ ) { if ( (document.forms[theFormNo].elements[i].type == "text") || (document.forms[theFormNo].elements[i].type == "password") ) { // || (document.forms[theFormNo].elements[i].type == "textarea") FieldName = document.forms[theFormNo].elements[i].name; // alert ("i=" + i + "; FieldName='" + FieldName + "'"); // alert (document.forms[theFormNo].elements[i].type + "," + FieldName); FldVal = document.forms[theFormNo].elements[i].value; idx=notReq.indexOf( FieldName ); if ( ( idx == -1 ) && ( FldVal.length == 0 ) ) { IsError = 1; break; } // if ( ( FieldName == "BillState" ) && ( ( document.forms[theFormNo].BillCountry.value == "USA" ) || ( document.forms[theFormNo].BillCountry.value == "US" ) ) ) { // if ( CheckStateAbr( FldVal ) == false ) { // IsError = 3; // break; // } // } if ( ( FieldName == "Freight" ) && ( FldVal.length != 0 ) && ( IsError == 0 ) ) { if ( CheckDecimalVal( FldVal ) == false ) { IsError = 3; break; } } if ( FieldName == "Comments" ) // last field to validate break; } } if ( IsError > 0 ) { return CheckError( IsError, theFormNo , FieldName ); } else if ( !checkEmail(document.forms[theFormNo].EmailAddress.value) ) { lvFlag = window.confirm ("The email address you entered appears to be invalid, are you sure you want to use it?"); if ( lvFlag == false ) { document.forms[theFormNo].EmailAddress.focus(); document.forms[theFormNo].EmailAddress.select(); return false; } } //check credit card number and use OK/Cancel message if it appears invalid return true; } </@IF> // -- End JavaScript --> </SCRIPT>