
function hidestories() {
	var stories = ["noca-check", "noca-payment", "noca-signup", "noca-integration", "noca-rates", "noca-contact"];
	
	for(var s in stories) {
		$('#'+stories[s]).hide();
	}
}
var openingStory = null;
function showstory(story) {
	if(openingStory) {
		$('#'+openingStory).hide('fast');
	}
	openingStory = story;
	hidestories();
	
	$('#'+story).show('slow', function() {
			openingStory = null;
		});

}
function enterHandler(field, e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13) {
   		emailSignup(field.value);
	}
}
function emailSignup(emailAddr) {
  $.post("emailSignup.php", { email: emailAddr }, emailSignupResponse ); 
}
function emailSignupResponse(response) {

	container = document.getElementById('info-email-text');	
	field = document.getElementById('email-input');
	if(response == 0) {
		jContainer = $('#info-email-text');
		jContainer.hide();
		container.innerHTML = "Thanks!  We'll keep in touch.";
		jContainer.show("slow");
		container.style.top = 14;		
		container.style.color = "#003366";
	} else if (response == 1) {
		//invalid email
		field.style.background = "#FF5555";
		field.style.color = "#FFFFFF";
	} else {
		//server failure
		//do nothing.  maybe user will try again?
	}

}

function submitContact() {		 
	 
	var data = {
		name : document.getElementById("contactName").value,
		email: document.getElementById("contactEmail").value,
		topic : document.getElementById("contactTopic").value,
		subject: document.getElementById("contactSubject").value,
		message: document.getElementById("contactMessage").value,
		user_code: document.getElementById("security_code").value
	}		
	//alert ("ok "+ document.getElementById("security_code").value);
	$.post("feedbackEmail.php", data, contactResponse );
}

function contactResponse(response) {	
	//alert("resp: "+response);
	if ( response == 0 ) {		
		$('#noca-contact').hide("fast");
		container = document.getElementById("noca-contact").innerHTML = "<h1>Thanks for your input.</h1><h3>We'll be in touch.</h3>";
		$('#noca-contact').show("slow");
	} else if (response == 1) {
		emaile = document.getElementById("contactEmail");
		emaile.style.background = "#FF5555";
		emaile.style.color = "#FFFFFF";
	} else if (response == 10) {
		alert("Please enter correct code.");
	} else {
		//server error.  standby.	
	}
}

function load() {
	hidestories();
	showstory("noca-check");
}
