// JavaScript Document

$(document).ready(function(){
						   
	/*
	$('div.extrafields').before('<br /><a href="" id="morefields"><span class="extrashow">Show</span><span class="extrahide">Hide</span> Advanced Search</a>');
	$('div.extrafields').hide();
	$('span.extrahide').hide();
	$('#morefields').click(function(){
		$('div.extrafields').slideToggle(1000);
		$('span.extrahide').toggle();
		$('span.extrashow').toggle();
		
		return false;
	});
	*/
	
	$(' a.execshort').click(function(){	
		var refid = $(this).attr('rel');
		$('div.summary'+refid+' div.execshortcont').slideUp(300,function(){
			$('div.summary'+refid+' div.execlongcont').slideDown(300);		
			$.post("/lib/cr.php?m=reftracker", {refid:refid});
		});
		return false;
	});
	$('a.execlong').click(function(){	
		var refid = $(this).attr('rel');
		$('div.summary'+refid+' div.execlongcont').slideUp(300,function(){
			$('div.summary'+refid+' div.execshortcont').slideDown(300);			
		});
		return false;		
	});
	
	$('input.pagebutton').click(function(){
		$('input#page').val($(this).val());
		//$('form#refsearch').submit(function(){
			// do something
			
			
		//});
	});
	
	$('input#allsector').click(function(){
		
		if ($(this).attr('checked')){
			$("input[@name^='sector']:checked").addClass('chosen');
			$("input[@name^='sector']").attr('checked',true);
			
		} else {
			$("input[@name^='sector']").attr('checked',false);
			$("input[@name^='sector'].chosen").attr('checked',true);
			$("input[@name^='sector'].chosen").removeClass('chosen');
		
		}
	});
	
	$('input#allsubject').click(function(){
		
		if ($(this).attr('checked')){
			$("input[@name^='subject']:checked").addClass('chosen');
			$("input[@name^='subject']").attr('checked',true);
			
		} else {
			$("input[@name^='subject']").attr('checked',false);
			$("input[@name^='subject'].chosen").attr('checked',true);
			$("input[@name^='subject'].chosen").removeClass('chosen');
		
		}
	});
	
	$("input[@name^='sector']").click(function(){
	
		var sectorid = $(this).val();
		var sectoridchosen = $(this).attr('checked');
		if(!sectoridchosen){
			sectoridchosen = false;
		}
		
		if (sectorid != ''){
			$.post("/lib/cr.php?m=getsectorboxes", {id:sectorid}, function(xml) {	
				if ($("status", xml).text() == 'success'){					
					if($("boxes", xml).text() != ''){					
						var bs = $("boxes", xml).text();
						bslist = bs.split('|');
						for (i=0;i<bslist.length;i++){
							if ($("input#sector"+bslist[i]).val() != sectorid){
								$("input#sector"+bslist[i]).attr('checked',sectoridchosen);															
							}
						}					
					}				
				}
			});
		}		
	
	});
	
	$("input[@name^='subject']").click(function(){
	
		var subjectid = $(this).val();
		var subjectidchosen = $(this).attr('checked');
		if(!subjectidchosen){
			subjectidchosen = false;
		}
		
		if (subjectid != ''){
			$.post("/lib/cr.php?m=getsubjectboxes", {id:subjectid}, function(xml) {	
				if ($("status", xml).text() == 'success'){					
					if($("boxes", xml).text() != ''){					
						var bs = $("boxes", xml).text();
						bslist = bs.split('|');
						for (i=0;i<bslist.length;i++){
							if ($("input#subject"+bslist[i]).val() != subjectid){
								$("input#subject"+bslist[i]).attr('checked',subjectidchosen);															
							}
						}					
					}				
				}
			});
		}		
	
	});
	
	$('#perpage').change(function(){
		$('form.reflist').submit();							  
	});
	
	if ($.browser.msie && parseInt($.browser.version)< 7) {  
         $("#navlist li").hover(  
             function() {  
                $(this).addClass("sf");  
             },  
             function() {  
         		$(this).removeClass("sf");  
             });  
     } 

});