$(document).ready(
	function init(){
		$(".button").click(function(){
			
		
			if (!isValidEmailAddress($("#f_email").attr('value'))){
				alert("Вы ввели некорректный email!"); return 0;}
			
			if ($("#f_letter_text").attr('value')=='') 	{
				alert("Введите сообщение!"); return 0;}
			 
			var ajax = $.ajax({
		        url:    '/plugins/backform/index.php',
		        type: 'POST',
		        data: 'posText=' + $('#f_letter_text').val() +
		        	'&posEmail='+$('#f_email').val() + 
		        	'&f_letter_them='+$('#f_letter_them').val()+
		        	'&f_send_copy='+$('#f_send_copy').attr('checked')+
		        	'&f_phone='+$('#f_phone').val()+
		        	'&f_name='+$('#f_name').val()
		        	,               
		        async:   false
			});  
			if (ajax.responseText == "1")
				alert("Спасибо! Ваше сообщение отправлено!");
			document.getElementById('formLayer').style.display='none';
		});
		
		
		if($('#top_menu li.to_right a').length)
			$('#top_menu li.to_right a').click(function(){
				showForm();
			}
		)
		
		if($('#sendmail').length)
			$('#sendmail').click(function(){
				
				$('#f_letter_them :nth-child(2)').attr("selected", "selected");				
				showForm();
				
			}
		)
	})
function showForm(){
		if (( $.browser.msie )&&( $.browser.version < 7)){
				$('#formLayer').css({'height':$('body').height()});
		};
	$('#formLayer').toggle('normal');
	return false;
}


function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
    }

