function limpiarPrecioSemanalHasta()
{
	if(document.frmPrecioSemanal.cboPrecioSemanalDesde.value == "+800"){
		document.frmPrecioSemanal.cboPrecioSemanalHasta.selectedIndex = 0;
	}
	return true;
}

function limpiarPrecioMensualHasta()
{
	if(document.frmPrecioMensual.cboPrecioMensualDesde.value == "+3000"){
		document.frmPrecioMensual.cboPrecioMensualHasta.selectedIndex = 0;
	}
	return true;
}

function validarFrmPrecioSemanal()
{
    if(frmPrecioSemanal.cboPrecioSemanalDesde.value != "+800")
    {
        if(frmPrecioSemanal.cboPrecioSemanalHasta.value == "-")
		{
			alert("To Weekly Price is mandatory.");
			frmPrecioSemanal.cboPrecioSemanalHasta.focus();
			return false;
		}
		
		var iDesde = parseInt(frmPrecioSemanal.cboPrecioSemanalDesde.value);
		var iHasta = parseInt(frmPrecioSemanal.cboPrecioSemanalHasta.value);
		
		if(parseInt(iDesde) >= parseInt(iHasta))
		{
			alert("From Weekly Price must be less than To Weekly Price.");
        	return false;
		}
    }
	else
	{
		if(frmPrecioSemanal.cboPrecioSemanalHasta.value != "-")
		{
			alert("Search Format Error.");
			frmPrecioSemanal.cboPrecioSemanalDesde.focus();
			return false;
		}
	}

    return true;
}

function validarFrmPrecioMensual()
{
    if(frmPrecioMensual.cboPrecioMensualDesde.value != "+3000")
    {
        if(frmPrecioMensual.cboPrecioMensualHasta.value == "-")
		{
			alert("To Monthly Price is mandatory.");
			frmPrecioMensual.cboPrecioMensualHasta.focus();
			return false;
		}
		
		var iDesde = parseInt(frmPrecioMensual.cboPrecioMensualDesde.value);
		var iHasta = parseInt(frmPrecioMensual.cboPrecioMensualHasta.value);
		
		if(parseInt(iDesde) >= parseInt(iHasta))
		{
			alert("From Monthly Price must be less than To Monthly Price.");
        	return false;
		}
    }
	else
	{
		if(frmPrecioMensual.cboPrecioMensualHasta.value != "-")
		{
			alert("Search Format Error.");
			frmPrecioMensual.cboPrecioMensualDesde.focus();
			return false;
		}
	}

    return true;
}

function validarFrmFechas()
{
    if(frmFechas.txtFechaDesde.value == "")
    {
        alert("To is mandatory.");
        return false;
    }
    if(frmFechas.txtFechaHasta.value == "")
    {
        alert("From is mandatory.");
        return false;
    }
    
    var str1 = frmFechas.txtFechaDesde.value;
    var str2 = frmFechas.txtFechaHasta.value;
    
    var y1 = parseInt(str1.substring(0,4), 10);
    var m1 = parseInt(str1.substring(5,7), 10);
    var d1 = parseInt(str1.substring(8,10), 10);
    
    var y2 = parseInt(str2.substring(0,4), 10);
    var m2 = parseInt(str2.substring(5,7), 10);
    var d2 = parseInt(str2.substring(8,10), 10);
    
    var date1 = new Date(); 
    date1.setFullYear(y1, m1, d1);
    var date2 = new Date();
    date2.setFullYear(y2, m2, d2);
    
    if(date1 > date2)
    {
        alert("To Date must be before From Date.");
        return false;
    } 

    return true;
}

function validarRecomendar()
{
	if(frmRecomendar.txtNombre.value == "")
	{
		alert("Your Name is mandatory.");
		frmRecomendar.txtNombre.focus();
		return false;
	}
	if(frmRecomendar.txtEmail.value == "")
	{	
		alert("Your Friend's E-Mail is mandatory.");
		frmRecomendar.txtEmail.focus();
		return false;
	}
	return true;
}

function validarNewsletter()
{
	if((frmNewsletter.txtNombre.value == "Your Name") || (frmNewsletter.txtNombre.value == ""))
	{
		alert("Your Name is mandatory.");
		frmNewsletter.txtNombre.focus();
		return false;
	}
	if((frmNewsletter.txtMail.value == "Your E-Mail") || (frmNewsletter.txtMail.value == ""))
	{
		alert("Your E-Mail is mandatory.");
		frmNewsletter.txtMail.focus();
		return false;
	}
	window.open('','fncNewsletter','width=330,height=180,scrollbars=no,menubar=no,titlebar=no,resizable=no','');
	document.frmNewsletter.target='fncNewsletter';
	return true;
}

function validarNoticia()
{
	if(frmNoticia.txtNombreApellido.value == "")
	{
		alert("Full Name  is mandatory.");
		frmNoticia.txtNombreApellido.focus();
		return false;
	}
	if(frmNoticia.txtLugar.value == "")
	{
		alert("Origin is mandatory.");
		frmNoticia.txtLugar.focus();
		return false;
	}
	if(frmNoticia.txtEmail.value == "")
	{
		alert("E-Mail is mandatory.");
		frmNoticia.txtEmail.focus();
		return false;
	}
	return true;
}

function validarContacto()
{
	if(frmContactenos.txtNombreApellido.value == "")
	{
		alert("Full Name is mandatory.");
		frmContactenos.txtNombreApellido.focus();
		return false;
	}
	if(frmContactenos.txtLugar.value == "")
	{
		alert("Origin is mandatory.");
		frmContactenos.txtLugar.focus();
		return false;
	}
	return true;
}

function validarContactoVenta()
{
	if(frmContactenosVenta.txtNombreApellido.value == "")
	{
		alert("Full Name is mandatory.");
		frmContactenosVenta.txtNombreApellido.focus();
		return false;
	}
	return true;
}

function validarAgregar()
{
	if(frmAgregar.txtNombreApellido.value == "")
	{
		alert("Full Name is mandatory.");
		frmAgregar.txtNombreApellido.focus();
		return false;
	}
	if(frmAgregar.txtEmail.value == "")
	{
		alert("E-Mail is mandatory.");
		frmAgregar.txtEmail.focus();
		return false;
	}
	if(frmAgregar.txtTelefono.value == "")
	{
		alert("Telephone is mandatory.");
		frmAgregar.txtTelefono.focus();
		return false;
	}
	if(frmAgregar.txtCelular.value == "")
	{
		alert("Mobile is mandatory.");
		frmAgregar.txtCelular.focus();
		return false;
	}
	if(frmAgregar.txtDireccion.value == "")
	{
		alert("Address is mandatory.");
		frmAgregar.txtDireccion.focus();
		return false;
	}
	if(frmAgregar.txtDomicilio.value == "")
	{
		alert("Address is mandatory.");
		frmAgregar.txtDomicilio.focus();
		return false;
	}
	if(frmAgregar.txtBarrio.value == "")
	{
		alert("Neighbourhood is mandatory.");
		frmAgregar.txtBarrio.focus();
		return false;
	}
	if(frmAgregar.txtAmbientes.value == "")
	{
		alert("Rooms is mandatory.");
		frmAgregar.txtAmbientes.focus();
		return false;
	}
	if(frmAgregar.txtMetros.value == "")
	{
		alert("Area Size is mandatory.");
		frmAgregar.txtMetros.focus();
		return false;
	}
	if(frmAgregar.txtCapacidad.value == "")
	{
		alert("Capacity is mandatory.");
		frmAgregar.txtCapacidad.focus();
		return false;
	}
	return true;
}

/*function isDate(dateStr) {
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat);
	
	if (matchArray == null) {
		alert("Por favor ingrese la fecha correctamente.");
		return false;
	}
	
	month = matchArray[3];
	day = matchArray[1];
	year = matchArray[5];
	
	if (month < 1 || month > 12) {
		alert("El Mes debe ser un nro entre 1 y 12.");
		return false;
	}
	
	if (day < 1 || day > 31) {
		alert("El Dia debe ser un nro entre 1 y 31.");
		return false;
	}
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("El Mes "+month+" no tiene 31 dias!");
		return false;
	}
	
	if (month == 2) {
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			alert("Febrero " + year + " no tiene " + day + " dias!");
			return false;
		}
	}
	
	return true;
}
*/
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsNumber = false;
      }
   }
   return IsNumber;
}

function validarReserva()
{
	var iFechaDesde;
	var iFechaHasta;
	var dFechaIN;
	var dFechaOUT;
	
	if(frmCliente.txtNombre.value == "")
	{
		alert("First Name is mandatory.");
		frmCliente.txtNombre.focus();
		return false;
	}
	if(frmCliente.txtApellido.value == "")
	{
		alert("Last Name is mandatory.");
		frmCliente.txtApellido.focus();
		return false;
	}
	if(frmCliente.txtLugar.value == "")
	{
		alert("Origin is mandatory.");
		frmCliente.txtLugar.focus();
		return false;
	}
	if(frmCliente.txtNacionalidad.value == "")
	{
		alert("Nacionality is mandatory.");
		frmCliente.txtNacionalidad.focus();
		return false;
	}
	if(frmCliente.txtPasaporte.value == "")
	{
		alert("Passport / DNI is mandatory.");
		frmCliente.txtPasaporte.focus();
		return false;
	}
	if(frmCliente.txtEmail.value == "")
	{
		alert("E-Mail is mandatory.");
		frmCliente.txtEmail.focus();
		return false;
	}
	if(frmCliente.txtTelefono.value == "")
	{
		alert("Telephone is mandatory.");
		frmCliente.txtTelefono.focus();
		return false;
	}
	if(frmCliente.txtDireccion.value == "")
	{
		alert("Address is mandatory.");
		frmCliente.txtDireccion.focus();
		return false;
	}
	if(frmCliente.txtAdultos.value == "")
	{
		alert("Adults is mandatory.");
		frmCliente.txtAdultos.focus();
		return false;
	}
	if(frmCliente.txtNinos.value == "")
	{
		alert("Children is mandatory.");
		frmCliente.txtNinos.focus();
		return false;
	}
	if(!IsNumeric(frmCliente.txtAdultos.value))
	{
		alert("Adults must be a number.");
		frmCliente.txtAdultos.focus();
		return false;
	}
	if(!IsNumeric(frmCliente.txtNinos.value))
	{
		alert("Children must be.");
		frmCliente.txtNinos.focus();
		return false;
	}
	if(frmCliente.chkTerminos.checked == false)
	{
		alert("You must select I have read and accepted Terms and Conditions.");
		return false;
	}

	return true;
}

function openAgregar()
{
    window.open('http://www.buenosairesapartments.net/frmAgregarProp.asp','frmAgregarProp','width=330,height=680,scrollbars=no,menubar=no,titlebar=no,resizable=no','');
	document.frmNewsletter.target='frmAgregarProp';
}

function openVentas()
{
    window.open('http://www.buenosairesapartments.net/frmContactenosVenta.asp','frmContactenosVenta','width=350,height=560,scrollbars=no,menubar=no,titlebar=no,resizable=no','');
	document.frmNewsletter.target='frmContactenos';
}
