function ById(id)
	{return document.getElementById(id);}


function ByTag(el,tag)
	{
	return el.getElementsByTagName(tag);
	}

function CheckEmptyField(ob)
			{
			var str = ob.value;
			if(ob.tagName.toLowerCase() == 'select')
				{
				str = ob[ob.selectedIndex].text;
				}
			var reg = new RegExp("^\\s+$","i");
			var result = reg.test(str);
			if(str=='' || result)
			  {
			  return 0;
			  }
			return 1;
			}


function IEPngBGFix(id)
	{	var ua = navigator.userAgent.toLowerCase();
	if(ua.match(/msie 6\./i)){	        src = $('div#'+id).css('background-image').match(/url\("(.+\.png)"\)/i)
			if (src){				src = src[1];
				$('div#'+id).css('background-image','none');
				ById(id).style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
			}
		}
	}

/*Проверка email*/
function CheckEmail(str)
			{
				reg = new RegExp("^[0-9\\-a-z_\\.]+@[0-9\\-a-z_^\\.]+\\.[a-z]{2,3}$","i");
				result = reg.test(str);
				if(result==false)
					 {
						return 0;
					 }
			return 1;
			}


function CheckPhone(str)
			{
				reg = new RegExp("^[0-9\-() ]{5,25}$","i");
				result = reg.test(str);
				if(result==false)
					 {
						return 0;
					 }
			return 1;
			}


function viewImg(id)
{
		if(id==0) return;
		$("span#loading").show();
		$.post(
			   "/include/ajax.php",
		{
			type: "test-request",
			target: 'basket',
			action: 'show_prev_prod',
			id: id
		},
		function(data)
		{
			$("span#loading").hide();
		},
		"script"
		);

}

function user_login(action){
  if(!action){
  	$("table#login_form").hide();
  	$('div#restore_pass').animate({opacity: "show"}, 500);
  	}
  else{
    $('div#restore_pass').hide();
    $('div#restore_err').hide();
    $('div#action_ok').hide();
    $('input#reemail').attr('value','');
    $("table#login_form").animate({opacity: "show"}, 500);
  }

}

function user_reg(action)
{
 if(action){
 	$("table#login_form").hide();
 	$('div#restore_pass').hide();
 	$("div#user_reg_form").animate({height: "show"}, 500);;
 	}
 else{
 	  $("div#user_reg_form").animate({height: "hide"}, 500, function(){
 	  	$("table#login_form").show();
	 	$('div#restore_pass').hide();
 	  });
 }
}

function newpass(id)
{
	var email  = ById(id).value;
	if(!CheckEmail(email)){
		alert('Email задан не верно!');
		return 0;
	}

	$("span#loading4").show();
	$.post(
				   "/include/ajax.php",
			{
				type: "test-request",
				target: 'users',
				action: 'user_pass_restore',
				email: email
			},
			function(data){},'script'
			);

}


function DelAllCart()
{

	$('div.cart').animate({opacity: "hide"}, 500, function()
	{
		$("span#loading").show();
		$.post(
			   "/modules/ajax/addtocart.php",
		{
			type: "test-request",
			del: 1
		},
		onAjaxSuccessAdd
		);
	});

}

function bclear(in_sales)
	{
	$('div#cart').animate({opacity: "hide"}, 500,function(){
  		$.post(
			   "/include/ajax.php",
		{
			target: 'basket',
			action: 'add',
			clear: 1,
			in_sales: in_sales
		},
		function(data){},
        "script"
		);
  		});
	}

function addToCart(in_sales)
	{
	if(arguments[1]){
		var id = $('#product_mid').attr('value');
        var base_pv_id = $('#product_id').attr('value');
		}
	else{		var id = $('#product_id').attr('value');
		var base_pv_id = 0;	}
    $('span#add_cart').animate({opacity: "hide"}, 500);
	$('div#cart').animate({opacity: "hide"}, 500,function(){
  		$.post(
			   "/include/ajax.php",
		{
			target: 'basket',
			action: 'add',
			id: id,
			base_pv_id: base_pv_id,
			in_sales: in_sales
		},
		function(data){
				$('span#add_cart').animate({opacity: "show"}, 500);
			    ShowDialogSales();
			    $('div#show_dialog').animate({opacity: "hide"}, 1500);
		},
        "script"
		);

  		});
 	}


function addToWaitingList()
	{    var id = $('#product_id_wl').attr('value');
    $('span#add_cart_wl').animate({opacity: "hide"}, 500);

    $.post(
			   "/include/ajax.php",
		{
			target: 'users',
			action: 'add_to_wl',
			id: id
		},
		function(data){
				$('span#add_cart_wl').animate({opacity: "show"}, 500);
			    ShowDialogSales(text);
			    $('div#show_dialog').animate({opacity: "hide"}, 1500);
		},
        "script"
		);

	}


function SetCenterPage(el)
	{
	     var div_h = el.clientHeight;
         var offset = (document.documentElement) ? document.documentElement : document.body;
         var clientH = offset.clientHeight;
         el.style.top = (clientH < div_h) ?  offset.scrollTop+"px" : parseInt((clientH - div_h)/2)+offset.scrollTop+"px";
         el.style.left = parseInt((offset.clientWidth - el.clientWidth)/2) + 'px';
	}


function ShowDialogSales()
	{
	var text = (arguments[0]) ? arguments[0] : 'Товар добален в корзину';
	var dialog = ById('show_dialog')
	if(dialog){dialog.parentNode.removeChild(dialog); }
	var div = document.createElement("div");
	div.id = 'show_dialog';
	div.className = 'addtocart';
	div.innerHTML = '<div>'+text+'</div>';
	document.body.appendChild(div);
    SetCenterPage(div);
	}


function ch_size(m1,m2)
{
	$('div.size_text').hide();
	$('div.text_add').hide();

		$("span#loading").show();
		$.post(
			   "/modules/ajax/ch_size.php",
		{
			type: "test-request",
			tid: m1,
			sid: m2
		},
		onAjaxSuccess4
		);
}

function ch_ccolor(id,in_sales)
	{		 var wl = (arguments[2]) ? parseInt(arguments[2]) : 0;
		 var dprod_box =  ById('poduct_pid');
		 var pid = (dprod_box) ? dprod_box.value : 0;
  $('div#prod_main_img').animate({opacity: "hide"}, 200, function(){
  		/*if(in_sales){  			$('div#dprod_img').css('background','none');}*/
  		$.post(
			   "/include/ajax.php",
		{
			target: 'catalog',
			action: 'change_ccolor',
			in_sales:in_sales,
			wl: wl,
			prodvar_id: id,
			pid:pid

		},
		function(data){},
        "script"
		);
  		});
	}

function ch_pvar(param,id,color_dop,prodvar_id,box,in_sales,wl_)
{
  if(wl_){  	 var wl = 1;
  	 var wl_s = '_wl';
 	 }
  else{  	var wl  = 0;  	var wl_s = '';
  	}
//  alert(arguments[7]);
//  alert(wl);
  var pid = $('#product_pid').attr('value');
  var mpid = $('#product_mid').attr('value');
  var pcolor = $('#product_pcolor'+wl_s).attr('value');
  var ccolor = $('#product_ccolor'+wl_s).attr('value');
  var fason = $('#product_fason'+wl_s).attr('value');
  var base_id = (arguments[7]) ? $('#product_base_id'+wl_s).attr('value') :0;
  $('div#'+box+wl_s).animate({opacity: "hide"}, 500,function(){
  		$.post(
			   "/include/ajax.php",
		{
			target: 'catalog',
			action: 'change_prodvar',
			pid: pid,
			fason: fason,
            pcolor: pcolor,
            ccolor: color_dop,
			prodvar_id: prodvar_id,
			mpid: mpid,
			param: param,
			in_sales: in_sales,
			wl:wl,
			id_param: id,
			base_id: base_id
		},
		function(data){},"script");

  		});
  $('div#prod_main_img').animate({opacity: "hide"}, 200);
}



function SetProdSize(el)
	{
    var in_sales =  (arguments[2]) ? arguments[2] : 0;
    if(arguments[1]){    	var wl_s = '_wl';    	var wl = 1;
    	}
    else{    	var wl_s = '';
    	var wl = 0;   	  }
    var main_id = (arguments[3]) ? $('#product_mid'+wl_s).attr('value') : 0;
    $("input#product_id"+wl_s).attr("value",el.value);
    if(wl)
    	 { $("span#loading21").show();}
    else
    	{ $("span#loading2").show();}
    //$("div#product_size").attr("value",el.value);
	$.post(
			   "/include/ajax.php",
		{
			target: 'catalog',
			action: 'check_nal',
			wl:wl,
			id: el.value,
			in_sales: in_sales,
			main_id: main_id
		},
		function(data){}, "script");

//	$('span#add_cart').animate({opacity: 'show'}, 500);
	}

function Dostavka(index_id,oplata,delivery_id)
{
        var index  = ById(index_id);
        if (!index || index.value.length<3) return;
		var delivery  = ById(delivery_id);
		if(!delivery || delivery.value == 0) {		alert('Укажите способ доставки!'); return;		}
		if(oplata==0){		alert('Укажите способ оплаты!'); return;		}
		$("span#loading2").show();
        $("div#errOplata").hide();

			$.post(
				   "/include/ajax.php",
			{
				type: "request",
				target: 'users',
				action: 'getdostavka',
				index: index.value,
				oplata: oplata,
				delivery: delivery.value
			},
				function(data){}, 'script'
			);
}

function GetOplata(delivery)
	{	$("span#loading2").show();
	$("div#errDelivery1").hide();
	$("div#errDelivery2").hide();
			$.post(
				   "/include/ajax.php",
			{
				type: "request",
				target: 'users',
				action: 'getoplata',
				delivery: delivery
			},
				function(data){}, 'script'
			);

	}


function selIndexReg(index)
	{
      $.post(
				   "/include/ajax.php",
			{
				type: "request",
               	target: 'users',
				action: 'getindex',
				index: index

			},
        	function(data){}, 'script'
			);
	}


function selIndex(index,oplata_id,delivery_id)
{

		var oplata_box = ById(oplata_id);
		var oplata = (oplata_box) ? oplata_box.value : 0;
        var delivery_box = ById(delivery_id);
        var delivery = (delivery_box) ? delivery_box.value : 0;

			$.post(
				   "/include/ajax.php",
			{
				type: "request",
               	target: 'users',
				action: 'getindex',
				index: index

			},

				function(data){
					var deliv = ById()
					if ((index.length==6 || index.length==3) && oplata >0 && delivery >0)
						Dostavka('s_index',oplata,delivery_id);
				}, 'script'

			);
}
function selCorp(m1)
{
		if (m1.length>0)
	$("input[@name='nocorpus']").check('off');
	else
	$("input[@name='nocorpus']").check('on');
}
jQuery.fn.check = function(mode) {
   // если mode непоределен, используем 'on' по умолчанию
   var mode = mode || 'on';

   // В функцию неявно передана коллекция выбранных элементов.
   // Поэтому с этой коллекцией можно работать, как с любой другой
   // коллекцией элементов в jQuery
   // В нашем случае мы воспользуемся методом each()
   return this.each(function() {
     switch(mode) {
       case 'on':
         this.checked = true;
         break;
       case 'off':
         this.checked = false;
         break;
       case 'toggle':
         this.checked = !this.checked;
         break;
     }
   });
 };
function selDom(m1)
{
	if (m1.length>0)
	$("input[@name='noroom']").check('off');
	else
	$("input[@name='noroom']").check('on');
}

function ShowPhotoProd(id)
	{
    $("div#prod_main_img").animate({height: 'hide'}, 500, function(){
    $.post(
				   "/include/ajax.php",
			{
				type: "request",
               	target: 'catalog',
				action: 'showphoto',
				id: id,
				box: 'prod_main_img'

			},

				function(data){$("div#prod_main_img").animate({height: 'show'}, 500);}, 'script'

			);
		});
	}

function chPass()
{
	var params = {};
	$(document).find("input[@type='password']").each(function() {
		params[ this.id ] =this.value;
	});
	if (params['pass'] == params['repass'] )
		$("span.pass").css( "background-color", "green" );
	else $("span.pass").css( "background-color", "red" );
	$("span.pass").show();
}


function ShowZakaz(order_id)
	{
     if($("div.Zakaz"+order_id).css('display')=='none')
     	$("span#loading").show();
     else
     	{
     	$("span#loading").hide();
     	$("div.Zakaz"+order_id).hide();
     	return;
     	}

     $.post(
				   "/include/ajax.php",
			{
				type: "request",
				target: 'users',
				action: 'show_zakaz',
				order_id: order_id
			},
				function(data){}, 'script'
			);

	return;
	}
function User_Logout(){
	if(!confirm('Ваша текущая корзина будет очищена. Продолжить?')) return;
	location.href = '/cabinet/?action=logout';
	}


function ShowUserCabWList()
	{	var derl_wl = (arguments[0]) ? arguments[0] : 0;
    var div = (arguments[1]) ? arguments[1] : '';
    if(derl_wl!=0){    	$('div#zakl11_box').html('<div style="padding:100px 0;text-align:center "><span id="loading21"><img src="/images/loading.gif"></span></div>');
   	 }

    $.post(
				   "/include/ajax.php",
			{
				type: "request",
				target: 'users',
				action: 'show_wlist',
				id: derl_wl,
				div: div
			},
				function(data){}, 'script'
			);	}


function ShowUserCabInnerMsg(box_id)
	{     $('div#'+box_id).html('<div style=\"padding:100px 0; text-align:center\"><span id=\"loading21\"><img src=\"/images/loading.gif\"></span></div>');
     $.post(
				   "/include/ajax.php",
			{
				type: "request",
				target: 'users',
				action: 'show_imsg_list',
				div: box_id
			},
				function(data){}, 'script'
			);
	}

function SendAdminMsg()
	{     var msg_box = ById('inmsg');
     if(msg_box){        if(!CheckEmptyField(msg_box)){        	alert('Не указан текст сообщения!');        	return;
        	}
        $("div#zakl4_box").animate({opacity: "hide"}, 500,function(){
        $.post(
				   "/include/ajax.php",
			{
				type: "request",
				target: 'users',
				action: 'send_imsg',
				div: 'zakl4_box',
				msg: msg_box.value
			},
				function(data){$("div#zakl4_box").animate({height: "show"}, 500);}, 'script'
			);
         });     	}
	}

function SendReview()
	{
     var msg_box = ById('inmsg');
     if(msg_box){
        if(!CheckEmptyField(msg_box)){
        	alert('Не указан текст отзыва!');
        	return;
        	}
        $("div#review_text_box").animate({opacity: "hide"}, 500,function(){
        $.post(
				   "/include/ajax.php",
			{
				type: "request",
				target: 'users',
				action: 'send_review',
				div: 'review_text_box',
				review: msg_box.value
			},
				function(data){$("div#review_text_box").animate({height: "show"}, 500);}, 'script'
			);
         });
     	}
	}



function UserDelMsg(id)
	{      $("div#zakl4_box").animate({opacity: "hide"}, 500,function(){
       $.post(
				   "/include/ajax.php",
			{
				type: "request",
				target: 'users',
				action: 'del_imsg',
				div: 'zakl4_box',
				id: id
			},
				function(data){$("div#zakl4_box").animate({height: "show"}, 500);}, 'script'
			);
        });
	}


function ClearUserCabWList(id)
	{     if(!confirm("Очистить лист ожидания?")) return;
     ShowUserCabWList(-1,id)
	}

function ShowAddToWL(action)
	{                             $('div#restore_pass').animate({opacity: "show"}, 500);    if(action){       $("div#order_nal_box").animate({height: "hide"}, 500,function(){$("div#order_wl_box").animate({height: "show"}, 500);});
      }
    else{     $("div#order_wl_box").animate({height: "hide"}, 500,function(){$("div#order_nal_box").animate({height: "show"}, 500);});
      }
	}


function ChangeOrderDelivery(delivery,order_id)
	{    var index = ById('order_index'+order_id);
    if(index && delivery>0){          $("div#delivery_err"+order_id).hide();

          var olplata = ById('order_oplata'+order_id);
          $(olplata).html('<option></option>');
          $(olplata).attr("disabled","disabled");

          $.post(
				   "/include/ajax.php",
			{
				type: "request",
				target: 'users',
				action: 'getoplata_in_order',
				delivery: delivery,
				index: index.value,
				order_id:order_id
			},
				function(data){}, 'script'
			);

	    }
	}

function ChangeOrderOplata(order_id)
	{
    if(!confirm('Изменить способ доставки и оплаты заказа?')) return false;
    var oplata = ById('order_oplata'+order_id);
    var delivery = ById('order_delivery'+order_id);
    var index = ById('order_index'+order_id);
    if(oplata && delivery && index){
         $.post(
				   "/include/ajax.php",
			{
				type: "request",
				target: 'users',
				action: 'update_order_oplata',
				delivery: delivery.value,
				id:order_id,
				index: index.value,
				oplata: oplata.value
			},
				function(data){}, 'script'
			);

    	}
	}

function UserCabChangeZakl(el)
	{
	var arrDiv = ByTag(ById('panel_zbox'),'div');
    var cur_zakl = '';
    var pref = (arguments[1]) ? arguments[1]: '';
    var action = (arguments[2]) ? arguments[2]: '';
    if(arrDiv){
	    for(var i = 0; i<arrDiv.length; i++){
	     arrDiv[i].className = 'user_cab_zakl';
	     if(arrDiv[i].id != el.id){	     	$("div#"+arrDiv[i].id+"_box").hide();
	     }
	     else{	     	   cur_zakl  = arrDiv[i].id+"_box";	     	   $("div#"+cur_zakl).show();
	     	}
	    }
    }
    el.className = 'user_cab_zakl_s';
    switch(action){
    	case 'show_wl':
	    	var user_wl_box = ById('user_wl_box');
	           if(!user_wl_box)
	           	{	            ShowUserCabWList(0,cur_zakl);
	           	}
    	break;
    	case 'show_imsg':
	            ShowUserCabInnerMsg(cur_zakl);
    	break;
   	  }

	}


function UserRegSubmit(oFormId,box)
		{
        var oForm = ById(oFormId);
        //var user_edit = (arguments[1]) ? arguments[1] : 0;
        $("span#loading2").show();
        $("span#loading7").show();
        oForm.submit = function(){
                	var params = {};
		    $(document)
		    .find("input[@checked], input[@type='text'], input[@type='hidden'], input[@type='password'], input[@type='submit'], option[@selected], textarea")
		    .filter(":enabled")
		    .each(function() {
		      params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
		    });
				params['target'] = 'users';
				params['action'] = 'user_try_reg';
				params['div_box'] = box;

				$.post("/include/ajax.php", params,function(data){$("span#loading2").hide(); $("span#loading7").hide();},'script' );
				return false;
				}
        oForm.submit();
		}


function ClearFastOrderForm()
	{     $('input#user_phone').attr('value','');
     $('input#user_name').attr('value','');
     $('input#user_sname').attr('value','');
     $('input#user_email').attr('value','');
	}

function BasketSubmitNotReg(oFormId,button)
	{    var oForm = ById(oFormId);
    var phone = ById('user_phone');
    var name  = ById('user_name');
    var sname  = ById('user_sname');
    var email  = ById('user_email');
    if(oForm && phone && name){		 if(!CheckPhone(phone.value)) {		 	alert('Телефон указан не верно!');
            phone.focus();
		 	return;
		 }

		 if(!CheckEmptyField(name)) {
		 	alert('Укажите Ваше имя!');
            name.focus();
		 	return;
		 }

         if(!CheckEmptyField(sname)) {
		 	alert('Укажите Вашу фамилию!');
            name.focus();
		 	return;
		 }
    	 $("span#loading2").show();
    	 button.disabled = true;
    	 $.post(
				   "/include/ajax.php",
			{
				type: "request",
				target: 'users',
				action: 'user_save',
				mobile: phone.value,
				name: name.value,
				sname : sname.value,
				email: email.value,
				notreg: 1
			},
				function(data){}, 'script'
			);
    	}
	}


//$.fn.ajaxSubmit = function() {
function BasketSubmit(oFormId,button){
			/* Change a form's submission type to ajax */
			var oForm = ById(oFormId);
			if(oForm){

				var params = {};
			    $(document)
			    .find("input[@checked], input[@type='text'], input[@type='hidden'], input[@type='password'], input[@type='submit'], option[@selected], textarea")
	            .each(function() {
			      params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
			    });
			  		$("span#loading2").show();
					params['target'] = 'users';
					params['action'] = 'user_save';

					$.post("/include/ajax.php", params,function(data){},'script' );
				}
   			 //button.disabled = true;
		}


	function CheckForm()
	{
     var uForm = document.getElementById(arguments[0])
			for (var i=0; i < uForm.length; i++)
				{
				if($(uForm[i]).attr('validate') =='text' && CheckEmptyField(uForm[i]) == 0)
					{
					alert("Поле должно быть заполнено");
					uForm[i].focus();
					return;
					}
				else if($(uForm[i]).attr('validate') =='email' && CheckEmail(uForm[i].value) == 0)
				 	{
					alert("Поле заполнено не верно");
					uForm[i].focus();
				     return 0;
					}
				}
     uForm.submit();
	}

	function SetCatalogFilter()
		{         var form_filter  = ById('form_cfilter');
         var size_box  = ById('filter_size');
         if(form_filter && size_box){           var size_field  = ById('size_field');
           if(size_field){               var arrSize = $(size_box).find('input[@type="checkbox"]');
               var list_size = '';
               var flag = 0;               for (var i=0; i < arrSize.length; i++){                 if(!arrSize[i].checked){                    if(flag) list_size += ',';
                    list_size += arrSize[i].value;
                    flag = 1;                    }
               }
                size_field.value  = list_size;
          	 }
          form_filter.submit();
          }		}

	/*function ClearCatalogFilter()
		{         var form_filter  = ById('form_cfilter');
         var action  = ById('f_action');
         if(action) action.value = 0;
         form_filter.submit();		}
      */

      function ClearCatalogFilter(action)
		{
         var form_filter  = ById('form_cfilter');
         if(action==1){
	         $('input#nal_def').attr('checked',true);
    	     $('input#date_def').attr('checked',true);
    	     var ch = true
    	     }
    	 else{    	 	 $('input#in_nal').attr('checked',true);
    	     $('input#date_enable').attr('checked',true);
    	     var ch = false    	 }

         $('form#form_cfilter')
		    .find("input[@type='checkbox']")
		    .each(function() {
		      this.checked = ch;
		    });
		}

	 function  ShowProdNalInfo(pid,nal,in_sales,event)
	 	{		e = event || window.event;
		var info_box = ById('show_info')
		if(info_box){			SetToMousePosition(info_box,e);
			return;}
		else{			var head = (nal) ? 'Товар есть в наличии':'Товара нет в наличии';
			var info_box = document.createElement("div");
			info_box.id = 'show_info';
			info_box.className = 'prod_show_info';
			info_box.innerHTML = (nal) ?  '<div class="prod_show_info_h">'+head+'</div><div id="prod_show_info_b"><div class="load">&nbsp;</div></div>' : '<div class="prod_show_info_h">'+head+'</div>';
			document.body.appendChild(info_box);
            if(nal)
            	{
		            $.post(
						   "/include/ajax.php",
							{
								type: "request",
								target: 'catalog',
								action: 'show_prod_nal_info',
								pid: pid,
								in_sales: in_sales
							},
								function(data){}, 'script'
							);
                }
            else
			SetToMousePosition(info_box,e);
			}
	 	}

	 function SetToMousePosition(el,e)
	 	{        var position = defMousePosition(e);
        el.style.top = position.y -22+"px";
		el.style.left = position.x+5+"px";	 	}

	 function ShowProdNalClose()
	 	{	 	var info_box = ById('show_info');
		if(info_box) { info_box.parentNode.removeChild(info_box);}
	 	}

	 //Опеределяет позицию курсора мышки
	function defMousePosition(event) {
		var x = y = 0;
		if (document.attachEvent != null) { // Internet Explorer & Opera
			x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
			y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
		}
		if (!document.attachEvent && document.addEventListener) { // Gecko
			x = event.clientX + window.scrollX;
			y = event.clientY + window.scrollY;
		}
		return {x:x, y:y};
	}

function SetCenterPage(el)
	{
	     var offset =  (document.documentElement) ?  document.documentElement : document.body;
	     var div_h = el.clientHeight;
         var clientH = offset.clientHeight;
         var scrollTop = (offset.scrollTop >  document.body.scrollTop) ? offset.scrollTop : document.body.scrollTop;
         el.style.top = (clientH < div_h) ?  scrollTop+"px" : parseInt((clientH - div_h)/2)+scrollTop+"px";
         el.style.left = parseInt((offset.clientWidth - el.clientWidth)/2) + 'px';
	}

function SetSizeShowBgimg(el)
		{
		  var div_box = document.getElementById('show_img_bg');
		  if(!div_box) return;
		  div_box.style.height = el.height+20+'px';
          div_box.style.width = el.width+'px';
          div_box.style.padding = '10px';
		  var imgs  = div_box.getElementsByTagName('img');
		  SetCenterPage(div_box);
		  imgs[0].style.display = '';
   		}

function CloseShowBgImg()
	{
	 var div_box =  document.getElementById('show_img_bg');
     var div_bg =  document.getElementById('img_bg_bl');
     if(div_box) div_box.parentNode.removeChild(div_box);
     if(div_bg) div_bg.parentNode.removeChild(div_bg);
	}

function ShowBgImg(img_url)
	{
     if(ById('show_img_bg')) CloseShowBgImg();
     var img = new Image();
     img.id  = 'show_img_src';
     img.alt  = '';
     img.style.display = 'none';
     img.onload  = function()
     				{
                     this.style.display = 'inline';
                     SetSizeShowBgimg(this);
	  				}
	 img.onclick  =  CloseShowBgImg;
	 img.src =  img_url;
     var div_bg = document.createElement("div");
     var div_box = document.createElement("div");
     var div_cl = document.createElement("div");
     div_cl.className = 'show_bg_img_close';
     div_cl.onclick = CloseShowBgImg;

     div_cl.appendChild(document.createTextNode('Закрыть'));
     div_bg.id  = 'img_bg_bl';
     div_box.className = "show_img_bg";
     div_box.id = "show_img_bg";
     div_bg.className = "img_bg_bl";
     div_box.appendChild(div_cl);
     div_box.appendChild(img);

     div_bg.style.backgroundColor = '#000';
     var off_w = (document.documentElement && document.documentElement.clientWidth) || document.body.clientWidth;
     var off_y = document.body.scrollHeight || (document.documentElement && document.documentElement.scrollHeight);
     var left_off  = (document.documentElement && document.documentElement.scrollWidth) || document.body.scrollWidth;

     var width_bg = (left_off > off_w) ? left_off : off_w;

     div_bg.style.width = left_off+'px';
     div_bg.style.height = off_y + 'px';

     div_box.style.textAlign = 'right';
     div_bg.style.filter = "alpha(opacity='80')";

     div_box.style.width = 300 + 'px';
     div_box.style.height = 300 + 'px';
     div_box.style.padding = '10px';
     div_box.style.backgroundColor = '#fff';

     div_box.style.filter = "alpha(opacity='100')";
     div_bg.style.top = 0;
     div_bg.style.left = 0;

     document.body.appendChild(div_bg);
     document.body.appendChild(div_box);
     SetCenterPage(div_box);
     //var img_ =  document.getElementById('show_img_src');
     if(img && img.width > 0){SetSizeShowBgimg(img)};
   	}

function CloseProdvarPhoto()
	{
	$('#prodvar_preview_img').hide();
	//var div  = ById('prodvar_preview_img');
	//if(div) div.parentNode.removeChild(div);

	}


var last_show_img = 0;
function ShowProdvarPhoto(el,event)
	{
      e = event || window.event;
	  var prodvar_id = el.id.replace(/^([a-zA-Z]*)_/,'');
	  var div  = ById('prodvar_preview_img');
	  if(div && prodvar_id == last_show_img){
		 $('#prodvar_preview_img').show();
		//  CloseProdvarPhoto();
		}
	  else {            if(div) div.parentNode.removeChild(div);
    		var div = document.createElement("div");
    		div.className = 'prodvar_show_img_box';
    		div.innerHTML = '&nbsp;';

    		div.id = 'prodvar_preview_img';
    		document.body.appendChild(div);

    		$.post(
						   "/include/ajax.php",
							{
								type: "request",
								target: 'catalog',
								action: 'show_smallphoto',
								div: 'prodvar_preview_img',
								id: prodvar_id
							},
								function(data){}, 'script'
							);


    		/*
    		ajax_request = 'div=prodvar_preview_img&action=showphoto&target=catalog&id='+prodvar_id;
    		GoCatalogRequest(ajax_request);*/
    		last_show_img = prodvar_id;
    	}
    	var position = defMousePosition(e);
    	div.style.top = position.y +"px";
		div.style.left = position.x+"px";
	}

function InitShowPhotoProduct(id)
	{    var box = ById(id);
    if(box){        var arrProd = ByTag(box,'a');
        if(arrProd){            for(var i=0;i<arrProd.length;i++){            	prodvar_id = '' + arrProd[i].id;
            	arrProd[i].onmousemove = function(event){ShowProdvarPhoto(this,event);};
            	arrProd[i].onmouseout = function(){CloseProdvarPhoto();};
            	}
        	}
    	}
	}

 	function MenuInit(id){
		var obj = (id.constructor == Object) ? id : document.getElementById(id);
		var arrBlock  = obj.getElementsByTagName('li');
		if(arrBlock){
			for(var i=0;i<arrBlock.length;i++){
			  arrBlock[i].onmouseover = function(){this.className = 'select';};
			  arrBlock[i].onmouseout = function(){this.className = 'n_select';};
			  }
			}
	}