function get_x(eve)  
{  
	var x = 0;  
	var ev = eve || window.event;
	if(ev==undefined){ev=0;}
	if(ev.pageX){
		x = ev.pageX - (document.documentElement.scrollLeft || document.body.scrollLeft);
	}
	else if(ev.clientX)
	{
		x = ev.clientX + document.body.scrollLeft - document.body.clientLeft ;
	}
	return x;  
}
function get_y(eve)  
{
	var y = 0;  
	var e2 = eve || window.event;
	if(e2==undefined){e2=0;}
	if (e2.pageY){
		y = e2.pageY - (document.documentElement.scrollTop || document.body.scrollTop);		
	}
	else if(e2.clientY){		
		y = e2.clientY + document.body.scrollTop - document.body.clientTop;		
	}	
	return y;  
}
function getClientWidth()
{
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}
function warning(msg,head,t,x,y){
	if(!x) var x=get_x();
	if(!y) var y=get_y();
	if((x==0)||(y==0)){
		x=parseInt(getClientWidth()/2)-100;
		$.jGrowl(msg,{header:head,life:t});
		$('div.jGrowl').css('top',0 + 'px').css('left',x + 'px');
		x=0;
		y=0;
	}
	else{
		$.jGrowl(msg,{header:head,life:t});
		x=x-255;
		$('div.jGrowl').css('top',y + 'px').css('left',x + 'px');
		x=0;
		y=0;
	}
}
function suc_msg(msg,head,t,x,y){
	if(($.browser.msie)&&($.browser.version=='6.0')){		
		var x=parseInt(getClientWidth()/2)+220;
		var y=1;
	}
	else{
		if(!x) var x=get_x();
		if(!y) var y=get_y();
	}
	if((x==0)||(y==0)){
		x=parseInt(getClientWidth()/2)-100;
		$.jGrowl(msg,{header:head,life:t,theme:'manilla'});
		$('div.jGrowl').css('top',0 + 'px').css('left',x + 'px');
		x=0;
		y=0;
	}
	else{
		$.jGrowl(msg,{header:head,life:t,theme:'manilla'});
		x=x-255;
		$('div.jGrowl').css('top',y + 'px').css('left',x + 'px');
		x=0;
		y=0;
	}
}
function refresh(){
	vitrina_to_arr();
	$.ajax({
        url: '/catalog/sale/index.php',
        type: 'POST',
        data: {new_vitrina:vitrina_mas},
        dataType: "json",
        success: function(json){uspeh_refresh($(json));}
        });
}
function vitrina_to_arr(){
	vitrina_mas=new Array();
	$('#goods_show').find('tr:eq(0)').find('td').each(function(n){
		var g=$(this).find('a').attr('cid');
		vitrina_mas.push(g);
	});
}
function uspeh_refresh(massiv){
	$('.good_img').fadeOut('slow');
	$('.goods_price').hide();
	var bash_s='';
	setTimeout(function() {
		for(i=0;i<5;i++){
   		bash_s=great_string.replace('$id',massiv[i][1]).replace('$title',massiv[i][2]).replace('$id',massiv[i][1]).replace('$file',massiv[i][3]);
			$('#goods_show').find('tr:first').find('td:eq(' + i + ')').html(bash_s);
			$('#goods_show').find('tr:last').find('td:eq(' + i + ')').html('<span class="goods_price">' + massiv[i][0] + '<p>руб.</p></span>');			
		}
		$('#goods_show').find('tr').fadeIn('slow');
	},1000);
	
}
function select_unit(){
   var s=$('#select_unit').find("[selected]").val();
   $.cookie('unit',s, {expires: 31, path: '/', secure: false});
}
