// подсветка рядов таблицы
function setActiveStyleSheet(title){  // select the stylesheet
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link") [i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) {
       a.disabled = true;
       if(a.getAttribute("title") == title) a.disabled = false;
     }
   }
}

function select_row($id)
{
	var $c = $($id).className;
	if ($c == 'even')
	{
		$($id).className = 'even_selected';
	}
	else if($c == 'odd')
	{
		$($id).className = 'odd_selected';
	}
}
function deselect_row($id)
{
	var $c = $($id).className;
	if ($c == 'even_selected')
	{
		$($id).className = 'even';
	}
	else if($c == 'odd_selected')
	{
		$($id).className = 'odd';
	}
}

function showCartAdd(obj, stockCode, inStock, page)
{
	offsetTop=-5;
	if (page == 'card')
	{
		offsetLeft = -285
	}
	else if (page == 'item')
	{
		offsetLeft = -5
	}
	else if (page=='aj')
	{
		offsetLeft = -306;
		jQuery('#cart_add').show();
	}
	else
	{
		return
	}
	jQuery('#spinner').show();
	jQuery('#cart_addBG').show();
	
	position = jQuery('#'+obj).position();
	position.left+=offsetLeft;
	position.top+=offsetTop;
	if (page=='aj')
	{
		scrtop = jQuery('#card_window_descr').position().top;
		position.top-=scrtop;
	}
	jQuery('#cart_add').css("top",position.top);
	jQuery('#cart_add').css("left",position.left);
	new Ajax.Updater('cart_add', '/cart/add/' + stockCode + '/ajax', {asynchronous: false, evalScripts: true});
	new Effect.Appear('cart_add', {duration: 0.5, afterFinish: focusCartAdd});
	jQuery('#spinner').hide();
}

function focusCartAdd(obj)
{
	$('cart_add_qty').activate();
}
function submitCartAdd(commonCode, qty)
{
	new Ajax.Updater('cart_block', '/cart/block/ajax?item=' + commonCode + '&qty=' + qty);
}

function submitCartAdd_(commonCode, qty,k)
{
	if ((qty%k)==0) {jQuery('#btnbye').html('<div style="float:left"><img src="/img/check_ok.gif" ></div>КУПИТЬ');
	new Ajax.Updater('cart_block', '/cart/block/ajax?item=' + commonCode + '&qty=' + qty);
	try {new Effect.Corner($("btnbye"), "5px"); return true; }catch(e){};} 
	else {jQuery('#cartaddErr').text('Количество должно быть кратно '+k); i=Math.round(qty/k)*k; i=((i==0)?k:i); jQuery('#inpqty').val(i);return false;}
	
}

function hideCartAdd(id)
{
	new Effect.Fade('cart_add', {duration: 0.5});
	if (jQuery('#cart_addBG').length){jQuery('#cart_addBG').hide()};
}

function cartPopupBeforeHide()
{
	$('cart_update').click();
}
function cartPopupAfterHide()
{
	new Ajax.Updater('cart_block', '/cart/block/ajax'); // EvalScripts?
}
/*function toggleCart()
{
	if ($('cart_block').getStyle('position') != 'fixed')
	{
		$('cart_block').setStyle({position: 'fixed', width: '190px', bottom: '0px', right: '0px'});
	}
	else
	{
		$('cart_block').setStyle({position: 'static'});
	}
}*/
	function getkey(e)
	{
	if (window.event)
	return window.event.keyCode;
	else if (e)
	return e.which;
	else
	return null;
	}

	function goodchars(e)
	{
	var key = getkey(e);
	if (key == null) return true;
	//alert(key);
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 || (key>=48 && key<=57) || key==44 || key==46 )
	return true;
	else
	return false;
	}

	
	function goodchars_cart_add(e)
	{var key = getkey(e);
	if (key == null) return true;
	if (key==0) hideCartAdd();
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 || (key>=48 && key<=57) )
	return true;
	else
	return false; }
	