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 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); 
				document.formulario.listaDestinos[j] = new Option(v[i][1], 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); 
					document.formulario.listaDestinos[j] = new Option(v[i][1], i); 
					j += 1;
				}
			}
		}
		if (j>0) {
			document.getElementById('div_formulario').style.display="block";
		} else {
			document.getElementById('div_formulario').style.display="none";
		}
	}
}
function visualizarLista(valor) {
	document.getElementById('div_formulario').style.display=valor;
}
function limpiarDestino() {
	document.getElementById('idHotel').value = "";
	document.getElementById('destino').value = "";
	document.getElementById('destino').readOnly="";
}
function cargarDestino() {
	//sel = document.getElementById('listaDestinos').value;
	sel = document.getElementById('listaDestinos').options[document.getElementById('listaDestinos').selectedIndex].value;
	document.getElementById('destino').value = v[sel][1];
	//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 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 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 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 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 verDivPaquete() {
	if (document.getElementById("ayudaPaquete").style.display == "block") {
		document.getElementById("ayudaPaquete").style.display = "none";
	} else {
		document.getElementById("ayudaPaquete").style.display = "block";
	}
}
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;			
		}
	}
	is_loaded();
	document.formulario.submit();
}
function reBuscar() {
	document.getElementById('codigoBusqueda').value = '';
	if (document.getElementById('pag')) {
		document.getElementById('pag').value = '1';
	}
	is_loaded();
	document.formulario.submit();
}
function is_loaded() { //DOM
	if (document.getElementById){
		document.getElementById('preloader').style.display='block';
	} else {
		if (document.layers){ //NS4
			document.preloader.visibility = 'block';
		} else { //IE4
			document.all.preloader.style.visibility = 'block';
		}
	}
	document.getElementById('formulario').style.filter = "alpha(opacity=20)";
	document.getElementById('formulario').style.opacity = ".2";
}
function cambiaColor(control, COLOR_LISTA) {
	control.bgColor = COLOR_LISTA;
}
function devuelveColor(control, color) {
	control.bgColor = color;
}
function reOrdenar(orden) {
	document.getElementById('orden').value = orden;
	document.formulario.submit();
}
function rePintar(incompleto) {
	document.getElementById('incompleto').value = incompleto;
	document.formulario.submit();
}
 function clearInput(valor){
 	var valorActual = document.getElementById('destino').value;
 	if (valor == valorActual){
 		document.getElementById('destino').value= '';
 	}
 }
 function agregar_favoritos(cadena_url){
   if ((navigator.appName=="Microsoft Internet Explorer") && 
         (parseInt(navigator.appVersion)>=4)) {
      var url="http://" + cadena_url; 
      var titulo=cadena_url;
      window.external.AddFavorite(url,titulo);
   } else { 
      if(navigator.appName == "Netscape") 
         alert("Presione Crtl+D para agregar este sitio en sus Bookmarks"); 
   }
}
function reBuscarViejo() {
	document.formulario.submit();
}
function reBuscarViejo2() {
	document.getElementById('pag').value = document.getElementById('pag2').value;
	document.formulario.submit();
}
function redondeo2decimales(numero) {
	var original=parseFloat(numero);
	var result=Math.round(original*100)/100 ;
	return result;
}
function cargarReserva(codigoBusqueda, idHotel,sCodPromocion) {
	precio = document.getElementById('dsPrecioComision_' + idHotel + '_' + sCodPromocion).innerHTML;
	if (precio != '') {
		if (precio <= 0) {
			alert('No es posible realizar esta reserva.');
			return false;
		}
	}
	document.getElementById('idBusquedas').value = document.getElementById('idBusquedasTemporal_'+idHotel+'_'+sCodPromocion).value;
	document.getElementById('codigoBusqueda').value = codigoBusqueda;
	document.formulario.submit();
}
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('nac_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('nac_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;
				}
			}
		}
	}
	if (document.getElementById('nombre_apellidos')) {
		if (document.getElementById('nombre_apellidos').value == "") {
			alert("Debe de introducir el nombre y los apellidos del cliente que irá al hotel");
			document.getElementById('nombre_apellidos').focus();
			return false;
		}
	}	
	return true;
}
function cargarHotel(cod, nom) {
	if (document.getElementById('idHotel')) {
		document.getElementById('idHotel').value = cod;
		document.getElementById('destino').value = "HOTEL " + nom.toUpperCase();
		document.getElementById('destino').readOnly="readOnly";
	}
}
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); }
	*/
}


