PageSourceSearch

https://roswell-nm.gov/Areas/MyAccount/Assets/Scripts/HomeIndex.js

js roswell-nm.gov collected 2026-10-02 06:20:55 UTC 18,362 bytes, 672 lines download raw bytes

1var fb_busy = false;
2$(document).ready(function () {
3	if ($('#makeToolbarSignInButtonDisappear').val() == 'True') {
4		if ($('#loggedOutToolbarSignInButton')) {
5			$('#loggedOutToolbarSignInButton').hide();
6			$('#signedOutToolbarMoreInformationButtons').hide();
7		}
8	}
9
10	var userName;
11
12	if (document.layers)
13		document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)
14
15	document.onmouseover = hidestatus;
16	document.onmouseout = hidestatus;
17
18	userName = document.getElementById('UserName');
19	if (userName) {
20		if (userName.value == '') {
21			userName.focus();
22		} else {
23			document.getElementById('Password').focus();
24		}
25	}
26
27	if (document.getElementById('fb-root')) {
28		if (typeof (FB) != "undefined") {
29			FB.init({
30				appId: $('#AppID').val(),
31				cookie: true,
32				status: true,
33				oauth: true
34			});
35		}
36		$('.fb-login').click(function (evt) {
37			var from;
38			var url;
39			var anchor;
40			var signInURL;
41
42			if (fb_busy) return;
43			fb_busy = true;
44
45			$('.fb-login').fadeOut(100);
46			$('.loginBox').fadeOut(100);
47			$('#login-fb-waiting-text').delay(100).text('Signing in with Facebook...');
48			$('#login-fb-waiting').delay(100).fadeIn(100);
49
50			try {
51				FB.login(function (response) {
52					if (response.authResponse) {
53						var res = HasAcceptedTerms('/MyAccount/HasAcceptedTermsFacebook?access_token=' 
53+ response.authResponse.accessToken + '&orgName=' + (document.getElementById('Organization') != null ? document.getElementById('Organization').value : ''));
54						if (res.status != 1) {
55							alert(res.msg);
56						} else if (!res.HasAcceptedTerms) {
57							ShowTerms(function () {
58								PerformFacebookSignIn(response.authResponse.accessToken);
59							});
60						} else {
61							PerformFacebookSignIn(response.authResponse.accessToken);
62						}
63					} else {
64						// user is not logged in
65						LoginFailed('Sign in with Facebook cancelled.');
66					}
67				}, {
68					scope: 'email'
69				});
70			} catch (e) {
71
72			}
73		});
74	}
75
76	$('.performSignIn').unbind('click').click(function (e) {
77		performSignIn();
78	});
79
80	$('.forgot').unbind('click').click(function (e) {
81		var $self = $(this);
82		var uniqueID = $self.parents('ol.loginBox').find('.UniqueID').val();
83		var username = $('#UserName' + uniqueID).val();
84		recover(username);
85	});
86});
87
88function PerformFacebookSignIn(accessToken) {
89	// user is logged in and granted permission.
90	signInURL = '/MyAccount/FacebookSignIn?access_token=' + accessToken;
91	from = GetQueryStringParameter('from');
92	var dn = GetQueryStringParameter('dn');
93	if (dn != "") {
94		signInURL = signInURL + '&dn=' + dn;
95	}
96	if (from != "") {
97		url = GetQueryStringParameter('url');
98		anchor = GetQueryStringParameter('anchor');
99		signInURL = signInURL + '&from=' + from + '&url=' + url + '&anchor=' + anchor;
100
101	}
102
103	window.location.href = signInURL;
104}
105
106function LoginFailed(message) {
107	$('#login-fb-waiting-text').fadeOut(250);
108	$('#login-fb-waiting-text').text(message);
109	$('#login-fb-waiting-text').fadeIn(250).delay(2000).fadeOut(250);
110	$('#login-fb-waiting').delay(2250).fadeOut(250);
111	$('.loginBox').delay(2250).fadeIn(250);
112	$('.fb-login').delay(2250).fadeIn(250);
113	fb_busy = false;
114}
115
116function hidestatus() {
117	window.status = ''
118	return true
119}
120
121function performSignIn() {
122	var res = HasAcceptedTerms('/MyAccount/HasAcceptedTerms?userName=' + document.getElementById('UserName').value + '&orgName=' + (document.getElementById('Organization') != null ? document.getElementById('Organization').value : ''));
123	if (res.status != 1) {
124		alert(res.msg);
125	} else if (!res.HasAcceptedTerms) {
126		ShowTerms(function () {
127			if (window.chrome !== null && window.chrome !== undefined && window.navigator.vendor === "Google Inc.") {
128				setTimeout(function () { //issue with chrome where the form submit doesn't respect the form's action. SetTimeout is a workaround.
129					$('#aspnetForm:first').submit();
130				}, 0);
131			} else {
132				$('#aspnetForm:first').submit();
133			}
134
135		});
136	} else {
137		//This call is necessary here since when we do programatic submits, it does not remove the placeholder and the submit handler automatically. Refer to removePlaceHolder() in GlobalJSFunctionDetail.js for detailed comment.
138		removePlaceHolders();
139		setDaysSinceLastLoginCookie();
140		if (window.chrome !== null && window.chrome !== undefined && window.navigator.vendor === "Google Inc.") {
141			setTimeout(function () { //issue with chrome where the form submit doesn't respect the form's action. SetTimeout is a workaround.
142				$('#aspnetForm:first').submit();
143			}, 0);
144		} else {
145			$('#aspnetForm:first').submit();
146		}
147	}
148}
149
150function signInOnEnter(ev) {
151	ev = (window.event ? window.event : ev);
152
153	if (ev.keyCode == 10 || ev.keyCode == 13)
154		performSignIn();
155}
156
157function VerifyUserOnEnter(ev) {
158	ev = (window.event ? window.event : ev);
159
160	if (ev.keyCode == 10 || ev.keyCode == 13)
161		VerifyEditUser();
162}
163
164function VerifyEditUser(isNew) {
165	var alertMsg = "";
166	var errString = 'The form can not be submitted due to the following error(s):\n';
167	errString += "-----------------------------------------------------------------------\n\n";
168	var doSubmit = true;
169
170	txtPassword = TrimString(document.getElementById('Password').value);
171	txtConfirmPassword = TrimString(document.getElementById('ConfirmPassword').value);
172
173	if (FieldIsEmpty(document.getElementById('UserName').value)) {
174		doSubmit = false;
175		alertMsg += "Your email cannot be blank.\n";
176	}
177
178	if (FieldIsEmpty(document.getElementById('FirstName').value)) {
179		doSubmit = false;
180		alertMsg += "Your first name cannot be blank.\n";
181	}
182
183	if (FieldIsEmpty(document.getElementById('LastName').value)) {
184		doSubmit = false;
185		alertMsg += "Your last name cannot be blank.\n";
186	}
187
188	if (txtPassword != txtConfirmPassword) {
189		doSubmit = false;
190		alertMsg += "Passwords do not match.\n";
191	}
192
193	if ((txtPassword.length > 0) && (txtPassword.length < 5)) {
194		doSubmit = false;
195		alertMsg += "Password needs to be 5 characters or longer.\n";
196	}
197
198	if (isNew) {
199		if (FieldIsEmpty(document.getElementById('Password').value)) {
200			doSubmit = false;
201			alertMsg += "Your password cannot be blank.\n";
202		}
203
204		if (!$('#HasAcceptedTerms').is(':checked')) {
205			doSubmit = false;
206			alertMsg += "You must agree to the policies, terms and conditions.\n";
207		}
208	}
209
210	if (alertMsg.length > 0) {
211		errString += alertMsg;
212		errString += "\n-----------------------------------------------------------------------\n";
213		errString += "Please correct them and re-submit.";
214		alert(errString)
215	}
216
217	if (doSubmit) {
218		if (isNew) {
219			performSignIn();
220		} else {
221			document.forms[0].submit();
222		}
223	}
224}
225
226function validateContact(idPrepend) {
227	var alertMessage = "";
228
229	if ($(idPrepend + 'FirstName').val() == '' || $(idPrepend + 'FirstName').val() == 'First Name') {
230		alertMessage += "Please enter a valid first name.\n";
231	}
232
233	if ($(idPrepend + 'LastName').val() == '' || $(idPrepend + 'LastName').val() == 'Last Name') {
234		alertMessage += "Please enter a valid last name.\n";
235	}
236
237	if ($(idPrepend + 'Address1').val() == '' || $(+'Address1').val() == 'Address') {
238		alertMessage += "Please enter a valid address.\n";
239	}
240
241	if ($(idPrepend + 'City').val() == '' || $(idPrepend + 'City').val() == 'City') {
242		alertMessage += "Please enter a valid city.\n";
243	}
244
245	if ($(idPrepend + 'State').val() == '' || $(idPrepend + 'State').val() == 'ST') {
246		alertMessage += "Please enter a valid " + getLowerCaseStateString() + ".\n";
247	} else if (!RegExValidate('^[A-Z]{2}$', $(idPrepend + 'State').val(), 'i') || !RegExValidate('^[a-z]{2}$', $(idPrepend + 'State').val(), 'i')) {
248		alertMessage += "Please enter a valid " + getLowerCaseStateString() + ".\n";
249	}
250
251	if ($(idPrepend + 'PostalCode').val() == '' || (!isZipCode($(idPrepend + 'PostalCode').val(), intCountryCode))) {
252		if (intCountryCode == 840)
253			alertMessage += "Please enter a valid US zip code.\n";
254		else if (intCountryCode == 124)
255			alertMessage += "Please enter a valid Canadian postal code.\n";
256		else
257			alertMessage += "Please enter a valid zip code.\n";
258
259	}
260
261	if ($(idPrepend + 'Phone').val() == '' || !phoneValidate($(idPrepend + 'Phone').val())) {
262		alertMessage += "Please enter a valid phone number.\n";
263	}
264
265	return alertMessage;
266}
267
268function validateRequiredProfile(alertMsgDetail) {
269
270	if (txtCompany != null) {
271		if (txtCompany.value == '') {
272			alertMsgDetail.doSubmit = false;
273			alertMsgDetail.alertMsg += "Your company name cannot be blank.\n";
274		}
275	}
276	if (txtAddress1.value == 'Address' || txtAddress1.value == '') {
277		alertMsgDetail.doSubmit = false;
278		alertMsgDetail.alertMsg += "Please enter Contact address.\n";
279	}
280	if (txtCity.value == 'City' || txtCity.value == '') {
281		alertMsgDetail.doSubmit = false;
282		alertMsgDetail.alertMsg += "Please enter City for contact address.\n";
283	}
284	if (txtState.value == 'ST' || txtState.value == '') {
285		alertMsgDetail.doSubmit = false;
286		alertMsgDetail.alertMsg += "Please enter State for contact address.\n";
287	} else if (!RegExValidate('^[A-Z]{2}$', txtState.value, 'i') || !RegExValidate('^[a-z]{2}$', txtState.value, 'i')) {
288		alertMsgDetail.doSubmit = false;
289		alertMsgDetail.alertMsg += "Please enter a valid State for contact address.\n";
290	}
291	if (txtZip.value == 'Zip' || txtZip.value == '') {
292		alertMsgDetail.doSubmit = false;
293		alertMsgDetail.alertMsg += "Please enter Zip for contact address.\n";
294	} else if (!RegExValidate('^[0-9]{5}$', txtZip.value, 'i')) {
295		alertMsgDetail.doSubmit = false;
296		alertMsgDetail.alertMsg += "Please enter a valid Zip for contact address.\n";
297	}
298
299}
300
301//Get the contact list
302function contactList(contactID) {
303	$.ajax({
304		url: '/MyAccount/ContactList?contactID=' + contactID,
305		type: 'GET',
306		success: function (data) {
307			if (data.RedirectURL)
308				window.location = data.RedirectURL;
309			else {
310				$('#addressesBlock').html(data);
311				$('.section.selfClear').css('display', 'block');
312				// some address blocks were not enhanced by Jquery.Mobile libraries so, solution
313				// seems to be triggering pagecreate event
314				$('#mainProfileCreate').trigger('pagecreate');
315			}
316		},
317		error: function (jqXHR, textStatus, errorThrown) {
318			alert('An error occurred');
319		},
320		beforeSend: function () {
321			ajaxPostBackStart('Loading');
322		},
323		complete: function () {
324			ajaxPostBackEnd();
325		}
326	});
327}
328
329//Removes a contact
330function contactDelete(contactID) {
331	if (confirm('Are you sure you want to delete this address?')) {
332		$.ajax({
333			url: '/MyAccount/ContactDelete?contactID=' + contactID,
334			type: 'GET',
335			success: function (data) {
336				$('#addressesBlock').html(data);
337			},
338			error: function (jqXHR, textStatus, errorThrown) {
339				alert('The address could not be deleted.');
340			},
341			beforeSend: function () {
342				ajaxPostBackStart('Loading');
343			},
344			complete: function () {
345				ajaxPostBackEnd();
346			}
347		});
348	}
349}
350
351//Saves a contact
352function contactSave(contactID, isMobileView, idPrepend, isEdit) {
353
354	isEdit = isEdit || false;
355
356	if (arguments.length == 1 && typeof isMobileView == 'undefined') {
357		isMobileView = false;
358	}
359
360	if (arguments.length >= 1 && arguments.length <= 2 && typeof idPrepend == 'undefined') {
361
362		idPrepend = "";
363	}
364
365	idPrepend = "#" + idPrepend;
366
367	var result = validateContact(idPrepend);
368
369	var firstName = $(idPrepend + 'FirstName');
370	var lastName = $(idPrepend + 'LastName');
371	var address1 = $(idPrepend + 'Address1');
372	var address2 = $(idPrepend + 'Address2');
373	var city = $(idPrepend + 'City');
374	var state = $(idPrepend + 'State');
375	var postalcode = $(idPrepend + 'PostalCode');
376	var phone = $(idPrepend + 'Phone');
377
378	var isDefault;
379
380	if (result == "") {
381		isDefault = firstName.parents('.address').find('.isDefault').is(':checked');
382		var token = $("#addressesBlock input[name='__RequestVerificationToken']").val();
383		$.ajax({
384			url: '/MyAccount/ContactSave',
385			contentType: 'application/x-www-form-urlencoded',
386			type: 'POST',
387			dataType: 'json',
388			data: {
389				__RequestVerificationToken: token,
390				ContactID: contactID,
391				FirstName: firstName.val(),
392				LastName: lastName.val(),
393				Address1: address1.val(),
394				Address2: address2.val(),
395				City: city.val(),
396				State: state.val(),
397				PostalCode: postalcode.val(),
398				Phone: phone.val(),
399				IsDefault: isDefault
400			},
401			success: function (data) {
402				if (data != null && data != undefined && data.RedirectURL) {
403					window.location = data.RedirectURL;
404				} else {
405
406					//var obj = jQuery.parseJSON(data);
407					if (data.Successful == false) {
408
409						alert(data.ErrorMessage);
410						return false;
411
412					} else {
413
414						contactList(0);
415					}
416
417				}
418			},
419			error: function (jqXHR, textStatus, errorThrown) {
420				alert('The address could not be saved.');
421			},
422			beforeSend: function () {
423				ajaxPostBackStart('Loading');
424			},
425			complete: function () {
426				ajaxPostBackEnd();
427			}
428		});
429	} else {
430		alert(result);
431
432		if (isMobileView) return false;
433	}
434
435
436	if (isMobileView && !isEdit) {
437
438		firstName.val("");
439		lastName.val("");
440		address1.val("");
441		address2.val("");
442		city.val("");
443		//state = ...
444		postalcode.val("");
445		phone.val("");
446
447		return true;
448	}
449
450}
451
452//Changes the default address on myaccount screen.
453function changeDefaultContact(checkBox, contactID) {
454	if (contactID == 0) {
455		setDefaultContact(checkBox);
456	} else {
457		$.ajax({
458			url: '/MyAccount/ContactSetDefault?contactID=' + contactID,
459			type: 'GET',
460			success: function (data) {
461				setDefaultContact(checkBox);
462			},
463			error: function (jqXHR, textStatus, errorThrown) {
464				alert('The default address could not be changed.');
465			},
466			beforeSend: function () {
467				ajaxPostBackStart('Loading');
468			},
469			complete: function () {
470				ajaxPostBackEnd();
471			}
472		});
473	}
474}
475
476//Changes the default address on myaccount screen.
477function changeDefaultContactMobile(contactID) {
478
479	$.ajax({
480		url: '/MyAccount/ContactSetDefault?contactID=' + contactID,
481		type: 'GET',
482		success: function (data) {
483
484		},
485		error: function (jqXHR, textStatus, errorThrown) {
486			alert('The default address could not be changed.');
487		},
488		beforeSend: function () {
489			ajaxPostBackStart('Loading');
490		},
491		complete: function () {
492			ajaxPostBackEnd();
493		}
494	});
495
496}
497
498function setDefaultContact(checkBox) {
499	var $addressBlock;
500	$('.address input[type=checkbox]').each(function () {
501		this.checked = false;
502		this.disabled = false;
503	});
504
505	checkBox.checked = true;
506	checkBox.disabled = true;
507
508	$('.address.active').removeClass('active');
509	$addressBlock = $(checkBox).parents('.address');
510	$addressBlock.addClass('active');
511}
512
513function recover(username) {
514	var responseFN = function (ajaxRequest) {
515		alert(ajaxRequest);
516	}
517
518	makeHttpRequestEx('/Services/ForgotPassword.ashx?Username=' +
519        encodeURIComponent(username) + '&set=admin', null, responseFN, false);
520}
521
522function SetPhotoMobile(photoType, createProfile) {
523	SetPhoto(photoType, createProfile);
524}
525
526
527function SetPhoto(photoType, createProfile) {
528	if (createProfile.toLowerCase() == 'true') {
529		$.post('/MyAccount/CreateProfilePhoto?photoType=' + photoType, function (response) {
530			$('.photo.fbPhoto').html(response);
531			switch (photoType) {
532				case 0:
533					$('#SetRemovePhoto').val('False');
534					break;
535				case 1:
536					$('#SetRemovePhoto').val('False');
537					break;
538				case 2:
539					$('#SetRemovePhoto').val('True');
540					break;
541			}
542		});
543	} else {
544		$.post('/MyAccount/ProfilePhoto?photoType=' + photoType, function (response) {
545			if (response.RedirectURL)
546				window.location.href = response.RedirectURL;
547			else {
548				$('.photo.fbPhoto').html(response);
549				switch (photoType) {
550					case 0:
551						$('#SetRemovePhoto').val('False');
552						break;
553					case 1:
554						$('#SetRemovePhoto').val('False');
555						break;
556					case 2:
557						$('#SetRemovePhoto').val('True');
558						break;
559				}
560			}
561		});
562	}
563}
564
565function HasAcceptedTerms(url) {
566
567	var result = {
568		status: 1,
569		HasAcceptedTerms: true
570	};
571	if ($('#HasAcceptedTerms').is(':checked')) {
572		return result;
573	}
574
575	$.ajax({
576		url: location.origin + url,
577		type: 'POST',
578		async: false,
579		dataType: 'json',
580		success: function (data) {
581			result = data;
582		},
583		error: function (jqXHR, textStatus, errorThrown) {
584			result = {
585				status: 0,
586				msg: 'Error encountered while checking terms acceptance.'
587			};
588		}
589	});
590
591	return result;
592}
593
594function openCpModalMobile(options) {
595
596	var msg;
597	var title = options.title;
598
599	$.ajax({
600		url: options.url,
601		type: 'GET',
602		async: false,
603		cache: false,
604		success: function (result) {
605			msg = result;
606		},
607		error: function (xhr, textStatus, exception) {
608			alert('Error encountered while loading modal.');
609		}
610	});
611
612	$('#popupBasic .header').html(title);
613	$('#popupBasic .content').html(msg);
614	$("#popupBasic").popup('open', {
615		positionTo: 'window',
616		overlayTheme: 'a'
617	});
618}
619
620function ShowTerms(onAccept) {
621
622	if ($('#IsMobile').val() == 'True') {
623
624		openCpModalMobile({
625			title: 'Our Terms Have Changed',
626			className: 'legalUpdate',
627			isFrontEnd: true,
628			url: '/MyAccount/Terms'
629		});
630
631		$('.legalUpdate .button.accept').click(onAccept);
632		$('.legalUpdate .button.cancel').click(DoNotAcceptMobile);
633
634	} else {
635
636		openCpModal({
637			title: 'Our Privacy Policy/Terms and Conditions Have Changed',
638			className: 'legalUpdate',
639			isFrontEnd: true,
640			url: '/MyAccount/Terms'
641		});
642
643		$('.legalUpdate .button.accept').click(onAccept);
644		$('.legalUpdate .modalClose').click(DoNotAccept);
645	}
646}
647
648
649function DoNotAccept() {
650	$('#login-fb-waiting-text').hide();
651	$('#login-fb-waiting').hide();
652	$('.loginBox').show();
653	$('.fb-login').show();
654	fb_busy = false;
655	closeCpModal();
656
657	return false;
658}
659
660function DoNotAcceptMobile() {
661
662	window.location = '/MyAccount';
663
664}
665
666// Returns TRUE if the password and confirm password field match.
667function passwordFieldsMatch() {
668	// NOTE: e_5 and e_6 are hard-coded IDs
669	var passwordField = $('#e_5');
670	var confirmPasswordField = $('#e_6');
671	return passwordField.val() == confirmPasswordField.val();
672}

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.