
function login(){
  if('{$Think.session.uid}'){
  
  //如果存在session，直接进入后台
  window.location.href="index.php?m=User&a=edit"; 
  }else{
  //弹出窗体，选择登陆还是注册
  
  $('#doc-modal-User').modal('open');
  }
}
function recheck(){
  if($("#reform :input[name=tel]").val()==""){
     alert("手机号不能为空");
	 return
  }
  if($("#reform :input[name=password]").val()==""){
     alert("密码不能为空");
	 return
  }
  if($("#reform :input[name=password]").val()!=$("#reform :input[name=repassword]").val()){
     alert("两次密码不一致");
	 return
  }
  //判断一下是否开启短信验证
  if("{$site.is_sms_validate}" == "1"){
	  if($("#reform :input[name=verify]").val()==""){
		 alert("验证码不能为空");
		 return
	  }
	  if($("#reform :input[name=verify]").val()!=Num){
		 alert("验证码不正确");
		 return
	  }
  }
  
  $("#reform").submit();
}
function locheck(){
  if($("#loform :input[name=tel]").val()==""){
     alert("手机号不能为空");
	 return
  }
  if($("#loform :input[name=password]").val()==""){
     alert("密码不能为空");
	 return
  }
  $("#loform").submit();
}
function ocheck(){
  if("{$Think.CONFIG.SITE_CONFIG.is_ghost}"=="0" && "{$Think.session.uid}" ==""){
     alert("本站禁止游客下单，请先登录！");
	 return
  }
  
  
  if($("#oform :input[name=tel]").val()==""){
     alert("手机号不能为空");
	 return
  }
  if($("#oform :input[name=name]").val()==""){
     alert("收货人不能为空");
	 return
  }
  if($("#oform :input[name=address]").val()==""){
     alert("收货地址不能为空");
	 return
  }
    var ShoppingCart = utils.getParam("ShoppingCart");
	if(ShoppingCart==null||ShoppingCart==""){
	    alert("没有商品，请先去购物吧！");
	    return
	}else{
		var jsonstr = JSON.parse(ShoppingCart.substr(1,ShoppingCart.length));
		//alert(jsonstr);
		//return;
		var productlist = jsonstr.productlist;
		orderdetail.totalAmount = jsonstr.totalAmount;	
		orderdetail.totalintergal = jsonstr.totalintergal;	
		if(orderdetail.totalAmount.toFixed(2)<=0){
			alert("没有商品，请先去购物吧！");
	        return
		}else{
			var order_no = new Date().getTime(); 
			$("#oform :input[name=order_no]").val(order_no);   //获取一个时间戳作为订单号
			$("#oform :input[name=totalAmount]").val(orderdetail.totalAmount.toFixed(2));   //提交订单总额
			$("#oform :input[name=give_integral]").val(orderdetail.totalintergal.toFixed(2));   //提交订单积分
			var n = 0 ;
			for(var i=0;i<productlist.length;i++){
				$.post("{:U('ordergood')}", { gid: productlist[i].id, num: productlist[i].num ,name:productlist[i].name,price:productlist[i].price,order_no:order_no},function(data)                    {
                    n = n+1;
					if(n==productlist.length){
				    	utils.setParam("ShoppingCart","");
			            car_load();
		            	$("#oform").submit();	
					}
                    } ,'json');	
			}	
		}
	}
}


<!--购物车处理-->
$(function(){
//商品减
$(".pd_product-num-minus").click(function(){
  
   var buycount = $('.buycount').html();              // 数量
   if(buycount<=1){
   $('.buycount').html(Number(1));
   }else{
   $('.buycount').html(Number(buycount)-Number(1)); 
   }
});
//商品加
$(".pd_product-num-plus").click(function(){
   var buycount = $('.buycount').html();              // 数量
   $('.buycount').html(Number(buycount)+Number(1)); 
});


//加载购物车
car_load();

});
//清空购物车
$("#delcart").click(function(){
    if(confirm('您确定要清空购物车吗?')==false)return false;
	cart.delcart();
	car_load();//更新购物车
});


//商品详情界面将商品放入购物车
function putCart(){
	var product={
			id:'{$good.gid}',    // 商品的ID
			name: '{$good.name}',    // 商品名称
			num:$('.buycount').html(),              // 数量
			price:'{$good.price}',    // 价格
			intergal:'{$good.give_integral}',       //积分
		};
	var thisTop = $("#img_{$good.gid}").offset().top; //所在位置的高度
	var thisLeft = $("#img_{$good.gid}").offset().left; //所在位置的宽度
	
	animatenTop(thisTop,thisLeft,'{$good.gid}',product);

}

//商品列表界面将商品放入购物车
function addCart(id,name,price,intergal){
	var product={
			id:id,    // 商品的ID
			name:name,    // 商品名称
			num:1,              // 数量
			price:price,    // 价格
			intergal:intergal,
		};	
	var thisTop = $("#img_"+id).offset().top; //所在位置的高度
	var thisLeft = $("#img_"+id).offset().left; //所在位置的宽度
	//alert(product);
	animatenTop(thisTop,thisLeft,id,product);
}
//购物框标签晃动一下
function shock(){

    var div=$(".Allcount");
    
	div.animate({left:'60%'},100);
    div.animate({left:'50%'},100);
	div.animate({left:'60%'},100);
    div.animate({left:'50%'},100);

}
//修改购物车内的商品
function update(id,num){
    var buycount = $('#'+id).html();              // 数量

    $('#'+id).html(Number(buycount)+Number(num));   //更新购物车里面的数量
    var num = $('#'+id).html();   //获取更新后的
	if(num<=0){
	cart.deleteproduct(id);
	}else{
	cart.updateproductnum(id,num);
	}
	shock();//购物框标签晃动一下
	car_load();//更新购物车
}

function animatenTop(thisTop,thisLeft,menID,product) {
   
    //判断商品图片往哪个方向飞去
	
	var cartLength = $(".am-icon-shopping-cart").offset().left; //取得到购物车的宽度
	if(cartLength>0){
	     //说明是电脑端，选择第一个class
		var cart_direction = $(".Allcount:first");
	}else{
	    var cart_direction = $(".Allcount:last");
	}
	var topLength =  cart_direction.offset().top; //取得到购物车的宽度
    var leftLength = cart_direction.offset().left; //取得到购物车的宽度

    //判断一下当前窗口的宽度是否大于1280px
	var windowwidth  =  $(window).width();
	if(windowwidth>1280){
	   var thisLeft = thisLeft - (windowwidth-1280)/2;
	   var leftLength = leftLength - (windowwidth-1280)/2;
	}
	//获取商品图片的div的宽高
	var width=$(".good_img").width();
	var height=$(".good_img").height();
    var CopyDiv = '<img src="'+$("#img_" + menID).attr("src")+'" id="box" style="top:' + thisTop + 'px;left:' + thisLeft + 'px;z-index:9999;width: '+width+'px;height: '+height+'px"   />';
    
	
    $("body").append(CopyDiv);
	
    $("body").children("#box").animate({width: "30px",height: "30px","top": topLength, "left": leftLength, "opacity": .1  },1000, function(){
	    $(this).remove();
		shock();//购物框标签晃动一下
		cart.addproduct(product);
	    car_load();//更新购物车
    });
    
}
function car_load(){

	var ShoppingCart = utils.getParam("ShoppingCart");
	
	if(ShoppingCart==null||ShoppingCart==""){
		var str='<div style="font-size: 16px;font-weight: bold;text-align: center;color: #009f3c;line-height: 160px;">购物车空空如也</div>';
		$('#totalAmount').html('总计价格：0元');
	}else{
	//alert(ShoppingCart);
	    var jsonstr = JSON.parse(ShoppingCart.substr(1,ShoppingCart.length));
		var productlist = jsonstr.productlist;
		orderdetail.totalNumber = jsonstr.totalNumber;
		orderdetail.totalAmount = jsonstr.totalAmount;
		orderdetail.totalintergal = jsonstr.totalintergal;
		var str='';
		for(var i=0;i<productlist.length;i++){
			str+='<li><a href="index.php?m=Index&a=good&gid='+productlist[i].id+'" style="width:140px; overflow:hidden;">'+productlist[i].name.substr(0,9)+'</a><div style="display: -webkit-box;float:right;margin-right:10px;">'+productlist[i].price+'元 x <div class="pd_product-num-wrap"><span class="pd_product-num-minus" onclick="update('+productlist[i].id+',-1)"></span><span class="Number" id="'+productlist[i].id+'">'+productlist[i].num+'</span><span class="pd_product-num-plus" onclick="update('+productlist[i].id+',1)"></span></div></div></li>'; 
		}	
		str+='<li id="Hide" style="text-align:right;padding-right:20px;background-color:#C6F5C6;">总计价格：<span style="color:red; font-weight:bold;font-size:14px;">'+orderdetail.totalAmount.toFixed(2)+'<span>元</li>';
		$('.Allcount').html(orderdetail.totalNumber);
		$('#totalAmount').html('总计价格：<span style="font-weight:bold;">'+orderdetail.totalAmount.toFixed(2)+'<span>元');
		$("#goforcart").attr("onclick","showcanuse(orderdetail.totalAmount.toFixed(2),{$user.integral_num});");
	}//onclick="showcanuse(ShoppingCart.totalAmount,{$user.integral_num})"
	
	$('#cart').html(str);
	
	//onclick="cart.deleteproduct('+productlist[i].id+');"
}

//短信操作
var wait=60;
function codecheck(){
  if($("#reform :input[name=tel]").val()==""){
     alert("手机号不能为空");
	 return
  }
  if($("#reform :input[name=password]").val()==""){
     alert("密码不能为空");
	 return
  }
  if($("#reform :input[name=password]").val()!=$("#reform :input[name=repassword]").val()){
     alert("两次密码不一致");
	 return
  }
  time(); 
  num();
}
function time() {
	if (wait == 0) {
		code.removeAttribute("disabled");            
		code.innerHTML="获取验证码";
		wait = 60;
	} else { // www.jbxue.com
		code.setAttribute("disabled", true);
		code.innerHTML="重新发送(" + wait + ")";
		wait--;
		setTimeout(function() {
			time()
		},
		1000)
	}
}
var Num=""; 
function num() {
	for(var i=0;i<6;i++) 
	{ 
	Num+=Math.floor(Math.random()*10); 
	} 
	var phone=$("#reform :input[name=tel]").val();
	$.post("index.php?m=Index&a=sendmsg", { "phone": phone ,"Num": Num });
}
function showcanuse(totalamount,totalintrgral){
	if (parseInt('{$site.each_inte}') != '')
	{
		therate = parseInt('{$site.each_inte}');
	}else{
		therate = 0;
	}
    //therate = {$each_inte};
	totalcanuse = parseInt(totalamount*therate/100);
	//remain = totalamount - totalcanuse/10 ;
	if(totalcanuse<totalintrgral){
		remain = totalamount - totalcanuse/10 ;
		$('#maxinteg').html(totalcanuse);
		$('#remainuse').html(remain.toFixed(2));
		$("#oform :input[name=pay_cash]").val(remain.toFixed(2));   
		$("#oform :input[name=use_inter]").val(totalcanuse);   

	}else{
		remain = totalamount - totalintrgral/10 ;
		$('#maxinteg').html(totalintrgral);
		$('#remainuse').html(remain.toFixed(2));
		$("#oform :input[name=pay_cash]").val(remain.toFixed(2));   
		$("#oform :input[name=use_inter]").val(totalintrgral);  
	}
}
flagofinput = 0;
alert('{$user.integral_num}');
function changevalue(){
	if(flagofinput == 0){
		$("#oform :input[name=pay_cash]").val(orderdetail.totalAmount.toFixed(2));   
		$("#oform :input[name=use_inter]").val(0);   
		$('#remainuse').html(orderdetail.totalAmount.toFixed(2));
		flagofinput = 1;
	}else{
		showcanuse(orderdetail.totalAmount.toFixed(2),'{$user.integral_num}');
		flagofinput = 0;
	}
}
