// FUNCIONES GENÉRICAS PARA TODOS LOS IDIOMAS


// Función para inicializar los precios
function recargar(){
	document.getElementById('txtSuma').value = tarifa[0]+'€';
	document.getElementById('coste').value = tarifa[0]+'€';
	document.getElementById('ahorro').value = 18-tarifa[0] + '€';
    document.getElementById('pulsado').checked = true;
	
}
	
// Función para desabilitar períodos de días
function disponibilidad(idioma) {
	var fecha;
	var fecha_sep;
	
	// fecha de entrada tipo string
	fecha = $("#fecha_entrada").val();
	fecha_sep = fecha.split('/');	
	var fecha_ent = fecha_sep[2] + (fecha_sep[1].length==1? '0'+fecha_sep[1] : fecha_sep[1]) + (fecha_sep[0].length==1? '0'+fecha_sep[0] : fecha_sep[0]);
  	
	// fecha salida tipo string
	fecha = $("#fecha_salida").val();
	fecha_sep = fecha.split('/');
	var fecha_sal = fecha_sep[2] + (fecha_sep[1].length==1? '0'+fecha_sep[1] : fecha_sep[1]) + (fecha_sep[0].length==1? '0'+fecha_sep[0] : fecha_sep[0]);
	
	// Recoge las fechas de bloqueo
	fecha_sep = fechaBloqueoDesde.split('-');
	fechaBloDes = fecha_sep[0] + fecha_sep[1] + fecha_sep[2];	
	fecha_sep = fechaBloqueoHasta.split('-');
	fechaBloHas = fecha_sep[0] + fecha_sep[1] + fecha_sep[2];
	
	// Comprueba que las fechas de ent-sal no estén entre las de bloqueo
	if ((fecha_ent >= fechaBloDes && fecha_ent <= fechaBloHas) || (fecha_sal <= fechaBloHas && fecha_sal >= fechaBloDes)  || (fecha_ent <= fechaBloDes && fecha_sal >= fechaBloHas)) {
	  	if (idioma=='esp')
			alert("Lo sentimos, el parking está completo. Disculpen las molestias.");
		else
			alert("The car park is full. Sorry for the inconvenience.");
  		
		fecha_sep = fechaBloqueoHasta.split('-');
		fecha = new Date(fecha_sep[0], fecha_sep[1], fecha_sep[2]);
		fechaEnt = parseInt(fecha.getDate())+1 + "/" + fecha.getMonth() + "/" + fecha.getFullYear();
		fechaSal = parseInt(fecha.getDate())+2 + "/" + fecha.getMonth() + "/" + fecha.getFullYear();
		$("#fecha_entrada").val(fechaEnt);
  		$("#fecha_salida").val(fechaSal);
		return false;
	}
	
	return true;
}


// Comprueba que la fecha de salida no sea menor o igual a la de entrada
//  y la de entrada no sea inferior a hoy
function comprobarFechasReserva() {
	var hoy = new Date();
	var hoy_ano = hoy.getFullYear().toString();
	var hoy_mes = parseInt(hoy.getMonth()+1).toString().length==1? '0' + parseInt(hoy.getMonth()+1).toString() : parseInt(hoy.getMonth()+1).toString();
	var hoy_dia = hoy.getDate().toString().length==1? '0' + hoy.getDate().toString() : hoy.getDate().toString();
	var hoy_cad = hoy_ano + hoy_mes + hoy_dia;
	var hoy_fecha = hoy.getDate() + "/" + parseInt(hoy.getMonth()+1) + "/" + hoy.getFullYear();
	
	var fecha = new Date(); 
	fecha.setDate(fecha.getDate()+1);
	var manana_fecha = fecha.getDate() + "/" + parseInt(fecha.getMonth()+1) + "/" + fecha.getFullYear();
	
	var fecha_ent = $("#fecha_entrada").val();
	fecha_ent = fecha_ent.split('/');
	fecha_ent = fecha_ent[2]+(fecha_ent[1].length==1? '0' + fecha_ent[1] : fecha_ent[1])+fecha_ent[0];
	
	var fecha_sal = $('#fecha_salida').val();
	fecha_sal = fecha_sal.split('/');
	fecha_sal = fecha_sal[2]+(fecha_sal[1].length==1? '0' + fecha_sal[1] : fecha_sal[1])+fecha_sal[0];
	
	// Comprueba que la fecha de entrada no sea anterior a hoy
	if (fecha_ent < hoy_cad) {
		alert ("Fecha de entrada incorrecta: el día de entrada no puede ser anterior a hoy.");
		$('#fecha_entrada').val(hoy_fecha);
		return false;		
	} else
		// Comprueba que la fecha de salida no sea anterior a la de entrada.
		if (fecha_sal < fecha_ent) {
		  alert ("Fecha de vuelta incorrecta: el día de salida no puede ser anterior al de la entrada.");
	 		  
		  $('#fecha_entrada').val(hoy_fecha);		  
		  $('#fecha_salida').val(manana_fecha);
		  return false;
	}
	
	return true;
}

// Convierte la fecha de formato castellano a Mysql
function dateToMysql(date){
	var fecha_ent = date;
	fecha_ent = fecha_ent.split('/');
	fecha_ent = fecha_ent[2]+'-'+(fecha_ent[1].length==1? '0' + fecha_ent[1] : fecha_ent[1])+'-'+fecha_ent[0];
	
	return fecha_ent;
} 

  
