﻿
// ++++++++++ Base Master Page Search Box ++++++++++
function SearchFocus()
{
  if (this.hasValue == false)
  {
    this.value = '';
    this.style.color = "#000";
  }
};

function SearchBlur()
{
  if (this.hasValue == false)
  {
    this.value = "Search";
    this.style.color = "#999";
  }
};

function SubmitSearch()
{
  var txt = document.getElementById("txtSearch");
  if (txt.hasValue == false)
  {
    alert("Search terms are empty\n");
  }
};

function SubmitKeyCheck(e)
{
  var ret = false;
  switch(e.keyCode)
  {
    case 13:
      ret = true;
      SubmitSearchCheck();
      break;
    case 32:
      if (this.value.length > 0)
      {
        ret = true;
      }
      break;
    default:
      ret = true;
      break;
  }
  
  return ret;
};

function ValidateSearchValue()
{
  this.hasValue = (this.value.length > 0);
};

function RegisterSearchBoxEvents()
{
  var btn = new Object();
  btn = document.getElementById("ctl00_ctl00_btnSearch");
  btn.onclick = SubmitSearch;
  
  var txt = new Object();
  txt = document.getElementById("txtSearch");
  txt.style.color = "#999";
  txt.hasValue = false;
  txt.onkeydown = SubmitKeyCheck;
  txt.onkeyup = ValidateSearchValue;
  txt.onfocus = SearchFocus;
  txt.onblur = SearchBlur;
};
// ~~~~~~~~~~ Base Master Page Search Box ~~~~~~~~~~

// ++++++++++ Base Master Page Logo Switching ++++++++++
var logos = new Array();

function AddHeaderLogo(logoPath)
{
  logos[logos.length] = logoPath;
};

function ShowRandomLogo()
{
  if (logos.length > 0)
  {
    var pick = Math.floor(logos.length * Math.random());
    var imgHeaderLogo = document.getElementById("ctl00_ctl00_imgHeaderLogo");
    imgHeaderLogo.src = logos[pick];
  }
};
// ~~~~~~~~~~ Base Master Page Logo Switching ~~~~~~~~~~

// ++++++++++ Item Pickers ++++++++++
  function itemPicker(parentId) {
    var _images = $("#" + parentId + " .imgOuter");
    var _textBlocks = $("#" + parentId + " .textOuter");
    
    if (_images.length != _textBlocks.length) {
      alert("ERROR: There are different numbers of rotating images (" + itemPicker.images.length + ") than text blocks (" + itemPicker.textBlocks.length + ").");
      //break;
      
    } else {          
      /* hide all items to traverse except for first */
      $(_images).hide();
      $(_images[0]).show();
      
      $(_textBlocks).hide();
      $(_textBlocks[0]).show();
      
      var nextButton = new Object();
      //nextButton.name = parentId + 'right');
      nextButton = $("#" + parentId + " .rightLink");
      var prevButton = new Object();
      //prevButton.name = parentId + 'left';
      prevButton = $("#" + parentId + " .leftLink");
      
      nextButton.click(function(){ changeImage('next'); });
      prevButton.click(function(){ changeImage('prev'); });
    }  
  
  function changeImage(type) {
    
    var currentIndex = null;
    //alert("rotate.images.length " + rotate.images.length);
    
    /* find currently selected item */
    for (i = 0; i < _images.length; i++) {
      if ($(_images[i]).is(':visible')) {
        currentIndex = i;
        break;
      }
    }
    
    //alert("currentIndex " + currentIndex);
    
    var newIndex = null;
    
    /* determine new item to show */
    if (type == 'next') {
      newIndex = (currentIndex < (_images.length-1)) ? (currentIndex+1) : 0;
    } else {
      newIndex = (currentIndex > 0) ? (currentIndex-1) : (_images.length-1);
    }
    
    //alert("newIndex " + newIndex);
    
    $(_images[currentIndex]).hide();
    $(_images[newIndex]).show();
    
    $(_textBlocks[currentIndex]).hide();
    $(_textBlocks[newIndex]).show();
  }
}
// ~~~~~~~~~~ Item Pickers ~~~~~~~~~~
