function open_fly_date_from(d,t){
	$('fly_date_from').show();
	$('fly_date_to').hide();
	$('fly_date_from').style.top=Position.page($('fly_date_from_pos'))[1]+50;
	$('fly_date_from').style.left=Position.page($('fly_date_from_pos'))[0]-50;
	new Ajax.Updater('fly_date_from_c', '/index.php?p=calendar&date='+d+'&type='+t);
}

function valid_fly_date_to(){
	
	var df = $('date_from').value.split(".");
	var dt = $('date_to').value.split(".");
	
	if(Date.UTC(df[2], df[1], df[0]) > Date.UTC(dt[2], dt[1], dt[0])){
		var Zeit = new Date();	
		var AbsolutDann = Date.UTC(df[2], df[1], df[0]) + (7 * 24 * 60 * 60 * 1000);
		Zeit.setTime(AbsolutDann);
		var Jahr = Zeit.getFullYear();
		var Monat = Zeit.getMonth();
		var Tag = Zeit.getDate();
		if(Tag<10) Tag='0'+Tag;
		if(Monat<10) Monat='0'+Monat;
		$('date_to').value=Tag+'.'+Monat+'.'+Jahr;
	}
}

function open_fly_date_to(d,t){
	$('fly_date_to').show();
	$('fly_date_from').hide();
	$('fly_date_to').style.top=Position.page($('fly_date_to_pos'))[1]+50;
	$('fly_date_to').style.left=Position.page($('fly_date_to_pos'))[0]-50;
	new Ajax.Updater('fly_date_to_c', '/index.php?p=calendar&date='+d+'&type='+t);
}

function open_fly_code_from(){
	
	$('from_code').show();
	$('to_code').hide();
	$('from_code').style.top=Position.page($('from_code_pos'))[1]+10;
	$('from_code').style.left=Position.page($('from_code_pos'))[0]+10;
	
	if($('from').value.length>=3){
		new Ajax.Updater('from_code', '/index.php?p=search_fly_code&q='+$('from').value);
	} else {
		$('from_code').hide();
	}
}

function open_fly_code_to(){
	
	$('to_code').show();
	$('from_code').hide();
	$('to_code').style.top=Position.page($('to_code_pos'))[1]+10;
	$('to_code').style.left=Position.page($('to_code_pos'))[0]+10;
	
	if($('to').value.length>=3){
		new Ajax.Updater('to_code', '/index.php?p=search_fly_code&q='+$('to').value);
	} else {
		$('to_code').hide();
	}
}

function set_fly_code(q,iso){
		
	if($('from_code').visible()){
		$('from_code').hide();
		$('from').value=q;
		$('c_from').src='/images/iso/'+iso+'.png';
	} else {
		$('to_code').hide();
		$('to').value=q;
		$('c_to').src='/images/iso/'+iso+'.png';
	}
}

function set_from_iso(code){
    
    new Ajax.Request('/set_from_iso.php?code=' +code, {
        method: 'get',
        onComplete: function(resp) {
          if(String(resp.responseText).length>0) {
          	$('c_from').src='/images/iso/'+resp.responseText+'.png';
          
         }
        }
      });
}

function set_to_iso(code){
		
    new Ajax.Request('/set_to_iso.php?code=' +code, {
        method: 'get',
        onComplete: function(resp) {
          if(String(resp.responseText).length>0) {
         
          	$('c_to').src='/images/iso/'+resp.responseText+'.png';
          
         }
        }
      });
}

function cdtime(container, targetdate, curdate){
if (!document.getElementById || !document.getElementById(container)) return
this.container=document.getElementById(container)
this.currentTime=new Date(curdate)
this.targetdate=new Date(targetdate)
this.timesup=false
this.updateTime()
}

cdtime.prototype.updateTime=function(){
var thisobj=this
this.currentTime.setSeconds(this.currentTime.getSeconds()+1)
setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
}

cdtime.prototype.displaycountdown=function(baseunit, functionref){
this.baseunit=baseunit
this.formatresults=functionref
this.showresults()
}

cdtime.prototype.showresults=function(){
var thisobj=this


var timediff=(this.targetdate-this.currentTime)/1000 //difference btw target date and current date, in seconds
if (timediff<0){ //if time is up
this.timesup=true
this.container.innerHTML=this.formatresults()
return
}
var oneMinute=60 //minute unit in seconds
var oneHour=60*60 //hour unit in seconds
var oneDay=60*60*24 //day unit in seconds
var dayfield=Math.floor(timediff/oneDay)
var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour)
var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute)
var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute))
if (this.baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level
hourfield=dayfield*24+hourfield
dayfield="n/a"
}
else if (this.baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level
minutefield=dayfield*24*60+hourfield*60+minutefield
dayfield=hourfield="n/a"
}
else if (this.baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level
var secondfield=timediff
dayfield=hourfield=minutefield="n/a"
}
this.container.innerHTML=this.formatresults(dayfield, hourfield, minutefield, secondfield)
setTimeout(function(){thisobj.showresults()}, 1000) //update results every second
}

function blink() {
  var obj = document.getElementById("blinker").style;
  if(obj.visibility == "visible") {
    obj.visibility = "hidden";
  }
  else {
    obj.visibility = "visible";
  }
  window.setTimeout(blink, 500);
}

function clearbox(inputbox) {
	if (document.getElementById(inputbox).value != "") document.getElementById(inputbox).value = "";
	//if (document.getElementById(inputbox).value != "") document.getElementById(inputbox).value = "";
}

function hinflug(hinflug) {
	//var radiohinflug = document.getElementById("flyback"); 
	//alert (radiohinflug.value);
	if (hinflug == 1) document.getElementById("hinflug").style.display   = 'none';
	else if (hinflug == 0) document.getElementById("hinflug").style.display   = 'table';
}

