﻿var intervalTimer = null;
var provinceTimer = null;
var lastAirport="";
var step = 0;
var needHidePolicyTop = true;
var needHidePolicyShow = true;
var timer1 = null;
var timer2 = null;
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));



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 + "')",1);
}
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;
    }  
}
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-NanJing","NKG",16);