/*
This file contains Javascript code for use on the Sunset HOG website.
*/
// This function builds an email address and a mailto: link out of the given
// parameters so that email addresses don't need to be embedded within the
// web pages. This will stop spam harvesters from getting these email addresses.
function makeAddress(name,domain,TLD,subject,body) {
	var address = name + "@" + domain + ".";
	if (TLD == "c") address = address + "com";
	if (TLD == "n") address = address + "net";
	if (TLD == "o") address = address + "org";
	if (body == undefined) {
		body = "";
	} else {
		body = "&body=" + body;
	}
	return "mailto:" + address + "?subject=" + subject + body;
}
function makeAddressCC(name,domain,TLD,nameCC,domainCC,TLDCC,subject,body) {
	var address = name + "@" + domain + ".";
	var addressCC = nameCC + "@" + domainCC + ".";
	if (TLD == "c") address = address + "com";
	if (TLD == "n") address = address + "net";
	if (TLD == "o") address = address + "org";
	if (TLDCC == "c") addressCC = addressCC + "com";
	if (TLDCC == "n") addressCC = addressCC + "net";
	if (TLDCC == "o") addressCC = addressCC + "org";
	if (body == undefined) {
		body = "";
	} else {
		body = "&body=" + body;
	}
	return "mailto:" + address + "?cc=" + addressCC + "&subject=" + subject + body;
}

// This function assembles and displays a scrambled phone number.
function makePhone(area,prefix,number) {
	return "(" + area + ") " + prefix + "-" + number;
}

//Create a new text string with today's date in the form "Friday, November 5, 2004"
function todayText() {
	var today = new Date();
	var monthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	var dayNames = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
	var Month = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";
	return dayNames[today.getDay()] + ", " + monthNames[today.getMonth()] + " " + today.getDate() + ", " + today.getFullYear();
	}

// This function returns text that is descriptive of when an event is going to occur.
function when(myDateString) {
		var myDate = new Date(myDateString);
		var today = new Date();
		today.setHours(0);
		today.setMinutes(0);
		today.setSeconds(0);
		var dateDiff = (today - myDate)/1000/3600/24;
		if (dateDiff > 3.5) return "has already happened";
		if (dateDiff > 1.5 && dateDiff < 3.5) return "happened a few days ago";
		if (dateDiff > .5 && dateDiff < 1.5) return "was yesterday";
		if (dateDiff > -.5 && dateDiff < .5) return "is today";
		if (dateDiff > -1.5 && dateDiff < -.5) return "is tomorrow";
		if (dateDiff > -2.5 && dateDiff < -1.5) return "is the day after tomorrow";
		if (dateDiff > -4.5 && dateDiff < -2.5) return "is in a few days";
		return "is soon";
}

// Set a cookie
function setCookie(cookieName, cookieValue, days) {
	var expDate = "";
	if (days > 0) {
		var exp = new Date();
		var nowPlusDays = exp.getTime() + (days*24*60*60*1000);
		exp.setTime(nowPlusDays);
		expDate = " expires=" + exp.toGMTString();
		}
	document.cookie = cookieName + "=" + cookieValue + "; path=/;" + expDate;
	}

//Get all of the cookies for this site in the present path
function getCookies() {
	return escape(document.cookie);
	}

