//utile.js
define = (function(){
	function toString(name, value){
		return	"const " + name + "=" + (
			/^(null|true|false|(\+|\-)?\d+(\.\d+)?)$/.test(value = String(value)) ? value : '"' + replace(value) + '"'
		)
	};
	var	define, replace;
	try{
		eval("const e=1");
		replace = function(value){
			var	replace = {"\x08":"b","\x0A":"\\n","\x0B":"v","\x0C":"f","\x0D":"\\r",'"':'"',"\\":"\\"};
			return	value.replace(/\x08|[\x0A-\x0D]|"|\\/g, function(value){return	"\\"+replace[value]})
		};
		define = function(name, value){
			var	script = document.createElement("script");
			script.type = "text/javascript";
			script.appendChild(document.createTextNode(toString(name, value)));
			document.documentElement.appendChild(script);
			document.documentElement.removeChild(script);
		}
	}
	catch(e){
		replace = function(value){
			var	replace = {"\x0A":"\\n", "\x0D":"\\r"};
			return	value.replace(/"/g, '""').replace(/\n|\r/g, function(value){return replace[value]}) // "
		};
		define = this.execScript ?
		function(name, value){
			execScript(toString(name, value), "VBScript");
		}:
		function(name, value){
			eval(toString(name, value).substring(6));
		}
	};
	return	define;
})();
try{
define('DOMENIU','www.fly-go.ro/');
define('DOMENIU_FARA_WWW','www.fly-go.ro/');
}
catch(e){

define('DOMENIU','www.fly-go.ro/');
define('DOMENIU_FARA_WWW','www.fly-go.ro/');
}
define('EMAIL_REZERVARI','rezervari@fly-go.ro');
define('EMAIL_REZERVARI_NUME','fly-go.ro');
define('EMAIL_SUBIECT_CERERE_DE_GRUP','Cerere de grup');
define('EMAIL_INFO','info@fly-go.ro');
define('EMAIL_RENT_A_CAR','rent-a-car@fly-go.ro');
define('EMAIL_SUBIECT_RENT_A_CAR','Inchiriere masina cu datele din e-mail');
define('EMAIL_ONLINE','online@fly-go.ro');
define('EMAIL_SUBIECT_REZERVARE','Detalii rezervare fly-go.ro');
define('EMAIL_STEFANO','stefano@fly-go.ro');

try{
var protocol=window.parent.document.location.protocol;
}
catch(e){
	var protocol='http:';
}
var https=1;
if(protocol=='http:'){
	https=0;
}
jQuery.fn.aeroport=function (val_predefinita){
	mm=1;
	if (val_predefinita)mm=0;
	var aurl="https://"+DOMENIU+"pub/php/aero.php";
	if(https==0)aurl="http://"+DOMENIU+"pub/php/aero.php";
	jQuery(this).autocomplete(aurl,
	{ minChars:2,
	 matchSubset:1,
	  matchContains:1,
	   cacheLength:0,
	   formatItem:formatItem,
	    mustMatch:mm,
	    onItemSelect:autocomplete_id,
	    onItemSelectParams:this,
	    selectOnly:true });

	return this;
}



jQuery(function(){
	var aurl="https://"+DOMENIU+"pub/php/aero.php";
	if(https==0)aurl="http://"+DOMENIU+"pub/php/aero.php";
	$('.autocomplete2').fautocomplete(aurl,{
		onSelect:function(data,input){
			data=data.data;
			jQuery('input[name='+input.attr('rel')+']').attr('autocomplete','off');
			jQuery('input[name='+input.attr('rel')+']').val(data[1]);
		}
	});
	var aurl="https://"+DOMENIU+"pub/php/aero_mapamond.php";
	if(https==0)aurl="http://"+DOMENIU+"pub/php/aero_mapamond.php";
	$('.autocomplete3').fautocomplete(aurl,{
		onSelect:function(data,input){
			data=data.data;
			jQuery('input[name='+input.attr('rel')+']').attr('autocomplete','off');
			jQuery('input[name='+input.attr('rel')+']').val(data[1]);
		}
	})
});

function autocomplete_id(li,el){
	if (li.extra) {
		$("#in"+el.attr('id')).val(li.extra[0]);
	}
}

function dep(li) {
	if (li.extra) {
		$("#inDeparture").val(li.extra[0]);
	}
}
function des(li) {
	if (li.extra) {
		$("#inDestination").val(li.extra[0]);
	}
}
jQuery.fn.calendar=function (){
	this.datepicker({
		showAnim: 'show',
		duration:0,
		minDate: "+1d",
		maxDate: "12m",
				numberOfMonths: 2,
		beforeShow: customRange,
		showOn: "focus",
		firstDay: "1",
		dateFormat: "dd-mm-yy"

	});
	return this;
}
jQuery.fn.calendar2=function (){
	this.datepicker({
		showAnim: 'fadeIn',
		minDate: "+1d",
		maxDate: "12m",numberOfMonths: 2,
		duration:0,
		beforeShow: customRange,
		showOn: "focus",
		firstDay: "1",
		dateFormat: "dd-mm-yy"

	});
	return this;
}
$j(
function(){

	$j('.modal').click(function(){

		modal(this); return false;});

		$j("#drp_arr").bind('click',function(e){
			if ($j('#drpdwn').is(':hidden')){
				$j('#drpdwn').slideDown('slow')
			}else{
				$j("#drpdwn").slideUp();
			}
		})

		$j("#drpdwn_st a").bind('click',function(e){
			if ($j('#drpdwn').is(':hidden')){
				$j('#drpdwn').slideDown('slow')
			}else{
				$j("#drpdwn").slideUp();
			}
			return false;
		})
});
var dialog_modal=$(document.createElement("div"));
function modal(a) {
	$j('#harta_sss').remove();
	$j('div[role=dialog]').remove();
	dialog_modal.remove();
	dialog_modal=$(document.createElement("div"));
	dialog_modal.attr('title',$j(a).attr('title'));
	$j('select').css('visibility','hidden');
	$j('object').css('visibility','hidden');


	dialog_modal.dialog({
		title:a.title,
		width:700,
		height:500,
		autoOpen:true,
		modal: false,
		bgiframe:true,
		draggable:false,
		remove_me:true,
		close: function() {

			$j('select').css('visibility','visible');
			$j('object').css('visibility','visible');


		} ,
		buttons:{
		'Ok': function() {
			$j(this).dialog('destroy');
			$j('select').css('visibility','visible');
			$j('object').css('visibility','visible');

		}
		}
	}).html('<center>Se incarca detaliile.<br /><br /><img src="pub/img/ajax-loader-hotel.gif" /></center>').load(a.href,'',function(){
		$(this).find("img.gal").css('cursor','help').tooltip({
    bodyHandler: function() {
        return "<img height='300' src='"+$(this).attr('src')+"' />";
    },
    showURL: false,
	delay: 0,
	opacity: 1,
	track: true
});
		});

}

function init_cerere_grup(el){
	$j('#aeroport_plecare').aeroport();
	$j('#aeroport_destinatie').aeroport();
	$j('#data_dus').calendar2();
	$j('#data_intoarcere2').calendar2();
}

function customRange(input) {
	dateMin = $("#startDate").datepicker("getDate");
	var azi= new Date();
	var rangeStart = new Date(azi.getFullYear(), azi.getMonth(), azi.getDate()+1);
	if(input.id == "startDate"){
		return {minDate: rangeStart,maxDate: null};
	}
	if(input.id == "endDate" && dateMin){
		var rangeMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate());
		return {minDate: rangeMax,
		maxDate: null};
	}
}
function formatItem(row) {
	return row[0] + " - <i>" + row[1] + "</i>";
}

$(document).ready(function() {

	$("#departure").aeroport();
	$("#destination").aeroport();
	$("#destination_top").aeroport(1);
	$("#departure_top").aeroport(1);

	$("#startDate,#endDate").calendar();

	$("#startDateIcon").click ( function(){ $("#startDate").focus(); });
	$("#endDateIcon").click ( function(){ $("#endDate").focus(); });

	$("#startDate").datepicker({
		minDate: "+1d",
		maxDate: "12m",
		numberOfMonths: 2,
		showOn: "both",
		dateFormat: "dd-mm-yy"
	});
	$("#startDate,#endDate").datepicker({
		//defaultDate: +1,
		numberOfMonths: 2,
		     maxDate: "12m",
		beforeShow: customRange,
		showOn: "both",
		dateFormat: "dd-mm-yy"
	});
});

function show_auto()
{

if(fara_autocomplete!=1)
{

	$("#departure").aeroport();
	$("#destination").aeroport();
	$("#destination_top").aeroport(1);
	$("#departure_top").aeroport(1);
	fara_autocomplete=0;
}
}

function afisare_data(id) {
	container=document.getElementById(id);
	container.style.visibility='visible';
}

function ascundere_data(id) {
	container=document.getElementById(id);
	container.style.visibility='hidden';
	data=document.getElementById('endDate');
	data.value='';


}
function detalii_taxe() {
	alert("Taxele biletului cuprind:\n- Taxe guvernamentale\n- Taxe aeroport\n- Control bagaje\n- Securitate\n- Agency handling fee");
}
function asigurare() {
	$('#cu_asigurare').toggle();
	$('#fara_asigurare').toggle();

}
$(function () {
  $('.bubbleInfo').each(function () {
    // options
    var distance = 10;
    var time = 150;
    var hideDelay = 0;

    var hideDelayTimer = null;

    // tracker
    var beingShown = false;
    var shown = false;
    
    var trigger = $('.trigger', this);
    var popup = $('.popup', this).css('opacity', 0);

    // set the mouseover and mouseout on both element
    $([trigger.get(0), popup.get(0)]).mouseover(function () {
      // stops the hide event if we move from the trigger to the popup element
      if (hideDelayTimer) clearTimeout(hideDelayTimer);

      // don't trigger the animation again if we're being shown, or already visible
      if (beingShown || shown) {
        return;
      } else {
        beingShown = true;

        // reset position of popup box
        popup.css({
          top:  -60,
          left: 0,
          display: 'block' // brings the popup back in to view
        })

        // (we're using chaining on the popup) now animate it's opacity and position
        .animate({
          top: '-=' + distance + 'px',
          opacity: 1
        }, time, 'swing', function() {
          // once the animation is complete, set the tracker variables
          beingShown = false;
          shown = true;
        });
      }
    }).mouseout(function () {
      // reset the timer if we get fired again - avoids double animations
      if (hideDelayTimer) clearTimeout(hideDelayTimer);
      
      // store the timer so that it can be cleared in the mouseover if required
      hideDelayTimer = setTimeout(function () {
        hideDelayTimer = null;
        popup.animate({
          top: '-=' + distance + 'px',
          opacity: 0
        }, time, 'swing', function () {
          // once the animate is complete, set the tracker variables
          shown = false;
          // hide the popup entirely after the effect (opacity alone doesn't do the job)
          popup.css('display', 'none');
        });
      }, hideDelay);
    });
  });
});


