///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function reOrdenar(orden) {
	//if (validarDatos()) {
		document.getElementById('orden').value = orden;
		document.formulario.submit();
	//}
}
function rePintar(incompleto) {
	//if (validarDatos()) {
		document.getElementById('incompleto').value = incompleto;
		document.formulario.submit();
	//}
}
function reBuscar() {
	document.getElementById('codigoBusqueda').value = '';
	if (document.getElementById('pag')) {
		document.getElementById('pag').value = '1';
	}
	document.formulario.submit();
}
function reBuscarViejo() {
	document.formulario.submit();
}
function reBuscarViejo2() {
	document.getElementById('pag').value = document.getElementById('pag2').value;
	document.formulario.submit();
}
function cargarReserva(codigoBusqueda, idHotel,sCodPromocion) {
	document.getElementById('idBusquedas').value = document.getElementById('idBusquedasTemporal_'+idHotel+'_'+sCodPromocion).value;
	document.getElementById('codigoBusqueda').value = codigoBusqueda;
	document.formulario.submit();
}
function validarDatos() {
	if (document.getElementById('idBusquedas').value=='') {
		if (document.getElementById('fechaLlegada').value=='') {
			alert("Debe especificar la fecha de llegada.");
			document.getElementById('fechaLlegada').focus();
			return false;			
		}
		if (document.getElementById('fechaSalida').value=='') {
			alert("Debe especificar la fecha de salida.");
			document.getElementById('fechaSalida').focus();
			return false;			
		}
		if (document.getElementById('destino').value=='') {
			alert("Debe especificar el lugar de destino.");
			document.getElementById('destino').focus();
			return false;			
		}
	}
	return true;
}
function cargarLista() {
	document.getElementById('idHotel').value="";
	for (m=document.formulario.listaDestinos.options.length-1;m>=0;m--){
		document.formulario.listaDestinos.options[m]=null;
	}	
	if (document.getElementById('destino').value.length > 1) {
		j = 0;
		var valorDestino = document.getElementById('destino').value;
		for (i=1;i<v.length;i++) {
			if (v[i][0].substr(0,valorDestino.length).toUpperCase()==valorDestino.toUpperCase()) {
				document.formulario.listaDestinos[j] = new Option(v[i][0]+' - '+v[i][1]+' - '+v[i][2], i); 
				j += 1;
			} else {
				if (v[i][1].substr(0,valorDestino.length).toUpperCase()==valorDestino.toUpperCase()) {
					document.formulario.listaDestinos[j] = new Option(v[i][0]+' - '+v[i][1]+' - '+v[i][2], i); 
					j += 1;
				}
			}
		}
		if (j>0) {
			document.getElementById('div_formulario').style.display="block";
		} else {
			document.getElementById('div_formulario').style.display="none";
		}
	}
}
function cargarDestino() {
	sel = document.getElementById('listaDestinos').value;
	document.getElementById('destino').value = v[sel][0]+' - '+v[sel][1]+' - '+v[sel][2];
	document.getElementById('zonaX').value = "";
	document.getElementById('div_formulario').style.display="none";
}
function visualizarLista(valor) {
	document.getElementById('div_formulario').style.display=valor;
}

function verDivPaquete() {
	if (document.getElementById("ayudaPaquete").style.display == "block") {
		document.getElementById("ayudaPaquete").style.display = "none";
	} else {
		document.getElementById("ayudaPaquete").style.display = "block";
	}
}
function verDivDestinos() {
	if (document.getElementById("ayudaDestino").style.display == "block") {
		document.getElementById("ayudaDestino").style.display = "none";
		document.getElementById("cadenas").style.display = "block";
		document.getElementById("regimen").style.display = "block";
	} else {
		document.getElementById("ayudaDestino").style.display = "block";
		document.getElementById("cadenas").style.display = "none";
		document.getElementById("regimen").style.display = "none";
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function cambiaColor(control, COLOR_LISTA) {
	control.bgColor = COLOR_LISTA;
}
function cambiaColor_destacado(control, COLOR_LISTA_DESTACADO) {
	control.bgColor = COLOR_LISTA_DESTACADO;
}
function devuelveColor(control, color) {
	control.bgColor = color;
}
function cambiarColorAZUL(imagen) {
	document.getElementById('img1_' + imagen).src='images/imagen_azul.gif';
	document.getElementById('img2_' + imagen).src='images/imagen_azul.gif';
}
function cambiarColorROJO(imagen) {
	document.getElementById('img1_' + imagen).src='images/imagen_rojo.gif';
	document.getElementById('img2_' + imagen).src='images/imagen_rojo.gif';
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function numeroHabitaciones(maximo_ninos, maximo_habitaciones) {
	for(j=1;j<=maximo_habitaciones;j++) {
		document.getElementById('hab_'+j).style.display="none";
	}																					
	for(j=1;j<=document.getElementById('habitaciones').value;j++) {
		document.getElementById('hab_'+j).style.display="block";
	}
	for(j=1;j<=maximo_habitaciones;j++) {
		if (document.getElementById('hab_'+j).style.display=="none") {
			document.getElementById('ninos_'+j).value = 0;
			for(k=1;k<=maximo_ninos;k++) {
				document.getElementById('tdedad_'+j+'_'+k).style.display="none";
				document.getElementById('edad_'+j+'_'+k).value = 2;
			}
		}
	}	
	textoEdades(maximo_ninos, maximo_habitaciones);	
}
function numeroHabitaciones_X(maximo_ninos, maximo_habitaciones, cCont) {
	for(j=1;j<=maximo_habitaciones;j++) {
		document.getElementById('hab_'+j+'_'+cCont).style.display="none";
	}																					
	for(j=1;j<=document.getElementById('habitaciones'+'_'+cCont).value;j++) {
		document.getElementById('hab_'+j+'_'+cCont).style.display="block";
	}
	for(j=1;j<=maximo_habitaciones;j++) {
		if (document.getElementById('hab_'+j+'_'+cCont).style.display=="none") {
			document.getElementById('ninos_'+j+'_'+cCont).value = 0;
			for(k=1;k<=maximo_ninos;k++) {
				document.getElementById('tdedad_'+j+'_'+k+'_'+cCont).style.display="none";
				document.getElementById('edad_'+j+'_'+k+'_'+cCont).value = 2;
			}
		}
	}	
	textoEdades_X(maximo_ninos, maximo_habitaciones, cCont);
	calcularPrecioFinal(cCont, maximo_habitaciones);	
}
function numeroHabitaciones_N(maximo_ninos, maximo_habitaciones, cCont) {
	for(j=1;j<=maximo_habitaciones;j++) {
		document.getElementById('hab_'+j+'_'+cCont).style.display="none";
	}																					
	for(j=1;j<=document.getElementById('habitaciones'+'_'+cCont).value;j++) {
		document.getElementById('hab_'+j+'_'+cCont).style.display="block";
	}
	for(j=1;j<=maximo_habitaciones;j++) {
		if (document.getElementById('hab_'+j+'_'+cCont).style.display=="none") {
			document.getElementById('ninos_'+j+'_'+cCont).value = 0;
			for(k=1;k<=maximo_ninos;k++) {
				document.getElementById('tdedad_'+j+'_'+k+'_'+cCont).style.display="none";
				document.getElementById('edad_'+j+'_'+k+'_'+cCont).value = 2;
			}
		}
	}	
	textoEdades_N(maximo_ninos, maximo_habitaciones, cCont);
}
function cargarEdadesNinos(habitacion, maximo_ninos, maximo_habitaciones) {
	if (document.getElementById('ninos_'+habitacion).value == "0") {
		document.getElementById('edad_'+habitacion).style.display="none";
	} else {
		document.getElementById('edad_'+habitacion).style.display="block";
	}
	for(j=1;j<=maximo_ninos;j++) {
		document.getElementById('tdedad_'+habitacion+'_'+j).style.display="none";
	}																					
	for(j=1;j<=document.getElementById('ninos_'+habitacion).value;j++) {
		document.getElementById('tdedad_'+habitacion+'_'+j).style.display="block";
	}
	textoEdades(maximo_ninos, maximo_habitaciones);																				
}
function cargarEdadesNinos_X(habitacion, maximo_ninos, maximo_habitaciones, cCont) {
	if (document.getElementById('ninos_'+habitacion+'_'+cCont).value == "0") {
		document.getElementById('edad_'+habitacion+'_'+cCont).style.display="none";
	} else {
		document.getElementById('edad_'+habitacion+'_'+cCont).style.display="block";
	}
	for(j=1;j<=maximo_ninos;j++) {
		document.getElementById('tdedad_'+habitacion+'_'+j+'_'+cCont).style.display="none";
	}																					
	for(j=1;j<=document.getElementById('ninos_'+habitacion+'_'+cCont).value;j++) {
		document.getElementById('tdedad_'+habitacion+'_'+j+'_'+cCont).style.display="block";
	}
	textoEdades_X(maximo_ninos, maximo_habitaciones, cCont);
	calcularPrecioFinal(cCont, maximo_habitaciones);																				
}
function cargarEdadesNinos_N(habitacion, maximo_ninos, maximo_habitaciones, cCont) {
	if (document.getElementById('ninos_'+habitacion+'_'+cCont).value == "0") {
		document.getElementById('edad_'+habitacion+'_'+cCont).style.display="none";
	} else {
		document.getElementById('edad_'+habitacion+'_'+cCont).style.display="block";
	}
	for(j=1;j<=maximo_ninos;j++) {
		document.getElementById('tdedad_'+habitacion+'_'+j+'_'+cCont).style.display="none";
	}	
	for(j=1;j<=document.getElementById('ninos_'+habitacion+'_'+cCont).value;j++) {
		document.getElementById('tdedad_'+habitacion+'_'+j+'_'+cCont).style.display="block";
	}
	textoEdades_N(maximo_ninos, maximo_habitaciones, cCont);
}
function textoEdades(maximo_ninos, maximo_habitaciones) {
	document.getElementById('edades').style.display="none";
	salir = false;
	for(j=1;j<=maximo_habitaciones;j++) {
		if (document.getElementById('ninos_'+j).value!="0") {
			document.getElementById('edades').style.display="block";
			break;
		}
	}	
}
function textoEdades_X(maximo_ninos, maximo_habitaciones, cCont) {
	document.getElementById('edades'+'_'+cCont).style.display="none";
	salir = false;
	for(j=1;j<=maximo_habitaciones;j++) {
		if (document.getElementById('ninos_'+j+'_'+cCont).value!="0") {
			document.getElementById('edades'+'_'+cCont).style.display="block";
			break;
		}
	}	
}
function textoEdades_N(maximo_ninos, maximo_habitaciones, cCont) {
	document.getElementById('edades'+'_'+cCont).style.display="none";
	salir = false;
	for(j=1;j<=maximo_habitaciones;j++) {
		if (document.getElementById('ninos_'+j+'_'+cCont).value!="0") {
			document.getElementById('edades'+'_'+cCont).style.display="block";
			break;
		}
	}	
}
function validarDatosUsuarios(MAX_NUMERO_HABITACIONES, MAX_NUMERO_ADULTOS, MAX_NUMERO_NINOS) {
	for (i=1;i<=MAX_NUMERO_HABITACIONES;i++) {
		for (j=1;j<=MAX_NUMERO_ADULTOS;j++) {
			if (document.getElementById('nom_adultos_'+i+'_'+j+'_1')) {
				if (document.getElementById('nom_adultos_'+i+'_'+j+'_1').value == "") {
					alert("Debe de introducir el nombre de todos los ocupantes");
					document.getElementById('nom_adultos_'+i+'_'+j+'_1').focus();
					return false;
				}
			}
			if (document.getElementById('ape_adultos_'+i+'_'+j+'_1')) {
				if (document.getElementById('ape_adultos_'+i+'_'+j+'_1').value == "") {
					alert("Debe de introducir los apellidos de todos los ocupantes");
					document.getElementById('ape_adultos_'+i+'_'+j+'_1').focus();
					return false;
				}
			}
			if (document.getElementById('doc_adultos_'+i+'_'+j+'_1')) {
				if (document.getElementById('doc_adultos_'+i+'_'+j+'_1').value == "") {
					alert("Debe de introducir el documento de todos los ocupantes");
					document.getElementById('doc_adultos_'+i+'_'+j+'_1').focus();
					return false;
				}
			}
			if (document.getElementById('nom_adultos_'+i+'_'+j+'_1')) {
				if (document.getElementById('nac_adultos_'+i+'_'+j+'_1').value == "") {
					alert("Debe de introducir la fecha de nacimiento de todos los ocupantes");
					document.getElementById('nac_adultos_'+i+'_'+j+'_1').focus();
					return false;
				}
			}
		}
		for (j=1;j<=MAX_NUMERO_NINOS;j++) {
			if (document.getElementById('nom_ninos_'+i+'_'+j+'_1')) {
				if (document.getElementById('nom_ninos_'+i+'_'+j+'_1').value == "") {
					alert("Debe de introducir el nombre de todos los ocupantes");
					document.getElementById('nom_ninos_'+i+'_'+j+'_1').focus();
					return false;
				}
			}
			if (document.getElementById('ape_ninos_'+i+'_'+j+'_1')) {
				if (document.getElementById('ape_ninos_'+i+'_'+j+'_1').value == "") {
					alert("Debe de introducir los apellidos de todos los ocupantes");
					document.getElementById('ape_ninos_'+i+'_'+j+'_1').focus();
					return false;
				}
			}
			if (document.getElementById('nom_ninos_'+i+'_'+j+'_1')) {
				if (document.getElementById('nac_ninos_'+i+'_'+j+'_1').value == "") {
					alert("Debe de introducir la fecha de nacimiento de todos los ocupantes");
					document.getElementById('nac_ninos_'+i+'_'+j+'_1').focus();
					return false;
				}
			}
		}
	}
	return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function sumarDia(dia) {
	if (dia==''){
		return '';
	}
	num=1;  // Incrementamos 1 dia
	// pasaremos la fecha a formato mm/dd/yyyy 
	dia=dia.split('/'); 
	dia=dia[1]+'/'+dia[0]+'/'+dia[2]; 
	
	hoy=new Date(dia); 
	hoy.setTime(hoy.getTime()+num*24*60*60*1000); 
	mes=hoy.getMonth()+1;
	dia=hoy.getDate();
	if(mes<10) mes='0'+mes; 
	if(dia<10) dia='0'+dia; 
	fecha=dia+'/'+mes+'/'+hoy.getFullYear(); 
	return fecha;
}
function redondeo2decimales(numero) {
	var original=parseFloat(numero);
	var result=Math.round(original*100)/100 ;
	return result;
}
function fechaMayor(fecha1, fecha2) {
	// Devuelte 1 si es mayor la primera, 2 si es mayor la segunda y 0 si son iguales
	fecha1 = replaceAll(fecha1,"-","/");
	fecha2 = replaceAll(fecha2,"-","/");
	
	String.prototype.fechaDDMMAAAA = function() {
		return this.replace(/^(\d{2})\/(\d{2})\/(\d{4})$/, "$2/$1/$3");
	}
	String.prototype.fechaMMDDAAAA = function() {
		return this.replace(/^(\d{2})\/(\d{2})\/(\d{4})$/, "$2/$1/$3");
	}
	
	f1=new Date( fecha1.fechaMMDDAAAA() );
	f2=new Date( fecha2.fechaMMDDAAAA() );
	
	if (f1>f2) {
		return "1";
	} else if (f1==f2) {
		return "0";
	} else {
		return "2";
	}
}
function replaceAll( str, from, to ) {
	var idx = str.indexOf( from );
		while ( idx > -1 ) {
			str = str.replace( from, to ); 
			idx = str.indexOf( from );
		}
	return str;
}

function OpenNewWindow(Destination,WindowName,Width,Height,Position,Scrollbars,Resizable,Left,Top)	{
/*	var features = "resizable:"+Resizable+";scroll:"+Scrollbars+";status:no;center:yes;help:no;dialogWidth:"+Width+"px;dialogHeight:"+Height+"px;";
	window.showModalDialog(Destination, window, features);
*/
//   Position where the window will open
//   --------------------
//   |   TL   TC   TR   |
//   |   ML   MC   MR   |
//   |   BL   BC   BR   |
//   --------------------
	DefaultPosition = 'MC';
	DefaultWidth = 200;
	DefaultHeight = 150;
	DefaultMargin = 10;
	
	if (!Position)
		{ Position = DefaultPosition; }

	if (!Height)
		{ Height = DefaultHeight; }

	if (!Width)
		{ Width = DefaultWidth; }

	if (!Scrollbars && !Resizable)
		{
		Scrollbars = 'no';
		Resizable = 'no';
		}

	if (!Left && !Top)
		{
		Left = DefaultMargin;
		Top = DefaultMargin;
		}

	if (Position == 'TC')
		{ Left = (screen.width - Width) / 2; }
	else if (Position == 'TR')
		{ Left = screen.width - Width - (Left * 2); }
	else if (Position == 'ML')
		{ Top = (screen.height - Height) / 2; }
	else if (Position == 'MC')
		{
		Left = (screen.width - Width) / 2;
		Top = (screen.height - Height) / 2;
		}
	else if (Position == 'MR')
		{
		Left = screen.width - Width - (Left * 2);
		Top = (screen.height - Height) / 2;
		}
	else if (Position == 'BL')
		{ Top = screen.height - (Height + (Top * 2) + 45); }
	else if (Position == 'BC')
		{
		Left = (screen.width - Width) / 2;
		Top = screen.height - (Height + (Top * 2) + 45);
		}
	else if (Position == 'BR')
		{
		Left = screen.width - Width - (Left * 2);
		Top = screen.height - (Height + (Top * 2) + 45);
		}

 	WindowName = window.open(Destination,WindowName,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + Scrollbars + ",resizable=" + Resizable + ",copyhistory=yes,top=" + Top + ",left=" + Left + ",width=" + Width + ",height=" + Height+",dialog=yes,modal=yes")
	WindowName.focus();

/*	if (ErrorOpeningPopups && !Window)
		{ alert(ErrorOpeningPopups); }
*/
	}

