jQuery(document).ready(function($){ 
	try{
		for(var i in advert){
			if (advert[i][0].isrand==1) {
				advert[i].shuffle();
			}
		}
		scope.advert=advert;
		scope.$apply();
	}catch(e){
		//TODO handle the exception
	}
	try{
		jQuery(document).on('click','#ad_left',function () {
			var the=jQuery(this);
			jQuery("#ad_left").remove(); 
		});
		jQuery(document).on('click','#ad_right .close',function () {
			var the=jQuery(this);
			jQuery("#ad_right").remove(); 
		});
		jQuery(document).on('click','#ad_right_bottom .close',function () {
			var the=jQuery(this);
			jQuery("#ad_right_bottom").remove(); 
		});
	}catch(e){
		//TODO handle the exception
	}
});
jQuery(document).on('click', '.btn_buy', function() {
	var the = jQuery(this);
	var form=the.closest('form');
	var isemail = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$");
	if (!isemail.test(form.find('#email').val())) {
		form.find('#email').next('div').html('<span style="color:#f00">邮箱格式不正确</span>');
		form.find('#email').on('focus',function () {
			form.find('#email').next('div').html('');
		});
		return false;
	}
	if (form.find('#email').val()=='') {
		form.find('#email').next('div').html('<span style="color:#f00">邮箱不能为空</span>');
		form.find('#email').on('focus',function () {
			form.find('#email').next('div').html('');
		});
		return false;
	}
	if (form.find('#pay_way').val()=='') {
		form.find('#pay_way').next('div').html('<span style="color:#f00">请选择支付方式</span>');
		form.find('#pay_way').on('focus',function () {
			form.find('#pay_way').next('div').html('');
		});
		return false;
	}
	jQuery('#buy').modal('close');
	jQuery('#payconfirm').modal({
		relatedTarget: this,
		onconfirm: function() {
			jQuery(".btn_tqmxz").click();
		},
		onCancel: function() {

		}
	});
	the.closest('form').submit();
});

jQuery(document).on('click', '.btn_tqmxz', function() {
	jQuery('#download').modal();
});
jQuery(document).on('click', '.btn_download_tqm', function() {
	var the = jQuery(this);
	jQuery.ajax({
		url: "/file/download",
		data: the.closest('form').serializeArray(),
		dataType: "json",
		type: "post",
		timeout: 10000,
		success: function(data) {
			if(data.status == 1) {
				jQuery('#download').modal('close');
				the.closest('form')[0].reset();
				location.href = data.url;
			} else {
				wd_alert({
					msg: data.info,
					background: '#f00'
				})
			}

		},
		error: function() {}
	});
});

jQuery(document).on('click','.btn_order_search',function () {
	var the=jQuery(this);
	jQuery('#order_search').modal();
});
jQuery(document).on('click','.btn_order_search_go',function () {
	var the=jQuery(this);
	jQuery.ajax({
		url:"/pay/file_alipay_pc_return",
	    data:the.closest('form').serializeArray(),
	    dataType: "json",
	    type: "post",
	    timeout: 10000,
	    success: function(data) {
	    	if (data.status=='0') {
	    		alert(data.info);
	    	}else{
	    		location.href='/pay/file_alipay_pc_return/order_no/'+jQuery('[name="order_no"]').val();
	    	}
	    },
	    error: function() {
	        mui.toast("网络连接超时");
	    }
	});          
})