var lvid = getParameter("lvid");
var sign = getParameter("sign");
var monthNum, yearNum, yearcount;
var alipay = false;
var params = {
	'lvid': lvid,
	'sign': sign,
	'vid': 1,
	'pid': 1
}
function info () {
	$.ajax({
		url:requestUrlMap['vipInfo']['url'],
		dataType: 'jsonp',
		data: params,
		success: function(json) {
			var paytype = json.paytype;
			var vipinfo = json.vipinfo;
			if(json.errorid == 0) {
				yearcount = paytype[1].discount;
				$('.discount').text(yearcount * 100 + '折');
				monthNum = paytype[0].price;
				yearNum = paytype[1].price;
				$('.bim_money b').text(monthNum);
				$('.bim_service p').attr('vid', vipinfo.vid);
				$('.bim_pay p:first-child').attr('pid', paytype[0].pid);
				$('.bim_pay p:nth-child(2)').attr('pid', paytype[1].pid);
				$('.vipName').text(vipinfo.name);
				$('.beginTime').text($.formatDateStyle1(new Date(vipinfo.starttime * 1000)));
				$('.endTime').text($.formatDateStyle1(new Date(vipinfo.endtime * 1000)));
				$('.money').text(vipinfo.price);
				$('.remark').html(vipinfo.remark);
				if(!vipinfo.endtime && !vipinfo.starttime) {
					$('.openTime').hide();
				} else {
					$('.openTime').show();
				}
				if(vipinfo.state == -1) {
					$('.vipIcon').attr('src', '../images/bim/bim_no.png');
				} else {
					$('.vipIcon').attr('src', '../images/bim/bim_yes.png');
				}
				codeImg();
			}
		}
	});
}
info();
$(document).ready(function() {
	$('.bim_account').val(lvid);
	$('.bim_service p,.bim_pay p,.bim_mode p').click(function() {
		$(this).addClass('active').siblings().removeClass('active');
	})
	$('.bim_pay p:nth-child(2)').hover(function() {
		if($(this).hasClass('active')) {
			$(this).find('span.bim_discount').css({
				top: "-4px",
				position: "absolute",
				right: "-6px"
			})
		}
		$(this).find('span.bim_discount').css({
			top: "-4px",
			position: "absolute",
			right: "-6px"
		})
	}, function() {
		if($(this).hasClass('active')) {
			$(this).find('span.bim_discount').css({
				position: "absolute",
				top: "-4px",
				right: "-6px"
			})
		}
		$(this).find('span.bim_discount').css({
			position: "absolute",
			top: "-3px",
			right: "-5px"
		})
	})
	$('.bim_succBack a').click(function() {
		$(this).parents('.bim_succLeft').hide();
		$(this).parents().find('.bim_left').show();
	})
	$('.bim_failBack a').click(function() {
		$(this).parents('.bim_failLeft').hide();
		$(this).parents().find('.bim_left').show();
	})
	$('.bim_mode p').click(function() {
		if($(this).index() == 0) {
			alipay = false;
			codeImg();
		} else {
			alipay = true;
			codeImg();
		}
	})
	$('.bim_time').keyup(function() {
		if(!$(this).val()) {
			return;
		}
		if($('.bim_pay p:first-child').hasClass('active')) {
			$('.bim_money b').text($(this).val() * monthNum);
			codeImg();
		} else {
			$('.bim_money b').text(($(this).val() * yearNum) * yearcount);
			codeImg();
		}
	})
	$('.bim_pay p').click(function() {
		var txt = $('.bim_time').val();
		if($(this).index() == 1) {
			$('.openType').text('年');
			$('.unit').text('年');
			$('.money').text(yearNum * yearcount);
			$('.bim_money b').text((yearNum * txt) * yearcount);
			$('.bim_brief h2').text('年服务期限：开通当日起365天');
			codeImg();
		} else {
			$('.openType').text('月');
			$('.unit').text('月')
			$('.money').text(monthNum);
			$('.bim_money b').text(monthNum * txt);
			$('.bim_brief h2').text('月服务期限：开通当日起31天');
			codeImg();
		}
	})
	$('#service').click(function() {
		var params = "{command:9038,params:{lvid:" + lvid + "}}";
		sendCommand(params);
	})
})
function codeImg() {
	var pid = $('.bim_pay .active').attr('pid');
	var payId = $('.bim_mode .active').attr('payId');
	var num = $('.bim_time').val();
	var vid = $('.bim_service p').attr('vid');
	$('.codeImg').attr('src', requestUrlMap['vipBuildOrder']['url'] + '?lvid=' + lvid + '&sign=' + sign + '&pid=' + pid + '&vid=' + vid + '&num=' + num + '&'+ '&paytype='+ payId +'&' + Math.random());
}

function paySuccess() {
	$('.bim_left').hide();
	$('.bim_succLeft').show();
	info();
}