function hiddenLayer(div_name) {
document.getElementById(div_name).style.visibility = "hidden";
}

function showLayer(div_name) {
document.getElementById(div_name).style.visibility = "visible";

}
function filterVendors ( category, another ) {
	
	if ( another ) var objId = '#vendor_sel_two';
	else var objId = '#vendor_sel';
	
	var req = new JsHttpRequest();
    req.onreadystatechange = function() { if (req.readyState == 4 && req.responseJS.success == 1 ) $(objId).html ( req.responseJS.vendors ); }
    req.open( null, '/ajax.php', true );
    req.send( { 'category': category, action: 'vendor_filter' } );
}

function addToCart ( id, count, ctcolor, ctsize ) {
	
	if ( count<1 ) return;

	if (typeof ctcolor == "undefined") ctcolor = 0;
	if (typeof ctsize == "undefined") ctsize = 0;
	
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            
            if ( req.responseJS.success == 1 ) {
            	showCartStat();
            	alert ('Товар добавлен в вашу корзину');
            } else if ( req.responseJS.alert.length > 0 ) {
            	alert ( req.responseJS.alert );
            } else {
            	alert ( 'Неизвестная ошибка.' );
            }
        }
    }
    req.open(null, '/ajax.php', true);
    req.send( { id: id, count: count, action: 'add_to_cart', color: ctcolor, size: ctsize } );
}

function showCartStat() {
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('cart_total').innerHTML = req.responseJS.total;
            document.getElementById('cart_price').innerHTML = req.responseJS.price;
        }
    }
    req.open(null, '/ajax.php', true);
    req.send( { action: 'show_cart_stat' } );
}
function useCheckbox( hidden_id, orig_value ) {
	var hidden_el = document.getElementById ( hidden_id );
	if ( hidden_el.value == orig_value ) hidden_el.value = 0;
	else hidden_el.value = orig_value;
}

popup = null;
function openIMG(URL,w,h)
{
	var WNAME = 'Фото';
	if (popup != null && !popup.closed) popup.close();  
	sw = screen.width-100;
	sh = screen.availHeight-100;
	if (w > sw || h > sh)
	{
		if (w > sw) {w1 = sw;} else {w1 = w+17;}
		if (h > sh) {h1 = sh;} else {h1 = h+17;}
		mtw1 = (screen.width-w1)/2;
		mth1 = (screen.availHeight-h1)/2;
		popup = window.open('',WNAME,"width="+w1+",height="+h1+",top="+mth1+",left="+mtw1+",status=no,toolbar=no,scrollbars=yes,resizable=no,menubar=no");
		popup.focus();
	}
	else
	{
		mtw = (screen.width-w)/2;
		mth = (screen.availHeight-h)/2;
    	popup = window.open('',WNAME,"width="+w+",height="+h+",top="+mth+",left="+mtw+",status=no,toolbar=no,scrollbars=no,resizable=no,menubar=no");
		popup.focus();
	}
  	popup.document.writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>'+WNAME+'</title></head><body style="margin: 0px;"><a href="javascript:window.close();"><img src="'+URL+'" border=0 width="'+w+'" height="'+h+'" alt="Закрыть окно"></a></body></html>');
}

function chImg ( path, myClass, x, y ) {
	var img = '<img border=0 id="mainimg" src="' + path + '" />';
	//$('#imgContainer').attr('src', path );
	if ( myClass == 'havebig' ) {
		$('#imgContainer').html( '<a href="#" onclick="openIMG ( \'' + path + '_big\', ' + x + ', ' + y + ' ); return false;">' + img +'</a>' );
	} else {
		$('#imgContainer').html( img );
	}
}