$(function(){
	$('#updateCallPhone').click(function(){
		var data = getFormData('callPhone_form');
		data.cancall = $('input[type="radio"]:checked').val();
        data.callphone = $('#callphone').attr('data');
		if( data.cancall){
			if(data.callphone==null || data.callphone==''){
				$('#tips_msg').text('请输入呼叫电话');
				showTips('orther_tips',false);
				return;
			}
			var phoneRe = /(^\d{3,4}-?\d{5,8}$)|(^(\d{2})?1[3|4|5|6|7|8|9]\d{9}$)/;
			if(!phoneRe.test(data.callphone)){
				$('#tips_msg').text('呼叫电话不合法，请重新输入');
				showTips('orther_tips',false);
				return;
			}
		}

		waiting();
		doPost(ctx+"/info/setphone?appId="+appId,data,false,function(result){	
			if(typeof result == "string"){
				result = eval('('+result+')');
			}
			if(result.error == 0){//绑定成功
				$('#ok_msg').text('设置成功');
				showTips('success_tips',true);
			}else{//其他提示 如校验错误
				$('#tips_msg').text(result.errormsg);
				showTips('orther_tips',false);
			}
			waitingStop();
		});
	});
	
	$('.backBtn').click(function(){
		waiting();
		window.history.go(-1);
	});

	$('#ok_tips_btn').click(function(){
		$(this).parent().hide();
		$('#div_tips').hide();
	});
	$('#orther_tips_btn').click(function(){
		$(this).parent().hide();
		$('#div_tips').hide();
	});
    $('#callphone').change(function () {
        var newValue = $(this).val();
        $(this).attr('data',newValue);
    });
});