
function ajax_calculeaza_recomandari(id, data_plecare, data_intoarcere, from, to, price, today, txt_search, type){
	//check dates
	var split_dep_date = data_plecare.split('-');
	var split_date_today = today.split('-');
	var dep_date = new Date(split_dep_date[2], split_dep_date[1], split_dep_date[0]);
	var today_date = new Date(split_date_today[2], split_date_today[1], split_date_today[0]);

	if(type=="dus-intors"){
		var split_ret_date = data_intoarcere.split('-');
		var ret_date = new Date(split_ret_date[2], split_ret_date[1], split_ret_date[0]);
	}

	//cell id
	var elem = '#recom_'+id;

	//comma to period conversion;
	price = price.replace(",",".");
	price = parseFloat(price);

	//check if date is in the past or if such route is not valid
	if(type=='dus-intors'){
		if(dep_date < today_date || dep_date >= ret_date){
			//gray it out
			$(elem).addClass("disabled");
			//there is no need for the ajax call
			return;
		}
	}else{ // flight is one-way
		if(dep_date < today_date){
			//gray it out
			$(elem).addClass("disabled");
			//there is no need for the ajax call
			return;
		}
	}

	//add loading indicator
	$(elem).addClass("loading");

    $.ajax({
        type: 'POST',
        url: 'zboruri/ajax_recomandari',
        data:{
              idTd:id,
              dplecare:data_plecare,
              dintoarcere:data_intoarcere,
              aeroport_plecare:from,
              aeroport_sosire:to,
			  flight_type:type
            },
        dataType: 'html',

        beforeSend: function() {
        //$('#loader').show();
        },
        success: function(response) {
			//data received, set common elements
			$(elem).removeClass("loading");
			$(elem).attr("onclick", "ajax_recomandari_form('" + data_plecare + "','" + data_intoarcere + "')");
			$(elem).addClass('link');

			//check if anything
			if(response == null || response <=0){
				//no valid reply or zero price
				$(elem+" span").html(txt_search);
			}else if(response > 0){
				//prep response
				response = response.replace(",",".");
				response = parseFloat(response);

				//display it
				$(elem+" span").html(response+" &euro;");

				//price received, check if we have what to compare it to
				if(price == null || price == 0){
					//default to same (equal) price
					$(elem).addClass('same');
				}else{
					//got a valid response, compare it to the baseline price
					if(response > price){
						//price is steeper
						$(elem).addClass('pricier');
					}else if(response < price){
						//price is cheaper
						$(elem).addClass('cheaper');
					}else{
						//price is equal
						$(elem).addClass('same');
					}
				}
			}
        },
        error:function(xhr, status, errorThrown) {
            //$('#loader').hide();
            //alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
			$(elem).removeClass("loading");
        }
    });
}

function ajax_recomandari_form(data_plecare, data_intoarcere){
    $('#startDate').val(data_plecare);
	if(data_intoarcere){
		$('#endDate').val(data_intoarcere);
		//$("#dusIntorsRadio").attr("checked", true);
	}else{
		//$("#numaiDusRadio").attr("checked", true);
	}
    //$('#form_src').submit();
	if(verifica_cautare(document.getElementById('form_src')))
		document.getElementById('form_src').submit();
}
