/*
$Id: $
*/

// Update comment preview box
function updateCommentPreview(o) {
	var preview = document.getElementById("commentpreview");
	if (preview != null) {
		preview.innerHTML = o.value;
	}
}

// Toggle menu sections on left nav
function toggleMenuSection(s, force) {
	var section = document.getElementById(s);
	var button = document.getElementById(s + '_button');
	if (section != null) {
		if (section.style.display == "none" || force == 1) {
			section.style.display = "block";
			if (button != null) {
				button.src = '/images/seccol_arrow_con_d.gif';
			}
		} else {
			section.style.display = "none";
			if (button != null) {
				button.src = '/images/seccol_arrow_con_r.gif';
			}
		}
	}
}

// Check all elem checkboxes according to checked value
function checkAll(name, checked) {
	e = document.getElementsByName(name);
	if (e != null) {
		for(i=0;i<e.length;i++) {
			e[i].checked = checked;
		}
	}
}

// Submit main form
function submitMainForm(v) {
	var mainform = document.getElementById("mainform");
	if (mainform != null) {
		if (v != null) {
			var action = mainform.action;
			if (action != null) {
				action.value = v;
			}
		}
		mainform.submit();
		return(false);
	}
}

// Set mode
function setMode(v) {
	var mainform = document.getElementById("mainform");
	if (mainform != null) {
		if (v != null) {
			var mode = mainform.mode;
			if (mode != null) {
				mode.value = v;
			}
		}
	}
}

// Throw a confirm popup
function confirmChoice(question, href) {
	if (confirm(question)) {
		document.location = href
	}
}

// Move messages to the container with id=messagebox
// This is called in the footer on every page so you can
// customize the location of any messages that appear on
// the page by simply adding a <div id="messagebox"></div>
// wherever you'd like them to show. If javascript is
// disabled or there is no messagebox container, then
// nothing happens and the messages will appear in their
// default location at the top of the page.
function moveMessages() {
	var m = document.getElementById('message');
	var mb = document.getElementById('messagebox');
	if (m == null) return;
	if (mb == null) return;
	
	var html = m.parentNode.innerHTML;
	var newmessage = document.createElement('DIV');
	newmessage.innerHTML = html;
	
	m.parentNode.removeChild(m);
	mb.appendChild(newmessage);
	mb.style.display = "block";
}

// Unhide an element
function show2(id, layout) {
	var e = document.getElementById(id);
	if (e != null) {
		if (layout == null) {
			e.style.display = "block";
		} else {
			e.style.display = layout;
		}
	}
}

// Hide an element
function hide(id) {
	var e = document.getElementById(id);
	if (e != null) {
		e.style.display = "none";
	}
}

// Add asterisks to the inner HTML of all elements tagged with the CSS
// class "labelrequired". It would be cleaner to do this in CSS with
// content:before but IE doesn't support it. :| jdw
function addAsterisks(n) {
	var i;
	var nodes = n.childNodes;
	for(i=0;i<nodes.length;i++) {
		if (nodes[i].nodeType == 1) {
			addAsterisks(nodes[i]);
			if (nodes[i].className != null) {
				if (nodes[i].className.indexOf('labelrequired') >= 0) {
					if (nodes[i].innerHTML.indexOf('asterisk') < 0) {
						nodes[i].innerHTML = '<span class="asterisk">*</span>&nbsp;' + nodes[i].innerHTML;
					}
				}
			}
		}
	}
}
	
// Called after every page is loaded. Here you can put whatever javascript
// hooks you want into any page.
function bodyLoaded() {
	// Move error messages
	
	
	
	// Add asterisks to elements with the class "labelrequired"
	//addAsterisks(document);
	
	//moveMessages();
	//show2('messageparentinnerhtmlhack');
}

// Does nothing (wink wink, nudge nudge)
function nop() {
}

// Open tour window
function openWin() {
	window.open("new_tour/default.html", "thewindow", "scrollbars=0,toolbar=no,width=748,height=450,top=0,left=0");
}

// Validate submitted verses
function validate_submit_verses() {
	/*if (document.ScriptureSearch.ScriptureStartChapterA.value == "") {
		alert("Please enter a Starting Chapter")
		ScriptureSearch.ScriptureStartChapterA.select()
		return false
	}*/
	if (window.document.ScriptureSearch.ScriptureStartChapterA.value == "") {
		var clear_all = "yes";
	}
	
	if (window.document.ScriptureSearch.ScriptureStartVerseA.value == "" && window.document.ScriptureSearch.ScriptureEndChapterA.value == "" && window.document.ScriptureSearch.ScriptureEndVerseA.value == "") {
		window.document.ScriptureSearch.search_entire_chapter.value = "yes";
	}
	if (window.document.ScriptureSearch.ScriptureEndChapterA.value == window.document.ScriptureSearch.ScriptureStartChapterA.value && (window.document.ScriptureSearch.ScriptureStartVerseA.value == "" && window.document.ScriptureSearch.ScriptureEndVerseA.value == "") ){
		window.document.ScriptureSearch.ScriptureEndChapterA.value = "";
		window.document.ScriptureSearch.search_entire_chapter.value = "yes";
	}
	
	if (window.document.ScriptureSearch.ScriptureEndChapterA.value == "" && (window.document.ScriptureSearch.ScriptureStartVerseA.value != "") ) {
		window.document.ScriptureSearch.ScriptureEndChapterA.value = window.document.ScriptureSearch.ScriptureStartChapterA.value;
		window.document.ScriptureSearch.search_entire_chapter.value="no";
	}
	if (window.document.ScriptureSearch.ScriptureStartVerseA.value == "" && window.document.ScriptureSearch.ScriptureEndChapterA.value == "" && window.document.ScriptureSearch.ScriptureEndVerseA.value != "") {
		window.document.ScriptureSearch.ScriptureStartVerseA.value = window.document.ScriptureSearch.ScriptureEndVerseA.value;
		window.document.ScriptureSearch.ScriptureEndChapterA.value = window.document.ScriptureSearch.ScriptureStartChapterA.value;
		window.document.ScriptureSearch.search_entire_chapter.value="no";
	}
	if (window.document.ScriptureSearch.ScriptureEndChapterA.value != "" && (window.document.ScriptureSearch.ScriptureStartVerseA.value == "") ) {
		window.document.ScriptureSearch.ScriptureStartVerseA.value = 1;
		window.document.ScriptureSearch.search_entire_chapter.value="no";
	}
	if (window.document.ScriptureSearch.ScriptureEndVerseA.value == "" && (window.document.ScriptureSearch.ScriptureStartChapterA.value == window.document.ScriptureSearch.ScriptureEndChapterA.value) ) {
		window.document.ScriptureSearch.ScriptureEndVerseA.value = window.document.ScriptureSearch.ScriptureStartVerseA.value;
	}
	if (window.document.ScriptureSearch.ScriptureEndVerseA.value == "" && (parseInt(window.document.ScriptureSearch.ScriptureStartChapterA.value) < parseInt(window.document.ScriptureSearch.ScriptureEndChapterA.value)) ) {
		window.document.ScriptureSearch.ScriptureEndVerseA.value = 1;
		window.document.ScriptureSearch.search_entire_chapter.value="no";
	}
	if (clear_all == "yes") {
		window.document.ScriptureSearch.search_entire_chapter.value = "yes";
		window.document.ScriptureSearch.ScriptureStartChapterA.value = "";
		window.document.ScriptureSearch.ScriptureStartVerseA.value = "";
		window.document.ScriptureSearch.ScriptureEndChapterA.value = "";
		window.document.ScriptureSearch.ScriptureEndVerseA.value = "";
	}
	if (parseInt(window.document.ScriptureSearch.ScriptureEndChapterA.value) < parseInt(window.document.ScriptureSearch.ScriptureStartChapterA.value)) {
		alert("The Ending Chapter cannot be a Lower number than the Starting Chapter");
		return false
	}
	if ((parseInt(window.document.ScriptureSearch.ScriptureEndChapterA.value) == parseInt(window.document.ScriptureSearch.ScriptureStartChapterA.value)) && parseInt(window.document.ScriptureSearch.ScriptureEndVerseA.value) <parseInt(window.document.ScriptureSearch.ScriptureStartVerseA.value) ) {
		alert("The Ending Verse cannot be a Lower number than the Starting Verse");
		return false
	}
	return true
}	

// Parse verse input
function test_verse_input(FieldName) {
	scripture = window.document.ScriptureSearch[FieldName].value
		
	field_length = parseInt(window.document.ScriptureSearch[FieldName].value.length)
	if (field_length > 3){
		alert("The length of this field cannot exceed 3 characters.")
		window.document.ScriptureSearch[FieldName].select()
		return false
	}
	return validate_integer(scripture,FieldName)
}

// Parse verse input
function test_verse_input_byForm(FormName, FieldName) {
    var theForm = document[FormName];
    var theField = theForm[FieldName];
	var scripture = theField.value;
		
	field_length = parseInt(window.document[FormName][FieldName].value.length)
	if (field_length > 3){
		alert("The length of this field cannot exceed 3 characters.");
		window.document[FormName][FieldName].select();
		return false
	}

	return validate_integer_byForm(scripture,FieldName, FormName)
}

// Validate integer
function validate_integer_byForm(strValue,FieldName, FormName) {
	if (strValue == "") {
		return true
	}	
	var integer  = /(^\d\d*$)/;
																 
	//check for integer characters
	if (!integer.test(strValue)) {
		alert("Please enter numbers only for Chapters and Verses.");
		var theForm = document[FormName];
        var theField = theForm[FieldName];
		//theField.select();
		return false	
	}
	return true
}

// Validate integer
function validate_integer(strValue,FieldName) {
	if (strValue == "") {
		return true
	}	
	var integer  = /(^\d\d*$)/;
																 
	//check for integer characters
	if (!integer.test(strValue)) {
		alert("Please enter numbers only for Chapters and Verses.")
		window.document.ScriptureSearch[FieldName].select()
		return false	
	}
	return true
}

// Check for empty keyword entry
function test_keyword_field() { 
	if (window.document.KeyWordSearch.keyword.value == "") {
		alert("Please enter a Keyword")
		window.document.KeyWordSearch.keyword.value = "Please enter a Keyword"
		window.document.KeyWordSearch.keyword.select()
		return false
	}
	return true
}

// Check for empty category
function test_category_field(){ 
	if (document.illustration.CategoryName.value == "") {
		alert("Please select a Category")
		return false
	}
	return true
}

// Check for empty audience
function test_audience_field() { 
	if (document.audience_search.AudienceID.value == "") {
		alert("Please Select an Audience")
		return false
	}
	return true
}

// Check for empty contributor name
function test_cont_field() { 
	if (document.TopicSearch.NameLast.value == "") {
		alert("Please enter a Contributor\'s Last Name")
		document.TopicSearch.NameLast.value = "Last Name"
		document.TopicSearch.NameLast.select()
		return false
	}
	return true
}

// Check for empty denomination
function test_denomination_field() { 
	if (document.Denomination.denomination.value == "") {
		alert("Please Select an Denomination")
		return false
	}
	return true
}

// TODO: Dreamweaver open window. Check for usage and remove.
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function openWinReview(URL) {
	aWindow = window.open(URL, "thewindow", "width=440,height=300,top=200,left=250");
}

function versedisplay(load) {
	wide = (document.all) ? (screen.AvailWidth - 330) : (screen.width - 330) ;
	msg = window.open("","versebox","scrollbars=yes,toolbar=no,width=320,height=450,left=" + wide + ",top=0");
	if (navigator.appVersion.indexOf("2.0") != -1 || navigator.appVersion.indexOf("(X11") != -1 || navigator.appVersion.indexOf("(Mac") != -1) {
		msg = window.open("","versebox","scrollbars=yes,toolbar=no,width=320,height=450,left=" + wide + ",top=0");
	}
	msg.location.href = load;
	msg.focus();
}

function openWin2() {
	aWindow = window.open("mail_to_friend.asp?sermon_id=<%=sermon_id%>", "thewindow", "scrollbars=0,toolbar=no,width=360,height=375,top=0,left=0");
}

function ValidateNumeric(FormName, FieldName, FieldValue) {
    len = FieldValue.length;
	nums = "0123456789";
	
	for(i=0; i<len; i++){
		if (nums.indexOf(FieldValue.charAt(i)) < 0){
			alert('Please enter only numbers!');
			document[FormName][FieldName].focus(); 
			document[FormName][FieldName].select(); 
			return false;
		}
	}
	return true;
}	


//overlay sutff. There is one main overlay function that will make the div in the _header visible and set the background and such....It's all in a style on screen.css named overlay and overlayinside. 
//Each action such as AddToFavorites, SuggestKeyword, ScriptureSearchHelp, etc. is simply loaded into an iframe. To add more overlay features in the future just create a function for it, set
//the iframe url and then call the ShowOverlay() function. The timeout is included to give the iframe some time to load before it's displayed.
function ShowOverlay(){
	//document.documentElement.scrollTop work on all browsers on the PC. Macs will have a value of 0.
    var scrollTop1 = document.documentElement.scrollTop;
    //document.body.scrollTop works on all browsers on the MAC. PCs will have a value of 0.
    var scrollTop2 = document.body.scrollTop;
    
    var useScrollTop = scrollTop1; 
    if(scrollTop2 > scrollTop1) //set useScrollTop equal to whichever scrollTop has a value that isn't 0.
    {
        useScrollTop = scrollTop2;
    }
	
	document.getElementById("Overlay").style.top = useScrollTop + "px";
	document.getElementById("Overlay").style.display = "";
	
	if (screen.height > 769){
	    document.getElementById("OverlayInside").style.top = (useScrollTop + 120) + "px";
	}else{
	    document.getElementById("OverlayInside").style.top = (useScrollTop) + "px";
	}
	document.getElementById("OverlayInside").style.display = "";
	
    window.onscroll = closeOverlay;
    document.body.onscroll = closeOverlay;
}

function SuggestKeyword(ResourceTypeID, ResourceID, Title, Topic){
	document.getElementById("OverlayIFrame").src = "/Overlays/KeywordSuggestion.asp?ResourceID=" + ResourceID + "&ResourceTypeID=" + ResourceTypeID
	document.getElementById("OverlayIFrame").style.width = "464px";
	document.getElementById("OverlayIFrame").style.height = "540px";
	
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-45px";}
	
	//the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 400);	
}

function ShareWithFriend(ResourceID, ResourceTypeID){
    document.getElementById("OverlayIFrame").src = "/Overlays/ShareWithFriend.asp?ResourceID=" + ResourceID + "&ResourceTypeID=" + ResourceTypeID;
	document.getElementById("OverlayIFrame").style.width = "464px";
	document.getElementById("OverlayIFrame").style.height = "540px";
	
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-45px";}
	
	//the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 400);	
}

function AddResourceToCalendar(Item_ID, Type_ID){
    document.getElementById("OverlayIFrame").src = "/Overlays/AddToCalendar.asp?Item_ID=" + Item_ID + "&Type_ID=" + Type_ID;
	document.getElementById("OverlayIFrame").style.width = "464px";
	document.getElementById("OverlayIFrame").style.height = "540px";
	
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-45px";}
	
	//the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 400);	
}

function AddResourceToFavorites(Item_ID, Type_ID){
    document.getElementById("OverlayIFrame").src = "/Overlays/AddToFavorites.asp?Item_ID=" + Item_ID + "&Type_ID=" + Type_ID;
	document.getElementById("OverlayIFrame").style.width = "464px";
	document.getElementById("OverlayIFrame").style.height = "540px";
	
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-45px";}
	
	//the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 400);	
}

function EmailSearch(SearchURL){
    document.getElementById("OverlayIFrame").src = "/Overlays/EmailSearch.asp?SearchURL=" + SearchURL;
	document.getElementById("OverlayIFrame").style.width = "464px";
	document.getElementById("OverlayIFrame").style.height = "540px";
	
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-45px";}
	
	//the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 400);	
}

function NewsletterSignup(LYRIS_Email,MoreInfo){
    document.getElementById("OverlayIFrame").src = "/Overlays/NewsletterSignup.asp?MoreInfo=" + MoreInfo + "&LYRIS_Email=" + LYRIS_Email;
    document.getElementById("OverlayIFrame").style.width = "464px";
	document.getElementById("OverlayIFrame").style.height = "540px";
	
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-45px";}
	
	//the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 400);	
}

function MarketingOverlay_Favorites(){
    document.getElementById("OverlayIFrame").src = "/Overlays/MarketingOverlay_Favorites.asp";
    document.getElementById("OverlayIFrame").style.width = "620px";
	document.getElementById("OverlayIFrame").style.height = "470px";
	
	//if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-120px";}
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function MarketingOverlay_FullPageSermon(){
    document.getElementById("OverlayIFrame").src = "/Overlays/MarketingOverlay_FullPageSermon.asp";
    document.getElementById("OverlayIFrame").style.width = "620px";
	document.getElementById("OverlayIFrame").style.height = "470px";
	
	//if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-120px";}
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function MarketingOverlay_MyCalendar(){
    document.getElementById("OverlayIFrame").src = "/Overlays/MarketingOverlay_MyCalendar.asp";
    document.getElementById("OverlayIFrame").style.width = "620px";
	document.getElementById("OverlayIFrame").style.height = "470px";
	
	//if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-120px";}
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function MarketingOverlay_Illustrations(){
    document.getElementById("OverlayIFrame").src = "/Overlays/MarketingOverlay_Illustrations.asp";
    document.getElementById("OverlayIFrame").style.width = "620px";
	document.getElementById("OverlayIFrame").style.height = "490px";
	
	//if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-120px";}
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function MarketingOverlay_PowerPoints(){
    document.getElementById("OverlayIFrame").src = "/Overlays/MarketingOverlay_PowerPoints.asp";
    document.getElementById("OverlayIFrame").style.width = "620px";
	document.getElementById("OverlayIFrame").style.height = "470px";
	
	//if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-120px";}
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function Country_Overlay(){
    document.getElementById("OverlayIFrame").src = "/Overlays/Country_Overlay.asp";
    document.getElementById("OverlayIFrame").style.width = "620px";
	document.getElementById("OverlayIFrame").style.height = "490px";
	
	//if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-120px";}
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function PreviewVideo(video_preview,pid,video_title,price){
    document.getElementById("OverlayIFrame").src = "/Overlays/PreviewVideo.asp?pid=" + pid + "&video_preview=" + video_preview + "&video_title=" + video_title + "&price=" + price;
	document.getElementById("OverlayIFrame").style.width = "464px";
	document.getElementById("OverlayIFrame").style.height = "415px";
	
	//if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-45px";}
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function SaveSermonSearch(querystring){
    document.getElementById("OverlayIFrame").src = "/Overlays/SaveSermonSearch.asp?querystring=" + querystring;
	document.getElementById("OverlayIFrame").style.width = "464px";
	document.getElementById("OverlayIFrame").style.height = "415px";
	
	//if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-45px";}
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function DownloadVideoOfTheWeek(){
    document.getElementById("OverlayIFrame").src = "/Overlays/DownloadVideoOfTheWeek.asp";
	document.getElementById("OverlayIFrame").style.width = "464px";
	document.getElementById("OverlayIFrame").style.height = "215px";
	
	//if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-45px";}
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function PreviewVideoFromFeed(VideoFeedProductGroup_ID){
    document.getElementById("OverlayIFrame").src = "/Overlays/PreviewVideoFromFeed.asp?VideoFeedProductGroup_ID=" + VideoFeedProductGroup_ID;
	document.getElementById("OverlayIFrame").style.width = "464px";
	document.getElementById("OverlayIFrame").style.height = "490px";
	
	//if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-45px";}
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function PreviewVideoFromFeed_Test(VideoPreviewURL){
    document.getElementById("OverlayIFrame").src = "/Overlays/PreviewVideoFromFeed_Test.asp?VideoPreviewURL=" + VideoPreviewURL;
	document.getElementById("OverlayIFrame").style.width = "464px";
	document.getElementById("OverlayIFrame").style.height = "388px";
	
	//if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-45px";}
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function ReportProblemWithVideoFeed(VideoFeedProductGroup_ID){
    document.getElementById("OverlayIFrame").src = "/Overlays/ReportProblemWithVideoFeed.asp?VideoFeedProductGroup_ID=" + VideoFeedProductGroup_ID;
	document.getElementById("OverlayIFrame").style.width = "464px";
	document.getElementById("OverlayIFrame").style.height = "460px";
	
	//if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-45px";}
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function ReportComment(Comment_ID){
    document.getElementById("OverlayIFrame").src = "/Overlays/ReportComment.asp?Comment_ID=" + Comment_ID;
	document.getElementById("OverlayIFrame").style.width = "464px";
	document.getElementById("OverlayIFrame").style.height = "460px";
	
	//if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-45px";}
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function ReportAbuse(Contributor_ID){
    document.getElementById("OverlayIFrame").src = "/Overlays/ReportAbuse.asp?Contributor_ID=" + Contributor_ID;
	document.getElementById("OverlayIFrame").style.width = "464px";
	document.getElementById("OverlayIFrame").style.height = "460px";
	
	//if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-45px";}
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function ProvideSiteFeedback(){
    document.getElementById("OverlayIFrame").src = "/Overlays/ProvideSiteFeedback.asp"
	document.getElementById("OverlayIFrame").style.width = "464px";
	document.getElementById("OverlayIFrame").style.height = "460px";
	
	//if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-45px";}
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function LoginOverlay(){
    document.getElementById("OverlayIFrame").src = "/Overlays/Login.asp"
	document.getElementById("OverlayIFrame").style.width = "610px";
	document.getElementById("OverlayIFrame").style.height = "405px";
	
	//if the browser is IE 6, do not add a negative style left.
	document.getElementById("OverlayInside").style.left = "-100px";
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function CreateBasicOverlay(email, CreateContributor){
    document.getElementById("OverlayIFrame").src = "/Overlays/createbasic.asp?email=" + email + "&CreateContributor=" + CreateContributor;
	document.getElementById("OverlayIFrame").style.width = "600px";
	document.getElementById("OverlayIFrame").style.height = "405px";
	
	//if the browser is IE 6, do not add a negative style left.
	document.getElementById("OverlayInside").style.left = "-100px";
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function LogoutOverlay(){
    document.getElementById("OverlayIFrame").src = "/Overlays/Logout.asp"
	document.getElementById("OverlayIFrame").style.width = "480px";
	document.getElementById("OverlayIFrame").style.height = "405px";
	
	//if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-45px";}
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function LinkToThis(VideoFeedProductGroup_ID){
    document.getElementById("OverlayIFrame").src = "/Overlays/LinkToThis.asp?VideoFeedProductGroup_ID=" + VideoFeedProductGroup_ID;
	document.getElementById("OverlayIFrame").style.width = "464px";
	document.getElementById("OverlayIFrame").style.height = "460px";
	
	//if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-45px";}
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 300);	
}

function PowerPointPreview(root, image1, image2, image3, PowerPointID){
    var url = "/Overlays/PreviewPowerpoint.asp?root=" + root + "&image1=" + image1 + "&image2=" + image2 + "&image3=" + image3 + "&PowerPointID=" + PowerPointID;
    document.getElementById("OverlayIFrame").src = url;
    document.getElementById("OverlayIFrame").style.width = "512px";
    document.getElementById("OverlayIFrame").style.height = "430px";
    
    //if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-70px";}
  
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 400);	
}

function SuggestScripture(url){
    document.getElementById("OverlayIFrame").src = url;
    document.getElementById("OverlayIFrame").style.width = "650px";
    document.getElementById("OverlayIFrame").style.height = "500px";
    document.getElementById("OverlayInside").style.overflow = "auto";
    
    //if the browser is IE 6, do not add a negative style left.
	if(navigator.appVersion.indexOf("MSIE 6.") < 0){document.getElementById("OverlayInside").style.left = "-150px";}
	
    //the timeout is here to give the new page in the iframe time to reload the new page.
	window.setTimeout("ShowOverlay()", 400);	
}

function closeOverlay(){
    
    document.getElementById("OverlayIFrame").src = "";
    document.getElementById("Overlay").style.display = "none";
    document.getElementById("OverlayInside").style.display = "none";
	document.getElementById("OverlayIFrame").style.height = "240px";
	document.getElementById("OverlayIFrame").style.width = "400px";
    window.onscroll = null;
    document.body.onscroll = null;
}

////////////////////////////////////////////////////////////////////////////////////////
//////////////////End OVERLAY STUFF/////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

function toggleVideoFeedScriptureSuggestions(id)
{
    if (document.getElementById("divScripture" + id).style.display == 'none')
    {
        document.getElementById("divScripture" + id).style.display = '';
        document.getElementById("a" + id).style.display = 'none';
    }
    else
    {
        document.getElementById("divScripture" + id).style.display = 'none';
        document.getElementById("a" + id).style.display = '';
    }
}

function toggleKeywordSuggestions(id)
{
    if (document.getElementById("div" + id).style.display == 'none')
    {
        document.getElementById("div" + id).style.display = '';
        document.getElementById("a" + id).style.display = 'none';
    }
    else
    {
        document.getElementById("div" + id).style.display = 'none';
        document.getElementById("a" + id).style.display = '';
    }
}

function toggleDescription(id)
{
    if (document.getElementById("DescDiv" + id).style.display == 'none')
    {
        document.getElementById("DescDiv" + id).style.display = '';
        document.getElementById("DescA" + id).style.display = 'none';
    }
    else
    {
        document.getElementById("DescDiv" + id).style.display = 'none';
        document.getElementById("DescA" + id).style.display = '';
    }
}

function ShowAltTextOnRating(obj,altText)
{
    document.getElementById(obj).innerHTML = "(" + altText + ")"
}


//this variable is used between a few of the folling scroll contributors functions. it is used to clear a timeout after a user clicks on the blue boxes or an arrow
//to scroll the contributors.
var timeout;


//this function will change the margin offset of the 2000px wide contributors strip of which only 500px pixels is visible at any given time.
//this function is initiated by clicking either the left arrow or the right arrow.
function ScrollContributors(direction)  {
	    
    var obj = document.getElementById('FeaturedContributors');
    var currentOffset = obj.style.marginLeft;
    currentOffset = parseInt(currentOffset.replace("px",""));
    var newOffset;
    var offsetIncrement = parseInt(500);
    
    if(direction == 'right')
    {
        if (currentOffset >= -1475) //this number comes from the number of contributors on the home page which is 16. Each is 125px wide (16*135) minus the 4 that will always be visible (125*4=525))
        {
            newOffset = eval(currentOffset + -(offsetIncrement));
            obj.style.marginLeft = newOffset + "px";     
        }
        else
        {
            newOffset = 0;
            obj.style.marginLeft = newOffset + "px";     
        }
    }
    else //direction = left
    {
        if (currentOffset < 0)
        {
            newOffset = eval(currentOffset + offsetIncrement);    
            obj.style.marginLeft = newOffset + "px";
        }
        else
        {
            newOffset = -1500;
            obj.style.marginLeft = newOffset + "px";
        }
    }
    
    //the clearTimeout is used to reset the auto scrolling of the contributors. The contributors will scroll on a timer
    //every 5 seconds. What we don't want is for something to manually scroll the contributors and then 1 or 2 seconds later the timer scrolls it again.
    //to fix this, on a manual button click of either the arrows or clicking on the blue boxes, lets first reset the timeout and then start it over again
    //after setting the background color and display. setBackgroundColorAndDisplay(). The time is first initiated on default.asp.
    clearTimeout(timeout);  
    
}


function toggleMoreResources()
{
    if(document.getElementById('MoreResourcesMenu').style.display == "")
    {
        //it's currently visible, let's make it not visible.
        document.getElementById('MoreResourcesMenu').style.display = "none";
    }
    else
    {
        //it's not visible, let's make it visible.
        document.getElementById('MoreResourcesMenu').style.display = "";
    }
    
}

function ChangeMenuSearch(resourcetype)
{
    UpdateMenuSearchLinks(resourcetype,false);
}

function ChangeMenuSearchAndSubmit(resourcetype)
{
    UpdateMenuSearchLinks(resourcetype,true);
}

function UpdateMenuSearchLinks(resourcetype,submitform)
{
    if(resourcetype == "sermons")
    {
        UnBoldAllROSSearch();
        document.getElementById('frmRunOfSiteSearch').action = "/Sermons/SearchResults.asp";
        document.getElementById('ROS_SearchSermons').className = "SearchBar_Cateogry bold";
        document.getElementById('ROSSS').style.color = "#000";
        
        var Element = document.getElementById("ProSearchesBlock");
        if (Element != null){
            document.getElementById('ProSearchesBlock').style.display = "block";
            document.getElementById('ProSearchesText').style.display = "block";
        }
        
        var AdvancedSearchLink = document.getElementById("AdvancedSearchLink");
        if (AdvancedSearchLink != null){
            AdvancedSearchLink.href = "/Sermons/SearchResults.asp?AdvancedSearch=1";
        }
        
    }
    if(resourcetype == "illustrations")
    {
        UnBoldAllROSSearch();
        document.getElementById('frmRunOfSiteSearch').action = "/Illustrations/SearchResults.asp";
        document.getElementById('ROS_SearchIllustrations').className = "SearchBar_Cateogry bold";
        document.getElementById('ROSSI').style.color = "#000";
        
        var AdvancedSearchLink = document.getElementById("AdvancedSearchLink");
        if (AdvancedSearchLink != null){
            AdvancedSearchLink.href = "/Illustrations/SearchResults.asp?AdvancedSearch=1";
        }
        
        var TopicsRow = document.getElementById("DateRow");
        if (TopicsRow != null){
            TopicsRow.style.display = "none";
        }
        
    }
    if(resourcetype == "videos")
    {
        UnBoldAllROSSearch();
        document.getElementById('frmRunOfSiteSearch').action = "/Videos/SearchResults.asp";
        document.getElementById('ROS_SearchVideos').className = "SearchBar_Cateogry bold";
        document.getElementById('ROSSV').style.color = "#000";
        
        var AdvancedSearchLink = document.getElementById("AdvancedSearchLink");
        if (AdvancedSearchLink != null){
            AdvancedSearchLink.href = "/Videos/SearchResults.asp?AdvancedSearch=1";
        }
        
        var TopicsRow = document.getElementById("TopicsRow");
        if (TopicsRow != null){
            TopicsRow.style.display = "none";
        }
        
        var Element = document.getElementById("VideoProvidersBlock");
        if (Element != null){
            document.getElementById('VideoProvidersBlock').style.display = "block";
        }
        
        
        
    }
    if(resourcetype == "powerpoints")
    {
        UnBoldAllROSSearch();
        document.getElementById('frmRunOfSiteSearch').action = "/PowerPoints/SearchResults.asp";
        document.getElementById('ROS_SearchPowerPoints').className = "SearchBar_Cateogry bold";
        document.getElementById('ROSSPP').style.color = "#000";
        
        var AdvancedSearchLink = document.getElementById("AdvancedSearchLink");
        if (AdvancedSearchLink != null){
            AdvancedSearchLink.href = "/PowerPoints/SearchResults.asp?AdvancedSearch=1";
        }
    }
    
    if(resourcetype == "scripture")
    {
        UnBoldAllROSSearch();
        document.getElementById('frmRunOfSiteSearch').action = "/bible.asp";
        document.getElementById('ROS_SearchScripture').className = "SearchBar_Cateogry bold";
        document.getElementById('ROSSSC').style.color = "#000";
        
        var AdvancedSearchLink = document.getElementById("AdvancedSearchLink");
        if (AdvancedSearchLink != null){
            AdvancedSearchLink.href = "/bible.asp";
        }
    }
    
    if(submitform == true)
    {
        if(document.getElementById("SearchBar").value != "")
        {
            document.frmRunOfSiteSearch.submit();
        }
    }
}

function UnBoldAllROSSearch()
{
    document.getElementById('ROS_SearchSermons').className = "SearchBar_Cateogry";
    document.getElementById('ROS_SearchIllustrations').className = "SearchBar_Cateogry";
    document.getElementById('ROS_SearchVideos').className = "SearchBar_Cateogry";
    document.getElementById('ROS_SearchPowerPoints').className = "SearchBar_Cateogry";
    document.getElementById('ROS_SearchScripture').className = "SearchBar_Cateogry";
    document.getElementById('ROSSS').style.color = "#4595d8";
    document.getElementById('ROSSI').style.color = "#4595d8";
    document.getElementById('ROSSV').style.color = "#4595d8";
    document.getElementById('ROSSPP').style.color = "#4595d8";
    document.getElementById('ROSSSC').style.color = "#4595d8";
    document.getElementById('MoreResourcesMenu').style.display = "none";
    
    var Element = document.getElementById("ProSearchesBlock");
    if (Element != null)
    {
        document.getElementById('ProSearchesBlock').style.display = "none";
        document.getElementById('ProSearchesText').style.display = "none";
    }
    
    var Element = document.getElementById("VideoProvidersBlock");
    if (Element != null)
    {
        document.getElementById('VideoProvidersBlock').style.display = "none";
    }
    
    var TopicsRow = document.getElementById("TopicsRow");
    if (TopicsRow != null){
        TopicsRow.style.display = "block";
    }
    
    var TopicsRow = document.getElementById("DateRow");
    if (TopicsRow != null){
        TopicsRow.style.display = "block";
    }
}


function showSPM(section)
{
    UnSelectAllSPM();
    
    if(section == 'scripture')
    {
        document.getElementById('SPMNav1').style.backgroundImage = 'url(/images/40/btn_spm_selected.jpg)';
        document.getElementById('SPMNav1').style.backgroundPosition = 'right';
        document.getElementById('SPMNav1').style.backgroundRepeat = 'no-repeat';
        document.getElementById('SPM_Scripture').style.display = 'block';
        document.getElementById('SPM_A1').style.fontWeight = 'bold';
    }
    if(section == 'sermons')
    {
        document.getElementById('SPMNav2').style.backgroundImage = 'url(/images/40/btn_spm_selected.jpg)';
        document.getElementById('SPMNav2').style.backgroundPosition = 'right';
        document.getElementById('SPMNav2').style.backgroundRepeat = 'no-repeat';
        document.getElementById('SPM_Sermons').style.display = 'block';
        document.getElementById('SPM_A2').style.fontWeight = 'bold';
    }
    if(section == 'illustrations')
    {
        document.getElementById('SPMNav3').style.backgroundImage = 'url(/images/40/btn_spm_selected.jpg)';
        document.getElementById('SPMNav3').style.backgroundPosition = 'right';
        document.getElementById('SPMNav3').style.backgroundRepeat = 'no-repeat';
        document.getElementById('SPM_Illustrations').style.display = 'block';
        document.getElementById('SPM_A3').style.fontWeight = 'bold';
    }
    if(section == 'videos')
    {
        document.getElementById('SPMNav4').style.backgroundImage = 'url(/images/40/btn_spm_selected.jpg)';
        document.getElementById('SPMNav4').style.backgroundPosition = 'right';
        document.getElementById('SPMNav4').style.backgroundRepeat = 'no-repeat';
        document.getElementById('SPM_Videos').style.display = 'block';
        document.getElementById('SPM_A4').style.fontWeight = 'bold';
    }
    if(section == 'powerpoints')
    {
        document.getElementById('SPMNav5').style.backgroundImage = 'url(/images/40/btn_spm_selected.jpg)';
        document.getElementById('SPMNav5').style.backgroundPosition = 'right';
        document.getElementById('SPMNav5').style.backgroundRepeat = 'no-repeat';
        document.getElementById('SPM_PowerPoints').style.display = 'block';
        document.getElementById('SPM_A5').style.fontWeight = 'bold';
    }
    
    if(section == 'more')
    {
        document.getElementById('SPMNav6').style.backgroundImage = 'url(/images/40/btn_spm_selected.jpg)';
        document.getElementById('SPMNav6').style.backgroundPosition = 'right';
        document.getElementById('SPMNav6').style.backgroundRepeat = 'no-repeat';
        document.getElementById('SPM_More').style.display = 'block';
        document.getElementById('SPM_A6').style.fontWeight = 'bold';
    }
}

function UnSelectAllSPM() //'spm stands for Service Preparation Module on homepage.
{
    document.getElementById('SPMNav1').style.backgroundImage = 'url(/images/40/btn_spm_not_selected.jpg)';
    document.getElementById('SPMNav2').style.backgroundImage = 'url(/images/40/btn_spm_not_selected.jpg)';
    document.getElementById('SPMNav3').style.backgroundImage = 'url(/images/40/btn_spm_not_selected.jpg)';
    document.getElementById('SPMNav4').style.backgroundImage = 'url(/images/40/btn_spm_not_selected.jpg)';
    document.getElementById('SPMNav5').style.backgroundImage = 'url(/images/40/btn_spm_not_selected.jpg)';
    document.getElementById('SPMNav6').style.backgroundImage = 'url(/images/40/btn_spm_not_selected.jpg)';
    document.getElementById('SPM_Scripture').style.display = 'none';
    document.getElementById('SPM_Sermons').style.display = 'none';
    document.getElementById('SPM_Illustrations').style.display = 'none';
    document.getElementById('SPM_Videos').style.display = 'none';
    document.getElementById('SPM_PowerPoints').style.display = 'none';
    document.getElementById('SPM_More').style.display = 'none';
    document.getElementById('SPM_A1').style.textDecoration = 'none';
    document.getElementById('SPM_A2').style.textDecoration = 'none';
    document.getElementById('SPM_A3').style.textDecoration = 'none';
    document.getElementById('SPM_A4').style.textDecoration = 'none';
    document.getElementById('SPM_A5').style.textDecoration = 'none';
    document.getElementById('SPM_A6').style.textDecoration = 'none';
    document.getElementById('SPM_A1').style.fontWeight = 'normal';
    document.getElementById('SPM_A2').style.fontWeight = 'normal';
    document.getElementById('SPM_A3').style.fontWeight = 'normal';
    document.getElementById('SPM_A4').style.fontWeight = 'normal';
    document.getElementById('SPM_A5').style.fontWeight = 'normal';
    document.getElementById('SPM_A6').style.fontWeight = 'normal';
   
    
}


function toggleSermonPageRateThis()
{
    
    if(document.getElementById('SermonPageRateThis').style.display == "none")
    {
        document.getElementById('SermonPageRateThis').style.display = "block";
    }
    else
    {
        document.getElementById('SermonPageRateThis').style.display = "none";
    }

}

// this function toggles the Contributor Menu on the main Navigation.
function toggleContributorMenu()
{
    document.getElementById('ProMenu').style.display = "none";
    if(document.getElementById('ContributorMenu').style.display == "none")
    {
        document.getElementById('ContributorMenu').style.display = "block";
    }
    else
    {
        document.getElementById('ContributorMenu').style.display = "none";
    }
}

// this function toggles the Pro Menu on the main Navigation.
function toggleProMenu()
{
    document.getElementById('ContributorMenu').style.display = "none";
    if(document.getElementById('ProMenu').style.display == "none")
    {
        document.getElementById('ProMenu').style.display = "block";
    }
    else
    {
        document.getElementById('ProMenu').style.display = "none";
    }
}

// this function determines whether the event is the equivalent of the microsoft
// mouseleave or mouseenter events. It is used on the main menu dropdowns for Contributor and Pro Menus.
// it is also used for the "More" link on the Run of Site Searchbar.
function isMouseLeaveOrEnter(e, handler)
{		
	if (e.type != 'mouseout' && e.type != 'mouseover') return false;
	var reltg = e.relatedTarget ? e.relatedTarget :
	e.type == 'mouseout' ? e.toElement : e.fromElement;
	while (reltg && reltg != handler) reltg = reltg.parentNode;
	return (reltg != handler);
}


