
/* FUNCIONES GLOBALIA SISTEMAS */
/*******************************/
function validarEmail(valor) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
	return (true)
	} else {
		return (false);
	}
}
function clonarSesionPaquetes(idioma){
	document.getElementById('frameActualizador').src="../jsp_utils/pasarPaquetesASesion.jsp?idi="+idioma;
}

function iniciaCortinilla(){
	document.getElementById("cortina_cp").height = document.body.clientHeight;
	document.getElementById("cortina_cp").width = document.body.clientWidth;
}

function cargaCortinillaHabitacion(codHot,codHab,idiomaPag) {
	window.scrollTo(0,0);

	document.getElementById('frameActualizador').src="/hotel/plantillas/cortinillas/infoTipoHabitacion.jsp?idi="+idiomaPag+"&codhot="+codHot+"&codth="+codHab;
	
	//document.getElementById('cortina_cp').style.visibility='visible';
	document.getElementById('cortina_HAB').style.visibility='visible';
	document.getElementById('divOvlHab').style.visibility='visible';
	
	//changeOpac(20,'cortina_cp');
	changeOpac(20,'cortina_HAB');
}

function cargaCortinillaFotos(codHot,idiomaPag) {
	window.scrollTo(0,0);

	document.getElementById('frameActualizador').src="/hotel/plantillas/cortinillas/infoFotosHotel.jsp?idi="+idiomaPag+"&codhot="+codHot;
	document.getElementById('cortina_cp').style.visibility='visible';
	document.getElementById('divOvlHab').style.visibility='visible';
	
	changeOpac(20,'cortina_cp');
}

function cargaCortinillaMapa(codHot,idiomaPag) {
	window.scrollTo(0,0);

	document.getElementById('frameActualizador').src="/hotel/plantillas/cortinillas/infoMapaHotel.jsp?idi="+idiomaPag+"&codhot="+codHot;
	
	document.getElementById('cortina_cp').style.visibility='visible';
	document.getElementById('divOvlHab').style.visibility='visible';
	
	changeOpac(20,'cortina_cp');
}

function cargaCortinillaCondicionesGenerales(idiomaPag, entorno) {
	window.scrollTo(0,0);
	//alert(idiomaPag);
	valor ="";
	if (document.getElementById('congenerales').checked){
		valor = "S";
	}else{
		valor = "N";
	}
	//alert("funcion cargaCortinillaCondiciones: "+idiomaPag+" "+valor);

	document.getElementById('frameActualizador').src=entorno+"/hotel/plantillas/cortinillas/infoCondicionesGenerales.jsp?idi="+idiomaPag+"&valor="+valor;
	
	document.getElementById('cortina_HAB').style.visibility='visible';
	document.getElementById('divOvlHab').style.visibility='visible';
	
	changeOpac(20,'cortina_HAB');
}

function cargaCortinillaPrivacidad(idiomaPag, entorno,id_retorno) {
	window.scrollTo(0,0);
	//alert(idiomaPag);
	valor ="";
	if (document.getElementById(id_retorno).checked){
		valor = "S";
	}else{
		valor = "N";
	}
	document.getElementById('frameActualizador').src=entorno+"/hotel/plantillas/cortinillas/infoPoliticaPrivacidad.jsp?idi="+idiomaPag+"&valor="+valor+"&id_retorno="+id_retorno;
	
	document.getElementById('cortina_HAB').style.visibility='visible';
	document.getElementById('divOvlHab').style.visibility='visible';
	
	changeOpac(20,'cortina_HAB');
}

function cargaCortinillaCancelacion(idiomaPag, entorno) {
	window.scrollTo(0,0);
	if (document.getElementById('polcancelacion').checked){
		valor = "S";
	}else{
		valor = "N";
	}
	document.getElementById('frameActualizador').src=entorno+"/hotel/plantillas/cortinillas/infoPoliticaCancelacion.jsp?idi="+idiomaPag+"&valor="+valor;
	
	document.getElementById('cortina_cp').style.visibility='visible';
	document.getElementById('divOvlHab').style.visibility='visible';
	
	changeOpac(20,'cortina_cp');
}

function cargaCortinillaCondiciones(codHot,idiomaPag) {
	window.scrollTo(0,0);
	document.getElementById('frameActualizador').src="/hotel/plantillas/cortinillas/infoCondiciones.jsp?idi="+idiomaPag+"&codhot="+codHot;
	document.getElementById('cortina_cp').style.visibility='visible';
	document.getElementById('divOvlHab').style.visibility='visible';
	changeOpac(20,'cortina_cp');
}

function cargaCortinillaPaxes (urlIframe) {
	   try {
			window.scrollTo(0,0);
			document.getElementById('frameActualizador').src=urlIframe;
			document.getElementById('cortina_HAB').style.visibility='visible';
			document.getElementById('divOvlHab').style.visibility='visible';
			changeOpac(20,'cortina_HAB');
	   }catch (e) {
		   alert(e.name + " - "+e.message);
	   }
}

function cargaCortinillaPrecioGarantizado(idiomaPag, entorno) {
	window.scrollTo(0,0);
	document.getElementById('cortina_img_POG').style.width = document.body.scrollWidth;
	document.getElementById('cortina_img_POG').style.height=document.body.scrollHeight;
	document.getElementById('frameActualizador').src="/hotel/plantillas/cortinillas/cortinillaPrecio.jsp?idi="+idiomaPag;
	document.getElementById('cortina_POG').style.visibility='visible';
	document.getElementById('divOvlPOG').style.visibility='visible';
	document.getElementById('divOvlPOG').style.display='block';
	changeOpac(20,'cortina_POG');
}

function cerrarCortina(){
		document.getElementById("divInicial").style.display='none';
		document.getElementById("divOvlTerm").style.display='none';
		document.getElementById("divOvlForm").style.display='none';
		document.getElementById("divOvlFormOk").style.display='none';
		document.getElementById("divInicial").style.visibility='hidden';
		document.getElementById("divOvlTerm").style.visibility='hidden';
		document.getElementById("divOvlForm").style.visibility='hidden';
		document.getElementById("divOvlFormOk").style.visibility='hidden';
		document.getElementById('divOvlPOG').style.visibility='hidden';
		document.getElementById('divOvlPOG').style.display='none';
		document.getElementById('cortina_POG').style.visibility='hidden';
}

function actualizarClientesGarantia(idioma, mensaje){
	var errores = "";
	locata = document.getElementById('p_locata').value;
	if (locata==""){
		errores = "locata";		
	}
	nomhot = document.getElementById('p_nomhot').value;
	if (nomhot==""){
		errores = "nomhot";		
	}
	fecha = document.getElementById('p_fecha').value;
	if (fecha==""){
		errores = "fecha";		
	}
	imptot = document.getElementById('p_imptot').value;
	if (imptot==""){
		errores = "imptot";		
	}
	urlweb = document.getElementById('p_urlweb').value;
	if (urlweb==""){
		errores = "urlweb";		
	}
	nomcom = document.getElementById('p_nomcom').value;
	if (nomcom==""){
		errores = "nomcom";		
	}
	email = document.getElementById('p_email').value;
	if (email==""){
		errores = "email";		
	}
	telefono = document.getElementById('p_telefono').value;
	if (telefono==""){
		errores = "telefono";		
	}	
	observaciones = document.getElementById('p_observaciones').value;	
    //
	  if (errores == "") {
		//
		var cadenaParametros="?locata="+locata;
		    cadenaParametros+="&nomhot="+nomhot;
		    cadenaParametros+="&fecha="+fecha;
		    cadenaParametros+="&imptot="+imptot;	
		    cadenaParametros+="&urlweb="+urlweb;
		    cadenaParametros+="&nomcom="+nomcom;
		    cadenaParametros+="&email="+email;
		    cadenaParametros+="&telefono="+telefono;
		    cadenaParametros+="&observaciones="+observaciones;	
		    cadenaParametros+="&idioma="+idioma;	    
		    document.getElementById("frameActualizador").src="/hotel/jsp_utils/actualizarClientesGarantia.jsp"+cadenaParametros;			
	  }else{
      	alert(mensaje);
	  }
}

function cerrarCortinillaPaxes () {
	   try {
		   cortina_HAB.style.visibility='hidden';
		   divOvlHab.style.visibility='hidden';
		   window.parent.document.getElementById('divOvlHab').innerHTML="";
	   }catch (ex) {
		   alert(ex.name + " - "+ex.message);
	   }
}

function ocultarCortinillas(cortinillaVisible) {	
	document.getElementById("divInicial").style.display='none';
	document.getElementById("divOvlTerm").style.display='none';
	document.getElementById("divOvlForm").style.display='none';
	document.getElementById("divOvlFormOk").style.display='none';
	document.getElementById(cortinillaVisible).style.display='block';
	if (document.getElementById("caja_cortinilla")) {
		if (cortinillaVisible=="divOvlForm") {
			document.getElementById("caja_cortinilla").style.width="710px";
			document.getElementById("caja_cortinilla").style.height="750px";
			document.getElementById("caja_cortinilla").style.top="5%";
			document.getElementById("caja_cortinilla").style.left="25%";
			//document.getElementById("caja_cortinilla").style.backgroundColor=colorFondo;
	    } else {
	    	document.getElementById("caja_cortinilla").style.width="650px";
			document.getElementById("caja_cortinilla").style.height="400px";
			document.getElementById("caja_cortinilla").style.top="25%";
			document.getElementById("caja_cortinilla").style.left="25%";
	    }
	}
	if(cortinillaVisible == "divOvlForm"){
		document.getElementById("p_locata").focus();
	}
}

function validaFecha (valor) {
   if (valor.length != 10) {
	return false;
   }
   for (j=0; j<valor.length; j++) {
   //all figures and spacers in place?
     if ((j == 2) || (j == 5)) {

       if (valor.charAt(j) != "/") {
		return false;
       }
     } else if ((valor.charAt(j)<"0") || (valor.charAt(j)>"9")) {
		return false;
     }
   }
//using right format dd/mm/yyyy and year 2002 or more? Change this for diff formats...

	bits = valor.split("/");
	days = Number(bits[0]);
	month = Number(bits[1]);
	year=Number(bits[2]);
	if (days > 31) { return false;}
	else if (month > 12) { return false;}
	return true;
} 

function validarFecha(valor, mensaje){
	if( !validaFecha(valor)){
	   alert(mensaje);
	   document.getElementById("p_fecha").value="";
	   document.getElementById("p_fecha").focus();
	   }
}

function validarFormDatosGrupo(Tipo) {
	
	errores = "";	
	
	tratamientoCliente = document.getElementById('tratamiento').value;
	
	nombreCliente = document.getElementById('nombre').value;
	if (nombreCliente=="") {
		errores+=recuperar_valor_array("FORM_CLI_1_0",array_mensajes)+"\n"; //"Debe introducir el nombre \n";
		document.getElementById('nombre').style.borderColor="#FF0000";
	}
	
	apellido1Cliente = document.getElementById('apellido1').value;
	if (apellido1Cliente=="") {
		errores+=recuperar_valor_array("FORM_CLI_1_1",array_mensajes)+"\n"; //"Debe introducir el apellido 1 \n";
		document.getElementById('apellido1').style.borderColor="#FF0000";
	}	
	
	apellido2Cliente = document.getElementById('apellido2').value;

	if (Tipo==2) {
		agencia = document.getElementById('agencia').value;
		if (agencia=="") {
			errores+=recuperar_valor_array("FORM_CLI_3_3",array_mensajes)+"\n"; //"Debe introducir nombre de la agencia \n";
			document.getElementById('agencia').style.borderColor="#FF0000";
		}	
	}
	
	direccion = document.getElementById('direccion').value;
	if (direccion=="") {
		errores+=recuperar_valor_array("FORM_CLI_1_7",array_mensajes)+"\n"; //"Debe introducir la dirección \n";
		document.getElementById('direccion').style.borderColor="#FF0000";
	}
	
	
	codigoPostal = document.getElementById('cp').value;
	if (codigoPostal=="") {
		errores+=recuperar_valor_array("FORM_CLI_1_8",array_mensajes)+"\n"; //"Debe introducir el código postal \n";
		document.getElementById('cp').style.borderColor="#FF0000";
	/*}else{
		if (isNaN(parseInt(codigoPostal))) {		
			errores+="El código postal debe ser numérico \n";
			document.getElementById('cp').style.borderColor="#FF0000";
		}*/
	}
	
	localidad = document.getElementById('localidad').value;
	if (localidad=="") {
		errores+=recuperar_valor_array("FORM_CLI_2_0",array_mensajes)+"\n"; //"Debe introducir la localidad \n";
		document.getElementById('localidad').style.borderColor="#FF0000";
	}
	
	provincia = document.getElementById('provincia').value;
	if (provincia=="") {
		errores+=recuperar_valor_array("FORM_CLI_2_1",array_mensajes)+"\n"; //"Debe introducir la provincia \n";
		document.getElementById('provincia').style.borderColor="#FF0000";
	}
	
	pais = document.getElementById('seleccion_pais').value;
	if (pais=="") {
		errores+=recuperar_valor_array("FORM_CLI_3_4",array_mensajes)+"\n"; //"Debe seleccionar de la lista el país de origen \n";
		document.getElementById('seleccion_pais').style.borderColor="#FF0000";
	}
	
	
	telefonoM = document.getElementById('telefonoMovil').value;
	if (Tipo==1) {
		if (telefonoM=="") {
			errores+=recuperar_valor_array("FORM_CLI_3_5",array_mensajes)+"\n"; //"Debe introducir el teléfono móvil \n";
			document.getElementById('telefonoMovil').style.borderColor="#FF0000";
		/*}else{
			if (isNaN(parseInt(telefono))) {		
				errores+="El número de tlf. debe ser numérico \n";
				document.getElementById('telf').style.borderColor="#FF0000";
			}*/
		}
	}
	
	
	if (Tipo==1) {
		telefonoF = document.getElementById('telefonoFijo').value;
	}else{
		telefono0 = document.getElementById('telefonoOficina').value;
		if (telefono0=="") {
			errores+=recuperar_valor_array("FORM_CLI_3_6",array_mensajes)+"\n"; //"Debe introducir el teléfono de la oficina \n";
			document.getElementById('telefonoOficina').style.borderColor="#FF0000";
		}
	}
	
	
	email1 = document.getElementById('email').value;
	if (email1=="") {
		errores+=recuperar_valor_array("FORM_CLI_1_3",array_mensajes)+"\n"; //"Debe introducir el correo electrónico \n";
		document.getElementById('email').style.borderColor="#FF0000";
	}
	else{
		if (!validarEmail(email1)){
			errores+=recuperar_valor_array("FORM_CLI_1_4",array_mensajes)+"\n"; //"Debe introducir una dirección de correo electrónico válida\n";
			document.getElementById('email').style.borderColor="#FF0000";
		}
	}
	email2 = document.getElementById('email2').value;
	if (email2=="") {
		errores+=recuperar_valor_array("FORM_CLI_1_3",array_mensajes)+"\n"; //"Debe introducir el correo electrónico \n";
		document.getElementById('email2').style.borderColor="#FF0000";
	}
	else{
		if (!validarEmail(email2)){
			errores+=recuperar_valor_array("FORM_CLI_1_4",array_mensajes)+"\n"; //"Debe introducir una dirección de correo electrónico válida\n";
			document.getElementById('email2').style.borderColor="#FF0000";
		}else{
			if (email1!=email2) {
				errores+=recuperar_valor_array("FORM_CLI_1_5",array_mensajes)+"\n"; //"El correo electrónico repetido no coincide con el inicial \n";
				document.getElementById('email2').style.borderColor="#FF0000";
			}
		}
	}	
	
	dirUrl = document.getElementById('url').value;

	
	hotel = document.getElementById('hoteles').value;
	if (hotel=="") {
		errores+=recuperar_valor_array("FORM_CLI_3_7",array_mensajes)+"\n"; //"Debe seleccionar de la lista un hotel \n";
		document.getElementById('hoteles').style.borderColor="#FF0000";
	}
	
	var fecIni  = document.getElementById('diaIni').value+"/"+document.getElementById('mesIni').value.replace("_", "/");
	var fecFin  = document.getElementById('diaFin').value+"/"+document.getElementById('mesFin').value.replace("_", "/");
	
	//--------------------- comprobación de fechas --------------------------------------------------
	var fechaIniSplit = fecIni.split("/");
	var fechaFinSplit = fecFin.split("/");
	var fechaActual = new Date();
	//alert ("fecha: "+fechaActual.getDate()+"/"+fechaActual.getMonth()+"/"+fechaActual.getFullYear());
	
	var fechaEntrada  = new Date();
	
	if (fechaIniSplit[0].charAt(0)=="0")
		fechaIniSplit[0] = fechaIniSplit[0].charAt(1);

	fechaEntrada.setDate(parseInt(fechaIniSplit[0]));
	
	if (fechaIniSplit[1].charAt(0)=="0")
		fechaIniSplit[1] = fechaIniSplit[1].charAt(1);

	fechaEntrada.setMonth(parseInt(fechaIniSplit[1])-1);
	
	fechaEntrada.setFullYear(parseInt(fechaIniSplit[2]));
	
	if (fechaEntrada>=fechaActual) {
		var fechaSalida   = new Date();
		
		if (fechaFinSplit[0].charAt(0)=="0")
			fechaFinSplit[0] = fechaFinSplit[0].charAt(1);

		fechaSalida.setDate(parseInt(fechaFinSplit[0]));

		if (fechaFinSplit[1].charAt(0)=="0")
			fechaFinSplit[1] = fechaFinSplit[1].charAt(1);

		fechaSalida.setMonth(parseInt(fechaFinSplit[1])-1);
		
		fechaSalida.setFullYear(parseInt(fechaFinSplit[2]));
		//var fechaSalida   = new Date(parseInt(fechaFinSplit[2]),parseInt(fechaFinSplit[1])-1,parseInt(fechaFinSplit[0]));
		
		/*var FEdia = parseInt(fechaIniSplit[0]);
		var FEmes = parseInt(fechaIniSplit[1]);
		var FEano = parseInt(fechaIniSplit[2]);

		var FFdia = parseInt(fechaFinSplit[0]);
		var FFmes = parseInt(fechaFinSplit[1]);
		var FFano = parseInt(fechaFinSplit[2]);
		alert("FEano: "+FEano+" - "+FFano);
		alert("FEmes: "+FEmes+" - "+FFmes);
		alert("FEdia: "+FEdia+" - "+FFdia);
		if ( FFano>=FEano && FFmes>=FEmes && FFdia>FEdia ) {
				errores[e] = "La fecha de salida debe ser mayor que la de entrada.";
				e++;
		}*/		
		
		//alert("Fecha entrada: "+fechaEntrada.toString()+"\n\nFecha salida: "+fechaSalida.toString());
		
		if (fechaEntrada>=fechaSalida) {
			errores+=recuperar_valor_array("FORM_CLI_3_8",array_mensajes)+"\n"; //" La fecha de salida debe ser posterior a la fecha de entrada \n";
			document.getElementById('diaFin').style.borderColor="#FF0000";
			document.getElementById('mesFin').style.borderColor="#FF0000";
		}
		
	}else{
		errores+=recuperar_valor_array("FORM_CLI_3_9",array_mensajes)+"\n"; //" La fecha de entrada debe ser posterior o igual a la fecha actual \n";
		document.getElementById('diaIni').style.borderColor="#FF0000";
		document.getElementById('mesIni').style.borderColor="#FF0000";
	}
	//-----------------------------------------------------------------------------------------------------
	
	
	numPersonas = document.getElementById('numpersonas').value;
	if (numPersonas=="") {
		errores+=recuperar_valor_array("FORM_CLI_4_0",array_mensajes)+"\n"; //"Debe introducir el número de personas \n";
		document.getElementById('numpersonas').style.borderColor="#FF0000";
	}
	
	regimenSeleccionado = document.getElementById('regimen').value;
	if (regimenSeleccionado=="") {
		errores+=recuperar_valor_array("FORM_CLI_4_1",array_mensajes)+"\n"; //"Debe seleccionar un regimen para el alojamiento \n";
		document.getElementById('regimen').style.borderColor="#FF0000";
	}
	

	observ = document.getElementById('observaciones').value;

		
	/*necesario para poder continuar la reserva*/

	if (errores==""){
		document.getElementById('formDatosGrupo').submit();
}else{
			alert(errores);
	}

}

function recuperar_valor(codmsg,idioma) {
	document.getElementById("frameActualizador").src="/hotel/plantillas/mensajesAplicacion.jsp?codIdi="+idioma+"&codmsg="+codmsg+"&";
	return document.getElementById("frameActualizador").mensaje();
}

function validarFormDatosCliente(idioma, validaTarjeta, formReducido) {
	//alert("Dentro validarFormDatosCliente...");
	errores = "";
	nombreCliente = document.getElementById('nombre').value;
	if (nombreCliente=="") {
		errores+=recuperar_valor_array("FORM_CLI_1_0",array_mensajes)+"\n";
		document.getElementById('nombre').style.borderColor="#FF0000";
	}
	
	apellido1Cliente = document.getElementById('apellido1').value;
	apellido2Cliente = document.getElementById('apellido2').value;

	if (apellido1Cliente=="") {
		errores+=recuperar_valor_array("FORM_CLI_1_1",array_mensajes)+"\n"; 
		document.getElementById('apellido1').style.borderColor="#FF0000";
	}	
	
	//Si es un usuario B2B con formulario reducido, estos campos no se validarian
	if (!formReducido) {
		
		telefono = document.getElementById('telf').value;
		if (telefono=="") {
			errores+=recuperar_valor_array("FORM_CLI_1_2",array_mensajes)+"\n";
			document.getElementById('telf').style.borderColor="#FF0000";
		}
		
		direccion = document.getElementById('direccion').value;
		if (direccion=="") {
			errores+=recuperar_valor_array("FORM_CLI_1_7",array_mensajes)+"\n"; //"Debe introducir la dirección \n";
			document.getElementById('direccion').style.borderColor="#FF0000";
		}
		
		codigoPostal = document.getElementById('cp').value;
		if (codigoPostal=="") {
			errores+=recuperar_valor_array("FORM_CLI_1_8",array_mensajes)+"\n"; //"Debe introducir el código postal \n";
			document.getElementById('cp').style.borderColor="#FF0000";
		}
		
		pais = document.getElementById('seleccion_pais').value;
		if (pais=="") {
			errores+=recuperar_valor_array("FORM_CLI_1_6",array_mensajes)+"\n"; // "Debe seleccionar de la lista el país de origen \n";
			document.getElementById('seleccion_pais').style.borderColor="#FF0000";
		}
		
		localidad = document.getElementById('localidad').value;
		if (localidad=="") {
			errores+=recuperar_valor_array("FORM_CLI_2_0",array_mensajes)+"\n"; //"Debe introducir la localidad \n";
			document.getElementById('localidad').style.borderColor="#FF0000";
		}
		
		provincia = document.getElementById('provincia').value;
		if (provincia=="") {
			errores+=recuperar_valor_array("FORM_CLI_2_1",array_mensajes)+"\n"; //"Debe introducir la provincia \n";
			document.getElementById('provincia').style.borderColor="#FF0000";
		}
		
		empresa = document.getElementById('empresa').value;
	}
	
	email1 = document.getElementById('email').value;
	if (email1=="") {
		//errores+="Debe introducir el correo electrónico \n";
		errores+=recuperar_valor_array("FORM_CLI_1_3",array_mensajes)+"\n"; //recuperar_valor("FORM_CLI_1_3",idioma);
		document.getElementById('email').style.borderColor="#FF0000";
	}
	else{
		if (!validarEmail(email1)){
			errores+=recuperar_valor_array("FORM_CLI_1_4",array_mensajes)+"\n"; //"Debe introducir una dirección de correo electrónico válida\n";
			document.getElementById('email').style.borderColor="#FF0000";
		}
	}
	email2 = document.getElementById('email2').value;
	if (email2=="") {
		errores+=recuperar_valor_array("FORM_CLI_1_3",array_mensajes)+"\n";   //"Debe introducir el correo electrónico \n";
		document.getElementById('email2').style.borderColor="#FF0000";
	}
	else{
		if (!validarEmail(email2)){
			errores+=recuperar_valor_array("FORM_CLI_1_4",array_mensajes)+"\n"; //"Debe introducir una dirección de correo electrónico válida\n";
			document.getElementById('email2').style.borderColor="#FF0000";
		}else{
			if (email1!=email2) {
				errores+=recuperar_valor_array("FORM_CLI_1_5",array_mensajes)+"\n"; //"El correo electrónico repetido no coincide con el inicial \n";
				document.getElementById('email2').style.borderColor="#FF0000";
			}
		}
	}
	
	if (validaTarjeta) {

		numeroTarjeta = document.getElementById('numtarjeta').value;
		tipoTarjeta= document.getElementById('seleccion_tipoTarjeta').value;

		if (tipoTarjeta=="") {
			errores+=recuperar_valor_array("FORM_CLI_2_2",array_mensajes)+"\n"; //"Debe seleccionar un tipo de tarjeta \n";
			document.getElementById('seleccion_tipoTarjeta').style.borderColor="#FF0000";
		}
		
		if (numeroTarjeta=="") {
			errores+=recuperar_valor_array("FORM_CLI_2_3",array_mensajes)+"\n"; //Debe introducir el numero de la tarjeta de crédito \n";
			document.getElementById('numtarjeta').style.borderColor="#FF0000";
		}else{
			if (document.getElementById('resultadoValidacionCVC').innerHTML=='N')
				errores+=recuperar_valor_array("FORM_CLI_2_4",array_mensajes)+"\n"; //El número de tarjeta de crédito no es válido \n";
		}
		
		mesTarjeta = document.getElementById('mesTarjeta').value;
		if (mesTarjeta=="") {
			errores+=recuperar_valor_array("FORM_CLI_2_5",array_mensajes)+"\n"; //Debe seleccionar un mes para la caducidad de la tarjeta \n";
			document.getElementById('mesTarjeta').style.borderColor="#FF0000";
		}
		
		anoTarjeta = document.getElementById('anoTarjeta').value;
		if (anoTarjeta=="") {
			errores+=recuperar_valor_array("FORM_CLI_2_6",array_mensajes)+"\n"; //Debe seleccionar un año para la caducidad de la tarjeta \n";
			document.getElementById('anoTarjeta').style.borderColor="#FF0000";
		}
		var fechaCaducidad   = new Date();
		fechaCaducidad.setDate(parseInt('01'));
		fechaCaducidad.setMonth(parseInt(mesTarjeta)-1);
		fechaCaducidad.setFullYear(parseInt(anoTarjeta));
		var fechaActual = new Date();
	
		if (fechaActual>fechaCaducidad) {
			errores+=recuperar_valor_array("FORM_CLI_2_7",array_mensajes)+"\n"; //"La fecha de caducidad de la tarjeta es errónea \n";	
		}
		
		codigoTarjeta = document.getElementById('codigoCVC').value;
		if (codigoTarjeta=="") {
			errores+=recuperar_valor_array("FORM_CLI_2_8",array_mensajes)+"\n"; //"Debe introducir el código CVC de la tarjeta \n";
			document.getElementById('codigoCVC').style.borderColor="#FF0000";
		}else{
			if (codigoTarjeta.length!=3 && codigoTarjeta.length!=4 ) {
				errores+=recuperar_valor_array("FORM_CLI_2_9",array_mensajes)+"\n"; //"El código CVC de la tarjeta debe tener 3 dígitos \n";
				document.getElementById('codigoCVC').style.borderColor="#FF0000";
			}else{
				if (isNaN(parseInt(codigoTarjeta))) {		
					errores+=recuperar_valor_array("FORM_CLI_3_0",array_mensajes)+"\n"; //"El código CVC de la tarjeta debe ser numérico \n";
					document.getElementById('codigoCVC').style.borderColor="#FF0000";
				}
			}
		}
	}
	recibirOfertas = document.getElementById('recibirOfertas').checked;
	cesionDatosGrupo = document.getElementById('cesionDatosGrupo').value;
	observ = document.getElementById('observaciones').value;
		
	/*necesario para poder continuar la reserva*/
	
	if (errores=="" && document.getElementById('congenerales').checked ) {		
		/*var cadParam = "?idioma="+idioma+"&nom="+nombreCliente+"&ape1="+apellido1Cliente+"&ape2="+apellido2Cliente+"&tel="+telefono;
		cadParam = cadParam+"&mail="+email1+"&pais="+pais+"&dir="+direccion+"&cp="+codigoPostal+"&loc="+localidad;
		cadParam = cadParam+"&prov="+provincia+"&emp="+empresa+"&recM="+recibirOfertas+"&obs="+observ;
		if (validaTarjeta) {
			cadParam = cadParam+"&tipT="+tipoTarjeta+"&numT="+numeroTarjeta;
			cadParam = cadParam+"&fecT="+anoTarjeta+"-"+mesTarjeta+"-01"+"&codT="+codigoTarjeta;			
		}
		document.getElementById('frameActualizador').src="/hotel/jsp_utils/actualizarDatosCliente.jsp"+cadParam;*/
		document.getElementById('formDatosCliente').submit();
		//alert("dsp llamar al frameActualizador");
		//setTimeout("",50000);
		
	}else{
		if (errores!="")
			alert(errores);
		else{			
			if (!document.getElementById('congenerales').checked)
				alert(recuperar_valor_array("FORM_CLI_3_1",array_mensajes)); //"Debe aceptar la política de privacidad para avanzar al siguiente paso");
			
			/*if (!document.getElementById('polcancelacion').checked)
				alert(recuperar_valor_array("FORM_CLI_3_2",array_mensajes)); //"Debe aceptar la política de cancelación para avanzar al siguiente paso");*/
		}
	}
}

function cargaCalendario(idioma, hotel, tipHab, regimen, sufijoCampos, difmeses, carga, divisa) {

	//Solo cargamos si no está cargado ya o forzamos la carga cambiando de mes	
	if (divisa=='€')
		divisa = "euro";

	if (document.getElementById('divCalPrec'+sufijoCampos).innerHTML=="" || carga) {
		
		document.getElementById('divCalPrec'+sufijoCampos).style.display = "block";
	
		var imagenLoad = document.createElement("img");
		imagenLoad.setAttribute("src", "/img/cargando.gif");
		imagenLoad.setAttribute("width", "16");
		imagenLoad.setAttribute("height", "16");
		imagenLoad.setAttribute("border", "0");

		document.getElementById('divCalPrec'+sufijoCampos).appendChild(imagenLoad);

		document.getElementById('frameActualizador').src="/hotel/plantillas/calendarioPrecios.jsp?codIdi="+idioma+"&codHot="+hotel+"&codThab="+tipHab+"&codReg="+regimen+"&sufix="+sufijoCampos+"&difMeses="+difmeses+"&divisa="+divisa;
		
		if (document.getElementById("tablaCalendarioPrecios")!=null)
			document.getElementById("tablaCalendarioPrecios").style.display = "block";
			
		document.getElementById("calRegVer1"+sufijoCampos).style.display = "none";
		document.getElementById('calRegOcul'+sufijoCampos).style.display = "block";
		//document.getElementById("divCalPrec"+sufijoCampos).innerHTML=document.getElementById('frameActualizador').contentDocument.getElementById("divCalendarioPrecios").innerHTML;		
	}else{
		mostrarOcultarDiv('divCalPrec'+sufijoCampos,1000);
		if (document.getElementById('divCalPrec'+sufijoCampos).style.display = "none") {
			document.getElementById("calRegVer1"+sufijoCampos).style.display="none";
			document.getElementById('calRegOcul'+sufijoCampos).style.display="block";
		}else{
			document.getElementById("calRegVer1"+sufijoCampos).style.display="block";
			document.getElementById('calRegOcul'+sufijoCampos).style.display="none";
		}
	}
}

function cerrarCalendario(sufijoCampos) {
	mostrarOcultarDiv('divCalPrec'+sufijoCampos,1000);
	document.getElementById("calRegVer1"+sufijoCampos).style.display="block";
	document.getElementById('calRegOcul'+sufijoCampos).style.display="none";	
}

function actualizaDiasReserva (numIdTD, fechaIni, numDias, codTipHab, codReg) {
	
	//[10/09/2009] Le pasamos el Id del codHab y del codReg para que pueda encontrar específicamente
	//             los td´s del calendario donde ha hecho click el usuario, no en todos.
	//-----------------------------------------------------------------------------------------------//
	
	//Cojemos todos los TD´s del documento y los recorremos simplemente para deshabilitarlos
	var tds = document.getElementsByTagName("td");
	for (var n=0; n<tds.length; n++) {
		td = tds[n];
		if (td.className=="cHnum_dia_semana_on" && td.id.indexOf(codTipHab+codReg)!=-1) {
			td.className="cHnum_dia_semana_off";
			td.setAttribute("onmouseout", "this.className='cHnum_dia_semana_off'");
			td.setAttribute("onmouseover", "this.className='cHnum_dia_semana_on'");
		}
	}
	//en este punto hemos dejado todos los td´s (activos) de la página, como deseleccionados 
	var m = 0;
	var j = 0;
	//marcamos tantos td´s como dias dure la reserva desde el dia seleccionado
	while (m<numDias) {
		stringId = "tdDia"+(numIdTD+j)+codTipHab+codReg;
		if (document.getElementById(stringId)!=null) {
			if (document.getElementById(stringId).className!="cHnum_dia_sem_des") {
				document.getElementById(stringId).className="cHnum_dia_semana_on";
				document.getElementById(stringId).setAttribute("onmouseout", "");
				document.getElementById(stringId).setAttribute("onmouseover", "");
				m++;
			}
		//Han marcado como dia inicial 30 o 31 (se pasa del segundo mes)
		}else{m++;}
		j++;
	}
	
	//Guardamos en campos ocultos los datos necesarios para actualizar posteriormente las nuevas fechas
	document.getElementById("nuevaFechaIni").value=fechaIni;
	document.getElementById("nuevaNumDias").value=numDias;
}

function actualizaDiasReservaDispo (numIdTD, fechaIni, numDias, codTipHab, codReg, sufijoCelda) {
	
	//Cojemos todos los TD´s del calendario y los recorremos simplemente para quitarles el borde negro
	var tds = document.getElementsByTagName("td");
	
	for (var n=0; n<tds.length; n++) {
		td = tds[n];
		if (td.className.indexOf("cal_dia_sel")!=-1 && td.id.indexOf(codTipHab+codReg+sufijoCelda)!=-1) {
			td.className=td.className.replace("cal_dia_sel", "");
			td.setAttribute("onmouseout",  "this.className = this.className.replace('cal_dia_sel', '')");
			td.setAttribute("onmouseover", "this.className = this.className+' cal_dia_sel'");
		}
	}

	//Averiguamos si es el primer click o el segundo sependiendo de los siguientes valores
	var obj_hidden_numCelda1 = document.getElementById("numCeldaC1");
	var obj_hidden_numCelda2 = document.getElementById("numCeldaC2");
	var obj_hidden_fechaIni  = document.getElementById("nuevaFechaIni");
	var obj_hidden_fechaFin  = document.getElementById("nuevaFechaFin");
	var obj_hidden_fechasMal = document.getElementById("nuevasFechasX")
	
	//Si los 4 están vacios, o los 4 llenos... es que es el PRIMER click
	if ( (obj_hidden_numCelda1.value=='' && obj_hidden_numCelda2.value=='' && obj_hidden_fechaIni.value=='' && obj_hidden_fechaFin.value=='') ||
		 (obj_hidden_numCelda1.value!='' && obj_hidden_numCelda2.value!='' && obj_hidden_fechaIni.value!='' && obj_hidden_fechaFin.value!='')) {

		obj_hidden_numCelda1.value=numIdTD;
		obj_hidden_numCelda2.value="";
		obj_hidden_fechaIni.value=fechaIni;
		obj_hidden_fechaFin.value="";
		
		obj_hidden_fechasMal.value="N";
		
		var stringId = "tdDia"+numIdTD+codTipHab+codReg+sufijoCelda;
		document.getElementById(stringId).className=document.getElementById(stringId).className+" cal_dia_sel";
		document.getElementById(stringId).setAttribute("onmouseout", "");
		document.getElementById(stringId).setAttribute("onmouseover", "");
	}else{
		//SEGUNDO Click
		if (numIdTD<obj_hidden_numCelda1.value) {
			//Intercambiamos las fechas inicial y final
			obj_hidden_numCelda2.value=obj_hidden_numCelda1.value;
			obj_hidden_fechaFin.value=obj_hidden_fechaIni.value;
			obj_hidden_numCelda1.value=numIdTD;
			obj_hidden_fechaIni.value=fechaIni;
		}else{
			obj_hidden_numCelda2.value=numIdTD;
			obj_hidden_fechaFin.value=fechaIni;
		}
	
		var c1 = parseInt(obj_hidden_numCelda1.value);
		var c2 = parseInt(obj_hidden_numCelda2.value);
		while ( c1<=c2) {
			activarCeldaCalendario("tdDia"+c1+codTipHab+codReg+sufijoCelda);
			c1++;
		}
	}
}

function activarCeldaCalendario (idCelda) {
	var ObjCelda = document.getElementById(idCelda);
	if (ObjCelda) {
		ObjCelda.className=ObjCelda.className+" cal_dia_sel";
		ObjCelda.setAttribute("onmouseout", "");
		ObjCelda.setAttribute("onmouseover", "");
		
		if (ObjCelda.className.indexOf("dia_no_dispo")!=-1) {
			document.getElementById("nuevasFechasX").value="S";
		}
	}
}

function guardaNuevasFechas(idioma, tipHab) {
	fecIni = document.getElementById("nuevaFechaIni").value;
	numDias = document.getElementById("nuevaNumDias").value;
	document.getElementById("frameActualizador").src="/hotel/jsp_utils/actualizaFechasCalendario.jsp?fecIni="+fecIni+"&numDias="+numDias+"&idi="+idioma+"&tipHab="+tipHab;
}

function guardaNuevasFechasDispo(idioma, tipHab, msgNoFechaSel, idHotel, msgdiasnodispo) {
	fecIni = document.getElementById("nuevaFechaIni").value;
	fecFin = document.getElementById("nuevaFechaFin").value;
	seleccNOdispo = document.getElementById("nuevasFechasX").value
	
	if (seleccNOdispo=='N') {
		if (fecIni!="null" && fecIni!="" && fecIni!="undefined") {
			document.getElementById("frameActualizador").src="/hotel/jsp_utils/actualizaFechasCalendario.jsp?fecIni="+fecIni+"&fecFin="+fecFin+"&idi="+idioma+"&tipHab="+tipHab+"&esDispo=S&codHot="+idHotel;
		}else{
			alert(msgNoFechaSel);
		}
	}else if (seleccNOdispo=='S') {
		alert(msgdiasnodispo);
	}
}

function ocultarMostrarDesgloseHabitacion1() {
	if (document.getElementById("divHabitacion1").style.display=="block") {
		document.getElementById("divHabitacion1").style.display="none";
		document.getElementById("lupaH1").src="/img/iconos/magnifier_zoom_in.png";
	}else{
		document.getElementById("divHabitacion1").style.display="block";
		document.getElementById("lupaH1").src="/img/iconos/magnifier_zoom_out.png";
	}
}

function ocultarMostrarDesgloseHabitacion2() {
	if (document.getElementById("divHabitacion2").style.display=="block") {
		document.getElementById("divHabitacion2").style.display="none";
		document.getElementById("lupaH2").src="/img/iconos/magnifier_zoom_in.png";
	}else{
		document.getElementById("divHabitacion2").style.display="block";
		document.getElementById("lupaH2").src="/img/iconos/magnifier_zoom_out.png";
	}
}

function ocultarMostrarDesgloseHabitacion3() {
	if (document.getElementById("divHabitacion3").style.display=="block") {
		document.getElementById("divHabitacion3").style.display="none";
		document.getElementById("lupaH3").src="/img/iconos/magnifier_zoom_in.png";
	}else{
		document.getElementById("divHabitacion3").style.display="block";
		document.getElementById("lupaH3").src="/img/iconos/magnifier_zoom_out.png";
	}
}

function ocultarMostrarDesglosePersona1() {
	if (document.getElementById("divPersona1").style.display=="block") {
		document.getElementById("divPersona1").style.display="none";
		document.getElementById("lupaP1").src="/img/iconos/magnifier_zoom_in.png";
	}else{
		document.getElementById("divPersona1").style.display="block";
		document.getElementById("lupaP1").src="/img/iconos/magnifier_zoom_out.png";
	}
}

function ocultarMostrarDesglosePersona2() {
	if (document.getElementById("divPersona2").style.display=="block") {
		document.getElementById("divPersona2").style.display="none";
		document.getElementById("lupaP2").src="/img/iconos/magnifier_zoom_in.png";
	}else{
		document.getElementById("divPersona2").style.display="block";
		document.getElementById("lupaP2").src="/img/iconos/magnifier_zoom_out.png";

	}
}

function ocultarMostrarDesglosePersona3() {
	if (document.getElementById("divPersona3").style.display=="block") {
		document.getElementById("divPersona3").style.display="none";
		document.getElementById("lupaP3").src="/img/iconos/magnifier_zoom_in.png";
	}else{
		document.getElementById("divPersona3").style.display="block";
		document.getElementById("lupaP3").src="/img/iconos/magnifier_zoom_out.png";
	}
}

function cargaCalendarioDispo(idioma, hotel, tipHab, regimen, sufijoCampos, difmeses, carga, divisa) {
	
	//alert("Llamada a cargaCalendarioDispo con idioma="+idioma+", hotel="+hotel+", tipHab="+tipHab+", regimen="+regimen+", sufijoCampos="+sufijoCampos+", difmeses="+difmeses+", carga="+carga+", divisa="+divisa);
	
	//Solo cargamos si no está cargado ya o forzamos la carga cambiando de mes
	if (divisa=='€')
		divisa = "euro";

	if (document.getElementById('contenedorCalendarioDispo'+sufijoCampos).innerHTML=="" || carga) {
	
		document.getElementById('contenedorCalendarioDispo'+sufijoCampos).innerHTML="";
		
		document.getElementById('contenedorCalendarioDispo'+sufijoCampos).style.display = "block";
		//document.getElementById('id_bordeCalDisponibilidad'+sufijoCampos).style.display="block";

		var imagenLoad = document.createElement("img");
		imagenLoad.setAttribute("src", "/img/cargando.gif");
		imagenLoad.setAttribute("width", "16");
		imagenLoad.setAttribute("height", "16");
		imagenLoad.setAttribute("border", "0");

		document.getElementById('contenedorCalendarioDispo'+sufijoCampos).appendChild(imagenLoad);
		document.getElementById('frameActualizador').src="/hotel/plantillas/calendarioDispo.jsp?codIdi="+idioma+"&codHot="+hotel+"&codThab="+tipHab+"&codReg="+regimen+"&sufix="+sufijoCampos+"&difMeses="+difmeses+"&divisa="+divisa;
		
		if (document.getElementById("tablaCalendarioPrecios")!=null)
			document.getElementById("tablaCalendarioPrecios").style.display = "block";
			
		document.getElementById("linkVerCalDispo"+sufijoCampos).style.display = "none";
		document.getElementById('linkOcuCalDispo'+sufijoCampos).style.display = "block";
		//document.getElementById("divCalPrec"+sufijoCampos).innerHTML=document.getElementById('frameActualizador').contentDocument.getElementById("divCalendarioPrecios").innerHTML;		
	}else{
		mostrarOcultarDiv('contenedorCalendarioDispo'+sufijoCampos,1000);
		if (document.getElementById('contenedorCalendarioDispo'+sufijoCampos).style.display = "none") {
			document.getElementById("linkVerCalDispo"+sufijoCampos).style.display="none";
			document.getElementById('linkOcuCalDispo'+sufijoCampos).style.display="block";
		}else{
			document.getElementById("linkVerCalDispo"+sufijoCampos).style.display="block";
			document.getElementById('linkOcuCalDispo'+sufijoCampos).style.display="none";
		}
	}
}

function cerrarCalendarioDispo(sufijoCampos) {
	mostrarOcultarDiv('contenedorCalendarioDispo'+sufijoCampos,1000);
	document.getElementById("linkVerCalDispo"+sufijoCampos).style.display="block";
	document.getElementById("linkOcuCalDispo"+sufijoCampos).style.display="none";	
}

function cambiaFechasCalDispo(fecha, celda, msgFechas, idioma, codHotel, codTipHab, codReg, sufijoID, divisa) {

	if (numClickCalDispo==0) {
		
		celda.className=celda.className + " current";
		idCeldaIniCalDis = celda.id;
		fecIniciCalDispo = fecha;
		numClickCalDispo=1;
		
	}else{

		var fechaIniSplit = fecIniciCalDispo.split("/");
		var fechaFinSplit = fecha.split("/");

		var fechaInicio = new Date();
		var fechaFin  = new Date();
		
		// Pasamos de fecha string a Date la fecha ini//
		if (fechaIniSplit[1].charAt(0)=="0")
			fechaIniSplit[1] = fechaIniSplit[1].charAt(1);

		fechaInicio.setMonth(parseInt(fechaIniSplit[1])-1);
		
		fechaInicio.setFullYear(parseInt(fechaIniSplit[2]));
		
		if (fechaIniSplit[0].charAt(0)=="0")
			fechaIniSplit[0] = fechaIniSplit[0].charAt(1);
		
		fechaInicio.setDate(parseInt(fechaIniSplit[0]));		
		// Pasamos de fecha string a Date la fecha fin//
		if (fechaFinSplit[1].charAt(0)=="0")
			fechaFinSplit[1] = fechaFinSplit[1].charAt(1);

		fechaFin.setMonth(parseInt(fechaFinSplit[1])-1);
		
		fechaFin.setFullYear(parseInt(fechaFinSplit[2]));
		
		if (fechaFinSplit[0].charAt(0)=="0")
			fechaFinSplit[0] = fechaFinSplit[0].charAt(1);
		
		fechaFin.setDate(parseInt(fechaFinSplit[0]));
		// Fin conversion de fechas //
		
		if (fechaInicio>=fechaFin) {
			alert(msgFechas);
			numClickCalDispo = 0;
			//alert("idCelda="+idCeldaIniCalDis+", className="+document.getElementById(idCeldaIniCalDis).className);
			document.getElementById(idCeldaIniCalDis).className=document.getElementById(idCeldaIniCalDis).className.replace("current", "");
		}else{
			celda.className=celda.className+" current";
			numClickCalDispo = 0;
			document.getElementById("frameActualizador").src="/hotel/jsp_utils/actualizaFechasCalDispo.jsp?fecIni="+fecIniciCalDispo+"&fecFin="+fecha+"&idioma="+idioma;
			//document.getElementById("contenedorCalendariosDisponibilidad"+sufijoID).innerHTML=="";
			setTimeout("cargaCalendarioDispo('"+idioma+"', '"+codHotel+"', '"+codTipHab+"', '"+codReg+"', '"+sufijoID+"', '"+0+"', '"+true+"', '"+divisa+"')", 500);
		}
	}
}

function soloNumeros(evento){
	var numeros = "0123456789";
	var teclas_especiales = [8, 37, 39, 46];
	var evt = evento || window.event;
	var codigoCaracter = evt.charCode || evt.keyCode;
	var caracter = String.fromCharCode(codigoCaracter);
	
	var tecla_especial = false;
	for(var i in teclas_especiales) {
	  if(codigoCaracter == teclas_especiales[i]) {
	    tecla_especial = true;
	    break;
	  }
	}
	return numeros.indexOf(caracter) != -1 || tecla_especial;//Si es un número o una tecla especial, se podrá escribir en el campo de texto
}

function operacionPasarelaPago(v_refere,v_import,v_divisa,v_estado,v_idioma,v_cliente,v_key){
	document.getElementById('frameActualizador').src="../jsp_utils/iniciaPasarelaPago.jsp?v_idioma="+v_idioma+"&v_refere="+v_refere+"&v_import="+v_import+"&v_divisa="+v_divisa+"&v_estado="+v_estado+"&v_cliente="+v_cliente+"&v_key="+v_key;
}

function mostrarOcultarDiv(idDiv, tmilis) {
	
	if (!tmilis) {tmilis=2000;}

	if (idDiv) {
		var x; 
		x=$(document);
		x=$("#"+idDiv);		
		if (x.css("display")=="none") {
			x.slideDown(tmilis);  
		}else{
			x.slideUp(tmilis);
		}
	}
}
