//html fontSize 重置
(function (doc, win) {
  var docEl = doc.documentElement,
  resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
  recalc = function () {
    var clientWidth = docEl.clientWidth;
    if (!clientWidth)
    {
      return;
    } 
    else if(clientWidth>750){
      docEl.style.fontSize = 100 + 'px';
    }
    else if(clientWidth<=750)
    {
      docEl.style.fontSize = (clientWidth / 7.5) + 'px';
    }
  };
 
  if (!doc.addEventListener) return;
  win.addEventListener(resizeEvt, recalc, false);
  doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);
(function() {
     var e = "abbr, article, aside, audio, canvas, datalist, details, dialog, eventsource, figure, footer, header, hgroup, mark, menu, meter, nav, output, progress, section, time, video".split(', ');
     var i= e.length;
     while (i--){
         document.createElement(e[i]);
     } 
})() 

$(function(){
	 $(".select .radio input").live("click",function(){
    var p= $(this).parents(".select").find("input");
    var i =p.index(this)
     if($(this).is(":checked")){
         $(this).parents(".select").find(".radio").removeClass("on").eq(i).addClass("on")
     }
   })

   $(".num .next").click(function(){
    var val = $(".num input").val();
    if(isNaN(val)){
      val = 1;
    }
    val = ++val;
    $(".num input").val(val)
   })
    $(".num .prev").click(function(){
    var val = $(".num input").val();
    if(isNaN(val)){
      val = 1;
    }
    val = --val < 1 ? 1 : val;
    $(".num input").val(val)
   })

    $(".reTop").click(function(){
      $(window).scrollTop(0)
    })

    $(".pronum .next").click(function(){
    var val = $(this).parents(".pronum").find("input").val();
    if(isNaN(val)){
      val = 1;
    }
    val = ++val;
    $(this).parents(".pronum").find("input").val(val);
    var prie = parseFloat($(this).parents(".test").find(".nowM span").text().replace("￥",""));
    count(val,prie,$(this).parents(".numcount").find(".procount"))
    ajaxku($(this).parents(".pronum").find("input").attr("name"),val)
   })
    $(".pronum .prev").click(function(){
    var val = $(this).parents(".pronum").find("input").val();
    if(isNaN(val)){
      val = 1;
    }
    val = --val < 1 ? 1 : val;
    $(this).parents(".pronum").find("input").val(val);
    var prie = parseFloat($(this).parents(".test").find(".nowM span").text().replace("￥",""));
    count(val,prie,$(this).parents(".numcount").find(".procount"))
    ajaxku($(this).parents(".pronum").find("input").attr("name"),val)
   })
    //计算价格
    function count(num,prie,obj){
		var mjVal1 = mjVal;
		var max_mjVal1 = max_mjVal;
      var num = num,prie=prie,obj=obj;
      var wl_n = 0;
      var procount = num*prie;
      obj.find("span").text("￥"+procount.toFixed(2));
      var count = 0;
      
      for(var i=0;i<$(".procount").length;i++){
        count += parseFloat($(".procount").eq(i).find("span").text().replace("￥",""));
  
      }
      for(var i=0;i<$(".cart_pro_list").length;i++){
       wl_n += parseFloat($(".cart_pro_list").eq(i).find(".free").attr("data-value"));
	
      }
      $(".wl span").text("￥"+wl_n)
      $(".count span").text("￥"+count.toFixed(2));
      var wl = parseFloat($(".wl span").text().replace("￥",""));
	  
	  

		if(count >= max_mjVal1){
      countg= count+wl - mjVal1;
			 $(".countg span").text("￥"+count.toFixed(2)+"+￥"+wl+"(邮费)-￥"+mjVal1+"(优惠券)=￥"+countg.toFixed(2));
			}else{
        countg= count+wl ;
				 $(".countg span").text("￥"+count.toFixed(2)+"+￥"+wl+"(邮费)=￥"+countg.toFixed(2));
				}
     

      var count_n = 0;
       for(var i=0;i<$(".cart_pro ").length;i++){
        count_n += parseFloat($(".cart_pro ").eq(i).find("input").val())
      }
      $('footer').find("span").text(count_n)
    }

    //更新库存
    function ajaxku(val,num){
     $.ajax({
        type: 'POST',
        url: 'user_cart_update.asp',
        // post payload:
        data: "num="+num+"&val="+val,
        succsee:function(){

        }
      })
    }
	
	$(".pinglun .xx i").click(function(){
        var i = $(".pinglun .xx i").index(this)+1;
        $(".pinglun .xx_num").val(i)
        $(".pinglun .xx i").removeClass("xx_t");
        for(var j = 0;j<i;j++){
         $(".pinglun .xx i").eq(j).addClass("xx_t");
        }
      })
	
	})


 
//************************顶部商品和店铺搜索*********************
function sb(){ 
 var form =  document.getElementById("frm_find"); 	
 var t =  document.getElementById("stype").value; 
 var skey=document.getElementById("skey").value; 
 if (skey.length==0)
     {
  alert ("请输入搜索关键词!");
  document.frm_find.skey.focus();
  return false;
  }
  
 if (t==1) 
   {
	form.action = "product_list.asp";
	}
	else
	{
	form.action = "Mall_list.asp";
	}
 
return true;
}
 


