﻿function Update_cart(item_id,qty,callback){
	if(qty<1){
		if(!confirm('Remove this item')){return}
		qty=0;
	};
	if(qty>99){qty=99};
	jqueryAJAX(
				   '/public/cart_act.aspx'
				   ,'act=update&item_id='+encodeURIComponent(item_id)+'&qty='+qty
				   ,function(o){
						o=eval('('+o+')')
						if(o.sts=='Y'){
							recart(o)
							if(typeof callback=='function'){callback()}
						}else if(o.sts=='N'){
							alert(o.msg)
						}else{
							
							if(confirm('You can only add items that belong to the same server in your cart, Empty your cart now.')){
									isajax=false;
									jqueryAJAX(
												   '/public/cart_act.aspx'
												   ,'act=update2&item_id='+encodeURIComponent(o.item_id)+'&qty='+o.qty
												   ,function(o){recart(eval('('+o+')'))}
											)

							}
							

						}

					}
			   )
}
function Update_gift(p,items,callback){
	jqueryAJAX(
				   '/public/cart_act.aspx'
				   ,'act=update_gift&items='+encodeURIComponent(items)+'&p='+encodeURIComponent(p)
				   ,function(o){
						o=eval('('+o+')')
						if(o.sts=='Y'){
							if(typeof callback=='function'){callback()}
						}

					}
			   )
}
function Update_incart(item_id,qty,callback){
	if(qty<1){
		if(!confirm('Remove this item')){return}
		qty=0;
	};
	if(qty>99){qty=99};
	jqueryAJAX(
				   '/public/cart_act.aspx'
				   ,'act=cartupdate&item_id='+encodeURIComponent(item_id)+'&qty='+qty
				   ,function(o){
						o=eval('('+o+')')
						if(o.sts=='Y'){
							isajax=false;
							jqueryAJAX(
								   '/public/cart_act.aspx'
								   ,'act=tohtml&typ=edit'
								   ,function(o){recart(o)}
							)
						}

					}
			   )
}




(function($) {
	$.extend({
		add2cart: function(source_id, target_id, callback) {
      var source = $('#' + source_id );
      var target = $('#' + target_id );
      
      var shadow = $('#' + source_id + '_shadow');
      if( !shadow.attr('id') ) {
          $('body').prepend('<div id="'+source.attr('id')+'_shadow" style="display: none; background-color: #888; border: solid 1px darkgray; position: static; top: 0px; z-index: 100000;">&nbsp;</div>');
          var shadow = $('#'+source.attr('id')+'_shadow');
      }
      
      if( !shadow ) {
          alert('Cannot create the shadow div');
      }
      
      shadow.width(source.css('width')).height(source.css('height')).css('top', source.offset().top).css('left', source.offset().left).css('opacity', 0.5).show();
      shadow.css('position', 'absolute');
      
      shadow.animate( { width: target.innerWidth(), height: target.innerHeight(), top: target.offset().top, left: target.offset().left }, { duration: 300 } )
        .animate( { opacity: 0 }, { duration: 100, complete: function(){
																	  $('#' + source_id + '_shadow').remove();
																	  if(typeof callback=='function'){callback()}
																			  } } );
		}
	});
})(jQuery);