function checkform(){
	searchBoxFrom = document.getElementById("search-box-from");
	searchBoxTo = document.getElementById("search-box-to");	

	if (searchBoxFrom.value == ""){
		alert("Please type in departing airport.\nYou can use full city name or 3 letter airport code.");
		return false;
	}
	if (searchBoxTo.value == ""){
		alert("Please type in destination airport.\nYou can use full city name or 3 letter airport code.");
		return false;
	}
	
	if (document.mainform.from.value == ""){
		document.mainform.from.value = searchBoxFrom.value;
	}

	if (document.mainform.to.value == "")	{
		document.mainform.to.value = searchBoxTo.value;
	}

	if( searchBoxFrom.value == searchBoxTo.value ) {
		alert("Please use different departure and arrival airports.");
		return false;
	}

	var diffDate= (Date.parse(document.mainform.d2.value) - Date.parse(document.mainform.d1.value)) / 86400000;
	if( diffDate < 1 || isNaN(diffDate) ){
        alert("Please check depart and return dates!");
		return false;
	}
	populateActionLink(document.mainform, searchBoxFrom.value, searchBoxTo.value);
	return true;
}

function showitnow(){
	var divHide = document.getElementById('progressDIV');
	var divShow = document.getElementById('hiddenBody');

	while (divHide.hasChildNodes())	{
		divHide.removeChild(divHide.firstChild);
	}
	divHide.parentNode.removeChild(divHide);
	divShow.style.display = "block";
}

function populateActionLink(form, dep, arr) {
    var action = form.attributes["action"];
    var isBusiness = (form.c.value == 2 ? true : false);
    var sefTo = sefName(arr);
    var sefFrom = sefName(dep);
    var actionUrl = (isBusiness?"/business-class":"")+"/search"+"/"+sefFrom+"/"+sefTo;
    action.value = actionUrl;
    return;
}

function sefName(fullName) {
    var i;
    for( i=0; i<allAir.length; ++i ) {
	if( allAir[i] == fullName ) return allAirSef[i];
    }
    return "nowhere";
}

oldIndex = -1;
function showLine(newIndex) {
    hideLine();
    document.getElementById('hinfo-' + newIndex).style.display = "none";
    document.getElementById('pinfo-' + newIndex).style.display = "";
    oldIndex = newIndex;
}

function hideLine() {
    if (oldIndex != -1) {
	document.getElementById('hinfo-' + oldIndex).style.display = "";
	document.getElementById('pinfo-' + oldIndex).style.display = "none";
    }
}

function ShowDiv(elem) {
    var div = document.getElementById('Tooltip');
    div.style.top = getY(elem) + 20 + "px";
    div.style.left = getX(elem) + 50 + "px";
    div.style.display = 'inline';
}

function getY(oElement) {
    var iReturnValue = 0;
    while( oElement != null ) {
	iReturnValue += oElement.offsetTop;
	oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

function getX(oElement) {
    var iReturnValue = 0;
    while( oElement != null ) {
	iReturnValue += oElement.offsetLeft;
	oElement = oElement.offsetParent;
    }
    return iReturnValue;
}
                    																    
