// settings
emailURL = "/utilities/email.html?title=%%title%%&url=%%url%%";
printURL = "/utilities/print.html?id=%%id%%";
similarURL = "/utilities/search.html?similar=%%url%%";

// print this page
// Usage:
// <a href="javascript:printPage(ID);">LINK</a>
//
function printPage(id)
{
	windowArray[windowArray.length] = window.open(printURL.replace('%%id%%', id), 'printWindow', 'width=760,height=400,toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1');
}

//	Requires one or more tabs to be deselected, followed by one tab to be selected
// Overwrites current class
function deselectSelect() {

	var argLength = arguments.length;
	var currentDiv = argLength - 1;

	if (argLength < 1) {
		return;
	} else {
		for (i=0; i<(currentDiv); i++) {
			document.getElementById(arguments[i]).className = "";
		}
		document.getElementById(arguments[currentDiv]).className = "current";
	}
	return;
}

//	Requires one or more elements to be hidden, followed by one element to be shown
//Overwrites current class
function hideShow() {

	var argLength = arguments.length;
	var showDiv = argLength - 1;

	if (argLength < 1) {
		return;
	} else {
		for (i=0; i<(showDiv); i++) {
			document.getElementById(arguments[i]).className = "hide";
		}
		document.getElementById(arguments[showDiv]).className = "show";
	}
	return;
}


// homepage content panel

// channel load
	function channelLoad()
	{
		if (window.advancePanel) advancePanel();

		// TEMP - find 'related' section and apply style
		var anchorArray = document.getElementsByTagName("a");
		for (var i = 0; i < anchorArray.length; i++)
		{
			if (anchorArray[i].href.indexOf("#related") >= 0)
			{
				anchorArray[i].id = "relatedLink";
				break;
			}
		}
	}

// panel settings	
	var panelCount = 4;
	var panelDelay = 6;

	var currentPanel = 0;
	var panelTimeout;

	function showPanel(panelNumber)
	{
		for (var panelIndex = 1; panelIndex <= panelCount; panelIndex++)
		{
			var myPanel = document.getElementById('panel_' + panelIndex);
			var myListItem = document.getElementById('panel_btn_' + panelIndex);
			
			if (myPanel)
			{
				if (panelIndex == panelNumber)
				{
					currentPanel = panelIndex;
					myPanel.style.display = 'inline';
					if (myListItem) myListItem.style.backgroundPosition = 'bottom';
				}
				else
				{
					myPanel.style.display = 'none';
					if (myListItem) myListItem.style.backgroundPosition = 'top';
				}
			}
		}

		pausePanel();
	}
	
	function advancePanel()
	{
		nextPanel();
		panelTimeout = window.setTimeout(advancePanel, panelDelay * 1000);
	}
	
	function nextPanel()
	{
		currentPanel++;
		if (currentPanel > panelCount) currentPanel = 1;
		showPanel(currentPanel);
	}

	function previousPanel()
	{
		currentPanel--;
		if (currentPanel == 0) currentPanel = panelCount;
		showPanel(currentPanel);
	}
	
	function pausePanel()
	{
		if (panelTimeout) clearTimeout(panelTimeout);
	}

// search functions
	var queryChanged = false;

	function changeQuery()
	{
		queryChanged = true;
	}
	
	function changeSearchType(type)
	{
		var submit_form = false;
		var query_input = document.getElementById("query");
		if (type && query_input && query_input.value && queryChanged)
		{
			submit_form = true;
		}
		
		if (type == null)
		{
			var query = window.getQueryVariable("type");
			if (query != "scripture")
			{
				type = "word";
			}
			else
			{
				type = query;
			}
		}
		window.writeCookie("searchType", type, null);
		
		var scripture_div = document.getElementById("scriptureSearch");
		var word_div = document.getElementById("wordSearch");
		var type_input = document.getElementById("searchType");
		
		if (scripture_div) scripture_div.style.display = "none";
		if (word_div) word_div.style.display = "none";
		
		switch (type)
		{
			case "scripture":
				if (scripture_div) scripture_div.style.display = "block";
				type_input.value = "scripture";
				break;
			case "word":
				if (word_div) word_div.style.display = "block";
				type_input.value = "word";
				break;
			default:
				if (word_div) word_div.style.display = "block";
				type_input.value = "word";
				break;
		}

		if (submit_form)
		{
			var submit_button = document.getElementById("searchSubmit");
			if (submit_button) submit_button.click();
		}
	}
	
	function itemtoggleSearch(currItem, PlusMinusBtn)
	{
		if (document.getElementById)
		{
			my_div = document.getElementById(currItem).style;
			my_img = document.getElementById(PlusMinusBtn);
			my_div.display = (my_div.display == "inline") ? "none" : "inline";			
			my_img.src = (my_div.display == "inline") ? "/home/img/btn_search_up.gif" : "/home/img/btn_search_down.gif";
			return(false);
		}
		else
		{				
			return(true);
		}
	}	
	
	function submitSearchForm()
	{
		// display search status
		var status_span = document.getElementById("searchStatus");
		if (status_span) status_span.style.visibility = "visible";
		
		// compile filters
		var elements = document.getElementsByTagName("input");
		var filter_string = "";
		for (var i = 0; i < elements.length; i++)
		{
			if (elements[i].type == "checkbox" && elements[i].attributes.filter && elements[i].checked)
			{
				if (filter_string != "") filter_string += ";";
				filter_string += elements[i].value;
			}
		}
		var filter_input = document.getElementById("filter");
		if (filter_input) filter_input.value = filter_string;
	
		return(false);
	}

	function clearFilters()
	{
		var elements = document.getElementsByTagName("input");
		for (var i = 0; i < elements.length; i++)
		{
			if (elements[i].type == "checkbox" && elements[i].attributes.filter)
			{
				elements[i].checked = false;
			}
		}
		var element = document.getElementById("toneAny");
		if (element) element.checked = true;
	}
	
	function selectAll()
	{
		var elements = document.getElementsByTagName("input");
		for (var i = 0; i < elements.length; i++)
		{
			if (elements[i].type == "checkbox" && elements[i].attributes.filter)
			{
				elements[i].checked = true;
			}
		}
		var element = document.getElementById("toneAny");
		if (element) element.checked = true;
	}

// rating functions
	function toggleEdit(currItem, editItem)
	{
		if (document.getElementById)
		{	
			my_div = document.getElementById(currItem).style;
			my_div.display = (my_div.display == "none") ? "inline" : "none";	
			my_div = document.getElementById(editItem).style;
			my_div.display = (my_div.display == "inline") ? "none" : "inline";	
			return(false);
		}
		else
		{				
			return(true);
		}
	}
	
	function returnStar(hidestar, showstars, reminder, starimg, theRating, theForm)
	{
		if (document.getElementById)
		{
			my_vote = document.getElementById(hidestar).style;
			my_result = document.getElementById(showstars).style;
			my_reminder = document.getElementById(reminder).style;
			my_img = document.getElementById(starimg);
			my_vote.display = (my_vote.display == "none") ? "inline" : "none";
			my_result.display = (my_result.display == "inline") ? "none" : "inline";
			my_reminder.display = (my_reminder.display == "inline") ? "none" : "inline";
			
			switch(theRating)
			{
				case "1":
					my_img.src = "/home/img/stars-1.gif";
					theForm.rating.value = '20';
					break;
				case "2":
					my_img.src = "/home/img/stars-2.gif";
					theForm.rating.value = '40';
					break;
				case "3":
					my_img.src = "/home/img/stars-3.gif";
					theForm.rating.value = '60';
					break;
				case "4":
					my_img.src = "/home/img/stars-4.gif";
					theForm.rating.value = '80';
					break;
				case "5":
					my_img.src = "/home/img/stars-5.gif";
					theForm.rating.value = '100';
					break;
				default:
					my_img.src = "/home/img/stars-0.gif";
					theForm.rating.value = '0';
					break;
			}
			return(false);
		}
		else
		{				
			return(true);
		}
	}

	function validateDelete(theName)
	{
		msg = confirm("Are you sure you want to delete the comment from " + theName + "?");
		if (msg == true)
		{
			return(true);
		}
		return(false);
	}	

	function validateUserDelete()
	{
		msg = confirm("Are you sure you want to delete your comment?");
		if (msg == true)
		{
			return(true);
		}
		return(false);
	}		
	
	function checkStarRate(theForm)
	{
		if (theForm.rating.value == '0')
		{
			alert("Please select a Star Rating")
			return(false);
		}
		return(true);
	}

	var form_submitted = false;	
	
	function submitRateForm(theForm)
	{
		if (checkStarRate(theForm))
		{
			if (form_submitted)
			{
				alert("Your form has already been submitted. Please wait...");
				return(false);
			}
			else
			{
				form_submitted = true;
				return(true);
			}
			return(true);	
		}
		else
		{
			return(false);
		}		
	}

// limit characters in a text area
	//
	// Usage:
	// <span id="message_limit"><strong>1000</strong> characters remaining</span>
	// <textarea name="#" id="#" onkeyup="charCount(this,1000)" />
	//
	// Note: change limit of characters as needed
	//
	
	function charCount(what, maxCount)
	{
		var str = new String(what.value);
		var len = str.length;
		var limitSpan = document.getElementById("limitText");
		
		len = maxCount - len;
		
		if (document.getElementById)
		{
			if (len < 0)
			{
				what.value = what.value.substring(0, maxCount);
			}
			else if (len > 1)
			{
				limitSpan.innerHTML = "<strong>" + len + "</strong> characters remaining";
			}
			else
			{
				limitSpan.innerHTML = "<strong>" + len + "</strong> character remaining";
			}
		}
	}
		
	function stripURL(urlinput)
	{ 
		urlString = new String(urlinput.value)
		strip_start = urlString.lastIndexOf('/');
		strip_end = urlString.length;
		strip_string = (urlString.substring(strip_start+1, strip_end)); 
		urlString = 'http://www.churchsafety.com/admin?url=' + strip_string;
		return(urlString);
	}
	
	function writeText(form)
	{
	 //   form.emailField.value = "";
	}


// ------------------------------------------------
//   PVII Equal CSS Columns scripts -Version 2
//   Copyright (c) 2005 Project Seven Development
//   www.projectseven.com
//   Version: 2.1.0
//   ------------------------------------------------


function P7_colH2(){ //v2.1.0 by PVII-www.projectseven.com
 var i,oh,h=0,tg,el,np,dA=document.p7eqc,an=document.p7eqa;if(dA&&dA.length){
 for(i=1;i<dA.length;i+=2){dA[i+1].style.paddingBottom='';}for(i=1;i<dA.length;i+=2){
 oh=dA[i].offsetHeight;h=(oh>h)?oh:h;}for(i=1;i<dA.length;i+=2){oh=dA[i].offsetHeight;
 if(oh<h){np=h-oh;if(!an&&dA[0]==1){P7_eqA2(dA[i+1].id,0,np);}else{
 dA[i+1].style.paddingBottom=np+"px";}}}document.p7eqa=1;
 document.p7eqth=document.body.offsetHeight;
 document.p7eqtw=document.body.offsetWidth;}
}
function P7_eqT2(){ //v2.1.0 by PVII-www.projectseven.com
 if(document.p7eqth!=document.body.offsetHeight||document.p7eqtw!=document.body.offsetWidth){P7_colH2();}
}
function P7_equalCols2(){ //v2.1.0 by PVII-www.projectseven.com
 var c,e,el;if(document.getElementById){document.p7eqc=new Array();
 document.p7eqc[0]=arguments[0];for(i=1;i<arguments.length;i+=2){el=null;
 c=document.getElementById(arguments[i]);if(c){e=c.getElementsByTagName(arguments[i+1]);
 if(e){el=e[e.length-1];if(!el.id){el.id="p7eq"+i;}}}if(c&&el){
 document.p7eqc[document.p7eqc.length]=c;document.p7eqc[document.p7eqc.length]=el}}
 setInterval("P7_eqT2()",10);}
}
function P7_eqA2(el,p,pt){ //v2.1.0 by PVII-www.projectseven.com
 var sp=10,inc=20,g=document.getElementById(el);np=(p>=pt)?pt:p;
 g.style.paddingBottom=np+"px";if(np<pt){np+=inc;
 setTimeout("P7_eqA2('"+el+"',"+np+","+pt+")",sp);}
}

//  ------------------------------------------------
//   VERSION 2 - MODIFIED, SO WE CAN USE IT A SECOND TIME ON THE SAME PAGE
//  ------------------------------------------------

function P7_colH2_1(){ //v2.1.0 by PVII-www.projectseven.com
 var i,oh,h=0,tg,el,np,dA=document.p7eqc_1,an=document.p7eqa_1;if(dA&&dA.length){
 for(i=1;i<dA.length;i+=2){dA[i+1].style.paddingBottom='';}for(i=1;i<dA.length;i+=2){
 oh=dA[i].offsetHeight;h=(oh>h)?oh:h;}for(i=1;i<dA.length;i+=2){oh=dA[i].offsetHeight;
 if(oh<h){np=h-oh;if(!an&&dA[0]==1){P7_eqA2_1(dA[i+1].id,0,np);}else{
 dA[i+1].style.paddingBottom=np+"px";}}}document.p7eqa_1=1;
 document.p7eqth_1=document.body.offsetHeight;
 document.p7eqtw_1=document.body.offsetWidth;}
}
function P7_eqT2_1(){ //v2.1.0 by PVII-www.projectseven.com
 if(document.p7eqth_1!=document.body.offsetHeight||document.p7eqtw_1!=document.body.offsetWidth){P7_colH2_1();}
}
function P7_equalCols2_1(){ //v2.1.0 by PVII-www.projectseven.com
 var c,e,el;if(document.getElementById){document.p7eqc_1=new Array();
 document.p7eqc_1[0]=arguments[0];for(i=1;i<arguments.length;i+=2){el=null;
 c=document.getElementById(arguments[i]);if(c){e=c.getElementsByTagName(arguments[i+1]);
 if(e){el=e[e.length-1];if(!el.id){el.id="p7eq"+i;}}}if(c&&el){
 document.p7eqc_1[document.p7eqc_1.length]=c;document.p7eqc_1[document.p7eqc_1.length]=el}}
 setInterval("P7_eqT2_1()",10);}
}
function P7_eqA2_1(el,p,pt){ //v2.1.0 by PVII-www.projectseven.com
 var sp=10,inc=20,g=document.getElementById(el);np=(p>=pt)?pt:p;
 g.style.paddingBottom=np+"px";if(np<pt){np+=inc;
 setTimeout("P7_eqA2_1('"+el+"',"+np+","+pt+")",sp);}
}


// rating functions
function toggleEdit(currItem, editItem)
{
	if (document.getElementById)
	{
		my_div = document.getElementById(currItem).style;
		my_div.display = (my_div.display == "none") ? "inline" : "none";	
		my_div = document.getElementById(editItem).style;
		my_div.display = (my_div.display == "inline") ? "none" : "inline";	
		return(false);
	}
	else
	{
		return(true);
	}
}

// nav functions
function activateMenu ()
{
	//this function fixes the shakiness of IE
	if (isIE)
	{
		document.detachEvent('onmousemove', mouseMove);
		window.attachEvent('onload', sfHover);
	}

}

function activateTips ()
{
	//this function fixes the conflict in IE with css menus and tooltips
	if (isIE)
	{
		window.detachEvent('onload', sfHover);
		document.attachEvent('onmousemove', mouseMove);
	}

}

sfHover = function()
{
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++)
	{
		sfEls[i].onmouseover = function()
		{
			this.className += " sfhover";
		}
		sfEls[i].onmouseout = function()
		{
			this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);
