function validarConsultaContacto()
{
	if (document.form1.txtNombre.value=='')
	{
		alert('Por favor, ingrese su nombre');
		document.form1.txtNombre.focus();
		return 0;
	}
	
	if (document.form1.txtEmail.value=='')
	{
		alert('Por favor, ingrese su email');
		document.form1.txtEmail.focus();
		return 0;
	}	
	
	if (!isEmailAddress(document.form1.txtEmail.value))
	{
		alert('Por favor, ingrese un email correcto');
		document.form1.txtEmail.focus();
		return 0;
	}
	
	if (document.form1.txtConsulta.value=='')
	{
		alert('Por favor, ingrese su consulta');
		document.form1.txtConsulta.focus();
		return 0;
	}

	document.form1.submit();
}

function validarUsuarioParticular()
{
	if (document.form1.txtNombre.value=='')
	{
		alert('Por favor, ingrese su nombre');
		document.form1.txtNombre.focus();
		return 0;
	}
	
	if (document.form1.txtApellido.value=='')
	{
		alert('Por favor, ingrese su apellido');
		document.form1.txtApellido.focus();
		return 0;
	}
	
	if (document.form1.txtUserName.value=='')
	{
		alert('Por favor, ingrese su nombre de usuario');
		document.form1.txtUserName.focus();
		return 0;
	}
	
	if (document.form1.txtPassword.value=='')
	{
		alert('Por favor, ingrese su password');
		document.form1.txtPassword.focus();
		return 0;
	}
	
	if (document.form1.txtRepetirPassword.value=='')
	{
		alert('Por favor, repita su password');
		document.form1.txtRepetirPassword.focus();
		return 0;
	}
	
	if (document.form1.txtRepetirPassword.value!=document.form1.txtPassword.value)
	{
		alert('Debe ingresar en ambos recuadros la misma password');
		document.form1.txtPassword.focus();
		return 0;
	}	
	
	if (document.form1.txtEmail.value=='')
	{
		alert('Por favor, ingrese su email');
		document.form1.txtEmail.focus();
		return 0;
	}	
	
	if (!isEmailAddress(document.form1.txtEmail.value))
	{
		alert('Por favor, ingrese un email correcto');
		document.form1.txtEmail.focus();
		return 0;
	}
	
	document.form1.submit();
}

function validarHotel()
{
	if (document.form1.txtNombre.value=='')
	{
		alert('Por favor, ingrese el nombre del hotel');
		document.form1.txtNombre.focus();
		return 0;
	}
	
	if (document.form1.cmbProvincia.value=='')
	{
		alert('Por favor, ingrese la provincia del hotel');
		document.form1.cmbProvincia.focus();
		return 0;
	}
	
	if (document.form1.cmbCiudad.value=='')
	{
		alert('Por favor, ingrese la ciudad del hotel');
		document.form1.cmbCiudad.focus();
		return 0;
	}
	
	if (document.form1.txtEmail.value=='')
	{
		alert('Por favor, ingrese el email del hotel');
		document.form1.txtEmail.focus();
		return 0;
	}
	
	if (!isEmailAddress(document.form1.txtEmail.value))
	{
		alert('Por favor, ingrese un email correcto');
		document.form1.txtEmail.focus();
		return 0;
	}
	
	if (document.form1.txtTelefono.value=='')
	{
		alert('Por favor, ingrese el telefono del hotel');
		document.form1.txtTelefono.focus();
		return 0;
	}
	
	if (document.form1.txtDireccion.value=='')
	{
		alert('Por favor, ingrese la direccion del hotel');
		document.form1.txtDireccion.focus();
		return 0;
	}
	
	if (document.form1.txtWeb.value=='')
	{
		alert('Por favor, ingrese la página web del hotel');
		document.form1.txtWeb.focus();
		return 0;
	}
	document.form1.accion.value = 'guardar';
	document.form1.submit();
	
}

function seleccionoProvincia()
{
	var provinciaSeleccionada = document.form1.cmbProvincia.value;
	
	if (provinciaSeleccionada=='') 
	{
		vaciarCombo(document.form1.cmbCiudad);
		document.form1.cmbCiudad.options[0] = new Option("Seleccione provincia primero","");
		document.form1.cmbCiudad.disabled = true;
	}
	else
	{
		var stringCiudades = document.getElementById("prov_"+provinciaSeleccionada).value;
		var arrayCiudades = stringCiudades.split(",");
		
		vaciarCombo(document.form1.cmbCiudad);
		
		for (i=0; i<arrayCiudades.length-1; i++) 
		{
			var ciudad = arrayCiudades[i].split("_");
			document.form1.cmbCiudad.options[i] = new Option(ciudad[1],ciudad[0]);
		}
	}
	document.form1.cmbCiudad.disabled=false;
}

function cambioCiudad()
{
	document.form1.posCiudadSeleccionada.value = document.form1.cmbCiudad.selectedIndex;
}

function setearCiudad()
{
	document.form1.cmbCiudad.selectedIndex = document.form1.posCiudadSeleccionada.value;
}

function vaciarCombo(combo)
{
	var cantOpciones = combo.options.length;
	for (i=cantOpciones-1; i>=0; i--)
	{
		combo.remove(i);
	}
}

function isEmailAddress(valor)
{
	var s = valor;
	var filter=/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (s.length == 0 ) return true;
	if (filter.test(s))
		return true;
	return false;
}

function validarLogin()
{
	if (document.formLogin.txtUsuario.value=='')
	{
		alert('Por favor, ingrese su nombre de usuario');
		document.formLogin.txtUsuario.focus();
		return 0;
	}
	
	if (document.formLogin.txtPassword.value=='')
	{
		alert('Por favor, ingrese su password');
		document.formLogin.txtPassword.focus();
		return 0;
	}
	
	document.formLogin.submit();
}

function limpiarTexto(objeto, textoLimpiar)
{
	if (objeto.value==textoLimpiar)
		objeto.value='';
}


function validarConsulta()
{
	if (document.form1.cmbProvincia.value=='')
	{
		alert('Por favor, ingrese la provincia a donde viaja');
		document.form1.cmbProvincia.focus();
		return 0;
	}
	
	if (document.form1.cmbCiudad.value=='')
	{
		alert('Por favor, ingrese la ciudad a donde viaja');
		document.form1.cmbCiudad.focus();
		return 0;
	}
	
	if (document.form1.cmbPasajeros.value=='')
	{
		alert('Por favor, ingrese la cantidad de pasajeros');
		document.form1.cmbPasajeros.focus();
		return 0;
	}
	
	if (document.form1.txtDesde.value=='')
	{
		alert('Por favor, ingrese la fecha de check in');
		document.form1.txtDesde.focus();
		return 0;
	}
	
	if (document.form1.txtHasta.value=='')
	{
		alert('Por favor, ingrese la fecha de check out');
		document.form1.txtHasta.focus();
		return 0;
	}	

	if (document.getElementById('cantNoches').innerHTML=='')
	{
		alert('La fecha de check in debe ser anterior a la de check out');
		document.form2.txtHasta.focus();
		return 0;
	}	
	
	document.form1.hizoSubmit.value=2;	
	document.form1.submit();
}

function calcularNoches(){
	var date1 = document.getElementById('txtHasta').value;
	var date2 = document.getElementById('txtDesde').value;
	if (date1!='' && date2!='')
	{
		date1 = date1.split("/");
		date2 = date2.split("/");
		var sDate = new Date(date1[1]+"/"+date1[0]+"/"+date1[2]);
		var eDate = new Date(date2[1]+"/"+date2[0]+"/"+date2[2]);
		var daysApart = Math.round((sDate-eDate)/86400000);
		if (daysApart<=0)
			document.getElementById('hdnCantNoches').value = '';
		else
		{
			document.getElementById('hdnCantNoches').value = daysApart;
		}
		//document.getElementById('hdnCantNoches').value = document.getElementById('cantNoches').innerHTML;
	}
}

function procesarMensajes(accion)
{
    var marco=0;
    
    for (i=0; i<=document.form1.elements.length-1; i++)
    {
        if(document.form1.elements[i].id.indexOf('chk')==0)
        {
            if (document.form1.elements[i].checked) marco++;
        }
    }
    
    if (marco==0)
    {
       alert('No ha seleccionado ningun mensaje');
       return 0;
    }
    
    document.form1.accion.value = accion;
    document.form1.submit();
}

function procesarMensaje(accion)
{
    document.form1.accion.value = accion;
    document.form1.submit();
}

function enviarMensaje()
{
    if (document.form1.txtMensaje.value=='')
    {
        alert('Por favor, ingrese el mensaje a enviar');
        document.form1.txtMensaje.focus();
        return 0;
    }
    
    document.form1.submit();
}

function adminUsuarios(accion)
{
    var marco=0;

    if (accion=='Borrar')
    {
       for (i=0; i<=document.form1.elements.length-1; i++)
       {
          if(document.form1.elements[i].id.indexOf('chk')==0)
          {
             if (document.form1.elements[i].checked) marco++;
          }
       }

       if (marco==0)
       {
          alert('No ha seleccionado ningun usuario');
          return 0;
       }
    }
    else
    {
        window.location = "alta_usuario_hot.php";
        return 0;
    }
    
    if (confirm('Esta seguro que desea borrar a los usuarios seleccionados?'))
    {
      document.form1.accion.value = accion;
      document.form1.submit();
    }
}

function validarOlvidoPass()
{
	if (document.form1.txtEmail.value=='')
	{
		alert('Por favor, ingrese su direccion de email');
		document.form1.txtEmail.focus();
		return 0;
	}
	
	if (!isEmailAddress(document.form1.txtEmail.value))
	{
		alert('Por favor, ingrese un email correcto');
		document.form1.txtEmail.focus();
		return 0;
	}
	
	document.form1.submit();
}
function mostrarPropHospedaje(tipoHospedaje)
{
	
	if(tipoHospedaje == '1')
	{
		document.getElementById('tableHotelProperties').style.display = 'block';
		document.getElementById('titleBoutique').style.visibility = 'visible';
		document.getElementById('bodyBoutique').style.visibility = 'visible';
	}
	else
		if(tipoHospedaje == '2')
		{
			document.getElementById('tableHotelProperties').style.display = 'block';
			document.getElementById('titleBoutique').style.visibility = 'hidden';
			document.getElementById('bodyBoutique').style.visibility = 'hidden';
			document.getElementById('chkBoutique').checked = false;
		
		}
		else
		{
			document.getElementById('tableHotelProperties').style.display = 'none';
			document.getElementById('chkVacacional').checked = false;
			document.getElementById('chkCorporativo').checked = false;
			document.getElementById('chkBoutique').checked = false;
		}
}

function seleccioneInputUser()
{
	if (formLogin.txtUsuario.value=='Usuario')
	{
		formLogin.txtUsuario.value='';
		formLogin.txtUsuario.style.color = "#000000";
	}
	
}

function seleccioneInputPassword()
{
	if (formLogin.txtPassword.value=='Password')
	{
		formLogin.txtPassword.value='';
		obj = changeInputType(formLogin.txtPassword,'password','',true,false);
		obj.className = 'inputTextoNegro';
		obj.id = 'txtPassword';
		obj.name = 'txtPassword';
	}
}

function changeInputType(
  oldElm, // a reference to the input element
  iType, // value of the type property: 'text' or 'password'
  iValue, // the default value, set to 'password' in the demo
  blankValue, // true if the value should be empty, false otherwise
  noFocus) {  // set to true if the element should not be given focus
 
  if(!oldElm || !oldElm.parentNode || (iType.length<4) || 
    !document.getElementById || !document.createElement) return;
  var newElm = document.createElement('input');
  newElm.type = iType;
  if(oldElm.name) newElm.name = oldElm.name;
  if(oldElm.id) newElm.id = oldElm.id;
  if(oldElm.className) newElm.className = oldElm.className;
  if(oldElm.size) newElm.size = oldElm.size;
  if(oldElm.tabIndex) newElm.tabIndex = oldElm.tabIndex;
  if(oldElm.accessKey) newElm.accessKey = oldElm.accessKey;
  newElm.onfocus = function(){return function(){
    if(this.hasFocus) return;
    var newElm = changeInputType(this,'password',iValue,
      (this.value.toLowerCase()==iValue.toLowerCase())?true:false);
    if(newElm) newElm.hasFocus=true;
  }}();
  newElm.onblur = function(){return function(){
    if(this.hasFocus)
    if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
      changeInputType(this,'text',iValue,false,true);
    }
  }}();
 // hasFocus is to prevent a loop where onfocus is triggered over and over again
  newElm.hasFocus=false;
  oldElm.parentNode.replaceChild(newElm,oldElm);
  if(!blankValue) newElm.value = iValue;
  if(!noFocus || typeof(noFocus)=='undefined') {
    window.tempElm = newElm;
    setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
  }
  return newElm;
}

function seleccionarTodos()
{
	var i = 0;
	
	for(i=0; i<document.form2.elements.length; i++)
	{
		if (document.form2.elements[i].id.substring(0,3)=='chk')
		{
			document.form2.elements[i].checked = true;
		}		
	}
}

function quitarTodos()
{
	var i = 0;
	
	for(i=0; i<document.form2.elements.length; i++)
	{
		if (document.form2.elements[i].id.substring(0,3)=='chk')
		{
			document.form2.elements[i].checked = false;
		}		
	}
}

function seleccionarSeccion(hotel, estrellas, hosteria, cabania, apart, hostel)
{
	var principioNombre = "chk_" + hotel + "_" + estrellas + "_" + hosteria + "_" + cabania + "_" + apart + "_" + hostel;
	var longNombre = principioNombre.length;
	
	for(i=0; i<document.form2.elements.length; i++)
	{
		if (document.form2.elements[i].id.substring(0,longNombre)==principioNombre)
		{
			document.form2.elements[i].checked = true;
		}		
	}
}

function quitarSeccion(hotel, estrellas, hosteria, cabania, apart, hostel)
{
	var principioNombre = "chk_" + hotel + "_" + estrellas + "_" + hosteria + "_" + cabania + "_" + apart + "_" + hostel;
	var longNombre = principioNombre.length;
	
	for(i=0; i<document.form2.elements.length; i++)
	{
		if (document.form2.elements[i].id.substring(0,longNombre)==principioNombre)
		{
			document.form2.elements[i].checked = false;
		}		
	}
}

function validarConsultaMasiva()
{
	var seleccionados = 0;
	for(i=0; i<document.form2.elements.length; i++)
	{
		if (document.form2.elements[i].id.substring(0,3)=='chk')
		{
			if (document.form2.elements[i].checked) 
			{
				document.form2.submit();
				return 1;
			}
		}		
	}
	
	alert ('Debe seleccionar al menos un hotel para enviar la consulta');
	return 0;
	
}

function validarFormConsultaMasiva()
{
	if (document.form2.txtNombre.value=='')
	{
		alert('Por favor, ingrese su nombre y apellido');
		document.form2.txtNombre.focus();
		return 0;
	}
	
	if (document.form2.txtEmail.value=='')
	{
		alert('Por favor, ingrese su email');
		document.form2.txtEmail.focus();
		return 0;
	}	
	
	if (!isEmailAddress(document.form2.txtEmail.value))
	{
		alert('Por favor, ingrese un email correcto');
		document.form2.txtEmail.focus();
		return 0;
	}
	
	if (document.form2.cmbPasajeros.value=='')
	{
		alert('Por favor, ingrese la cantidad de pasajeros');
		document.form2.cmbPasajeros.focus();
		return 0;
	}
	
	if (document.form2.txtDesde.value=='')
	{
		alert('Por favor, ingrese la fecha de check in');
		document.form2.txtDesde.focus();
		return 0;
	}
	
	if (document.form2.txtHasta.value=='')
	{
		alert('Por favor, ingrese la fecha de check out');
		document.form2.txtHasta.focus();
		return 0;
	}	

	calcularNoches();
	
	if (document.getElementById('hdnCantNoches').value=='' || document.getElementById('hdnCantNoches').value<=0)
	{
		alert('La fecha de check in debe ser anterior a la de check out');
		document.form2.txtHasta.focus();
		return 0;
	}	
	
	document.form2.submit();
}

function ValidarComentarios()
{
	if (document.formCalificar.txtNombre.value=='')
	{
		alert('Por favor, ingrese su nombre y apellido');
		document.formCalificar.txtNombre.focus();
		return 0;
	}
	
	if (document.formCalificar.txtEmail.value=='')
	{
		alert('Por favor, ingrese su email');
		document.formCalificar.txtEmail.focus();
		return 0;
	}	
	
	if (!isEmailAddress(document.formCalificar.txtEmail.value))
	{
		alert('Por favor, ingrese un email correcto');
		document.formCalificar.txtEmail.focus();
		return 0;
	}
	
	if (document.formCalificar.cmbCalificacion.value=='')
	{
		alert('Por favor, ingrese la calificacion general del alojamiento');
		document.formCalificar.cmbCalificacion.focus();
		return 0;
	}
	
	if (document.formCalificar.txtComentarios.value=='')
	{
		alert('Por favor, ingrese algun comentario sobre el alojamiento');
		document.formCalificar.txtComentarios.focus();
		return 0;
	}
	
	document.formCalificar.submit();
}

function viewHotelDetail(hotelID, top)
{	
	hiddenHotelID = document.getElementsByName("selectedHotelID")[0];
	boton = document.getElementsByName("btnViewDetail" +hotelID)[0];
	if(boton.value == '>')
	{
		if(hiddenHotelID.value != "")
		{
			botonAnterior = document.getElementsByName("btnViewDetail" +hiddenHotelID.value)[0];
			botonAnterior.value = '>';
		}
		yPos = top +'px';
		$("#divHotelDetail").css('top', yPos);
		$("#divHotelDetail").show('slow');
		hiddenHotelID.value = hotelID;
		boton.value = '<<';
	}
	else
	{
		$("#divHotelDetail").hide('slow');
		hiddenHotelID.value = "";
		boton.value = '>';
	}
}

function popitup(url) 
{
	newwindow=window.open(url,'name','height=200,width=150');
	if (window.focus) {newwindow.focus()}
	return false;
}

function mostrarMenu(id)
{
	if (document.getElementById(id).style.display == 'none')
	{
		document.getElementById(id).style.display = 'block';
		document.getElementById('img_' + id).src = 'imagenes/menos.gif';
	}
	else
	{
		document.getElementById(id).style.display = 'none';
		document.getElementById('img_' + id).src = 'imagenes/mas.gif';
	}
}

function mostrarIMGProvincia(src)
{
	document.getElementById('imgMapa').src = 'imagenes/' + src;
}

function preCargarImagenesMapa()
{
	if (document.images)
	{
		pic1= new Image(100,25); 
		pic1.src="imagenes/mapa_er.jpg";

		pic2= new Image(100,25); 
		pic2.src="imagenes/mapa_bsas.jpg";

		pic3= new Image(100,25); 
		pic3.src="imagenes/mapa_catamarca.jpg";

		pic4= new Image(100,25); 
		pic4.src="imagenes/mapa_chubut.jpg";

		pic5= new Image(100,25); 
		pic5.src="imagenes/mapa_cordoba.jpg";

		pic6= new Image(100,25); 
		pic6.src="imagenes/mapa_corrientes.jpg";

		pic7= new Image(100,25); 
		pic7.src="imagenes/mapa_formosa.jpg";

		pic8= new Image(100,25); 
		pic8.src="imagenes/mapa_jujuy.jpg";

		pic9= new Image(100,25); 
		pic9.src="imagenes/mapa_lapampa.jpg";

		pic10= new Image(100,25); 
		pic10.src="imagenes/mapa_larioja.jpg";

		pic11= new Image(100,25); 
		pic11.src="imagenes/mapa_mendoza.jpg";

		pic12= new Image(100,25); 
		pic12.src="imagenes/mapa_misiones.jpg";

		pic13= new Image(100,25); 
		pic13.src="imagenes/mapa_neuquen.jpg";

		pic14= new Image(100,25); 
		pic14.src="imagenes/mapa_rionegro.jpg";

		pic15= new Image(100,25); 
		pic15.src="imagenes/mapa_salta.jpg";

		pic16= new Image(100,25); 
		pic16.src="imagenes/mapa_sanjuan.jpg";

		pic17= new Image(100,25); 
		pic17.src="imagenes/mapa_sanluis.jpg";

		pic18= new Image(100,25); 
		pic18.src="imagenes/mapa_santacruz.jpg";

		pic19= new Image(100,25); 
		pic19.src="imagenes/mapa_santiago.jpg";

		pic20= new Image(100,25); 
		pic20.src="imagenes/mapa_stafe.jpg";

		pic21= new Image(100,25); 
		pic21.src="imagenes/mapa_tierradelfuego.jpg";

		pic22= new Image(100,25); 
		pic22.src="imagenes/mapa_tucuman.jpg";

		pic23= new Image(100,25); 
		pic23.src="imagenes/mapa_chaco.jpg";
	}
}
