function genSetRandDARTNumber()
{
	randDARTNumber = Math.round(Math.random()*1000000000000);
}

// site specific javascript

if (!$.browser.safari) {
	$(document).ready(function(){
		behavior_binder();
	});
} else {
	$(window).load(function(){
		behavior_binder();
	});
}


/*
Binds behaviors
** can be re-run whenever there are DOM changes
*/
function behavior_binder()
{
	$('.button_style').wrapInner('<span></span>');
	
	$('#header_search_input').click(function(){
		$('#header_search_input_label').hide();
	});
	
	if($('#header_search_input').val() != ""){
	  $('#header_search_input_label').hide();	
	} 
/* ADD FIRST/LAST TO LI
		adds a class 'first' to the first LI, and a 'last' to the last LI and 'first last' to a single LI
	*/
	$('ul').each(function(i){
		$(this).children('li:first').addClass('first');
		$(this).children('li:last').addClass('last');
	});
/* ADD FIRST/LAST TO DT/DD
		adds a class 'first' to the first DT and DD, and a 'last' to the last DT and DD and 'first last' to a single DT and DD
	*/
	$('dl').each(function(i){
		$(this).children('dt:first').addClass('first');
		$(this).children('dt:last').addClass('last');
		$(this).children('dd:first').addClass('first');
		$(this).children('dd:last').addClass('last');
	});
	$('form#page_controls select').bind('change',function(e){
		$('form#page_controls').submit();
	});
	$('form#search_form').submit(function(e){
		e.preventDefault();
		val=$('input#header_search_input').val();
		if(val==''){
			alert('Please enter a search term');
			
		}
		else{
			window.location.href='/search/'+escape(val);
		}
	});
	if($('dl.search_results_related dd.hidden').length){
		$('dl.search_results_related dd.hidden:eq(0)').before('<dd class="last more"><a href="#">more..</a></dd>');
		$('dl.search_results_related dd.more a').bind('click',function(e){display_more_related(e)});
	}
	$('form#list_subscribe').submit(function(e){list_subscribe(e)});
}

function list_subscribe(e)
{
	var errors=[];
	if(!$('form#list_subscribe input#alert_email').val()){
		errors.push('Please enter in an email address');
	}
	if(!$('form#list_subscribe input#alert_name').val()){
		errors.push('Please enter in your name');
	}
	if(!$('form#list_subscribe input#privacy_agree').is(':checked')){
		errors.push('You have to agree to the terms of service before you subscribe');
	}
	if(errors.length){
		var msg="Please fix the following error";
		if(errors.length!=1){
			msg+='s';
		}
		msg+=":\n"+errors.join("\n");
		alert(msg);
		e.preventDefault();
	}
}

function display_more_related(e)
{
	e.preventDefault();
	$('dl.search_results_related .more').remove();
	$('dl.search_results_related .hidden').removeClass('hidden');
}

