// Constant Settings
var ie,ns4,ns6;

if (document.all)
  ie = true;
else if (document.layers)
  ns4 = true;
else if(document.getElementById)
  ns6 = true;
  
/////////////////////////////////////////////////////////////////////////////////////////////////
// Common functions

function setPointer(s)
{
  document.body.style.cursor = s; // set mouse pointer
}

function getelement(id)
{
  el = document.all ? document.all[id] : document.getElementById(id);
  return el;
}

function getQueryVariable(variable) 
{
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) 
  {
    var pair = vars[i].split("=");
    if (pair[0] == variable) 
      return pair[1];
  } 
  
  return null;
}

function showhide(id, show) 
{
  el = getelement(id);
  if(el.style) 
    els = el.style;
  else
    els = null;
  
  if (el && els)
  {
    if (show)
      els.display = 'block';
    else 
      els.display = 'none'; 
  }
}

function altshowhide(id) 
{
  el = getelement(id);
  if(el.style) 
    els = el.style;
  else
    els = null;
  
  if (el && els)
  {
    if ( (els.display == 'block') || (els.display == 'visible') )
      els.display = 'none';
    else 
      els.display = 'block'; 
  }
}

function Open(page, name, width, height)
{
  var winl;
  var wint;

  if(width < screen.width)
    winl = (screen.width - width) / 2;
  else
    winl = 10;

  if(width < screen.height)
    wint = (screen.height - height) / 2;
  else
    wint = 10;

  OpenWin = this.open(page, name, 'width=' + width + ',height=' + height + ',top=' + wint + ',left=' + winl +
                      ',toolbar=no,menubar=no,location=no,status=yes,scrollbars=yes,resizable=yes');
}

function OpenHelp(page)
{
  OpenWin = this.open(page, 'Help', 'toolbar=yes,menubar=yes,status=yes,scrollbars=yes,resizable=yes');
}

function OpenFixed(page, name, width, height)
{
  var winl;
  var wint;

  if(width < screen.width)
    winl = (screen.width - width) / 2;
  else
    winl = 10;

  if(width < screen.height)
    wint = (screen.height - height) / 2;
  else
    wint = 10;

  OpenWin = this.open(page, name, 'width=' + width + ',height=' + height + ',top=' + wint + ',left=' + winl +
                      ',toolbar=no,menubar=no,location=no,status=no,scrollbars=no,resizable=no');
}

function OpenReport(page, name)
{
  var width = 620;
  var height = 400;
  var winl;
  var wint;

  if(width < screen.width)
    winl = (screen.width - width) / 2;
  else
    winl = 10;

  if(width < screen.height)
    wint = (screen.height - height) / 2;
  else
    wint = 10;  
 
  OpenWin = this.open(page, name, 'width=' + width + ',height=' + height + ',top=' + wint + ',left=' + winl +
                                  ',toolbar=yes,menubar=yes,location=no,status=yes,scrollbars=yes,resizable=yes');
}

function GetSelectedValue(selectbox)
{
  if( !selectbox )
    return null;
  
  return selectbox.options[selectbox.selectedIndex].value;
}

function GetCheckedValue(checkbox)
{
  if( !checkbox )
    return null;
    
  for (i = 0; i < checkbox.length; i++)
  {
    if(checkbox[i].checked)
    {
      return checkbox[i].value;
    }
  }
  return null;
}

function setChoice(radio, value)
{
  var bSelectionMade = false;
  
  if( !radio || !value )
    return false;

  for (i = 0; i < radio.length; i++)
  {
    if (radio[i].value == value)
    {
      radio[i].checked = true;
      bSelectionMade = true;
    }
  }

  return bSelectionMade;
}

function SetSelectedValue(selectbox, value)
{
  if( !selectbox || !value)
    return false;
    
  for(i = 0; i < selectbox.options.length; i++)
  {
    if(selectbox.options[i].value == value)
    {
      selectbox.options[i].selected = true;
      return true;
    }
  }
  return false;
}

function SetSelectionName(selectbox, value, name)
{
  if( !selectbox || !value || !name)
    return false;
    
  for(i = 0; i < selectbox.options.length; i++)
  {
    if(selectbox.options[i].value == value)
    {
      selectbox.options[i].text = name;
      return true;
    }
  }
  return false;
}

function SetCheckedValue(checkbox, value)
{
  if( !checkbox || !value )
    return false;
    
  for (i = 0; i < checkbox.length; i++)
  {
    if(checkbox[i].value == value)
    {
      checkbox[i].checked = true;
      return true;
    }
  }
  return false;
}

function OnlyNumbers(textbox)
{
  var accept = "1234567890";
  
  if( textbox.value.match(/[^0-9]/gi) )
  {
    textbox.value = textbox.value.replace(/[^0-9]/gi, '');
    alert('Please only enter numbers.');
    return false;
  }
}

function IsValid(name)
{ 
  var str = name;
  var valid="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_ "
  
  if(name.length == 0)
    return -1;

  for (var i=0; i < str.length; i++)
  {
    if ( valid.indexOf(name.charAt(i)) < 0 ) 
      return -2;
  }

  return 1;
}

function IsValidNumber(name)
{ 
  if ( text.match(/[^0-9]/gi) ) 
    return false;

  return true;
}

function isDefined(param) 
{
  if (param) 
    return true;
  else 
  {
    if ( param == false)
      return true
    else
      return false
  }
}

function ChangeColor(element, bgcolor, textcolor)
{
  element.style.backgroundColor = bgcolor;
  element.style.color = textcolor;
}

function SelectDivLink(s)
{
  var div = getelement(s + 'Div');
  var link = getelement(s + 'Link');
 
  if( div )
    div.style.display = 'block';
  if( link )
    link.style.color = 'white';
}

function UnselectDivLink(s)
{
  var div = getelement(s + 'Div');
  var link = getelement(s + 'Link');
  
  if( div )
    div.style.display = 'none';
  if( link )
    link.style.color = 'gray';
}

function show(s)
{
  var header;
  var div;
  
  getelement('GameReportsMenuDiv').style.display = 'none'; 
  getelement('ScheduleMenuDiv').style.display = 'none'; 
  getelement('StandingsMenuDiv').style.display = 'none'; 
  if( s != '')
  {
    header = getelement(s + "Header");
    div = getelement(s + "Div");
    div.style.top = window.event.clientY + 15;
    div.style.left = window.event.clientX;
    div.style.position = 'absolute'; 
    div.style.display = 'block'; 
  }
}

var popup;

function CreatePopup(title, content)
{
  var html;
  
  if( title.length <= 0 )
    alert('Popup title is empty');

  if( content.length <= 0 )
    alert('Popup content is empty');
 
  popup = window.open('popup.htm?Content='+content,'scripture','width=250,height=180,scrollbars=yes');
}

function WriteScripture(content)
{
  if( content == "Romans 3:23" )
    content = '<B>Romans 3:23 KJV</B><BR><BR>"For all have sinned and come short of the glory of God."';
  else if( content == "Ephesians 2:8" )
    content = '<B>Ephesians 2:8 KJV</B><BR><BR>"For by grace are ye saved through faith; and that not of yourselves: it is the gift of God."';
  else if( content == "Acts 2:21" )
    content = '<B>Acts 2:21 KJV</B><BR><BR>"And it shall come to pass, that whosoever shall call on the name of the Lord shall be saved."<BR><BR>'+
              '<B>Romans 10:9-13 KJV</B><BR><BR>&nbsp;&nbsp;9 "That if thou shalt confess with thy mouth the Lord Jesus, and shalt believe in thine heart that God hath raised him from the dead, thou shalt be saved."<br>'+
              '&nbsp;&nbsp;10 "For with the heart man believeth unto righteousness; and with the mouth confession is made unto salvation."<br>'+
              '&nbsp;&nbsp;11 "For scripture saith, whosoever believeth on Him shall not be ashamed."<br>'+
              '&nbsp;&nbsp;12 "For there is no difference between the Jew and the Greek: for the same Lord over all is rich unto all that call upon him."<br>'+
              '&nbsp;&nbsp;13 "For whosoever shall call upon the Name of the Lord shall be saved."';
  else if( content == "Acts 2:41" )
    content = '<B>Acts 2:41 KJV</B><BR><BR>"Then they that gladly received his word were baptized: and the same day there were added unto them about three thousand souls."<BR><BR>'+
              '<B>Matthew 28:19-20 KJV</B><BR><BR>&nbsp;&nbsp;19 "Go ye therefore, and teach all nations, baptizing them in the name of the Father, and of the Son, and of the Holy Ghost:"<BR>'+
              '&nbsp;&nbsp;20 "Teaching them to observer all things whatsoever I have commanded you: and, lo, I am with you alway, even unto the end of the world. Amen."';
  else if( content == "Acts 2:41-47" )
    content = '<B>Acts 2:41-47 KJV</B><BR><BR>&nbsp;&nbsp;41 "Then they that gladly received his word were baptized: and the same day there were added unto them about three thousand souls."<BR>'+
              '&nbsp;&nbsp;42 "And they continued steadfastly in the apostles\' doctrine and fellowship, and in breaking of bread, and in prayers."<BR>'+
              '&nbsp;&nbsp;43 "And fear came upon every soul: and many wonders and signs were done by the apostles."<BR>'+
              '&nbsp;&nbsp;44 "And all that believed were together, and all things common."<BR>'+
              '&nbsp;&nbsp;45 "And sold their possessions and goods and parted them to all men, as every man had need."<BR>'+
              '&nbsp;&nbsp;46 "And they, continuing daily with one accord in the temple, and breaking bread from house to house, did eat their meat with gladness and singleness of heart"<BR>'+
              '&nbsp;&nbsp;47 "Praising God, and having favor with all people.  And the Lord added to the church daily such as should be saved."';
  else if( content = "John 14:6" )
    content = '<B>John 14:6 KJV</B><BR><BR>"Jesus saith unto him, I am the way, the truth, and the life: no man cometh unto the Father, but by me."';

  document.write(content);  
}

function WriteHeader()
{
  var date = new Date();
  var time = date.getUTCSeconds();
  var el = getelement('HeadingRight');

  document.write('<TR><TD valign="bottom" class="HeadingTitle">Pidcoke Baptist Church</TD>');

  if( (time % 3) == 1 )
    document.write('<TD id="HeadingRight" rowspan=2 class="HeadingRight" style="background-image:url(_images/crossbw-small.jpg);">&nbsp;</TD></TR><TR><TD valign=top class="HeadingTimes">');
  else if( (time % 3) == 2 )
    document.write('<TD id="HeadingRight" rowspan=2 class="HeadingRight" style="background-image:url(_images/biblebw.jpg);">&nbsp;</TD></TR><TR><TD valign=top class="HeadingTimes">');
  else
    document.write('<TD id="HeadingRight" rowspan=2 class="HeadingRight" style="background-image:url(_images/dovebw.jpg);">&nbsp;</TD></TR><TR><TD valign=top class="HeadingTimes">');

  document.write('Pastor - Brother Nathan Booth<BR>Sunday Bible Study - 10:00 AM<BR>Sunday Worship Service - 11:00 AM<BR>');
  document.write('<A href="HowToBeSaved.htm" style="color:red;font-size:12px;font-style:italic">How can I be saved?</A></TD></TR>');
}

function WriteFooter()
{
  var sLastUpdate = document.lastModified;

  CreateFooterMenu();
  document.write('<BR><BR>Serving the Copperas Cove, Gatesville, Fort Hood, and Killeen, Texas area since 1884.<br><br><a border=1 href="http://www.sbc.net/" target="sbc">');
  document.write('<img src="_images/sbcnet.gif" border=0 vspace=1 hspace=1 alt="Visit SBC.Net">');
  document.write('</a><BR>Member of the Southern Baptist Convention<BR>For comments or suggestions please contact the <a class="FooterLink" href="mailto:jrox6279@gmail.com?subject=Comment%20or%20Suggestion">Web Administrator</a>.<BR>Copyright © 2004-2010 Pidcoke Baptist Church. All rights reserved.');
}