

function cambiar_fondo(celda1,color1,color2,img){

		if(color1){
			if(color1=="none"){
				 celda1.style.background='';
			}else{
				 celda1.style.background=color1;
				 celda1.style.color=color1;
			}
			
			 celda1.style.color=color2;
			 celda1.style.cursor='pointer';
		}else{
			celda1.style.backgroundImage="url('"+img+"')";
			celda1.style.cursor='pointer';
		}
			 
}


function oc(a)
{
  var o = {};
  for(var i=0;i<a.length;i++)
  {
    o[a[i]]='';
  }
  return o;
}

function cargar_select(accion,nom_sel1,nom_sel2,str,form){
			
		if(accion){
			cad="document."+form+"."+nom_sel1+".selectedIndex";
			
			nva=eval(cad);
			
			if(nva!=-1){
					cad="document."+form+"."+nom_sel1+".options["+nva+"]";	
					nva=eval(cad).value;
					nva_text=eval(cad).text;
					cad="document."+form+"."+str;
					cadena=eval(cad).value;
					cadena_array = cadena.split("#");
					if(!(nva in oc(cadena_array)))
					{
						
						cad="document."+form+"."+nom_sel2;
						if(eval(cad).length){
							if(eval(cad+'[0]').text.indexOf("...")!=-1){
								eval(cad+"[0]=null");
							}
						}
						val=eval(cad).length;
						val=nva+"-"+val;
						//alert(nva)
						cad="document."+form+"."+nom_sel2+".options[document."+form+"."+nom_sel2+".options.length]=new Option(nva_text,val)";
						//prp_dom.options [document.formulario.prp_dom.options.length]=new Option(nva,val);
						eval(cad);
						cad="document."+form+"."+str;
						eval(cad).value +=  nva + "#";
						//alert(eval("document.formulario."+str).value)
					}else{
						alert("Revise su sintaxis o asegurese de no estar repitiendo el item");
					}	
			}else{
				alert("Seleccione un Item para agregar")
			}	
				    						
		}else{
			    var cpto_borrar,e,aux,valor=0;
			    cad="document."+form+"."+str;
			    cadena=eval(cad).value;
			   // alert(document.formulario.prp_dom.selectedIndex)
			    cad="document."+form+"."+nom_sel2+".selectedIndex";
			    if(eval(cad)!=-1){
			    		cad="document."+form+"."+nom_sel2+".options[document."+form+"."+nom_sel2+".selectedIndex]";
			    		borrar=eval(cad).text;
						valor=eval(cad).value;
                                                valor = valor.split("-");
						cpto_borrar=valor[0] + "#";
						//alert(cadena.substring(cadena.indexOf(cpto_borrar,0)));
                                          // alert(cadena +'     ' + cpto_borrar)
                                            cadena2=cadena.substring(0,cadena.indexOf(cpto_borrar,0));
                                            
					    cadena3=cadena.substring(cadena.indexOf(cpto_borrar,0) + cpto_borrar.length,cadena.length);
					    str_zon=cadena2 + cadena3;
					    cad="document."+form+"."+str+".value=str_zon";
					    eval(cad);
					    cad="document."+form+"."+nom_sel2+".options[document."+form+"."+nom_sel2+".selectedIndex]=null";
					    eval(cad);	
			    }else{
					alert("Seleccione un Item para quitar")
                            }
		}
}

function agregarSitio(url,titulo){
	if (document.all){
		window.external.AddFavorite(url,titulo);
	}else{ 
		alert("Para Agregar en Favoritas presione Ctrl + D");
	}
}

function editarSeleccion(accion,usr_id){
		cad="";
		
		if(accion=="modificar"){
		
			for(i=0;i<10;i++){
				
				if($('prop'+i)){
					if($('prop'+i).checked){
						location.href="../propiedades/edit/usr_id/"+usr_id+"/prp_id/"+$('prop'+i).value+".html";
						return 1;
					}
				}
			}
	
		}else{

			for(i=0;i<10;i++){
				
				if($('prop'+i)){
					if($('prop'+i).checked){
						cad+=$('prop'+i).value+"-";		
					}
				}
			}
		
		}
		
		if(cad){
			if(confirm("�Esta seguro q desea eliminar las propiedades seleccionadas?")){
				location.href="../propiedades/delete/usr_id/"+usr_id+"/prps/"+cad+".html";
				return 1;	
			}
		}else{
		
			alert('Seleccione un Item')	
		}		
		
}

function checkEnter(event,form)	{ 	
	var code = 0;

	code = event.keyCode;
		
	if (code==13){
		eval('document.'+form).submit();
	}	
}
function checkUrlEnviar(event)	{
	var code = 0;

	code = event.keyCode;

	if (code==13){
            enviar_url();
	}
}

function flash(pelicula,width,height){

	document.write('<object type="application/x-shockwave-flash" data="' + pelicula + '" width="' + width + '" height="' + height + '">\n');
	document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
	document.write('<param name="movie" value="' + pelicula + '" />\n');
	document.write('<param name="quality" value="high" />\n');
	document.write('<param name="menu" value="false" />\n');
	document.write('</object>\n');
}

function enviarConsulta(tipo){
			
		if(tipo!="por_id"){
			
			url="";
			
   			pro=document.getElementById('prov');
			loc=document.getElementById('loc_id');
            tip=document.getElementById('tip_id');
            con=document.getElementById('con_id');
            pre_mi=document.getElementById('pre_min');
            pre_ma=document.getElementById('pre_max'); 
            dom=document.getElementById('prp_dom').value;
            mon_p=document.getElementById('pesos_p');
            mon_d=document.getElementById('pesos_d');
            s1=document.getElementById('ser1');
            s2=document.getElementById('ser2');
            s3=document.getElementById('ser3');
            s4=document.getElementById('ser4');
            cFoto=document.getElementById('conFoto');
            uSemana=document.getElementById('ultSemana');
            uMes=document.getElementById('ultMes');
            pro_la=document.getElementById('pro_lat');
            pro_ln=document.getElementById('pro_lng');
          
           
        	pro_id_=pro[pro.selectedIndex].value;
        	loc_id_=loc[loc.selectedIndex].value;
        	tip_id_=tip[tip.selectedIndex].value;
        	con_id_=con[con.selectedIndex].value;
        	
        	if(pro_id_!=0){
        		url+="pro_desc/"+pro[pro.selectedIndex].text;	
        	}
        	
        	if(loc_id_!=0){
        		url+="/loc_desc/"+loc[loc.selectedIndex].text;
        	}
        	
        	if(tip_id_!=0){
        		url+="/tip_desc/"+tip[tip.selectedIndex].text;
        	}
        	
        	if(con_id_!=0){
        		url+="/con_desc/"+con[con.selectedIndex].text;
        	}
        	
            pre_min_=pre_mi[pre_mi.selectedIndex].value;
        	pre_max_=pre_ma[pre_ma.selectedIndex].value;
        	
        	if(pre_min_>0){
        		url+="/pre_min/"+pre_min_;
        	}
        	
        	if(pre_max_>0){
        		url+="/pre_max/"+pre_max_;
        	}
        	
        	ser1_=s1[s1.selectedIndex].value;
        	ser2_=s2[s2.selectedIndex].value;
        	ser3_=s3[s3.selectedIndex].value;
        	ser4_=s4[s4.selectedIndex].value;
        	
        	if(ser1_!=""&&ser1_!="Indistinto"){
        		url+="/ser1/"+ser1_;
        	}
        	if(ser2_&&ser2_!="Indistinto"){
        		url+="/ser2/"+ser2_;
        	}
        	if(ser3_&&ser3_!="Indistinto"){
        		url+="/ser3/"+ser3_;
        	}
        	if(ser4_&&ser4_!="Indistinto"){
        		url+="/ser4/"+ser4_;
        	}
        	
        	cFoto_='';
        	uMes_='';
        	uSemana_='';
        	
        	if(cFoto.checked){
        		url+="/conFoto/"+cFoto.value;
        	}
        	
        	if(uMes.checked){
        		url+="/ultMes/"+uMes.value;
        	}
        	if(uSemana.checked){
        		url+="/ultSemana/"+uSemana.value;
        		
        	}
        	
        	if(dom){
        		url+="/prp_dom/"+dom;
        	}
        	
        	if(mon_p.checked)
        		url+="/pesos_desc/en-pesos";
        	else
        		url+="/pesos_desc/en-dolares";
        	
        	location.href='/es/propiedades/buscarPropiedades/'+url+'.html';	
		}else{
			$('usr_id').value;
			location.href='/es/propiedades/fichaGeneral.html?usr='+$('usr_id').value+'&prp='+$('prp_id').value;	
		}
}

function buscar_propiedades(obj,id,valor){
	
	
	
	if($('es_mapa').value==0){
                $(id).value=valor;
		$('form_filtros').submit();
	}else{
		
		handleSelected(obj);
	}
}

function enviar_detalles_filtro(cant,cad,query,url,q_string){
        q_string='';
        for(i=0;i<cant;i++){

            if($(cad+'_'+i).checked){
                q_string+='&'+cad+'[]='+$(cad+'_'+i).value;
            }
            
        }
       buscar_propiedades('',1,1,query,url,q_string);
}
function marcar_detalles_filtro(cantidad,cadena,indice){


if(!indice){
    marcado=0;
    cuenta=1;
    if(cantidad>0){
        for(i=0;i<cantidad;i++){

            if($(cadena+'_'+i).checked){
                cuenta++;
            }
        }

        if(cuenta-1==cantidad){
            for(i=0;i<cantidad;i++){
                    $(cadena+'_'+i).checked=0;
            }
        }else{
            for(i=0;i<cantidad;i++){
                    $(cadena+'_'+i).checked=1;
            }
        }
    }
    
 }else{
     for(i=0;i<cantidad;i++){
         $(cadena+'_'+i).checked=0;
      }
      $(cadena+'_'+indice).checked =1;
      $('form_filtros').submit();
 }

}



function guardar_consulta(url){

     comentario_nombre = jQuery('#comentario_nombre').val();
     comentario_texto = jQuery('#comentario_texto').val();
     comentario_telefono= jQuery('#comentario_telefono').val();
     comentario_email = jQuery('#comentario_email').val();
     consulta= jQuery('#guardar_consulta').attr('checked');

     if(consulta){
         jQuery('#guardar_consulta').removeAttr('checked');
         consulta = 0;
     }else{
         jQuery('#guardar_consulta').attr('checked','checked');
         consulta = 1;
     }

     jQuery.ajax({
          type: 'GET',
          url: url,
          data: 'comentario_nombre='+comentario_nombre+'&comentario_email='+comentario_email+'&comentario_texto='+comentario_texto+'&comentario_telefono='+comentario_telefono+'&guardar_consulta='+consulta
        });
}


function guardar_comentario(usr_id,prp_id,url){
	
	  var num=0;	
	  var contenedor = document.getElementById('comentarios_dinamicos'); //toma el DOM del div
	  

          comentario_nombre = jQuery('#form_comentarios').validate().element('#comentario_nombre');
          comentario_texto = jQuery('#form_comentarios').validate().element('#comentario_texto');
          comentario_email = jQuery('#form_comentarios').validate().element('#comentario_email');

	  if(comentario_nombre&&comentario_texto&&comentario_email){
                
	  	 var fila = document.getElementById('numero_fila'); //numero de fila del seguimiento
			//alert(fila.value)
		  
		  num = parseInt(fila.value) + 1;
		  fila.value = num;
		  
		   
		  var newdiv = document.createElement('div');
		  var divIdName = 'filaDiv_'+num;
		 
		  newdiv.setAttribute('id',divIdName);
		  
		  fila.value=num;
				

                               jQuery.ajax({
                                  type: 'POST',
                                  url: url,
                                  data: jQuery("#form_comentarios").serialize(),
                                  success: function(data) {
                                        jQuery.blockUI({ message: data });
                                        jQuery('.blockOverlay').attr('title','Click para cerrar').click(jQuery.unblockUI);
                                        setTimeout(jQuery.unblockUI, 4000);
                                        jQuery('#cargando_comentarios').hide();
                                       jQuery('#boton_guardar_comentario').attr('disabled',false);
                                    /*  jQuery('#comentario_nombre').val('');
                                        jQuery('#comentario_email').val('');
                                        jQuery('#comentario_telefono').val('');
                                        jQuery('#comentario_texto').val('');*/
                                    },
                                  beforeSend:function(){
                                      jQuery('#cargando_comentarios').show();
                                      jQuery('#boton_guardar_comentario').attr('disabled',true);
                                    }
                                });
	  }
	
}


function ver_datos_vendedor(usr_id,prp_id,url){
	  
	  nombre_contacto=document.getElementById('nombre_contacto').value; 
	  mail_contacto=document.getElementById('mail_contacto').value; 
	  telefono_contacto=document.getElementById('telefono_contacto').value;
	  
	  
	  if(nombre_contacto&&mail_contacto){
	  	
	  	if(echeck(mail_contacto)){
		
                                       jQuery.ajax({
                                          type: 'POST',
                                          url: url,
                                          data: jQuery("#formularioConsultas").serialize(),
                                          success: function(data) {
                                                jQuery('#cargando_datos_vendedor').hide();
                                                jQuery('#datos_vendedor').html(data);

                                            },
                                          onLoading:function(request, json){
                                              jQuery('#cargando_datos_vendedor').show();
                                              jQuery('#datos_vendedor').hide();

                                            }
                                        });

	  	}else{
	  		alert('Debe ingresar un E-mail Valido');
	  	}
	  	
	  }else{
	  		alert('Debe completar los datos del Formulario');
	  }
	  
	 
	
}
function echeck(str) 
{
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var dir_mal=0;
		if (str.indexOf(at)==-1){
		   dir_mal=1;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   dir_mal=1;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   dir_mal=1;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   dir_mal=1;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   dir_mal=1;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   dir_mal=1;
		 }
		
		 if (str.indexOf(" ")!=-1){
		   dir_mal=1;
		 }
		if (dir_mal==1)
		{
			return false;
		}
		else
		{
			return true;
		}
}

function watch(url,q_string,url_loc,url_precios,pro_id,con_id,query,pre_min,pre_max){
	
	if($('barra_buscador')){


             jQuery.history.init(function(url) {
                    buscar_propiedades('','watch_url','1',query,url,q_string);
                }
            );
		
		if($('pro_id')){
			obj_prov=$('pro_id');
			
		}else{
			obj_prov=$('prov');
		}
		
		new Ajax.Updater('sel_loc',
				url_loc,
				 {asynchronous:true, 
				  evalScripts:false, 
				  onComplete:function(request, json){
				  						Element.hide('cargandoLocalidad');
				  						Element.show('Localidad')}, 
				  onLoading:function(request, json){
				  						Element.show('cargandoLocalidad');
				  						Element.hide('Localidad')}, 
				  parameters:'pro_id=' + obj_prov.options[obj_prov.selectedIndex].value}
				  );
		
		
		new Ajax.Updater('preciosBuscadorSimple',
				url_precios,
				 {
				  asynchronous:false, 
				  evalScripts:false, 
				  onComplete:function(request, json){
				  						Element.hide('cargandoPreciosBuscadorSimple');
				  						Element.show('preciosBuscadorSimple')}, 
				  onLoading:function(request, json){
				  						Element.show('cargandoPreciosBuscadorSimple');
				  						Element.hide('preciosBuscadorSimple')}, 
				  parameters:'con_id=' + $('con_id').options[$('con_id').selectedIndex].value}
				  );
			
		  if($('con_id').options[$('con_id').selectedIndex].value==0){
                      con_id=1;
                  }else{
                      con_id=$('con_id').options[$('con_id').selectedIndex].value;
                  }
                  //alert(pre_min + ' ' +pre_max )
		  ejecutar_precios(con_id,query,url,pre_min,pre_max);
		
		if(document.getElementById('pro_id')){
                    buscar_propiedades('','watch_url','1',query,url,q_string);
		}

                
           

		//alert(history.previous)
			
	}
	
}

function tooltips(){
    jQuery(document).ready(function() {
                    jQuery('#demo img[title]').tooltip({
                                                            bodyHandler: function() {
                                                                 //  return jQuery("<img/>").attr("src", this.src)
                                                                 return "ajajajjaja";
                                                            },
                                                            showURL: false,
                                                            top :500 ,
                                                            left: -200
                                                        }
                         );

                });
    

}


  function activar_slider(id_slider,id_min,id_max,rango_1,rango_2,min_def,max_def,array_valores,query,url){
						  	
			    var slider = $(id_slider);
			
			   // alert('rango_1 ' + rango_1 + ' - ' + 'min_def ' + min_def  );
			    
			    new Control.Slider(slider.select('.handle'), slider, {
			      range: $R(rango_1, rango_2),
			      sliderValue: [min_def,max_def],
			      
			      values: array_valores,
			      restricted:true,
			      onSlide: function(values) {
			      		$(id_min).style.color='#999';
			      		$(id_max).style.color='#999';
			      		
			      		aux1=new oNumero(values[0]);
			      		aux2=new oNumero(values[1]);
			      		aux1=aux1.formato(-1,true).replace(/,/gi,".");
			      		aux2=aux2.formato(-1,true).replace(/,/gi,".");
			      		
			      		$(id_min).innerHTML=aux1;
			      		if(array_valores[array_valores.length-1]==values[1]){
			      	 		$(id_max).innerHTML='+'+aux2;
			      	 	}else{
			      	 		$(id_max).innerHTML=aux2;
			      	 	}
			      		
			      		
			      },
			      onChange: function (values){

			      	aux2=new oNumero(values[1]);
			      	aux2=aux2.formato(-1,true).replace(/,/gi,".");
			      	 	
			      	 if(array_valores[array_valores.length-1]==values[1]){
			      	 	$(id_max).innerHTML='+'+aux2;
			      	 }else{
			      	 	$(id_max).innerHTML=aux2;
			      	 }
			      	
			      	$(id_min).style.color='#000';
			      	$(id_max).style.color='#000';

                               /* new Ajax.Updater(
					'rangos_precios',
                                        '/es/propiedades/traerRangosPrecios.html?p_min='+values[0]+'&p_max='+values[1],
					{
					 asynchronous:true,
					 evalScripts:false
                                        }
					 );*/

			      	$(id_slider+'_min').value=values[0];
			      	if(values[1]==rango_2){
			      		$(id_slider+'_max').value=0;	
			      	}else{
			      		$(id_slider+'_max').value=values[1];
			      	}

                                if($('barra_buscador')){
                                    if($('barra_buscador').value==1){
                                           // buscar_propiedades(this,id_slider+'_min',values[0],query,url,'&'+id_slider+'_max='+values[1]);
                                    }
			      	}
			      	
			      }
			      
			    });
	 }
	 
	 function ejecutar_precios(con_id,query,url,min_def,max_def){
            
                if($('pre_min').value!=0){
                    min_def=$('pre_min').value;
                }

                
                if(($('pre_max').value!=1000000 || $('pre_max').value!=20000) && $('pre_max').value!=""){
                    max_def=$('pre_max').value;
                }

	 	
	 	if(con_id==1 || con_id==4 || con_id==0){
	 		if(max_def==0){
	 			max_def=1000000;
	 		}
                        
	 		activar_slider('pre','pre_valor1','pre_valor2',0,1000000,min_def,max_def,[0,10000,20000,30000,40000,50000,60000,70000,80000,90000,100000,120000,150000,170000,200000,250000,300000,350000,400000,500000,600000,700000,800000,900000,1000000],query,url);
	 	}else{
	 		if(max_def==0){
	 			max_def=20000;
	 		}
	 		activar_slider('pre','pre_valor1','pre_valor2',50,20000,min_def,max_def,[0,100,200,300,400,500,600,700,800,900,1000,1200,1500,1700,2000,2500,3000,3500,4000,5000,6000,7000,8000,9000,10000,12000,15000,17000,20000],query,url);
	 	}
	 }
	 
	 function oNumero(numero)
							{
		//Propiedades
		this.valor = numero || 0
		this.dec = -1;
		//M�todos
		this.formato = numFormat;
		this.ponValor = ponValor;
		//Definici�n de los m�todos
		function ponValor(cad)
		{
		if (cad =='-' || cad=='+') return
		if (cad.length ==0) return
		if (cad.indexOf('.') >=0)
		    this.valor = parseFloat(cad);
		else
		    this.valor = parseInt(cad);
		}
		function numFormat(dec, miles)
		{
		var num = this.valor, signo=3, expr;
		var cad = ""+this.valor;
		var ceros = "", pos, pdec, i;
		for (i=0; i < dec; i++)
		ceros += '0';
		pos = cad.indexOf('.')
		if (pos < 0)
		    cad = cad+"."+ceros;
		else
		    {
		    pdec = cad.length - pos -1;
		    if (pdec <= dec)
		        {
		        for (i=0; i< (dec-pdec); i++)
		            cad += '0';
		        }
		    else
		        {
		        num = num*Math.pow(10, dec);
		        num = Math.round(num);
		        num = num/Math.pow(10, dec);
		        cad = new String(num);
		        }
		    }
		pos = cad.indexOf('.')
		if (pos < 0) pos = cad.lentgh
		if (cad.substr(0,1)=='-' || cad.substr(0,1) == '+')
		       signo = 4;
		if (miles && pos > signo)
		    do{
		        expr = /([+-]?\d)(\d{3}[\.\,]\d*)/
		        cad.match(expr)
		        cad=cad.replace(expr, RegExp.$1+','+RegExp.$2)
		        }
		while (cad.indexOf(',') > signo)
		    if (dec<0) cad = cad.replace(/\./,'')
		        return cad;
		}
		}//Fin del objeto oNumero:


         function enviar_url(tipo_buscador,pesos,pro_id_query,query){

         //  alert('tipo_buscador' + tipo_buscador + ' persos' + pesos + 'pro_id_query ' + pro_id_query + ' query:' + query)
                if(!tipo_buscador){
                    tipo_buscador=(document.getElementById('tipo_buscador'))?document.getElementById('tipo_buscador').value:'';
                    
                }

                if(!pesos){
                    pesos=(document.getElementById('pesos'))?document.getElementById('pesos').value:'';
                }

                if(!pro_id_query){
                    pro_id_query=(document.getElementById('pro_id_query'))?document.getElementById('pro_id_query').value:'';
                }

                if(!query)
                       query=(document.getElementById('query'))?document.getElementById('query').value:'';
                
                if(query!=""){
                    location.href="/es/buscar-propiedades/"+tipo_buscador+"/"+pesos+"/"+pro_id_query+"/"+query+".html";
                }else{

                     document.getElementById('form_buscador_textual').submit();
                }

         }

         

function validar(campos)
{
	
	ok=1;
	for(i=0;i<campos.length;i++){
		
		str=(document.getElementById(campos[i])).value;
        if(str.match(/([\<])([^\>]{1,})*([\>])/i)!=null){
         ok=0;
		}
	}
	if(ok){
		return 1;
	}else{
		alert("No puede ingresar texto en HTML");
		return 0;	
	}	
        
}



         

