/*****Note*******/
// Currently using jQuery inplace of the default Prototype

// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function initListSearch(){

	$('#listsearch input[type="image"]').click(function(){

		var gp_checked = $('#gp_blacklist').attr('checked');
		var off_checked = $('#official_blacklist').attr('checked');		
		if(location){
			var path = location.pathname.split('/');
		}
		var both_action = '9';
		var gp_action = '1';
		var off_action = '0';

		switch(gp_checked && off_checked){
			case true:
				path[1] = both_action;
				$('#listsearch').parent().attr('action',path.join('/'));
				break;
			case false:
				if(gp_checked){
					path[1] = gp_action;
					$('#listsearch').parent().attr('action',path.join('/'));
					break;
				}
				if(off_checked){
					path[1] = off_action;
					$('#listsearch').parent().attr('action',path.join('/'));
					break;
				}
			default:
				alert('please select a list to search from');
				return false;
		}
	});

}

function initReportExport(){
	var tabs = '<ul class="tabs"><li id="vessel" class="currentTab">Vessel</li><li id="company">Company</li><li id="all">All</li></ul>';
	var report_type = $('#reportType');
	if(report_type){
		report_type.after(tabs);
		report_type.css({'display':'none'});
		$('#companyReport').css({'display':'none'});
		$('#report_type_0').attr('checked','checked');
	}
	$('#vessel').click(function(){
		$(this).addClass('currentTab');
		$('#company').removeClass('currentTab');
		$('#all').removeClass('currentTab');
		$('#vesselReport').show();
		$('#companyReport').hide();
		$('#report_type_0').attr('checked','checked');
	});
	$('#company').click(function(){
		$(this).addClass('currentTab');
		$('#vessel').removeClass('currentTab');
		$('#all').removeClass('currentTab');
		$('#vesselReport').hide();
		$('#companyReport').show();
		$('#report_type_1').attr('checked','checked');
	});
	$('#all').click(function(){
		$(this).addClass('currentTab');
		$('#vessel').removeClass('currentTab');
		$('#company').removeClass('currentTab');
		$('#vesselReport').hide();
		$('#companyReport').hide();
		$('#report_type_2').attr('checked','checked');
	});

}

$().ready(function(){
	initListSearch();
	initReportExport();
});
