window.addEvent('domready', function() {
	form_send();

		 function form_send() {
		
		 //AJAX запрос 
		  if ($chk($$('.js-send'))) {

		  		if	($$('.js-form').getElement('#ajax').get('value')==1) {
					 $$('.js-form').addEvent('submit', function(e) { // добавляем событие к форме
						    var node =  this;
						   // var  n= node.getParent().getParent();
						   // n.getElement('.status').set('html','<img src="/images/ajax-loader.gif">'); 
						    new Event(e).stop(); // блокируем открытие страницы, указанной в action	    
						    
						    this.set('send', { // обработка запроса
						        onSuccess: function(response) { // запрос выполнен уcпешно
						             //n.getElement('.status').set('html','');						            				            
						             
									 node.getParent().set('html',response) ;
						             form_send();
						            
						        },
						        onFailure: function() { // ошибка запроса
						           
						        },
						        onCancel: function() { // отмена запросаы
						              
						        }
						    }).send();
						});
				}
		 }
		 if ($chk($$('.js-close'))) {
		  
					 $$('.js-close').addEvent('click', function(e) {
					 		new Event(e).stop(); 				  
						  this.getParent().getParent().morph({'opacity': 0}); 
						   
					});
		 }	  
		 if ($chk($$('.js-openform'))) {
		  
					 $$('.js-openform').addEvent('click', function(e) {
					 		new Event(e).stop();
							 var rel= this.get('rel');
							  $$('.popup').setStyle('visibility','hidden');
							  $$('.popup').setStyle('z-index','0');
							  var left = document.body.scrollLeft/2;
							  var top = document.body.scrollTop/2;
		                      
							  
							  $('popup'+rel).setStyle('z-index', '9999');  					 
							 $('popup'+rel).morph({'opacity': 1});  				  
						  
						   
					});
		 }	          	      
		
		}
});
