function show_dm(id){
	document.getElementById(id+'').style.display="block";
}

function hide_dm(id){
	document.getElementById(id+'').style.display="none";
}

function switch_subcat(id){
	
	var el=document.getElementById('cat_'+id);
	if (el.className=="show") el.className="hide";
	else el.className="show";
	
	return false;
}

function themeChange(id){
	window.location='/consult/'+id+'/';
}


function increase(itemid){
	var input=document.getElementById('q_'+itemid);
	if (parseInt(input.value)==input.value) input.value=parseInt(input.value)+1;
	else input.value=1;
	
	 recalc(itemid);
	 
	 return false;
}


function decrease(itemid){
	var input=document.getElementById('q_'+itemid);
	if (parseInt(input.value)>0) input.value=parseInt(input.value)-1;
	else input.value=0;
	
	 recalc(itemid);
	 
	 return false;
}

function clear_basket(){
	$.ajax({
    url: '/ajax_clear_basket.php',            
    async : true,
    type: 'GET',
    dataType : "json", 
    success: function (data, textStatus) {
    	 if (data=='1')
    	 window.location='/basket/';
        }});
        
}

function basket(itemid){
	var input=document.getElementById('q_'+itemid);
	if (parseInt(input.value)<1) input.value=1;
	
	$.ajax({
    url: '/ajax_basket.php',            
    async : true,
    data : "id="+itemid+"&q="+input.value,
    type: 'GET',
    dataType : "json", 
    success: function (data, textStatus) {
         if (data) {
         	$("#on_"+itemid).removeClass('show').addClass('hide');
         	$("#off_"+itemid).removeClass('hide').addClass('show');
         } else {
         	$("#item_row_"+itemid).animate({ opacity: "hide" }, "fast");
         	$("#on_"+itemid).removeClass('hide').addClass('show');
         	$("#off_"+itemid).removeClass('show').addClass('hide');
         }
        }});
        
	rec(itemid);
}

function recalc(itemid) {
	if (itemid) var input=document.getElementById('q_'+itemid);
	if (input && parseInt(input.value)<1) input.value=1;
	$.ajax({
    url: '/ajax_recalc.php',            
    async : false,
    data : {id: itemid, q: input.value},
    type: 'GET',
    dataType : "json", 
    success: function (data, textStatus) {
    	var all_q=data.response.all_q;
    	var all_sum=Number(data.response.all_sum).toFixed(2);
    	if (all_q==0 && $("#basket_flag").attr("value")=='1') window.location='/basket/';
    	$("#all_sum").text(all_sum); 
    	$("#all_q").text(all_q); 
    	$("#all_sum2").text(all_sum); 
    	$("#all_q2").text(all_q); 
        }
	
	});

}



function rec(itemid){
		if (itemid) var input=document.getElementById('q_'+itemid);
	if (input && parseInt(input.value)<1) input.value=1;
	$.ajax({
    url: '/ajax_recalc.php',            
    async : false,
    data : {id: itemid, q: input.value},
    type: 'GET',
    dataType : "json", 
    success: function (data, textStatus) {
    	var all_q=data.response.all_q;
    	var all_sum=Number(data.response.all_sum).toFixed(2);
    	if (all_q==0 && $("#basket_flag").attr("value")=='1') window.location='/basket/';
    	$("#all_sum").text(all_sum); 
    	$("#all_q").text(all_q); 
    	$("#all_sum2").text(all_sum); 
    	$("#all_q2").text(all_q); 
        }
	
	});
}