window.addEvent('domready',subscribe_form_init);

function subscribe_form_init()
{
	var req = new Request.HTML
	(
		{
			url:'subscribe',
			method: 'post',
			onSuccess: function( tree, elements, html, javascript )
			{
				if ( html != 'ok' )
				{
					this.onFailure( );
//					$('info_pane').setStyle('color','red');
//					$('info_pane').set('text', html);
				}
				else
				{
					$('info_pane').setStyle('color','green');
					$('info_pane').set('text', 'Ваша анкета принята.');
				}
			},
			onFailure: function( )
			{
				$('info_pane').setStyle('color','red');
				$('info_pane').set('text', 'На Ваш электронный адрес подписка уже была оформлена ранее.' );
			}
		}
	);
	
	$('subscribe_form_submit').addEvent
	(
		'click',
		function ( el )
		{
			var inp_el = new Element( 'input', { 'name': 'ajax', 'type': 'hidden', 'value': '1' } );
			$('subscribe_form').adopt( inp_el );
			
			$('info_pane').setStyle('color','orange');
			$('info_pane').set('text', 'Ваши анкета отправляется.');
			
			req.send( $('subscribe_form') );
		}
	);
	$('subscribe_form').addEvent
	(
		'submit',
		function()
		{
			return false;
		}
	);
}
