﻿
///Top change panel
function changePanel(panelIndex) {
	$("#searchPanel" + ((panelIndex + 1) % 2)).hide();
	$("#searchPanel" + panelIndex).show();
}



$(function() {
	$(".trainid").autocomplete(
				"/Services/TrainId.ashx",
				{
					delay: 10,
					minChars: 1,
					matchSubset: 1,
					cacheLength: 10
					//onItemSelect: searchTrainId
					, maxItemsToShow: 10
				}
			);

	$(".station").autocomplete(
				"/Services/Station.ashx",
				{
					delay: 10,
					minChars: 1,
					matchSubset: 10
					//cacheLength: 10,
					//onItemSelect: ,
					, maxItemsToShow: 10
				}
			);
	$(".trainid").attr("title", "输入拼音/中文或用↑↓选择");
	$(".station").attr("title", "输入拼音/中文或用↑↓选择");

	$('#topsearch_form input[type=text]').focus(function(evt) {
		var ipt = $(evt.target);
		if (ipt.attr("v") == ipt.val()) {
			ipt.val('');
		}
		ipt.select();
	}).blur(function(evt) {
		var ipt = $(evt.target);
		if (ipt.val() == '') {
			ipt.val(ipt.attr("v"));
		}
	}).change(function(evt) {
		var ipt = $(evt.target);
		if (ipt.val() == '') {
			ipt.val(ipt.attr("v"));
		}
	})
});


function searchTicket(type, startId, endId) {
	var startStation = $("#" + startId).val();
	var endStation = $("#" + endId).val();

	if (startStation == "") {
		alert("请填写起始车站!");
		$("#" + startId).focus();
		return false;
	}
	if (endStation == "") {
		alert("请填写终点车站!");
		$("#" + endId).focus();
		return false;
	}

	window.location.href = "/TicketSearch.aspx?t=" + type + "&pss=" + encodeURIComponent(startStation) + "&pes=" + encodeURIComponent(endStation);
}

function hotTrainSearch(id) {
	var train = $("#" + id);
	var tId = train.val();
	if (tId == "") {
		alert("请填写车次!");
		return false;
	}

	return window.location.href = "/train_" + tId;
}

function ticketAction(id, type) {

	var msg;
	if (type == 0)
		msg = "您确认该消息已经过期吗？";
	else
		msg = "您确认该消息是虚假消息吗?";
	if (!confirm(msg))
		return false;

	var params = "id=" + id + "&t=" + type;

	$.ajax({
		type: "GET",
		url: '/Services/Tickets.ashx',
		data: params,
		cache: false,
		success: function(r) {
			$("#ticketMsg").html("成功提交，感谢您的轻轻点击，让后来的人受到您的恩惠。");
		},
		error: function(r) { }
	});

	return true;
}