$(function(){
	var desde;
	var hasta;
	var galletita=document.cookie.split(';');
	var hoy=new Date();
	hoy.setDate(hoy.getDate());
	var desde=$.datepicker.formatDate('yy-mm-dd', hoy);
	hoy.setDate(hoy.getDate()+1);
	var hasta=$.datepicker.formatDate('yy-mm-dd', hoy);
	for(key in galletita){
		var temp=galletita[key].replace(/^\s*|\s*$/g,"");
		var temp=temp.split('=');
		if (temp[0]=='desde'){
			desde=temp[1];
		}else if (temp[0]=='hasta'){
				hasta=temp[1];
		}
	}
	var url=/(?:apartamento)|(?:hotel)|(?:villas)|(?:bungalows)|(?:oferta)|(?:suite-hotel)|(?:gran-hotel)|(?:aparthotel)|(?:casa-rural)|(?:club)|(?:hostal)|(?:pension)-(.*)/.exec(document.URL)
	var hotel=url[1];
	var intervalo=($.datepicker.parseDate('yy-mm-dd', hasta)-$.datepicker.parseDate('yy-mm-dd', desde))/86400000 ;
	$("#botonactualizar").click(function(){
		document.location.reload();
	});	
	$("#reservar").click(function(){
		var queryhabitaciones='';
		var hayalgunahabitacion = false;
		$(".scantidad").each(function(){
			if (this.value>0){
				hayalgunahabitacion=true;
				queryhabitaciones+="nr_rooms_"+this.id+"="+this.value+"&";
			}
		});
		if(hayalgunahabitacion){
			queryhabitaciones+="aid=315627&hotel_id="+jidhotel+"&checkin="+desde+"&interval="+intervalo;
			$('#formulario').attr("action","https://secure.booking.com/book.html?"+(queryhabitaciones)+"&stage=1&hostname=www.booking.com&label=XMLCANARIAS");
		}else{
			$('#errormayor').text('Error: Debe seleccionar la cantidad de habitaciones que desea');
			return false;
		}
});	

});
