function closeThanks() {
	$("#SendFriendDiv").slideUp("slow");
	setTimeout('$("#formthanks").fadeOut("slow");', 1500);
	setTimeout('$("#formholder").fadeIn("slow");', 1500);
}

String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};

function sendFriend() {
	to_email=$("#friendsemail").val();
	to_name=$("#friendsname").val();
	from_name=$("#sendersname").val();
	pdf_link =$("#pdf_link").val();
	text_link = $("#text_link").val();
	
	if ($("#find_location_me").attr("checked"))
	{
		find_location = 'me';
	}
	else
	{
		find_location = 'friend';
	}
		 
	if (to_email.trim() === '' || to_name.trim() === '' || from_name.trim() === '')
	{
		alert("Please complete the form and try again.");
		showForm();
	}
	else
	{
		//post it ajax.
		$.ajax(
		{
			type: "POST",
			url: "/send-to-friend/guest_pass_send.php",
			data: "from_name=" + from_name + "&to_name=" + to_name + "&to_email=" + to_email + "&pdf_link=" + pdf_link + "&text_link=" + text_link + "&find_location=" + find_location,
			async: false,
			success: function(data) 
			{
				if (data.search("ERROR") != -1)
				{
					alert(data);
					showForm();					
				}
				else 
				{
					$("#formthanks").fadeIn("slow");
					setTimeout('closeThanks();', 2000);
					$("#formloading").fadeOut();
					//alert("successfully sent the email");
				}
			}
		});		
	}
};

function showLoader() {
	$("#formloading").fadeIn();
	$("#formholder").slideUp("slow");
	setTimeout('sendFriend();', 1500);
}

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}
function showForm() {
	$("#formloading").fadeOut();
	$("#formholder").slideDown();
	$("#SendFriendDiv").slideDown("slow");
}
function closeForm() {
	$("#SendFriendDiv").slideUp("slow");
}
$.preloadImages("/images/bg_send_friend.gif");
