﻿var intervalTimer = null;
var provinceTimer = null;
var lastAirport="";
var step = 0;
var needHidePolicyTop = true;
var needHidePolicyShow = true;
var timer1 = null;
var timer2 = null;
var airportList = new Array(
["guangdong","CAN|广州","SZX|深圳","ZHA|湛江","ZUH|珠海","SWA|汕头","CCC|潮州","FUO|佛山","MXZ|梅县","XIN|兴宁"],
["beijing","PEK|北京(首都)","NAY|北京(南苑)"],
["shanghai","SHA|上海(虹桥)","PVG|上海(浦东)"],
["tianjin","TSN|天津"],
["chongqing","CKG|重庆"],
["shandong","TNA|济南","TAO|青岛","YNT|烟台","LYI|临沂","DOY|东营","JNG|济宁","WEF|潍坊","WEH|威海"],
["jiangsu","NKG|南京","XUZ|徐州","CZX|常州","LYG|连云港","YNZ|盐城","NTG|南通","SZV|苏州","WUX|无锡"],
["zhejiang","NGB|宁波","WNZ|温州","YIW|义乌","HGH|杭州","HYN|黄岩","JUZ|衢州","HSN|舟山"],
["henan","CGO|郑州","LYA|洛阳","AYN|安阳","NNY|南阳"],
["hebei","SJW|石家庄","SHP|秦皇岛","XNT|邢台","HDG|邯郸"],
["sichuan","CTU|成都","WXN|万县","GYS|广元","LZO|泸州","MIG|绵阳","DAX|达县","DZU|大足","GHN|广汉","JZH|九寨沟","LIA|梁平","NAO|南充","PZI|攀枝花","XIC|西昌","YBP|宜宾"],
["liaoning","DLC|大连","SHE|沈阳","AOG|鞍山","CNI|长海","CHG|朝阳","DDG|丹东","JNZ|锦州","XEN|兴城"],
["hubei","WUH|武汉","XFN|襄樊","YIH|宜昌","ENH|恩施","SHS|荆沙"],
["hunan","CSX|长沙","DYG|张家界","CGD|常德","HNY|衡阳","HJJ|芷江"],
["fujian","XMN|厦门","FOC|福州","WUS|武夷山","JJN|晋江"],
["anhui","HFE|合肥","TXN|黄山","AQG|安庆","BFU|蚌埠","FUG|阜阳","HUZ|徽州","WHU|芜湖"],
["heilongjiang","HRB|哈尔滨","JMU|佳木斯","MDG|牡丹江","HEK|黑河","NZH|满州里","NDG|齐齐哈尔","OHE|漠河"],
["guangxi","KWL|桂林","BHY|北海","NNG|南宁","WUZ|梧州","LZH|柳州","AEB|百色"],
["jiangxi","KHN|南昌","KOW|赣州","JDZ|景德镇","KNC|吉安","JIU|九江","LUZ|庐山","JGS|井冈山"],
["neimenggu","HET|呼和浩特","CIF|赤峰","BAV|包头","XIL|锡林浩特","HLH|乌兰浩特","HLD|海拉尔","TGO|通辽","DSN|鄂尔多斯","LXI|林西","WUA|乌海"],
["yunnan","KMG|昆明","JHG|西双版纳","LJG|丽江","DLU|大理","BSD|保山","DIG|迪庆","LUM|芒市","SYM|思茅","YUA|元谋","ZAT|昭通","LNJ|临沧"],
["jilin","CGQ|长春","JIL|吉林","YNJ|延吉","TNH|通化"],
["xinjiang","URC|乌鲁木齐","AKU|阿克苏","AAT|阿勒泰","FYN|富蕴","HMI|哈密","HTN|和田","KHG|喀什","KRY|克拉玛依","KCA|库车","KRL|库尔勒","IQM|且末","SXJ|鄯善","TCG|塔城","YIN|伊宁","NLT|那拉提","KJI|喀纳斯"],
["guizhou","KWE|贵阳","TEN|铜仁","AVA|安顺","ACX|兴义","ZYI|遵义"],
["hainan","HAK|海口","SYX|三亚"],
["ningxia","INC|银川"],
["xizang","LXA|拉萨","LZY|林芝","BPX|昌都"],
["shanxiA","TYN|太原","CIH|长治","DAT|大同","YCU|运城"],
["shanxi","XIY|西安","ENY|延安","HZG|汉中","UYN|榆林","AKA|安康"],
["qinghai","XNN|西宁","GOQ|格尔木"],
["gansu","LHW|兰州","DNH|敦煌","JGN|嘉峪关","CHW|酒泉","IQN|庆阳"],
["hongkong","HKG|香港"],
["aomeng"],
["taiwan","LHN|梨山","MZG|马公"],
["hanguo","ICN|汉城"],
["riben","NRT|东京"]
);
function HidePolicyTip()
{
    needHidePolicyShow = true;
    if (timer1 != null)
    {
        window.clearTimeout(timer1);
    }
    timer1 = window.setTimeout(DoHidePolicyTop,10);
}
function DoHidePolicyTop()
{
    if (needHidePolicyTop)
    {
        lastAirport = "";
        document.getElementById("policyTipShow").style.display = "none";
        document.getElementById("policyTipShowListBox").style.display = "none";
    }
}

(function (bool)
{
    //兼容FF一些方法
    var html;
    if (bool)
    {
	    html = window.HTMLElement.prototype;
	    window.__defineGetter__("event", function ()
	    {
		    //兼容Event对象
		    var o = arguments.callee;
		    do
		    {
			    if (o.arguments[0] instanceof Event) return o.arguments[0];
		    }
		    while (o = o.caller);
		    return null;
	    });
	    Event.prototype.__defineGetter__("fromElement", function ()
	    {
		    return this.relatedTarget;
	    });
	    html.contains = function (o)
	    {
		    do
		    {
			    if (o == this) return true;
		    }
		    while (o = o.parentNode);
		    return false;
	    };
    }
})(/Firefox/.test(window.navigator.userAgent));

window.onload = function ()
{
    var wc = document.getElementById("policyTipShow");
    wc.onmouseover = function ()
    {
	    var wc = this, e = window.event;
	    if (!wc.contains(e.fromElement))
	    {
		    needHidePolicyShow = false;
	    }
    };
    wc.onmouseout = function ()
    {
	    var wc = this, e = window.event;
	    if (!wc.contains(e.toElement || e.fromElement))
	    {
		    HidePolicyTip();
	    }
    };
    var wc1 = document.getElementById("policyTipShowListBox");
    wc1.onmouseover = function ()
    {
	    var wc1 = this, e = window.event;
	    if (!wc1.contains(e.fromElement))
	    {
		    needHidePolicyTop = false;
	    }
    };
    wc1.onmouseout = function ()
    {
	    var wc1 = this, e = window.event;
	    if (!wc1.contains(e.toElement || e.fromElement))
	    {
		    HidePolicyAirportList();
	    }
    };
};
function HidePolicyAirportList()
{
    needHidePolicyTop = true;
    if (timer2 != null)
    {
        window.clearTimeout(timer2);
    }
    timer2 = window.setTimeout(DoHidePolicyAirportList,10);
}
function DoHidePolicyAirportList()
{
    if (needHidePolicyShow)
    {
        lastAirport = "";
        document.getElementById("policyTipShowListBox").style.display = "none";
        document.getElementById("policyTipShow").style.display = "none";
    }
}
function ShowpolicyTip(objName)
{
    if (provinceTimer != null)
    {
        window.clearTimeout(provinceTimer);
    }
    provinceTimer = window.setTimeout("DoShowpolicyTip('" + objName + "')",12);
}
function DoShowpolicyTip(objName)
{
    var obj = document.getElementById(objName);
    var div = "";
    var height = 0;
    var totalHeight = 0;
    for (var i=0;i<airportList.length;i++)
    {
        if (airportList[i][0] == objName)
        {
            var provinceList = airportList[i];
            for (var k=1;k<provinceList.length;k++)
            {
                var airport = provinceList[k].split("|");
                div += "<p id='" + airport[0] + "' onmouseover='SelectAirport(this)'>" + airport[1]  + "</p>";
                height += 25;
            }
            break;
        }
    }
    var listObj = document.getElementById("policyTipShowCont");
    if (div == "")
    {
        div = "<p class='on'>暂无数据</p>";
    }
    listObj.innerHTML = div;
    var fullObj = document.getElementById("policyTipShow");
    fullObj.style.display = "";
    fullObj.style.left = (obj.offsetLeft - (fullObj.offsetWidth - obj.offsetWidth - 15)) + "px";
    fullObj.style.bottom = (560 - obj.offsetTop - 13) + "px";
    if (height<22)
    {
        height = 25;
        totalHeight = 25;
    }
    else
    {
        totalHeight = height + 15;
    }
    step = 0;
    listObj.style.height = "0px";
    if (intervalTimer != null)
    {
        window.clearInterval(intervalTimer);
    }
    intervalTimer = window.setInterval("PopAirportList(" + height + "," + totalHeight + ",'policyTipShowCont')",10);
}
function PopAirportList(height,totalHeight,objName)
{
    var obj = document.getElementById(objName);
    if (step < totalHeight)
    {
        step += 10;
        obj.style.height = step + "px";
    }
    else
    {
        step = 0;
        obj.style.height = height + "px";
        if (intervalTimer != null)
        {
            window.clearInterval(intervalTimer);
        }
    }
}
var formerTipSense = "";
function ShowTipSense(num,height,obj)
{
    var tn = "tipSense" + num;
    var obj1 = document.getElementById(tn);
    if (formerTipSense != "")
    {
        document.getElementById(formerTipSense).style.display = "none";
    }
    formerTipSense = tn;
    var l = getleftPos(obj);
    var t = getTopPos(obj);
    obj1.style.display = "";
    obj1.style.bottom = "29px";
    obj1.style.left = -((obj1.offsetWidth - obj.offsetWidth) / 2) + "px";
    if (intervalTimer != null)
    {
        window.clearInterval(intervalTimer);
    }
    var totalHeight = height + 10;
    obj1.style.height = "0px";
    intervalTimer = window.setInterval("PopAirportList(" + height + "," + totalHeight + ",'" + tn + "')",10);
}
function CloseTipSense()
{
    if (formerTipSense != "")
    {
        document.getElementById(formerTipSense).style.display = "none";
        formerTipSense="";
    }
}
function SelectAirport(obj)
{
    obj.className = "on";
    if (obj.id != lastAirport)
    {
        if (lastAirport != "")
        {
            document.getElementById(lastAirport).className = "";
        }
        lastAirport = obj.id;
        var flightListObj = document.getElementById("policyTipShowListBox");
        flightListObj.style.display = "";
        var fullDiv = document.getElementById("policyTipShow");
        var ptLeft = fullDiv.offsetLeft - flightListObj.offsetWidth;
        var ptBottom = parseInt(fullDiv.style.bottom.replace("px","")) + fullDiv.offsetHeight - obj.offsetTop - 29;
        flightListObj.style.left = ptLeft + "px";
        flightListObj.style.bottom = ptBottom + "px";
        step = 0;
        document.getElementById("policyTipShowList").style.height = "20px";
        var ajax = new Ajax();
        var url = "ReadPolicyList.aspx?fromCity=" + obj.id;
        ajax.RequestURL(url,DealPolicyFlightList);
    }  
}
function DealPolicyFlightList(result)
{
    var obj = document.getElementById("policyTipShowList");
    if (result == "")
    {
        obj.innerHTML = "<p>本机场暂无特价机票信息<p>";
    }
    else
    {
        obj.style.height = "";
        obj.innerHTML = result;
        var height = obj.offsetHeight;
        var totalHeight = height + 10;
        obj.style.height = "0px";
        if (intervalTimer != null)
        {
            window.clearInterval(intervalTimer);
        }
        intervalTimer = window.setInterval("PopFlightList(" + height + "," + totalHeight + ")",10);
    }
}
function PopFlightList(height,totalHeight)
{
    var obj = document.getElementById("policyTipShowList");
    var flightListObj = document.getElementById("policyTipShowListBox");
    if (step < totalHeight)
    {
        step += 30;
        obj.style.height = step + "px";
        if (height > 40)
        {
            flightListObj.style.bottom = (parseInt(flightListObj.style.bottom.replace("px","")) - 12) + "px";
        }
    }
    else
    {
        step = 0;
        obj.style.height = height + "px";
        if (intervalTimer != null)
        {
            window.clearInterval(intervalTimer);
        }
    }
}

function IndexSearch()
{
    var flyType = "1";
    if (document.getElementsByName("FlyType")[1].checked)
    {
        flyType = "2";
    }
    var url = "Flight.aspx?flyType=" + flyType + "&fromCity=" + document.getElementById("HiddenFromCity").value + "&toCity=" + document.getElementById("HiddenToCity").value + "&flyDate=" + document.getElementById("FlyDate").value + "&returnDate=" + document.getElementById("ReturnDate").value;
    window.location.href = url;
}
function ChangeFlyType()
{
    var obj = document.getElementsByName("FlyType");
    if (obj[0].checked)
    {
        document.getElementById("ReturnDateDiv").style.display = "none";
    }
    else
    {
        document.getElementById("ReturnDateDiv").style.display = "";
    }
}
document.getElementById("FlyDate").value = GetDate(1);
document.getElementById("ReturnDate").value = GetDate(2);
//SwithPolicyTitle("p-bj","PEK",16);
