
/*
	JavaScript for the airport atlas.
	
	This file must be included (via script-Tag) in
	every page, where a airport altlas link occur, and
	also in the application popup for the airport atlas (the searchform).
	Because the file contains the function for the opener-page and for the searchform.
	
*/
/*
	Function to open a airport atlas popup.
	The parameter 'sId' is the id of the formelement where the airportname should later appear
*/
function lh_open_atlas(sId)
{
	oAtlas = window.open("../app_aa/app_aa_main.jsp?sid="+sId,"atlas","width=430,height=300,left=200,top=200");
	oAtlas.focus();
	return false;
}
/*
	Function to recieve the airport name from the popup.
	The parameter 'sId' is the id of the formelement where the airportname should appear.
	The parameter 'sApName' is the airportname.
	The function checks if the formelement (where the airportname should appear) is a select list
	and change the selectlist to a text-input field.
*/
function lh_receive_atlas(sId,sApName,hId,sApCode)
{
	oReceiveEle = document.getElementById(sId);
	if(oReceiveEle.type.indexOf("select")>=0)
	{
		// the formelement is a selectlist, so a new html-element of typ 'input' is generated.
		oNewEle = document.createElement("input");
	 	// get 'name' and 'id' attribute for the new element form the old element.
	 	// important for the form-communication with the backend.
		oNewEle.setAttribute("name",oReceiveEle.getAttribute("id")); // we use allways name=id in inputfields, except the selectlist in AD!
		oNewEle.setAttribute("id",oReceiveEle.getAttribute("id"));
		strNewWidth = getStyle(oReceiveEle,"width");
		if(strNewWidth=="")
		{
			
			oNewEle.setAttribute("class",oReceiveEle.getAttribute("class"));
		}
		else
		{
			if(navigator.userAgent.indexOf("Gecko")!=-1)
			{
				value = strNewWidth.substring(0,strNewWidth.length-2);
				unit = strNewWidth.substring(strNewWidth.length-2,strNewWidth.length);
				oNewEle.style.width = String(parseInt(value)+4)+unit;
			}
			else oNewEle.style.width = strNewWidth;
		}
		oNewEle.setAttribute("value",sApName);
		oNewEle.setAttribute("onchange","delAirportCode('"+hId+"')");
		oParentEle = oReceiveEle.parentNode; // get the parent Node of the formelement (a selectlist).
		oParentEle.replaceChild(oNewEle,oReceiveEle); // replace the selectlist with the new input field in the DOM-tree.
		oNewEle.focus();
	}
	else
	{
		// the formelement is a input field. Set new value form the atlas popup.
		oReceiveEle.value = sApName;
	}
	oReceiveHiddenEle = document.getElementById(hId);
	oReceiveHiddenEle.value = sApCode;
}
/*
	Function to send the selected airport back to the mainpage. Used in the popup
	The parameter 'sId' is the id of the formelement where the airportname should appear.
*/
var bErrorFlag = false;
function lh_select_airport(sId)
{
	oApEle = document.getElementById(sId);
	// check if the user select an airport
	if(oApEle.value=="")
	{
		// user selected no airport, so the errormessage is displayed
		oErEle = document.getElementById(sErEleId);
		oErEle.style.display = "block"; // element is display:none via css by default!
		// content is longer because of the new blockelement, so the window is extended.
		if(!bErrorFlag)window.resizeBy(0,30);
		bErrorFlag = true; // extend window  only once!
		return false;
	}
	try
	{
		// sometimes the openerwindow is missing (e.g. user close browserwindow)
		// To check that for all browser for sure, "try/catch" is the solution (and it's easy)
		if(!opener.lh_receive_atlas) throw "error";
		aValues = oApEle.value.split("|");
		opener.lh_receive_atlas(sOpenerReceiveEleId,aValues[0],sOpenerReceiveHiddenEleId,aValues[1]);
	}
	catch(e)
	{
		// do nothing
	}
	finally
	{
		window.setTimeout('window.close()',300);
	}
}
/*
	Function deletes the airport code in the mainpage, if the user changed something in the airportname-field.
	This is necessary, because the backend uses the airportcode if a code is in the request form the browser.
	Called if the onchange-Event is fired.
*/
function delAirportCode(id)
{
	obj = document.getElementById(id);
	obj.value = "";
	return true;
}

function getStyle(el, style)
{
   if(!document.getElementById)return;
   var value = el.style[toCamelCase(style)];
   if(!value)
   {
        if(document.defaultView && document.defaultView.getComputedStyle)
        {
            value = document.defaultView.getComputedStyle(el, "").getPropertyValue(style);
        }    
        else if(el.currentStyle)
        {
            value = el.currentStyle[toCamelCase(style)];
        }
    }
    return value;
}

/** toCamelCase(input)
 * Converts string input to a camel cased version of itself.
 * For example:
 * toCamelCase("z-index"); --> returns zIndex
 * toCamelCase("border-bottom-style"); --> returns borderBottomStyle.
 */
function toCamelCase(sInput)
{
    var oStringList = sInput.split('-');
    if(oStringList.length == 1)return oStringList[0];
    var ret = sInput.indexOf("-") == 0 ? oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
    for(var i = 1, len = oStringList.length; i < len; i++)
    {
        var s = oStringList[i];
        ret += s.charAt(0).toUpperCase() + s.substring(1)
    }
    return ret;
}

/// added for awardbooking
function duplicateField(obj,strId)
{
	targetObj = document.getElementById(strId);
	if(targetObj.value=="")
	{
		targetObj.value = obj.value;
	}
}