/*///////////////////////////////////////////////////////////////////////
Part of the code from the book 
Building Findable Websites: Web Standards, SEO, and Beyond
by Aarron Walter (aarron@buildingfindablewebsites.com)
http://buildingfindablewebsites.com

Distrbuted under Creative Commons license
http://creativecommons.org/licenses/by-sa/3.0/us/
///////////////////////////////////////////////////////////////////////*/

// Load Events Listeners
Event.observe(window, 'load', init, false);
var mtimerChat;
function init(){
	Event.observe('signup','submit',storeAddress);
}

// AJAX call sending sign up info to store-address.php
function storeAddress(event) {
	// Update user interface
	$('response').innerHTML = '';//Adding email address...';
	$('response').style.display='none';
	// Prepare query string and send AJAX request
	var pars = 'ajax=true&email=' + escape($F('email'));
	var myAjax = new Ajax.Updater('response', 'subscribe/inc/store-address.php', {method: 'get', parameters: pars});
	Event.stop(event); // Stop form from submitting when JS is enabled
	checkfield();	
}

function checkfield(){
	if($('response').innerHTML !="" && $('response').innerHTML !="Check your email to receive your free report"){
			document.getElementById('response').style.display='block';
	}else if ($('response').innerHTML == 'Check your email to receive your free report'){
		document.getElementById('newsletterText').innerHTML='Success!';	
		document.getElementById('newsletter').style.fontSize='20px'; 
		document.getElementById('newsletter').style.color='#666666'; 
		document.getElementById('newsletter').style.paddingTop='14px';
		document.getElementById('newsletter').innerHTML='Check your email to receive your free report';		
	}else{
	mTimerChat = setTimeout('checkfield();',1000);	
	}
}
