
function getTotal(){
$.ajax({
			type: "GET",
			url: "cart.php",
			data: "getTotal=1",
			success: function(msg){
				//$("#cart").html(msg);
				//alert("success");
				$("#fin_total").html(msg);
			}
			});
//$("#fin_total").html();
}
function isNumberKey(evt) {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 44 || charCode > 57))
            return false;
         return true;
}
 //add to cart


function calc_cart(num,upd_id) {
var price, count, prnt;
price = parseFloat($("#price_"+num).val());
count = parseInt($("#count_"+num).val());
prnt = Math.round(price*count*100,2)/100;
$("#total_"+num).html(prnt);
$("#total_"+num+"_t").html(prnt+" лв.");

$.ajax({
			type: "GET",
			url: "cart.php",
			data: "upd_id="+upd_id+"&count="+count,
			success: function(msg){
				//$("#cart").html(msg);
				//alert("success");
				getTotal();
			}
			});
}

function loadPage(page){
	if(cart == true){
	showCart()
	}
	//location.hash = 'p'+page;

	$("#contents").addClass("loading");
	$.ajax({
			type: "GET",
			url: page+".php",
			//data: "",
			success: function(msg){
				$("#contents").html(msg);
				//scrollActive(id);	//loadTree(id);
				$("#contents").removeClass("loading");
			}
			});		
			
				
}

function showActiveOffer(id){
$("#main_offers").animate({height: 220},"fast");
	$("#act_offer").addClass(".loading");
	$.ajax({
			type: "GET",
			url: "offers.php",
			data: "info="+id,
			success: function(msg){
				$("#act_offer").html(msg);
				//scrollActive(id);	//loadTree(id);
				
				cycle_offers();
				
				$("#act_offer").removeClass(".loading");
			}
			});	

}
function cycle_offers(){
	$('#s6').cycle({
			fx:  	'scrollDown', 
			timeout: 10000, 
			delay:  -2000,
			speedIn:  2000, 
			speedOut: 500,
			next:   '#next2', 
    		prev:   '#prev2' ,
			easeIn:  'bounceout', 
			easeOut: 'backin'

	});
}
function hideActiveOffer(){
$("#main_offers").animate({height: 135},"fast");
}
function scrollActive(obj){
	if(cart == true){
	showCart()
	}
	
	$("li[id='"+obj+"']").parents(">ul").fadeIn();
	$("li[id='"+obj+"']").children(">ul").fadeIn();
	
	var className = $("li[id='"+obj+"']").attr("class");
	if(className){
	className = className.replace('close','open');		
	$("li[id='"+obj+"']").attr("class",className);
	}
	
	$("li[id='"+obj+"']").parents("li").each( function () {
	var className = $(this).attr("class");
	if(className){
	className = className.replace('close','open');		
	$(this).attr("class",className);
	}
	});
	
	$("li[id='"+obj+"']").siblings().filter('.folder-open, .folder-open-last').each(function(){
				var childUl = $('>ul',this);
				var className = this.className;
				className = className.replace('open','close');
				$(this).attr('class',className);
					childUl.animate({height:"toggle"},"fast");
			});	
	
	if($("li[id='"+obj+"']").children("span").filter(".toggler").is(':visible')){
		$(this).click();
		//alert("click");
	} else {
		//alert("error");
	}
	

}
function scrollActiveElement(obj,element){
	if(cart == true){
	showCart()
	}
	
	$("li[id='"+obj+"&element_id="+element+"']").parents(">ul").fadeIn();

	var className = $("li[id='"+obj+"&element_id="+element+"']").not("li[class='root']").attr("class");
	if(className){
	className = className.replace('close','open');		
	$("li[id='"+obj+"&element_id="+element+"']").attr("class",className);
	}
	
	$("li[id='"+obj+"&element_id="+element+"']").parents("li").not("li[class='root']").each( function () {
	var className = $(this).attr("class");
	if(className){
	className = className.replace('close','open');		
	$(this).attr("class",className);
	}
	});
		
	if($("li[id='"+obj+"&element_id="+element+"']").children("span").filter(".toggler").is(':visible')){
		$(this).click();
		//alert("click");
	} else {
		//alert("error");
	}
	
}

function showCart(){


	if(cart == false){
		$("#bag_area").show();//$("#cart").css('height')
		$("#bag_area").animate({height: 250, width: 430}, 400, function() { $("#purchase_button").show(); 
		//$("#bag").animate({height: 450}, 400);
		});	// $("#bag_area").fadeTo("slow", 0.97); 
		cart = true;
	}else{
		$("#purchase_button").hide()//function() { 
		$("#bag_area").animate({height: 0, width: 175}, "slow", function() { $("#bag_area").hide(); });
		
		cart = false;
		//}); 
	}
}
ask = false;
function showAsk(){
	if(ask == false){
		
		$("#ask_par").animate({height: 250}, "slow", function(){ $("#ask").show(); } );	// $("#bag_area").fadeTo("slow", 0.97); 
		ask = true;
	}else{
		$("#ask").hide( function(){
		$("#ask_par").animate({height: 0}, "slow");
		});
		ask = false;
		
	}
}


function up(num){
$('#count_'+num).val(parseInt($('#count_'+num).val()) + 1); 

}
function down(num){
if($('#count_'+num).val() > 1) $('#count_'+num).val(parseInt($('#count_'+num).val()) - 1); 

}