// purchase
function fill_destionation_code(){
  document.getElementById('destination_code').value = document.getElementById('destination_name').value;
}
function fill_destionation_name(){
  var a=document.getElementById('destination_code').value;
  a=a.toUpperCase();
  var res=false;
  for (i=0;i<document.getElementById('destination_name').length;i++)
  {
    if (a == document.getElementById('destination_name').options(i).value )
      {
      document.getElementById('destination_name').options(i).selected = true;
      res=true;
      }
  }
  if(!res) {
    alert('For the entered code was not found any airport. Please, try to enter the code again or you can choose the airport from the selection below.');
    document.getElementById('destination_name').options(0).selected = true;
    document.getElementById('destination_code').focus();
  }
  else{
    return;
  }

}
function check_register_purchase(){
  if(document.getElementById('departure_day').value==0){
    alert('Please, enter the departure date.');
    document.getElementById('departure_day').focus();
    return false;
  }
  if(document.getElementById('departure_month').value==0){
    alert('Please, enter the departure month.');
    document.getElementById('departure_month').focus();
    return false;
  }
  
  date_verify = new Date(document.getElementById('departure_year').value, (document.getElementById('departure_month').value-1), document.getElementById('departure_day').value);
  date_verify = date_verify.getFullYear()+''+(date_verify.getMonth()+1)+''+date_verify.getDate();
  date_input = document.getElementById('departure_year').value+Math.ceil(document.getElementById('departure_month').value)+Math.ceil(document.getElementById('departure_day').value);
  if(date_verify!=date_input){
    alert('Incorect departure data format.');
    //alert(date_verify);
    //alert(date_input);
    return false;
  }
  
  if(document.getElementById('departure_hour').value=='0'){
    alert('Please, enter the departure time.');
    document.getElementById('departure_hour').focus();
    return false;
  }
  if(document.getElementById('departure_minute').value=='0'){
    alert('Please, enter the appprox. departure minute.');
    document.getElementById('departure_minute').focus();
    return false;
  }
  
  if(document.getElementById('destination_name').value==0){
    alert('Please, enter the destination airport for the flight from Prague.');
    document.getElementById('destination_name').focus();
    return false;
  }
  if(document.getElementById('terminal').value==0){
    alert('Please, enter the departure terminal.');
    document.getElementById('terminal').focus();
    return false;
  }
  
  if(document.getElementById('pickup_hour').value==0){
    alert('Please, enter the approx. pick up hour.');
    document.getElementById('pickup_hour').focus();
    return false;
  }
  if(document.getElementById('pickup_minute').value=='0'){
    alert('Please, enter the approx. pick up minute.');
    document.getElementById('pickup_minute').focus();
    return false;
  }
  
  if(document.getElementById('email').value.length==0){
    alert('Please, enter the e-mail address for the order confirmation.');
    document.getElementById('email').focus();
    return false;
  }
  else{
    if(!isEmail(document.getElementById('email').value)){
	    alert('The format of e-mail address for the order confirmation is not valid.');
	    document.getElementById('email').focus();
	    return false;
    }
  }
  
  now = new Date;
  //alert(now.toString());
  departure = new Date(document.getElementById('departure_year').value, (document.getElementById('departure_month').value-1), document.getElementById('departure_day').value, document.getElementById('pickup_hour').value, document.getElementById('pickup_minute').value);
  //alert(departure.toString());
  difference = departure.getTime() - now.getTime();
  difference_hours = Math.floor(difference / (1000*60*60));
  //alert(difference_hours);
  if(difference_hours<12){
    alert('The purchase can be prepared only after minimum 12 hours from the time, when the order will be send.');
    return false;
  }
  if(difference_hours<13){
    return confirm('The purchase can be prepared only after minimum 12 hours from the time, when the order will be send.');
    //return false;
  }
  
  return true;
}
function confirm_purchase_cancel(){
  return confirm('Are you sure to cancel your flight registration and your order?');
}
function confirm_purchase_send(){
  return confirm('After sending the order you can not add any more products. To add more products you will have to start new order than. Are you sure to finish your purchase and send the order now?');
}
