/* ================================================================ 
Scripts available to use throughout the website of
Covenant Love Church (www.covenantlovechurch.org)
=================================================================== */

/* ================================================================ 
Display email in a way to protect from spam harvesting
=================================================================== */

function printclcon (name,dname,display) {
	if (dname == '') {
		document.write("<a href=\"mailto:" + name + "&#64;" + "covenantlovechurch.org\">" + display + "</a>");
	} else {
		document.write("<a href=\"mailto:" + name + "&#64;" + "covenantlovechurch.org\">" + dname + "&#64;" + "covenantlovechurch.org</a>");
	}
}


/* ================================================================ 
Date-generating or date-checking scripts
=================================================================== */

function todaysdate () {
	var d_names = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
	var m_names = new Array("Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec");
	var d = new Date();
	var curr_day = d.getDay();
	var curr_date = d.getDate();
	var curr_month = d.getMonth();
	var curr_year = d.getFullYear();
	var fulldate = d_names[curr_day] + " " + m_names[curr_month] + " " + curr_date + ", " + curr_year;
	return (fulldate);

}

function notpast(month,day,year){
month--;
var today = new Date();  var eventday = new Date();  eventday.setFullYear(year,month,day);
if (eventday<today){
	return false;
}
return true;
}

function hascome(month,day,year){
month--; 
var today = new Date();  var eventday = new Date();  eventday.setFullYear(year,month,day);
if (eventday>today){
	return false;
}
return true;
}

function isoneweek(month,day,year){
month--; 
var today = new Date(); var eventday = new Date();  eventday.setFullYear(year,month,day); var prevSun = new Date(eventday.getTime() - 7*24*60*60*1000); 
if(today>prevSun){
	return false;
}
return true;
}

function isnotthur(month,day,year){
// make sure that today's date is not past the Thursday cutoff
month--; 
var today = new Date(); var eventday = new Date();  eventday.setFullYear(year,month,day); var prevThur = new Date(eventday.getTime() - 4*24*60*60*1000); 
if(today>prevThur){
	return false;
}
return true;
}



/* ================================================================ 
Live Streaming Church scripts
=================================================================== */

function printnotes (sermonnotes)
{//see http://www.ozzu.com/website-design-forum/printing-all-text-from-textarea-t22136.html
	var linebreak=/\n/gi;
	sermonnotes=sermonnotes.replace(linebreak, '<br />');
	var d_names = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
	var m_names = new Array("Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec");
	var d = new Date(); var curr_day = d.getDay(); var curr_date = d.getDate(); var curr_month = d.getMonth();var curr_year = d.getFullYear();

	printwindow = window.open('','Covenant_Love_Sermon_Notes','width=680, height=580, location=0, menubar=0, status=0, toolbar=0, scrollbars=yes, resizable=0');
	printwindow.document.open();
	printwindow.document.write('<html><head><title>Covenant Love Live Streaming Church Sermon Notes</title><style>a:hover {text-decoration: none; color:#000;} body {background:#fff; margin:5px; font-family:Helvetica,sans-serif; font-size: 11pt;} h1 {font-size: 12pt; font-weight: bold; margin:10px 0 14px 10px;} div#printdiv {width:640px; min-height: 540px; height: auto !important; height:540px;} p {margin:2px 6px 8px 10px;}</style></head><body><div id="printdiv"><a style="float:left;" href="javascript:window.print();" >Print</a><a style="float:right; clear:right;" href="javascript:window.close();" >Close</a><br style="clear:both"/><br style="clear:both"/><img src="http://www.covenantlovechurch.org/fileadmin/templates/CLC/images/clclive_logo.jpg" alt="Covenant Love Church" width="220" height="77" /><br style="clear:both"/><br style="clear:both"/><h1>Sermon Notes: ');
	printwindow.document.write(d_names[curr_day] + " " + m_names[curr_month] + " " + curr_date + ", " + curr_year);
	printwindow.document.write('</h1><p>' + sermonnotes + '</p></div></body></html>');
	printwindow.document.close();

}


function wopen(url, name, w, h)
{
// Script from http://www.boutell.com/newfaq/creating/windowsize.html
// Fudge factors for window decoration space.
// In my tests these work well on all platforms & browsers.
w += 32;
h += 96;
 var win = window.open(url,
  name, 
  'width=' + w + ', height=' + h + ', ' +
  'location=0, menubar=0, ' +
  'status=0, toolbar=0, scrollbars=1, resizable=0, location=0, status=0');
 win.resizeTo(w, h);
 win.focus();
}


/* ********************************
/* Functions to manipulate tables
/* for dyanamic content and options
/* in Forms - JDS
/* ********************************/

function CollapseAll(tname) {
/* tname = id of table to collapse 
/* numrows = detects and stores the number of rows in tname
/**/
		var numrows = tname.rows.length;
		
		for ( i = 0; i<numrows; i++){
			tname.rows[i].style.display = "none";
		}
		HideCLCtableStyle (tname);
		return;
}

function ShowRows (tabname, numitems) {
/* tabname = id of table to alter
/* numitems = number of consecutive rows to expand,
/* including row 0 (header row)
/**/
	CollapseAll(tabname);

	if ( numitems != 0 && numitems != "") {
		if (document.all && !window.opera) {
			tabname.rows[0].style.display = "block";
		}
		else {
			tabname.rows[0].style.display = "table-row";
		}

/* Shows number of rows selected (numitems)
*/
		for ( i = 0; i<numitems; i++){
			if (document.all && !window.opera)
				{tabname.rows[i+1].style.display = "block";}
			else
				{tabname.rows[i+1].style.display = "table-row";}
		}

/* Apply grey color and border to displayed table
*/
	ShowCLCtableStyle (tabname);
	}
	return;
	
}

function ToggleCheckedTable(check,tabname)
{
	if (check.checked == false){
		CollapseAll(tabname)
		return;
	}
	else {
		var numrows = tabname.rows.length;
		numrows--; // exclude leading header row
		ShowRows ( tabname, numrows );
		return;
	}
}

function ToggleCheckedDiv(check, divname) {
	if (check.checked == true) {
		divname.style.display = "block";
	}
	else {
		divname.style.display = "none";
	}
}


/* *************************************
/* Apply collapsable tables in current CLC format
/* 10-18-2010 - JDS
/* *************************************/

function ShowCLCtableStyle (table) {
table.style.background = "#f4f4f4";
table.style.border = "10px solid #f4f4f4";
table.style.borderRadius = "10px";
table.style.MozBorderRadius = "10px";
}

function HideCLCtableStyle (table) {
table.style.border = "none";
}

/* *************************************
/* Alternate solution to window.onload
/* http://haacked.com/archive/2006/04/06/StopTheWindow.OnloadMadness.aspx
/* *************************************/

function AddOnload(myfunc)
{
if(window.addEventListener)
window.addEventListener('load', myfunc, false);
else if(window.attachEvent)
window.attachEvent('onload', myfunc);
}


