/* ===========================================================================   validate.js	Form validation code for Relationshop Web Site	 jB  F 042905     Source:  Copyright (c) 2005-2007  J. E. Brown  all rights reserved  =========================================================================== */function validate_you_must_answer(element, blankname) {	alert('You must answer the "' + blankname + '" question.'); //	location = '#' + element.name; 	return false }function validate_text(element, blankname) { 	if (element.value == "") 		return validate_you_must_answer(element, blankname) 	else 		return true }function validate_button(element, blankname) { //	for (var i in element) // Doesn't work in Netscape 7 & possibly MSIE 6.0. 	for (var i = 0; i < element.length; ++ i) 		if (element[i].checked) 			return true 	return validate_you_must_answer(element[0], blankname) }function validate_bool(is_true, element, blankname) { 	if (!is_true) 		return validate_you_must_answer(element, blankname) 	else 		return true }// 112208 function validate_email_address(element, blankname) { 	if (!validate_text(element, blankname)) 		return false 	else 		return if_true_else_alert(/^[\w\-\.]+@[A-Za-z0-9][\w\-]*\.[\w\.\-]*[A-Za-z]$/.test(element.value), '"' + element.value + '" is an invalid e-mail address.') }// 041510 function validate_email_addresses(element1, element2, blankname) { 	return	validate_email_address(element1,              blankname) 		 && validate_email_address(element2, 're-type ' + blankname) 		 &&	if_true_else_alert(element1.value == element2.value, blankname + 'es must match.') }// 021207// if_true_else_alert(): Convenience function. Shortens callers dramatically. // Intended usage: return if_true_else_alert(x == y, "x and y do not match") // Use without "if," when return is unconditional. function if_true_else_alert(condition, false_message) {	if (condition) 		return true 	else 		{		alert(false_message); 		return false 		}}// 021207// false_then_alert(): Convenience function. Shortens callers dramatically. // Intended usage: if (false_then_alert(x == y, "x and y do not match")) //						return false // Use after "if," when return is conditional. function false_then_alert(condition, false_message) {	if (!condition) 		alert(false_message); 		return !condition // caller will check this and return iff true }// Validation routines for HMS / DMS input. // 021207 function validate_number_in_range(element, blankname, min, max, may_be_blank) { 	if (element.value == "") 		return if_true_else_alert(may_be_blank, 'You must type a number in the "' + blankname + '" field.'); 		var re = /^-?\d+$/ ; // numerals, optionally preceded by '-' 	if (false_then_alert(re.test(element.value), 'The "' + blankname + '" field must be a whole number.\nRequired characters are 0-9.\nAn optional minus sign is allowed.\nNo other characters are allowed.')) 		return false; 		var	i = parseInt(element.value, 10);		// See if is in range: 	return if_true_else_alert(i >= min && i <= max, 'The "' + blankname + '" field must be between ' + min + ' and ' + max + '.'); }// 021207 function validate_parse_DMS(D, M, S) {	var total = parseInt(D.value, 10); 	var sign  = ( D.value.substr(0, 1) != '-' ? 1 : -1 ); //	var sign  = ( D.value.[0] != '-' ? 1 : -1 ); // fails IE5 		if (M.value != "") 		{		total += sign * parseInt(M.value, 10) / 60; 				if (S.value != "") 			total += sign * parseInt(S.value, 10) / 3600; 		}		return total }// Alert and return false iff the DMS total is even one second out of range. // 021207// Assumes: the D, M, S fields have already been proved numeric or blank. function validate_hms_total_in_range(D, M, S, units, Dmin, Dmax) { 	var total = validate_parse_DMS(D, M, S); 	return if_true_else_alert(Dmin <= total && total <= Dmax, 'The ' + units + ' total (' + total + ') \nis not in the range ' + Dmin + ' to ' + Dmax + '.'); }// 021207 function validate_hms_in_range(D, M, S, units, Dmin, Dmax, M_S_blanks_ok) { 	return (   1			&& validate_number_in_range(D,     units, Dmin, Dmax, false        ) 			&& validate_number_in_range(M, "minutes",    0,   59, M_S_blanks_ok) 			&& validate_number_in_range(S, "seconds",    0,   59, M_S_blanks_ok) 			&& validate_hms_total_in_range(D, M, S, units, Dmin, Dmax) 		   ) }// 112807 var forms_are_working = true; // 120507 function validate_forms_are_working() {//	return if_true_else_alert(forms_are_working, "As explained at the top of this page, forms are not working today, due to the quality problems at America Online."); 	return if_true_else_alert(forms_are_working, "As explained at the top of this page, forms are not working today."); }// 051207 function write_form_status_message() {	if (!forms_are_working) 		{		if (false) // false as of 051307 			document.writeln("<P Style='background-color: white; color: rgb(128,0,0); padding: 1em; font-size: 200%;'>NEWS FLASH: Forms are not working today. On May 11, the company that processes our forms, wwwtoolz.com, suddenly abandoned its customers and went offline. We're looking for a more reliable provider. <BR>Please bookmark this page and try again tomorrow."); 		if (false) // true as of 101407, 102507 			document.writeln("<P Style='background-color: white; color: rgb(128,0,0); padding: 1em; font-size: 200%;'>NEWS FLASH: Due to AOL's incompetence, forms are not working today. <BR>Please do not fill in the form or press Submit; <BR>if you do, your data will disappear off the face of the Earth. <BR>We're looking for a more reliable Internet provider. <BR>Please bookmark this page and try again in 2 days, and remember, <BR> <B>AOL Sucks</B>."); 		if (false) // true as of 120507 			document.writeln("<P Style='background-color: white; color: rgb(128,0,0); padding: 1em; font-size: 200%;'>NEWS FLASH: Due to AOL's incompetence, forms are not working. <BR>Please do not fill in the form or press Submit; <BR>if you do, your data will disappear off the face of the Earth. <BR>We're looking for a more reliable Internet provider. <BR><B>AOL Sucks</B>."); 		if (true) // true as of 100708 			document.writeln("<P Style='background-color: white; color: rgb(128,0,0); padding: 1em; font-size: 200%;'>NEWS FLASH: We just moved the entire website, and forms are not working yet. <BR>Please do not fill in the form or press Submit; <BR>if you do, your data will disappear off the face of the Earth. <BR>Please try again in a few days."); 		}}// 051810. For Decision 051910-F. function write_form_rcvd_thanks_message() {	document.writeln("<P><B>Attention Gmail Users:</B> If you don't receive a reply in 2-3 days, remember to check your Spam folder. <BR> Due to hyperactive spam filters at Gmail, letters from new contacts sometimes get blocked."); }// jB  W 112807, 120507 function how_to_submit_plan_b(	verb, 		// "apply", "submit your data", etc. 	subj, 	emailaddr ) {	if (!forms_are_working) 		document.writeln("<P Style='background-color: white; color: rgb(128,0,0); padding: 1em; font-size: 200%;'>Forms are not working today. You will need to " + verb + " by e-mail. <BR>To " + verb + ", copy this entire page (text only) and paste it into an e-mail, <BR>and then type your answers into the same e-mail. <BR>Please use the subject line \"" + subj + "\". <BR>Send the finished e-mail to: " + emailaddr + " "); }/* ======================================================================== */
