function pop_up(my_file, width, height, title)
{ 
	if(!width) width = 600;      
	if(!height) height = 700;      
	 wnd = window.open(my_file,"wind",'width='+width+',height='+height+',left='+((screen.width-width)/2)+',top='+((screen.height-height)/2)+',scrollbars=yes,resizable=no');
	
	if(title)
	{
		wnd.document.title = title;
	
	}
	
  }
  
  
  function pop_up_t(my_file, width, height, title)
{ 
	if(!width) width = 600;      
	if(!height) height = 700;	
	 var wnd = window.open("/popups/?f="+my_file+"&t="+title ,"wind",'width='+width+',height='+height+',left='+((screen.width-width)/2)+',top='+((screen.height-height)/2)+',scrollbars=yes,resizable=no');
	
	return wnd;

  }
  
  
 
 function GetYPos(elem)
  {
   var pos = elem.offsetTop;
   while (elem.offsetParent != null)
     {
      elem = elem.offsetParent;
      pos += elem.offsetTop;
      if (elem.tagName == 'BODY') break;
     }
   return pos;
  }  

function ScrollTo(which)
  {
   if (document.all.item(which) == null)
     return true;
   var elem = eval(which);
   targetPos=GetYPos(elem);
   docLength=GetYPos(docEndImg);
   if ((docLength-targetPos) > (document.body.clientHeight-Header.offsetHeight))
     document.body.scrollTop = targetPos-Header.offsetHeight;
   else 
     document.body.scrollTop = docLength-document.body.clientHeight;
   CloseAll(0);
   return false;
  }

function skidka()
  {
   if (document.body.scrollTop>42)
     {
      plashka.style.top = document.body.scrollTop-42;
      var i=0;
      while (elem=document.all.item("grouplist"+i++))
        elem.style.top = document.body.scrollTop+1;
     }
   else
     {
      plashka.style.top = 0;
      var i=0;
      while (elem=document.all.item("grouplist"+i++))
        elem.style.top = 1;
     }
  }

  var ratesNames = {1: '(очень плохо)', 2: '(плохо)', 3: '(средне)', 4: '(хорошо)', 5: '(отлично)'};

function onOverStar(n) {
	rating_scroll.style.width = 20*n;
	rates_names.innerHTML = ratesNames[n];
}
function setRater(n) {	
	response_form.rate.value = curr_rate = n;
	rates_names.innerHTML = curr_rate_name =  ratesNames[n];
}
function restoreRate() {
	rating_scroll.style.width = 20*curr_rate;
	rates_names.innerHTML = curr_rate_name;
}

var curr_rate = 3;
var curr_rate_name = ratesNames[curr_rate];


//-------------------------------------------------------------------
function cb_add(data) 
{    
    $j('#cartCount').html(data.cart_count);
    
    var str = '<div style="float: right; padding: 5px; 5px 0px 0px;"><img src=/i/close.gif width=13 height=13 style="cursor: pointer;" id=x_close></div>';
    str+= '<div class=item_price style="text-align: center; padding: 10px 0px 0px 10px; margin: 0px 0px 10px 0px;">Товар добавлен в корзину</div>';
    
    str+= '<div class=item_title style="float: left; width: 155px; margin: 0px 0px 0px 10px;"><a href="/basket/"><u>Оформить заказ</u></a></div>';
    str+= '<div class=item_title style="float: right; width: 155px; cursor: pointer; margin: 0px 10px 0px 0px;" id=cont_shop><u>Продолжить покупки</u></div>';
    
    $j('#cb_add').find('#cb_content').html(str);    
    $j('#cb_add').find('#cb_content').find('#x_close,#cont_shop').click(function(){$j('#cb_add').hide(); $j('#cb_add_shadow').hide();});
}


 function init_forms() {    
    $j('body').append("<div id=cb_add_shadow></div><div id=cb_add ><div id=cb_content ></div></div>");
    
    $j("form.item_form").each(function(){
    $j(this).bind("submit", function(e){        
    
        var offset = $j(this).offset();        
        $j('#cb_add').show();
        $j('#cb_add').offset({top: offset.top + cb_add_top_offset, left: offset.left});
        
        $j('#cb_add_shadow').show();
        $j('#cb_add_shadow').offset({top: offset.top + cb_add_top_offset + 3, left: offset.left + 3});
       
        
        $j('#cb_add').find('#cb_content').html('<div align=center style="padding-top: 12px;"><img src="/i/preloader1.gif" width=44 height=44></div>');
        
        var d = {add: 1,
                      tovar_id: $j(this).find('input[name=tovar_id]').attr('value'),
                      tovar_count: $j(this).find('input[name=tovar_count]').attr('value')
                      };
        
        $j.getJSON('/add/', d, cb_add);
        
        return false;        
      });
    });
    
    
    //cart_arch_help
     $j("a.cart_arch_help").each(function(){ 
       $j(this).bind("click", function(e){
       //---------------------------
        var str = '<div style="float: right; padding: 5px; 5px 0px 0px;"><img src=/i/close.gif width=13 height=13 style="cursor: pointer;" id=x_close></div>';
        str+= '<div class=ntxt style="font-size: 11px; text-align: center; padding: 5px 0px 0px 0px; margin: 0px 0px 5px 0px;">Данный раздел позволяет Вам просматривать<br>10 последних покупок (корзин) товаров,<br>оформленных через Интернет-магазин "Автомаг".<br> Перейти в "Архив корзин" <a href="/cart_arch/">&gt;&gt;</a></div>';        
        
        
        $j('#cb_add').find('#cb_content').html(str);    
        $j('#cb_add').find('#cb_content').find('#x_close,#cont_shop').click(function(){$j('#cb_add').hide(); $j('#cb_add_shadow').hide();});
        
    
          var offset = $j(this).offset();  
          
          $j('#cb_add').show();
          $j('#cb_add').offset({top: offset.top + 5, left: (offset.left > 900)?offset.left - $j('#cb_add').width():offset.left});
          
          $j('#cb_add_shadow').show();
          $j('#cb_add_shadow').offset({top: offset.top + 5 + 3, left: (offset.left > 900)?offset.left +3 - $j('#cb_add').width():offset.left +3});
    
       //-------------------------- 
       });
     });
    
      
  }
  
  
function help_message(e)
{
  var str = '<div style="float: right; padding: 5px; 5px 0px 0px;"><img src=/i/close.gif width=13 height=13 style="cursor: pointer;" id=x_close></div>';
        str+= '<div class=ntxt style="font-size: 11px; text-align: center; padding: 5px 0px 0px 0px; margin: 0px 0px 5px 0px;">' +$j(this).attr('help_text') + '</div>';
  
  $j('#cb_add').find('#cb_content').html(str);    
  $j('#cb_add').find('#cb_content').find('#x_close,#cont_shop').click(function(){$j('#cb_add').hide(); $j('#cb_add_shadow').hide();});
  
  var offset = $j(this).offset();  
          
  $j('#cb_add').show();
  $j('#cb_add').offset({top: offset.top + 5, left: (offset.left > 800)?offset.left - $j('#cb_add').width():offset.left});
          
  $j('#cb_add_shadow').show();
  $j('#cb_add_shadow').offset({top: offset.top + 5 + 3, left: (offset.left > 800)?offset.left +3 - $j('#cb_add').width():offset.left +3});
  
  
 }


