function findPosX(obj)
{
    var _41 = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            _41 += obj.offsetLeft;
            obj = obj.offsetParent;
        }
    }
    else
    {
        if (obj.x)
        {
            _41 += obj.x;
        }
    }
    return _41;
};
function findPosY(obj)
{
    var _43 = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            _43 += obj.offsetTop;
            obj = obj.offsetParent;
        }
    }
    else
    {
        if (obj.y)
        {
            _43 += obj.y;
        }
    }
    return _43;
};
var who;
var ESC = 27;
var TAB = 9;
var ALT = 18;
var UP = 38;
var DOWN = 40;
var LEFT = 37;
var RIGHT = 39;
var ENTER = 13;
var SHIFT = 16;
var lastKey = 0;
function keyDown(e)
{
    var pK = document.all ? window.event.keyCode : e.which;
    var pK2 = String.fromCharCode(pK).toLowerCase();
    lastKey = pK;
    if (who != null)
    {
        who(pK, pK2);
    }
};
function keysInit(callback)
{
    document.onkeydown = keyDown;
    who = callback;
    if (document.layers)
    {
        document.captureEvents(Event.KEYPRESS);
    }
};
function noEnter()
{
    return lastKey != ENTER;
};
var _toolong, _lastsent, _timeout, _itemCount, _idletimer, _cursel, _target;
var _prevsel;
var _inputcode = null, _searchtype;
var _targetBG;
var _input = null;
var _numChoices;
var sbHttp = null;
var _stop;
var _sboxminwidth;
var _clientsbcb;
var d_d_air_scc;
function d_d_air_c()
{
    keysInit(null);
    if (_inputcode != null && _inputcode.value != null &&
        _inputcode.value.length < 1)
    {
        c(0);
    }
    d_d_air_abr();
    d_d_air_cls();
    _input = null;
    _stop = false;
};
function d_d_air_abr()
{
    if (sbHttp != null)
    {
        if (sbHttp.inprogress)
        {
            sbHttp.cancelRequest();
        }
    }
};
function d_d_air_cls()
{
    if (_target != null)
    {
        _target.style.display = 'none';
        _target.innerHTML = "";
    }
    if (_targetBG != null)
    {
        _targetBG.style.display = 'none';
    }
    _stop = true;
};


function d_d_air(form_type,form_fill_no,where, wherecode, regcode, searchtype, timeout, minwidth,
    valuesetcb)
{
	form_types=form_type;

	
	form_fill_nos=form_fill_no;
	form_fill_noss=form_fill_nos-1;
	
	
    _inputcode = _input = _inputregcode = null;
    d_d_air_c();
    var body = document.getElementsByTagName("body")[0];
    _target = document.getElementById('smartbox');
    if (!_target)
    {
        _target = document.createElement("div");
        _target.id = "smartbox";
        _target.style.zIndex = 510000;
        _target.style.position = 'absolute';
        _target.style.display = 'none';
        _target.style.width = 'auto';
		
        body.appendChild(_target);
    }
    _target.className = searchtype + "smartboxResults";
    _targetBG = document.getElementById('smartboxBG');
    if (!_targetBG)
    {
        _targetBG = document.createElement("iframe");
        _targetBG.id = "smartboxBG";
        _targetBG.style.zIndex = 50;
        _targetBG.setAttribute('scrolling', 'no');
        _targetBG.setAttribute('frameborder', '0');
        _targetBG.style.position = "absolute";
        _targetBG.style.display = "none";
        body.appendChild(_targetBG);
    }
    if (isNaN(parseInt(minwidth)))
    {
        _sboxminwidth =  - 1;
    }
    else
    {
        _sboxminwidth = parseInt(minwidth);
		
    }
    keysInit(keypressed);
    _input = where;
    _inputcode = wherecode;
    _inputregcode = regcode;
    _searchtype = searchtype;
    _lastsent = "";

    _timeout = timeout;
    _clientsbcb = valuesetcb;
    var x = findPosX(where);
    var y = findPosY(where) + where.offsetHeight + 1;
    _target.style.top = y + 'px';
    _target.style.left = x + 'px';
    if (_idletimer)
    {
        clearTimeout(_idletimer);
        _idletimer = '';
    }
    _toolong = false;
    _lastsent = "";
    _cursel =  - 1;
    _prevsel =  - 1;
    _stop = false;
};
function d_d_air_sea(input)
{
    if (sbHttp == null)
    {
        sbHttp = new xml_http();
    }
    if (_searchtype == 'air')
    {
        var url = 'city.php?where=' + encodeURIComponent(_lastsent);
        var _chars = 3;
    }
    else
    {
        var url = 'airline.php?where=' + encodeURIComponent(_lastsent);
        var _chars = 2;
    }
    if (!sbHttp.inprogress)
    {
        if (_lastsent == _input.value || _input.value.length < _chars)
        {
            return ;
        }
        window.status = "searching...";
        _lastsent = _input.value;
        var buffer = "where=" + encodeURIComponent(_lastsent);
        var sbHttp = new xml_http();
        buffer += "&lc=en&lc_cc=US";
        if (_searchtype == "air")
        {
            buffer += "&s=1";
        }
        else if (_searchtype == "car")
        {
            buffer += "&s=2";
        }
        else if (_searchtype == "hotel")
        {
            buffer += "&s=3";
        }
        else if (_searchtype == "any")
        {
            buffer += "&s=4";
        }
        if (d_d_air_scc != null && d_d_air_scc.length > 0)
        {
            buffer += "&cc=" + d_d_air_scc;
        }
        buffer += "&f=h";
        sbHttp.init(url, buffer);
        try
        {
            sbHttp.setTimeout(10000);
            sbHttp.asyncGET(new _Callback(input));
        }
        catch (e)
        {
            alert(e);
        }
    }
    else
    {
        alert("busy");
    }
};
function d_d_air_cc(code)
{
    d_d_air_scc = code;
	
};
function t()
{
    d_d_air_scc = null;
};
function f(elem)
{
    var list = d_d_air_sbl();
    var retIndex = 0;
    for (var i = 0; i < list.childNodes.length; i++)
    {
        if (elem == list.childNodes[i])
        {
            retIndex = i;
            break;
        }
    }
    return retIndex;
};
function l(event)
{
    var obj = event ? event.target : this;
    _cursel =  - 1;
    d( - 1);
};
function k(event)
{
    var obj = event ? event.target : this;
    _cursel = f(obj);
    c(_cursel);
    d_d_air_cls();
};
function o(event)
{
    var obj = event ? event.target : this;
    _cursel = f(obj);
    d(_cursel);
};
function j()
{
    _target.style.display = 'inline';
    if (m())
    {
        _targetBG.style.display = 'inline';
    }
    if (_sboxminwidth > _target.offsetWidth)
    {
        _targetBG.style.width = _sboxminwidth + "px";
        _target.style.width = _sboxminwidth + "px";
    }
    else
    {
        _targetBG.style.width = _target.offsetWidth + "px";
    }
    _targetBG.style.height = _target.offsetHeight + "px";
    _targetBG.style.top = _target.style.top;
    _targetBG.style.left = _target.style.left;
};
function g()
{
    _target.style.display = 'none';
    _targetBG.style.display = 'none';
};
function d_d_air_sbl()
{
    var ul;
    for (var i = 0; i < _target.childNodes.length; i++)
    {
        var node = _target.childNodes[i];
        if (node.nodeName == 'UL')
        {
            ul = node;
            break;
        }
    }
    return ul;
};
function _Callback(input)
{
    this.onError = function(status, statusText){}
    ;
    this.onLoad = function done(client)
    {
        window.status = "";
        if (!client.cancelled && (_input == input))
        {
            _target.innerHTML = client.getText();
            var list = d_d_air_sbl();
            _itemCount = list.childNodes.length;
            if (_itemCount > 0)
            {
                for (var i = 0; i < list.childNodes.length; i++)
                {
                    li = list.childNodes[i];
                    li.onmousedown = k;
                    li.onmouseover = o;
                    li.onmouseout = l;
                }
                _target.style.width = 'auto';
                j();
            }
            else
            {
                g();
            }
            _cursel = 0;
            _prevsel = 0;
            d(0);
        }
    }
};
function c(newi)
{
    if (newi < 0)
    {
        _lastsent = "";
        try
        {
            _inputcode.value = "";
            _inputregcode.value = "";
            _clientsbcb(null);
        }
        catch (e){}
    }
    else if (_itemCount > 0)
    {
        var list = d_d_air_sbl();
        if (list == null || list.childNodes == null)
            return ;
        var selected = list.childNodes[newi];
        var fields = selected.id.split("-");
        var id;
        var reg;
        var hotels;
        var lmid;
        if (fields.length >= 2)
        {
            id = fields[1];
            reg = fields[2]
        }
        if (fields.length >= 3)
        {
            hotels = fields[2]
        }
        if (fields.length >= 4)
        {
            lmid = fields[3]
        }
        _inputcode.value = id;
        _inputregcode.value = reg;
        if (selected.innerText != undefined)
        {
            _input.value = selected.innerText;
			
	  	  if(form_types=='des')
		  {
			document.getElementById("origin_"+form_fill_nos).value=document.getElementById("destination_"+form_fill_noss).value;
			document.getElementById("ori_"+form_fill_nos).value=document.getElementById("des_"+form_fill_noss).value;
			document.getElementById("originregioncode_"+form_fill_nos).value=document.getElementById("destinationregioncode_"+form_fill_noss).value;
		}
        
        }
        else
        {
            _input.value = selected.textContent;

if(form_types=='des'){
        document.getElementById("origin_"+form_fill_nos).value=document.getElementById("destination_"+form_fill_noss).value;
		 document.getElementById("ori_"+form_fill_nos).value=document.getElementById("des_"+form_fill_noss).value;
		  document.getElementById("originregioncode_"+form_fill_nos).value=document.getElementById("destinationregioncode_"+form_fill_noss).value;
		
		
		
		}
		
			
        }
        try
        {
            if (typeof _clientsbcb == 'function')
            {
                var cbData = new Object();
                cbData.str = selected.innerHTML;
                cbData.hc = hotels;
                cbData.id = id;
                cbData.lmid = lmid;
                _clientsbcb(cbData);
            }
        }
        catch (ignored){}
    }
};
function d(newi)
{
    var list = d_d_air_sbl();
    if (list.childNodes.length > 0)
    {
        if (_prevsel >= 0)
        {
            var prev = list.childNodes[_prevsel];
            prev.className = prev.className.replace( /  * smartboxItemHi / , "")
                ;
        }
        if (newi >= 0)
        {
            if (list.childNodes.length > 0)
            {
                var cur = list.childNodes[newi];
                cur.className = cur.className + " smartboxItemHi";
            }
            _prevsel = newi;
        }
    }
};
var _pressed = 0;
function keypressed(keycode, keyvalue)
{
    clearTimeout(_idletimer);
    _pressed = new Date().getTime();
    switch (keycode)
    {
        case LEFT:
        case UP:
            _cursel = _cursel - 1;
            if (_cursel < 0)
            {
                _cursel = 0;
            }
            d(_cursel);
            break;
        case RIGHT:
        case DOWN:
            _cursel++;
            if (_cursel >= _itemCount)
            {
                _cursel = _itemCount - 1;
            }
            d(_cursel);
            break;
        case ENTER:
            if (_itemCount > 0)
            {
                c(_cursel);
                d_d_air_cls();
            }
            break;
        case ESC:
            d_d_air_cls();
            break;
        case TAB:
            if (_cursel >= 0 && _cursel < _itemCount)
            {
                c(_cursel);
            }
        case ALT:
        case SHIFT:
            break;
        default:
            c( - 1);
            _idletimer = self.setTimeout('idle()', _timeout);
    }
};
function r()
{
    var v = (_stop == null || _stop != true);
    _stop = false;
    return (v ? true : noEnter());
};
function idle(input)
{
    if (noEnter())
    {
        var now = new Date().getTime();
        if (now - _pressed > _timeout)
        {
            clearTimeout(_idletimer);
            _typer(_input);
        }
        else
        {
            clearTimeout(_idletimer);
            _idletimer = self.setTimeout('idle()', _timeout);
        }
    }
};
function _typer(input)
{
    if ((_input != null) && _input.value.length > 0)
    {
        d_d_air_abr();
        d_d_air_sea(input);
		
    }
    else
    {
        c( - 1);
        d_d_air_cls();
    }
};
function m()
{
    return (window.opera) ? false : true;
}
