  var coupon =new  Array ("5","5","5","5","10","5","5","5","5","10","5","5","5","5","20","5","5","5","5","20","5","5","5","5","30","5","5","5","5","30","5","5","5","5","40","5","5","5","5","40");
  var started = false;
  var lefttimes = 10;
  var timer;
  var submitted = false;




 function Browser() {



   var ua, s, i;



   this.isIE     = false;   // Internet Explorer

   this.isNS     = false;   // Netscape

   this.version = null;



   ua = navigator.userAgent;



   s = "MSIE";

   if ((i = ua.indexOf(s)) >= 0) {

     this.isIE = true;

     this.version = parseFloat(ua.substr(i + s.length));

     return;

   }



   s = "Netscape6/";

   if ((i = ua.indexOf(s)) >= 0) {

     this.isNS = true;

     this.version = parseFloat(ua.substr(i + s.length));

     return;

   }



   // Treat any other "Gecko" browser as NS 6.1.



   s = "Gecko";

   if ((i = ua.indexOf(s)) >= 0) {

     this.isNS = true;

     this.version = 6.1;

     return;

   }

}



var browser = new Browser();





   function hideyhq(){

		divyhq.style.display="none";

		divbuttons.style.display="none";

	}

	

 function showyhq(){

		if (browser.isIE) {	

			if (browser.version <7) {

				divyhq.style.display="";

				divbuttons.style.display="";

				}

			else if (browser.version >=7) {

			window.open( "/sd/yhq.html","yhq","left=200,top=100,height=516,width=610,toolbar= no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");

			}

		}
		else
			window.open( "/sd/yhq.html","yhq","left=200,top=100,height=516,width=610,toolbar= no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
		

	}

 
  function sstart() {
    if (!started) {
		started =true;

		lefttimes = lefttimes-1;
		if (lefttimes<0) {
			alert("你抽取优惠券的次数已经用完，欢迎2小时后再来！\n您现在可以输入用户名并点击“提交优惠券”将您抽到的优惠券提交给我们。");
			return;
		}

		btnStart.value="停止";
		btnSubmit.style.display ="none";
		timer= window.setInterval("setcoupon()",100);
		divlefttimes.innerHTML = "您还有"+lefttimes+"次机会";
		}
	else {
		window.clearInterval(timer);
		started =false;
		btnStart.value="重来";
		btnSubmit.style.display ="";
		}
	}

  function setcoupon() {
	var rndno = Math.random()*1000000;
	rndno = Math.round(rndno);
	if (rndno< 100 ) rndno= rndno*10000;
	if (rndno< 1000 ) rndno= rndno*1000;
	if (rndno< 10000 ) rndno= rndno*100;
	if (rndno< 100000 ) rndno= rndno*10;
    couponForm.coupon_num.value  =  rndno;
    couponnum.innerHTML = "优惠券号："+ rndno;
    
    rndno =  Math.random()* 39;
	rndno = Math.round(rndno);
	var sval = coupon[rndno];
    couponForm.coupon_value.value  =  sval;

    if (sval <10) sval = "0" + sval;
    couponvalue.innerHTML = "可抵扣"+sval + "元";
	}	
	
	
 function submitForm(){

	if (submitted)
	{
		alert("您不能多次提交！");
		return false;
	}
    if (couponForm.username.value =='') {
      alert("请输入用户名");
      return false;      
    }
    if (couponForm.coupon_num.value =='000000')  {
      alert("您还没有抽取优惠券");
      return false;      
    }
    if (couponForm.coupon_value.value  =='00') {
      alert("您还没有抽取优惠券");
      return false;      
    }
    
	couponForm.submit();
	submitted = true;
	btnSubmit.disabled = true;

	alert("优惠券提交成功！敬请咨询客服人员如何在订单中使用优惠券.");


 }	
