//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").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 num = num,prie=prie,obj=obj;
      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("￥",""));
       
      }
      $(".count span").text("￥"+count.toFixed(2));
      var wl = parseFloat($(".wl span").text().replace("￥",""));
      var countg = count+wl;
      $(".countg span").text("￥"+count.toFixed(2)+"+￥"+wl+"(邮费)-￥0(优惠券)=￥"+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(){

        }
      })
    }
	})


function checkform()
{
	
				if(document.myform.gname.value==''){
				alert('商品名称不能为空，请重新填写！');
				document.myform.gname.focus();
				return false;
				} 
 
				if(document.myform.img.value==''){
            		alert('商品图片不能为空，请确保已上传！');
            		document.myform.img.focus();
            		return false;
            	}
  
				if(parseInt(document.myform.store.value)<1){
            		alert('商品库存必须大于1，请重新填写！');
            		document.myform.store.focus();
            		return false;
            	}
  
  document.getElementById('myform').submit();   
}

function ChCheck(){
        if(!/^[\u4e00-\u9fa5]+$/gi.test(document.getElementById("uname").value))
            alert("只能输入汉字");
        else
            return true;
    }


