PageSourceSearch

https://financing.macjames.ca/includes/commonfunctions.js

js macjames.ca collected 2026-10-05 09:35:50 UTC 16,476 bytes, 440 lines download raw bytes

1var regExp = /<\/?[^>]+>/gi;
2function ReplaceTags(xStr){
3  xStr = xStr.replace(regExp,"");
4  return xStr;
5}
6var szResultType = "";
7var nX = 0;
8var nY = 0;
9function GetXY(e) {
10	if (window.event) { e = window.event; };
11	if (document.all){
12		nX = event.clientX+5;
13		nY = event.clientY+10;
14	}
15	else {
16		nX = e.pageX+5;
17		nY = e.pageY+10;
18	}
19	//}
20/*
21	if (IE)	{
22		 var tmpX = event.clientX;
23		 var tmpY = event.clientY;
24		}	
25	else 	{
26			 var tmpX = m.pageX;
27		 var tmpY = m.pageY;
28		}  
29	if (!document.body.scrollTop)
30		{
31		 var iL = document.documentElement.scrollLeft;	
32		 var iV = document.documentElement.scrollTop;
33		}
34	else 	{
35		 var iL = document.body.scrollLeft;	
36		 var iV = document.body.scrollTop;	
37		}
38*/
39}
40
41var myAgent = navigator.userAgent.toLowerCase();
42var myVersion = parseInt(navigator.appVersion);
43var is_ie = ((myAgent.indexOf("msie") != -1) 
44         && (myAgent.indexOf("opera") == -1));
45var is_nav = ((myAgent.indexOf('mozilla')!=-1) 
46           && (myAgent.indexOf('spoofer')==-1) 
47           && (myAgent.indexOf('compatible') == -1) 
48           && (myAgent.indexOf('opera')==-1)
49           && (myAgent.indexOf('webtv') ==-1) 
50           && (myAgent.indexOf('hotjava')==-1));
51var is_win = ((myAgent.indexOf("win")!=-1) 
52           || (myAgent.indexOf("16bit")!=-1));
53var is_mac = (myAgent.indexOf("mac")!=-1);
54var pageWidth = 0, pageHeight = 0;
55
56     if( typeof( window.innerWidth ) == 'number' ) {
57       pageWidth = window.innerWidth;
58       pageHeight = window.innerHeight;
59     }
60     else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
61       //IE 6+ in 'standards compliant mode'
62       pageWidth = document.documentElement.clientWidth;
63       pageHeight = document.documentElement.clientHeight;
64     }
65     else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
66       //IE 4 compatible
67       pageWidth = document.body.clientWidth;
68       pageHeight = document.body.clientHeight;
69     }
70
71function IsNumeric(String)//Positive and Negative Numbers.
72{
73	var ValidDigits = "()- ./0123456789";
74	var Digit;
75	var bOpenBracket = false;
76	var bCloseBracket = false;
77	var bDash = false;
78	var bDecimal = false;
79	var bValid = true;
80	var Len = String.length;
81	
82	//characters can be only . or a digit, but only one decimal.
83	for(var nIndex = 0; nIndex < Len && bValid; nIndex++)
84	{
85		check_char = ValidDigits.indexOf(String.charAt(nIndex));
86		if(check_char < 0){bValid = false;}//not a valid number (including spaces or decimals or parenthesis)
87		if(check_char == 0){bOpenBracket ? bValid=false : bOpenBracket=true;}//( 
88		if(check_char == 1){bCloseBracket ? bValid=false : bCloseBracket=true;}//( 
89		if (check_char == 2){bDash ? bValid=false : bDash=true;}//-
90		if (check_char == 4){bDecimal ? bValid=false : bDecimal=true;}//.
91	}	
92    return bValid;
93}
94/*function IsNumeric(input)
95{
96    return (input - 0) == input && input.length > 0;
97}
98Here's how it works:
99The (input - 0) expression forces JavaScript to do type coercion on your input value; it must first be interpreted as a number for the subtraction operation. If that conversion to a number fails, the expression will result in NaN. This numeric result is then compared to the original value you passed in. Since the left hand side is now numeric, type coercion is again used. Now that the input from both sides was coerced to the same type from the same original value, you would think they should always be the same (always true). However, there's a special rule that says NaN is never equal to NaN, and so a value that can't be converted to a number (and only values that cannot be converted to numbers) will result in false.
100The check on the length is of course for the empty string special case. Also note that it falls down on your 0x89f test, but that's because in many environments that's an okay way to define a number literal. If you want to catch that specific scenario you could add an additional check. Even better, if that's your reason for not using isNaN() then just wrap your own function around isNaN() that can also do the additional check.
101In summary, if you want to know if a value can be converted to a number, actually try to convert it to a number.
102*/
103
104function isValidDate(dateStr) {
105	// Checks for the following valid date formats:
106	// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
107	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year
108
109	var matchArray = dateStr.match(datePat); // is the format ok?
110	if (matchArray == null) {
111		alert(dateStr + " Date is not in a valid format.")
112		return false;
113	}
114	month = matchArray[1]; // parse date into variables
115	day = matchArray[3];
116	year = matchArray[4];
117	if (month < 1 || month > 12) { // check month range
118		alert("Month must be between 1 and 12.");
119		return false;
120	}
121	if (day < 1 || day > 31) {
122		alert("Day must be between 1 and 31.");
123		return false;
124	}
125	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
126		alert("Month "+month+" doesn't have 31 days!")
127		return false;
128	}
129	if (month == 2) { // check for february 29th
130		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
131		if (day>29 || (day==29 && !isleap)) {
132		alert("February " + year + " doesn't have " + day + " days!");
133		return false;
134    }
135    }
136	return true;
137}
138
139function IsValidEmail(szEmail)
140{
141	var bValid = true;
142	var nAtPos = szEmail.indexOf('@');
143
144	if (nAtPos <= 0 || nAtPos >= szEmail.length-4) {bValid =false;}
145	if (szEmail.indexOf('@.') >=  0 || szEmail.indexOf('.@') >=  0) {bValid =false;}
146
147	if (szEmail.charAt(szEmail.length-4) != '.' && szEmail.charAt(szEmail.length-3) != '.') {bValid =false;}
148	
149	return bValid;
150}
151
152function isValidCreditCard(cardNumber, cardType)
153{
154  var isValid = false;
155  var ccCheckRegExp = /[^\d ]/;
156  isValid = !ccCheckRegExp.test(cardNumber);
157
158  if (isValid)
159  {
160    var cardNumbersOnly = cardNumber.replace(/ /g,"");
161    var cardNumberLength = cardNumbersOnly.length;
162    var lengthIsValid = false;
163    var prefixIsValid = false;
164    var prefixRegExp;
165
166    switch(cardType)
167    {
168      case "mastercard":
169        lengthIsValid = (cardNumberLength == 16);
170        prefixRegExp = /^5[1-5]/;
171        break;
172
173      case "visa":
174        lengthIsValid = (cardNumberLength == 16 || cardNumberLength == 13);
175        prefixRegExp = /^4/;
176        break;
177
178      case "amex":
179        lengthIsValid = (cardNumberLength == 15);
180        prefixRegExp = /^3(4|7)/;
181        break;
182
183      default:
184        prefixRegExp = /^$/;
185        alert("Card type not found");
186    }
187
188    prefixIsValid = prefixRegExp.test(cardNumbersOnly);
189    isValid = prefixIsValid && lengthIsValid;
190  }
191
192  if (isValid)
193  {
194    var numberProduct;
195    var numberProductDigitIndex;
196    var checkSumTotal = 0;
197
198    for (digitCounter = cardNumberLength - 1; digitCounter >= 0; digitCounter--)
199    {
200      checkSumTotal += parseInt (cardNumbersOnly.charAt(digitCounter));
201      digitCounter--;
202      numberProduct = String((cardNumbersOnly.charAt(digitCounter) * 2));
203      for(var productDigitCounter = 0;productDigitCounter < numberProduct.length;productDigitCounter++)
204      {
205        checkSumTotal += 
206          parseInt(numberProduct.charAt(productDigitCounter));
207      }
208    }
209
210    isValid = (checkSumTotal % 10 == 0);
211  }
212
213	if(cardNumber=="1111 1111 1111 1111")
214	{
215		isValid = true;
216	}
217		
218  return isValid;
219}
220function insertAtCursor(myField, myValue) { //This is for inserting into Text areas (Report Body and Emailer)
221	//IE support
222	if (document.selection) {
223		myField.focus();
224		sel = document.selection.createRange();
225		sel.text = myValue;
226	}
227	//MOZILLA/NETSCAPE support
228	else if (myField.selectionStart || myField.selectionStart == '0') {
229		var startPos = myField.selectionStart;
230		var endPos = myField.selectionEnd;
231		myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
232		myField.focus(myField.caretPos);
233		//alert(myField.scrollHeight);
234		myField.scrollTop = myField.scrollHeight;
235	}
236	else {
237		myField.value += myValue;
238	}
239}
240function showtip(e,nID){
241	//if (document.readyState=="complete") {
242		var sz = DataStuff["ReportDescription"+nID];
243		if (document.all){
244			var nPagePos = event.clientX+5;
245			if(sz.length > 200) {nPagePos=nPagePos-250; }
246			if(nPagePos < 0) {nPagePos=5; }
247			document.all.DebtorInfo.innerHTML=sz;
248			document.all.DebtorInfo.style.pixelLeft=nPagePos;
249			document.all.DebtorInfo.style.pixelTop=event.clientY+10;
250			document.all.DebtorInfo.style.visibility="visible";
251		}
252		else {
253			var nPagePos = e.pageX+5;
254			if(sz.length > 200) {nPagePos=nPagePos-250; }
255			if(nPagePos < 0) {nPagePos=5; }
256			document.getElementById("DebtorInfo").innerHTML = sz;
257			document.getElementById("DebtorInfo").style.left=nPagePos;
258			document.getElementById("DebtorInfo").style.top=e.pageY+10;
259			document.getElementById("DebtorInfo").style.visibility ="visible";
260		}
261	//}
262}
263
264function hidetip(){
265//	if (document.all) {document.all.DebtorInfo.style.visibility="hidden";}
266	document.getElementById("DebtorInfo").style.visibility ="hidden";
267}
268function ShowPopup(sz, szDivID, bAutoHide) {
269    if (!szDivID) { szDivID = "PopupBox"; };
270    if (bAutoHide === undefined) { bAutoHide = true; };
271    if (szDivID.length <= 0 || !document.getElementById(szDivID)) { szDivID = "PopupBox"; };
272    if (szDivID == "DebtorInfo") { bAutoHide = false; };
273    //if (document.readyState=="complete") {
274
275    nY += 10;
276    if ((nX + 500) > document.body.clientWidth) { nX = document.body.clientWidth - 500 - 50; };
277    if (nX < 0) { nX = 5; }
278
279    if (sz.length > 0) {
280        if (!bAutoHide) {
281            sz = "<DIV width='99%' height=12 align=right style='background-color:#FFFF00;width:99%;align=right;margin:0px;padding:0px;'><a href='JavaScript:HidePopup(\"" + szDivID + "\");'><img src='Graphics/close.gif' border=0 alt='Close' title='Close'></a></DIV><BR><BR>" + sz;
282
283            document.getElementById(szDivID).onmouseout = "";
284        } else {
285            document.getElementById(szDivID).onmouseout = function () {
286                this.innerHTML = '';
287                this.style.visibility = 'hidden';
288                this.visibility = 'hidden';
289            };
290        }
291        //sz+="<BR>nX="+nX+"<BR>nY="+nY+"<BR>document.body.clientWidth="+document.body.clientWidth;
292
293        //if(sz.length > 200) {nX=nX-250; }
294        //if (document.all){document.all(szDivID).innerHTML=sz;  OR document.all.PopupBox.innerHTML=sz;	};
295
296        document.getElementById(szDivID).innerHTML = sz;
297    }
298    if (document.getElementById(szDivID).innerHTML.length > 0) {
299        if (document.all) {
300            //document.all(szDivID).style.pixelLeft=nX+"px";  OR document.all.PopupBox.innerHTML=sz;
301            //document.all(szDivID).style.pixelTop=nY+"px";
302            //document.all(szDivID).style.visibility="visible";
303            //document.getElementById(szDivID).innerHTML+=" -- nX:"+nX+" nY:"+nY;
304            document.getElementById(szDivID).style.pixelLeft = nX + "px";
305            document.getElementById(szDivID).style.pixelTop = nY + "px";
306            document.getElementById(szDivID).style.left = nX + "px";
307            document.getElementById(szDivID).style.top = nY + "px";
308            document.getElementById(szDivID).style.visibility = "visible";
309        }
310        else {
311            document.getElementById(szDivID).style.left = nX + "px";
312            document.getElementById(szDivID).style.top = nY + "px";
313            document.getElementById(szDivID).style.visibility = "visible";
314        }
315    }
316}
317
318function HidePopup(szDivID, bEmptyDIV) {
319    if (bEmptyDIV == undefined) { bEmptyDIV = 1; };
320    if (bEmptyDIV != 0) { bEmptyDIV = 1; };
321
322    //	if (document.all) {document.all.PopupBox.style.visibility="hidden";}
323    if (!szDivID) { szDivID = "PopupBox"; };
324    if (szDivID.length <= 0 || !document.getElementById(szDivID)) { szDivID = "PopupBox"; };
325    if (bEmptyDIV == 1) { document.getElementById(szDivID).innerHTML = ""; };
326    document.getElementById(szDivID).style.visibility = "hidden";
327    document.getElementById(szDivID).visibility = "hidden";
328}
329
330function CleanIntRate(nIntRate) {
331    nIntRate = nIntRate.replace("%", "");
332    nIntRate = nIntRate.replace(",", "");
333    nIntRate = nIntRate.replace("+", "");
334    nIntRate = nIntRate.replace("-", "");
335    nIntRate = nIntRate.replace("(", "");
336    nIntRate = nIntRate.replace(")", "");
337    nIntRate = nIntRate.replace(" ", "");
338    if (!IsNumeric(nIntRate)) { nIntRate = 14.9; };
339    return nIntRate;
340}
341function CleanTax(nTax) {
342    nTax = nTax.replace("%", "");
343    nTax = nTax.replace(",", "");
344    nTax = nTax.replace("+", "");
345    nTax = nTax.replace("-", "");
346    nTax = nTax.replace("(", "");
347    nTax = nTax.replace(")", "");
348    nTax = nTax.replace(" ", "");
349    if (!IsNumeric(nTax)) { nTax = 5; };
350    return nTax;
351}
352
353function CalcPayment(loanAmt, nDownPayment, nIntRate, nAmortization, pay
353Freq, nTax) {
354	// loanAmt, intRate, amortization, payFreq, payAmt
355    //alert("Loan Amt:" + loanAmt);
356    //November 2012 REMOVE GST
357    //formLoan = 1.05 * (parseValue(loanAmt) + 725.98) - nDownPayment;
358    formLoan = (parseValue(loanAmt) + 725.98) - nDownPayment;
359    //alert("Loan Amt (includes GST and Misc Fees minus DownPayment"+formLoan);
360    //TAXES
361    if (nTax == undefined) { nTax = 0; };
362    nTax = CleanTax(nTax);
363    formLoan = formLoan + (formLoan * (nTax / 100));
364
365    loanAmt = parseValue(formLoan);
366    intRate = parseValue(nIntRate) / 100;
367	nNumPayments = nAmortization / payFreq;
368	//alert("Interest Rate:" + intRate + "!");
369	//alert("nAmortization:" + nAmortization + "!");
370    //alert("payFreq:" + payFreq + "!");
371    //alert("# Payments:" + nNumPayments + "!");
372	if (intRate == 0) {
373	    payAmt = loanAmt / nNumPayments;
374	} else {
375	    payAmt = (loanAmt * (intRate * payFreq / 12) * Math.pow((1 + (intRate * payFreq / 12)), nNumPayments)) / (Math.pow((1 + (intRate * payFreq / 12)), nNumPayments) - 1);
376	}
377	//alert("Payment:" + payAmt);
378
379	payAmt = Math.round(payAmt *100) /100
380//		if (goodVersion == true) {
381		if (payAmt.toString() == "NaN") {
382			payAmt = 0
383		}
384//		}
385
386	return payAmt;
387}
388function CalcInterest(loanAmt, nDownPayment, nIntRate, nAmortization, payFreq, nTax) {
389    //November 2012 REMOVE GST
390    //nLoanAmt = parseValue(1.05 * (parseValue(loanAmt) + 725.98) - nDownPayment);
391    nLoanAmt = parseValue((parseValue(loanAmt) + 725.98) - nDownPayment);
392    //alert("nLoanAmt:" + nLoanAmt + "!");
393    //TAXES
394    if (nTax == undefined) { nTax = 0; };
395    nTax = CleanTax(nTax);
396    nLoanAmt = nLoanAmt + (nLoanAmt * (nTax / 100));
397
398    nPayAmt = CalcPayment(loanAmt, nDownPayment, nIntRate, nAmortization, payFreq, nTax);
399    //alert("nPayAmt:" + nPayAmt + "!");
400    nTotalpayments = nPayAmt * (nAmortization / payFreq);
401    //alert("nTotalpayments:" + nTotalpayments + "!");
402    nInterest = nTotalpayments - nLoanAmt;
403    //alert("nInterest:" + nInterest + "!");
404
405    if (nInterest.toString() == "NaN") { nInterest = 0 };
406    nInterest = Math.round(nInterest * 100) / 100
407	return nInterest;
408}
409function CalcSavings(loanAmt, nDownPayment, nIntRate, nAmortization, nAmortization2, payFreq, nTax) {
410
411    nInt = CalcInterest(loanAmt, nDownPayment, nIntRate, nAmortization, payFreq, nTax);
412    nInt2 = CalcInterest(loanAmt, nDownPayment, nIntRate, nAmortization2, payFreq, nTax);
413    //alert("nInterest:" + nInt + "! nInterest2:" + nInt2 + "!");
414    nSavings = nInt2 - nInt;
415	if (nSavings.toString() == "NaN") { nSavings = 0 };
416	nSavings = Math.round(nSavings * 100) / 100
417	return nSavings;
418}
419function parseValue(inputNum) {
420	//return parseInt(inputNum)
421
422	var inStr = inputNum.toString()
423	var outStr = ""
424	for (var i=0;i<inStr.length;i++) {
425		var thisChar = inStr.substring(i,i+1)
426		var thisInt = parseInt(thisChar)
427		//alert(thisChar + " " + thisInt)
428		if (((thisInt >= 0) && (thisInt <= 9) && (thisInt == thisChar)) || thisChar == ".") {
429			outStr = outStr + thisChar
430		}
431	}
432	//alert(outStr)
433	return parseFloat(outStr)
434}
435
436function selectValue(formItem) {
437	selected = formItem.selectedIndex;
438	value = formItem.options[selected].value;
439	return value;
440}

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.