               /* ................................................. */
               /* file: shepher.js                                  */
               /* author: Ted O'Hara                                */
               /* purpose: Shepher theme specific scripts           */                       
               /* Created: 07/29/2009                               */
               /* Copyright (C) 2008 - 2010 bx.com, Inc.            */
               /* ................................................. */ 
               
function btnOn() 
  {
    var srcString = this.src
    srcString = srcString.replace(/.gif/,'_over.gif')
    this.src = srcString
  }
function btnOff() 
  {
    var srcString = this.src
    srcString = srcString.replace(/_over.gif/,'.gif')
    this.src = srcString
  }
  
// ==== WeldingMart theme specific. Namespaced ----------------------------------------------------
  
var shepherTheme = new Object() //namespace for music theme specific code

//Initialize form fields
shepherTheme.initFormFields = function()
  {

    var formfields = [ {fm:document.shep_login, fld:'username',ds:'Enter Username'},
                       {fm:document.searchform, fld:'search_string',ds:'Search Site'}]
    
    var selectedForm,formfield;
    
    for (var bt = 0; bt < formfields.length; bt++)
      {
        selectedForm = formfields[bt].fm;
        if (selectedForm)
          {
            formfield = selectedForm.elements[formfields[bt].fld]
            if (formfield)
              {
                formfield.label = document.getElementById('lbl_' + formfield.id)
                if(formfield.label)
                  {
                    formfield.defaultString = formfield.label.firstChild.nodeValue;
                    formfield.label.style.display = 'none'
                  }
                else {formfield.defaultString = formfields[bt].ds;}
                
                formfield.onfocus = function(){if(this.value == this.defaultString) {this.value = '' }}
                formfield.onblur = function(){if(this.value == '') { this.value = this.defaultString }};
                formfield.onblur()  
              } //end, formfield exists
          } //end, if selected form
      } //end, for
  
  
  }//end, initFormFields
  
shepherTheme.showRealPassword = function()  
  {
    var realfield = document.getElementById('shep_password');
    this.style.display = 'none'
    realfield.style.display = ''
    realfield.focus()
  }

shepherTheme.showFauxPassword = function()  
  {
    var fauxfield = document.getElementById('shep_fauxpassword')
    if(this.value != '') {return false}
    this.style.display = 'none'
    fauxfield.style.display = ''
  }

shepherTheme.initCustomPassword = function()
  {
     var realfield = document.getElementById('shep_password')
     if(realfield == null) {return} //bail if doesn't exist
     var fauxfield = document.getElementById('shep_fauxpassword')
     realfield.onblur = this.showFauxPassword
     fauxfield.onfocus = this.showRealPassword
     realfield.onblur()
  }

//print page  
shepherTheme.printPage = function()
  {
    if (window.print) {self.print()}
    else {alert('Choose Print from the browser\'s File menu')}
  }
  

  
//shop by form event handlers
shepherTheme.handleShopBy = function()
  {
    var targetOption = this.options[this.selectedIndex]
    var targetId = targetOption.value
    var targetText = encodeURIComponent(targetOption.text.replace(/-/g,'')) + '/';
    if(targetId == '') return false
    if(this.id == 'shopbygroup') {var destination = '/category/' + targetText + targetId}
    else {var destination = '/manufacturer/' + targetText + targetId}
    window.location = destination;
  }
  
shepherTheme.initShopBy = function()
  {
    if(document.getElementById('shopbygroup')){document.getElementById('shopbygroup').onchange = this.handleShopBy}
    if(document.getElementById('shopbybrand')){document.getElementById('shopbybrand').onchange = this.handleShopBy}
  }
 
//Add a rollover event handler to images with a class of "ro" 
shepherTheme.initImages = function()
  {
    var pageImgs = document.getElementsByTagName('IMG');
    for (i = 0; i < pageImgs.length; i++)
      {  
        if (pageImgs[i].className == 'ro'){pageImgs[i].onmouseover = btnOn; pageImgs[i].onmouseout = btnOff; }
      }  
  }//END: init images
  
//adds rollover handlers to the search form 'Enter' button  
shepherTheme.initSubmits = function()
  {
    var idArray = ['goSearch'];
    for (var i = 0; i < idArray.length; i++)
      {
        var thisBtn = document.getElementById(idArray[i])
        if(thisBtn != null) {thisBtn.onmouseover = btnOn; thisBtn.onmouseout = btnOff;}
      }
    
  }
  




//add popup event handlers to all links in the content area.  
shepherTheme.checkLinks = function()
  {
    var context = document.getElementById('pagebody');
    if(context == null) {return false}
    var contentLx = context.getElementsByTagName('A')
    
    for (var cl = 1; cl < contentLx.length; cl++)
    {
      if (contentLx[cl].className.match(/popup/)) {contentLx[cl].onclick = function(){newwindow(this.href); return false}}
    }
  }


//Function to run all initialization
shepherTheme.initialize = function()
  {
    if (!(document.getElementById && document.getElementsByTagName && document.createElement)) {return false}
    
    this.checkLinks();
    this.initFormFields();      
    this.initImages();
    this.initSubmits();
    this.initShopBy();
    this.initCustomPassword()
  }
  
window.postAJAXfn = function() {shepherTheme.initialize()};
shepherTheme.initialize()


  

