/*************************************************************************************
	*
	*	PANEL JS
	*	Copyright 2008, Rewe Touristik
	*	www.itsreisen.de
	*	Author:Joerg Di Terlizzi, JUNG v. MATT Neckar GmbH
	*
 *************************************************************************************/	
	var xmlHttp = null;
	var dateSelectForm = 'ajaxPanel';
	var loadingscreen 	= '<img src="/images/loading.gif" alt="Laden..." />';
	var travelType		= 'PF';
	var elementIdDay    = '';
	var elementIdMonth  = '';
	var elementIdYear   = '';
	var index = 0;
	var currentFlyOut = '';
	var isflyout = false; 
	var childrenDates 	= new Array();
		childrenDates[0] = new Array();
		childrenDates[1] = new Array();
		childrenDates[2] = new Array();
	
	function closeFlyOut(){
		document.getElementById('panelFlyOut').style.display = 'none';
		setElementProperty(loadingscreen, 'flyOutCt');
	}
	
	//show and place the flyout
	function showFlyOut(name, width){
		
		setElementProperty(loadingscreen, 'flyOutCt');
		
		var eventShow = true;
		if((name == currentFlyOut || currentFlyOut == '') && document.getElementById('panelFlyOut').style.display == 'block' && doClose){
			//alert(currentFlyOut+"<>"+name);
			closeFlyOut();
			eventShow =  false;
		}
		else{
			document.getElementById('panelFlyOut').style.width = width.toString()+'px'; 
			document.getElementById('panelFlyOut').style.display = 'block';	
			doClose = true;
		}
		
		document.getElementById('dcCont').onclick = function(){}
	
		currentFlyOut = name;
		
		return eventShow;
	}
	
	//-------------------------------------------------------------------------------
	//depart Airport
	function getDptAirport(){
		//closeFlyOut();
		var data_dpt_airport_alt = document.getElementById('departureAirportAlt').value;
		setElementPosition('formText_dep_airport', 'panelFlyOut', -3, 19);
		if(showFlyOut('formText_dep_airport', 400)){
			writeAjax('/ajax_module/getNlAirport.php?dpt_airport_alt='+data_dpt_airport_alt, 'flyOutCt', 'dpt_airport_alt='+data_dpt_airport_alt);
		}
	}
	function setDptAirport(val, text){
		document.getElementById('departureAirport').value = val;
		document.getElementById('formText_dep_airport').innerHTML = text;
		closeFlyOut();
	}
	//EO depart Airport alternativ
	//-------------------------------------------------------------------------------
	//depart Airport
	function getDptAirportAlt(){
		//closeFlyOut();
		var data_dpt_airport = document.getElementById('departureAirport').value;
		setElementPosition('formText_dep_airport_alt', 'panelFlyOut', -3, 19);
		if(showFlyOut('formText_dep_airport_alt', 400)){
			writeAjax('/ajax_module/getNlAirport.php?dpt_airport='+data_dpt_airport+'&alt=1', 'flyOutCt', 'dpt_airport='+data_dpt_airport+'&alt=1');
		}
	}
	function setDptAirportAlt(val, text){
		document.getElementById('departureAirportAlt').value = val;
		document.getElementById('formText_dep_airport_alt').innerHTML = text;
		closeFlyOut();
	}
	//EO depart Airport
	//-------------------------------------------------------------------------------	
	
	/********************************************************************************/
	
	/*	 	AJAX BUILD FUNCTIONS 	*/
	
	/********************************************************************************/
	
	
	//getElementposition from target Element
	function getElementPosition(targetElement) {
		var offsetTrail = document.getElementById(targetElement);
		var offsetLeft = 0;
		var offsetTop = 0;
		var offsetarray = new Array();
		while (offsetTrail) {
			offsetLeft += offsetTrail.offsetLeft;
			offsetTop += offsetTrail.offsetTop;
			offsetTrail = offsetTrail.offsetParent;
		}
		if (navigator.userAgent.indexOf("Mac") != -1 && 
			typeof document.body.leftMargin != "undefined") {
			offsetLeft += document.body.leftMargin;
			offsetTop += document.body.topMargin;
		}
		offsetarray = Array(offsetLeft, offsetTop);
	
		return offsetarray;
	}
	
	//define position for target;
	function setElementPosition(targetElement, showElement, left, top){
		offsetarray = getElementPosition(targetElement);
		leftposition = offsetarray[0]+left;
		topposition = offsetarray[1]+top;
		document.getElementById(showElement).style.left = leftposition.toString()+'px';
		document.getElementById(showElement).style.top = topposition.toString()+'px';
	}
	
	//sets Element property 
	function setElementProperty(value, targetElement) {
		//if IE 4+
		if (document.all) {
			eval(targetElement+'.innerHTML = value;');
		//else if NS 4
		} else if (document.layers) {
			eval('document.'+targetElement+'.document.write(value);');
			eval('document.'+targetElement+'.document.close();');
		}
		//else if NS 6 (supports new DOM)
		else if (document.getElementById) {
			rng = document.createRange();
			el = document.getElementById(targetElement);
			rng.setStartBefore(el);
			htmlFrag = rng.createContextualFragment(value);
			while (el.hasChildNodes())
				el.removeChild(el.lastChild);
			el.appendChild(htmlFrag);
		}
	} 
	
	//-----------------------------------------------------------------------------------------------------------------------//
    // A-X-send function //POST
	function writeAjax(fileElement, targetElement, requestUri){
		if (window.ActiveXObject){
			// Internet Explorer
			try {
				xmlHttp = new ActiveXObject("Msxm12.XMLHTTP");
			}
			catch (e){
				
				try {
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {}
			}
		}
		else if (window.XMLHttpRequest){
			// Opera, Firefox
			try {
				xmlHttp = new XMLHttpRequest();
			}
			catch (e) {}
		}
		
		if (xmlHttp){
			xmlHttp.open("POST", fileElement, true);
			xmlHttp.onreadystatechange = function(evt) { 
				if (xmlHttp.readyState == 4){
					setElementProperty(xmlHttp.responseText, targetElement);
				}}	
			xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
			xmlHttp.send(requestUri);
		}
		else {
			setTimeout("writeAjax('"+fileElement+"','"+targetElement+"','"+requestUri+"')",500);
		}

	return(true);
	}