PageSourceSearch

https://secure.medicalletter.org/wp-content/themes/tml/js/account.js

js medicalletter.org collected 2026-10-02 05:41:48 UTC 9,665 bytes, 316 lines download raw bytes

1function toggleAccountState(){
2	if (document.getElementById('accountpopup').style.display != 'block'){
3		document.getElementById("triangle").src="/images/popup_triangle1ah.png";
4		document.getElementById('accountpopup').style.display = 'block';
5		document.getElementById('username').style.color = '#FFF';
6	}
7	else  {
8		document.getElementById("triangle").src="/images/popup_triangle1a.png";
9		document.getElementById('accountpopup').style.display = 'none';
10		document.getElementById('username').style.color = '#FFF';
11	}	 
12}
13
14//Creating a function called PosEnd in JavaScript to place the cursor at the end 
15function posEnd(end) {
16	var len = end.value.length;
17            
18	if (end.setSelectionRange) {
19		end.focus();
20		end.setSelectionRange(len, len);
21	} else if (end.createTextRange) {
22		var t = end.createTextRange();
23		t.collapse(true);
24		t.moveEnd('character', len);
25		t.moveStart('character', len);
26		t.select();
27	}
28}
29
30function toggleSearchState(){
31	if (document.getElementById('nLogin').style.display == 'block' || document.getElementById('nLogin').style.display == ''){
32			document.getElementById('searchpopup').style.display = 'block';
33			document.getElementById('accountpopup').style.display = 'none';
34		document.getElementById('nLogin').style.display = 'none';
35		// document.getElementById('edit-tid').focus();
36		posEnd(document.getElementById('edit-tid'));
37	}
38	else  {
39			document.getElementById('searchpopup').style.display = 'none';
40		document.getElementById('nLogin').style.display = 'block';
41	}	 
42}
43
44
45function showerror(err){
46	$('#messagepanel').html('<div class="messages error"><ul>'+err+'</ul></div>');
47	$("html, body").animate({ scrollTop: 0 }, "slow");
48}
49
50// Customized to use webform structure to provide error indication for required radio and checkboxes
51function validateform(required){
52	var missing = [];
53	var el, pp;
54	$.each(required, function (index, value){
55        el = "[name='submitted["+value+"]']";
56	    if ($(el).length > 1){ // this is radios or checkboxes
57			if (!$(el).is(':checked')){
58				pp = $(el).parents('.form-radios');
59				if (pp.length == 1){
60					$(pp).addClass('error');
61					$(el).on('change', function(){
62						let p = $(this).parents('.form-radios');
63						$(p).removeClass('error');
64						$(this).off("change");
65					});	
66					missing.push(pp);
67				} else {
68					el = "[name='submitted["+value+"][]']";
69					pp = $(el).parents('.form-checkboxes');
70					$(pp).addClass('error');
71					$(el).on('change', function(){
72						let p = $(this).parents('.form-checkboxes');
73						$(p).removeClass('error');
74						$(this).off("change");
75					});
76					missing.push(pp);
77				}
78			}
79		} else if ($(el).val() == ''){
80			$(el).addClass('error');
81			$(el).on('change', function(){
82				$(this).removeClass('error');
83				$(this).off("change");
84			});	
85			missing.push(el);
86		}	
87	});
88	console.log(missing);
89	if (missing.length > 0){
90		var err = '';
91		$.each(missing, function (index, el){
92			let value = $(el).prev('label').text();
93            		let label = value.substr(0, value.indexOf(':'));
94			err += '<li>'+label+' is a required field.</li>';
95		});
96		showerror(err);
97		return false;
98	} else {
99		return true;
100	}	
101}
102
103// Extra validation is achieved by specialized functions for specific Web forms
104function validateform_sltrial(required){
105	var err;
106		if (!validateform(required)) return false;
107		var el = "[name='submitted[number_of_potential_users]']";
108		if (!(parseInt($(el).val()) > 2)){
109			$(el).addClass('error');
110			$(el).on('change', function(){
111				$(this).removeClass('error');
112				$(this).off("change");
113			});
114			err = 'A free trial is only available to organizations that require multi-user access to <b>The Medical Letter</b> content.<br>As you indicated you are a single user, you may view free articles and sample CME activities at <a href="sample-articles">sample articles</a>';
115			showerror(err);
116			return false;
117		}
118		el = "[name='submitted[email]']"; // reusing el
119		var el2 = "[name='submitted[confirm_email]']";
120		if ($(el).val() != $(el2).val()) {
121			$(el).addClass('error');
122			$(el2).addClass('error');
123			$(el).on('change', function(){
124				$(this).removeClass('error');
125				$(this).off("change");
126			});
127			err = 'The email addresses do not match.';
128			showerror(err);
129			return false;
130		}
131		if (!validateEmail($(el).val())){
132			$(el).addClass('error');
133			$(el).on('change', function(){
134				$(this).removeClass('error');
135				$(this).off("change");
136			});
137			err = 'The email address appears to be invalid.';
138			showerror(err);
139			return false;
140		}
141		var email = $(el).val();
142		var start = email.indexOf("@");
143		var domain = email.substr(start+1);
144		if (domain == 'yahoo.com' || domain == 'gmail.com' || domain == 'hotmail.com' || domain == 'aol.com'){
145			$(el).addClass('error');
146			$(el).on('change', function(){
147				$(this).removeClass('error');
148				$(this).off("change");
149			});
150  		        err = 'We cannot accept your request for a trial without a corporate email address. Individuals interested in seeing sample content should go to our <a href="sample-articles">sample articles page</a>';
151			showerror(err);
152			return false;
153
154		}	
155	return true;
156}
157
158// Extra validation is achieved by specialized functions for specific Web forms
159function validateform_slquote(required){
160	var err;
161		if (!validateform(required)) return false;
162		var el = "[name='submitted[number_of_anticipated_users]']";
163		if (!(parseInt($(el).val()) > 2)){
164			$(el).addClass('error');
165			$(el).on('change', function(){
166				$(this).removeClass('error');
167				$(this).off("change");
168			});
169			err = 'A site license is only available to organizations that require multi-user access to <b>The Medical Letter</b> content.';
170			showerror(err);
171			return false;
172		}
173		el = "[name='submitted[email]']";
174		if (!validateEmail($(el).val())){
175			$(el).addClass('error');
176			$(el).on('change', function(){
177				$(this).removeClass('error');
178				$(this).off("change");
179			});
180			err = 'The email address appears to be invalid.';
181			showerror(err);
182			return false;
183		}	
184	return true;
185}
186
187// should just use more general form above but this form uses data array vs submitted
188function datavalidate(required){
189	let missing = [];
190	let el, pp;
191	$.each(required, function (index, value){
192		el = "[name='data["+value+"]']";
193		if ($(el).val() == ''){
194			$(el).addClass('error');
195			$(el).on('change', function(){
196				$(this).removeClass('error');
197				$(this).off("change");
198			});	
199			missing.push(el);
200		}	
201	});
202	if (missing.length > 0){
203		let err = '';
204		$.each(missing, function (index, el){
205			let value = $(el).prev('label').text();
206            let label = value.substr(0, value.indexOf(':'));
207			err += '<li>'+label+' is a required field.</li>';
208		});
209		showerror(err);
210		return false;
211	} else {
212		return true;
213	}	
214}
215
216function validateEmail(inputText){
217	var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
218	if(inputText.match(mailformat)) return true;
219	else return false;
220}
221
222function datavalidate_with_passwords(required){
223	//do validation check
224	if (!datavalidate(required)){
225		//$("html, body").animate({ scrollTop: 0 }, "slow");
226		return false;
227	}
228	if (!validatepasswords()){
229		//$("html, body").animate({ scrollTop: 0 }, "slow");
230		return false;
231	}
232	return true;
233}
234
235function validatepasswords(){
236	var el = "[name='data["+"pass1"+"]']";
237	var el2 = "[name='data["+"pass2"+"]']";
238   
239    if ($(el).val() != $(el2).val()){
240        var err = '<li>Passwords do not match.</li>';
241        $(el).addClass('error');
242		$(el).on('change', function(){
243			$(this).removeClass('error');
244			$(this).off("change");
245		});	
246        $(el2).addClass('error');
247		$(el2).on('change', function(){
248			$(this).removeClass('error');
249			$(this).off("change");
250		});
251	showerror(err);	
252        return err;
253    }
254    return true;
255}
256
257function pwdStrength(password) { // returns 0 to 5
258    let strength = 0
259    if (password.length > 6) strength++;
260    // If password contains both lower and uppercase characters, increase strength value.
261    if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) strength++;
262    // If it has numbers and characters, increase strength value.
263    if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) strength++;
264    // If it has one special character, increase strength value.
265    if (password.match(/([!,%,&,@,#,$,^,*,?,_,~])/)) strength++;
266    // If it has two special characters, increase strength value.
267    if (password.match(/(.*[!,%,&,@,#,$,^,*,?,_,~].*[!,%,&,@,#,$,^,*,?,_,~])/)) strength++;
268    return strength;
269}
270
271function validateform_uri(required){
272	var err;
273	if (!validateform(required)) return false;
274	var el = "[name='submitted[email]']";
275	var el2 = "[name='submitted[email2]']";
276	if ($(el).val() != $(el2).val()) {
277		$(el).addClass('error');
278		$(el2).addClass('error');
279		$(el).on('change', function(){
280			$(this).removeClass('error');
281			$(this).off("change");
282		});
283		err = 'The email addresses do not match.';
284		showerror(err);
285		return false;
286	}
287	if (!validateEmail($(el).val())){
288		$(el).addClass('error');
289		$(el).on('change', function(){
290			$(this).removeClass('error');
291			$(this).off("change");
292		});
293		err = 'The email address appears to be invalid.';	
294		showerror(err);
295		return false;
296	}
297	el = "[name='submitted["+"pass1"+"]']";
298	el2 = "[name='submitted["+"pass2"+"]']";
299    	if ($(el).val() != $(el2).val()){
300        	var err = '<li>Passwords do not match.</li>';
301        	$(el).addClass('error');
302		$(el).on('change', function(){
303			$(this).removeClass('error');
304			$(this).off("change");
305		});	
306        	$(el2).addClass('error');
307		$(el2).on('change', function(){
308			$(this).removeClass('error');
309			$(this).off("change");
310		});
311		showerror(err);	
312        	return false;
313    	}
314	return true;
315}
316

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.