$(document).ready(function() {
    var rightHeight = $('#sideRight').height();
    var middleHeight = $('#middle').height();

    if(middleHeight>rightHeight){
         $('#sideRight').height(middleHeight);
    }

});


function changePic(name){
	$('#item-photo').attr('src', '/uploads/goods/large/'+name);
	return false;
}

function toggleFilter(obj){

	$('#filter-content').toggle('fast',
		function(){
		if(/Скрыть/.test($(obj).text())){
			$(obj).html('Показать фильтр товаров');
			$.cookie('filter', 'hide' ,{path: "/"});
	
		}else{
			$(obj).html('Скрыть фильтр товаров');
			$.cookie('filter', 'show' ,{path: "/"});
	
		}
	});
	
	
	return false;
}


function setListMode(mode){
	$.cookie('list_mode',mode,{path: "/"});
	window.location.reload(true);
	return false;
} 


function saveGoodsOnPage(value){
	$.cookie('goods_on_page',value,{path: "/"});
	window.location.reload(true);
	return false;
}


function buyItem(good_id){
	$.post('/cart/add', $('#buy-form-'+good_id).serialize());
	var w = $.jWin.create({
		alwaysCentered:true,
		overlayColor:'#000',
        height: 180,
		handleEscape:true
	});
	w.setContent(good_id);
	w.show();
	
	return false;
}



function phoneRequest(){
	var w = $.jWin.create({
		alwaysCentered:true,
		overlayColor:'#000',
		handleEscape:true,
		height: 180
	});
	w.setContent('',1);
	w.setTitle('<b>Заказ обратного звонка</b>');
	w.show();
	
	return false;
}


function smsCart(good_id){
	var w = $.jWin.create({
		alwaysCentered:true,
		overlayColor:'#000',
		handleEscape:true,
		height: 100
	});
	w.setContent(good_id, 2);
	w.setTitle('<b>Отправка SMS-карточки</b>');
	w.show();
	
	return false;
}


function checkQuestionForm(){
	if($('#question').val()=='' || $('#email').val()==''){
		alert('Поля "E-mail" и "Вопрос" обязательны к заполнению');
		return false;
	}

	return true;
}


function inStockNotify(good_id, title){
	var w = $.jWin.create({
		alwaysCentered:true,
		overlayColor:'#000',
		handleEscape:true,
		height: 100
	});
	w.setContent({'good_id':good_id,'title':title}, 3);
	w.setTitle('<b>Уведомление при поступлении на склад</b>');
	w.show();

	return false;
}


function setPriceFilter(){
    var minPrice = parseInt(document.getElementById('filter_min_price').value+0);
    var maxPrice = parseInt(document.getElementById('filter_max_price').value+0);

    var uri = new Array;
    if(minPrice<0){
        document.getElementById('filter_min_price').value = '';
    }

    if(maxPrice<0 || maxPrice<minPrice){
        document.getElementById('filter_max_price').value = '';
    }

    document.getElementById('price_filter').submit();
    return false;
}
