function ampliar(URLampliacion,nombreventana,ancho,alto) {
	window.open(URLampliacion, nombreventana, "toolbar=no,location=no,status=yes,menubar=no,scrollbars=auto,outerWidth="+ancho+",width="+ancho+",height="+alto+",resizable=no" );
}

function ir(paso) {
	document.getElementById('paso').value = paso;
	document.getElementById('modificar').value = 'true';
	document.getElementById('frmReserva').submit();
}
function enviar() {
	document.getElementById('frmReserva').submit ();
}

function mostrarBuscando(mensaje) {
	cargandoBuscador(mensaje);
	document.getElementById('frmBuscador').submit();
}

function addBookmark(title,url) {



	if (window.sidebar) { // Mozilla Firefox 
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE 
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera 
		return true; }
 }

function setPrecios(data) {
	$(".search_f_e").html(data.fecha_entrada);
	$(".search_f_s").html(data.fecha_salida);
	$(".search_p").html(data.personas);
	$("#fechaInicio").val(data.fecha_entrada);
	$("#fechaFin").val(data.fecha_salida);
	$("#personasAjax").val(data.personas);
	$(".search_estancia").html(data.estancia);
	$(".search_precio_reserva").html(data.precio_reserva +' €');
	$(".search_precio_dia").html(data.precio_dia +' €');
	$(".search_precio_total").html(data.precio_total +' €');
	
	
	
	
	
}
function disponibilidadApartamento(lang) {
		var valores = $('#verBuscador').formdata();
		var req = $.ajax({
		type: "POST",
		cache: true,
		data: valores,
		dataType : "json",
		url: "/"+ lang + "/ajax/disponibilidad",
		success: function(data) {
			body = data.html;
			respuesta = data.respuesta;
			$("#seed_reserva").val(data.s);
			$("#cds_reserva").val(data.cds);
			if (respuesta == 'ok') {
				$("#comprobacionDisponibilidad").html(body);
				setPrecios(data.precios)
			} else {
				$("#comprobacionDisponibilidad").html('<p class="error_ajax">' + body +'</p>');
			}
			req = null;
	  }
	});
	
	return false;
	
	setTimeout(function(){
		if ( req ) req.abort();
	}, 6000)
	

	}

function cargandoBuscador(mensaje) {
	$("body").prepend("<div id=\"bloqueador_buscador\"><img src=\"/img/logo_buscador.png\" /><h4>"+ mensaje +"</h4></div>");
	$.glassPane(true);
	$("div#bloqueador").addClass("bloqueador");
	var pagesize = tamanioPantalla();
	var arrayPageScroll = calculaScroll();
	$("div#bloqueador_buscador").css({display: "block", left: ((pagesize[0] - 300)/2)+"px", top: (arrayPageScroll[1] + ((pagesize[1]-100)/2))+"px" });
};

$.glassPane = function (show) {
	var o = $('#bloqueador');
	if (o.size() == 0 && !show) { // don't bother creating if show==false
		return;
	}
	if (o.size() == 0) {
		// create glass pane element
		$("body").append("<div id='bloqueador'><\/div>");
		$("#bloqueador").addClass('bloqueador');
	} else {
		o = o[0];
	}	
	if (show) {
		if (window.innerHeight && window.scrollMaxY) {	
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			yScroll = document.body.offsetHeight;
		}
		$("#bloqueador").css("height",yScroll +"px");
		$(window).scroll(actualizaScroll);
	}else{
		$("div#bloqueador").remove();
	// for good measure, set cursor on the body too
	}
	document.body.style.cursor = show ? 'wait' : 'default';
};

function actualizaBloqueador(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;		
	var yScrolltop;
	if (self.pageYOffset) {
		yScrolltop = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){   // Explorer 6 Strict
		yScrolltop = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScrolltop = document.body.scrollTop;
	}		
	$("#bloqueador").css("height",h +"px");
	actualizaScroll();
};



function actualizaScroll() {  
	if (window.innerHeight && window.scrollMaxY) {      
		yScroll = window.innerHeight + window.scrollMaxY;  
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac   
		yScroll = document.body.scrollHeight;  
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari   
		yScroll = document.body.offsetHeight;    
	}
	$("#bloqueador").css("height",yScroll +"px"); 
};

function tamanioPantalla(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	
	arrayPageSize = new Array(w,h) 
	return arrayPageSize;
};	

function calculaScroll(){
	var yScrolltop;
	if (self.pageYOffset) {
		yScrolltop = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScrolltop = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScrolltop = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScrolltop) 
	return arrayPageScroll;
};

	$.fn.serialize = function() {
		var a = [];
		var ok = {INPUT:true, TEXTAREA:true, OPTION:true, HIDDEN:true};

		$('*', this).each(function() {
				var par = this.parentNode;
				var p = par.nodeName.toUpperCase();
				var n = this.name || p == 'OPTGROUP' && par.parentNode.name || p == 'SELECT' && par.name || this.id;

				if ( !n || this.disabled || this.type == 'reset' ||
						(this.type == 'checkbox' || this.type == 'radio') && !this.checked ||
						!ok[this.nodeName.toUpperCase()] ||
						(this.type == 'submit' || this.type == 'image') && this.form.clicked != this ||
						(p == 'SELECT' || p == 'OPTGROUP') && !this.selected ) { return; }

				if (this.type == 'image' && this.form.clicked_x) {
						return a.push(
								{name: this.name+'_x', value: this.form.clicked_x},
								{name: this.name+'_y', value: this.form.clicked_y}
						);
				}
				a.push({name: n, value: this.value});
		}).end();

		this.vars = a;

		return this;
	};

	$.fn.formdata = function(){
	        this.serialize();
	        return this.vars;
	};
				Date.abbrDayNames = ['Dom', 'Lun', 'Mart', 'Mier', 'Juev', 'Vier', 'Sab'];
						Date.dayNames = ['Dom', 'Lun', 'Mart', 'Mier', 'Juev', 'Vier', 'Sab'];

			$(function() {
				$("#ver_calendario").bind('click',function() {
					$("#cargaCalendarioItem").html("<img src=\"\/img\/cargando-item.gif\" alt=\"Cargando\" \/>");
					$("#cargaCalendarioItem").animate({height:"300px"},"slow");
					cargaCalendario('','','');
				});

				$('#calendarioFin')
					.datePicker({
							createButton:false
					}).bind('click',function() {
							updateSelects($(this).dpGetSelected()[0],'Fin');
							$(this).dpDisplay();
							return false;
						}
					).bind('dateSelected',function(e, selectedDate, $td, state) {
							updateSelects(selectedDate,'Fin');
						}
					).bind('dpClosed',function(e, selected){
							updateSelects(selected[0],'Fin');
				});
				$('#calendarioInicio')
					.datePicker({
							createButton:false
					}).bind('click',function() {
							updateSelects($(this).dpGetSelected()[0],'Inicio');
							$(this).dpDisplay();
							return false;
						}
					).bind('dateSelected',function(e, selectedDate, $td, state) {
							updateSelects(selectedDate,'Inicio');
							if (selectedDate) {
								d = new Date(selectedDate);
								updateSelects(d.addDays(3),'Fin');
							}
						}
					).bind('dpClosed',function(e, selected){
							updateSelects(selected[0],'Inicio');
							var d = selected[0];
							if (d) {
								d = new Date(d);
								$('#calendarioFin').dpSetStartDate(d.addDays(3).asString());
							}

				});
				var updateSelects = function (selectedDate,queFecha) {
					selectedDate = new Date(selectedDate);
					var d = selectedDate.getDate();
					var m = selectedDate.getMonth() ;
					m = m + 1;
					d =(d <10)?'0'+d :d ;
					m =(m <10)?'0'+m :m ;
					var y = selectedDate.getFullYear();
					var mesSeleccionado = m +''+ y;
					$('#dia'+ queFecha).val(d) ;
					$('#mes'+ queFecha).val(mesSeleccionado) ;
				}

				$('#diaFin, #mesFin')
					.bind(
						'change',
						function()
						{
							var fecha  = $("#mesFin").val();
							anio = fecha.substring(2,fecha.length);
							mes = fecha.substring(0,fecha.length - 4);
							var d = new Date(
										anio,
										parseInt(mes,10) - 1,
										$('#diaFin').val()
									);

							
							$('#calendarioFin').dpSetSelected(d.asString());
						}
					);

				$('#diaInicio, #mesInicio')
					.bind(
						'change',
						function()
						{
							var fecha  = $("#mesInicio").val();
							anio = fecha.substring(2,fecha.length);
							mes = fecha.substring(0,fecha.length - 4);
							
							var d = new Date(
										anio,
										parseInt(mes,10) - 1,
										$('#diaInicio').val()
									);
							$('#calendarioInicio').dpSetSelected(d.asString());
						}
					);

				//$('#mesFin').trigger('change');
				//$('#mesInicio').trigger('change');
				
				$("a[rel=external]").click(function(){
					this.target = "_blank";
				});		
			});

