//局部刷新 根据查询条件显示列表信息
function service(){
	var serviceType = $("#serviceType").val();
	var searchCriteria = $("#searchCriteria").val();
	var searchKeyWord = $("#searchKeyWord").val();
	var authcode = $.trim($("#authcode").val()); 
	if(searchCriteria=="0"){
		var regu = /^\d{12}$/;
		if(searchKeyWord==""){
			$("#errorMsg").addClass("littleiconno");
			$("#errorMsg").html("请输入正确的会员卡号");
			return false;
		}else if((searchKeyWord!="")&&(!regu.test(searchKeyWord))){
			$("#errorMsg").addClass("littleiconno");
			$("#errorMsg").html("请输入正确的会员卡号");
			return false;
		}
	}else if(searchCriteria=="1"){
		var regu = /^\d{10,12}$/;
		if(searchKeyWord==""){
			$("#errorMsg").addClass("littleiconno");
			$("#errorMsg").html("请输入正确的销售单号");
			return false;
		}else if((searchKeyWord!="")&&(!regu.test(searchKeyWord))){
			$("#errorMsg").addClass("littleiconno");
			$("#errorMsg").html("请输入正确的销售单号");
			return false;
		}
	}else if(searchCriteria=="2"){
		if(searchKeyWord==""){
			$("#errorMsg").addClass("littleiconno");
			$("#errorMsg").html("请输入正确的联系电话");
			return false;
		}else if(searchKeyWord!=""){
			if(searchKeyWord.charAt(0)=="1"){
				//手机验证
				var regu = /^1\d{10}$/;
				if(!regu.test(searchKeyWord)){
					$("#errorMsg").addClass("littleiconno");
					$("#errorMsg").html("请输入正确的联系电话");
					return false;
				}
			}else if(searchKeyWord.charAt(0)=="0"){
				//固话
				var regu1 = /^0\d{10,11}$/;
				var regu2 = /^00852\d{8}$/;
				if(searchKeyWord.substring(0,5)=="00852"){
					if(!regu2.test(searchKeyWord)){
						$("#errorMsg").addClass("littleiconno");
						$("#errorMsg").html("请输入正确的联系电话");
						return false;
					}else{
						searchCriteria = "3";
					}
				}else{
					if(!regu1.test(searchKeyWord)){
						$("#errorMsg").addClass("littleiconno");
						$("#errorMsg").html("请输入正确的联系电话");
						return false;
					}else{
						searchCriteria = "3";
					}
				}
			}else if(searchKeyWord.charAt(0)!="1"||searchKeyWord.charAt(0)!="0"){
				$("#errorMsg").addClass("littleiconno");
				$("#errorMsg").html("请输入正确的联系电话");
				return false;
			}
		}
	}
	if(authcode.length!=4){
		$("#yzmMsg").addClass("littleiconno");
		$("#yzmMsg").html("请输入正确的验证码");
		return false;
	}else if(authcode.length==4){
		$.ajax({url:"SNCheckAuthcodeView?authcode="+authcode,cache: false,async: false,success: function(data){
			if(data==1){
				//验证码输入错误
				$("#yzmMsg").addClass("littleiconno");
				$("#yzmMsg").html("验证码输入错误");
				return false;
			}else{
				$("#errorMsg").removeClass("littleiconno");
				$("#errorMsg").html("");
				$("#yzmMsg").removeClass("littleiconno");
				$("#yzmMsg").html("");
				$("#deliver-install-result").html("<div class='cardloading'></div>");
				var url;
				var div;
				if(serviceType=="complainService"){
					//咨询/投诉
					url = "SNComplainServiceListView?searchCriteria="+searchCriteria+"&searchKeyWord="+searchKeyWord+"&operate=refresh";
					div = "complainServiceList";
				}else if(serviceType=="repairService"){
					//维修/其他
					url = "SNRepairServiceListView?searchCriteria="+searchCriteria+"&searchKeyWord="+searchKeyWord+"&operate=refresh";
					div = "repairServiceList";
				}else if(serviceType=="distributionService"){
					//送货/安装
					url = "SNDistributionServiceListView?searchCriteria="+searchCriteria+"&searchKeyWord="+searchKeyWord+"&operate=refresh";
					div = "distributionServiceList";
				}
				//必须调用see(),用于重复加载列表中的js信息。此函数在service.js中定义
				$.ajax({url:url,cache: false,async: true,success: function(data){$("#"+div).html(data);see();}}); 
			}
		}}); 
	}
}

function searchDeliver(){
	var searchCriteria = $("#searchCriteria").val();
	var authcode = $.trim($("#authcode").val()); 
	var keyWord,searchKeyWord,searchKeyWord1,searchKeyWord2;

	if(searchCriteria=="0"){
		searchKeyWord = $("#searchKeyWord").val();
		var regu = /^\d{12}$/;
		if(searchKeyWord==""){
			$("#errorMsg").addClass("littleiconno");
			$("#errorMsg").html("请输入正确的会员卡号");
			return false;
		}else if((searchKeyWord!="")&&(!regu.test(searchKeyWord))){
			$("#errorMsg").addClass("littleiconno");
			$("#errorMsg").html("请输入正确的会员卡号");
			return false;
		}
		$("#errorMsg").removeClass("littleiconno");
		$("#errorMsg").html("");
		keyWord='&searchKeyWord='+searchKeyWord;
	}else if(searchCriteria=="1"){
		searchKeyWord1 = $("#searchKeyWord1").val();
		searchKeyWord2 = $("#searchKeyWord2").val();
		var regu = /^\d{10,12}$/;
		if(searchKeyWord1==""){
			$("#errorMsg").addClass("littleiconno");
			$("#errorMsg").html("请输入正确的销售单号");
			return false;
		}else if((searchKeyWord1!="")&&(!regu.test(searchKeyWord1))){
			$("#errorMsg1").addClass("littleiconno");
			$("#errorMsg1").html("请输入正确的销售单号");
			return false;
		}
		$("#errorMsg1").removeClass("littleiconno");
		$("#errorMsg1").html("");
		
		if(searchKeyWord2==""){
			$("#errorMsg2").addClass("littleiconno");
			$("#errorMsg2").html("请输入正确的联系电话");
			return false;
		}else if(searchKeyWord2!=""){
			if(searchKeyWord2.charAt(0)=="1"){
				//手机验证
				var regu = /^1\d{10}$/;
				if(!regu.test(searchKeyWord2)){
					$("#errorMsg2").addClass("littleiconno");
					$("#errorMsg2").html("请输入正确的联系电话");
					return false;
				}
			}else if(searchKeyWord2.charAt(0)=="0"){
				//固话
				var regu1 = /^0\d{10,11}$/;
				var regu2 = /^00852\d{8}$/;
				if(searchKeyWord2.substring(0,5)=="00852"){
					if(!regu2.test(searchKeyWord2)){
						$("#errorMsg2").addClass("littleiconno");
						$("#errorMsg2").html("请输入正确的联系电话");
						return false;
					}else{
						searchCriteria = "3";
					}
				}else{
					if(!regu1.test(searchKeyWord2)){
						$("#errorMsg2").addClass("littleiconno");
						$("#errorMsg2").html("请输入正确的联系电话");
						return false;
					}else{
						searchCriteria = "3";
					}
				}
			}else if(searchKeyWord2.charAt(0)!="1"||searchKeyWord2.charAt(0)!="0"){
				$("#errorMsg2").addClass("littleiconno");
				$("#errorMsg2").html("请输入正确的联系电话");
				return false;
			}
		}
		$("#errorMsg2").removeClass("littleiconno");
		$("#errorMsg2").html("");
		keyWord='&searchKeyWord1='+searchKeyWord1+'&searchKeyWord2='+searchKeyWord2;
	}
	if(authcode.length!=4){
		$("#yzmMsg").addClass("littleiconno");
		$("#yzmMsg").html("请输入正确的验证码");
		return false;
	}else if(authcode.length==4){
		$.ajax({url:"SNCheckAuthcodeView?authcode="+authcode,cache: false,async: false,success: function(data){
			if(data==1){
				//验证码输入错误
				$("#yzmMsg").addClass("littleiconno");
				$("#yzmMsg").html("验证码输入错误");
				return false;
			}else{
				$("#errorMsg").removeClass("littleiconno");
				$("#errorMsg").html("");
				$("#yzmMsg").removeClass("littleiconno");
				$("#yzmMsg").html("");
				$("#deliver-install-result").html("<div class='cardloading'></div>");
				var url;
				var div;
				
					//送货/安装
				url = "SNDistributionServiceListView?searchCriteria="+searchCriteria+keyWord+"&operate=refresh";
				div = "distributionServiceList";
				//必须调用see(),用于重复加载列表中的js信息。此函数在service.js中定义
				$.ajax({url:url,cache: false,async: true,success: function(data){$("#"+div).html(data);see();}}); 
			}
		}}); 
	}
}

//分页显示调用入口
function showPaging(pageIndex,pageCount,totalPages,totalCount){
	var serviceType = $("#serviceType").val();
	if(serviceType=='complainService'){
		complainServicePaging(pageIndex,pageCount,totalPages,totalCount);
	}else if(serviceType=='repairService'){
		reairServicePaging(pageIndex,pageCount,totalPages,totalCount);
	}else if(serviceType=='distributionService'){
		distributionServicePaging(pageIndex,pageCount,totalPages,totalCount);
	}	
}

//重构咨询/投诉列表信息分页
function complainServicePaging(pageIndex,pageCount,totalPages,totalCount){
	var up;
	var down;
	if(pageIndex==1){
		up = "<a href='#'>上一页</a>";
	}else{
		up = "<a href='javascript:showPaging("+(pageIndex-1)+","+pageCount+","+totalPages+","+totalCount+")';>上一页</a>";
	}
	if(pageIndex==totalPages){
		down = "<a href='#'>下一页</a>";
	}else{
		down = "<a href='javascript:showPaging("+(pageIndex+1)+","+pageCount+","+totalPages+","+totalCount+")';>下一页</a>";
	}
	//重构页面列表信息
	var htmlDiv = "<div>咨询/投诉查询结果:<div>"+
		up+"&nbsp;<span class='fontColorLight-blue'>"+pageIndex+"</span>/<span>"+totalPages+"</span>&nbsp;"+down+"</div></div>"+
		"<table cellpadding='0' cellspacing='0' border='0'>"+
		"<tr class='bgLight-blue'><th width='123'>工单号</th><th width='90'>工单类型</th><th width='282'>提交问题</th><th width='101'>提交时间</th><th width='81'>处理状态</th><th width='121' class='border-right'>操作</th></tr>";
	var start = (pageIndex-1)*pageCount+1;
	var end = start+pageCount;
	for(var i=1;i<=totalCount;i++){
		var listTemp = $("#list"+i).html();
		var contentTemp = $("#content"+i).html();
		var listInfo;
		var contentInfo;
		if(i>=start&&i<end){
			listInfo = "<tr class='list' style='display: block;' id='list"+i+"'>"+listTemp+"</tr>";
			contentInfo = "<tr class='content' id='content"+i+"'>"+contentTemp+"</tr>";
		}else{
			listInfo = "<tr class='list' style='display: none;' id='list"+i+"'>"+listTemp+"</tr>";
			contentInfo = "<tr class='content' id='content"+i+"'>"+contentTemp+"</tr>";
		}
		htmlDiv = htmlDiv+listInfo+contentInfo;
	}
	htmlDiv = htmlDiv+"</table>";
	$("#deliver-install-result").html(htmlDiv);
	rebuildPagingNumber(pageIndex,pageCount,totalPages,totalCount);
}

//重构维修/其他列表信息分页
function reairServicePaging(pageIndex,pageCount,totalPages,totalCount){
	var up;
	var down;
	if(pageIndex==1){
		up = "<a href='#'>上一页</a>";
	}else{
		up = "<a href='javascript:showPaging("+(pageIndex-1)+","+pageCount+","+totalPages+","+totalCount+")';>上一页</a>";
	}
	if(pageIndex==totalPages){
		down = "<a href='#'>下一页</a>";
	}else{
		down = "<a href='javascript:showPaging("+(pageIndex+1)+","+pageCount+","+totalPages+","+totalCount+")';>下一页</a>";
	}
	//重构页面列表信息
	var htmlDiv = "<div>维修/其他查询结果:<div>"+
		up+"&nbsp;<span class='fontColorLight-blue'>"+pageIndex+"</span>/<span>"+totalPages+"</span>&nbsp;"+down+"</div></div>"+
		"<table cellpadding='0' cellspacing='0' border='0'>"+
		"<tr class='bgLight-blue'><th width='142'>服务单号</th><th width='264'>商品</th><th width='108'>数量</th><th width='122'>服务日期</th><th width='162' class='border-right'>操作</th></tr>";
	var start = (pageIndex-1)*pageCount+1;
	var end = start+pageCount;
	for(var i=1;i<=totalCount;i++){
		var listTemp = $("#list"+i).html();
		var contentTemp = $("#content"+i).html();
		var listInfo;
		var contentInfo;
		if(i>=start&&i<end){
			listInfo = "<tr class='list' style='display: block;' id='list"+i+"'>"+listTemp+"</tr>";
			contentInfo = "<tr class='content' id='content"+i+"'>"+contentTemp+"</tr>";
		}else{
			listInfo = "<tr class='list' style='display: none;' id='list"+i+"'>"+listTemp+"</tr>";
			contentInfo = "<tr class='content' id='content"+i+"'>"+contentTemp+"</tr>";
		}
		htmlDiv = htmlDiv+listInfo+contentInfo;
	}
	htmlDiv = htmlDiv+"</table>";
	$("#deliver-install-result").html(htmlDiv);
	rebuildPagingNumber(pageIndex,pageCount,totalPages,totalCount);
}	

//重构送货/安装列表信息分页
function distributionServicePaging(pageIndex,pageCount,totalPages,totalCount){
	var up;
	var down;
	if(pageIndex==1){
		up = "<a href='#'>上一页</a>";
	}else{
		up = "<a href='javascript:showPaging("+(pageIndex-1)+","+pageCount+","+totalPages+","+totalCount+")';>上一页</a>";
	}
	if(pageIndex==totalPages){
		down = "<a href='#'>下一页</a>";
	}else{
		down = "<a href='javascript:showPaging("+(pageIndex+1)+","+pageCount+","+totalPages+","+totalCount+")';>下一页</a>";
	}
	var htmlDiv = "<div>送货/安装查询结果:<div>"+
		up+"&nbsp;<span class='fontColorLight-blue'>"+pageIndex+"</span>/<span>"+totalPages+"</span>&nbsp;"+down+"</div></div>"+
		"<table cellpadding='0' cellspacing='0' border='0'>"+
		"<tr class='bgLight-blue'><th width='101'>销售单号</th><th width='251'>商品</th><th width='99'>数量</th><th width='98'>销售日期</th><th width='104'>配送方式</th><th width='145' class='border-right'>操作</th></tr>";
	var start = (pageIndex-1)*pageCount+1;
	var end = start+pageCount;
	for(var i=1;i<=totalCount;i++){
		var listTemp = $("#list"+i).html();
		var listInfo;
		var contentInfo;
		var distributionViewId = $("#content"+i).attr("title");
		if(i>=start&&i<end){
			listInfo = "<tr class='list' style='display: block;' id='list"+i+"'>"+listTemp+"</tr>";
			contentInfo = "<tr class='content' title='"+distributionViewId+"' id='content"+i+"'><td colspan='6' id="+distributionViewId+" class='bgLight-yellow'><div class='status space-tb' id='"+distributionViewId+"'></div></td></tr>";
		}else{
			listInfo = "<tr class='list' style='display: none;' id='list"+i+"'>"+listTemp+"</tr>";
			contentInfo = "<tr class='content' title='"+distributionViewId+"' id='content"+i+"'><td colspan='6' id="+distributionViewId+" class='bgLight-yellow'><div class='status space-tb' id='"+distributionViewId+"'></div></td></tr>";
		}
		htmlDiv = htmlDiv+listInfo+contentInfo;
	}
	htmlDiv = htmlDiv+"</table>";
	$("#deliver-install-result").html(htmlDiv);
	rebuildPagingNumber(pageIndex,pageCount,totalPages,totalCount);
}

//重构分页代码
function rebuildPagingNumber(pageIndex,pageCount,totalPages,totalCount){
	var pagingHtml = "";
	if(pageIndex==1){
		pagingHtml = pagingHtml+"<a href='#' class='none'>首页</a><a href='#' class='none'>&lt;&lt;上一页</a>";
	}else{
		pagingHtml = pagingHtml+"<a href='javascript:showPaging(1,"+pageCount+","+totalPages+","+totalCount+");' class='none'>首页</a><a href='javascript:showPaging("+(pageIndex-1)+","+pageCount+","+totalPages+","+totalCount+");' class='none'>&lt;&lt;上一页</a>";
	}	
	if(totalPages<=5){
		for(var i =1;i<=totalPages;i++){
			if(pageIndex==i){
				pagingHtml = pagingHtml+"<a href='#' class='on'>"+pageIndex+"</a>";
			}else{
				pagingHtml = pagingHtml+"<a href='javascript:showPaging("+i+","+pageCount+","+totalPages+","+totalCount+");'>["+i+"]</a>";
			}
		}
	}else if(totalPages>5){
		if(pageIndex<=3){
			for(var i=1;i<=5;i++){
				if(pageIndex==i){
					pagingHtml = pagingHtml+"<a href='#' class='on'>"+pageIndex+"</a>";
				}else{
					pagingHtml = pagingHtml+"<a href='javascript:showPaging("+i+","+pageCount+","+totalPages+","+totalCount+");'>["+i+"]</a>";
				}
			}
		}else if(pageIndex>=totalPages-2){
			for(var i=totalPages-4;i<=totalPages;i++){
				if(pageIndex==i){
					pagingHtml = pagingHtml+"<a href='#' class='on'>"+pageIndex+"</a>";
				}else{
					pagingHtml = pagingHtml+"<a href='javascript:showPaging("+i+","+pageCount+","+totalPages+","+totalCount+");'>["+i+"]</a>";
				}
			}
		}else{
			for(var i=pageIndex-2;i<=pageIndex+2;i++){
				if(pageIndex==i){
					pagingHtml = pagingHtml+"<a href='#' class='on'>"+pageIndex+"</a>";
				}else{
					pagingHtml = pagingHtml+"<a href='javascript:showPaging("+i+","+pageCount+","+totalPages+","+totalCount+");'>["+i+"]</a>";
				}
			}
		}
	}
	if(pageIndex==totalPages){
		pagingHtml = pagingHtml+"<a href='#' class='none'>下一页&gt;&gt;</a><a href='#' class='none'>尾页</a>";
	}else{
		pagingHtml = pagingHtml+"<a href='javascript:showPaging("+(pageIndex+1)+","+pageCount+","+totalPages+","+totalCount+");' class='none'>下一页&gt;&gt;</a><a href='javascript:showPaging("+totalPages+","+pageCount+","+totalPages+","+totalCount+");' class='none'>尾页</a>";
	}
	$("#paging").html(pagingHtml);	
	//必须调用see(),用于重复加载列表中的js信息。此函数在service.js中定义
	see();
}	

//常见问题 局部刷新
function answerforServiceCenter(questionId){
	toPageNoBlock("SNServiceCenterAnswerView?questionId="+questionId,"faq-text");
}

//获取验证码
function fun_getVcode(imageUrl){
	var timenow = new Date().getTime();
	document.getElementById("vcodeimg1").src =  imageUrl+"?test=" +timenow;
}
