function ShowProductsBySectionId(section_id, is_index){
	if(is_index === undefined) var is_index = 1;
	$('#d_index_objs').html('<p align="center"><img src="/images/loading.gif"></p>');
	$.ajax({
		url: '/ajax/main.php',
		data: 'action=show_productsBySectionId&section_id=' + section_id + '&is_index='+is_index,
		type: 'get',
		success: function (response) {
			$('#d_index_objs').html(response);
		}
	});
}

function ShowObjectsWithPropValue(property_id, value_id, is_index){
	if(is_index === undefined) var is_index = 1;
	$('#d_index_objs').html('<p align="center"><img src="/images/loading.gif"></p>');
	$.ajax({
		url: '/ajax/main.php',
		data: 'action=show_productsByPropertyValue&property_id=' + property_id + '&value_id=' + value_id + '&is_index='+is_index,
		type: 'get',
		success: function (response) {
			$('#d_index_objs').html(response);
		}
	});
}

function ShowObjectsWithPriceFromTo(is_index){
	if(is_index === undefined) var is_index = 1;
	$('#d_index_objs').html('<p align="center"><img src="/images/loading.gif"></p>');
	$.ajax({
		url: '/ajax/main.php',
		data: 'action=show_productsByPrice&price_from_to[from]=' + $('#search_price_from').val() + '&price_from_to[to]=' + $('#search_price_to').val() + '&is_index='+is_index,
		type: 'get',
		success: function (response) {
			$('#d_index_objs').html(response);
		}
	});
}

function ShowObjectsByKod(){
	$.ajax({
		url: '/ajax/main.php',
		data: 'action=show_productsByKod&search_kod=' + $('#search_kod').val(),
		type: 'get',
		success: function (response) {	
			if(response.indexOf('/') != -1){
				window.open(response, '_self');
			}
			else alert(response);
		}
	});
}


function ChangePriceCurrency(price_currency){
	$.ajax({
		url: '/ajax/main.php',
		data: 'action=change_priceCurrency&price_currency=' + price_currency,
		type: 'get',
		success: function (response) {
			window.open(location.href, '_self');
		}
	});
}

/*Basket START*/
function PutIntoBasket(product_id){
	$.ajax({
		url: '/ajax/main.php',
		data: 'action=put_ProductIntoBasket&product_id=' + product_id,
		type: 'get',
		success: function (response) {
			$('#a_inbasket_'+product_id).attr('class', 'in_not');
			$('#basket_cnt').html('('+response+')');
			$('#basket_cnt2').html('('+response+')');
		}
	});
}
function RemoveFromBasket(product_id){
	$.ajax({
		url: '/ajax/main.php',
		data: 'action=remove_ProductFromBasket&product_id=' + product_id,
		type: 'get',
		success: function (response) {
			$('#basket_cnt').html('('+response+')');
			$('#basket_cnt2').html('('+response+')');
			$('#d_product_in_basket_'+product_id).css('display', 'none');
		}
	});
}
/*Basket END*/


$(document).ready(function(){
	$("a[rel='lightbox_forsell']").lightBox();
	$("a[rel='lightbox_objts']").lightBox();
	$("a[rel='lightbox_inbasket']").lightBox();
});


$(document).ready(function(){
	$('#im_fb_send').click(function () {
		var name = $('#fb_name').val();
		var phone = $('#fb_phone').val();
		var text = $('#fb_text').val();
		var email = $('#fb_email').val();
		var subject = $('#fb_subject').val();

		if(text.length > 10 && name.length > 3 && phone.length > 4 && email.length > 6) {
			$.ajax({
				url: '/ajax/fb_feedback.php',
				data: 'action=save_FB&text='+text+'&email='+email+'&name='+name+'&phone='+phone+'&subject='+subject,
				type: 'post',
				success: function (msg) {
					$('#d_rec_message').html('Спасибо за Вопрос');
					$('#fb_name').val('');
					$('#fb_email').val('');
					$('#fb_phone').val('');
					$('#fb_text').val('');
				}
			});
		}
		if(name.length <= 3){
			$('#d_rec_message').html('<span style="font-size: 13px">Введите своё имя</span>');
		}
		else if(email.length <= 6){
			$('#d_rec_message').html('<span style="font-size: 13px">Введите Email</span>');
		}
		else if(phone.length <= 4){
			$('#d_rec_message').html('<span style="font-size: 13px">Введите Телефон</span>');
		}
		else if(text.length <= 10){
			$('#d_rec_message').html('<span style="font-size: 13px">Вы не ввели вопрос</span>');
		}
	});
        		
    $('#ta_recommendation').keyup(function () {
		var m = $('#d_rec_message').html();
		if(m.length){
			$('#d_rec_message').html('');
		}
	});
});

function ShowHideOtherPhotos(){
	$("tr[tag='other_photos']").each(function() {
    	if(this.style.display == 'none') this.style.display = '';
		else  this.style.display = 'none';
	});
}

function number_format(number, decimals, dec_point, thousands_sep) {
    var n = !isFinite(+number) ? 0 : +number, 
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    return s.join(dec);
}
