// Subscription and contact related code
var subscribing = false;
var sendingContactForm = false;

var host = location.protocol + "//" + location.hostname;
var emailHandler = host + "/ajax/email_subscription.php";
var contactHandler = host + "/ajax/email_contact.php";

//var emailHandler = "http://neoday.philter.org/ajax/email_subscription.php";
//var contactHandler = "http://neoday.philter.org/ajax/email_contact.php";

function subscriptionSignup()
{
	
	subscribing = true;
	var address = document.getElementById("subscriptionEmail").value;
	// Send an email to the server and wait for a response
	//debug(address);
	animateInputBackground();
	loadXMLDocPost(emailHandler, "e=" + escape(address));
	
}

function sendContactEmail()
{
	
	sendingContactForm = true;
	var subject = document.getElementById("subject").value;
	var returnAddress = document.getElementById("yourEmail").value;
	var body = document.getElementById("body").value;
	
	displayContactProgress(true, 1);
	loadXMLDocPost(contactHandler, "s=" + subject + "&r=" + returnAddress + "&b="  + body);

}

function changeContactStatusText(text)
{
	
	var statusText = document.getElementById("contact_status_text");
	statusText.innerHTML = text;
	
}

function displayContactProgress(state, time)
{
	
	if(state)
	{
		
		document.getElementById("contact_form").style.display = "none";
		document.getElementById("contact_response").style.display = "block";
		
	}
	else
	{
		
		setTimeout('document.getElementById("contact_response").style.display = "none"', time * 1000);
		setTimeout('document.getElementById("contact_form").style.display = "block"', time * 1000);
		
	}
		
	
}

var origNewsletterHint = "Sign up for updates";

function clearSubscriptionField(input)
{
	if(input.value == origNewsletterHint)
	{
	
		input.value = "";
	
	}
}

function resetSubscriptionField(input)
{

	if(input.value == "")
	{
	
		input.value = origNewsletterHint;
	
	}

}

function resetForm()
{

	if(subscribing)
	{
	
		
	
	}
	else
	{
	
		
	
	}

}

function displayStatusIndicator()
{

	if(subscribing)
	{
	
		animateInputBackground();
	
	}
	else
	{
	
	
	
	}
	
}

var progressPosLeft = 0;

function animateInputBackground()
{
	var input = document.getElementById("subscriptionEmail");
	input.style.backgroundImage = "url(/images/progress.indicator.gif)";
	input.style.backgroundPosition = "Top Left";
	input.style.backgroundRepeat = "no-repeat";
	input.style.border = "1px Solid #ccc";
	input.style.height = "13px";
	input.style.width = "177px";
	changeInputBackground();
}

function changeInputBackground()
{
	while(progressPosLeft < 200)
	{
		var input = document.getElementById("subscriptionEmail");
		input.style.backgroundPosition = "0 " + progressPosLeft + "px" ;
		progressPosLeft++;
		debug(10 * progressPosLeft);
		setTimeout("changeInputBackground()", 10 * progressPosLeft);
	}
	

}

function catchScroll(e)
{
	if (!e) e = window.event;


	debug("scrollEvent: " + e.wheelDelta);

}

//window.addEventListener("DOMMouseScroll", catchScroll, false); 
//window.onscroll = catchScroll;
