/************************************************************************
 * Title:	E-mail hider						*
 * Creator:	Michael Bennett						*
 * Description:	This function scans the page when it is opened and	*
 *		converts properly formatted strings to clickable email	*
 *		links.  Because this happens in JavaScript, most bots 	*
 *		can only read the original, meaningless script.		*
 * Pre:		The document contains emails designated by id="email". 	*
 *		It applies the span's class to the email and uses the	*
 *		title (if present) as the visible text.  Text within	*
 *		the span must be in the format username 'AT domain DOT	*
 *		topdomain.'						*
 * Post:	All spans marked with the id "email" are converted to	*
 *		clickable links.					*
 ************************************************************************/
function betterHider()
{
	while ( document.getElementById('email') )
	{
		//Access the span we're going to be changing
		var emailToHide = document.getElementById('email');
		
		//Initialize the new output
		var finalOutput = "";
		
		//Access the interior of the span we're changing
		var info = emailToHide.innerHTML;
		
		//Set up the array with blanks for the new info
		var newInfo = new Array("", "", "", "");
		
		//Get the user information out of 'info'; it ends just before AT
		newInfo[0] = info.substring(0, (info.indexOf('AT')-1));
				
		//Get the domain information out of 'info'; we'll have to do some operations on it, because of the DOTs in it
		var domain = info.substring(info.indexOf("AT")+3);
		//As long as there's a 'DOT' in the domain, keep replacing it with '.'
		while (domain.indexOf('DOT') != -1)
		{
			domain = domain.substring(0,domain.indexOf('DOT')-1)+"."+domain.substring(domain.indexOf('DOT')+4);
		}
		newInfo[1] = domain;
		
		//Get the class information (same class that 'span' has)
		newInfo[2] = emailToHide.className;
		
		//Get the 'to show' information ('span's title)
		newInfo[3] = emailToHide.title;
		//This prevents us from the redundant case of having the title repeat the displayed text
		emailToHide.title = "";
		
		//This is the new link, and may also be the displayed text, if there was no SHOW specified
		var recreateEmail = newInfo[0]+'@'+newInfo[1];
		
		//If there was no SHOW specified, copy the link into the SHOW section of the array
		if ( newInfo[3] == "" )
		{
			newInfo[3] = recreateEmail;
		}
		
		//Check to see if a class was specified
		if ( newInfo[2] == "" )
		{
			//If no class specified, leave it blank
			finalOutput = '<a href="mailto:'+recreateEmail+'">'+newInfo[3]+'</a>';
		}
		else
		{
			//If a class was specified, put it in
			finalOutput = '<a class="'+newInfo[2]+'" href="mailto:'+recreateEmail+'">'+newInfo[3]+'</a>';
		}
		
		//Change the displayed HTML so it has the clickable link
		emailToHide.innerHTML = finalOutput;
		
		//Change the ID so the code won't endlessly 'fix' this one email
		emailToHide.id = "emailShown";
	}
}


/***********************************************
* Basic Calendar-By Brian Gosselin at http://scriptasylum.com/bgaudiodr/
* Script featured on Dynamic Drive (http://www.dynamicdrive.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function buildCal(m, y, cM, cH, cDW, cD, brdr)
{
	var mn=['January','February','March','April','May','June','July','August','September','October','November','December'];
	var dim=[31,0,31,30,31,30,31,31,30,31,30,31];
	var oD = new Date(y, m-1, 1); //DD replaced line to fix date bug when current day is 31st
	oD.od=oD.getDay()+1; //DD replaced line to fix date bug when current day is 31st
	var todaydate = new Date(); //DD added
	var scanfortoday = ( y == todaydate.getFullYear() && m == todaydate.getMonth() + 1 ) ? todaydate.getDate() : 0; //DD added
	dim[1]= ( ( ( oD.getFullYear() % 100 != 0 ) && ( oD.getFullYear() % 4 == 0 ) ) || ( oD.getFullYear() % 400 == 0 ) ) ? 29 : 28;
	var t = '<div class="' + cM + '"><table class="' + cM + '" cols="7" cellpadding="0" border="' + brdr + '" cellspacing="0"><tr align="center">';
	t += '<td colspan="7" align="center" class="' + cH + '">' + mn[m-1] + ' - ' + y + '</td></tr><tr align="center">';
	for ( s = 0 ; s < 7 ; s++ )
	{
		t += '<td class="' + cDW + '">' + "SMTWTFS".substr(s,1) + '</td>';
	}
	t += '</tr><tr align="center">';
	for ( i = 1 ; i <= 42 ; i++ )
	{
		var x = ( ( i - oD.od >= 0 ) && ( i - oD.od < dim[m-1] ) ) ? i - oD.od + 1 : '&nbsp;';
		if ( x == scanfortoday ) //DD added
		{
			x = '<span id="today">' + x + '</span>'; //DD added
		}
		t += '<td class="' + cD + '">' + x + '</td>';
		if ( ( ( i ) % 7 == 0 ) && ( i < 36 ) )
		{
			t += '</tr><tr align="center">';
		}
	}
	return t += '</tr></table></div>';
}

/************************************************************************
 *Multiple onload							*
 *Creator: Simon Willison						*
 ************************************************************************/
function addLoadEvent( func )
{
	var oldonload = window.onload;
	if ( typeof window.onload != 'function' )
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			if (oldonload)
			{
				oldonload();
			}
			func();
		}
	}
}

addLoadEvent(function()
{
	// truncate();
	betterHider();
	if ( calendarVeryYes )
	{
		changedate('return');
	}
});