
var Reservation = {
	language: "es",
	showError: function(msg){
		if($("error_messages").visible()==false){
			new Effect.Appear("error_messages", {duration:0.5});
		}
		$("error_messages").update(msg);
		window.setTimeout(function(){
			new Effect.Fade("error_messages");
		}, 5000);
	},
	saveCustomerData: function(){
		//this.value = "Volver a Buscar";
		if($F("documento").strip()==""){
			new Reservation.showError("Por favor indique su número de identificaci&oacute;n");
			$("documento").activate();
			return;
		};
		if($F("nombre").strip()==""){
			new Reservation.showError("Por favor indique su nombre");
			$("nombre").activate();
			return;
		};
		if($F("telefono_fijo").strip()==""){
			new Reservation.showError("Por favor indique su tel&eacute;fono fijo");
			$("telefono_fijo").activate();
			return;
		};
		if($F("telefono_movil").strip()==""){
			new Reservation.showError("Por favor indique su tel&eacute;fono m&oacute;vil");
			$("telefono_movil").activate();
			return;
		};
		if($F("direccion").strip()==""){
			new Reservation.showError("Por favor indique su direcci&oacute;n");
			$("direccion").activate();
			return;
		};
		if($F("nom_ciudad").strip()==""){
			new Reservation.showError("Por favor indique su ciudad");
			$("nom_ciudad").activate();
			return;
		};
		if($F("email").strip()==""){
			new Reservation.showError("Por favor indique su e-mail");
			$("email").activate();
			return;
		} else {
			var filter = /^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/
			if(filter.test($F("email"))==false){
				new Reservation.showError("Por favor indique un e-mail valido");
				$("email").activate();
				return;
			} else {
				if($F("email")!=$F("confirm_email")){
					new Reservation.showError("El e-mail de confirmaci&oacute;n no es igual al e-mail ingresado");
					$("email").activate();
					return;
				}
			}
		};
		//this.disable();
		new Ajax.Request(Utils.getKumbiaURL("availability/saveReservation"), {
			parameters: {
				tipo_documento: $F("tipo_documento"),
				documento: $F("documento"),
				nombre: $F("nombre"),
				telefono_fijo: $F("telefono_fijo"),
				telefono_movil: $F("telefono_movil"),
				email: $F("email"),
				direccion: $F("direccion"),
				ciudad: $F("nom_ciudad"),
				observacion: $F("observaciones")
			},
			onLoading: function(){
				$('spinner').show();
				$("tipo_documento").disable();
				$("documento").disable();
				$("nombre").disable();
				$("telefono_fijo").disable();
				$("telefono_movil").disable();
				$("email").disable();
				$("direccion").disable();
				$("nom_ciudad").disable();
				$("observaciones").disable();
			},
			onSuccess: function(transport){
				$('spinner').hide();
				$("hotel_info").update(transport.responseText);
			}
		});
	},
	saveData: function(element){
		if($F("nombre").strip()==""){
			new Reservation.showError("Por favor indique su nombre");
			$("nombre").activate();
			return;
		};
		if($F("telefono").strip()==""){
			new Reservation.showError("Por favor indique su tel&eacute;fono");
			$("telefono").activate();
			return;
		};
		if($F("email").strip()==""){
			new Reservation.showError("Por favor indique su e-mail");
			$("email").activate();
			return;
		};
		new Ajax.Request(Utils.getKumbiaURL("availability/storeInfo"), {
			onLoading: function(){
				$("nombre").disable();
				$("telefono").disable();
				$("email").disable();
				element.disable();
			},
			parameters: {
				nombre: $F("nombre"),
				telefono: $F("telefono"),
				email: $F("email")
			},
			onSuccess: function(transport){
				$("hotel_info").update(transport.responseText);
			}
		});
	},
	searchAvalibility: function(){
		if(Reservation.language=="es"){
			this.value = "Volver a buscar";
		} else {
			this.value = "Find Again";
		}
		if($F("hotel")=="@"){
			alert("No ha seleccionado el hotel");
			$(element).enable();
			return;
		};
		if($F("adultos")==""){
			$("adultos").value = 0;
		}
		if($F("ninos")==""){
			$("ninos").value = 0;
		}
		if((parseInt($F("adultos"))+parseInt($F("ninos")))==0){
			$("adultos").value = 1;
		}
		if(Prototype.Browser.IE){
			hotel_name = $("hotel").options[$("hotel").selectedIndex].innerText;
		} else {
			hotel_name = $("hotel").options[$("hotel").selectedIndex].text;
		}
		new Ajax.Request(Utils.getKumbiaURL()+"availability/searchAvalibility", {
			parameters: {
				hotel: $F("hotel"),
				fecha_inicial: $F("id_fecini"),
				fecha_final: $F("id_fecfin"),
				adultos: $F("adultos"),
				ninos: $F("ninos")
			},
			onLoading: function(){
				$("ciudad").disable();
				$("ninos").disable();
				$("adultos").disable();
				$("hotel").disable();
				disableDateInput('fecini');
				disableDateInput('fecfin');
				$('spinner').show();
				$("ofertas").hide();
				$("hotel_info").update(div);
			},
			onFailure: function(transport){
				$("hotel_info").update(transport.responseText);
			},
			onSuccess: function(transport){
				$("hotel_info").update(transport.responseText);
			},
			onComplete: function(){
				$("image_up").hide();
				$("ciudad").enable();
				$("hotel").enable();
				$("adultos").enable();
				$("ninos").enable();
				enableDateInput('fecini');
				enableDateInput('fecfin');
				$("hotel_info").setStyle({backgroundColor:"#C0CCD3"});
				//element.enable();
				$('spinner').hide();
			}
		});
	},

	showHotelInfo: function(id, background){
		$$(".hotel_div").each(function(element){
			if(element!=$("hotel_div"+id)){
				if(element.visible()==true){
					new Effect.Fade(element, {
						duration: 0.3,
						afterFinish: function(){
							new Effect.Appear($("hotel_div"+id), {
								duration: 0.3,
								afterFinish: function(){
									$("td_info").style.background = background;
								}
							});
						}
					});
				}
			}
		})
	},

	getHotelInfo: function(element){
		var value = $F(element);
		if(value!='@'){
			new Ajax.Request(Utils.getKumbiaURL()+"availability/getHotelInfo/"+value, {
				onSuccess: function(transport){
					$("image_up").hide();
					$("hotel_info").update(transport.responseText);
				}
			});
		}
	},
	captureCustomerData: function(id){
		new Ajax.Request(Utils.getKumbiaURL()+"/availability/captureCustomerData/"+id, {
			onSuccess: function(transport){
				$("hotel_info").update(transport.responseText);
			}
		})
	}

};

new Event.observe(document, 'dom:loaded', function(){
	if($('searchButton')){
		$('searchButton').observe('click', Reservation.searchAvalibility);
	}
})
