//#####################################################
// Common Functions
//#####################################################

// General Variables

	var pageWidth = '800';
	var churchList = new Array('Claverham', 'Cleeve', 'Kenn', 'Kingston Seymour', 'Yatton');
	var dayofWeek = new Array('SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT');
	var dayofWeekLong = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
	var shortMonth = new Array('JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUNE', 'JULY', 'AUG', 'SEPT', 'OCT', 'NOV', 'DEC');
	var longMonth = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

// Date Variables

	var currentTime = new Date();
	var curDay = currentTime.getDay() + 1;
	var curDate = currentTime.getDate();
	var curMonth = currentTime.getMonth() + 1;
	var curYear = currentTime.getFullYear();
	var curYMD = (curYear*10000)+(curMonth*100)+curDate;
	var curYM = (curYear*100)+curMonth;
	var thisYM = 0;
	var thisMonth = '';

//------------------------------------------------------------------------------------------------------------
//- GENERAL FUNCTIONS ----------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
function replaceAll(inString, regex, replacement) 
{
	var strIndex = 0;
	var returnString = inString;
	var repeatReplace = 1;
  	while (repeatReplace == 1) {
  		strIndex = returnString.indexOf(' ');
  		if (strIndex >= 0) {
 			returnString = returnString.replace(regex, replacement);
   		} 
   		else {
   			repeatReplace = 0;
   		}
  	}
	return returnString;
}
//------------------------------------------------------------------------------------------------------------
function getRandomNumber(vTo)
{
	var ran_number=Math.floor(Math.random()*vTo); 
	return ran_number;
}
//------------------------------------------------------------------------------------------------------------
function getBrowser()
{
	var detect = navigator.userAgent.toLowerCase();
	var browser = '';
	if (browserCheck('konqueror', detect)) {browser = "Konqueror";}
	else if (browserCheck('safari', detect)) {browser = "Safari";}
	else if (browserCheck('omniweb', detect)) {browser = "OmniWeb";}
	else if (browserCheck('opera', detect)) {browser = "Opera";}
	else if (browserCheck('webtv', detect)) {browser = "WebTV";}
	else if (browserCheck('icab', detect)) {browser = "iCab";}
	else if (browserCheck('msie', detect)) {browser = "msie";}
	else if (!browserCheck('compatible', detect)) {browser = "compatible";}
	else {browser = "unknown";}
	return browser;
}
//------------------------------------------------------------------------------------------------------------
function browserCheck(string, detect)
{
	var place = detect.indexOf(string) + 1;
	return place;
}

//------------------------------------------------------------------------------------------------------------
//- DATE FUNCTIONS -------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
function extractDate(inDate, inComponent, inType)
{
	var returnValue;
	var cInDate = inDate.substring(6,8);
	var cInMonth = inDate.substring(4,6);
	var cInYear = inDate.substring(0,4);
	
	if (inComponent == "date") {
		if (inType == 'nbr') returnValue = Number(cInDate);
		else returnValue = cInDate;
	}
	else if (inComponent == "month") {
		if (inType == 'nbr') returnValue = Number(cInMonth);
		else returnValue = cInMonth;
	}
	else if (inComponent == "year") {
		if (inType == 'nbr') returnValue = Number(cInYear);
		else returnValue = cInYear;
	}
	else if (inComponent == "day") {
		var inFullDate = new Date();
		var nInMonth = cInMonth-1;
		inFullDate.setFullYear(cInYear);
//		inFullDate.setDate(cInDate);
		inFullDate.setMonth(nInMonth,cInDate);
		var cInDay = inFullDate.getDay();
		if (inType == 'nbr') returnValue = Number(cInDay)+1;
		else returnValue = cInDay;
	}
	return returnValue;
}
//------------------------------------------------------------------------------------------------------------
function setThisYM(inYM)
{
	thisYM = inYM
}
//------------------------------------------------------------------------------------------------------------
function getThisYM()
{
	return thisYM;
}
//------------------------------------------------------------------------------------------------------------
function getCurYMD()
{
	return curYMD;
}
//------------------------------------------------------------------------------------------------------------
function setThisMonth(inMonth)
{
	thisMonth = inMonth;
}
//------------------------------------------------------------------------------------------------------------
function getThisMonth()
{
	return thisMonth;
}
//------------------------------------------------------------------------------------------------------------
function isTodayInRange(fromYMD, toYMD)
{
	var returnValue = 0;
	if ((curYMD >= fromYMD) && (curYMD <= toYMD)) returnValue = 1;
	else returnValue = 0;
	return returnValue;
}
//------------------------------------------------------------------------------------------------------------
function isTodaygeYMD(inYMD)
{
	var returnValue = 0;
	if (curYMD >= inYMD) returnValue = 1;
	else returnValue = 0;
	return returnValue;
}
//------------------------------------------------------------------------------------------------------------
function isYMDgeToday(inYMD)
{
	var returnValue = 0;
	if (inYMD >= curYMD) returnValue = 1;
	else returnValue = 0;
	return returnValue;
}
//------------------------------------------------------------------------------------------------------------
function isYMgeToday(inYM)
{
	var returnValue = 0;
	if (inYM >= curYM) returnValue = 1;
	else returnValue = 0;
	return returnValue;
}

//------------------------------------------------------------------------------------------------------------
//- COMMON PAGE FUNCTIONS ------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
function loadCommon()
{
	loadContactInformation();
}
//------------------------------------------------------------------------------------------------------------
function writeEmailFooter(vPrefix)
{
	var htmlString = '&nbsp;<A href="mailto:'+email+'"><IMG border="0" " alt="EMAIL US" src="'+vPrefix+'images/general/bubble004ic.gif" width="31" height="30"></A>';
	document.write(htmlString);
}

//------------------------------------------------------------------------------------------------------------
//- GETTERS/SETTERS ------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
function getPageWidth()
{
	return pageWidth;
}
//------------------------------------------------------------------------------------------------------------
function getDayOfWeek(index, length)
{
	index = parseInt(index);
	if (length == "short") {
		return dayofWeek[index];
	}
	else {
		return dayofWeekLong[index];
	}
}
//------------------------------------------------------------------------------------------------------------
function getShortMonth(index)
{
	index = parseInt(index);
	return shortMonth[index];
}
//------------------------------------------------------------------------------------------------------------
function getLongMonth(index)
{
	index = parseInt(index);
	return longMonth[index];
}
//------------------------------------------------------------------------------------------------------------
function getChurchName(index)
{
	return churchList[index];
}

//------------------------------------------------------------------------------------------------------------
function isLeapYear(vYear)
{
	vYear = parseInt(vYear);
	if (vYear%4 == 0) {
		if (vYear%100 != 0) return true;
		else {
			if (vYear%400 == 0) return true;
			else return false;
		}
	}
	return false;
}

//------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------