var flash_code;

function tell_friend_email_verify()
{
	var email_re = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	var mail = $("#email").val();
	if (!email_re.test($("#email").val()))
	{
		alert("Invalid e-mail address.");
		$("#email").focus();
		return false;	
	}
	
	return true;
}

function tell_friend_submit()
{
	if(!tell_friend_email_verify())
	{
		return false;
	}


	
	var emailFrom = $("#sender_name").val();
	var emailMsg  = $("#sender_msg").val();
	var mail = $("#email").val();
	var emptyStringPat = /^[\n\t\r ]*$/;
	var data = '<b>Send email to:'+ mail +' </B><br/><br/><b>E-mail text:</b><p>Hello,<br/><br/>Here is a link to Flex-Ability Concepts website: <a href="http://www.flexabilityconcepts.com">http://www.flexabilityconcepts.com</a><br/>They manufacture curvable framing products and are known as "The Curved Wall People"<br/><br/>Message:<p>'+emailMsg+'</p>Sincerely,<br/>'+emailFrom+'</p>';
	$('#window .jqmTarget').html(data);
	$('#window').jqm().jqmShow();
	flash_code = document.getElementById('flash_menu').innerHTML;
	document.getElementById('flash_menu').innerHTML = "";
	
	return false;
} 

function tell_friend_confirmation(t)
{
	if(t.value == "Cancel")
	{
		$('#window').jqm().jqmHide();
		document.getElementById('flash_menu').innerHTML = flash_code;
		document.getElementById('email').focus();
	}
	else if(t.value == "Send")
	{
		var tellFriendForm = $("#tell_friend_form");
		$(tellFriendForm).attr('action', 'http://www.flexc.com/phpscripts/sendmail.php?method=tell_frend');
		
		
		tellFriendForm[0].submit();
		window.location.href = "../sendmail_tell_fredn.html";
	}
	var test = test
}

function tell_friend_autoattach()
{
	$('body').append('<div id="window" class="jqmWindow"><div class="jqmHeader"></div><div class="jqmTarget">.....Content test.....</div><div class="jqmFooter"><form onsubmit="return false;" id="tell_friend_confirmation"><input type="submit" value="Send" style="font-family: tahoma; font-size: 10px; height: 17px; width: 40px;  border: 1px solid black;" onclick="tell_friend_confirmation(this)"/>&nbsp;<input type="submit" value="Cancel" style="font-family: tahoma; font-size: 10px; height: 17px; width: 40px;  border: 1px solid black;" onclick="tell_friend_confirmation(this)" /></form></div></div>');
	$('#window').jqm({target: '.jqmTarget', modal: true});
	var tellFriendForm = $("#tell_friend_form");
	//var oldOnSubmit = tellFriednForm.attr("onsubmit");
	tellFriendForm.submit(function(){
		return tell_friend_submit();		
	});
}

$("document").ready(tell_friend_autoattach);
