var $j = jQuery.noConflict();

$j(document).ready(function() {

/* equals module 3 sub boxes height */
$j('div.m3_center_content').each(function(){
   var max_height = 0;
   
   $j(this).find('.m3_push_box_bg').each(function(){
      if ($j(this).height() > max_height) max_height = $j(this).height();
   });
   $j(this).find('.m3_push_box_bg').height(max_height);

});

/* next prev hide if first last result page */
if($j('input.current_page').val()){
if ($j('input.current_page').val() == '1') $j('a.news_filter_previous').hide();
if ($j('input.current_page').val() == $j('input.total_pages').val()) $j('a.news_filter_next').hide();
}

/* adds all odd elements class on RSE listing */
/* couldnt use odd een fucntionality because of asset grouping */
$j('ul.executives li:odd').addClass('m_left');

/* onchange function for search page sort by dropdown */
$j('select#search_page_28891_sort_by').change(function(){$j('#search_button').click();})

/* clears username and password fields */
$j('#usertype').change(function(){
 $j('#username').val("");
 $j('#password').val("");
});
  
/* adds target attribute to each form to external page */
$j('form.ext_form').attr('target','_blank');

/*adds target blank to each external link class a tag */
$j('a.external_link').attr('target','_blank');

/* rollover on hover  */
$j('#rollover').hover(
		function(){
        $j(this).attr("src", "http://www.digitaluk.co.uk/__data/assets/image/0006/14757/ban_last_hover.jpg");
     },
	    function(){
        $j(this).attr("src", "http://www.digitaluk.co.uk/__data/assets/image/0005/14756/ban_last.jpg");
     }
);

/* starts pcd trade view checkboxfunction on click */
$j("#trade_view").click(tradeChecked);


/* latest news - changes links to rss feed */
  var current_region = '#rsstvr_' + $j('form#page_asset_listing_29787 select').val();
  $j(current_region).each(function(){
    var newsfeed_link = $j(this).val();
    $j('.news_feed_link').attr('href',newsfeed_link);
  });

/* changes text indention on online option */
$j('#rse option[value="34340"]').text('Online')


/* for 5.1 registered equipment search */
$j('select#equipment_type').change(function(){
var et=document.getElementById('equipment_type').value;if ((et=='Aerial') || (et=='Cable')) {document.getElementById('extraoptions').style.display='none';} else {document.getElementById('extraoptions').style.display='block';}
});

});


/* function for postcode checker trade view checkbox */
function tradeChecked() {
      var n = $j("#trade_view:checked").length;
      if (n == '0'){$j('#fPostcodeCheck').attr('action','http://www.digitaluk.co.uk/postcodechecker/'); } 
      if (n == '1'){$j('#fPostcodeCheck').attr('action','http://www.digitaluk.co.uk/postcodechecker/main/trade/'); }
     
    }

$j(document).ready(function(){ 
if($j("#news_total_pages").val() == 1) $j(".news_sites").css("display","none");
else
{
if($j("#news_page").val()==1) $j(".news_filter_previous").css("display","none");
if($j("#news_page").val()==$j("#news_total_pages").val()) $j(".news_filter_next").css("display","none");
}
});