var vent = false;
var reservando = false;
function selectCalendarCell(element,date,color) {
$(element).style.background ='white';
 var aleatorio=Math.random();
	var text ="His ckeck in date is selected "+date+" \nSelect ckeck out date";
	if ($('checkin').value == "") {
		text ="His ckeck in date is selected "+date+" \nSelect ckeck out date";
		//$('fechas').innerHTML="";
		new Ajax.Updater('fechas', 'rpc_ing.php', {method: 'post', postBody: 'action=generar_fecha_inicio&fecha_inicio='+date+'&aleatorio='+aleatorio});
		$('checkin').value = date;
		$('checkout').value = "";
		alert(text);
		//$(element).style.background="blue";
		
	} else if ($('checkout').value != "") {
		text ="His ckeck in date is selected "+date+" \nSelect ckeck out date";
		alert(text);
		new Ajax.Updater('fechas', 'rpc_ing.php', {method: 'post', postBody: 'action=generar_fecha_inicio&fecha_inicio='+date+'&aleatorio='+aleatorio});
		$('checkin').value = date
		$('checkout').value = ""
	

	} else {
		text ="His ckeck out is selected "+date;
		$('checkout').value = date
		new Ajax.Updater('fechas', 'rpc_ing.php', {method: 'post', postBody: 'action=generar_fecha_fin&fecha_fin='+date+'&aleatorio='+aleatorio});
		alert(text);
		cargando_cal();
		new Ajax.Updater('calendarInternal', 'rpc_ing.php', {method: 'post', postBody: 'action=startCalendar&month='+$('month').value+'&year='+$('year').value+'&aleatorio='+aleatorio});
		
	}

	
		
}
function startCalendar(month, year) {
	var aleatorio=Math.random();
	$('reserva').innerHTML ="";
	$('month').value = month;
	$('year').value = year;
	cargando_cal();
	new Ajax.Updater('calendarInternal', 'rpc_ing.php', {method: 'post', postBody: 'action=startCalendar&month='+month+'&year='+year+'&aleatorio='+aleatorio});
}
function borrar_fechas() {
 var aleatorio=Math.random();
if (vent) {
vent.close();
Element.remove($('lbLoadMessage'));
}
	$('reserva').value ="";
	$('checkin').value = "";
	$('checkout').value = "";
	cargando_cal();
	new Ajax.Updater('fechas', 'rpc_ing.php', {method: 'post', postBody: 'action=borrar_fechas&month='+$('month').value+'&year='+$('year').value+'&aleatorio='+aleatorio});
	cargando_cal();
	var nu = new Ajax.Updater('calendarInternal', 'rpc_ing.php', {method: 'post', postBody: 'action=startCalendar&month='+$('month').value+'&year='+$('year').value+'&aleatorio='+aleatorio});
	
}
function reservar() {
	$('reserva').value ="";
		if (confirm('Esta seguro que desea reservar')){
		new Ajax.Updater('reserva', 'rpc_ing.php', {method: 'post', postBody: 'action=reservar'});
		}
	borrar_fechas(); 
}
function pre_reservar() {
//bod 				= document.getElementsByTagName('body')[0];
bod 				= document.getElementsByClassName('calendarBox')[0];
	overlay 			= document.createElement('div');
	overlay.id		= 'overlay';
	lb					= document.createElement('div');
	lb.id				= 'lightbox';
	lb.className 	= 'loading';
	lb.innerHTML	= '<div id="lbLoadMessage">' +
						  '<center><p style="margin-top:200px">BOOK</p><p ><a href="javascript:borrar_fechas();">Change dates</a></p></center>' +
						  '</div>';
	bod.appendChild(overlay);
	bod.appendChild(lb);
vent=window.open('form_reservar_ing.php','','width=770,height=600,scrollbars=yes,resizable=yes,status=yes,menubar=no,location=no');

}
function cargando_cal () {
$('calendarInternal').style.height  ="500px";
$('calendarInternal').style.background ="#F0AE01";
$('calendarInternal').innerHTML = '<center><img src="images/loading.gif" width="32" height="32" style="margin-top:200px" /><br/>Loading...</center>';
}
