// JavaScript Document

$(document).ready(function() {


// Added by JJoven for Tables and Map added functionality

	$('#digester-table').hide();
	$(".pls-select").hide();
	$(".switcher").css('display','block');
	$(".maps p:first").css('margin-left','40px');
	$(".maps p:first").css('font-weight','bold');
	$(".maps p:first").css('color','#00853e');
	$(".maps p:nth-child(2)").css('margin-left','40px');
	$(".maps p:nth-child(2)").css('font-weight','bold');
	$(".maps p:nth-child(2)").css('color','#00853e');
	$("div.maps div:not(:first)").hide();
	$(".switcher a:first").css('font-weight','bold');
	
	if (window.location.hash) {
        $('#digester-table').show();
		$(".pls-select").show();
		var state = window.location.hash.substr(1);
		$("div.the-table").append("<div id='"+state+"'></div>");
		$("#digester-table tr:visible").hide();
		$("#digester-table tr:first").show();
        $("#digester-table tr."+state).show();		
	}
	
	$(".energy-production").click(function() {
		$('#digester-table').hide();
		$(".pls-select").hide();
		$(this).css('font-weight','bold');
		$(".digesters").css('font-weight', 'normal');
		$("#digesters").hide();
		$("#energy").show();
		return false;
		
	});
	
	$(".digesters").click(function() {
		$('#digester-table').hide();
		$(".pls-select").hide();
		$(this).css('font-weight','bold');
		$(".energy-production").css('font-weight', 'normal');
		$("#digesters").show();
		$("#energy").hide();
		return false;
	});
	
	$('area').click(function() { 
		$('#digester-table').show();
		$(".pls-select").show();
		$('html, body').animate({scrollTop:500}, 'slow'); 
		var state = $(this).attr('href').substr(1);
		$("#digester-table tr:visible").hide();
		$("#digester-table tr:first").show();
        $("#digester-table tr."+state).show();
	});
	
	$("#digester-table th").addClass('link');
	$("#digester-table th:first").css('font-weight','bold');
	$("#digester-table th").click(function() {
		$(this).siblings().css('font-weight','normal');
		$(this).css('font-weight','bold');
	});
	
	
// LIGHTBOX EFFECT
	// To use the lightbox function, simplay add the class 'lightbox' to the link to the image.
	//$('a.lightbox').lightBox();
	
	// SORTABLE TABLES
	// To use the table sorting function, apply the class 'sortable' to the table in question. Ensure that all the TH elements are in a THEAD block
	// and that all the table's data rows are contained within a TBODY block for this to work.
	$("table").tablesorter({
		widgets:['zebra']
	});
	
	$("#state, #eligible").each(function(){
		$(this).change(function(){
			var current_state = $("#state option:selected").val();
			var current_orgs = $("#eligible option:selected").val();
			$("#funding thead tr").show();
				current_state = current_state == "selectone" ? "all" : current_state;
				current_orgs = current_orgs == "selectone" ? "all" : current_orgs;
			$("#funding tbody tr").show().filter(":not(."+ current_state +"), :not(."+ current_orgs +")").hide();
		});
	});
	

	$("#showall").click(function(){
		$("table tr").show();
		$("#fundingddform").each(function() {
       		this.reset();
     	});
	});
	

	

	
});



function validate3(form) {
	var msg="";
	if (form.b_name.value == "") msg += "  * Name\n";
	if (form.e_org.value == "") msg += "  * Organization\n";
	if ((form.c_email.value.indexOf('@') == -1) || 
		(form.c_email.value.length < 8)) msg += "  * E-mail\n";
	if (msg == "") {
		return true;
	} else {
		alert("Please enter in the following information in order to submit your information:\n" + msg);
		return false;
	}
}







//OLD....

//function validate3(form) {
//	var msg="";
//	if ((form.email.value.indexOf('@') == -1) || 
//		(form.email.value.length < 8)) msg += "  * E-mail\n";
//	if (msg == "") {
//		return true;
//	} else {
//		alert("Please enter in the following information in order to submit your information:\n" + msg);
//		return false;
//	}
//}

//$("#funding tbody tr").show().filter(":not(.$1), :not(.$2)".replace("$1", current_state).replace("$2", current_orgs)).hide();
			
//$("#state").change(function () {
//		var stat = $("#state option:selected").val();
//		var elig = $("#eligible option:selected").val();
//			$("#funding tbody tr").not("."+stat).hide();
//			$("#funding thead tr").show();
//		if ($("#eligible option:selected").val() == "selectone") {
//				$("."+stat).filter(".all").show();
//			} else {
//				$("#funding tbody tr").not("."+elig).hide();
//				$("."+stat).filter("."+elig).show();
//			}
//		});
	
//	$("#eligible").change(function () {
//		var elig = $("#eligible option:selected").val();
//		var stat = $("#state option:selected").val();
//			$("#funding tbody tr").not("."+elig).hide();
//			$("#funding thead tr").show();
//		if ($("#state option:selected").val() == "selectone") {
//				$("."+elig).filter(".all").show();
//			} else {
//				$("#funding tbody tr").not("."+stat).hide();
//				$("."+elig).filter("."+stat).show();
//			}
//		});
	
	
	
	

//OLDER STILL.....
//$("#eligible").change(function () {
	//	var elig = $("#eligible option:selected").val();
		//var stat = $("#state option:selected").val();
		//$("#funding tr").not("."+elig).hide();	
		//$("#funding tr").not("."+stat).hide();
		//$("thead tr").show();
		//$("."+elig).filter("."+stat).show();
		//$("."+elig).show();
		//$("."+stat).show();
	//});


// $("#state").change(function () {
	//	var stat = $("#state option:selected").val();
	//	var elig = $("#eligible option:selected").val();
	//		if($("#eligible option:selected").val() == "selectone") {
	//			$("."+stat).show();
	//		} else {
	//	$("#funding tr").not("."+stat).hide();
	//	$("#funding tr").not("."+elig).hide();
	//	$("thead tr").show();
	//	$("."+stat).filter("."+elig).show();
	//		}	
//	});

//	$("#eligible").change(function () {
//		var elig = $("#eligible option:selected").val();
//		var stat = $("#state option:selected").val();
//		$("#funding tr").not("."+elig).hide();	
//		$("#funding tr").not("."+stat).hide();
//		$("thead tr").show();
//		$("."+elig).filter("."+stat).show();
		//$("."+elig).show();
		//$("."+stat).show();
//	});