// enter TAF e-mail address first to make sure that it's in the system

// 0. Detect logged in users??

// 1. replace TAF form with just an e-mail box


$(document).ready(function(){

$('form:contains("Recipient Email Addresses")').hide()
var addressForm = '<form id="dummy_email_form" action="#"><input id="js_email" name="js_email"/><input id="dummy_submit" type="submit" value="Sign up" onclick="swapForm()"></form>'

$('form:contains("Recipient Email Addresses")').before(addressForm)

//pic1= new Image(16,16); 
//pic1.src="https://admin5.getactive.com/img/gv2/custom_images/ran/ajax-loader.gif";

//$('.ga-tellFriendInput').css('display','block')
	
});

function emailSignup(email) {
	var http = new XMLHttpRequest();

	var url = "http://ga3.org/offsite-join.tcl";
	var params = "domain=ran&return_url=http://ga3.org/ran/&update=t&listserve1=weeklypanther&source=hansen_taf&email=" + email

	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			//alert(http.responseText);
			//$('#loading_gif').hide()

		}
	}
	http.send(params);
}


function swapForm() {
	var email = $('#js_email').val()
	//$('#dummy_email_form').replaceWith('<img src="https://admin5.getactive.com/img/gv2/custom_images/ran/ajax-loader.gif" width="20" id="loading_gif" />')
	emailSignup(email);
	$('#dummy_email_form').remove()
	$('form:contains("Recipient Email Addresses")').show()
	$('.ga-tellFriendContent').append('<h4 class="js_message">Thank you for committing to help stop mountaintop removal. The most important step you can take right now is to ask your friends and family to join in too!</h4>');
	$('[name="email"]').attr('value', email)

}


// 2. submit that e-mail as a signup and ignore result

// 3. put the form back in with e-mail address autopopulated 


/*

<form id="subscribe" method="post" action="http://ga3.org/offsite-join.tcl"><fieldset>
  <input name="domain" value="ran" type="hidden">
  <input name="return_url" value="http://ga3.org/ran/" type="hidden">
  <input name="update" value="t" type="hidden">
  <input name="listserve1" value="weeklypanther" type="hidden">
  <input name="source" value="hansen_taf" type="hidden">
  <input name="email" id="email" type="text">
  <input style="border: medium none ; position: relative;" name="submit" class="submit button" value="Subscribe" type="submit">
</fieldset></form>

*/