function hotelsSearch(){
	researchBy($('#categoria')[0].value, $('#localita')[0].value, $('#parent_loc')[0].value);
}

function researchBy(category_id, location_id, parent_id){
	$('#hotelListing').html('Caricamento in corso ..');
	$.ajax({
				type: "GET",
				url: "/hotel_list.php?cat="+category_id+"&loc="+location_id+"&parent="+parent_id,
				dataType: "html",
				cache: false,
				success: function(html) {
					$('#hotelListing').html(html);
				}
			});
}

function hotelRooms(){
	$('#theContent').html($('#roomsDescription').html());
}

function hotelGallery(){
	$('#theContent').html($('#hotelGallery').html());
}

function hotelLocation(){
	$('#theContent').html('');
	$('#hotelImage').html($('#locationInfo').html());
//	$('#locationInfo').show();
}

function hotelPrices(){
	$('#theContent').html($('#hotelPrice').html());
}

function hotelDescription(){
	$('#theContent').html($('#hotelDescription').html());
}


function initMap(latitude, longitude, zoom, mapDiv){
	if (GBrowserIsCompatible()) {
		map = new GMap2(mapDiv);
		map.setMapType(G_HYBRID_MAP);
		myPoint = new GLatLng(latitude, longitude);
		map.setCenter(myPoint, zoom);
		map.addControl(new GLargeMapControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT));
		map.addControl(new GMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_LEFT));
		markTheSpot(myPoint);
	}
}

function markTheSpot(clickedPoint){
	marker = new GMarker(clickedPoint,{draggable:false, autoPan:false});
	map.addOverlay(marker);
	marker.setImage("http://maps.google.com/mapfiles/marker.png");
}

function showTheMap(){
theDiv = document.getElementById('mapContainer');
	if (mapOnline == 0)
	{
		theDiv.innerHTML = '<div id="mapLayer"></div>';
		mapDiv = document.getElementById("mapLayer");
		initMap(latitude,longitude,13,mapDiv);
		mapOnline = 1;
	}
	else
	{
		theDiv.innerHTML = '';
		mapOnline = 0;
	}
}

function changeHotelImage(source){
	$('#hotelImage').html('<img src="http://www.italiatravelweb.it/image.php?image='+source+'&w=450&h=321&method=crop" border="0"/>');
}

function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false;
		 }

 		 return true;					
	}


function chkform()
{
	var formchk=0;
	var error_msg='';
	var form_dal = $('#gg_arrivo')[0].value+"/"+$('#mm_arrivo')[0].value+"/"+$('#yy_arrivo')[0].value;
	var form_al = $('#gg_partenza')[0].value+"/"+$('#mm_partenza')[0].value+"/"+$('#yy_partenza')[0].value;
	accept=document.getElementById("privacy");
	if (accept.checked==false)
	{
		formchk=formchk+1;
		error_msg="* Bisogna leggere ed accettare l\'informativa sulla privacy per continuare\n";
	}

	if (document.getElementById('nome').value.length < 3 || document.getElementById('nome').value.length > 10)
	{
		formchk=formchk+1;
		error_msg=error_msg+'* Nome inserito non valido\n';
	}

	if (document.getElementById('cognome').value.length < 3 || document.getElementById('cognome').value.length > 10)
	{
		formchk=formchk+1;
		error_msg=error_msg+'* Nome inserito non valido\n';
	}

	if (echeck(document.getElementById('email').value)==false)
	{
		formchk=formchk+1;
		error_msg=error_msg+'* E-Mail non valida\n';
	}

	if (form_dal.length>=8 && form_al.length>=8)
	{
		today=new Date();
		var txt_ar=form_dal;
		array_ar=txt_ar.split('/');
		chk_ar_date=new Date(array_ar[2],array_ar[1]-1,array_ar[0]);
		var txt_par=form_al;
		array_par=txt_par.split('/');
		chk_par_date=new Date(array_par[2],array_par[1]-1,array_par[0]);
		
		if (chk_ar_date<today)
		{
			formchk=formchk+1;
			error_msg=error_msg+'* Non e\' possibile specificare una data di arrivo precedente alla data odierna\n';
		}
	
		if (chk_par_date<chk_ar_date)
		{
			formchk=formchk+1;
			error_msg=error_msg+'* Non e\' possibile specificare una data di partenza precedente alla data di arrivo\n';
		}
	}
	else
	{
		formchk=formchk+1;
		error_msg=error_msg+'* Bisogna specificare una data di arrivo ed una di partenza\n';
	}
	
	if (document.getElementById('persone').value==0)
	{
		formchk=formchk+1;
		error_msg=error_msg+'* Non e\' stato specificata alcuna persona\n';
	}
	
	if (document.getElementById('camere').value==0)
	{
		formchk=formchk+1;
		error_msg=error_msg+'* Non e\' stata specificata alcuna camera\n';
	}

	if (formchk!=0)
	{
		alert('Non e\' possibile effettuare la richiesta a causa dei seguenti errori:\n\n'+error_msg);
	}
	else
	{
		$('#disponibilita_form')[0].submit();
	}
}

function checkaggiungi(){
	if ($('#nome')[0].value == '' || $('#nome_persona')[0].value == '' || $('#cognome')[0].value == '' || $('#ruolo')[0].value == '' || $('#ragsoc')[0].value == '' || $('#indirizzo')[0].value == '' || $('#piva')[0].value == '' || $('#telefono')[0].value == '' || $('#email')[0].value == '' || $('#localita')[0].value == '' || $('#categoria')[0].value == '' || $('#website')[0].length <= '7')
	{
		alert('Non tutti i campi sono stati compilati, impossibile procedere');
		return false;
	}
	else
	{
		return true;
	}
}
