$(document).ready(function(){
   var time = parseInt($("#viptime").val());
   var vipprice=parseInt($("#vipprice").val());
   if(vipprice<=0){ 
    	$(".order-btn").attr("disabled", 'disabled'); 
    }
   var total=time*vipprice;
   $("#viptime_post").val(time);
   $("#vipprice_post").val(vipprice);
   $("#viptimes_post").val(time);
   $("#viptotalprice").html("￥"+total+".00");
   $("#payprice").html("￥"+total+".00");
})
$('#viptime').bind('input propertychange', function() {  
   var time = parseInt($("#viptime").val());
   if(time<=0){
     $("#viptime").val('1');
	 time=1;
   }
   var vipprice=parseInt($("#vipprice").val());
   var total=time*vipprice;
   var d = new Date();
   var enddate=getMonthBeforeFormatAndDay(time,'-',d.getDate());
   $("#viptime_post").val(time);
   $("#vipprice_post").val(vipprice);
   $("#viptimes_post").val(time);
   $("#viptotalprice").html("￥"+total+".00");
   $("#payprice").html("￥"+total+".00");
   $("#vipend").html(enddate);
});  
function getMonthBeforeFormatAndDay(num, format, day) {
		var date = new Date();
		date.setMonth(date.getMonth() + (num*1), 1);
		//读取日期自动会减一，所以要加一
		var mo = date.getMonth() + 1;
		//小月
		if (mo == 4 || mo == 6 || mo == 9 || mo == 11) {
			if (day > 30) {
				day = 30
			}
		}
		//2月
		else if (mo == 2) {
			if (isLeapYear(date.getFullYear())) {
				if (day > 29) {
					day = 29
				} else {
					day = 28
				}
			}
			if (day > 28) {
				day = 28
			}
		}
		//大月
		else {
			if (day > 31) {
				day = 31
			}
		}

		retureValue = date.format('yyyy' + format + 'MM' + format + day);

		return retureValue;
	}

	//JS判断闰年代码
	function isLeapYear(Year) {
		if (((Year % 4) == 0) && ((Year % 100) != 0) || ((Year % 400) == 0)) {
			return (true);
		} else { return (false); }
	}

	//日期格式化
	Date.prototype.format = function (format) {
		var o = {
			"M+": this.getMonth() + 1, // month
			"d+": this.getDate(), // day
			"h+": this.getHours(), // hour
			"m+": this.getMinutes(), // minute
			"s+": this.getSeconds(), // second
			"q+": Math.floor((this.getMonth() + 3) / 3), // quarter
			"S": this.getMilliseconds()
			// millisecond
		}

		if (/(y+)/.test(format))
			format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
		for (var k in o)
			if (new RegExp("(" + k + ")").test(format))
				format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
		return format;
	}
$(function () {
if(checkIsMobile()){
	$(".check").css("width",'27%');
	$(".check").css("height",'36px');
	$(".check img").css("width",'100%');
	$(".check img").css("height",'100%');
}
});
function chengepay(pay){
var value = document.getElementById("payment");
   if(pay==1){
   
		document.getElementById('yuepay').className = 'check active';
		document.getElementById('alipay').className = 'check';
		document.getElementById('wxpay').className = 'check';
		value.value="yuepay"
   }
   if(pay==2){
	   document.getElementById('yuepay').className = 'check';
	   document.getElementById('alipay').className = 'check active';
	   document.getElementById('wxpay').className = 'check';
	   value.value="alipay"
   }if(pay==3){
	   document.getElementById('yuepay').className = 'check';
	   document.getElementById('alipay').className = 'check';
	   document.getElementById('wxpay').className = 'check active';
	   value.value="wxpay"
   }
}
function goToBank(){
	if(isLogin()){
	  var payment=$("#payment").val();
		if(payment=='yuepay'){
		   var yue=$("#myyue").val();
		   var total=$("#total").val();
		   if(parseInt(total)>parseInt(yue)){
		       dialog('提示','您的余额不足，请充值后再购买！',2);
		       return false;
		   } else{
		   	  $("#paySubmit").submit(); 
             // paydialog('提示','你选择使用余额进行在线支付</br>请在新打开的支付页面完成支付</br>祝你学习愉快！');
		   }
		}
		if(payment=='alipay'){
		   $("#paySubmit").submit(); 
		   //paydialog('提示','你选择使用支付宝进行在线支付</br>请在新打开的支付页面完成支付</br>祝你学习愉快！');
		}
		if(payment=='wxpay'){
		   $("#paySubmit").submit(); 
		   //paydialog('提示','你选择使用微信扫码进行在线支付</br>请在新打开的支付页面完成支付</br>祝你学习愉快！');
		}
	}else{
	   lrFun();
	}  
}