var initialTab = "";window.addEvent('domready', function(){	var i=0;	$$('a[rel=\'external\']').setProperty('target','_blank'); // Добавляем таргет всем ссылкам где стоит рел екстернал	if ($$('table tr')[0]) $$('table tr')[0].addClass('firsttr');	$$('table tr').each(function(element) { // Нечетным элементам таблиц добавляем класс		if (i++%2 == 0)		  {		  element.addClass('odd');		  }	});	$$('var').each(function(element) { // Для всех элементов информации		var info = JSON.decode(element.innerHTML);		if (info.preload) // Предподгрузка картинок		  {		  if ($type(info.preload) == 'string')		    {		    preload(info.preload)		    }		  else if($type(info.preload) == 'array')		    {		    info.preload.each(function(element){		    	preload(element);		    	});		    }		  }		if (info.mname && info.id) // Если есть название модуля и id, то это страница просмотра материала		  {		  new Request({method: 'post', url: '/ajax/count.php'}).send('id='+info.id+'&mname='+info.mname);		  }	});	$$('.highlight').each(function(element) {		element.addEvent('click', function(e) {			regexp = /.+(\.png|\.jpg|\.jpeg|\.gif)/i; // По этому регулярному выражению определяется картинка			if(regexp.test(element.getProperty('href')))			  {			  image = new Element('img', {'src':element.getProperty('href')});			  $('inlightbox').empty();			  $('inlightbox').adopt(image);			  }			showbox('show');			// Смещаем блок на половину чтоб отображался поцентру			lightboxSize = $('lightbox').getSize();			offsetX = Math.floor(lightboxSize.x/2);			$('lightbox').style.width = lightboxSize.x+'px';			$('lightbox').style.marginLeft = -offsetX+'px';			offsetY = Math.floor(lightboxSize.y/2);			$('lightbox').style.height = lightboxSize.y+'px';			$('lightbox').style.marginTop = -offsetY+'px';			e.stop();		});	});    if ($('CommentForm'))      {      $('CommentForm').addEvent('submit', function(e) {		e.stop();		var info = JSON.decode($('mid').innerHTML);		var log = $('CommentFormResult').empty().addClass('ajax-loading');		this.set('send', {url: '/ajax/addcomment.php?id='+info.id, evalScripts: true, onComplete: function(response) {			log.removeClass('ajax-loading');			log.set('html', response);		}});		this.send();	  });      }	if($('search')) // Если на странице есть форма поиска	  {	  $('search').addEvent('submit', function(event){ document.location = $('search').action+$$('form#search input[name="search"]')[0].value; return false; });	  }	// Ставим всем формам невидимое поле для того чтобы потом скриптом проверять его наличие чтоб определять что это был человек а не бот	inputElement  = new Element('input', {id: 'ishuman', 'type':'hidden', 'name':'ishuman','value':'1'});	$$('form').each(function(element) {			if(element.id) {				$(element.id).grab(inputElement);			}	});	if ($('register'))	  {	  $('register').addEvent('submit', function(e) {		e.stop();		var log = $('rezultdiv').empty().addClass('ajax-loading');		this.set('send', {url: '/modules/users/ajax/register.php', evalScripts: true, onComplete: function(response) {			log.removeClass('ajax-loading');			log.set('html', response);		}});		this.send();	  });	  }	$$('#register input').addEvent('keydown', function(e) {		$(this.getProperty('id')+'_div').removeClass('formerr');	});	init_toolpips($$('.tooltip'));	initStateFromURL();	setInterval(initStateFromURL, 1000);	fader = new Element('div', {'id':'fader'});	$$('body').adopt(fader);	fader.addEvent('click', function(e) {		showbox('hide');	});	lightbox = new Element('div', {'id':'lightbox'});	inlightbox = new Element('div', {'id':'inlightbox'});	$$('body').adopt(lightbox.adopt(inlightbox));	ajaxinit($$('a'));});function showbox(act)  {  if (act == 'show')    {    $('lightbox').style.visibility = 'visible';    $('lightbox').style.display = 'block';	$('fader').style.visibility = 'visible';    $('fader').style.display = 'block';    }  else    {    $('lightbox').style.visibility = 'hidden';    $('lightbox').style.display = 'none';	$('fader').style.visibility = 'hidden';    $('fader').style.display = 'none';    }  }function initStateFromURL() {		if (window.location.hash==initialTab) {      		 return; // Nothing's changed since last polled.     	}        regexp = /\/p([0-9]+)\//i; // По этому регулярному выражению определяется является ли строка партнерской ссылкой		if(regexp.test(window.location.hash))		  {		  var once;		  if (!once)		    {		    rez = regexp.exec(window.location.hash);    		window.location.hash = '';    		initialTab = window.location.hash;		    var myCookie = Cookie.write('partner', rez[1], {duration: 30}); // Ставим куку о том кто привел		    once = 1;		    }	      }	    else	      {     	  var loadhref = '';		  initialTab = window.location.hash;		  for(i=1;i<initialTab.length;i++)	  	    {	  		loadhref += initialTab[i];	  	    }		  if (loadhref) ajaxload(loadhref);	      }   }function ajaxinit(elems) { // Для всех elems ставим события чтобы они грузились через ajax    if (!$('focus')) {}	elems.each( function(element) {		element.addEvent('click', function(e){			var href = element.getProperty('href');			if (href[0] == '/' && element.hasClass('ajax'))			  {			  ajaxload(href);			  $('focus').focus();			  e.stop();			  }			else			  {			  return true;			  }		});	});}function ajaxload(href,elemid) {	var elemid = (elemid)?elemid:'infodiv';	var sizes = $(elemid).getScrollSize();	var loading = $$('body').addClass('ajax-loading');	$(elemid).setProperty('style','height:'+sizes.y+'px;');	var container = $(elemid).empty();	var myRequest = new Request({url: href, method: 'post', evalScripts: true, onSuccess: function(responseText, responseXML) {    	container.innerHTML = responseText;    	loading.removeClass('ajax-loading');    	ajaxinit($$('#'+elemid+' a'));    	$(elemid).setProperty('style','height:auto;');    	initialTab = '#'+href;    	window.location.hash = href;    }}).send('ajax=1');}function make_error() {	this.length = arguments.length;  	for (var i = 0; i < this.length; i++)  	  {      $(arguments[i]+'_div').addClass('formerr');      }}function init_toolpips(elems)  {  toolTips = new Tips(elems);  }function preload(src)  {  var img = new Image();  img.src = src;  }function Poll_SetVote()  {  var myHTMLRequest = new Request.HTML({url:'/modules/poll/ajax/otvetil.php',  		onSuccess: function(html) {			$('pollresults').set('text', '');			$('pollresults').adopt(html);		}  }).post($('pollform'));  return false;  }function Poll_vote_rezults(obj)  {  var myHTMLRequest = new Request.HTML({url:'/modules/poll/ajax/otvetil.php',  		onSuccess: function(html) {			$('pollresults').set('text', '');			$('pollresults').adopt(html);		}  }).post($('pollform'));  return false;  }function Shop_update_cartprice(num)  {  new Request.HTML({url:'/modules/shop/ajax/cartprice.php',		onSuccess: function(html) {              $('cart_price').set('text', '');			  $('cart_price').adopt(html);		      var total_price = parseInt($('cart_price').innerHTML);		      if ($('skidkanum'))		        {		        var skidka = parseInt($('skidkanum').innerHTML);                $('cart_skidka_price').innerHTML = total_price-total_price*skidka/100;                }              $('cart_kolvo').innerHTML = num;		      $('cart_total_price').innerHTML = total_price;		}	,evalScripts: true}).get();  }function shop_addToCart (id){ // Добавление товара в корзину	var kolvo = $('_kolvo').value;	var size = $('_size').value;	if ($('size2') && !$('_size').value) // Если есть вторая ссылка для выбора размера и размер не выбран, то сообщение	  {	  alert('Выберите размер');	  return false;	  }	var loading = $('addbutton').value = 'Добавление...';	var container = $('rez_div');	loading.disabled = 'true';	var myRequest = new Request({url: '/modules/shop/ajax/to_cart.php', method: 'get', evalScripts: true, onSuccess: function(responseText, responseXML) {    	alc.removeClass('ajax-loading');    }}).send('id='+id+'&kolvo='+kolvo+'&size='+size);    $('focus').focus();}function shop_change_size(num,j)  {  $('_size').value = num;  for (var i=1;;i++)    {    if (!$('size'+i))      {      break;      }    $('size'+i).removeClass('sel_size_selected');    }  $('size'+j).addClass('sel_size_selected');  }var total_price;function shop_check_dostavka(sposob)  {  if (!sposob) return;  if (!total_price)    {    total_price = parseInt($('k_oplate').innerHTML);    }  if ($$('var')[0]) // Если находимся на странице просмотра материала    {    var info = JSON.decode($$('var')[0].innerHTML);    if(/\%$/.test(info[sposob]))      {      izmenenie = Math.floor(parseInt(info[sposob])*total_price/100);      }    else      {      izmenenie = parseInt(info[sposob]);      }    if (izmenenie < 0) // Даем скидку      {      $('slovo_sposoba_oplaty').innerHTML = 'Скидка за предоплату';      $('k_oplate').innerHTML = total_price+izmenenie;      $('stoimost_dostavki').innerHTML = Math.abs (izmenenie);      }    else      {      $('slovo_sposoba_oplaty').innerHTML = 'Стоимость доставки';      $('k_oplate').innerHTML = total_price+izmenenie;      $('stoimost_dostavki').innerHTML = izmenenie;      }    $('stoimost_dostavki_div').style.display = 'block';    }  }function shop_sel_country(){	$('region').disabled=true;	$('city').disabled=true;	new Request.HTML({url:'/modules/shop/ajax/sel_country.php?id_country='+$('country').value,		onSuccess: function(html) {              $('div_region').set('text', '');			  $('div_region').adopt(html);		      shop_after_sel_country();		}	,evalScripts: true}).get();}function shop_after_sel_country(num){	if($('xer_region').value==1){		shop_sel_region();	}else{		$('div_city').innerHTML='<select style="width:180px;" id="city" name="city"><option value="0">Выберите регион</option></select>';		$('city').disabled=true;	}}function shop_sel_region(){	if($('region').value==-1){		if(!$('other_region')){			$('div_region').innerHTML+='<div id="other_region"><input class="inp" type="text" style="width:180px;" name="other_region" value=""></div>';		}		$('region').value=-1;	}else{		if($('other_region'))$('div_region').removeChild($('other_region'));	}	if($('region').value!=0){		$('city').disabled=true;		new Request.HTML({url:'/modules/shop/ajax/sel_region.php?id_country='+$('country').value+'&id_region='+$('region').value,		onSuccess: function(html) {              $('div_city').set('text', '');			  $('div_city').adopt(html);		      shop_after_sel_region();		}	,evalScripts: true}).get();	}else{		$('div_city').innerHTML='<select style="width:180px;" id="city" name="city"><option value="0">Выберите регион</option></select>';		$('city').disabled=true;	}}function after_sel_region(){}function shop_sel_city(){	if($('city').value==-1){		if(!$('other_city')){			$('div_city').innerHTML+='<div id="other_city" ><input class="inp" type="text" style="width:180px;" name="other_city" value=""></div>';		}		$('city').value=-1;	}else{		if($('other_city'))$('div_city').removeChild($('other_city'));	}}function shop_full_form_check()  {  var i = $$('.inp_posob_oplati');  var sposob_oplati_vibran;  i.each(function(el) { if(el.checked) { sposob_oplati_vibran = 1; } });  if (!sposob_oplati_vibran)    {    alert('Необходимо выбрать способ оплаты');    err = 1;    }  else    {    err = 0;    if (!$('country').value)      {      alert('Необходимо выбрать страну');      err = 1;      }    else      {      err = 0;      if (!$('region').value && !$('other_region').value)        {        alert('Необходимо указать регион');        err = 1;        }      else        {        err = 0;        if (!$('city').value && !$('city').value)          {          alert('Необходимо указать город');          err = 1;          }        else          {          err = 0;          }        }      }    }  if (!err)    {    $('last_step_form').submit();    }  return false;  }function users_login()  {  $('loginform').submit();  }function addmark(mark)  {  toolTips.hide();  info = JSON.decode($$('var')[0].innerHTML.toString());  $('rateinfo').empty();  var loading = $('ratingdiv').addClass('ajax-loading');  var myRequest = new Request({url: '/ajax/vote.php', method: 'post', evalScripts: true, onSuccess: function(responseText, responseXML) {    	loading.removeClass('ajax-loading');  }}).send('id='+info['id']+'&mark='+parseInt(mark));  }function redirect(url)  {  var myRequest = new Request({url: '/ajax/redirect.php', method: 'post', evalScripts: true, onSuccess: function(responseText, responseXML) {  }}).send('path='+url);  }
