// SINOPSIS
// Funciones comunes a tratamiento de mapas entre user y admin
// KNOWN BUGS
// BITACORA 
// GB 14-1-2008 CReacion
// GB 23-4-2008 Se agregaron atributos a propiedad
// GB 13-3-2009 Las calles y otros labels menores se muestran solo en el segundo nivel de zoom

// GB 17-4-2009 Cambio a version 7 para implementacion de nueva version del sitio
// GB 15-5-2009 Map Control to Top Right
// GB 29-5-2009 Cambio en mensaje "Sorry, we are experimenting..."

// GB 11-7-2009 Version 8: removes all functions related to labels like street names and plazas
// GB 17-7-2009 Version unificada de common y user!

// GB 30-7-2009 VERSION PARA VALUE HOMES

// GLOBALES (Revisar esto) 
var map;
var debug = 0;
var zoomLevel;
var INITIAL_ZOOM_LEVEL = 14;
// GB 11-2-2009
var SLOW = 0;
var FAST = 1;
// COLORES
var GRIS = "#333333";
var AZUL = "#0A1F62";
// Valores default
var filtroResidences = 0;
var filtroRentalPrice = 0;
var filtroSalePrice = 0;
var filtroSize = 0;
// GB 10-2-2009
// array de rotating properties
var rotatingProperties = new Array();
/* gb 2-9-2010 rotamos solo el resultado de las busquedas
if ( directory() == "valuehomestest" )
{
	rotatingProperties[0] = 107;
	rotatingProperties[1] = 108;
	rotatingProperties[2] = 109;
	rotatingProperties[3] = 110;
}
else
{
	rotatingProperties[0] = 128;
	rotatingProperties[1] = 142;
	rotatingProperties[2] = 143;
	rotatingProperties[3] = 144;
	rotatingProperties[4] = 145;
	rotatingProperties[5] = 146;
	rotatingProperties[6] = 147;
	rotatingProperties[7] = 148;
	rotatingProperties[8] = 119;
	rotatingProperties[9] = 149;
	rotatingProperties[10] = 150;
	rotatingProperties[11] = 127;
	rotatingProperties[12] = 129;
	rotatingProperties[13] = 130;
	rotatingProperties[14] = 151;
	rotatingProperties[15] = 120;
	rotatingProperties[16] = 121;
	rotatingProperties[17] = 154;
	rotatingProperties[18] = 122;
	rotatingProperties[19] = 156;
	rotatingProperties[20] = 157;
	rotatingProperties[21] = 158;
	rotatingProperties[22] = 159;
	rotatingProperties[23] = 131;
	rotatingProperties[24] = 132;
	rotatingProperties[25] = 160;
	rotatingProperties[26] = 161;
	rotatingProperties[27] = 162;
	rotatingProperties[28] = 163;
	rotatingProperties[29] = 181;
	rotatingProperties[30] = 164;
	rotatingProperties[31] = 165;
	rotatingProperties[32] = 166;
	rotatingProperties[33] = 133;
	rotatingProperties[34] = 167;
	rotatingProperties[35] = 168;
	rotatingProperties[36] = 169;
	rotatingProperties[37] = 170;
	rotatingProperties[38] = 118;
	rotatingProperties[39] = 171;
	rotatingProperties[40] = 172;
	rotatingProperties[41] = 173;
	rotatingProperties[42] = 134;
	rotatingProperties[43] = 112;
	rotatingProperties[44] = 114;
	rotatingProperties[45] = 135;
	rotatingProperties[46] = 137;
	rotatingProperties[47] = 174;
	rotatingProperties[48] = 175;
	rotatingProperties[49] = 176;
	rotatingProperties[50] = 177;
	rotatingProperties[51] = 178;
	rotatingProperties[52] = 179;
	rotatingProperties[53] = 139;
	rotatingProperties[54] = 140;
	rotatingProperties[55] = 141;
	rotatingProperties[56] = 128;
}
*/
var nextPropertyIndex = 0;
// gb 2-9-2010
// var rotatingTime = 7500;
var rotatingTime = 7500;
var timeoutId;

// SINOPSIS
// retorna el nombre del directorio, para distinguir si estamos en testing o no
// KNOWN BUGS
// No es automatica, setear a mano
// BITACORA 
// GB 17-3-2007 Creacion
function directory()
{
	// return "valuehomestest";
	return "valuehomesfl.com";
}

// SINOPSIS
// Carga el mapa
// KNOWN BUGS
// BITACORA 
// GB 16-12-2007 Creacion
// GB 13-7-2009 Grayed Properties
// function load() 
function load( properties ) 
{	
  	if (GBrowserIsCompatible()) 
  	{
		map = new GMap2( document.getElementById("map"), { mapTypes : [G_HYBRID_MAP, G_NORMAL_MAP]} );
		var topRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,10));
		map.addControl(new GSmallMapControl(), topRight);
		map.enableContinuousZoom();
		map.addControl(new GMapTypeControl());
		// Centro el mapa
		centerMap();
		// Muestra las propiedades
		showProperties();		
	}
}

// SINOPSIS
// Muestra una propiedad en infowindos
// KNOWN BUGS
// BITACORA 
// AG 04-2008 Creacion
// GB 10-04-2008 Revision y cambion nombre
// GB 9-3-2009 Agregamos posibilidad de contar vistas de infowindow
// function mostrarInfowindow( idx , speed )
function mostrarInfowindow( idx , speed, count )
{
	// alert( "En mostrarInfowindow, id = " + idx );
	ajax = creaAjax();	
	// gb 26-4-2008 pruebo con GET, como esta en los manuales en vez de POST, para sortear el problema com FF
	ajax.open("GET", "AXPropiedad.php?IA="+idx+"&count="+count, true);
	ajax.onreadystatechange = function() 
  	{   
	   	if (ajax.readyState == 4)
		{  
		  	// alert(ajax.responseText);
			// parseo la respuesta y convierto en array
			var arrTemp = ajax.responseText.split("|");
			// chequeo si hay contenido en la respuesta
			if ( arrTemp.length == 1 )
			{
				// GB 2-9-2010
				mostrarMensaje( "Retrieving properties...");
				return;
			}
			// creo propiedad en base a array
			p = createProperty( arrTemp );
			// armo infowindow
			var html = buildInfowindowContent( p );
			abrirInfowindow( html, speed );
		} 
    }
    ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    ajax.send(null);
}

// SINOPSIS
// Apaga con un efecto de fade out la infowindow
// BITACORA
// GB 11/2/2009 Cambio nombres desde Abrir... y saco window title
// GB 11/2/2009 Traida desde styled_popup.js aca
// GB 10/2/2008 Creacion
// GB 28/8/2009 Slowly queda mejor siempre
function abrirInfowindow(html, speed)
{
	// gb 2-9-2010
 	if ( speed == SLOW )
		slowlyFireMyPopup(html);
	else
		fireMyPopup(html);
}

// SINOPSIS
// Mueve mapa al centro elegido
// function centerMapInPalermo()
function centerMap()
{
	var point = new GLatLng(25.478268336775678, -80.42508058929443);
	map.setCenter( point, INITIAL_ZOOM_LEVEL );
}

// SINOPSIS
// Trae y muestra propiedades en el mapa
// KNOWN BUGS
// - separar en una funcion que haga el query y otra que muestre
// BITACORA 
// GB 16-12-2007 Creacion
// AG 18-12-2007 Agregado de llamado a funcion AJAX para traer lista de properties
// GB 18-12-2007 Revision, indentado.
// AG 1-3-3008 Agregado de filtros
function showProperties()
{
	// ag 1-3-2008 levantamos valores del filtro
   	var filtro_residences = obtenerFiltroResidences();
  	var filtro_rental_price = obtenerFiltroRentalPrice();
  	var filtro_sale_price = obtenerFiltroSalePrice();
  	var filtro_size = obtenerFiltroSize();
	
	// gb 1-3-2008 llamada ajax
	var arrTemp  = new Array(); 

	ajax = creaAjax();
	
	ajax.open("GET", "AXPropiedades.php?residences="+filtro_residences+"&rentalprice="+filtro_rental_price+"&saleprice="+filtro_sale_price+"&size="+filtro_size, true);
	
  	ajax.onreadystatechange = function() 
	{
   		if ( ajax.readyState == 1 ) 
		{
			// alert( "ajax.readyState = 1");
		} 
		else 
		if (ajax.readyState == 4 )
		{
			// alert(ajax.responseText);
     		// Convertir el contenido de ajax en arrays JS
     		arrTemp = convertirTextToArray(ajax.responseText);
			// Reset rotating properties
			nextPropertyIndex = 0;
    		// Recorro el array de propiedades
     		for( i = 0; i < arrTemp.length; i++)
     		{
				// gb 30-6-2008 Uso propiedad simplificada
				var p = new PropiedadMapaUser();
				// creo cada propiedad
				p.id  = arrTemp[i][0];
				// gb 30-6-2008 solo traigo los puntos
				p.latitud = arrTemp[i][1];
				p.longitud = arrTemp[i][2];
				// gb new 16-3
				p.capacidad = arrTemp[i][3];
				p.name = arrTemp[i][4];
				// fin new
				var point = new GLatLng( p.latitud, p.longitud );
				addPropertyToMap( map, point, p );
				// gb 2-9-2010 rearmo rotating properties
				rotatingProperties[i] = p.id;
			}
			// gb 2-9-2010 - para rotar solo la seleccion o busqueda
			lastPropertyIndex = arrTemp.length;
			// alert( arrTemp.length );
			
			//////////////////////////////////////////////////////////////////////////////////////////////////
			// gb 1-4-2008 desde aca poner todo lo que queremos hacer al mapa despues de recargar propiedades!
			/////////////////////////////////////////////////////////////////////////////////////////////////
				
			// Si se hizo cualquier busqueda...
			if ( filtro_residences > 0 || filtro_rental_price > 0 || filtro_sale_price > 0 || filtro_size > 0 )
			{
				if ( arrTemp.length == 0 )
					mostrarMensaje("There are no properties that fit your search. Please change selection or clear search");
				else
					mostrarMensaje("Click on pins to view filtered property details on the window to your left.");
			}
			else
			{
				centerMap();
			}
			
			// gb 2-9-2010
			rotarInfowindow();
		}
	} 
    ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    ajax.send(null);
}

// obtiene el filtro....
function obtenerFiltroResidences()
{
	// gb 17-6-2009
	if ( filtroResidences == 0 )
	{
		filtroResidences = readCookie( "filtroResidences" );
		if ( filtroResidences == null )
			filtroResidences = 0;
		else
			setFiltroResidences( filtroResidences );
	}
	// fin gb 17-6
	return filtroResidences;
}

// Obtiene el filtro de precio actualmente seteado
function obtenerFiltroRentalPrice()
{
	if ( filtroRentalPrice == 0 )
	{
		filtroRentalPrice = readCookie( "filtroRentalPrice" );
		if ( filtroRentalPrice == null )
			filtroRentalPrice = 0;
		else
			setFiltroRentalPrice( filtroRentalPrice );
	}
	// fin gb 17-6
	return filtroRentalPrice;
}

// Obtiene el filtro de precio actualmente seteado
function obtenerFiltroSalePrice()
{
	if ( filtroSalePrice == 0 )
	{
		filtroSalePrice = readCookie( "filtroSalePrice" );
		if ( filtroSalePrice == null )
			filtroSalePrice = 0;
		else
			setFiltroSalePrice( filtroSalePrice );
	}
	// fin gb 17-6
	return filtroSalePrice;
}

// Obtiene el filtro de tamaņo actualmente seteado
function obtenerFiltroSize()
{
	// gb 17-6-2009
	if ( filtroSize == 0 )
	{
		filtroSize = readCookie( "filtroSize" );
		if ( filtroSize == null )
			filtroSize = 0;
		else
			setFiltroSize( filtroSize );
	}
	// fin gb 17-6
	return filtroSize;
}

// SINOPSIS
// Constructor de objeto Propiedad
// KNOWN BUGS
// BITACORA 
// AG 18-12-2007 Creacion en base a PropiedadMapa en common
function PropiedadMapaUser() 
{ 
	var id;
	var longitud;
	var latitud;
	var capacidad;
	var name;

	this.id = id;
	this.latitud = latitud;   
	this.longitud = longitud;
	// new gb 16-3
	this.capacidad = capacidad;
	this.name = name;
}

// SINOPSIS
// Agregar una propiedad al mapa
// KNOWN BUGS
// BITACORA 
// GB 17-12-2007 Creacion
// GB 18-12-2007 Completar HTML en base a parametros
// GB 20-02-2008 Nueva interfase
// function addPropertyToMap( map, point, idx, direccion_publica )
function addPropertyToMap( map, point, property )
{
	var marker = createMarker( point, property.id, composeTooltip(property) );
	map.addOverlay( marker );	
}

// SINOPSIS
// Arma el texto del tooltip
// KNOWN BUGS
// BITACORA 
// GB 16-03-2009 Creacion
function composeTooltip( property )
{
	// gb 25-6-2009
	return property.name;
}

// SINOPSIS
// A function to create the marker and set up the event window
// KNOWN BUGS
// Dont try to unroll this function. It has to be here for the function closure
// Each instance of the function preserves the contends of a different instance
// of the "marker" and "html" variables which will be needed later when the event triggers.    
// INPUT 
// point - coordenadas donde ubicar el marker
// html - contenido de la ventana que se abre al "estimular" el marker
// windowTitle - titulo de la ventana
// BITACORA 
// GB 16-12-2007 Creacion
// GB 30-6-2008  Para mayor reuso de codigo
// function createMarker( point, html, windowTitle ) 
// function createMarker( point, idx, windowTitle ) 
function createMarker( point, idx, toolTip ) 
{
	// gb 23-3-2008 ponemos icono en azul, ver si sacar esto afuera para hacer mas eficiente
	// var icon = new GIcon(G_DEFAULT_ICON);
	var icon = new GIcon();
	
	// GB 2-9-2010 
	icon.image = "images/mm_20_red.png";
	icon.shadow = "images/mm_20_shadow.png";
	icon.iconSize = new GSize(12, 20);
	icon.shadowSize = new GSize(22, 20);
	icon.iconAnchor = new GPoint(6, 20);
	markerOptions = { icon:icon, title:toolTip };	

	// Set up our GMarkerOptions object
	var marker = new GMarker( point, markerOptions );
	
	// gb 3-6 prueba
	GEvent.addListener( marker, "click", function() {
		apagarRotarInfowindow();
		alertMessageOff();		
		mostrarInfowindow( idx, FAST, 1 );
	});
	
	return marker;
}

// SINOPSIS
// Apaga la rotacion de propiedades en el infowindow 
// ASSUPTIONS & BUGS
// Usa variable glbal timeoutId
// BITACORA
// GB 10-2-2008 Creacion
function apagarRotarInfowindow()
{
	clearTimeout( timeoutId );
}

// SINOPSIS
// Agregar una propiedad al mapa
// KNOWN BUGS
// BITACORA 
// GB 17-12-2007 Creacion
// GB 18-12-2007 Completar HTML en base a parametros
// GB 20-02-2008 Nueva interfase
// GB 23-4-2008 Nuevo layout
function buildInfowindowContent( property )
{
	// alert( "Entrando a buildInfowindowContent()");
	
	sIdx = new String(property.id);
	var newMoreUrl = 'propiedad.php?IA='+sIdx;
	
	/*
	var urlImagen1 = '../' + directory() + '/inmmo/upload/INMO/' + property.foto1_th;
	var urlImagen2 = '../' + directory() + '/inmmo/upload/INMO/' + property.foto2_th;
	var urlImagen3 = '../' + directory() + '/inmmo/upload/INMO/' + property.foto3_th;
	var urlImagen4 = '../' + directory() + '/inmmo/upload/INMO/' + property.foto4_th;
	var urlImagen5 = '../' + directory() + '/inmmo/upload/INMO/' + property.foto5_th;
	*/
	
	var urlImagen1 = '/inmmo/upload/INMO/' + property.foto1_th;
	var urlImagen2 = '/inmmo/upload/INMO/' + property.foto2_th;
	var urlImagen3 = '/inmmo/upload/INMO/' + property.foto3_th;
	var urlImagen4 = '/inmmo/upload/INMO/' + property.foto4_th;
	var urlImagen5 = '/inmmo/upload/INMO/' + property.foto5_th;
	
	// gb 23-4-2008 calculo la superficie total
	var sup_total_mts = parseInt(property.sup_int_mts) + parseInt(property.sup_ext_mts);
	var sup_total_pies = parseInt(property.sup_int_pies) + parseInt(property.sup_ext_pies);
				
	// esto es importante sino da undefined
	var myHtml="";
	
	// gb 31-3-2009 cambio font
	// gb 10-7-2009 simplifico codigo
	myHtml += '<span id="styled-popup-title">'+property.direccion_publica+'</span>';
		
	// IMAGENES
	
	// PRIMERA
	// gb 5-6-, antes relative, top 10
	if( property.foto1_th )
	{
		myHtml += '<div style="width:205px; height:140px; background-color:#999999; text-align:center; position: absolute; left: 15px; top: 30px">';
		myHtml += '<img src="'+urlImagen1+'" style="height:140px; width:205px; overflow:hidden; border: none" usemap="#p1"></img>';
		myHtml += '<map name="p1">';
		myHtml += '<area shape="rect" coords="0,0,205,140" href="propiedad.php?IA='+sIdx+'" />';
  		myHtml += '</map>';
		myHtml += '</div>';
	}
	
  	if( property.foto2_th )
	{
		myHtml += '<div style="width:100px; height:65px; background-color:#999999; text-align:center; position: absolute; left: 15px; top: 180px; border:none">';
 		myHtml += '<img src="'+urlImagen2+'" style="height:65px; width:100px; border:none" usemap="#p2"></img>';
		myHtml += '<map name="p2">';
		myHtml += '<area shape="rect" coords="0,0,65,100" href="propiedad.php?IA='+sIdx+'" />';
  		myHtml += '</map>';
		myHtml += '</div>';
	}
	
 	if( property.foto3_th )
	{
		myHtml += '<div style="width:100px; height:65px; background-color:#999999; text-align:center; position: absolute; left: 120px; top: 180px">';
		myHtml += '<img src="'+urlImagen3+'" style="height:65px; width:100px; overflow:hidden; border:none" usemap="#p3"></img>';
		myHtml += '<map name="p3">';
		myHtml += '<area shape="rect" coords="0,0,65,100" href="propiedad.php?IA='+sIdx+'" />';
  		myHtml += '</map>';
		myHtml += '</div>';
	}
	
   	if( property.foto4_th )
	{
		myHtml += '<div style="width:100px; height:65px; background-color:#999999; text-align:center; position: absolute; left: 15px; top: 253px">';
		myHtml += '<img src="'+urlImagen4+'" style="height:65px; width:100px; overflow:hidden; border:none" usemap="#p4"></img>';
		myHtml += '<map name="p4">';
		myHtml += '<area shape="rect" coords="0,0,65,100" href="propiedad.php?IA='+sIdx+'" />';
  		myHtml += '</map>';
		myHtml += '</div>';
	}
	
	// QUINTA
  	if( property.foto5_th )
	{
		myHtml += '<div style="width:100px; height:65px; background-color:#999999; text-align:center; position: absolute; left: 120px; top: 253px">';
		myHtml += '<img src="'+urlImagen5+'" style="height:65px; width:100px; overflow:hidden; border:none" usemap="#p5"></img>';
		myHtml += '<map name="p5">';
		myHtml += '<area shape="rect" coords="0,0,65,100" href="propiedad.php?IA='+sIdx+'" />';
  		myHtml += '</map>';
		myHtml += '</div>';
	}
	
	// features de la propiedad
	myHtml += '<table align="center" class="styled-popup-info">';

	// location va ahora centrado en la primera linea
	myHtml += '<tr>';		
	myHtml += '<td colspan="2" style="text-align: center">';		
	// Titulo?
	myHtml += '</td>';		
	myHtml += '</tr>';

	// la siguente linea con dos columnas
	myHtml += '<tr>';		
	myHtml += '<td>';		
	// Bedrooms 
	if ( property.ambientes == 0 )
		myHtml += '<b>Bedrooms:</b> ' + ' Studio' + '<br />'; 
	else
		myHtml += '<b>Bedrooms:</b> &nbsp;' + property.ambientes + '<br/>' + '<br/>';
	// Badrooms
	myHtml += '<b>Bathrooms:</b> ' + property.banos + '<br/>'; 

	myHtml += '</td>';
	
	myHtml += '<td style="text-align:right">';
	// Sale Price
	myHtml += '<b>Sale Price:</b> $ ' + property.precio + '<br/>' + '<br/>'; 
	// Rental Price
	myHtml += '<b>Rental Price:</b> $ ' + property.precio_mes + '<br/>'; 
	myHtml += '</td>';

	myHtml += '</tr>';
	
	myHtml += '</table>';		
	
	myHtml += '<br />';
	myHtml += '<br />';
	
	// gb 31-3-2009 sacamos el boton
	// myHtml += '<a href=' + newMoreUrl + ' style="position:absolute;left:0px;top:426px">';
	myHtml += '<a href=' + newMoreUrl + ' class="styled-popup-more-button">';
	myHtml += '<img src="images/version10/boton_on.gif" border="0" width="144" heigth="21">';
	// myHtml += 'View Full Property Details';
	myHtml += '</a>';
	return myHtml;
}

// SINOPSIS
// Rota propiedades en la infowindow
// ASSUPTIONS & BUGS
// Como en Testing y en Produccion difieren los ids, los tenemos que clavar a mano...
// BITACORA
// GB 23-4-2008 Creacion
// GB 10-2-2009 Agregamos rotacion
function openDefaultProperty()
{
	rotarInfowindow()
}

// SINOPSIS
// Rota la propiedad en la infowindow
// ASSUPTIONS & BUGS
// BITACORA
// GB 10-2-2008 Creacion
function rotarInfowindow()
{	
	// 2-9-2010
	apagarRotarInfowindow();
	propiedadId = obtenerProximaPropiedad();
	// 2-9-2010
	if ( propiedadId > 0 )
		mostrarInfowindow(propiedadId, SLOW, 0);
	timeoutId = setTimeout('rotarInfowindow()', rotatingTime);	
}

// SINOPSIS
// Obtiene la proxima propiedad a rotar 
// ASSUPTIONS & BUGS
// las propiedades estan fijas por id
// BITACORA
// GB 10-2-2008 Creacion
function obtenerProximaPropiedad()
{
	// gb 2-9-2010 si la busqueda da cero, no mostramos propiedades
	if ( lastPropertyIndex == 0 )
		return 0;
	// gb 2-9-2010 limitamos dinamicamente la rotacion a las busquedas
	// if ( nextPropertyIndex >= rotatingProperties.length )
	if ( nextPropertyIndex >= lastPropertyIndex )
		nextPropertyIndex = 0;
	return rotatingProperties[nextPropertyIndex++];
}

// Setea el fitro de area
function setFiltroResidences( valor )
{
   	filtroResidences = valor;
	/* gb 15-5-2009 no en la version con filtros tipografia diseņo 	*/
	document.getElementById("select-residences").innerHTML = residencesToString(valor);
	// gb 17-6-2009
	createCookie("filtroResidences",valor,0);
}

// Traduce el codigo de area a string
function residencesToString( valor )
{
	if ( valor == 0 )
		return '<span class="filter-option-not-selected">Residences</span>';
	else
	if ( valor == 1 )
		return '<span class="filter-option-selected">Home</span>';
	else
	if ( valor == 2 )
		return '<span class="filter-option-selected">Condominium</span>';
}

// SINOPSIS
// Muestra propiedades en el mapa teniendo en cuenta filtros
// KNOWN BUGS
// - Solo carga la propiedad de Pza. San Martin como ejemplo, falta el resto
// - Tambien habria que ver como implementar toda la estructura de filtros
// BITACORA 
// GB 1-3-2008 Creacion en base a AG
// function filtrarProperties()
function filtrarPropiedades()
{
	// alert( "En filtrarPropiedades(): entrando" );
	// Borrar los markers
	map.clearOverlays();
	// gb me aseguro un solo thread de infowindows, sino se disparan dos!
	// gb 2-9-2010 
	// apagarRotarInfowindow();
	showProperties();
}

// Setea el filtro de precio de alquiler
function setFiltroRentalPrice( valor )
{
	filtroRentalPrice = valor;
	// gb 15-5-2009 no en la version con filtros tipografia diseņo
	document.getElementById("select-rental-price").innerHTML = rentalPriceToString(valor);
	// gb 17-6-2009
	createCookie("filtroRentalPrice",valor,0);
}

// Setea el filtro de precio de venta
// COMPLETAR!!
function setFiltroSalePrice( valor )
{
	filtroSalePrice = valor;
	// gb 15-5-2009 no en la version con filtros tipografia diseņo
	document.getElementById("select-sale-price").innerHTML = salePriceToString(valor);
	// gb 17-6-2009
	createCookie("filtroSalePrice",valor,0);
}

// Traduce el codigo de precio a string
function salePriceToString( valor )
{
	if ( valor == 0 )
		return '<span class="filter-option-not-selected">Sale Price</span>';
	else	
	if ( valor == 1 )
		return '<span class="filter-option-selected">Under $90,000</span>';
	else	
	if ( valor == 2 )
		return '<span class="filter-option-selected">$90,000-$120,000</span>';
	else	
	if ( valor == 3 )
		return '<span class="filter-option-selected">$120,000-$150,000</span>';
	else	
	if ( valor == 4 )
		return '<span class="filter-option-selected">$150,000-$180,000</span>';
	else	
	if ( valor == 5 )
		return '<span class="filter-option-selected">$180,000-$210,000</span>';
	else	
	if ( valor == 6 )
		return '<span class="filter-option-selected">$210,000-$240,000</span>';
	else
	if ( valor == 7 )
		return '<span class="filter-option-selected">$240,000-$270,000</span>';
	else	
		return '<span class="filter-option-selected">More than $270,000</span>';
}

// Traduce el codigo de precio a string
function rentalPriceToString( valor )
{
	if ( valor == 0 )
		return '<span class="filter-option-not-selected">Rental Price</span>';
	else	
	if ( valor == 1 )
		return '<span class="filter-option-selected">Under $900</span>';
	else	
	if ( valor == 2 )
		return '<span class="filter-option-selected">$900-$1100</span>';
	else	
	if ( valor == 3 )
		return '<span class="filter-option-selected">$1100-$1300</span>';
	else	
	if ( valor == 4 )
		return '<span class="filter-option-selected">$1300-$1500</span>';
	else	
	if ( valor == 5 )
		return '<span class="filter-option-selected">$1500-$1700</span>';
	else	
	if ( valor == 6 )
		return '<span class="filter-option-selected">$1700-$2000</span>';
	else	
		return '<span class="filter-option-selected">More than $2000</span>';
}

// Setea el filtro de tamaņo (en variable global)
function setFiltroSize( valor )
{
	filtroSize = valor;
	// gb 15-5-2009 no en la version con filtros tipografia diseņo
	document.getElementById("select-size").innerHTML = sizeToString(valor);
	// gb 17-6-2009
	createCookie("filtroSize",valor,0);
}

// Traduce el codigo de tamaņo a string
function sizeToString( valor )
{
	if ( valor == 0 )
		return '<span class="filter-option-not-selected">Bed/Bath</span>';
	else	
	if ( valor == 1 )
		return '<span class="filter-option-selected">2/1</span>';
	else	
	if ( valor == 2 )
		return '<span class="filter-option-selected">2/2</span>';
	else	
	if ( valor == 3 )
		return '<span class="filter-option-selected">3/1</span>';
	else	
	if ( valor == 4 )
		return '<span class="filter-option-selected">3/2</span>';
	else	
	if ( valor == 5 )
		return '<span class="filter-option-selected">3/2.5</span>';
	else	
	if ( valor == 6 )
		return '<span class="filter-option-selected">4/2</span>';
	else	
	if ( valor == 7 )
		return '<span class="filter-option-selected">4/2.5</span>';
	else	
	if ( valor == 8 )
		return '<span class="filter-option-selected">5/2</span>';
}

// SINOPSIS
// Setea los combos en cero y vuelve a hacer la busqueda
// Centra el mapa?
// BITACORA
// gb 26-4-2009 Tambien vuelve a rotar las propiedades
function clearSearch()
{
	// gb 2-9-2010
	alertMessageOff();

	setFiltroResidences( 0 );
	setFiltroRentalPrice( 0 );
	setFiltroSalePrice( 0 );	
	setFiltroSize(0);
	
	filtrarPropiedades();
	
	// gb 2-9-2010 - no anda, algo se tara con esto
	// rotarInfowindow();
}

// SINOPSIS
// Muestra pagina de propiedad
// KNOWN BUGS
// Asegurarse que el path sirva en caso de mover la pagina de lugar...
// BITACORA 
// GB 2-3-2008 Creacion en base a AG
function mostrarPropiedad( idx )
{
	location.href="propiedad.php?IA="+idx;
}


// SINOPSIS
// Crea una propiedad en base a respuesta de query
// INPUT
// responseText - resultado de query ajax, en state = 4
// KNOWN BUGS
// Unificar y usar en maps_google_user_2.js tambien!
// BITACORA 
// GB 23-04-2008 Creacion
function createProperty( arrTemp )
{
	// alert( "Entrando a createProperty()");
	var p = new PropiedadMapa();
	// p.id = idx;
	p.id = arrTemp[0];
	// en la posision 1 esta la imagen chica o campo deprecado que no se usa mas
	p.direccion_publica = arrTemp[2];
	p.capacidad = arrTemp[3];
	p.sup_int_mts = arrTemp[4];
	p.ambientes = arrTemp[5];
	p.precio_diario = arrTemp[6]; 
	p.precio_semana = arrTemp[7]; 
	p.precio_mes = arrTemp[8];
	p.latitud = arrTemp[9];
	p.longitud = arrTemp[10];
	p.area = arrTemp[11];
	p.sup_int_pies = arrTemp[12];			
	// gb 23-4-2008 se agreagan estos tres y desplazan a las imagenes
	p.sup_ext_mts = arrTemp[13];
	p.sup_ext_pies = arrTemp[14];
	p.banos = arrTemp[15];
	/* gb 7-9-2009, agrego un campo mas aca y corro todos los que siguen una posicion */
	p.precio = arrTemp[16];
	p.foto1_th = arrTemp[17];
	p.foto2_th = arrTemp[18];				
	p.foto3_th = arrTemp[19];
	p.foto4_th = arrTemp[20];
	p.foto5_th = arrTemp[21];
	
	return p;
}

// SINOPSIS
// Constructor de objeto Propiedad
// KNOWN BUGS
// BITACORA 
// AG 18-12-2007 Creacion
// GB 18-12-2007 Revision, le faltaria pasar parametros en la creacion
function PropiedadMapa () 
{ 
	this.constructor.population++;  
	var id;
	// var foto_chica;
	var direccion_publica;
	var latitud;
	var longitud;
	var description;
	var capacidad;
	var ambientes;
	var sup_int_mts;
	var sup_int_pies;
	var precio_diario;
	var precio_semana;
	var precio_mes;
	var area;
	// gb 23-4-2008 se agregan estos tres
	var sup_ext_mts;
	var sup_ext_pies;
	var banos;
	// gb 7-9-2009 agrego el precio de venta
	var precio;
	
	var foto1_th;
	var foto2_th;
	var foto3_th;
	var foto4_th;
	var foto5_th;
		
	this.id = id;
	// this.foto_chica = foto_chica;
	this.direccion_publica = direccion_publica; 
	this.latitud = latitud;
	this.longitud = longitud;
	this.description = description;
	this.capacidad = capacidad;
	this.ambientes = ambientes;
	this.sup_int_mts = sup_int_mts;
	this.sup_int_pies = sup_int_pies;
	this.precio_diario = precio_diario;
	this.precio_semana = precio_semana;
	this.precio_mes = precio_mes;
	this.area = area;
	// gb 23-4-2008 se agregan estos tres
	this.sup_ext_mts = sup_ext_mts;
	this.sup_ext_pies = sup_ext_pies;
	this.banos = banos;
	// gb 7-9-2009 agrego precio de venta
	this.precio = precio;
	
	this.foto1_th = foto1_th;
	this.foto2_th = foto2_th;
	this.foto3_th = foto3_th;
	this.foto4_th = foto4_th;
	this.foto5_th = foto5_th;
}

// SINOPSIS
// Guarda valor en una cookie
// BITACORA
// gb 17-6-2009 Creacion
function createCookie(name,value,days) 
{
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

// SINOPSIS
// lee valor de una cookie
// BITACORA
// gb 17-6-2009 Creacion
function readCookie(name) 
{
	// alert( "Entrando a readCookie");
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

// SINOPSIS
// Elimina una cookie
// BITACORA
// gb 17-6-2009 Creacion
function eraseCookie(name) 
{
    createCookie(name,"",-1);
}

// SINOPSIS
// Muestra un mensaje en pantalla
// ASSUMPTIONS & BUGS
// POr ahora usa la infowindow de la home
// BITACORA
// gb 2-9-2010 creacion
function mostrarMensaje( mensaje )
{
	alertMessageOn( mensaje );
}


// SINOPSIS
// Muestra mensaje en zona de alerta
// BITACORA
// GB 19-10-2009 Creacion
// gb 2-9-2010 creacion
function alertMessageOn( s )
{
	// alert( "En alert Message on ");
	var element = document.getElementById("alert-message");
	element.innerHTML = "<p>"+s+"</p>";
	element.style.display = "block";
}

// SINOPSIS
// Apaga mensaje en zona de alerta
// BITACORA
// GB 19-10-2009 Creacion
// gb 2-9-2010 creacion
function alertMessageOff()
{
	var element = document.getElementById("alert-message");
	element.style.display = "none";
}

// SINOPSIS
// Convierte a formato $$$
// ASSUMPTIONS & BUGS
// BITACORA
// gb 17-9-2009 De la web
// gb 2-9-2010 creacion
function formatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
	// return (((sign)?'':'-') + '$' + num + '.' + cents);
	return (((sign)?'':'-') + ((num!=0)?'USD '+num:'N/A'));
}

// SINOPSIS
// Muestra un mensaje en pantalla
// ASSUMPTIONS & BUGS
// POr ahora usa la infowindow de la home
// BITACORA
// gb 24-4-2008 creacion
// gb 2-9-2010 deprecada
/*
function mostrarMensaje( mensaje )
{
	windowTitle = "";
	myHtml = "";
	myHtml += '<span style="position:absolute; top:175px; left:15px; width:200px; font-size:13px; font-weight:normal; text-align:center">';
	myHtml += mensaje;
	myHtml += "</span>";

	abrirInfowindow( myHtml, FAST );
}
*/

