function desplegarUnidad(id,cantidad,existe){
	
	for(i=0;i<cantidad;i++){
		var bloque= document.getElementById("u_"+i);
		var imga= document.getElementById("imga_"+i);
		var imga_proy= document.getElementById("imga_proy");
		var img = 'img_'+i;
		var ruta1 = '../img/desplegar1.gif';
		var ruta2 = '../img/desplegar2.gif';
		if(id!=i){
			bloque.style.display="none";
			imga.style.display="none";
			document.images[img].src = ruta2;
			document.images[img].setAttribute('alt','Desplegar');	
		}else{
			if(bloque.style.display=="block"){
				bloque.style.display="none";
				imga.style.display="none";
				document.images[img].src = ruta2;
				document.images[img].setAttribute('alt','Desplegar');
				imga_proy.style.display="block";
			}else{
				bloque.style.display="block";
				imga.style.display="block";
				imga_proy.style.display="none";
				document.images[img].src = ruta1;
				document.images[img].setAttribute('alt','Contraer');
			}
			if(existe==0){
				imga.style.display="none";
				imga_proy.style.display="block";
			}
		}
	}
}
function iniciarProyecto(id,imgd){
		var imga= document.getElementById("imga_"+imgd);
		if(id!="proy"){
			var bloque= document.getElementById("u_"+id);
			var img = 'img_'+id;
			var ruta1 = '../img/desplegar1.gif';
			var ruta2 = '../img/desplegar2.gif';
			bloque.style.display="block";
			imga.style.display="block";
			document.images[img].src = ruta1;
			document.images[img].setAttribute('alt','Contraer');
		}else{
			imga.style.display="block";
		}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function busqueda(){
	var idTipo = document.buscador.idTipo.value;
	var idOperacion = document.buscador.idOperacion.value;
	var idDep = document.buscador.idDep.value;
	var idZona = document.buscador.idZona.value;
	var idDormitorio = document.buscador.idDormitorio.value;
	var idMoneda = document.buscador.idMoneda.value;
	var precio1 = document.buscador.precio1.value;
	var precio2 = document.buscador.precio2.value;
	var codigo = document.buscador.codigo.value;
	var error = "";
	var url="par1="+idTipo;
	url+="&par2="+idOperacion;
	url+="&par3="+idDep;
	url+="&par4="+idZona;
	url+="&par5="+idDormitorio;
	url+="&par6="+idMoneda;
	url+="&par7="+precio1;
	url+="&par8="+precio2;
	url+="&par9="+codigo;
	if(precio1!=""){
		if(isNaN(precio1)){
			error+= "El Primer Precio debe ser un número mayor a 0.\n";
		}else{
			if(precio1<=0){
				error+= "El Primer Precio debe ser un número mayor a 0.\n";
			}else{
				if(precio2==""){
					error+= "Debe ingresar el Segundo Precio.\n";
				}
			}
		}
	}
	if(precio2!=""){
		if(isNaN(precio2)){
			error+= "El Segundo Precio debe ser un número mayor a 0.\n";
		}else{
			if(precio2<=0){
				error+= "El Segundo Precio debe ser un número mayor a 0.\n";
			}else{
				if(precio1==""){
					error+= "Debe ingresar el Primer Precio.\n";
				}else{
					if(parseInt(precio1)>=parseInt(precio2)){
						error+="El Primer Precio debe ser menor al Segundo.\n";
					}	
				}
			}
		}
	}
	if(error!=""){
		alert(error);	
	}else{
		document.location = "propiedades.php?"+url+"&buscar=1&us=1";	
	}

}

function abrirVentana(url,nombre,anchoV,altoV,scrolles) { 
  var ancho=screen.width;
  var alto=screen.height; 
  var pos = (ancho-anchoV)/2;
  if(!scrolles){
	scrolles = "yes";  
  }
	  
	var vtn = window.open(url,nombre,'scrollbars='+scrolles+',width='+anchoV+',height='+altoV+',top=200,left='+pos);
}
document.onLoad = MM_preloadImages('../img/bot-buscar2.gif','../img/mas2.gif');

function activarMenu(id){
	
	var arMenu = document.getElementById('menu_cabezal').getElementsByTagName('div');
	for(i=0;i<arMenu.length;i++){
		var idM = arMenu[i].id;
		if(idM == id){
			activarItem(id)
		}else{
			desactivarItem(idM);
		}
	}
}

function activarItem(id){
	var td1 = document.getElementById('td1_'+id);
	var td2 = document.getElementById('td2_'+id);
	var td3 = document.getElementById('td3_'+id);
	var links = document.getElementById('link_'+id);
	if(td1){
		td1.style.backgroundPosition='0 -22px';
	}
	if(td2){
		td2.style.color = "#ffffff";
		td2.style.backgroundPosition='0 -22px';
	}
	if(td3){
		td3.style.backgroundPosition='0 -22px';
	}
}
function desactivarItem(id){
	var td1 = document.getElementById('td1_'+id);
	var td2 = document.getElementById('td2_'+id);
	var td3 = document.getElementById('td3_'+id);
	var links = document.getElementById('link_'+id);
	if(td1){
		td1.style.backgroundPosition='0 0px';
	}
	if(td2){
		td2.style.color = "#000000";
		td2.style.backgroundPosition='0 0px';
	}
	if(td3){
		td3.style.backgroundPosition='0 0px';
	}
}

function enviarContacto(){
	
	var nombre = document.contacto.Nombre.value;
	var email = document.contacto.Email.value;
	var com = document.contacto.Mensaje.value;
	var error="";
	if(nombre==""){
		error+="Ingrese su Nombre.\n";	
	}
	if(email==""){
		error+="Ingrese su Email.\n";	
	}else{
		var p = email.indexOf("@");
		if(p<1){
			error+= "Su Email debe ser una dirección correcta.\n";
		}
	}
	if(com==""){
		error+="Ingrese el Mensaje.\n";	
	}
	if(error!=""){
		alert(error);
	}else{
		document.contacto.submit();
	}
}

function validaComentarios(){ 
   var permitidos = 250;
   var contenid="";
   num_caracteres = document.contacto.Mensaje.value.length 
   if (num_caracteres > permitidos){ 
      document.contacto.Mensaje.value = contenido; 
   }else{ 
      contenido =  document.contacto.Mensaje.value 
   } 
} 
