var fixed_position;

function init () {
	fixed_position = document.getElementById('fixed_bottom').offsetTop;
}


// FIXED BOTTOM
function fixedBottom () {

	var scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
	}

	if (scrOfY >= (fixed_position - 20)) {
		document.getElementById('fixed_bottom').style.position = "fixed";
		document.getElementById('fixed_bottom').style.top = "5px";
	} else {
		document.getElementById('fixed_bottom').style.position = "relative";
		document.getElementById('fixed_bottom').style.top = "0";
	}
	
}


// SUBMIT ON RETURN KEY DOWN
function submitenter(myfield,e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13) {
	   subscribe(document.forms['subscribeForm']['email'].value);return false;
	   return false;
	}
	else
	   return true;
}
	
	

// SUBSCRIBE
function subscribe(email) {

	$.ajax({
		type: "POST",
		url: "/ajax/subscribe.html",
		data: "email=" + email,
		success: function(msg){
			$('#subscribeMessage').html("<div style='padding:15px 0 5px;'>Thank you for subscribing.</div>");
			$('#subscribeMessage').animate({ height: 'show', opacity: 'show' }, 'slow');
		}
	});
	
}


// SUBSCRIBE TEAMAP
function subscribe_teamap(email, firstName, lastName, zipCode) {

	$.ajax({
		type: "POST",
		url: "/ajax/subscribe_teamap.html",
		data: "email=" + email + "&firstName=" + firstName + "&lastName=" + lastName + "&zipCode=" + zipCode,
		success: function(msg){
			$('#subscribeMessage').html("<div style='padding:15px 0 5px;'>Thank you for subscribing.</div>");
			$('#subscribeMessage').animate({ height: 'show', opacity: 'show' }, 'slow');
		}
	});
	
}


window.onload=init;
window.onscroll=fixedBottom;
