//	FILTRU OFERTE PRIMA PAGINA REQUEST
function filtru_pp_request()
{
	$('#loader').show();
	$('#num_results_link').hide();
	
	dest = $('#destinatie').val();
	per = $('#perioada').val();
	nz = $('#zile').val();
	
	$('#destinatie').empty(); $('#perioada').empty(); $('#zile').empty();
	$('#destinatie').append('<option value="0" >Alegeti destinatia</option>');
	$('#perioada').append('<option value="0" >Alegeti perioada</option>');
	$('#zile').append('<option value="0" >Alegeti numarul de zile</option>');
	$('#destinatie').attr("disabled", true); $('#perioada').attr("disabled", true);  $('#zile').attr("disabled", true);
	
	var url  = "request_nr_oferte-" + dest + "-" + per + "-" + nz + "-" + Math.random() + ".htm";
	$.get(url, "", function(xml) {
		nr_oferte = $("n", xml).text();
		
		$("d", xml).each(function() {
			var id = $(this).attr("v");
			var name = $(this).text();
			
			$('#destinatie').append('<option value="'+ id +'" ' + (dest==id ? 'selected="selected"': '') + '>'+ name +'</option>');
		});
		
		$("p", xml).each(function() {
			var id = $(this).attr("v");
			var name = $(this).text();
			
			$('#perioada').append('<option value="'+ id +'" ' + (per==id ? 'selected="selected"': '') + '>'+ name +'</option>');
		});
		
		$("z", xml).each(function() {
			var id = $(this).attr("v");
			var name = $(this).text();
			
			$('#zile').append('<option value="'+ id +'" ' + (nz==id ? 'selected="selected"': '') + '>'+ name +'</option>');
		});
		
		$('#num_results').text(nr_oferte);	
		
		$('#destinatie').attr("disabled", false); $('#perioada').attr("disabled", false);  $('#zile').attr("disabled", false);
		$('#loader').hide();
		$('#num_results_link').show();	
	});
}

//	PRETURI OFERTA DETALIATA
function get_preturi(id, data) {
	$('#loader_preturi').show();
	$('#tabel_preturi').hide();
	$('#lista_plecari1').hide();
	
	var url  = "return_preturi-" + id + "-" + Math.random() + ".htm";
	
	$.get(url, "", function(xml) {
		var tr1 = '';
		var tr2 = '';
		contor = 1;
		$("cab", xml).each(function() {
			var id = $(this).attr("i");
			var categ = $(this).attr("cat");
			var pret = $(this).text();
			
			while (parseInt(categ)>contor) {
				tr1 += '<td>&nbsp;</td>';
				tr2 += '<td>&nbsp;</td>';
				contor++;
			}
			
			if (parseInt(categ) == contor) {
				tr1 += '<td>De la<br /><strong>&euro; '+pret+'</strong><br />'+data+'</td>';
				tr2 += '<td class="right"><a class="ico arrow noprint" href="rezervare-'+id+'.htm"><span><em>Rezervati &gt;</em></span></a></td>';
			}
			contor ++;
		});
		while (contor<5) {
			tr1 += '<td>&nbsp;</td>';
			tr2 += '<td>&nbsp;</td>';
			contor++;
		}
		$('#preturi_sec1').html(tr1);
		$('#preturi_sec2').html(tr2);
		
		var p1_data = new Array();
		var p2_data = new Array();
		var p3_data = new Array();
		var p4_data = new Array();
		
		$("p", xml).each(function() {
			var id 		= $(this).attr("i");
			var categ 	= $(this).attr("cat");
			var tip 	= $(this).attr("cat");
			var pret 	= $(this).text();
			
			switch (categ) {
				case '1': p1_data.push("<td>"+tip+"</td><td>"+pret+" &euro;/pers</td>"); break;
				case '2': p2_data.push("<td>"+tip+"</td><td>"+pret+" &euro;/pers</td>"); break;
				case '3': p3_data.push("<td>"+tip+"</td><td>"+pret+" &euro;/pers</td>"); break;
				case '4': p4_data.push("<td>"+tip+"</td><td>"+pret+" &euro;/pers</td>"); break;
			}
			
		});
		
		var maxlength = p1_data.length; 
		if (maxlength<p2_data.length) maxlength=p2_data.length;
		if (maxlength<p3_data.length) maxlength=p3_data.length;
		if (maxlength<p4_data.length) maxlength=p4_data.length;

		output_preturi = '<tr><td colspan="3" class="center" style="border:none;"></td></tr><tr><th class="left" style="text-align:center; width:5%;">Tip</th><th class="center" style="width:20%;"><span style="color: #EAEAEA; font-size: 12px;">Categorie</span><br />Interioara</th><th class="center" style="width:5%;">Tip</th><th class="center" style="width:20%;"><span style="color: #EAEAEA; font-size: 12px;">Categorie</span><br />Exterioara</th><th class="center" style="width:5%;">Tip</th><th class="center" style="width:20%;"><span style="color: #EAEAEA; font-size: 12px;">Categorie</span><br />Exterioara cu balcon</th><th class="center" style="width:5%;">Tip</th><th class="right" style="width:20%;"><span style="color: #EAEAEA; font-size: 12px;">Categorie</span><br />Suita</th></tr>';
		
		for (var i=0; i<maxlength; i++) { 
			output_preturi += '<tr class="alt'+(i%2+1)+'">';
			if (p1_data[i]) output_preturi += p1_data[i];
				else output_preturi += '<td>&nbsp;</td><td>&nbsp;</td>';
			if (p2_data[i]) output_preturi += p2_data[i];
				else output_preturi += '<td>&nbsp;</td><td>&nbsp;</td>';
			if (p3_data[i]) output_preturi += p3_data[i];
				else output_preturi += '<td>&nbsp;</td><td>&nbsp;</td>';
			if (p4_data[i]) output_preturi += p4_data[i];
				else output_preturi += '<td>&nbsp;</td><td>&nbsp;</td>';
			output_preturi += '</tr>';
		}
		$('#tabel_p1').html(output_preturi);
		
		data_plecarii = $("dp", xml).text();
		$('#data_plecarii_p1').html(data_plecarii);
				
		
		$('#loader_preturi').hide();
		if (maxlength != 0)
			$('#tabel_preturi').show();
		$('#lista_plecari1').show();
	});
}