
var kepiao = 5;//客票销售服务费	
//var deliverWho = '';//选择的是哪一种配送方式 today......
var chaxun_url = $("#chaxun_url").val();//提示网址
var warn_time = $("#warn_time").val();//提示时间
var isDeliverValidate = false;

$(document).ready(function(){
	if($("#f_alert").val()!=""){
		alert($("#f_alert").val());
	}
		
	idenVal();//初始化身份证信息
	var trainNumber = $("#train_number").val();
	var areaId = $(".alist:checked").attr("area_id");//取第一次进入页面的area_id
	var dateTime = $("#ticket_datetime").val();//出发时间
	var fromStationId = $("#from_station_id").val();//出发站ID
	//alert("areaId:"+areaId+"|trainNumber:"+trainNumber+"|fromStationId:" +fromStationId);
	var url = "/backorder/buyajax2.php?action=deliver";
//	if(areaId!=0){
//		$("#deliver_l").load(url, {area_id:areaId, from_station_time:dateTime,train_number:trainNumber,warn_time:warn_time,chaxun_url:chaxun_url,from_station_id:fromStationId},function(){
//			if($(".deliver_list").length==1){
//				 $(".deliver_list").click();
//				 sumP();
//			 }
//		});
//	}
	
	//变换地址
	$(".alist").live("click", function(){
	
	//$(".alist").click(function(){
		var clickAreaId = $(this).attr("area_id");//取选中的单选按钮的area_id
		var trainNumber = $("#train_number").val();
		var dateTime = $("#ticket_datetime").val();//出发时间
		var fromStationId = $("#from_station_id").val();//出发站ID
		//alert("areaId:"+areaId+"|trainNumber:"+trainNumber+"|fromStationId:" +fromStationId);
		if(clickAreaId!=0){
			areaId = clickAreaId;
			$("#deliver_l").load(url, {area_id:clickAreaId, from_station_time:dateTime,train_number:trainNumber,warn_time:warn_time,chaxun_url:chaxun_url, from_station_id:fromStationId},function(){
				if($(".deliver_list").length==1){
					 $(".deliver_list").click();
					 sumP();
				 }
			});
			
			$("#tarea").hide();
		}
	});
	

	//如果重新填写地址
	$("#street").change(function(){
		var optionAreaId = $(this).val();
		var clickAreaId = $(this).attr("area_id");//取选中的单选按钮的area_id
		var trainNumber = $("#train_number").val();
		var dateTime = $("#ticket_datetime").val();//出发时间
		var fromStationId = $("#from_station_id").val();//出发站ID
		if(optionAreaId!=areaId){
			areaId = optionAreaId;
			$("#deliver_l").load(url,{area_id:optionAreaId, from_station_time:dateTime,train_number:trainNumber,warn_time:warn_time,chaxun_url:chaxun_url,from_station_id:fromStationId},function(){
				if($(".deliver_list").length==1){
					 $(".deliver_list").click();
					 sumP();
				 }
			});
			
		}
	});
});

//是否点击过选择不选择按钮
var isOtherSelection = false;
$(document).ready(function(){
//提交时通过ajax查询
	$(".yesbuy").click(function(){
		cruiseData(6);		
		
		//判断是否选择送票地址
		var addressMan = $(".alist");
		var addressSelectFlag = false;
		for(var a=0; a < addressMan.length; a++){
			if(addressMan.get(a).checked){
				addressSelectFlag = true;
				break;
			}
		}
		if(!addressSelectFlag){
			$("#valinow").html("请选择送票地址");
			return false;
		}
		
		//选择了座位票的，必须接无座	把这一段注释就行 end
		//$("#valinow").html("正在验证...<img src='media/image/loading.gif' />");

		var addressId = $(".alist:checked").val();
		var tkt_id = $("#ticket_id").val();
		var tNumber = $("#tnum").val();
		var pmt_id = $("#alipay").val();
		var buydate = $("#buydate").val();
		var cusmsg = $("#leavemes").val();
		var check_num = $("#checknum").val();
		var informed = $("#informed").val();
		var  seat_id = $("#seat_id").val();
		//var pay_type = $(this).attr("name");
		//var pay_type = $("input[@name=payer][checked]").val();
		
		if(!seat_id){
			$("#valinow").html("");
			//$(".zuoxi").text("请选择坐席");
			var errMsg = $("<div class=\"buyTishi4\"><div class=\"buyTishi4_r\"><p>请选择坐席</p></div><b></b></div>");	
			$(".f_buy_seat").prepend(errMsg);
			$("#seat_price").focus();
			moveFocusUp("#seat_price");
			return false;
		}else{
			var errDiv = $(".f_buy_seat").find(".buyTishi4");
			errDiv.remove();
			
		}
		if(!tNumber){
			$("#valinow").html("请填写数量！");
			return false;
		}
		//身份证验证
		var user_identity = '';
		var user_identity_insert = '';
		if( $("#uCheci").val() == "D" || $("#uCheci").val() == "G" || $("#uCheci").val() == "C"){
			var idenSelectFlag = true;
			var idNumberFlag = true;
			var idNumberFl = true;
			for(var i=0; i<tNumber; i++){
			    //(!(/(^\[a-zA-Z0-9]+$)/.test($("#idNumber"+i).val())))   
				if($("#idName"+i).val() == '' || $("#idSort"+i).val() == '' || !(/^[a-zA-Z0-9]+$/.test($("#idNumber"+i).val())) ){
					idenSelectFlag = false;
					$("#f_idinform"+i).show();
					$("#idinform"+i).html("请填写证件姓名或者号码");
					$("#idName"+i).focus();
					moveFocusUp("#idName"+i);
					break;
				}
			   if (($("#idSort"+i).val()) == "身份证")//身份证号码15位或18位
				{
					if(($("#idNumber"+i).val().length != '15' && $("#idNumber"+i).val().length != '18') || !checkIdcard($("#idNumber"+i).val()) ){
					idNumberFlag = false;
					$("#f_idinform"+i).show();
					$("#idinform"+i).html("请填写正确的身份证号码");
					$("#idNumber"+i).focus();
					moveFocusUp("#idNumber"+i);
			    	break;
					}
				}
				for (var j=0;j<i ;j++ )//判断是否重复输入证件号码
				{
					if(($("#idNumber"+j).val()) == ($("#idNumber"+i).val()))
					{
						idNumberFl = false;
						$("#f_idinform"+j).show();
						$("#idinform"+j).html("证件号码已存在，请重新填写");
						$("#idNumber"+j).focus();
						moveFocusUp("#idNumber"+j);
						break;
					}
				}				
				
				user_identity += $("#idName"+i).val()+',';
				user_identity += $("#idSort"+i).val()+',';
				user_identity += $("#idNumber"+i).val();
				if(i != tNumber-1){
					user_identity += '|';
				}
				if($("#idShenfen"+i).val() == ''){
					user_identity_insert += $("#idName"+i).val()+',';
					user_identity_insert += $("#idSort"+i).val()+',';
					user_identity_insert += $("#idNumber"+i).val();
					user_identity_insert += '|';
				}
				
					
				
			}
			if(user_identity_insert.indexOf('|') != -1){
			  user_identity_insert	= user_identity_insert.substring(0,user_identity_insert.length-1);
			}

            //票价身份信息 user_identity_insert
            
			if(!idenSelectFlag){
				//$("#valinow").html("请填写证件姓名或者号码");
				return false;
			}
			if(!idNumberFlag){
				//$("#valinow").html("请填写正确的身份证号码");
				return false;
			}

			if(!idNumberFl){
				//$("#valinow").html("证件号码已存在，请重新填写");
				return false;
			}
			
		}
		
		
		//身份证验证结束
		//首先判断是否选择了支付方式
		var paymethod = $(".paymethod");
		var paySelectFlag = false;
		for(var a=0; a < paymethod.length; a++){
			if(paymethod.get(a).checked){
				paySelectFlag = true;
				break;
			}
		}
		if(!paySelectFlag){
			$("#ticket_address").css("border", " solid 0px;");	
			$("#errmesage").text("");
			$("#valinow").html("请选择支付方式");
			return false;
		}
		var pay_type = $(".paymethod").filter(":radio[checked]").val();
		var acceptSeat = $("#accept_seat").val();
		var fromStationTime = $("#from_station_time").val();
		
	
		//列车信息
		var traindetailinfo = $("#traindetailinfo").text();
		//地址信息
		var addressdetailinfoid = $(".alist").filter(":radio[checked]").attr("id");
		
		var addressdetailinfo = $("label[for="+addressdetailinfoid+"]").text();
		
		if (""!==addressId) {
			//身份证表
//			if(user_identity_insert != ''){
//				$.post("/backorder/identity.php", 
//					{user_identity:user_identity_insert},	
//				function(data){
//						//alert(data.mes);
//					//$("#valinow").html(data.mes);
//					
//				}, "json");
//				
//			}
			//首先判断是否选择了配送方式
			var deliverMan = $(".deliver_list");
			var deliverSelectFlag = false;
			for(var a=0; a < deliverMan.length; a++){
				if(deliverMan.get(a).checked){
					deliverSelectFlag = true;
					break;
				}
			}
			if(!deliverSelectFlag){
				var errMsg = $("<div class=\"buyTishi4\"><div class=\"buyTishi4_r\"><p>请选择配送方式</p></div><b></b></div>");	
				$(".deliver_list").eq(0).parents("div").prepend(errMsg);
				$(".deliver_list").eq(0).focus();
				//$("#valinow").html("请选择配送方式");
				return false;
			}else{
				var errDiv = $(".deliver_list").parents("div").find(".buyTishi4");
				errDiv.remove();
			}
			
			if( $("#uCheci").val() == "D" || $("#uCheci").val() == "G"){
				var str = "<ul class=\"ul2\" >";
				for(var i=0; i<tNumber; i++){
					str += "<li><label>"+$("#idName"+i).val()+"("+$("#idSort"+i).val()+")</label><span>"+$("#idNumber"+i).val()+"</span></li>";
				}
				str+="</ul>";
				$("#f_id_info").html(str);
			}
			 
			$("#f_accept_li").html($("#accept_seat1").html());
			$("#f_buy_num").html($("#tnum").val()+"张");
			$("#f_seat_name").html($("#seat_name").html());
			$("#f_send_area").html("送票区域："+$("label[for="+addressdetailinfoid+"]").attr("area"));
			$("#f_send_address").html("送票地址："+$("label[for="+addressdetailinfoid+"]").attr("address"));
			$("#f_contact").html("联系人："+$("label[for="+addressdetailinfoid+"]").attr("name")+"&nbsp;&nbsp;&nbsp;&nbsp;联系电话："+$("label[for="+addressdetailinfoid+"]").attr("mobile"));
			$("#queren_box").show();
			
			//输出列车信息，地址信息让用户确认
			/*if(!confirm("              请再次确认信息（非常重要）\n\n"+"列车信息："+traindetailinfo+"\n"+"地址信息："+addressdetailinfo)){
				$("#valinow").html("");
				return false;
			}
			
			$("#valinow").html("正在生成订单信息...");
			$("#yesbuy").attr("disabled", true);
			alert("address_id="+addressId+" deliver_list="+deliverWho+"  ticket_id="+tkt_id+" ticket_num="+tNumber+"\nbuydate="+buydate+" payment_id="+pmt_id+" checknum="+check_num+" memo="+cusmsg+" informed="+informed+" accept_seat="+acceptSeat+"  from_station_time="+fromStationTime);
			$.post("/backorder/buyajax2.php?action=order", 
				{address_id:addressId,
				deliver_list:deliverWho,
				ticket_id:tkt_id,
				ticket_num:tNumber,
				date:buydate,
				payment_id:pmt_id,
				checknum:check_num,
				memo:cusmsg,
				informed:informed,
				accept_seat:acceptSeat,
				user_identity:user_identity,
				from_station_time:fromStationTime},
			function(data){
				
				if(data.tag==="e"){
					$("#valinow").html(data.mes);
					$("#validateimage").attr("src", "validateimage.php?t="+Math.random());
				}else if(data.tag==="orderid"){
					
					//设置生成的订单号
					$("#order_id").val(data.mes);
					try{send_pay(data.mes);}catch(e){};//add by rwx 2011-07-26
					$("#valinow").html("生成订单成功，正在跳转到支付平台，请稍候...<img src='media/image/loading.gif' />。");
					$("#errmesage").html("");//错误信息清空
					$("#go_pay").attr("action", "http://www.99pto.com/pay.php?payType="+pay_type);
					//$("form").submit();
					$("#go_pay").submit();
				}else if(data.tag==="err"){
					$("#valinow").html(data.mes);
					$("#validateimage").attr("src", "validateimage.php?t="+Math.random());
				}
				$("#yesbuy").attr("disabled", false);
			},"json");
			*/
			
		} else {
			var rname = $("#realName").val();
			//地址ID
			var cityid = $("#city").val();
			var districtid = $("#district").val();
			var streetid = $("#street").val();
			
			var streetxplct = $("#streetexplicit").val();
			var mbl = $("#moblie").val();
			if(!rname){
				var errMsg = $("<div class=\"buyTishi2\"><b></b><div class=\"buyTishi2_r\"><p>请输入收票人姓名</p></div></div>");	
				$("#realName").after(errMsg);
				$("#realName").focus();
				moveFocusUp("#realName");
				//$("#valinow").html("请输入收票人姓名！");
				return;
			}else{	
				var errDiv = $("#realName").parents("div").find(".buyTishi2");
				errDiv.remove();
			}
			
//			
//			if(!streetid){
//				var errMsg = $("<div class=\"buyTishi3\"><b></b><div class=\"buyTishi3_r\"><p>街道不能为空</p></div></div>");	
//				$("#street").after(errMsg);
//				$("#street").focus();
//				moveFocusUp("#street");
//				return;
//			}else{	
//				var errDiv = $("#street").parents("div").find(".buyTishi3");
//				errDiv.remove();
//			}
			
			if (!streetxplct) {
				var errMsg = $("<div class=\"buyTishi3\"><b></b><div class=\"buyTishi3_r\"><p>请把收票地址信息填写完整</p></div></div>");	
				
				//$("#valinow").html("请把收票地址信息填写完整！");
				$("#streetexplicit").focus();
				$("#streetexplicit").after(errMsg);
				moveFocusUp("#streetexplicit");
				return;
			}else{
				var errDiv = $("#streetexplicit").parents("div").find(".buyTishi3");
				errDiv.remove();
				//$("#valinow").html("");
			}
			
			if(/^\d{11}$/.test(mbl) === false ){
				var errMsg = $("<div class=\"buyTishi2\"><b></b><div class=\"buyTishi2_r\"><p>请填写正确的手机号。11位数字</p></div></div>");	
				$("#moblie").after(errMsg);
				$("#moblie").focus();
				moveFocusUp("#moblie");
				//$("#valinow").html("请填写正确的手机号。11位数字");
				return ;
			}else{
				var errDiv = $("#moblie").parents("div").find(".buyTishi2");
				errDiv.remove();
				$("#valinow").html("");
			}
			
			//首先判断是否选择了配送方式
			var deliverMan = $(".deliver_list");
			var deliverSelectFlag = false;
			for(var a=0; a < deliverMan.length; a++){
				if(deliverMan.get(a).checked){
					deliverSelectFlag = true;
					break;
				}
			}
			if(!deliverSelectFlag){
				var errMsg = $("<div class=\"buyTishi4\"><div class=\"buyTishi4_r\"><p>请选择配送方式</p></div><b></b></div>");	
				$(".deliver_list").eq(0).parents("div").prepend(errMsg);
				$(".deliver_list").eq(0).focus();
				//$("#valinow").html("请选择配送方式");
				return false;
			}else{
				var errDiv = $(".deliver_list").parents("div").find(".buyTishi4");
				errDiv.remove();
			}
			
			var telephone = ($("#tel1").val() && $("#tel2").val()) ? $("#tel1").val()+"-"+$("#tel2").val()+"-"+$("#tel3").val() : "";
			var provinceInfo = $("#province").find("option[selected]").text();
			var cityInfo = $("#city").find("option[selected]").text();
			var districtInfo = $("#district").find("option[selected]").text();
			var streetInfo = $("#street").find("option[selected]").text();
			var streetexplicitInfo = $("#streetexplicit").val();
			var addressdetailinfo = rname + " " + provinceInfo + cityInfo + districtInfo + streetInfo + streetexplicitInfo;
			
			//alert(addressdetailinfo);
			
			//输出列车信息，地址信息让用户确认
//			if(!confirm("              请再次确认信息（非常重要）\n\n"+"列车信息："
//							+traindetailinfo+"\n"+"地址信息："+addressdetailinfo+"\n"
//							+"电话："+mbl+"    "+telephone)){
//				$("#valinow").html("");
//				return false;
//			}
			
			if( $("#uCheci").val() == "D" || $("#uCheci").val() == "G"){
				var str = "<ul class=\"ul2\" >";
				for(var i=0; i<tNumber; i++){
					str += "<li><label>"+$("#idName"+i).val()+"("+$("#idSort"+i).val()+")</label><span>"+$("#idNumber"+i).val()+"</span></li>";
				}
				str+="</ul>";
				$("#f_id_info").html(str);
			}
			 
			$("#f_accept_li").html($("#accept_seat1").html());
			$("#f_buy_num").html($("#tnum").val());
			$("#f_seat_name").html($("#seat_name").html());
			$("#f_send_area").html("送票区域："+ provinceInfo + cityInfo + districtInfo + streetInfo);
			$("#f_send_address").html("送票地址："+streetexplicitInfo);
			$("#f_contact").html($("label[for="+addressdetailinfoid+"]").attr("name"));
			$("#f_contact").html("联系人："+rname+"&nbsp;&nbsp;&nbsp;&nbsp;联系电话："+mbl);
			$("#queren_box").show();
//			
//			$("#valinow").html("正在验证信息...");
//			$("#yesbuy").attr("disabled", true);
//			$.post("/backorder/buyajax2.php?action=address", 
//						{date:buydate,
//						street:streetid,
//						realName:rname,
//						streetexplicit:streetxplct,
//						mobile:mbl,
//						tel:telephone,
//						checknum:check_num},
//				function(data){
//					if(data.tag==="e"){
//						$("#valinow").html("");
//						$("#login_str").html(data.mes);
//						$("#reg_login").show();
//						//$("#validateimage").attr("src", "validateimage.php?t="+Math.random());
//					}else if (data.tag==="addressid") {
//						//身份证表 
//						if(user_identity_insert != ''){
//							$.post("/backorder/identity.php", 
//								{user_identity:user_identity_insert},	
//							function(data){
//									//alert(data.mes);
//								//$("#valinow").html(data.mes);
//								
//							}, "json");
//							
//						}
//						$("#address_id").val(data.mes);
//						if( $("#uCheci").val() == "D" || $("#uCheci").val() == "G"){
//							var str = "<dt>身份信息</dt><dd><ul class=\"ul2\" >";
//							for(var i=0; i<tNumber; i++){
//								str += "<li><label>"+$("#idName"+i).val()+"("+$("#idSort"+i).val()+")</label><span>"+$("#idNumber"+i).val()+"</span></li>";
//							}
//							str+="</ul></dd>";
//							$("#f_id_info").html(str);
//						}
//						
//						$("#f_buy_num").html($("#tnum").val());
//						$("#f_seat_name").html($("#seat_name").html());
//						$("#f_send_area").html("送票区域："+ provinceInfo + cityInfo + districtInfo + streetInfo);
//						$("#f_send_address").html("送票地址："+streetexplicitInfo);
//						$("#f_contact").html($("label[for="+addressdetailinfoid+"]").attr("name"));
//						$("#f_contact").html("联系人："+rname+"&nbsp;&nbsp;&nbsp;&nbsp;联系电话："+mbl);
//						$("#queren_box").show();
//						/*
//						$.post("/backorder/buyajax2.php?action=order", 
//								{address_id:data.mes,
//								deliver_list:deliverWho,
//								ticket_id:tkt_id,
//								ticket_num:tNumber,
//								date:buydate,
//								payment_id:pmt_id,
//								checknum:check_num,
//								memo:cusmsg,
//								accept_seat:acceptSeat,
//								user_identity:user_identity,
//								from_station_time:fromStationTime},
//							function(odata){
//								if(odata.tag==="e"){
//									$("#valinow").html(odata.mes);
//									
//									$("#validateimage").attr("src", "validateimage.php?t="+Math.random());
//								}else if (odata.tag==="orderid") {
//									//设置生成的订单号
//									$("#order_id").val(odata.mes);
//									try{send_pay(odata.mes);}catch(e){};//add by rwx 2011-07-26
//									$("#valinow").html("生成订单成功，正在跳转到支付平台，请稍候...<img src='media/image/loading.gif' />。");
//									$("#errmesage").html("");//错误信息清空
//									$("#go_pay").attr("action", "http://www.99pto.com/pay.php?payType="+pay_type);
//									//$("form").submit();
//									$("#go_pay").submit();
//								}else if(odata.tag==="err"){
//									$("#valinow").html(odata.mes);
//								}
//								//把按钮打开
//								$("#yesbuy").attr("disabled", false);
//						}, "json");
//						*/
//					}else if(data.tag==="err"){
//						$("#valinow").html(data.mes);
//						
//						$("#validateimage").attr("src", "validateimage.php?t="+Math.random());
//					}
//					//把按钮打开
//					$("#yesbuy").attr("disabled", false);
//				}, "json");
		}
		
		
//		$("#valinow").ajaxError(function(event, request, settings){
//			$(this).html("<li>出错页面:" + settings.url + "</li>");
//			 //$(this).html("页面错误，请刷新页面！");
//			 $("#validateimage").attr("src", "validateimage.php?t="+Math.random());
//			//把按钮打开
//			$("#yesbuy").attr("disabled", false);
//		});
	});	
});


$(document).ready(function(){
	$("#f_confirm_submit").live("click", function(){
		 var provinceInfo = $("#province").find("option[selected]").text();
		var cityInfo = $("#city").find("option[selected]").text();
		var districtInfo = $("#district").find("option[selected]").text();
		var streetInfo = $("#street").find("option[selected]").text();
		var streetexplicitInfo = $("#streetexplicit").val();
		//var addressdetailinfo = rname + " " + provinceInfo + cityInfo + districtInfo + streetInfo + streetexplicitInfo;
			
		//debugger;
			
	    var buydate = $("#ticket_datetime").val(); //购票日期
		var seatid = $("#seat_meg").val();         //选择坐席
	    var seatidbak = $("#accept_seat").val();        //选择坐席无票
        var paytype = $(".paymethod:checked").val();    //支付类型
        var deliverWho =$(".deliver_list:checked").val();//邮寄方式
		var deliverWhoPrice =$(".deliver_list:checked").attr("title");//邮寄费
        var fsName =  $("#from_station_name").val();      //出发站
        var tsName  =  $("#to_station_name").val();       //出发站
        var trainid =  $("#train_number").val();        //车次
        var btime =  $("#BeginTime").val();        //出发时间
        var etime =  $("#EndTime").val();            //到达时间 
        var cftime =  $("#BeginTime").val();        //出发时间
        var bctime =  $("#ticket_datetime").val();          //出发日期时间
        var distance =  $("#Distance").val();        //里程
        var sumtimes =  $("#Times").val();        //运行时间
        var ticet =  $("#ticketList").val();          //列车座位信息
        var realname = $("#realName").val()       //收票人
		
		//收票人快递地址 省+ 城市+ 区
        //var realaddress = provinceInfo + cityInfo + districtInfo + streetInfo+streetexplicitInfo;
        var realaddress = streetexplicitInfo;   //收票人快递地址
		
        //streetexplicitInfo  送票地址
        var realmoblie = $("#moblie").val();       //收票人电话
        var realmail =   $("#email").val();       //收票人email
        var sumpic =  $("#allPrice").text();       //支付金额
        var tNumber = $("#tnum").val();              //购票张数
		var Seller_Email = $("#SellerEmail").val(); 
		var Seller_EmailStr = $("#SellerEmailStr").val(); 
        
		//身份证验证
		var user_identity = '';
		
		if( $("#uCheci").val() == "D" || $("#uCheci").val() == "G" || $("#uCheci").val() == "C"){
			for(var i=0; i<tNumber; i++){
				user_identity += $("#idName"+i).val()+',';
				user_identity += $("#idSort"+i).val()+',';
				user_identity += $("#idNumber"+i).val();
				if(i != tNumber-1){
					user_identity += '|';
				}
			}
		}
		var addressId = $(".alist").filter(":radio[checked]").val();
		
		if (""==addressId) {
			addressId = $("#address_id").val();
		}
		//debugger;
		//alert("address_id="+addressId+" deliver_list="+deliverWho+"  ticket_id="+tkt_id+" ticket_num="+tNumber+"\nbuydate="+buydate+" payment_id="+pmt_id+" checknum="+check_num+" memo="+cusmsg+" informed="+informed+" accept_seat="+acceptSeat+"  from_station_time="+fromStationTime);
		$("#f_confirm_submit").attr("disabled", true);
		$.post("TrainOrder.asp", 
				{buy_date:buydate,
				seat_id:seatid,
				seat_idbak:seatidbak,
				pay_type:paytype,
				deliver_Who:deliverWho,
				deliver_WhoPrice:deliverWhoPrice,				
				fs_Name:fsName,
				ts_Name:tsName,
				train_id:trainid,
				b_time:btime,
				e_time:etime,
				cf_time:cftime,
				bc_time:bctime,
				distan_ce:distance,
				sum_times:sumtimes,
				tice_t:ticet,
				real_name:realname,
				real_address:realaddress,
				real_moblie:realmoblie,
				useridentity:user_identity,
				sum_pic:sumpic,
				email:realmail,
				t_Number:tNumber,
				S_ellerEmail:Seller_Email
				},
			function(odata){
				//alert(odata.tag);
				if(odata.tag=="e"){
					$("#valinow").html(odata.mes);
					
					//$("#validateimage").attr("src", "validateimage.php?t="+Math.random());
				}else if (odata.tag=="orderid") {
					//设置生成的订单号
					$("#order_id").val(odata.mes);
					//debugger;
					try{send_pay(odata.onum);}catch(e){};//add by rwx 2011-07-26
					if(odata.sendtype=="1")//需要审核
					{
					    $("#valinow").html("生成订单成功,系统将审核您的订单。请通过您输入的收件人以及联系方式查看您的订单。");
					    $("#errmesage").html("");//错误信息清空
					    $("#G_pay").attr("action", "/Main/Login.asp");
					    $("#G_pay").submit();
					}else{
					    $("#valinow").html("生成订单成功，正在跳转到支付平台，请稍候...<img src='images/loading.gif' />。");
					    $("#errmesage").html("");//错误信息清空
//				<input name="OrderNo" type="hidden" id="OrderNo" value="" />
//                <input name="TotalPrice" type="hidden" id="TotalPrice" value="" />
//                <input type="hidden" name="paymethod" value="bankPay">
//                <input type="hidden" name="PayStyle" value="1" />
//                <input type="hidden" name="PayBody" value="" />
					    //$("#G_pay").attr("action", "http://train.bingv.com/alipay/Index.aspx?payType="+paytype+"&orderNo="+odata.mes+"&Seller_Email="+Seller_Email+"&tocity="+cityInfo);
					    //$("#G_pay").attr("action", "/alipay/Index.asp?PayStyle=31&OrderNo="+odata.mes+"&TotalPrice="+sumpic+"&paymethod=bankPay&PayBody="+escape(buydate+" "+fsName+" - "+tsName+" 车次:"+trainid));
					    $("#G_pay").attr("action", "/UserCenter/TrainOrderList.asp");
						alert(Seller_EmailStr);
					    $("#G_pay").submit();
					}
				}else if(odata.tag=="err"){
					$("#valinow").html(odata.mes);
				}
				//把按钮打开
				$("#yesbuy").attr("disabled", false);
		}, "json");
	});
	 
	$("#f_queren_box_close").live("click", function(){
		$("#f_confirm_submit").attr("disabled", false);
		$("#queren_box").hide();
	});
	$(".deliver_list").live("click", function(){
		sumP();
	});
	
	$("#tnum").live("change", function(){
		idenVal();
		sumP();
	});	

	$(".passclass").live("click", function(){
		if ($(this).attr("checked")) {
			//alert($(this).val());
			for(var i=0;i < $("#tnum").val(); i++){
				if($("#idName"+i).val() == ''){
					var s_arr = ($(this).val()).split('|');
					$("#idShenfen"+i).val(s_arr[0]);
					$("#idName"+i).val(s_arr[1]);
					$("#idSort"+i).val(s_arr[2]);
					$("#idNumber"+i).val(s_arr[3]);
					break;
				}
			}
		} else {
			for(var i=0;i < $("#tnum").val(); i++){
				var s_arr = ($(this).val()).split('|');
				if($("#idShenfen"+i).val() == s_arr[0]){
					$("#idShenfen"+i).val('');
					$("#idName"+i).val('');
					$("#idSort"+i).val('');
					$("#idNumber"+i).val('');
					
				}
			}
		}
			
	});
});

var calculatePrice=function(obj){
	var seat_price = $(obj).val();
	var str=seat_price.split(","); 
		for (var i=0; i< $(".other_seat").length; i++) {
			
			tit = $(".other_seat")[i].title;
			if(tit == str[0])
			{
				$("#qita"+tit).hide();
			}else{
				$("#qita"+tit).show();	
			}
			$(".other_seat")[i].checked = false;
			$("#accept_seat").val("");
			$("#accept_seat1").html("");
			seatStr=[];
			//seatStr.length=0;
		}
		
		$("#seat_id").val(parseFloat(str[0]));
		$("#seat_name").html(str[2]);
		$(".no_seat").html(str[2]);
		$("#seat_meg").val(str[1]+","+str[2]); //获取选择的坐席
		//alert($("#seat_meg").val());
		sumP();
		var seatId = $("#seat_id").val();
		
		var atng =  $("#seat_name").val(); 
		
		//取得ticket_id start
//		from_station_id = $("#from_station_id").val();
//		to_station_id = $("#to_station_id").val();
//		train_number = $("#train_number").val();
//		buydate = $("#buydate").val();
//		seat_id = $("#seat_id").val();
//		//alert(seat_id);
//		$.post("http://www.99pto.com/backorder/buyTicket.php", 
//				{from_station_id:from_station_id,
//				to_station_id:to_station_id,
//				checi:train_number,
//				seat_id:seat_id,
//				ymd:buydate},
//				
//			function(data){
//					alert(data.mes);
//					$("#ticket_id").val(data.mes);
//				
//			}, "json");
	
}
/**
 * 计算金额
 */
function sumP(){
	//alert($(".deliver_list:checked").attr("title"));
	var tnum = parseFloat($("#tnum").val());
	var seatId = $("#seat_id").val();
	if($(".seat_price:checked").length>0){
	var eachPrice = parseFloat($(".seat_price:checked").attr("price"));
	
	var productPrice = eachPrice * tnum;//tnum张票的价格
	var purchasePrice = kepiao * tnum;//总客票销售服务费
	var total = (eachPrice + kepiao) * tnum;//总价格
	
	$("#product").text(productPrice.toFixed(2));
	$("#purchase").text(purchasePrice.toFixed(2));
	$("#total").text(total.toFixed(2));
	$("#totalprice").val(total);
	var deliverPrice = 0;
	var pay_order_num = 0;
	if($(".deliver_list:checked").length>0){
		deliverPrice = $(".deliver_list:checked").attr("title");
	}
	
	$(".Pay_fee_num").text(pay_order_num);
	$("#Pay_fee").text(deliverPrice);
		
				
	var allPrice = parseFloat(total) + parseFloat(deliverPrice);
					//+ (parseFloat(total) + parseFloat(deliverPrice))*0.01;//取消支付宝手续费
	$("#allPrice").text(allPrice.toFixed(2));
	}
				
}
/**
 * 高铁输入身份信息
 */
function idenVal(){
	//alert($("#uCheci").val());
	if( $("#uCheci").val() == "D" ||   $("#uCheci").val() == "G" ||  $("#uCheci").val() == "C"){
		var tnum = parseFloat($("#tnum").val());
		
		var str = '';
		for(var i=0;i < tnum; i++){
			str += "<ul class='gt_ul'>";	
			str += "<li><label>姓名：</label><input class='txt_name' type='text' id='idName"+i+"' name='idName"+i+"'/><input class='txt_name' type='hidden' id='idShenfen"+i+"' name='idShenfen"+i+"'/></li> ";
			str += "<li><label>证件类型：</label><select id='idSort"+i+"' name='idSort"+i+"' onchange=\"id_check("+i+")\">";
			str += "<option value=\"身份证\">身份证</option>";
			str += "<option value=\"户口簿\">户口簿</option>";
			str += "<option value=\"军人证\">军人证</option>";
			str += "<option value=\"机动车驾驶证\">机动车驾驶证</option>";
			str += "<option value=\"护照\">护照</option>";
			str += "<option value=\"回乡证\">回乡证</option>";
			str += "<option value=\"台胞证\">台胞证</option>";
			str += "<option value=\"港澳通行证\">港澳通行证</option>";
			str += "<option value=\"海员证\">海员证</option>";
			str += "<option value=\"外国人永久居留证\">外国人永久居留证</option>";
			str += "<option value=\"外国人出入境证\">外国人出入境证</option>";
			str += "<option value=\"其他证件\">其他证件</option>";
			str += "</select></li>";
			str += "<li><label>证件号码：</label><input type='text' id='idNumber"+i+"' name='idNumber"+i+"' onblur='id_check("+i+")' /></li>";
			str += "<li id=\"f_idinform"+i+"\" style=\"display:none\" ><div class=\"buyTishi\"><b></b><div class=\"buyTishi_r\"><p id='idinform"+i+"' ></p></div></div></li><br class=\"clear\" />";
			str += "</ul>";
			$(".dt_line").html(str);
			$(".dt_line").prepend("<p class=\"gtUl_shuoming\">同日期、同车次，相关证件只能购票一次。请正确输入乘客的证件号码，因您输入错误导致的后果请自行承担。</p>");
		}
	}else{
	   // $("#dtLinediv").removeClass("dt_line");
//	    $("#train").removeClass("sel3_text");
        $(".dt_line").attr("style","display:none");
	}
}
/**
 * 检查街道是否为空
 */
function   isaddress(){
	if($("#street").val() == ""){
		var errMsg = $("<div class=\"buyTishi3\"><b></b><div class=\"buyTishi3_r\"><p>街道不能为空</p></div></div>");	
		$("#street").after(errMsg);
	}else{	
		$("#street").parents("div").find(".buyTishi3").remove();
	}
}

/**
 * 身份证验证
 * @param identity
 */
function id_check(identity){
	
	if($("#idNumber"+identity).val().length != '15' && $("#idNumber"+identity).val().length != '18' && $("#idSort"+identity).val() == "身份证")
	{
		$("#f_idinform"+identity).show();
		$("#idinform"+identity).html("请填写正确的身份证号码");
	}else{
		$("#f_idinform"+identity).hide();
		$("#idinform"+identity).html("");
		for (var i=0;i<identity ;i++ )
		{
			
			if (($("#idNumber"+i).val() == $("#idNumber"+identity).val()) && $("#idSort"+identity).val() == "身份证" && $("#idNumber"+identity).val() != ""){
				$("#f_idinform"+identity).show();
				$("#idinform"+identity).html("此号码已存在，请重新填写");
				break;
			}else if(($("#idNumber"+identity).val().length == '15' || $("#idNumber"+identity).val().length == '18') && $("#idSort"+identity).val() == "身份证"){
				$("#f_idinform"+identity).hide();
				$("#idinform"+identity).html("");
			}
				
		}
	}
}
/**
 * 检测地址
 * @param obj
 */
function conflictTown(obj){
	if('镇'==$("#street").find("option:selected").text().substr(2)){
	if(obj.value.indexOf('镇')>0){
		if($("#street").val() == ""){
			var errMsg = $("<div class=\"buyTishi3\"><b></b><div class=\"buyTishi3_r\"><p>请确保所填镇与所选镇一致</p></div></div>");	
			$("#street").after(errMsg);
		}else{	
			var errDiv = $("#street").parents("div").find(".buyTishi3");
			errDiv.remove();
		}
		}
	}
}
function dd(id, obj)
{
	
	$.post("ajax/ticketCollecte.html", {iid:id, action:"del"}, function(data){
		if(data==1){
			$(obj).parent().parent().html("<td colspan='6'>删除成功</td>").fadeOut(3000).remove(); 
		}
	}, "html");
	
}

function p_del(id, obj)
{
	
	$.post("ajax/passengerCollecte.html", {iid:id, action:"del_pid"}, function(data){
		if(data==1){
			$(obj).parent().parent().html("<td colspan='6'>删除成功</td>").fadeOut(3000).remove(); 
		}
	}, "html");
	
}
//配送方式用到
function ShowUl()
{
    document.getElementById("UlBox").style.display= "block";
}
function HiddenUl()
{
    document.getElementById("UlBox").style.display = "none";
}

//常用乘客用到
$(document).ready(function(){
	$(".cyck li").mouseover(function(){      
	$(this).addClass("over");}).mouseout(function(){    
	$(this).removeClass("over");})   
	//------------
	$(".bor_bg").mouseover(function(){   
	$(this).addClass("over");
	
	}).mouseout(function(){    
	$(this).removeClass("over");}) 
	
}); 
//增加层高度

function toggle(){
	var div = document.getElementById("container");
	var span = document.getElementById("sh_txt");
	if(div.className=="cyck_box"){
		div.className="cyck_box2";
		span.innerHTML="收回显示";
		span.className="cyck_sh2";
	}else{
		div.className="cyck_box";
		span.innerHTML="显示更多";
		span.className="cyck_sh";
	}
	return false;
}
//IE下焦点对象现实位置

function moveFocusUp(focusObj){
	var position = $(focusObj).offset();
	var scrollTop = $(document).scrollTop();
	$(document).scrollTop(scrollTop-100);
}

function areaListChange(clickAreaId){
	var url = "/backorder/buyajax2.php?action=deliver";
	//var clickAreaId = $(this).attr("area_id");//取选中的单选按钮的area_id
	var trainNumber = $("#train_number").val();
	var dateTime = $("#ticket_datetime").val();//出发时间
	var fromStationId = $("#from_station_id").val();//出发站ID
	//alert("areaId:"+areaId+"|trainNumber:"+trainNumber+"|fromStationId:" +fromStationId);
	if(clickAreaId!=0){
		$("#deliver_l").load(url, {area_id:clickAreaId, from_station_time:dateTime,train_number:trainNumber,warn_time:warn_time,chaxun_url:chaxun_url, from_station_id:fromStationId},function(){
			if($(".deliver_list").length==1){
				 $(".deliver_list").click();
				 sumP();
			 }
		});
		$("#tarea").hide();
	}
}

function  checkIdcard(idcard){  

	var Errors = new Array(  
	"验证通过!",  
	"身份证号码位数不对!",  
	"身份证号码出生日期超出范围或含有非法字符!",  
	"身份证号码校验错误!",  
	"身份证地区非法!"  
	);  
	var   area={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"xingjiang",71:"台湾",81:"香港",82:"澳门",91:"国外"}    
	   
	var   idcard,Y,JYM;  
	var   S,M;  
	var   idcard_array   =   new   Array();  
	idcard_array   =   idcard.split("");  
	//地区检验  
	if(area[parseInt(idcard.substr(0,2))]==null)   return   false;  
	//身份号码位数及格式检验  
	switch(idcard.length){  
	case   15:  
	if   (   (parseInt(idcard.substr(6,2))+1900)   %   4   ==   0   ||   ((parseInt(idcard.substr(6,2))+1900)   %   100   ==   0   &&   (parseInt(idcard.substr(6,2))+1900)   %   4   ==   0   )){  
	ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;//测试出生日期的合法性  
	}   else   {  
	ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;//测试出生日期的合法性  
	}  
	if(ereg.test(idcard))   return   true;  
	else   return   false;  
	break;  
	case   18:  
	//18位身份号码检测  
	//出生日期的合法性检查    
	//闰年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))  
	//平年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))  
	if   (   parseInt(idcard.substr(6,4))   %   4   ==   0   ||   (parseInt(idcard.substr(6,4))   %   100   ==   0   &&   parseInt(idcard.substr(6,4))%4   ==   0   )){  
	ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;//闰年出生日期的合法性正则表达式  
	}   else   {  
	ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;//平年出生日期的合法性正则表达式  
	}  
	if(ereg.test(idcard)){//测试出生日期的合法性  
	//计算校验位  
	S   =   (parseInt(idcard_array[0])   +   parseInt(idcard_array[10]))   *   7  
	+   (parseInt(idcard_array[1])   +   parseInt(idcard_array[11]))   *   9  
	+   (parseInt(idcard_array[2])   +   parseInt(idcard_array[12]))   *   10  
	+   (parseInt(idcard_array[3])   +   parseInt(idcard_array[13]))   *   5  
	+   (parseInt(idcard_array[4])   +   parseInt(idcard_array[14]))   *   8  
	+   (parseInt(idcard_array[5])   +   parseInt(idcard_array[15]))   *   4  
	+   (parseInt(idcard_array[6])   +   parseInt(idcard_array[16]))   *   2  
	+   parseInt(idcard_array[7])   *   1    
	+   parseInt(idcard_array[8])   *   6  
	+   parseInt(idcard_array[9])   *   3   ;  
	Y   =   S   %   11;  
	M   =   "F";  
	JYM   =   "10X98765432";  
	M   =   JYM.substr(Y,1);//判断校验位  
	if(M   ==   idcard_array[17].toUpperCase())   return   true;   //检测ID的校验位  
	else   return   false;  
	}  
	else   return   false;  
	break;  
	default:  
	return   false;  
	break;  
	}  
}
