﻿//<!--
var emailRequest;
var emailAddress;
var message;
var currentSection = '';
var oldSection = '';

var scrollRate = 2;     //rate of scrolling for IE (pixels)
var scrollSpeed = 10;   //rate of scrolling for IE (time)
var currentTop = 0;     //default the scroll box to the top
var contentHeight = 0;  //height of the actual content

function SendMessage()
{
    var form = document.getElementById('frmSendMessage');
    
    emailAddress = document.getElementById('msgEmailAddress');
    message = document.getElementById('msgMessage');
    name = document.getElementById('msgName');
    path = document.getElementById('msgPath');
    
    if (isEmail(emailAddress) == true && message.value != '' && name.value != '')
    {
        var formData = '&message=' + message.value + '&emailAddress=' + emailAddress.value + '&name=' + name.value + '&path=' + path.value;
        
        emailRequest = createRequest();
	    emailRequest.open("POST", form.action, true);
	    emailRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    emailRequest.onreadystatechange = updateEmailForm;
	    emailRequest.send(formData);
	}
	else if (name.value == '')
	{
	    name.focus();
	    alert('Please enter your name.');
	}
	else if (isEmail(emailAddress) == false)
	{
	    emailAddress.focus();
	    alert('Please enter a valid e-mail address.');
	}
	else
	{
	    message.focus();
	    alert('Please enter a message to send to this ministry.');
	}
}

function emailThanks()
{
     var emailForm = document.getElementById('emailForm');
     var emailThanks = document.getElementById('emailThanks');
     
     emailForm.style.display = 'none';
     emailThanks.style.display = 'block';
}

function updateEmailForm()
{
    if (emailRequest.readyState == 4)
	{
		if (emailRequest.status == 200)
		{
		    emailThanks();                  
		}
	}
}

function Hide(oldSectionId)
{
    lnkSection = document.getElementById(oldSectionId);
    lnkSection.style.color = '#039';

    liSection = lnkSection.parentNode;
    liSection.style.backgroundPosition = 'top left';

    iSection = document.getElementById(oldSectionId.replace('lnk', 'i'));
    iSection.className = 'ihidden';   
}

function Show(sectionId, url)
{
    HideScrollBar();

    oldSection = currentSection;
    currentSection = sectionId;
    
    if (oldSection != '')
        Hide(oldSection);
        
    lnkSection = document.getElementById(currentSection);
    lnkSection.style.color = '#fff';
        
    liSection = lnkSection.parentNode;
    liSection.style.backgroundPosition = 'top right';
      
    iSection = document.getElementById(currentSection.replace('lnk', 'i'));
    iSection.className = 'ishown';
     
        
    pageHitRequest = createRequest();
		url = url + currentSection.replace('lnk', '') + '/';
		pageHitRequest.open("GET", url, true);
		pageHitRequest.send("void");
	
		return false;
}

function PageHit(sectionId, url)
{
    pageHitRequest = createRequest();
	url = url + sectionId.replace('lnk', '') + '/';
	pageHitRequest.open("GET", url, true);
	pageHitRequest.send("void");
	
	return true;
}

function createRequest()
{	
	var xmlHTTP;
	try 
	{
		xmlHTTP = new XMLHttpRequest();
	} 
	catch (trymicrosoft) 
	{
		try 
		{
			xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (othermicrosoft) 
		{
			try 
			{
				xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (failed) 
			{
				xmlHTTP = false;
			}
		}
	}
	return xmlHTTP;
}

function ShowScrollBar(id)
{
    iBar = document.getElementById(id + 'Up');
    iBar.style.display = 'block';
    iBar.style.right = '0px';
    
    iBar = document.getElementById(id + 'Down');    
    iBar.style.display = 'block';
    iBar.style.right = '0px';
}

function HideScrollBar(id)
{
    iBar = document.getElementById('iScrollUp');
    iBar.style.display = 'none';
    iBar.style.right = '-1000px';
    
    iBar = document.getElementById('iScrollDown');
    iBar.style.display = 'none';
    iBar.style.right = '-1000px';
}

function initializeArchives()
{
    stopAll();
    
    if (document.getElementById('archivesScrollBox') == null)
    {
        scrollRate = 8;
        scrollSpeed = 20;
    }   
    currentTop = 0;
    contentObj = document.getElementById('ArchivesScrollBox');
    contentObj.style.top = '0px';
    contentHeight = 0 - contentObj.offsetHeight;
    
    if (contentObj.offsetHeight > 245)
        ShowScrollBar('iScroll');
        
    return false;
}

function initializeDetails()
{
    stopAll();
    
    if (document.getElementById('detailsScrollBox') == null)
    {
        scrollRate = 8;
        scrollSpeed = 20;
    }   
    currentTop = 0;
    contentObj = document.getElementById('DetailsScrollBox');
    contentObj.style.top = '0px';
    contentHeight = 0 - contentObj.offsetHeight;
    
    if (contentObj.offsetHeight > 245)
        ShowScrollBar('iScroll');
        
    return false;
}

function scrollDown(id)
{
    if (currentTop >= (contentHeight + 245))
    {
        currentTop = currentTop - scrollRate;
        contentObj.style.top = currentTop + 'px';
        
        var scrollId = "scrollDown(" + id + ")";
        scrollTimerDown = setTimeout('scrollDown()', scrollSpeed);
    }
}

function scrollUp(id)
{
    if (currentTop <= (0 - scrollRate))
    {
        currentTop = currentTop + scrollRate;
        contentObj.style.top = currentTop + 'px';

        var scrollId = "scrollUp(" + id + ")";
        scrollTimerUp = setTimeout('scrollUp()', scrollSpeed);
    }
}

function stopAll()
{
    if(window.scrollTimerUp)
		clearTimeout(scrollTimerUp);
		
	if(window.scrollTimerDown)
		clearTimeout(scrollTimerDown);
}


//Window OnLoad Function --- automatically sets the button "clicked" to 'Today's Broadcast'
window.onload = function()
{
    Show('lnkBroadcast', originalPath);
}
//-->
