// Initialize the Scripts for this site.

$(document).ready(function() {
  
   if (window.location.href.indexOf("path=%2Fdealer-area") > -1)
   dealerArea();
    
    // Opens up Smart Solutions in new window.
    $('.lnkBlank').click(function() {
        window.open($(this).attr('href'), 'newWindow', '');
        return false;
    });
    
    //[[jsClearSearch]]
  
  // Change the Radio Button
  $(".DealerRegistration .radio input[type=radio]").change(function() {
        var test = $(this).val();
        $(".AddressMailing").removeClass('open');
        $(".AddressMailing."+test).addClass('open');
    }); 
    
    // Selects text in Search Box when focused:
    $('input[type=text].clearText').each(function() {
        $(this).css({'color':'#929292'});
        var txtSearchText = $(this).val();
        $(this).focus(function() {
            if ($(this).val() == txtSearchText) {
                $(this).val('');
                $(this).css({'color':'#153678'});
            }
        });
        $(this).blur(function() {
            if ($(this).val() == '') {
                $(this).val(txtSearchText);
                $(this).css({'color':'#929292'});
            }
        });
        
        if ($(this).hasClass('validate')) {
            $(this).parent().parent().submit(function() {
                //alert($(this).find('input[type=text]').val()+'|'+txtSearchText);
                if ($(this).find('input[type=text]').val() == txtSearchText) {
                    alert('Please enter a valid search term')
                    return false;
                }
            });
        }
    
    });
    
    // Hides list item images if no src is defined:
    
    $('img.listItemImage').each(function() {
        if ($(this).attr('src') == '') {
            $(this).hide();
        }
    });
    
    $('#rightBox').append('<img src="/right-col-footer.png" width="270" height="13" alt="" id="bottom" />');
    
  var blogFeed = $('.blogFeed');
  var date;
  var bmonth = '';
  var bday = '';
  var byear = '';
  if (blogFeed.size() >0) {
    blogFeed.find('li span.date').each(function() {
      date = $(this).text();
      date.replace(' +0000','');
      bmonth = date.slice(7,11);
      bday = date.slice(5,7);
      byear = date.slice(12,17);
      $(this).text(bmonth+'/'+bday+'/'+byear)
    });
  }
  blogFeed.find('li').hide();
  var feedMaxItems = 3;
  for (i=0;i<feedMaxItems;i++) {
    //alert(i);
    blogFeed.find('li:eq('+i+')').show();
  }
  
  //alert(feedTotal);
  
  
});

function dealerArea(){
// alert('hello');
  $('#column1 form').addClass('dealerForm')
  $('form.dealerForm').append('<div class="dealerFormLogin" style="margin-top:10px;"><p><a href="/lost-password/">Lost Password</a></p><h2>Not a dealer yet? Click <a href="/dealer-registration/">here</a></h2></div>');
  $('form.dealerForm').prepend('<div class=""><h1>Dealer Login</h1></div>');
}

