 
 var add_html='';
 var current_url=new String(location.href);
 function resize_col(){
     // alert($('.left_mnu').height());
	  if((($('.left_mnu').height()+370)<$('#main').height()) || (($('#sidebar').height()+220)<$('#main').height())||(($('.left_mnu').height()+370)>700) )
	  {
	
	  $('.left_mnu').css('height',$('#main').height()+'px');
	  $('#sidebar').css('height',$('#main').height()+'px');
	   $('.left_mnu').css('padding-bottom','0px');
	  $('#sidebar').css('padding-bottom','0px');
	  }
  }
function init() {
		// quit if this function has already been called
		if (arguments.callee.done) return;
		
		// flag this function so we don't do the same thing twice
		arguments.callee.done = true;
		
		// kill the timer
		if (_timer) {
			clearInterval(_timer);
			_timer = null;
		}
		
		// working
		//resize_col();
		CreateLoginDialog();
		
 };
	
function init_slider(){
if ($('#basket_items_list').children().size()==0){
$('#basket_sum').css('display','none');
$('#link_show_cart').css('display','none');

}else{
$('#basket_sum').css('display','block');
$('#link_show_cart').css('display','block');
 }

if ($('#basket_items_list').children().size()>10)
	{
	$('#basket_items_list').css('position','absolute');
	$('#basket_items').css('height','140px');
	$('#slider').css('display','block');
	var h_size=Math.round(Math.pow($('#slider').height(),2)/$('#basket_items_list').height());
		if (h_size<10){h_size=10;}
		$('#slider_handle').css('height',h_size+'px');
	$('#slider').slider({ min:0,max:$('#basket_items_list').height()-$('#basket_items').height(), steps: $('#basket_items_list').children().size(), slide: function(e,ui) { $('#basket_items_list').css('top','-'+ui.value+'px'); } });
	//$('#slider').slider( "enable" );
	// $('#slider').css('visibility','visible');
	 


	}else {
	$('#basket_items_list').css('position','static');
	$('#basket_items').css('height','auto');
	
	//$('#slider').css('visibility','hidden');
	$('#slider').css('display','none');
	}

}
function addTocart(item_id,item_cnt,btn,is_lens){
//alert(item_id);
//alert(item_cnt);
add_btn=btn;
add_html=btn.html();
btn.html('---------------');
if($('#frm_buy').length>0){
form_data=$('#frm_buy').serialize();
}
else {form_data='';}

$.post(

  REQUEST_URL+'ajax/addtocart/',
  {
    item_id: item_id,
    item_cnt: item_cnt,
	form_data:form_data,
	is_lens:is_lens
  },
  onAddToCartSuccess
);

}
function addTocartFromOrder(order_id,order_item_id,btn){
//alert(item_id);
//alert(item_cnt);
add_btn=btn;
add_html=btn.html();
btn.html('---------------');

$.post(

  REQUEST_URL+'ajax/addfromorder/',
  {
    order_item_id: order_item_id,
	order_id: order_id
  },
  onAddToCartSuccess
);

}

function onAddToCartSuccess(data)
{	
	//btn.disabled=false;
	add_btn.html(add_html);
	obj=eval(data);
	if(obj.cart_error==''){
	$('#basket_items_list').html(obj.cart_text);
	$('#basket_sum_value').html(obj.cart_sum+'');
	
	$('.stickers_block').css('background-image',BASKET_BACK);
	
	$('#slider').slider( "destroy" );
	$('#slider').slider( "disable" );
	init_slider();
	}else {
		if (obj.cart_error=='noparam') {alert(LNG_cart_error_noparam);location.href=obj.redirect_url;}
		if (obj.cart_error=='noitem') {alert(LNG_cart_error_noitem);}
			
	}
}
function UserLogin(par_login, par_pass){


$.post(

  FULL_URL+LANG_URL+'ajax/login/',
  {
    login:$('#login_field').val(),
    pass:$('#pass_field').val()
    
  },
  onUserLogin
);
}
function onUserLogin(data)
{
obj=eval(data);
if (!(obj.error)){
	
  if (current_url.indexOf('user')>0 )
	{
	location.href='/';
	 }
	else{
	  location.reload(true);
	}
  
  
}else{$('#login_err_text').html(obj.error);}
}


function CurrencyChange(currency_id){
//form_data=$('#frm_currency').serialize();

$.post(

  FULL_URL+'ajax/setcurrency/',
  {
    currency_id:currency_id
    
  },
  onCurrencyChange);
}





function onCurrencyChange(data)
{



if (current_url.indexOf('user')>0 )
{
location.href='/';
 }
else{
  location.reload(true);
}
}


function AfterLoadPage(){
		//resize_col();
		init_slider();
		
		//window.onresize = resize_col;

		CreateLoginDialog();
		CreateCurrencyDialog();
		if(datepicker_ini_str!='')
		eval(datepicker_ini_str);	
}
function SubmitOnEnter(form_id){
 var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          $('#'+form_id).submit();
     else
          return true;
}
function onShipChangeClick(itemid)
{
	$('#pay_block').css('visibility','visible');
	$('#pay_block input').removeAttr('disabled');
	//$('#pay_block input').removeAttr('checked');
	
	if(itemid==1){
		$('#pay_2').attr('disabled',true);
	}else
	{
		if(itemid==3){
		$('#pay_2').attr('disabled',true);
		$('#pay_1').attr('disabled',true);
		}else{
			if(itemid==2){
			$('#pay_1').attr('disabled',true);
			}		
		}
	}
	$('#pay_block input:disabled').removeAttr('checked');
	
}
function LinkConfirm(url,msg) {
     
                if (confirm(msg)) {
                        document.location = url;
                        return true;
                } else return false;
        
}
 function roundTo(number, to) {  
    return Math.round(number * to) / to;  
 } 
$(document).ready(AfterLoadPage);	
	
