// JavaScript Document

if (pcs_newsSlideShowPix != null)
{
  var pcs_newsSlideShowNumPix = pcs_newsSlideShowPix.length;

  if (pcs_newsSlideShowNumPix > 0)
  {
    // Set slideShowSpeed (milliseconds)
    var pcs_newsSlideShowDelay = 5000;
    var pcs_slideTransitionTime=1;

    var pcs_timeout_t = 0;
    var pcs_slideIndex1 = 0;
    var pcs_slideIndex2 = 2;
    var pcs_slideIndex3 = 4;

    var pcs_slidePreLoad = new Array();
    for (i = 0; i < pcs_newsSlideShowNumPix; i++)
    {
      pcs_slidePreLoad[i] = new Image();
      pcs_slidePreLoad[i].src = pcs_newsSlideShowPix[i];
    }
  }

  var pcs_thisWeekNumItems = pcs_thisWeekName.length;
  var pcs_thisWeekIndex = 0;
}

function pcswat_SlideShow ()
{
  if (pcs_newsSlideShowNumPix > 0)
  {
    if (document.all)
    {
       document.images.SlideShow1.style.filter="blendTrans(duration="+pcs_slideTransitionTime+")";
       document.images.SlideShow1.filters.blendTrans.Apply();
       document.images.SlideShow2.style.filter="blendTrans(duration="+pcs_slideTransitionTime+")";
       document.images.SlideShow2.filters.blendTrans.Apply();
       document.images.SlideShow3.style.filter="blendTrans(duration="+pcs_slideTransitionTime+")";
       document.images.SlideShow3.filters.blendTrans.Apply();
    }

    document.images.SlideShow1.src = pcs_slidePreLoad[pcs_slideIndex1].src;
    document.images.SlideShow1.alt = pcs_newsSlideShowTitle[pcs_slideIndex1];
    document.images.SlideShow1.title = pcs_newsSlideShowTitle[pcs_slideIndex1];
    document.images.SlideShow2.src = pcs_slidePreLoad[pcs_slideIndex2].src;
    document.images.SlideShow2.alt = pcs_newsSlideShowTitle[pcs_slideIndex2];
    document.images.SlideShow2.title = pcs_newsSlideShowTitle[pcs_slideIndex2];
    document.images.SlideShow3.src = pcs_slidePreLoad[pcs_slideIndex3].src;
    document.images.SlideShow3.alt = pcs_newsSlideShowTitle[pcs_slideIndex3];
    document.images.SlideShow3.title = pcs_newsSlideShowTitle[pcs_slideIndex3];
   
    if (document.all)
	{
      document.images.SlideShow1.filters.blendTrans.Play();
      document.images.SlideShow2.filters.blendTrans.Play();
      document.images.SlideShow3.filters.blendTrans.Play();
	}

    if (++pcs_slideIndex1 > (pcs_newsSlideShowNumPix-1))
      pcs_slideIndex1 = 0;

    if (++pcs_slideIndex2 > (pcs_newsSlideShowNumPix-1))
      pcs_slideIndex2 = 0;

    if (++pcs_slideIndex3 > (pcs_newsSlideShowNumPix-1))
      pcs_slideIndex3 = 0;

    var thisWeekName = document.getElementById ("thisWeekName");
	var thisWeekProgram = document.getElementById ("thisWeekProgram");
	var thisWeekDateTimePlace = document.getElementById ("thisWeekDateTimePlace");
	thisWeekName.firstChild.nodeValue = pcs_thisWeekName[pcs_thisWeekIndex];
	thisWeekProgram.firstChild.nodeValue = pcs_thisWeekProgram[pcs_thisWeekIndex];
	thisWeekDateTimePlace.firstChild.nodeValue = pcs_thisWeekDateTimePlace[pcs_thisWeekIndex];

    if (++pcs_thisWeekIndex > (pcs_thisWeekNumItems-1))
      pcs_thisWeekIndex = 0;

    pcs_timeout_t = setTimeout('pcswat_SlideShow()', pcs_newsSlideShowDelay)
  }
}

function pcswat_GetNewsURL (slideShow)
{
  var index;
  switch (slideShow)
  {
  case 1:
    index = pcs_slideIndex1-1;
    break;
  case 2:
    index = pcs_slideIndex2-1;
    break;
  case 3:
    index = pcs_slideIndex3-1;
    break;
  default:
    break;
  }
  if (index < 0)
    index = pcs_newsSlideShowNumPix-1;
  location.href=pcs_newsSlideShowURL[index];
}

function pcswat_OnLoad ()
{
	pcswat_LoadChurchPix();
    pcswat_SlideShow();
}

function pcswat_LoadChurchPix ()
{
	var churchPixArray=new Array ("http://www.ecbc.org/english/images/template/ecbc001.jpg","http://www.ecbc.org/english/images/template/ecbc002.jpg","http://www.ecbc.org/english/images/template/ecbc003.jpg");
	var churchPixArraySize=3;
	var obj=MM_findObj("churchPix");
	if (obj!=null) {
	  var j=Math.round((churchPixArraySize-1)*Math.random());
	  obj.style.backgroundImage="url("+churchPixArray[j]+")";
	}
}

function pcswat_HideL2Menus ()
{
  var l2menus=new Array ("hideL2MenuLayer","ourMinistries-Children-MenuBar","ourMinistries-YouthCollege-MenuBar","ourMinistries-YoungAdults-MenuBar","ourMinistries-CareGroups-MenuBar","ourMinistries-Worship-MenuBar","ourMinistries-ChristianEd-MenuBar","ourMinistries-Missions-MenuBar","ourMinistries-Community-MenuBar");
  for (i=0;i<l2menus.length;i++)
  {
    var obj, m=l2menus[i];
    if ((obj=MM_findObj(m))!=null) obj.style.visibility="hidden";
    if ((obj=MM_findObj(m+"Shadow"))!=null) obj.style.visibility="hidden";
  }
}

function pcswat_ShowL2Menu (m)
{
  pcswat_HideL2Menus();
  var obj;
  if ((obj=MM_findObj(m))!=null) obj.style.visibility="visible";
  if ((obj=MM_findObj(m+"Shadow"))!=null) obj.style.visibility="visible";
  if ((obj=MM_findObj("hideL2MenuLayer"))!=null) obj.style.visibility="visible";
}

function pcswat_NoSpamEmail(obj)
{
  var username=obj.getAttribute("username");
  var domain=obj.getAttribute("domain");
  var s=username;
  s+=String.fromCharCode(64);
  s+=domain;
  obj.href="mailto:"+s;
}

function pcswat_Valid (input, type)
{
	switch (type) { case 'required': return (input.value != ''); break;	default: return true; }
}

function pcswat_ValidateForm(form)
{
	var errors = '';
	var autoSelect;
	for (var id in validation)
	{
		var label = validation[id][1];
		var requirements = validation[id][2];
		if (requirements.length > 0)
		{
			for (var i in requirements)
			{
				if (!pcswat_Valid (form.elements[id], requirements[i]))
				{
					errors += ('\n- ' + label + ': ' + requirements[i]);
					if (!autoSelect) autoSelect = form.elements[id];
				}
			}
		}
	}

	if (errors == '')
	{
		return true;
	}
	else
	{
		autoSelect.select();
		alert('Please fill in the following required fields\nbefore submitting this form:\n' + errors);
		return false;
	}
}

function pcswat_ToggleVisibility(id)
{
	var elem = document.getElementById(id);
	if (elem)
	{
		if (elem.style.visibility == 'hidden')
		{
			elem.style.visibility = 'visible';
			elem.style.display = 'block';
		}
		else
		{
			elem.style.visibility = 'hidden';
			elem.style.display = 'none';
		}
	}
}

function pcswat_ShowAllAnswers(num)
{
	for (i=0; i<num; i++)
	{
		var elem = document.getElementById('Answer' + (i+1));
		if (elem)
		{
			if (elem.style.visibility == 'hidden')
			{
				elem.style.visibility = 'visible';
				elem.style.display = 'block';
			}
		}
	}
}

function pcswat_HideAllAnswers(num)
{
	for (i=0; i<num; i++)
	{
		var elem = document.getElementById('Answer' + (i+1));
		if (elem)
		{
			if (elem.style.visibility == 'visible')
			{
				elem.style.visibility = 'hidden';
				elem.style.display = 'none';
			}
		}
	}
}
