<!--
//	script_common.js contains JavaScript functions used throughout the
//	Orienteering Québec web site.
//	****************************************
//	Version number for tracking changes to script_common.js
	var version="3.0";	//	exploit style sheets and scripts in tools folder
//	****************************************
//	globally establish the calling document's lastModified date
	var lm = new Date(document.lastModified);
	var ludate = formatDate(lm);
//	globally establish the variables for deadlines
	var SECOND = 1000;
	var MINUTE = SECOND * 60;
	var HOUR = MINUTE * 60;
	var DAY = HOUR * 24;
	var WEEK = DAY * 7;
	var MONTH = DAY * 30.4375;
//	based on Danny Goodman's View Source article "JAVASCRIPT DATE OBJECT TECHNIQUES"	
function adjustDate() {
	var base = new Date();
	var testDate = base;
	testDate = testDate.toLocaleString();
	testDate = new Date(testDate);
	DATEADJUSTMENT = testDate.getTime() - base.getTime();
	ZONEERROR = (base.getTimezoneOffset() >= 720) ? DAY : 0;
}
//	****************************************
//	"pageFooter" displays a bottom of page message:
//			- optional request for feedback to the webmaster
//			- Copyright information.
//		If the "updated" parameter is passed,
//			it will also output a standard string
//			of last-modified date and time.
//	Syntax: pageFooter("updated");
//		by David Shapiro 2005-11-22 21:19:04
function pageFooter(updated){
	var copyyear = ludate.substring(0,4);
//	document.write('Please report any problems with this page to the <a href="mailto:webmaster@orienteringquebec.ca?subject=Report on page '+document.location.pathname+'&nbsp;'+ludate+'">webmaster</a>.');
	document.write('Copyright &copy;&nbsp;1996-'+copyyear+'&nbsp;&nbsp;Orientering Qu&eacute;bec.');
	document.write('&nbsp;&nbsp;Tout droits reserv&eacute;s.&nbsp;All rights reserved.');
	if (updated == 'updated') {
		document.write('<br>');
		document.write('<i>Last updated&nbsp;:&nbsp;'+ludate+"</i>");
	}
}
// ****************************************
//	"formatDate" takes a date object and formats it as yyyy-mm-dd hh:mm:ss
//	Syntax: formatDate(date_object);
//		script by Bernhard Friedrich; should work in all browsers
//		adapted by David Shapiro 2000-02-13 10:28:45
function formatDate(a){
	year=a.getYear();year=((year<1000)?((year<70)?2000:1900):0)+year;
	month=a.getMonth()+1;month=((month<10)?'0':'')+month;
	day=a.getDate();day=((day<10)?'0':'')+day;
	hour=a.getHours();hour=((hour<10)?'0':'')+hour;
	minute=a.getMinutes();minute=((minute<10)?'0':'')+minute;
	second=a.getSeconds();second=((second<10)?'0':'')+second;
	var formatted_date = "";
	formatted_date += year+'-'+month+'-'+day+' '+hour+':'+minute+':'+second; 
	return formatted_date;
}
//	****************************************
//	"checkEmail" validates that the Address is a valid email address
//		in the form [recipient.]name@subdomain.domain
//	Syntax: checkEmail(checkAddress);
//	COMPANY:       Netscape Communications
//	AUTHOR:        Robert W. Husted
//	DATE CREATED:  March 17, 1997
//		adapted by David Shapiro 2000-02-29 14:47:54
function checkEmail(checkAddress) {
//	Establish function variables
	var OKrecipient = false;
	var OKdomain = false;
//	Split proposed address at @, if it exists
	atPos = checkAddress.lastIndexOf("@");
	if ((atPos != -1) && (atPos != 0) && (atPos != checkAddress.length)) {
		recipient = checkAddress.substring(0,atPos);
		domain = checkAddress.substring(atPos+1);
//	check that recipient does not begin or end with a dot
		if (!((recipient.indexOf(".") == 0) || (recipient.lastIndexOf(".") == recipient.length-1))) {
//	locate the dot in the proposed domain, if it exists
			dotLast = domain.lastIndexOf(".");
			dotFirst = domain.indexOf(".");
//	and determine that it (they) occupy permitted positions (not first or last)
				if ((dotLast != -1) && (dotLast != 0) && (dotLast != domain.length-1) && (dotFirst != 0)) {
//	Validate recipient part characters
					OKrecipient = isOKchar(recipient);
//	Validate domain part characters
					OKdomain = isOKchar(domain);
				}
		}
	}
	if (OKrecipient && OKdomain) {
		OKemail = true;
	}
	else {
		OKemail = false;
// DISPLAY ERROR MESSAGE
		alert ("Please enter a valid,\n\ncurrent E-mail address,\n\nso that we may communicate.");
	}
	return OKemail;
}
//	****************************************
//	"isOKchar" validates that a string contains only characters acceptable
//		in an Email address. According to IETF RFC822
//		STANDARD FOR THE FORMAT OF ARPA INTERNET TEXT MESSAGES (August 13, 1982)
//		valid characters are any ASCII character (000-127), except:
//			CTL			:	000 through 031, and 127
//			Space		:	032
//			Specials	:	"034 (040 )041 ,044 .046 :058 ;059 
//							<060 >062 @064 [091 \092 ]093
//		However, the .046[dot] is permitted to serve as the separator.
//	Syntax: isOKchar(checkString);
//		by David Shapiro 2000-03-01 15:34:53
function isOKchar(checkString)
{
	var OKchar = true;
	for (var i = 0; i < checkString.length; i++)
	{
		ch = checkString.substring(i, i + 1);	//	if NOT
		if (! ((ch >= "^" && ch <= "~")			//	094 - 126 includes a-z
			|| (ch >= "A" && ch <= "Z")			//	065 - 090
			|| (ch == "?")						//	063
			|| (ch == "=")						//	061
			|| (ch >= "-" && ch <= "9")			//	045 - 057
			|| (ch >= "*" && ch <= "+")			//	042 - 043
			|| (ch >= "#" && ch <= "'")			//	035 - 039
			|| (ch == "!")) )					//	033

		{
			OKchar = false;
			break;
		}
	}
	return OKchar;
}
//	****************************************
//	Get checked value from radio button
function getRadioButtonValue(radio) {
	for (var i = 0; i < radio.length; i++) {
		if (radio[i].checked) {
		break;
		}
	}
	return radio[i].value;
}
// ****************************************	
//	Construct an e-mail call, not easily crawled by web spiders.
//	The 'link' parameter is optional, and will default to the e-mail address.
//	usage: contact('left','right','tld','subj','link')
function contact(left,right,tld,subj,link) {
	text=(link)?link:left+'&#64;'+right+'.'+tld;
	var line='<a href="mailto:'+left+'&#64;'+right+'.'+tld+'?subject='+subj+'">'+text+'<\/a>';
	document.write(line);
}
//	-->
