var events, thisMonth, thisYear, thisDate, beginMonth, meeting, pic01, pic02, pic03;
//	Slideshow
var imagefile;
var msg = "";
var slidecount = 0;

//var testDate="Dec 1, 2006";		//	Put testDate in each location where new Date() exists for testing
var today 	= new Date();
today.setHours(0,0,0,0);
thisYear 	= today.getFullYear();
thisMonth 	= today.getMonth();
thisDate	= today.getDate();

var index = "m" + thisMonth;

/*  Get page id from a var set on the page
var page 	= window.location.pathname;

var iPos 	= page.lastIndexOf('\\');	//	IE6 looks like this: /C:\dir\dir\dir  while IE7 & Firefox look like this:  /C:/dir/dir  So if the LAST index is -1, it is IE7 or Firefox
if (iPos == -1) iPos = page.lastIndexOf('/');


page		= page.substring(iPos+1);
iPos		= page.indexOf('.htm');
page		= page.substring(0,iPos);

*/

var deep 	= document.getElementsByTagName('link')[0].getAttribute("href");
iPos		= deep.lastIndexOf("../");
if (iPos != -1) {
	deep = deep.substring(0,iPos+3);
} else {
	deep = "";
}


function action()  {
	//  Show banner on page based on current month
	document.getElementById('banner').src=deep + "images/banner" + thisMonth + ".jpg";


	//  Show Random Pics
	getRandomPics();




	/*	Show swim team submenu
	if (window.location.pathname.indexOf('swimteam') != -1)  {
		try {
		    document.getElementById('gator').style.display = "block";
		} catch(e) {alert('Error in activating the Gator menu')};
	}
	
	*/
	
	
	
	/*	Show special notice on swim team schedule page
	if (page == 'schedule')  {
		var ScheduleTitle = document.getElementById('wideColumn').getElementsByTagName('h2')[0].firstChild.nodeValue;
		if (ScheduleTitle.indexOf(thisYear) == -1 ) {
			try {
				document.getElementById('SpecialNotice').style.display = "block";
			} catch(e) {alert("Error in activivating the special notice on the swim team page")}
			try {
				document.getElementById('wideColumn').getElementsByTagName('h2')[0].style.display="none";
			} catch(e) {alert("Error in hiding the out of date title on the swim team page")}

		}
	}

*/



	//	Thumbnail pages - number of pics stored as page variable
	if (window.location.pathname.indexOf('pics') != -1)  {
		var numCols = 4;
		var j;
		var html = '<table cellspacing="18">';
		if (numPics == 0) {
			html = "<b>There are no pictures available right now</b>";
		} else {
			for (var i=0;i<numPics;i++) {
				if (i%numCols == 0) html = html + '<tr>';
				j = i+1;
				if (j < 10) j = '0' + j;
				html = html + '<td><a href="pic' + j + '.jpg"><img src="tpic' + j + '.jpg"></a></td>';
				if (i%numCols == (numCols - 1)) html = html + '</tr>';
			}
			if (i%numCols != (numCols - 1)) html = html + '</tr>';
			html = html + '</table>';
		}
		try {
			document.getElementById('thumbnails').innerHTML = html;
		} catch(e) {alert('Error in creating thumbnail page')}
	}
}


// Random Pics
function getRandomPics()  {
	var narrowPics=3, regPics=6;
	if (deep=="") regPics=9;
	var str = document.getElementsByTagName('title').item(0).text;
	if (str.search('Book Club') != -1) regPics=10;  // npics not used; book used instead

	pic01  = 'images/pic'  + (1 + Math.floor(Math.random()*regPics)) + '.jpg';
	pic03  = 'images/pic'  + (1 + Math.floor(Math.random()*regPics)) + '.jpg';
	pic02  = 'images/npic' + (1 + Math.floor(Math.random()*narrowPics)) + '.jpg';
	if (pic03 == pic01) {
		getRandomPics();
	} else {

		try {
			if (deep > "") {		// Home page has a slide show in pic01 position, so don't process pic01
				if (document.getElementById('firstPic').src == "")  {
					document.getElementById('firstPic').src = pic01;
				}
			}
			if (document.getElementById('pic3').firstChild.src == "")  {
				document.getElementById('pic3').firstChild.src = pic03;
			}
  
			if (document.getElementById('pic2').firstChild.src == "")  {
				document.getElementById('pic2').firstChild.src = pic02;
			}
			
		} catch(e) {}
	}
	return;
}



	
function getData(element,i) {
	var myElement	= events[i].getElementsByTagName(element);
	try {
		if(! myElement[0].firstChild) {			
			myElement = "";
		} else {
			myElement = myElement[0].firstChild.data;
		}
	} catch(e) {alert('Error in event number ' + (i+1) + '.  Appears to be missing the ' + element + ' element')};
	return myElement;
}

function calMonth(month)  {
	switch (month) {
		case 0 :
			return 'Jan. ';
			break;
		case 1 :
			return 'Feb. ';
			break;
		case 2 :
			return 'Mar. ';
			break;
		case 3 :
			return 'Apr. ';
			break;
		case 4 :
			return 'May. ';
			break;
		case 5 :
			return 'Jun. ';
			break;
		case 6 :
			return 'Jul. ';
			break;
		case 7 :
			return 'Aug. ';
			break;
		case 8 :
			return 'Sep. ';
			break;
		case 9 :
			return 'Oct. ';
			break;
		case 10 :
			return 'Nov. ';
			break;
		case 11 :
			return 'Dec. ';
			break;
		case 12 :
			return 'Jan. ';
			break;
	}	
}

function FP_xmlview(oFrame,sXML,sErr){
	var oXml,oTarget=oFrame.parentNode,sHtml,oDoc=document,/*ie*/sMXSML="Microsoft.XMLDOM",/*moz*/oImp=oDoc.implementation,oXslProc,oXform,oXmlSer; 
		

	if(!XformInIE()&&!XformInMoz())  {
		oTarget.innerHtml=oTarget;
	}
	
	function OnMozXmlDocLoaded(e)  {
		sHtml=ProcessXml(oXml);
//		oXmlSer=new XMLSerializer();
//		sHtml=oXmlSer.serializeToString(sHtml);
		oTarget.innerHTML=sHtml; 	
	}
	
	function XformInIE()  { 
		if(!document.all)  {
			return false;
		} 
		try  {
			oXml=new ActiveXObject(sMXSML);
		} 
		catch(e)  {
			return false;
		} 
		
		if(oXml)  { 
			oXml.async=false;
			oXml.load(sXML); 
			sHtml=ProcessXml(oXml);
			oTarget.innerHTML=sHtml;
			return true; 
		} 
		return false; 
	}
			
	function XformInMoz()  { 
		if(oImp&&oImp.createDocument)  { 
			try  {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); 
			}
			catch(e)  {
				;
			}
			oXml=oImp.createDocument("","t1",null); 
			oXml.addEventListener("load",OnMozXmlDocLoaded,false);
			oXml.load(sXML); 
			return true; 
		} 
		return false; 
	}	
	
}	

// ADDITIONAL USEFUL STRING FUNCTIONS

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

String.prototype.ltrim = function() {
	return this.replace(/^\s+/g,"");
}

String.prototype.rtrim = function() {
	return this.replace(/\s+$/g,"");
}
