//  Library of JavaScript functions used on Winetaster Web Site.

function show_update (dt) {
	// Display an UPDATED flag if the specified date
	// is less than a specified number of days old.
	// The second parameter specifies the number of days -
	// the default, if omitted, is 3 weeks.
	// If an extra parameter is specified, it is taken as the
	// alignment - the default is top.

	xtra = 1;
	curdt = new Date()
	cmplen = 21;
	if ((arguments.length > 1)
	        && (typeof(arguments[1]) == "number")) {
	    cmplen = arguments[1];
	    xtra = 2;
	}
	   
	curdt -= (1000 * 24 * 60 * 60) * cmplen
	algn = "top"
	if (arguments.length > xtra)
	   algn = arguments[xtra];
	if (dt > curdt)
		document.write("<IMG SRC='wtupdt.gif' ALT='Updated!' "
				     + "ALIGN='" + algn + "'>");
}

months = ["January", "February", "March", "April", "May", "June",
	  "July", "August", "September", "October", "November",
	  "December"]
days   = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
	  "Friday", "Saturday"];

function show_date (dt) {

	// Display a date in text format
	var yr = dt.getFullYear()
	var day = dt.getDate()
	var mon = dt.getMonth()
	var monnm = months[mon]

	document.write(monnm + " " + day + ", " + yr)
}

WSTmailname = "winetsters"
WSTdomain = "winetasters.ca"
function mailaddr (name, domain) {
	 return name + "@" + domain;
}
function WSTmailaddr () {
	 return mailaddr(WSTmailname, WSTdomain);
}
function Send (name, domain, text) {
	 document.write("<A HREF='mailto:")
	 document.write(mailaddr(name, domain));
	 document.write("'>" + text + "</A>");
}
function WSTmail () {
	 Send(WSTmailname, WSTdomain, "Winetasters Society of Toronto");
}


// Write an arbitrary number of strings of HTML code.  This just
// allows HTML code in the middle of a script.
function html (str) {
	 for (k = 1; k <= arguments.length; ++k)
	     document.write(arguments[k]);

}

// Generate a mailto link combining a name, domain name and text for the link.
function maillink (name, domain, text)
{
	document.write(makeMaillink(name, domain, text));
}

function makeMaillink (name, domain, text)
{
	return "<a href='mailto:" + name + "@" + domain + "'>"
	       + text + "</a>";
}

function makePhoneNo (area, exch, nmbr, ext)
{
	result = "<em class=phone>"
			+ "(" + area + ") " + exch + "-" + nmbr;
	if (arguments.length > 3)
		result += " Ext. " + ext;
	result += "</em>";

	return result;
}

// Generate a phone number from its components.
function phoneNo (area, exch, nmbr, ext)
{
	if (arguments.length > 3)
	   document.write(makePhoneNo(area, exch, nmbr, ext));
	else
	   document.write(makePhoneNo(area, exch, nmbr));
}
