// JavaScript Document

var pst = 0;
var pst2 = 0;
function ajaxFunction(){
   if(pst) {
      clearTimeout(pst);
      pst  = 0;
   }
    if(pst2) {
      clearTimeout(pst2);
      pst  = 0;
   }
	var ajaxRequest;  
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
  if(ajaxRequest.readyState == 4){
		
			var response = ajaxRequest.responseText;
			var ajaxDisplay = document.getElementById('the_result');
			ajaxDisplay.innerHTML  = response;
			ajaxDisplay = document.getElementById('the_result');
			val = "Email Added!";
			if(ajaxDisplay.innerText != val)
			{
				//ajaxDisplay.className = "form_bad";
				ajaxDisplay.style.color = "#FFFFFF";
				ajaxDisplay.style.backgroundColor = "#FF0000";
				
				
			}
			else 
			{ 
				//ajaxDisplay.className = "form_good";
				ajaxDisplay.style.color = "#000066";
				ajaxDisplay.style.backgroundColor = "#CFE2D1";
				pst = setTimeout("parting_shot()", 2000);
			}
			
		
		}
	}

		
	var email = document.f1.email.value;
	email = escape(email);
	
   
	var myRand=parseInt(Math.random()*99999999);  // cache buster
	var queryString = "?bname=" + email +  "&therand=" + myRand;

	ajaxRequest.open("GET", "email_hand.php" + queryString, true);
	
	ajaxRequest.send(null); 
	
}

function parting_shot()
{
	ajaxDisplay = document.getElementById('the_result');
	ajaxDisplay.innerText = "I told you it was quick and painless!";
	pst2 = setTimeout("parting_shot2()", 2000);
}

function parting_shot2()
{
	ajaxDisplay = document.getElementById('the_result');
	ajaxDisplay.innerText = "Thank You!";
	
}


function handleKeyPress(e,form)
{
	var key=e.keyCode || e.which;
	if (key==13) 
	return ajaxFunction();
	
}
