var downloadNotStart = true;
var isNotSubmit = true;
$(document).ready(function() {
	clickStatistics(baseUrl,'Model_ssdb','Page_dborderrequest_button_wx',postDataDefaultErrorCallback);
	$('#customerSubmit').click(function(event) {
		customerInfoSubmit();
	});
	$('.apply-letter-btn').click(function(event) {
		gotoDownload();
	});
});

//电话校验
function checkTel(no){
	var isPhone = /^([0-9]{3,4}-)?[0-9]{7,8}$/;
	var isMob = /^1[0-9]{10}/;
	if(isMob.test(no)||isPhone.test(no)){
		return false;
	}else{
		return true;
	}
}

//客户联系方式提交
function customerInfoSubmit(){
	if(isNotSubmit){
		var name = $('#customerName').val();
		if(name.length < 1){
			showMsg('请输入姓名');
			return;
		}
		var mobile = $('#customerMobile').val();
		if(mobile.length < 1){
			showMsg('请输入电话');
			return;
		}
		if(checkTel(mobile)){
			showMsg('错误的电话号码');
			return;
		}
		var url = baseUrl + '/web/ssdb/saveFollowLog';
		var parameters = {'name':name,'mobile':mobile};
		postData(url, parameters, customerInfoSubmitSuccess, postDataDefaultErrorCallback);
	}
}

function customerInfoSubmitSuccess(data){
	if(data.success){
		isNotSubmit = false;
		var obj = $('#customerSubmit');
		obj.removeClass('btn-blue');
		obj.addClass('btn-brgrey');
		obj.text('已提交');
		showMsg('已提交，请耐心等待~');
	}else{
		showMsg(data.message);
	}
}

//下载统计错误回调
function downloadStatisticsErrorCallback(){
	downloadNotStart = true;
}

function gotoDownload(){
	if(downloadNotStart){
		downloadNotStart = false;
		clickStatistics(baseUrl,'Model_ssdb','Page_customer_service_download_wx',downloadStatisticsErrorCallback);
		window.location.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.falvshuo#rd';
		downloadNotStart = true;
	}else{
		showMsg('跳转中请稍候');
	}
}
