// JavaScript Document


$(document).ready(function() {


// ///////////////// Investment Application.
	$("span.wpcf7-list-item-label").html("");
	
	$("a#add-more-1").click(function(){
		$("div#hidden-field-1").fadeIn(400);
		$(this).hide();
		$("a#add-more-2").show();
	});
	$("a#add-more-2").click(function(){
		$("div#hidden-field-2").fadeIn(400);
		$(this).hide();
		$("a#add-more-3").show();
	});
	$("a#add-more-3").click(function(){
		$("div#hidden-field-3").fadeIn(400);
		$(this).hide();
	});




// ///////////////// Microfinance Form.
	if($("#include-access-prospectus").children().html()=="This post is password protected."){
		htmlcontent = '<div id="microfinance-side-box-step-1" style="display:;"><h3>Access Prospectus</h3><form action="http://www.communityfriends.org/wp-pass.php" method="post"><label for="pwbox-427"><strong>Password:</strong><input name="post_password" type="password" id="pwbox-427" maxlength="20" size="20" style="width:150px;border:1px solid #7e9db9; padding:2px 3px; font-size:15px; margin:0 0 0 2px;" /></label><input name="password-submit" id="password-submit" value="" type="submit" class="submit" /></form></div>';
			$("#include-access-prospectus").children().html(htmlcontent);
	}else{
		$("#dont-have-password").html("");
		};

	
	
	
	// /////////////////Carbon Offsets Calculation.
	if(document.getElementById("car-miles")){
		var coamount = Math.floor(document.getElementById("car-miles").value)*0.011 + Math.floor(document.getElementById("air-miles").value)*0.0184  + Math.floor(document.getElementById("electricity-usage").value)*0.2241;
	
		var co2metric = (coamount/27).toFixed(2);
		var ciamountprice = coamount.toFixed(2);
	
		$("div#Total-Metric-Tons-C02").html(co2metric);
		$("div#Total-Carbon-Offsets-Required").html(ciamountprice);
		$("input#amount").val(ciamountprice);
	};



// /////////////////Question Mark Popup in Carbon Offsets.
	$("a.carbon-offset-question-car").mouseover(function(){
		$("span.popup-question-car").fadeIn(200);
	});
	$("a.carbon-offset-question-car").mouseout(function(){
		$("span.popup-question-car").hide();
	});
	$("a.carbon-offset-question-air").mouseover(function(){
		$("span.popup-question-air").fadeIn(200);
	});
	$("a.carbon-offset-question-air").mouseout(function(){
		$("span.popup-question-air").hide();
	});
	$("a.carbon-offset-question-electricity").mouseover(function(){
		$("span.popup-question-electricity").fadeIn(200);
	});
	$("a.carbon-offset-question-electricity").mouseout(function(){
		$("span.popup-question-electricity").hide();
	});



}); //End of JQuery Functions.


// /////////////////Carbon Offsets Calculation Vol.2
var numb = "0123456789";

function calCarbonOffsets(t,v){
	
//		if(t.value==""){t.value = 0;}
	var w = "";
	for (i=0; i < t.value.length; i++) {
			x = t.value.charAt(i);
			if (v.indexOf(x,0) != -1)
			w += x;
	}
	t.value = w;
	
	var coamount = Math.floor(document.getElementById("car-miles").value)*0.011 + Math.floor(document.getElementById("air-miles").value)*0.0184  + Math.floor(document.getElementById("electricity-usage").value)*0.2241;

	var co2metric = (coamount/27).toFixed(2);
	var ciamountprice = coamount.toFixed(2);
			
	document.getElementById("Total-Metric-Tons-C02").innerHTML = co2metric;
	document.getElementById("Total-Carbon-Offsets-Required").innerHTML = ciamountprice;
	document.getElementById("amount").value = ciamountprice;
}



