var _bCanRun = true;
var _cursel;
var _keyword;
var _smartbox;
var _obj_location;
var _citycode;
var _isSmartBoxOpened;
var _prevsel = -1;

function bookit(bIsOTA, nSessionID, nVehID)
{
	location.href = 'booking.php?sessionid='+nSessionID+'&vehid='+nVehID;
}
function sort(s_type)
{
	objform = document.getElementById("list_form");
	document.location.href = './search_do.php?work=sort&sessionid='+objform.sessionid.value+'&search_type='+s_type+"&ct="+objform.ct.value+"&cv="+objform.cv.value;
}
function do_sort(s_type)
{
	objform = document.getElementById("list_form");
	last_sort = objform.last_sort.value;
	if (last_sort != s_type)
		sort(s_type);
}

function empty_window(value)
{
	var objEditBox = document.getElementById(value);
	if (!_isSmartBoxOpened && (objEditBox.value == "Please Enter City or Airport Code" || objEditBox.value == "Please Enter City"))
		objEditBox.value = '';
}

function mouse_up(value)
{
	var objEditBox = document.getElementById(value);
	if (!_isSmartBoxOpened && (objEditBox.value == "Please Enter City or Airport Code" || objEditBox.value == "Please Enter City"))
		bbbbb = 1;
	else
		objEditBox.select();
}

function keypress(e)
{
	if (e.keyCode == UP || e.keyCode == DOWN || e.keyCode == LEFT || e.keyCode == RIGHT || e.keyCode == TAB || e.keyCode == ALT || e.keyCode == SHIFT || e.keyCode == ESC || e.keyCode == ENTER)
		return false;

	return true;
}

function doCheckWork(e, v1, v2)
{
	if (e.keyCode == UP || e.keyCode == DOWN || e.keyCode == LEFT || e.keyCode == RIGHT || e.keyCode == TAB || e.keyCode == ALT || e.keyCode == SHIFT || e.keyCode == ESC || e.keyCode == ENTER)
		return false;
	var _keyword;

	objlocation = document.getElementById(v1);
	objCC = document.getElementById(v2);
	
	_obj_location = objlocation;
	_citycode = objCC;

	_keyword = _obj_location.value;

	if (_obj_location.value.length >= 3 && _bCanRun)
	{
		window.status = "searching...";
		_bCanRun = false;

		_url = "./getdestfromstate.php?s=c&key="+_keyword;
		loadXMLDoc(_url);
	}
	else
	{
		closeSmartBox();
	}
	return true;
}

function mouse_move(obj)
{
	nindex = getSbIndex(obj);
	_cursel = nindex;
	setChoise(nindex);
}

function mouse_sel(obj)
{
	nindex = getSbIndex(obj);
	setValue(nindex);
	closeSmartBox();
}

function setValue(nValue)
{
	_obj_location.value = _arrtext[nValue];
	_obj_location.value = _arrtext[nValue];
	_citycode.value = _arrid[nValue];
}

function closeSmartBox()
{
	_smartbox=document.getElementById('mytextbox');
	var smartboxBG  = document.getElementById("smartboxBG");

	if (_smartbox)
	{
		_smartbox.innerHTML = '';
		_smartbox.style.display = 'none';
	}
	if (smartboxBG)
		smartboxBG.style.display = 'none';

	_isSmartBoxOpened = false;

}

function mouse_out(obj)
{
	nindex = getSbIndex(obj);
	setChoise(nindex);
}

function getSbIndex(divObj)
{
	var retIndex = 0;
	for (var i=0; i < _smartbox.childNodes.length; i++)
	{
		if (divObj == _smartbox.childNodes[i])
		{
			retIndex = i;
			break;
		}
	}
	return retIndex;
}

function keypressed(keycode, keyvalue)
{
	var smartbox = _smartbox;
	switch (keycode){
		case LEFT:
		case UP:
			_cursel--;
			if (_cursel<0)
				_cursel=0;
			setChoise(_cursel);
			break;
		case RIGHT:
		case DOWN:
			_cursel++;
			if (_cursel>=smartbox.childNodes.length)
				_cursel=smartbox.childNodes.length-1;
			setChoise(_cursel);
			break;
		case ENTER:
			nindex = _cursel;
			setValue(nindex);
			closeSmartBox();
			break;
		case ESC:
		case TAB:
		case ALT:
		case SHIFT:
			break;
		default:
			break;
	}
}
function body_mouseclick(event)
{
	if(!event) var event = window.event;

	var objtag;
	if(event.srcElement)
		objtag=event.srcElement;
	else
		objtag=event.target;

	if (objtag.tagName == "BODY")
	{
		if (_isSmartBoxOpened)
		{
			setValue(_cursel);
			closeSmartBox();
		}
	}
}

function showmap_tn(s_location)
{
	var arrSp1 = s_location.split(", ");
	var strCityName = arrSp1[0];
	strCityName = strCityName.replace(/ /g, "\+");

	try
	{
		var arrSp2 = arrSp1[1].split(" ");
		var State = arrSp2[0];
		var Country = arrSp2[1];
	}
	catch(e)
	{
		var State = "";
		var Country = "";
	}
	
	var _url = "http://www.mapquest.com/maps/map.adp?formtype=address&country="+Country+"&popflag=0&latitude=&longitude=&name=&phone=&level=&addtohistory=&cat=&address=&city="+strCityName+"&state="+State+"&zipcode=";
	window.open(_url, "map", "left=0 top=0 width=700 height=600 toolbar=yes menubar=yes scrollbars=yes resizable=yes location=yes status=yes");
}

function showmap_ota(a1, a2, a3, a4)
{
	var _url = "http://www.mapquest.com/maps/map.adp?formtype=address&addtohistory=&address="+a1+"&city="+a2+"&state="+a3+"&zipcode="+a4+"&country=US&geodiff=1";
	window.open(_url, "map", "left=0 top=0 width=700 height=600 toolbar=yes menubar=yes scrollbars=yes resizable=yes location=yes status=yes");
}

function show_loading()
{
	objLoadingSpan = document.getElementById("show_loading");
	if (objLoadingSpan)
	{
		ntop = document.body.scrollTop + 280;
		nleft = document.body.clientWidth / 2 - 150;
		objLoadingSpan.style.top = ntop.toString()+"px";
		objLoadingSpan.style.left = nleft.toString()+"px";
		objLoadingSpan.style.display = 'block';
	}
}