$(document).ready(function(){	
	

	$("#mask").appendTo('body');
	$("#subscribe-price-window").appendTo('body');
	
	$('#a_subscribe_price').click(function(){
		
		
		var dW = $(document).width();
		var dH = $(document).height();
				  
		$('#mask').css({'width':dW,'height':dH});
		$('#subscribe-price-window').css({'top':$(window).scrollTop() + 150});
		
		$('#mask').fadeIn();
		$('#mask').fadeTo('fast', 0.8);
		$("#result").html('');
		$("#subscribe-price-window").show();
		return false;
		
	});
	
	$('#mask, .close').click(function () {
		$('#subscribe-price-window').hide();
		$('#mask').fadeOut('fast');
		
		return false;
	});
	
	
	$('#btn_subscribe_price').click(function(){
		
		var email = $('#sf-txt1').val();
		var object_id = $('#object_id').val();
		var page_type = $('#page_type').val();
		var old_price = $('#old_price').val();
		var type_of_currency = $('#type_of_currency').val();
		
		var post_data = 
			"email=" + email + 
			"&object_id=" + object_id + 
			"&page_type=" + page_type + 
			"&old_price=" + old_price + 
			"&type_of_currency=" + type_of_currency;
			
		var reg = /^(([-a-z_\.0-9]+)@([-a-z_\.0-9, ]+))+$/;
		if (reg.test(email))
		{
		
			$("#result").html('<img src="/images/loading_send.gif" alt="Отправка..." />');
				
			$.ajax({
	    		type: "POST",
	    		url: "/ajax/subscribe_price.php",
	    		data: post_data,
	    		success: function(msg){
							
					if (msg == 'ok')
					{
						$("#result").html('<b>Операция произведена успешно!</b>');
					}
					else
					{
						$("#result").html(msg);
					}
	   			}
	   		});
		}
		else
		{
			$("#result").html('<b style="font-weight:normal; color:red;">Ошибочно задан адрес электронной почты</b>');
		}
		
		return false;
	});
});
