var tmp_big_img = new Image();
var newimg 		= new Array();
var ua 			= navigator.userAgent.toLowerCase();
Preload();

$(document).ready(function(){
		 $('#coin-slider').coinslider({ width: 490, navigation: true, delay: 5000 });
		 /*
		 $("ul.sf-menu").superfish({
            animation: {height:'show'},
            disableHI: true,
            autoArrows: false,
            delay:     800,
            dropShadows: 0,
			speed: "fast"
        });*/
		MenuInit('top-cat-menu');
		$("div.NewPassForm").hide();
		$("div.addtocart").hide();
		$("span#loading").hide();
		$("span#loading1").hide();
		$("span#loading2").hide();
		$("span#loading3").hide();
		$("span#loading4").hide();
		//$('input#city').attr('autocomplete','off');

});

function ById(id)
	{return document.getElementById(id);}


function ByTag(el,tag){
	return el.getElementsByTagName(tag);
	}

function GetAttr(el,name){
	return el[name] || el.getAttribute(name) || '';
	}

function CheckEmpty(str){	var reg = new RegExp("^\\s+$","i");
	var result = reg.test(str);
	return (str=='' || result) ? false : true;}


function CheckEmptyField(ob)
			{
			var str = ob.value;
			if(ob.tagName.toLowerCase() == 'select')
				{
				str = ob[ob.selectedIndex].text;
				}
             return CheckEmpty(str);
			}


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 CheckMobile(ob){
	  var str =  ob.value.replace(/\s+/g,'')
	  			.replace(/\(\)/g,'')
	  			.replace(/\+/g,'')
	  			.replace(/-/g,'');
	  var reg = new RegExp("^9[0-9]{9}$","i");
	  return reg.test(str);
	};


function viewImg(id)
{
		if(id==0) return;
		$("span#loading").show();
		$.post(
			   "/include/ajax.php",
		{
			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",
			{
				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 addGiftToCart(id){	$.post(
			   "/include/ajax.php",
		{
			target: 'basket',
			action: 'add',
			id: id,
			base_pv_id: 0,
			in_sales: 0
		},
		function(data){
			//$('span#add_cart').animate({opacity: "show"}, 500);
		},
        "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);
			    //ShowDialogBasketAdd();
			   // $('div#show_dialog').animate({opacity: "hide"}, 1500);
		},
        "script"
		);

  		});
 	}

function addToFavorites(el,id){	if(parseInt(id)<1) return false
	var action  = (arguments[2]) ? 'delfromfav' : 'addtofav';
	ShowDialogSales('Подождите...');
	$.post(
			   "/include/ajax.php",
		{
			target: 'catalog',
			action: action,
			id: id
		},
		function(data){
                        if(data.cnt != 'undefined'){
                       		 $('span#fav_cnt').html(''+data.cnt);
                       		 if(action  == 'delfromfav'){
                       		 	var msg    = 'Товар удален из избранного';
                       		 	var ind    = 'Запомнить товар';
                       		 	el.onclick = function(){addToFavorites(el,id)};
                        	 }else{                                var msg    = 'Товар добавлен в избранное';
                       		 	var ind    = 'Убрать из избранного';
                       		 	el.onclick = function(){addToFavorites(el,id,1)};                        	 }
                        	 $('div#show_dialog').find('div').get(0).innerHTML = msg;
                             $(el).html(ind);
                        	 $('div#show_dialog').animate({opacity: 'hide'}, 2500);
                        }
		},
        "json"
	 );
}


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 ClearEvent(e)
			{
				if(e.stopPropagation) e.stopPropagation();
			    else e.cancelBubble = true;
			    if(e.preventDefault) e.preventDefault();
			    else e.returnValue = false;

			}


function ShowBodyHelper(el,event){	var e =  event || window.event;
	ClearEvent(e);
	var help  = ById('body_helper_id');
	if(help){		$(help).remove();
		return;	}
	var position = defMousePosition(e);
	var div 	 = $(el).next().clone().get(0);
	div.id 		 = 'body_helper_id';
    document.body.appendChild(div);
    $(div).css('top', position.y + 30+"px");
    $(div).css('left', position.x - 10 -  parseInt(parseInt($(el).next().css('width'))/2) +"px");
    $(div).show();}


function  ShowHelpAction(el,event){	 var e		  =  event || window.event;
	 var position = defMousePosition(e);
	 var left     =
	 ClearEvent(e);
	 $('#action-help').css({top:position.y + 30+"px",
	 						left: position.x - 10 - parseInt(parseInt($('#action-help').css('width'))/2) +"px"})

	 if($('#action-help').css('display')=='none'){
	  	 	 $('#action-help').show();
	  	     $(document.body).bind('click', function(){$('div.helper').hide(); $(document.body).unbind( "click")});
	  }
}



function ShowHelp(el,event)
	{	 var e =  event || window.event;
	 ClearEvent(e);
	 var position = defMousePosition(e);
     if(arguments[2]){
     	$(el).next().css('top', position.y + 30+"px");
     	$(el).next().css('left', position.x - 10 -  parseInt(parseInt($(el).next().css('width'))/2) +"px");
     }
	 if(e.type == 'click'){
	  	 if($(el).next().css('display')=='none'){	  	 	 $(el).next().show();
	  	     $(document.body).bind('click', function(){$('div.helper').hide(); $(document.body).unbind( "click")});
	  	   }
	  	 else $(el).next().hide();
	   }
	  else{
	  		$(el).bind((e.type == 'click') ? 'onclick' :  'mouseout',function(){$(el).next().hide(); return false;});
	         $(el).next().show();
	      }
	}

function CloseDialog(){	$('#show_dialog').remove();}

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 ShowDialogBasketAdd(html)
	{	var dialog = ById('show_dialog')
	if(dialog){dialog.parentNode.removeChild(dialog); }
	var div = document.createElement("div");
	div.id = 'show_dialog';
	div.className = 'addtocart_dialog';
	div.innerHTML = html;
	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",
		{
			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(){
  		$.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 = '';
  	}
  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();}
	$.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");
	}

function SetCitySpecial(el,index_id,delivery_id){
   if($('#'+delivery_id).attr('value')>0 && $('#s_oplata').attr('value')>0){   	Dostavka(index_id,$('#s_oplata').attr('value'),delivery_id);   }
}



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',
				index2: index.value,
				oplata: oplata,
				delivery: delivery.value,
				special: ($('#special').attr('checked')) ? 1 : 0
			},
				function(data){}, 'script'
			);
}

function GetOplata(delivery)
	{	$("span#loading2").show();
	$("div#errDelivery1").hide();
	$("div#errDelivery2").hide();
	$("select#s_oplata").html('');
			$.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',
				index2: index
			},
        	function(data){}, 'script'
			);
	}


function selIndex(index,oplata_id,delivery_id)
{

			$.post(
				   "/include/ajax.php",
			{
				type: "request",
               	target: 'users',
				action: 'getindex',
				index2: index
			},

				function(data){
                    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;
					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 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>');
     var page 	   = (arguments[1] && parseInt(arguments[1])) ?
       				 parseInt(arguments[1]) : 1;
     $.post(
				   "/include/ajax.php",
			{
				type: "request",
				target: 'users',
				action: 'show_imsg_list',
				div: box_id,
				page: page
			},
				function(data){}, 'script'
			);
	}

function ShowUserCabOptinfo(box_id)
	{
  $.post(
				   "/include/ajax.php",
			{
				type: "request",
				target: 'users',
				action: 'show_optinfo',
				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 SendPhotoComment(id)
	{
     var comment_box = ById('photo_comment');
     if(comment_box){
        if(!CheckEmptyField(comment_box)){
        	alert('Не указан текст комментария!');
        	return;
        	}
      var hash_ = ById('photo_hash');
      var hash  = (hash_) ? hash_.value : '';
        $("div#comment_form").hide();
        $("div#comments_list").animate({height: "hide"}, 200,function(){
        $.post(
				   "/include/ajax.php",
			{
				type: "request",
				target: 'gallery',
				action: 'send_comment',
				div: 'comments_list',
				comment: comment_box.value,
                pid: id,
                hash: hash
			},
				function(data){$("div#comments_list").animate({height: "show"}, 500);}, 'script'
			);
         });
     	}
	}

 function GalleryPhotoVote(id){
	ShowDialogSales('Загрузка...');
    $.post(
					   "/include/ajax.php",
						{
							type: "request",
							target: 'gallery',
							action: 'gallery_vote',
							div: 'vote_box',
							pid: id
						},
							function(data){}, 'script'
						);
}

function ShowMailDeliveryAdd(){
	ShowDialogSales('Загрузка...');
    $.post(
					   "/include/ajax.php",
						{
							type: "request",
							target: 'basket',
							action: 'show_mail_delivery_add'
						},
							function(data){}, 'script'
						);
}


function ReviewPrepateToEdit(text)
	{
	var reg=/<br\s*\/?>/gi;
	return text.replace(reg, "\n");
	}

function ReviewPrepateToCancelEdit(text)
	{
	var reg=/(\r)?\n/gi;
	return text.replace(reg, "<br />");
	}


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,
				index2: 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,
				index2: index.value,
				oplata: oplata.value
			},
				function(data){}, 'script'
			);

    	}
	}

function UserCabChangeZakl(el)
	{
	var prod_cont   = (el.tagName.toLowerCase() == 'li') ? true : false;
	var arrBm 		= ByTag(ById('panel_zbox'),el.tagName);
    var cur_zakl	= '';
    var action 		= (arguments[2]) ? arguments[2]: '';
    if(arrBm){
	    for(var i = 0; i<arrBm.length; i++){
	     arrBm[i].className = (prod_cont) ?  '' : 'user_cab_zakl';
	     if(arrBm[i].id != el.id){	     	$("div#"+arrBm[i].id+"_box").hide();
	     }
	     else{	     	   cur_zakl  = arrBm[i].id+"_box";	     	   $("div#"+cur_zakl).show();
	     	}
	    }
    }
    el.className = (prod_cont) ? 'bm_active' : '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_gallery':
	    	var user_gallery_box = ById('user_gallery_box');
	           if(!user_gallery_box)
	           	{
	            if(window.Gallery) Gallery.ShowGallery(cur_zakl);
	           	}
    	break;
    	case 'show_optinfo':
	          ShowUserCabOptinfo(cur_zakl);
		break;
    	case 'show_imsg':
	          ShowUserCabInnerMsg(cur_zakl);
    	break;
   	  }

	}


function UserRegSubmit(oFormId,box)
		{
        var oForm = ById(oFormId);
        $("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(oForm,buttonId)
	{
         if(!oForm || !CheckOrderForm(oForm)) return false;
    	 $("span#loading2").show();
    	 $('#'+buttonId).attr('disabled',true);
    	 $.post(
				   "/include/ajax.php",
			{
				type: "request",
				target: 'users',
				action: 'user_save',
				mobile: $('#user_phone').attr('value'),
				name: $('#user_name').attr('value'),
				sname : $('#user_sname').attr('value'),
				email: $('#user_email').attr('value'),
				notreg: 1
			},
				function(data){$('#'+buttonId).attr('disabled',false);}, 'script'
			);
	 return false;
	}


function BasketReserv(oFormId,button){     BasketSubmit(oFormId,button,true);}

function BasketSubmit(oFormId,button,in_reserv){
			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';
                    if(in_reserv) params['in_reserv'] = 1;

					$.post("/include/ajax.php", params,function(data){},'script' );
				}
   			 //button.disabled = true;
		}

    function GetLabelByEl(el,id)
		{
		var arrLabels = ByTag(el,'label');
		for (var i=0; i < arrLabels.length; i++)
			{
			var lFor =  GetAttr(arrLabels[i],'htmlFor');
			if(lFor==id) return arrLabels[i].innerHTML;
			}
        return '';
		}

	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(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{
    	     var ch = false    	 }

         $('form#form_cfilter')
		    .find("input[@type='checkbox']")
		    .each(function() {
		      this.checked = ch;
		    });
		}

     function SetCatNalPropertyFilter(el){
     	 var only_nal = (el.checked) ? 1 : '';         location.href = '?f_cat_prop_cnt='+only_nal;     }


     function ShowProductNextNav()
     	{
     	 IEPngBGFix('next_prod_arrov');
         IEPngBGFix('prev_prod_arrov');
     	 $('#next_prod_arrov').show();
     	 $('#prev_prod_arrov').show();
     	 ById('next_prod_arrov').onclick = function() {NextProduct(1);};
     	 ById('prev_prod_arrov').onclick = function() {NextProduct(-1);};
     	 $('#prod_main_img_box').bind('mouseout' ,function() {
				$('#next_prod_arrov').hide();
					$('#prev_prod_arrov').hide();
				});
     	}

     function NextProduct(dir)
     	{     		var pid = ById('product_pid');
     		var sort = ById('product_sort');
     		var in_sales = ById('in_sales');
     		var product_sid = ById('product_sid');
     		if(pid && sort) {
     		$.post(
						   "/include/ajax.php",
							{
								type: "request",
								target: 'catalog',
								action: 'next_product',
								dir: dir,
								id: pid.value,
								sort: sort.value,
								in_sales: in_sales.value,
								sid: product_sid.value
							},
								function(data){}, 'script'
							);     	  }
     	}

	 function SetProdviewImgMode(mode)
	 	{	 	var id = $('#product_mid').attr('value');
        var base_pv_id = $('#product_id').attr('value');
	 	 $("div#prod_main_img").animate({opacity: "hide"}, 200, function(){
 	  				$.post(
						   "/include/ajax.php",
							{
								type: "request",
								target: 'catalog',
								action: 'set_prodview_mode',
								mode: mode,
								id: id,
								base_pv_id: base_pv_id
							},
								function(data){}, 'script'
							);
 	  			});	 	}

	 function ClosePaymentForm()
	 	{	 	var paymnent_box = ById('paymnent_box');
	 	if(paymnent_box) paymnent_box.parentNode.removeChild(paymnent_box);	 	}


	 function ShowRBKPayment(order_id)
	 	{        var id = (order_id) ? parseInt(order_id) : 0 ;
	 	if(!id || id==0) return;
        ClosePaymentForm();
	 	var paymnent = document.createElement("div");
		paymnent.id = 'paymnent_box';
		paymnent.innerHTML = '<div class="load">&nbsp;</div>';
		document.body.appendChild(paymnent);
        SetCenterPage(paymnent);	 	$.post(
						   "/include/ajax.php",
							{
								type: "request",
								target: 'users',
								action: 'show_payment',
								id: id,
								payment: 'rbk'
							},
								function(data){}, 'script'
							);
	 	}


	 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 id = (arguments[0]) ? arguments[0] : 'show_img_bg';
	 var div_box =  document.getElementById(id);
     if(div_box) div_box.parentNode.removeChild(div_box);
     RestorePageBg();
     //SelectHide(0);
	}

function RestorePageBg()
	{
    var div_bg =  document.getElementById('img_bg_bl');
    if(div_bg) div_bg.parentNode.removeChild(div_bg);
	}

function SetPageBg(color,opacity)
	{
    RestorePageBg();
    var  div_bg = document.createElement("div");
    div_bg.id  = 'img_bg_bl';
    div_bg.className = "img_bg_bl";
    div_bg.style.backgroundColor = color;
    var off_w = (document.documentElement && document.documentElement.clientWidth) || document.body.clientWidth;
    var off_y = (document.documentElement && document.documentElement.scrollHeight)|| document.body.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_bg.style.opacity = opacity;
    div_bg.style.filter = "alpha(opacity='"+opacity*100+"')";
    div_bg.style.top = 0;
    div_bg.style.left = 0;
	document.body.appendChild(div_bg);
	}

function ShowBgImg(img_url)
	{
     if(ById('show_img_bg')) CloseShowBgImg();
   	 var i = document.createElement("img");
     i.id  = 'show_img_src';
     if(arguments[1]){
        i.title =
        i.alt   = arguments[1];
     }
     i.style.display = 'none';
     i.onclick = function(){CloseShowBgImg();};
     var div_box = document.createElement("div");
     var div_cl = document.createElement("div");
     div_cl.className = 'show_bg_img_close';
     div_cl.onclick = function(){CloseShowBgImg();};

     div_cl.appendChild(document.createTextNode('Закрыть'));
     div_box.className = "show_img_bg";
     div_box.id = "show_img_bg";
     div_box.appendChild(div_cl);
     div_box.appendChild(i);
     div_box.style.textAlign = 'right';
     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')";
     SetPageBg('#000',0.7);
     document.body.appendChild(div_box);
     $(tmp_big_img).bind('load',function()
     				{
                     i.src =  this.src;
                     i.style.display = 'inline';
                     SetSizeShowBgimg(i);
                     tmp_big_img = null;
                     tmp_big_img = new Image();
                     //this.src = null;
	  				});
     //tmp_big_img.onload  =
	 tmp_big_img.src = img_url;
     SetCenterPage(div_box);
     //SelectHide(1);
     if(i && i.width > 0){SetSizeShowBgimg(i)};

   	}

function CloseProdvarPhoto()
	{
	$('#prodvar_preview_img').hide();
	}


var last_show_img = 0;
function ShowProdvarPhoto(el,event)
	{
      e = event || window.event;
	  var prodvar_id = el.id.replace(/^([a-zA-Z]*)_/,'');
      if(el.onmouseout == null || el.onmouseout == 'undefined')
      		el.onmouseout = function(){CloseProdvarPhoto();};
	  var div  = ById('prodvar_preview_img');
	  if(div && prodvar_id == last_show_img){
		 $('#prodvar_preview_img').show();
		}
	  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'
							);
    		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 checkChildSelect(el,tag)
		{        var arrChildrens = ByTag(el,tag);
        for(var i=0;i<arrChildrens.length;i++)
        	{
        	if(arrChildrens[i].className == 'select'){
	        	return 1;	        	}        	}
         return 0;		}

   var cur_menu_el = false;
   var menu_timeout = null;
   var menu_out_timeout = null;

	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++){
			  if(arrBlock[i].parentNode != obj) continue;
			  arrBlock[i].onmouseover = function(){

			  										if(window.menu_out_timeout && window.menu_out_timeout != null) {
			  											clearTimeout(menu_out_timeout);
			  											menu_out_timeout = null;
			  											cur_menu_el.className = '';
			  									    }
			  									  	if(cur_menu_el != false) {
                                                       cur_menu_el 	  = this;
                                                       this.className = 'select';
			  									  	   return;
			  									  	}else{			  									  		var this_ = this;
			  									  		menu_timeout = setTimeout(function(){cur_menu_el = this_;
			  									  										 this_.className = 'select';},120);			  									  	}

			  									  };

			  arrBlock[i].onmouseout = function(){			  										if(cur_menu_el == false && window.menu_timeout){
                                                        this.className = '';
                                                        clearTimeout(menu_timeout);
                                                        return;			  										}
                                                    if(window.menu_out_timeout && window.menu_out_timeout != null) clearTimeout(menu_out_timeout);
                                                    var this_		 = this;
                                                    menu_out_timeout = setTimeout(function(){this_.className = ''; cur_menu_el = false},200);
			  									};
			  }
			}
	}

function PosSerachTRacking(ind)
	{	var eForm = document.createElement("form");
    eForm.action = 'http://www.russianpost.ru/rp/servise/ru/home/postuslug/trackingpo';
    eForm.method = 'post';
    eForm.target="_blank"
    var input_ind = document.createElement("input");
    input_ind.name = 'BarCode';
    input_ind.type = 'hidden';
    input_ind.value = ind;
    var input_sec = document.createElement("input");
    input_sec.name = 'searchsign';
    input_sec.type = 'hidden';
    input_sec.value = 1;
    eForm.appendChild(input_ind);
    eForm.appendChild(input_sec);
    document.body.appendChild(eForm);
    eForm.submit();
    document.body.removeChild(eForm);	}

function ShowFromProdQuestion(id){	ShowDialogSales('Загрузка...');
	$.post(
	 		"/include/ajax.php",
		 {
		   type: "request",
		   target: 'catalog',
		   action: 'show_prod_quest_form'
		},
		function(data){
						$('input#prod_quest_id').attr('value',id);
					  }, 'script'
	    );}

function UserGoProdQuestion(){
   var email = ById('u-email');
   if(!email || !CheckEmail(email.value)){
	 alert('Поле "E-mail" заполнено не верно!');
	 email.focus();
	 return
    }
   var msg = ById('u-quest');
   if(!msg || !CheckEmptyField(msg)){
	 alert('Поле "Текст вопроса" не заполнено!');
	 msg.focus();
	 return
    }
	var params = {};
    $('#prod-user-q').find("input, textarea, select")
					 .each(function() {
				      params[this.name || this.id] = this.value;
				   });
	params['action'] =  'send_user_prod_req';
	params['target'] =  'catalog';
	$.post(
			"/include/ajax.php",
			 params,
		     function(data){}, 'script'
		  );}

function VotePool(id)
{  $.post(
			"/include/ajax.php",
			 {			  target: 'poll',
			  action: 'vote',
			  id: id			 },
		     function(data){}, 'script'
		  );
}
function NewVotePool()
{	var new_vote = $('#new_poll').attr('value');
	if(!new_vote || !CheckEmpty(new_vote)){		alert('Предложение не заполнено!');
		return;	}
	 $.post(
			"/include/ajax.php",
			 {
			  target: 'poll',
			  action: 'new',
			  name: new_vote
			 },
		     function(data){}, 'script'
		  );}


function Preload()
		{
		for(var i=0;i<2;i++)
			{
			newimg[i] = new Image();
			}
		newimg[0].src = '/images/basket_info_btn_s.gif';
		newimg[1].src = '/images/top_cat_menu_s.gif';
		}
