var is_animating = false;
function basic_toggle(base)
{
	if(is_animating) return true;
	is_animating=true;
	toggleSectionA($('#'+base+'_simple'));
	toggleSection($('#'+base+'_advanced'));
	return;
}

function toggleSectionA(section){
	if(section.is(':visible')){
		section.animate( {opacity:0}, 150,'linear');
		section.slideUp(150);
	} else {
		section.slideDown(150);
		section.animate( {opacity:1}, 150,'linear');
	}
}
function toggleSection(section){
	if(section.is(':visible')){
		section.animate( {opacity:0}, 150,'linear');
		section.slideUp(150,function() {is_animating=false;});
	} else {
		section.slideDown(150);
		section.animate( {opacity:1}, 150,'linear',function() {is_animating=false;});
	}
}

function date_search_toggle(force)
{
if(typeof(force) == 'undefined'&&is_animating) return true;
	is_animating=true;
	if($('#date_simple').is(':visible')){
	  $('#date_advanced :input').removeAttr("disabled");
	 $('#date_simple :input').attr("disabled","disabled");
	 $('#date_simple :input').attr("value","");
	}
	else
	{
		$('#date_advanced :input').attr("value","");
		$('#date_advanced :input').attr("disabled","disabled");
		$('#date_simple :input').removeAttr("disabled");
	}

	toggleSectionA($('#date_simple'));
	toggleSection($('#date_advanced'));
	return;
}

function lang_search_toggle(force)
{
if(typeof(force) == 'undefined'&&is_animating) return true;
	is_animating=true;
	if($('#lang_simple').is(':visible')){
	  $('#lang_advanced :input').removeAttr("disabled");
	 $('#lang_simple :input').attr("disabled","disabled");
	}
	else
	{
		$('#lang_advanced :input').attr("disabled","disabled");
		$('#lang_simple :input').removeAttr("disabled");
	}

	toggleSectionA($('#lang_simple'));
	toggleSection($('#lang_advanced'));
	return;
}

function all_lang_on()
{
	$('#lang_advanced :input[type="checkbox"]').attr("checked","checked");
}
function all_lang_off()
{
	$('#lang_advanced :input[type="checkbox"]').removeAttr("checked");
}

function vstretch(i,elm)
{
	var tmp=$(elm).parent().height();
	elm.height=tmp;
}

//Hide 'advanced' options on load, open help in new window
$(document).ready(function(){
	$('.slide_toggle').show();
	$('div[id$="_advanced"]').hide();
	$('a[class$="close_window"]').mouseup(function(){window.close();});
	$('a.help').click(function(){window.open(this.href,'HelpWindow','width=950,height=550,location=0,status=1,menubar=1,scrollbars=1,directories=0,resizable=1'); return false;});
	$('#printicon').click(function(){window.open(this.href,'Print','width=950,height=550,location=0,status=1,menubar=1,scrollbars=1,directories=0,resizable=1'); return false;});
	$('.pop').click(function(){window.open(this.href,'Citation','width=950,height=550,location=0,status=1,menubar=1,scrollbars=1,directories=0,resizable=1'); return false;});
	$('a[class^="notecall"]').click(function(){window.open(this.href,'CritApp','width=950,height=550,location=0,status=1,menubar=1,scrollbars=1,directories=0,resizable=1'); return false;});
	$('a[class^="envelope"]').click(function(){window.open(this.href,'Envelope','width=950,height=550,location=0,status=1,menubar=1,scrollbars=1,directories=0,resizable=1'); return false;});
	$('a[class^="instances"]').click(function(){window.open(this.href,'Instances','width=950,height=550,location=0,status=1,menubar=1,scrollbars=1,directories=0,resizable=1'); return false;});
	$('a[class^="srceds"]').click(function(){window.open(this.href,'SourceEditions','width=950,height=550,location=0,status=1,menubar=1,scrollbars=1,directories=0,resizable=1'); return false;});
	$('#lang_simple :input').removeAttr("disabled");
	$('#lang_advanced :input').attr("disabled","disabled");
	$('#date_advanced :input').attr("disabled","disabled");
	$('a[rel="external"],a[rel="pop"],.critapp dd[class$="Content"] a').attr("target","_blank");
	jQuery.each($('.vstretch'),vstretch);

 });

