$().ready(function(){
	ec_basketGet();
	ec_basketListGet();
	
	$("a#imgec").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
	});
});

function ec_basketGet(){
	$.ajax({
	    type: "POST",
	    url:  URL+'modules/ext/ec_shipping/ajax/public.ajax.php?'+Math.random(1,9999),
	    dataType: "text",
	    complete: function(msg){},
	    success: function(msg){
	    	$("#basketBlock").html(msg);
			$(".btn_basket").overlay({mask: {
				color: '#000000',
				loadSpeed: 200,
				opacity: 0.3
			},
				onBeforeLoad : function(){
					ec_basketListGet();
				}
			});
			
	    }
	});
}


function ec_basketListGet(){
	
	$.ajax({
	    type: "POST",
	    url:  URL+'modules/ext/ec_shipping/ajax/public.ajax.php?e=basket_list_get&'+Math.random(1,9999),
	    dataType: "text",
	    complete: function(){
		
		},
	    success: function(msg){
			$("#div_basket_in").html(msg);
			$('#div_basket_in form').submit(function(){
			    $(this).ajaxSubmit({
			        url: URL+'modules/ext/ec_shipping/ajax/public.ajax.php?'+Math.random(1,36),
			        method: 'post',
			        dataType: 'html',
			        clearForm: false,
			        success: function(msg){
			    		ec_basketListGet();
			    		ec_basketGet();
			            $('#div_basket').unblock();
			        },
			        beforeSend: function(){
			            $('#div_basket').block({message: "<h4>Обработка</h4>", css: { border: '1px solid #a00', padding: '0px 0px 0px 0px',width:'50%'}});
			        }
			    });
			    return false;
			});
			
	    }
	});
}

function ec_basketAdd(id,objBtn){
	
	_gaq.push(['_trackEvent', 'ecBasketAdd', 'ecItemAdd', "item id " + id]);
	
	$.ajax({
	    type: "POST",
	    url:  URL+'modules/ext/ec_shipping/ajax/public.ajax.php?e=item_add&'+Math.random(1,9999),
	    dataType: "text",
	    data: "id="+id,
	    complete: function(){},
	    success: function(msg){
	  	  	ec_basketGet();
	  	    ec_basketListGet()
	    },
	    beforeSend: function(){
	  	  $(objBtn).effect("transfer",{to:"#basket", className: 'ui-effects-transfer'},1000);
	    }
	});
	return false;
}


function ec_closebasket(){
	var api = $(".btn_basket").data("overlay");
		api.close();
}

//DELL FROM BASKET
function ec_basketDelItem(id){
	$.ajax({
    type: "POST",
    url:  URL+'modules/ext/ec_shipping/ajax/public.ajax.php?e=item_del&'+Math.random(1,9999),
    dataType: "text",
    data: "id="+id,
    success: function(msg){
  		ec_basketGet();
	  	    ec_basketListGet()
    }
});
return false;
}

function ec_recallAdd(obj){
	
	$(obj).ajaxSubmit({
		url: URL+'modules/ext/ec_recall/ajax/public.ajax.php?e=add_recall&'+Math.random(1,9999),
		method: "POST",
		dataType: "html",
		success: function(msg){
			$("#ec_recallStatus",obj).html(msg);
		},
		beforeSubmit: function(){
			$("#ec_recallStatus",obj).html('Обработка...');
		}
	}); 
	return false;
}

$().ready(function(){
	
	if($("#commentsForm").length != 0){
//		$("#commentsForm").validate({
//			submitHandler: function() {
				$("#commentsForm").validator({lang: 'ru',speed:'fast',errorClass:'formErrorInput',messageClass:'formErrorMess'}).
				bind("onSuccess", function(e, els)  {
					if (e.originalEvent.type == 'submit') {
						$("#commentsForm").ajaxSubmit({
					  		url: URL+'modules/ext/ec_catalog/ajax/public.ajax.php?e=add_comments&'+Math.random(1,9999),
					  		method: "POST",
					  		dataType: "html",
					  		clearForm: true,
							success: function(msg){
								$('#commentsForm').unblock();
								$("#commentsNew").fadeIn(300).append(msg);
							},
							error: function(responseObj){alert("ERROR.RELOAD PAGE PLS");},
							beforeSubmit: function(){
								$('#commentsForm').block({message: "<h5>Отправка</h5>", css: { border: '1px solid #a00', padding: '10px 10px 10px 10px',width:'50%'}});
							},
							beforeSend: function(){}
						});
					}
					return false;
				});
//			}
//		});
	}
})
