// Crear solapas
var myTabs = new YAHOO.widget.TabView("editTabs");
		
function enableList (list, enable)
{	/*
	if (enable) {
		var obj = document.getElementById(list);
		if (obj) {
			obj.removeAttribute('disabled');
		}
	}
	else {
		var obj = document.getElementById(list);
		if (obj) {
			obj.setAttribute('disabled', true);
		}
	}
	*/
	var obj = document.getElementById(list);
	if (obj) 
	{
		//obj.removeAttribute('disabled');
		if (enable) // añadir villas
		{
			var o = document.createElement('option');
			o.innerHTML = villasText;
			o.setAttribute('value', 'villa');
			obj.appendChild(o);
		}
		else {
			var options = obj.getElementsByTagName ('option');
			for (i = 0; i < options.length; i++) {
				if (options[i].value == 'villa'){
					obj.removeChild (options[i]);
				}
			}
		}
		
	}
	// <option value="villa">Villas de lujo/Unifamiliares</option>
}

function mostrar_ficha (id, tipo, idant)
{
	var callback = 
	{ 
    	success:function (o) {
			var obj = document.getElementById('ficha' + tipo);
			if (obj) {
				obj.innerHTML = o.responseText;
				// Actualizar GreyBox
				GB_SETS={};
				decoGreyboxLinks();
				
				//tb_init('a.thickbox, area.thickbox, input.thickbox'); // le digo al thickbox que tenga en cuenta las nuevas imágenes
				
				var obj = document.getElementById('obra' + id);
				if (obj) { obj.className = 'obra sel'; }
				if (tipo == 'fin')
					obraSelFi = id;
				else
					obraSelEj = id;
			}
		},
	    failure:function (o) { 
			var obj = document.getElementById('ficha'+tipo);
			if (obj) {
				obj.innerHTML = '<span style="color: #999">' + o.statusText + '</span>';
			}
		},
		timeout: 20000
	};
	
	mostrarFicha(true, tipo);
	
	var obj = document.getElementById('ficha' + tipo);
	if (obj) {
			obj.innerHTML = '<img src="img/loadingAnimation.gif" alt="Cargando..." />';
	}
	// le quito la clase sel
	if (tipo == 'fin')
		name = 'obra' + obraSelFi;
	else
		name = 'obra' + obraSelEj;
	var obj = document.getElementById(name);
	if (obj) { obj.className = 'obra'; }
	
	YAHOO.util.Connect.asyncRequest('GET', urlFicha + id + '/tipo/' + tipo, callback, null); 
	
	return false;
}


function mostrar_listado (tipo) // tipo es eje o fin
{
	mostrarFicha(false, tipo);
	
	var form = 'form' + tipo;
	var oform = document.getElementById(form);
	var estado = (tipo == 'eje')? 'ejecucion' : 'finalizada';
	var url = urlListado + estado + '/tipo/';
	if (tipo == 'eje')
		url += ((oform.tipoejepub.checked)? 'publica' : 'privada') + '/tipo_vivienda/' + oform.tipopeje.value;
	else
		url += ((oform.tipopub.checked)? 'publica' : 'privada') +'/tipo_vivienda/' + oform.tipopr.value;
		
	var callbackList = 
	{ 
    	success:function (o) {
			var obj = document.getElementById('lista' + tipo);
			if (obj) {
				obj.innerHTML = o.responseText;
			}
		},
	    failure:function (o) { 
			var obj = document.getElementById('lista' + tipo);
			if (obj) {
				obj.innerHTML = '<span style="color: #999">' + o.statusText + '</span>';
			}
		},
		timeout: 20000
	};
	
	var obj = document.getElementById('lista' + tipo);
	if (obj) {
			obj.innerHTML = '<img src="img/loadingAnimation.gif" alt="Cargando..." />';
			var obj = document.getElementById('ficha' + tipo);
			if (obj) {
				obj.innerHTML = '';
			}
	}
	
	YAHOO.util.Connect.asyncRequest('GET', url, callbackList, null); 
	
}


function mostrarFicha(show, tipo)
{
	var ficha = document.getElementById('eFicha' + tipo);
	var listado = document.getElementById('Listado' + tipo);
	if (ficha && listado)
	{
		if (show) {
			ficha.style.display = '';
			listado.style.display = 'none';		
		} else {
			ficha.style.display = 'none';
			listado.style.display = '';		
		}
	}
	
	return false;
}