function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function BuscarAvanzada(display)
{
	if( document.getElementById('busqueda_avanzada').style.display == "none" || display == "none" )
	{
		document.getElementById('tblBusqueda').style.width  						= "500px";
		document.getElementById('tblBusqueda').style.height 						= "300px";
		document.getElementById('tblBusqueda').style.backgroundImage 		= "url(adminpanel/images_new/bkg_search-repeat_no-repeat2.gif)";
		document.getElementById('tblBusqueda').style.backgroundRepeat		= "no-repeat";
		document.getElementById('busqueda_avanzada').style.display			= "block";
	}
	else
	{
		document.getElementById('tblBusqueda').style.width  						= "500px";
		document.getElementById('tblBusqueda').style.height 						= "180px";
		document.getElementById('tblBusqueda').style.backgroundImage 		= "url(adminpanel/images_new/bkg_search-repeat_no-repeat.gif)";
		document.getElementById('tblBusqueda').style.backgroundRepeat		= "no-repeat";
		document.getElementById('busqueda_avanzada').style.display			= "none";
	}			
}

function TouryFoto(obj)
{
	if( obj.name == 'contour' )
	{
		if( obj.checked == true )
		{
			document.getElementById('PropCTour').value 							= 1;
		}
		else
		{
			document.getElementById('PropCTour').value 							= 0;
		}			
	}
	if( obj.name == 'confoto' )
	{
		if( obj.checked == true )
		{
			document.getElementById('PropCFoto').value 							= 1;
		}
		else
		{
			document.getElementById('PropCFoto').value 							= 0;
		}
	}	
}

function AgregarServicio(value)
{
	document.getElementById('Servicios').value  = value;
}

function BuscarPropiedad(accion)
{
	var codProp = document.getElementById('CodPropTourId');
	if( accion == 'buscar_codigo')
	{
		if(codProp.value != '')
		{
			document.getElementById('accion').value = accion;
			document.frmProp.submit();
		} else {
			alert('Debe ingresar un término para buscar por código');
			codProp.focus();
		}
	} 
	else if( accion == '' || accion == 'ver_todas') 
	{
		document.getElementById('accion').value = accion;
		document.frmProp.submit();
	}
	//document.frmProp.submit();
}

function PorPagina(valor)
{
	document.getElementById('porpagina').value = valor;
	BuscarPropiedad();
}

function VerPropiedad(idDpto)
{
	URL = 'editproperty.php?idDpto='+idDpto;
	popup(URL, 'EdicionPropiedad', 573, 780);
}

function popup(URL, name, Height, width)
{
	vars = 'height='+Height+',width='+width;
	newwindow=window.open(URL, name, vars);
	if (window.focus) {newwindow.focus()}
	return false;
}	

function iraPagina(pagina)
{
	window.location.href = pagina;
}

function changeZone(idRegion) 
{
	for(var i=0; i < 7; i++)
	{
		zona1 = "zona1_region"+i;
		zona2 = "zona2_region"+i;
		zona3 = "zona3_region"+i;
		
		if( i != idRegion )
		{
			if(document.getElementById(zona1) != null) { document.getElementById(zona1).style.display 	= 'none'; 	document.getElementById(zona1).disabled = 'disabled';	}
			if(document.getElementById(zona2) != null) { document.getElementById(zona2).style.display 	= 'none';		document.getElementById(zona2).disabled = 'disabled';	} 	
			if(document.getElementById(zona3) != null) { document.getElementById(zona3).style.display 	= 'none';		document.getElementById(zona3).disabled = 'disabled';	} 
		}
	}
	zona1 = 'zona1_region'+idRegion;
	zona2 = 'zona2_region'+idRegion;
	zona3 = 'zona3_region'+idRegion;
	
	if(document.getElementById(zona1) != null) { document.getElementById(zona1).style.display 			= 'block'; document.getElementById(zona1).disabled = false; } else { 	document.getElementById('zona1_region0').style.display = 'block';}
	if(document.getElementById(zona1) != null) { document.getElementById(zona2).style.display 			= 'block'; document.getElementById(zona2).disabled = false; } else { 	document.getElementById('zona2_region0').style.display = 'block';}	
	if(document.getElementById(zona1) != null) { document.getElementById(zona3).style.display 			= 'block'; document.getElementById(zona3).disabled = false; } else { 	document.getElementById('zona3_region0').style.display = 'block';}
}

function checkformcontact(MyFORM)
{
	if(MyFORM.apellido.value==""){
		alert("Por favor ingrese su apellido");
		MyFORM.apellido.focus();
		return false;
	}
	
	if(MyFORM.nombre.value==""){
		alert("Por favor ingrese su nombre");
		MyFORM.nombre.focus();
		return false;
	}
		
	if(MyFORM.telefono.value==""){
		alert("Por favor ingrese un número de teléfono");
		MyFORM.telefono.focus();
		return false;
	}

	if(MyFORM.email.value==""){
		alert("Por favor ingrese una dirección de E-mail");
		MyFORM.email.focus();
		return false;
	}
	else
	{
		if(isEmailAddr(MyFORM.email.value)==false)
		{
			alert("Por favor ingrese una dirección de E-mail válida");
			MyFORM.email.focus();
			return false;
		}		
	}
	
		if(MyFORM.localidad.value==""){
		alert("Por favor seleccione una localidad");
		MyFORM.localidad.focus();
		return false;
	}
	
		if(MyFORM.tipo_propiedad.value==""){
		alert("Por favor seleccione un tipo de propiedad");
		MyFORM.tipo_propiedad.focus();
		return false;
	}
		
		if(MyFORM.pref_contacto.value==""){
		alert("Por favor ingrese una preferencia de Contacto");
		MyFORM.pref_contacto.focus();
		return false;
	}
	MyFORM.submit();
}

function viewSubmenu(menu)
{
	if(document.getElementById(menu).style.display == 'none')
	{
		document.getElementById(menu).style.display 									= 'block';
		if(menu == 'submenuComprar')
		{
			document.getElementById('submenuHerramientas').style.display 	= 'none';
		} 
		else if(menu == 'submenuHerramientas')
		{
			document.getElementById('submenuComprar').style.display 	= 'none';
		}
		else if(menu == 'submenuComprarBuscador')
		{
			document.getElementById('submenuHerramientasBuscador').style.display 	= 'none';
		}		
		else if(menu == 'submenuHerramientasBuscador')
		{
			document.getElementById('submenuComprarBuscador').style.display 	= 'none';
		}
	}
	else
	{
		document.getElementById(menu).style.display = 'none';	
	}		
}