﻿var lastID = "";
var airportDivName = "airport";
var passengerDivName = "passenger";
var airportObj = null;
var hiddenAirportObj = null;
var lastPrefixTitle = "";
var lastPrefixContent = "";
var lastMemberMenuName = "";
var lastPolicyTitle = "";
var appendedChild = new Array();
function Login()
{
    win.Iframe.show('/LoginForm.aspx', '400', '120', true);
}
function LoginOK(username)
{
    parent.win.Iframe.hide();
    DealMemberInfo();
}
function Logout()
{
    DealMemberInfo("logout")
}
function Register()
{
    win.Iframe.show('/Register.aspx', '430', '380', true);
}
function BuyTicket(code,flag)
{
    var url="/OrderTicket.aspx?code=" + escape(code)  + "&flag=" + flag;
    window.open(url);
}
function AgentBuyTicket(code,flag)
{
    var url="AgentOrderTicket.aspx?code=" + code + "&flag=" + flag;
    popupWindow("buy",'机票订购',url,550,450,0,"auto",1);
}

function DealMemberInfo(action)
{
    var ajax = new Ajax();
    var url = "CheckMemberState.aspx";
    if (action != null)
    {
        url += "?action=" + action;
    }
    ajax.RequestURL(url,DisplayMemberInfo);
}
function DisplayMemberInfo(username)
{
    var obj = document.getElementById("LoginPanel");
    if (username == "")
    {
        obj.innerHTML = "[ <a href=\"javascript:Register()\">注册</a>]  [ <a href=\"javascript:Login()\">登录</a>] ";
    }
    else
    {
        obj.innerHTML = "欢迎您：<font color='red'>" + username + "</font>  [ <a href=\"javascript:Logout()\">退出登录</a>] ";
    }
}

function ShowMore(id)
{
    if (lastID != "" && lastID != id)
    {
        try
        {
            document.getElementById("AllPrice" + lastID).style.display = "none";
        }
        catch(ex){}
    }
    var obj=document.getElementById("AllPrice" + id);
    if (obj.style.display == "")
    {
        obj.style.display = "none";
    }
    else
    {
        obj.style.display = "";
    }
    lastID = id;
}
function ShowAirport(obj, hiddenObj)
{
    lastPrefixTitle = "t-hot";
    lastPrefixContent = "hot";
    var oldObj = document.getElementById(airportDivName);
    var flag = false;
    if (oldObj == null)
    {
        flag = true;
    }
    else
    {
        if (airportObj != obj)
        {
            flag = true;
        }
    }
    CloseAirportList();
    if (flag)
    {
        var div = document.createElement("div");
        with(div)
        {
            className = "airportList";
            id = airportDivName;
            style.position = "absolute";
            style.left = getleftPos(obj) + "px";
            style.top = getTopPos(obj) + "px";
            innerHTML = "<img src='/images/loading.gif'> 正在加载．．．";
        }
        document.body.appendChild(div);
        airportObj = obj;
        hiddenAirportObj = document.getElementById(hiddenObj);
        var ajax = new Ajax();
        ajax.RequestURL("/ReadAirportList.aspx",DealAirportList);
    }
}
function DealAirportList(result)
{
    var obj = document.getElementById(airportDivName);
    obj.style.width = "480px";
    obj.style.padding = "0px";
    obj.innerHTML = result;
}
function CloseAirportList()
{
    var oldObj = document.getElementById(airportDivName);
    if (oldObj != null)
    {
        document.body.removeChild(oldObj);
    }
}
function InputAirport(content)
{
    var array = content.split("|");
    if (airportObj != null)
    {
        hiddenAirportObj.value = content;
        airportObj.value = array[1];
        CloseAirportList();
    }
}
function ShowPassenger(obj, num)
{
    lastPrefixTitle = "t-hot";
    lastPrefixContent = "hot";
    var oldObj = document.getElementById(passengerDivName);
    var flag = false;
    if (oldObj == null)
    {
        flag = true;
    }
    else
    {
        if (airportObj != obj)
        {
            flag = true;
        }
    }
    ClosePassengerList();
    if (flag)
    {
        var div = document.createElement("div");
        with(div)
        {
            className = "airportList";
            id = passengerDivName;
            style.position = "absolute";
            style.left = getleftPos(obj) + "px";
            style.top = getTopPos(obj) + "px";
            innerHTML = "<img src='/images/loading.gif'> 正在加载．．．";
        }
        document.body.appendChild(div);
        airportObj = obj;
        var ajax = new Ajax();
        ajax.RequestURL("/ReadPassengerList.aspx?Number=" + num + "&t=" + new Date(),DealPassengerList);
    }
}
function DealPassengerList(result)
{
    var obj = document.getElementById(passengerDivName);
    obj.style.width = "480px";
    obj.style.padding = "0px";
    obj.innerHTML = result;
}

function SwitchSpan(spanObj)
{
    var n = spanObj.id.replace("t-","");
    var obj = document.getElementById(n);
    if (n != lastPrefixContent)
    {
        var contentObj = document.getElementById(lastPrefixContent);
        if (contentObj != null)
        {
            contentObj.style.display = "none";
        }
        if (obj != null)
        {
            obj.style.display = "";
        }
        lastPrefixContent = n;
    }
    if (spanObj.id != lastPrefixTitle)
    {
        document.getElementById(lastPrefixTitle).className = "";
        spanObj.className = "on";
        lastPrefixTitle = spanObj.id;
    }
    
}
function getTopPos(inputObj)
{
  var returnValue = inputObj.offsetTop + inputObj.offsetHeight;
  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
  return returnValue;
}
function getleftPos(inputObj)
{
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
  return returnValue;
}
function SearchFlight(flyDate,fromCityString,toCityString)
{
    var fromCity = fromCityString.split("|");
    var toCity = toCityString.split("|");
    if (fromCity[0] == toCity[0]) {
        alert("出发城市与目的城市不能相同");
        return;
    }
    document.getElementById("FlightResult").innerHTML = "";
    ShowLoading("正在查询机票数据,请稍候．．．");
    var ajax = new Ajax();
    var url = "FlightResult.aspx?fromCity=" + fromCity[0] + "&fromCityName=" + escape(fromCity[1]) + "&toCity=" + toCity[0] + "&toCityName=" + escape(toCity[1]) + "&flyDate=" + flyDate;
    ajax.RequestURL(url,DealResult);
}
function DealResult(result)
{
    CloseLoading();
    if (result.indexOf("error:") > -1)
    {
        result = "<br><br><center style='font-weight:bold;color:red;font-size:14px;font-family:宋体'>" + result.replace("error:","") + "</center>";
    }
    document.getElementById("FlightResult").innerHTML = result;
}
function SearchReturnFlight(flyDate,fromCityString,toCityString)
{
    var fromCity = fromCityString.split("|");
    var toCity = toCityString.split("|");
    var ajax = new Ajax();
    document.getElementById("ReturnResult").innerHTML = "";
    ShowLoading("正在查询机票数据,请稍候．．．");
    var url = "FlightResult.aspx?fromCity=" + fromCity[0] + "&fromCityName=" + escape(fromCity[1]) + "&toCity=" + toCity[0] + "&toCityName=" + escape(toCity[1]) + "&flyDate=" + flyDate;
    ajax.RequestURL(url,DealReturnResult);
}
function DealReturnResult(result)
{
    CloseLoading();
    if (result.indexOf("error:") > -1)
    {
        result = "<br><br><center style='font-weight:bold;color:red;font-size:14px;font-family:宋体'>" + result.replace("error:","") + "</center>";
    }
    document.getElementById("ReturnResult").innerHTML = result;
}
function Check()
{
	if (!confirm("注意：请问确定要操作吗"))
    {
        return false;
    }
	return true;
}
function GetQueryString(parmName)
{ 
    var result = '';
    var url = document.location.search;
    if(url!="undefined")
    {
        var arrParam = url.split("&");

        for(var i =0;i<arrParam.length;i++)
        {
            var loc = arrParam[i].indexOf(parmName + "=");

            if(loc!=-1)
            {
                result = arrParam[i].replace(parmName + "=","").replace("?","");
                break;
            }
            
        }
    }
    return result;
}
function ShowLoading(text)
{
    var loadingObj = document.getElementById("loading");
    if (loadingObj != null)
    {
        loadingObj.style.display = "";
    }
    var textObj = document.getElementById("loadingText");
    if (textObj != null)
    {
        textObj.innerHTML = text;
    }
}
function CloseLoading()
{
    var loadingObj = document.getElementById("loading");
    if (loadingObj != null)
    {
        loadingObj.style.display = "none";
    }
}
function GetDate(i)
{
    var date = new Date();
    return GetDateString(date,i);
}
function GetDateString(date, i)
{
    var tempDate = new Date(date);
    tempDate.setUTCDate(tempDate.getUTCDate() + i);
    var Zeroize = function (value)
    {
        value = String(value);
        for (var i = 0, zeros = ''; i < (2 - value.length); i++)
        {
            zeros += '0';
        }
        return zeros + value;
    }; 
    return tempDate.getFullYear() + "-" + Zeroize(tempDate.getMonth() + 1) + "-" + Zeroize(tempDate.getDate())
}
function SwithPolicyTitle(id,fromCity,number)
{
    if (lastPolicyTitle != id)
    {
        if (lastPolicyTitle != "")
        {
            document.getElementById(lastPolicyTitle).className = "";
        }
        var obj = document.getElementById(id);
        obj.className = "on";
        lastPolicyTitle = id;
        var loadingObj = document.getElementById("loadingData").style.display = "";
        document.getElementById("loadingDataTitle").innerHTML = "正在加载数据．．．";
        var ajax = new Ajax();
        var url = "ReadPolicyList.aspx?fromCity=" + fromCity + "&n=" + number;
        ajax.RequestURL(url,DealPolicyTitleResult);
    }
}
function DealPolicyTitleResult(text)
{
    document.getElementById("loadingData").style.display = "none";
    var obj = document.getElementById("policyList");
    obj.innerHTML = text;
}