// browse

var delayed_run_timer = 0;

function IsNumeric(sText) {
   var ValidChars="0123456789.";
   var IsNumber=true;
   var Char;
   for (i=0; i<sText.length&&IsNumber==true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char)==-1) { IsNumber=false; }
   }
   return IsNumber;
}

function post_rating_change( index, checked ) {
	if (delayed_run_timer) { window.clearTimeout(delayed_run_timer); }
	browse_rating[index] = (checked?1:'0');
	delayed_run_timer = window.setTimeout('delayed_run()',700);
}

function delayed_run() { 
	location.href = page_url + '?rated_nr='+browse_rating[0]+'&rated_g='+browse_rating[1]+
						'&rated_pg='+browse_rating[2]+'&rated_pg13='+browse_rating[3]+
						'&rated_r='+browse_rating[4]+'&rated_nc17='+browse_rating[5];
}

function browse_settings_change(el) {
	var elem;
	var uri = page_url;
	switch (el) {
		case 'browse-sort-by': 
			elem = document.getElementById('browse_sort_by');
			uri += '?sort_by='+elem.value;
			break;	
		case 'browse-sort-by-direction':
			uri += '?sort_by_direction='+_b_sort_by_direction;
			break;
		default : uri = '';
	}
	if (uri) { location.href = uri; }
}

function _b_hl(el,hl) {
	if (typeof(el)!='object') { if(!(el=document.getElementById(el))) { return false; } }
	el.style.backgroundColor = (hl?'#eaedf6':'#ffffff');								
}

function _b_go(u) { location.href = u; }

function _b_hl_htl( id, hl ) {
	var el = document.getElementById(id);
	el.src = '/images/buttons/' + (_b_sort_by_direction=='htl'?'high_to_low':'low_to_high')+(hl?'_h':'') + '.gif';
}

function price_limit() {
	var _p_all_min = document.getElementById('price_all_min').value;
	var _p_all_max = document.getElementById('price_all_max').value;
	var _p_cinematic_min = document.getElementById('price_cinematic_min').value;
	var _p_cinematic_max = document.getElementById('price_cinematic_max').value;
	var _p_video_min = document.getElementById('price_video_min').value;
	var _p_video_max= document.getElementById('price_video_max').value;
	var _p_free_tv_min = document.getElementById('price_free_tv_min').value;
	var _p_free_tv_max = document.getElementById('price_free_tv_max').value;
	var _p_vod_min = document.getElementById('price_vod_min').value;
	var _p_vod_max = document.getElementById('price_vod_max').value;
	var _p_ppv_min = document.getElementById('price_ppv_min').value;
	var _p_ppv_max = document.getElementById('price_ppv_max').value;
	 
	
	var uri = 'price_all_rights_min='+( IsNumeric(_p_all_min) ? _p_all_min : '!'  ) ;
	uri += '&price_all_rights_max='+(IsNumeric(_p_all_max) ? _p_all_max : '!') ;
	uri += '&price_cinematic_min='+(IsNumeric(_p_cinematic_min ) ? _p_cinematic_min  : '!') ;
	uri += '&price_cinematic_max='+(IsNumeric(_p_cinematic_max ) ? _p_cinematic_max  : '!') ;
	uri += '&price_video_min='+(IsNumeric(_p_video_min) ? _p_video_min : '!') ;
	uri += '&price_video_max='+(IsNumeric(_p_video_max ) ? _p_video_max  : '!') ;
	uri += '&price_free_tv_min='+(IsNumeric(_p_free_tv_min ) ? _p_free_tv_min  : '!') ;
	uri += '&price_free_tv_max='+(IsNumeric(_p_free_tv_max ) ? _p_free_tv_max  : '!') ;
	uri += '&price_vod_min='+(IsNumeric(_p_vod_min) ? _p_vod_min : '!') ;
	uri += '&price_vod_max='+(IsNumeric(_p_vod_max ) ? _p_vod_max  : '!') ;
	uri += '&price_ppv_min='+(IsNumeric(_p_ppv_min) ? _p_ppv_min : '!') ;
	uri += '&price_ppv_max='+(IsNumeric(_p_ppv_max ) ? _p_ppv_max  : '!') ;
	
	if (uri) { location.href = page_url + '?' + uri; }
}

function sort_by_change_direction() {
	if ( _b_sort_by_direction=='htl' ) {
		_b_sort_by_direction='lth';
	} else {
		_b_sort_by_direction='htl';
	}
	_b_hl_htl('sort_by_direction', 1);
	browse_settings_change('browse-sort-by-direction');
}

$(document).ready( function() {
	// $(".auction_images").nyroModal();	
	$(".bm_td2_fm_d2").hover( function() { $(this).animate( { height:  $(this).attr('scrollHeight' ) }, 'fast' );/* $(this).addClass("bsynhov");*/ }, function() { $(this).animate( { height: '70px' }, 'fast' ); /* $(this).removeClass("bsynhov"); */ } );
} );


function keyhandler(event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) { price_limit(); }
}