function noenter() 
{
	return !(window.event && window.event.keyCode == 13);
}

String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};
// FormOverlay
var lightBoxVar = 0;
var min_height;
var overlay_interval;
// Sizes overlay div to 100% of browser height
function overlaySize() {
	//winH = document.body.offsetHeight;
	winH = window.innerHeight;
	totalHeight = document.getElementById('mam_container').offsetHeight;
	totHeight = totalHeight + min_height;
	winW = document.body.offsetWidth;
	if(winW < 756) {
		document.getElementById('overlay').style.width = 756 + "px";
	} else {
		document.getElementById('overlay').style.width = 100 + "%";
	}
	if(winH > totHeight) {
		document.getElementById('overlay').style.height = winH + "px";
	} else {
		document.getElementById('overlay').style.height = (totHeight + 50) + "px";
		//document.getElementById('overlay').style.height = (totHeight + 215) + "px";
	}
}
function formOverlay(dynamic_height) {
	min_height = dynamic_height;
	lightBoxVar = 1;
	$("#overlay").show();
	$("#form_overlay").show();
	$("#form_send_friend").show();
	$("#overlay_loader").hide();
	$("#overlay_thanks").hide();
	overlay_interval = setInterval ( "overlaySize()", 33 );
}
function closeFormOverlay() {
	lightBoxVar = 0;
	$("#overlay").hide();
	$("#form_overlay").hide();
	document.getElementById('form_send_name').value="";
	document.getElementById('form_send_friends').value="";
	document.getElementById('form_send_email').value="";
}

function showThanks() {
	$("#overlay_loader").hide();
	$("#overlay_thanks").show();	
	setTimeout('closeFormOverlay();', 1000);
}

function sendFriend(email_message) {
	to_email=$("#form_send_email").val();
	to_name=$("#form_send_friends").val();
	from_name=$("#form_send_name").val();
	profile_name=$("#profile_name").val();
	profile_id=$("#profile_id").val();
		 
	if (to_email.trim() === '' || to_name.trim() === '' || from_name.trim() === '')
	{
		alert("Please complete the form and try again.");
	}
	else
	{
		$("#overlay_loader").show();
		$("#form_send_friend").hide();
		
		//post it ajax.
		$.ajax(
		{
			type: "POST",
			url: "/mostamazingmember/sendtofriend/send.php",
			data: "from_name=" + from_name + "&to_name=" + to_name + "&to_email=" + to_email + "&email=" + email_message + "&profile_id=" + profile_id + "&entrants_name=" + profile_name,
			async: false,
			success: function(data) 
			{
				if (data.search("ERROR") != -1)
				{
					alert(data);
					$("#overlay_loader").hide();
					$("#form_send_friend").show();				
				}
				else 
				{
					setTimeout('showThanks();', 1500);
				}
			}
		});		
	}
}

// To make sure the light box overlay resizes with the window
window.onresize = function() {
	if(lightBoxVar == 1) {
		overlaySize();
	}
}
// Size the Overlay when the window is loaded
window.onload = function() {
	overlaySize();
}