PageSourceSearch

https://www.brandingblvd.com/js/Utils.js

js brandingblvd.com collected 2026-10-08 06:00:43 UTC 10,665 bytes, 415 lines download raw bytes

1
2/* Entire page (C) Copyright 2000-2012 Quick Technologies Inc.		*/
3/* Copying or distribution of this proprietary source code is 		*/
4/* STRICTLY prohibited.  											*/
5
6/* Last Updated: 09/24/12 */
7
8function MinLen(fld,name,m)
9{
10	if (fld==null) return(true);
11	s=Trim(fld.value);
12	if (s.length>=m) return(true);
13	if (s=="")
14		alert("Please fill in the \""+name+"\" field.");
15	else
16		alert("Please enter at least "+m+" characters in the \""+name+"\" field.");
17    fld.focus();
18	return(false);
19}
20
21function MaxLen(fld,name,m)
22{
23	if (fld==null) return(true);
24	s=Trim(fld.value);
25	if (s.length<=m) return(true);
26	alert("Please enter a maximum of "+m+" characters in the \""+name+"\" field.");
27    fld.focus();
28	return(false);
29}
30
31function Trim(fld)
32{
33	return(LeftTrim(RightTrim(fld,"")," "));
34}
35
36function LeftTrim(String,TrimChar)
37{
38 	String += "";		// Force argument to string.
39 	TrimChar += "";		// Force argument to string.
40	if ((TrimChar == "") || (!(TrimChar.length == 1))) {
41		TrimChar = " ";
42 	}
43 	if (String.length==0) {
44  		return(String);
45	}
46 	var Count;
47 	for (Count = 0 ; Count<String.length ; Count++) {
48  		if(!(String.charAt(Count) == TrimChar)) {
49   			return(String.substring(Count,String.length));
50		}
51	}
52	return("");
53}
54function RightTrim(String,TrimChar)
55{
56	String += ""        // Force argument to string.
57 	TrimChar += ""      // Force argument to string.
58 	if ((TrimChar == "") || (!(TrimChar.length == 1)))
59  		TrimChar = " ";
60 	if (String.length==0) {
61  		return(String);
62	}
63 	var Count;
64 	for (Count = String.length-1 ; Count>=0 ; Count--) {
65		if (!(String.charAt(Count) == TrimChar)) {
66			return(String.substring(0,Count+1));
67		}
68	}
69	return("");
70}
71
72function MinNum(fld,name,m)
73{
74	if (fld==null) return(true);
75	if (parseInt(fld.value)>=m) return(true);
76	alert("The \""+name+"\" must be at least "+m+".");
77    fld.focus();
78	return(false);
79}
80
81function MaxNum(fld,name,m)
82{
83	if (fld==null) return(true);
84	if (fld.value<=m) return(true);
85	alert("The \""+name+"\" must be less than or equal to "+m+".");
86    fld.focus();
87	return(false);
88}
89
90function AllDigits(fld,name,allowdecimal)
91{
92	return(AllDigitsBase(fld,name,allowdecimal,false,false));
93}
94
95function IsNum(fld,name,allowdecimal)
96{
97	return(AllDigitsBase(fld,name,allowdecimal,true,false));
98}
99
100function IsMoney(fld,name,allownegative)
101{
102	return(AllDigitsBase(fld,name,true,true,allownegative));
103}
104
105function AllDigitsBase(fld,name,allowdecimal,allowcomma,allownegative)
106{
107	var chk = "0123456789";
108	if (allowdecimal==true) chk=chk+".";
109	if (allowcomma==true) chk=chk+",";
110	if (allownegative==true) chk=chk+"-";
111  	var valid = true;
112	var decimals = 0;
113  	if (fld==null) return(true);
114  	for (i = 0 ; i < fld.value.length ; i++) {
115    	ch = fld.value.charAt(i);
116    	for (j = 0;  j < chk.length;  j++) {
117      		if (ch == chk.charAt(j)) break;
118		}
119    	if (j == chk.length) {
120      		valid = false;
121      		break;
122    	}
123		if (ch=='.') decimals++;
124		if (decimals>1) {
125			valid=false;
126			break;
127		}
128		else if (ch=='-' && i!=0) {
129			valid=false;
130			break;
131		}
132  	}
133  	if (!valid) {
134    	alert("Please enter only numbers in the \""+name+"\" field.");
135    	fld.focus();
136    	return (false);
137  	}
138  	else return(true);
139}
140
141function RequiredIfFilled(fld1,fld1name,fld2,fld2name)
142{
143	// If fld1 is filled in, then fld2 becomes required
144	if (fld1==null || fld2==null) return(true);
145	s=Trim(fld1.value);
146	if (s.length==0) return(true);
147	s=Trim(fld2.value);
148	if (s.length>0) return(true);
149	alert("Please fill in "+fld2name+" because you filled in "+fld1name+".");
150	fld2.focus();
151	return(false);
152}
153
154function ValidateEmailAddr(fld,name,allowmultiple)
155{
156	var chk = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.!#$%&'*+-/=?^_`{|}~@";
157  	var valid = true;
158  	if (fld==null || fld.value=="") return(true);
159	fld.value=Trim(fld.value);
160	var i=0;
161	while (i<fld.value.length) {
162		var atsign=0, period=0;
163	  	for (i = i ; i < fld.value.length ; i++) {
164	    	ch = fld.value.charAt(i);
165			if (ch=='@') atsign++;
166			else if (ch=='.') period++;
167	    	for (j = 0;  j < chk.length;  j++) {
168	      		if (ch == chk.charAt(j)) break;
169			}
170			if (allowmultiple && ch==',') {
171				i++;
172				while (i<fld.value.length && fld.value.charAt(i)==' ') {
173					i++;
174				}
175				break;
176			}
177	    	else if (j == chk.length) {
178	      		valid = false;
179	      		break;
180	    	}
181	  	}
182		if (atsign!=1 || period==0) valid=false;
183	  	if (!valid) {
184	    	alert("The email address you entered in the \""+name+"\" field is not val
184id.");
185	    	fld.focus();
186	    	return (false);
187	  	}
188	}
189  	return(true);
190}
191
192function NoAngleBrackets(fld,name)
193{
194	var chk = "<>";
195  	var valid = true;
196  	if (fld==null) return(true);
197  	for (i = 0 ; i < fld.value.length ; i++) {
198    	ch = fld.value.charAt(i);
199    	for (j = 0;  j < chk.length;  j++) {
200      		if (ch == chk.charAt(j)) {
201				valid = false;
202				break;
203			}
204		}
205  	}
206  	if (!valid) {
207    	alert("You cannot use '<' or '>' signs in the \""+name+"\" field.");
208    	fld.focus();
209    	return (false);
210  	}
211  	else return(true);
212}
213
214function CheckPass(p1,p2)
215{
216	if (p1==null) return(true);
217	if (p2==null) return(true);
218	if (p1.value==p2.value) return(true);
219	alert("The new passwords you entered do not match.  Please re-type them.");
220	p1.value="";
221	p2.value="";
222	p1.focus();
223	return(false);
224}
225
226function CheckDate(mo,day,yr)
227{
228	var ok=true, leap, oddmo;
229
230	leap=(yr%4==0);
231	oddmo=(mo%2==1);
232	if (mo<1 || mo>12) {
233		ok=false;
234	}
235	else if ((day<1) ||
236			 (mo<8 && oddmo && day>31) ||
237			 (mo<8 && !oddmo && day>30) ||
238			 (mo>7 && !oddmo && day>31) ||
239			 (mo>7 && oddmo && day>30) ||
240			 (mo==2 && !leap && day>28) ||
241			 (mo==2 && leap && day>29)) {
242		ok=false;
243	}
244	else if (yr.length!=2 && yr.length!=4) {
245		ok=false;
246	}
247	else if (!(yr>=0 && yr<30) && !(yr>=2000 && yr<2030)) {
248		ok=false;
249	}
250	return(ok);
251}
252
253function DateOk(fld,name)
254{
255	var chk="0123456789/";
256  	var ok=true;
257	var mo="", day="", yr="";
258  	if (fld==null || fld.value=="") return(true);
259  	for (i=0 ; i<fld.value.length ; i++) {
260    	ch = fld.value.charAt(i);
261    	for (j=0 ; j<chk.length ; j++) {
262      		if (ch==chk.charAt(j)) break;
263		}
264    	if (j == chk.length) {
265      		ok=false;
266      		break;
267    	}
268	}
269	if (ok) {
270	  	for (i=0 ; i<fld.value.length ; i++) {
271	    	ch=fld.value.charAt(i);
272			if (ch=='/') break;
273			mo=mo+ch;
274		}
275	  	for (i=i+1 ; i<fld.value.length ; i++) {
276	    	ch=fld.value.charAt(i);
277			if (ch=='/') break;
278			day=day+ch;
279		}
280	  	for (i=i+1 ; i<fld.value.length ; i++) {
281	    	ch=fld.value.charAt(i);
282			yr=yr+ch;
283		}
284		ok=CheckDate(mo,day,yr);
285	}
286  	if (!ok) {
287    	alert("The date you entered in the \""+name+"\" field is invalid.  Please be sure you are entering the date in the format MM/DD/YYYY.");
288    	fld.focus();
289    	return (false);
290  	}
291  	else return(true);
292}
293
294function PhoneOK(fld,name)
295{
296	var permittedlist = "().-+/ 0123456789";
297	var digitlist = "0123456789";
298	var PhoneDigits = "";
299  	if (fld==null || Trim(fld.value).length==0) return(true);
300  	for (i = 0 ; i < fld.value.length ; i++) {
301    	ch = fld.value.charAt(i);
302		// check for invalid chars
303    	for (j = 0;  j < permittedlist.length;  j++) {
304      		if (ch == permittedlist.charAt(j)) break;
305		}
306		if (j == permittedlist.length) {
307			alert("The phone number you entered for the \""+name+"\" field is not valid.  Please make sure to enter the phone number in the form XXX-XXX-XXXX.  International phone numbers should begin with a '+' sign.");
308			fld.focus();
309			return(false);
310		}
311		// get numbers only
312    	for (j = 0;  j < digitlist.length;  j++) {
313      		if (ch == digitlist.charAt(j)) break;
314		}
315    	if (j<digitlist.length) {
316			PhoneDigits+=ch;
317    	}
318  	}
319	if (PhoneDigits.length<10) {
320		alert("The phone number you entered for the \""+name+"\" field is not valid.  Please make sure to enter the phone number in the form XXX-XXX-XXXX.  International phone numbers should begin with a '+' sign.");
321		fld.focus();
322		return(false);
323	}
324	else if (PhoneDigits.length>10 && fld.value.charAt(0)!='+') {
325		alert("The phone number you entered for the \""+name+"\" field is not valid.  Please make sure to enter the phone number in the form XXX-XXX-XXXX.  International phone numbers should begin with a '+' sign.");
326		fld.focus();
327		return(false);
328	}
329  	else return(true);
330}
331
332function RemoveSpaces(s) {
333	return s.replace(/\s/g, "");
334}
335
336function StrToFloat(s)
337{
338  /* converts a string to a float while removing commas */
339  return(parseFloat(s.toString().replace(/[^\d\.]/g,'')) || 0);
340}
341
342function StrToCurrency(s, rounding)
343{
344  // Note: this requires the currency.js library
345  var c = currency(s, { precision: rounding ? 2 : 5 });
346  return c.value;
347}
348
349function FormatPrice(n)
350{
351  /* Formats a numeric price with thousands separators and decimal with 2 digit cents */
352  return(NumberWithCommas(StrToFloat(n).toFixed(2)));
353}
354
355function CountDecimals(n)
356{
357  var decimals;
358  decimals=(n.toString().split('.')[1] || []).length;
359  return(decimals);
360}
361
362function FormatPrice(n,decimals)
363{
364  /* Formats a numeric price with thousands separators and decimal with at least two but up to decimals digits for cents */
365  if (!decimals || decimals<2) decimals=2;
366  var num = parseFloat(StrToFloat(n).toFixed(decimals)); // answer with however many decimals are required
367  num = num.toFixed(Math.max(2, (num.toString().split('.')[1] || []).length)); // enforce at least 2 decimals
368  return(NumberWithCommas(num));
369}
370
371function NumberWithCommas(x) {
372  /* Adds thousands separator to numbers */
373  var parts = x.toString().split(".");
374  parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
375  return parts.join(".");
376}
377
378function PostToService(URL, Params)
379{
380  var ok;
381  var ResponseRec;
382
383	$.ajax({
384	    type: "POST",
385	    url: URL,
386	    data: Params,
387		  async:false, // wait for it to finish
388	    success: function(response) {
389			     ResponseRec=response.split("\t");
390			     ok=ResponseRec[0]=='1';
391           if (!ok) {
392				         alert(ResponseRec[1]);
393           }
394			}
395	  });
396    return(ok);
397}
398
399function PostToServiceAsyncWithCallback(URL, Params, Callback, ErrorCallback)
400{
401	$.ajax({
402		type: "POST",
403		url: URL,
404		data: Params,
405		async:true, // don't wait
406		success: function(data, textStatus, jqXHR)
407		{
408			Callback(data);
409		},
410		error: function(jqXHR, textStatus, errorThrown)
411		{
412			ErrorCallback(textStatus);
413		}
414	});
415}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.