/*
 * ----------------------------------------------------
 * Mootools extensions
 * ----------------------------------------------------
 * by Limarc /Alexander Lobashev/
 * (c) 2007-2008 by Limarc, Lim-on Media
 * _link: http://www.free-lance.ru/users/Limarc
 * ----------------------------------------------------
 * Index: mootools-ext.js
 * ----------------------------------------------------
 */


 window.addEvent('domready', function()
 {
     //
     // Request of objects
     // date: 23/03/2009 17:25
     //       
     var ROO = new RequestOfObjects('#search-number');
     
     if ($chk($('nomer')))
     {
	     var myCookie = Cookie.read('snumber');
	     
	     if (myCookie)
	     {
		     $('nomer').setProperty('value', myCookie);
	     }
     }
     
     if ($chk($$('#list-table tbody tr')))
     {     
	     this.tableTr = $$('#list-table tbody tr');
	     this.tableTr.each(function(tr)
	     {
		     //alert(tr.get('id'));
		     tr.addEvents
		     ({
			     mouseenter: function(e)
			     {
				     this.setStyle('background', '#b90619');
				     this.setStyle('color', '#ffffff');
			     },
			     mouseleave: function(e)
			     {
				     this.setStyle('background', '#ffffff');
				     this.setStyle('color', '#000000');
			     },
			     dblclick: function(e)
			     {
				     var myCookie = Cookie.write('snumber', this.get('id'), {domain: 'mts-corp.ru', path: '/tarif'});
				    
				     if (document.location.href.indexOf("order.php") != -1)
				     {
					     $('search-complete').set('html', '<h1>Ваш номер выбран. Заполните пожалуйста форму выше...</h1>');
					     $('search-result').set('html', '');
					     $('nomer').setProperty('value', this.get('id'));
				     }
				     else
				     {
					     location.href = this.get('rel');
				     }
			     },
			     click: function(e)
			     {
				     var myCookie = Cookie.write('snumber', this.get('id'), {domain: 'mts-corp.ru', path: '/tarif'});
				    
				     if (document.location.href.indexOf("order.php") != -1)
				     {
					     $('search-complete').set('html', '<h1>Ваш номер выбран. Заполните пожалуйста форму выше...</h1>');
					     $('search-result').set('html', '');
					     $('nomer').setProperty('value', this.get('id'));
				     }
			     }						     
		    });
	     });         
     }
     
     
     var myTips = new Tips('.promo-code');
     
     myTips.addEvent('hide', function(tip)
     {
	 tip.fade('out');
     });
     
     myTips.addEvent('show', function(tip)
     {
	 tip.fade('in');
     });     
     
     //var mySortables = new Sortables('#list-1', { revert: { duration: 500, transition: 'elastic:out' } });
     //var mySortables = new Sortables('#list-table', { revert: { duration: 500, transition: 'elastic:out' } });
     
     var table = new Table.Select('list-table', {
				parsers: ['number', false, false, 'floatLax', false]
			});
     
     $('sort-1').fireEvent('click', this, 100);
     
     
 });
 
 //
 // Class: Request of objects
 // date: 21/03/2009 20:53
 // 
 var RequestOfObjects = new Class
 ({
	 options:
	 {
		 url: '/gold/search/'
	 },
	 
	 initialize: function(element, options)
	 {
		 //
                 // RequestOfObjects -> Set option...
                 //			
		 if (options)
                 {
                         this.setOptions(options);
                 }
                 
		 //
                 // RequestOfObjects -> Filtration
                 //		 
		 if (!$chk($$(element)))
                 {
			 return;
                 }		 
		 
		 var contain = $$(element);
		 
		 //
                 // RequestOfObjects -> Action
                 //
		 contain.removeEvent("submit").addEvent('submit', this.actionObject.pass(contain, this));
	 },
	 
         actionObject: function(contain)
	 {
                 var mRequest = new Request(
		 {
			 url: this.options.url,
			 methtod: 'post',
                         encoding: 'windows-1251',
			 onRequest: function ()
			 {
				 $('search-complete').set('html', "Пожалуйста, подождите...");
                                 $$('.loading').setStyle('display', 'inline');
			 },				 
			 onSuccess: function (r)
			 {
				     $('search-result').set('html', r);
                                     $('search-complete').set('html', "");
				     
                                     $$('.loading').setStyle('display', 'none');
                                     
                                     this.tableTr = $$('#list-table tbody tr');
                                     this.tableTr.each(function(tr)
				     {
                                             //alert(tr.get('id'));
                                             tr.addEvents
                                             ({
                                                     mouseenter: function(e)
                                                     {
                                                             this.setStyle('background', '#b90619');
                                                             this.setStyle('color', '#ffffff');
                                                     },
                                                     mouseleave: function(e)
                                                     {
                                                             this.setStyle('background', '#ffffff');
                                                             this.setStyle('color', '#000000');
                                                     },
                                                     dblclick: function(e)
                                                     {
							     Cookie.write('snumber', this.get('id'), {domain: 'mts-corp.ru', path: '/tarif'});
							     
							     if (document.location.href.indexOf("order.php") != -1)
							     {
								     $('search-complete').set('html', '<h1>Ваш номер выбран. Заполните пожалуйста форму выше...</h1>');
								     $('search-result').set('html', '');
								     $('nomer').setProperty('value', this.get('id'));
							     }
							     else
							     {
								     location.href = this.get('rel');
							     }
                                                     },
                                                     click: function(e)
                                                     {
							     Cookie.write('snumber', this.get('id'), {domain: 'mts-corp.ru', path: '/tarif'});
							     
							     if (document.location.href.indexOf("order.php") != -1)
							     {
								     $('search-complete').set('html', '<h1>Ваш номер выбран. Заполните пожалуйста форму выше...</h1>');
								     $('search-result').set('html', '');
								     $('nomer').setProperty('value', this.get('id'));
							     }
                                                     }						     
                                             });
                                     });
				     
				     
				     $('sort-1').fireEvent('click', this, 100);
			 }
		 }).send(contain.toQueryString());
		 
		 return false;
         },
	 
	 Implements : [Options, Events]
 });
