// JavaScript Document
function changeAvailability()	{	
	
	var am_nights,s, f = document.searchform_index;
	var id_city = 4; //Medellin
	var id_hotel = 635; 
	var valAdultos = $('#num_adults').val();
	var valNinos= $('#num_kids').val();
	var valHabitaciones = $('#num_rooms').val();

	if($('#start-date').val()!="" && $('#end-date').val()!="" && $('#start-date').val()!="aaaa - mm - dd" && $('#end-date').val()!="dd - mm - aaaa") {
		console.log(" fecha final "+$('#end-date').val());
		am_nights = DateDiff($('#start-date').val(), $('#end-date').val());
		o = $('#start-date').val();
	    if (o!=''){
		
			month = o.split('-');
			day=month[2];
			year = month[0];
			month = month[1];
	    }else{
			day = 0;
			year = 0;
			month = 0;
	    }
	}
	else {
		
		am_nights= 0;
		day = 0;
		year = 0;
		month = 0;
	}
		//Envío de parámetros a la Central de Reservas
	s = 'http://www.reservashoteleras.com.co/public/search_hotel_dtl.asp?h='+id_hotel+'&di='+id_hotel+'&c='+id_city+'&sl=1&yad='+day+'&htnom='+month+'&raey='+year+'&sthgin='+am_nights+'&smoor='+parseInt(valHabitaciones)+'&stluda='+parseInt(valAdultos)+'&nerdlihc='+parseInt(valNinos)+'&cca=H&popup=1&emarfi_ni=0';
	console.log(s);	
	document.location.href = s;
	
}

function getNewAvailability()	{
	console.log("otra funcion");
	
	var pos;
	var o, s;

	// split month and year
	o = $('#start-date').val();
	if (o!=''){
		
		month = o.split('-');
		day=month[2];
		year = month[0];
		month = month[1];
	}else{
		day = 0;
		year = 0;
		month = 0;
	}

}

function DateDiff(fechamenor, fechamayor) {
	var substr = fechamenor.split('-');
	var objFechaMe = new Date(substr[0],(substr[1]-1), substr[2]);
	
	substr = fechamayor.split('-');
	var objFechaMa = new Date(substr[0],(substr[1]-1), substr[2]);
	
	var diferencia = objFechaMa.getTime() - objFechaMe.getTime();  
    var dias = Math.floor(diferencia/(1000 * 60 * 60 * 24));
	return dias;
}
