
var asocimageurl = "fotos/";
var mask = null;
//var asocwindow = null;

Ext.onReady( function( ) 
{
	/*var parentdoc = window.parent.document;
	window.parent.asocwindow = new window.parent.Ext.Window({
		width: 715,
		height: 815,
		bodyBorder: false,
		hideBorder: true,
		border: false,
		draggable: false,
		closable: false,
		initHidden: true,
		modal: true,
		resizable: false,
		plain: true,
		y: 10,
		animateTarget: true,
		contentEl: parentdoc.getElementById( 'extcontainer' )
	});*/
});

function muestraAsociado( asocid )
{
	Ext.Ajax.request( { 
		url: "lib/JSON_Interface.php?class=asociado&id="+asocid, 
		callback: function( options, success, response )
		{
			if ( success )
			{
				try
				{
					var parentdoc = window.parent.document;
					var data = Ext.util.JSON.decode( response.responseText );
					Ext.fly( parentdoc.getElementById( 'asoctext' ) ).insertHtml( 'afterbegin', data.descripcion );
					
					if ( data.logo != null )
					{
						displayImage( 'asoclogo', asocimageurl + data.logo );					
					}
					if ( data.imgs != null )
					{
						var len = ( data.imgs.length > 4 ) ? 4 : data.imgs.length;
						for ( var i = 0; i < len; i++ )
						{
							displayImage( 'asocimage' + ( i + 1 ), asocimageurl + data.imgs[ i ] );
						}
					}
					
					Ext.fly( parentdoc.getElementById( 'asocdenominacion' ) ).insertHtml( 'afterbegin', data.denominacion );
					
					var direccion = data.direccion + "<br/>" + data.cp + " " + data.localidad + " (" + data.provincia + ")<br/>";
					direccion = direccion + "Tel: " + data.telefono + "<br/>Fax: " + data.fax;
					
					Ext.fly( parentdoc.getElementById( 'asocdireccion' ) ).insertHtml( 'afterbegin', direccion );
					
					var email = "Email: <a href='mailto:" + data.email + "'>" + data.email + "</a>";
					if ( data.web )
					{
						email = email + "<br/>Web: <a href='" + data.web + "'>" + data.web + "</a>";
					}
					Ext.fly( parentdoc.getElementById( 'asocemail' ) ).insertHtml( 'afterbegin', email );
					
					var extcontainer = Ext.fly( parentdoc.getElementById( 'extcontainer' ) ); 
					extcontainer.removeClass( 'hidden' );
					window.parent.mask = extcontainer.createChild({cls:'ext-el-mask'}, extcontainer.dom);
					window.parent.mask.enableDisplayMode('block');
					window.parent.mask.setSize( window.parent.Ext.lib.Dom.getViewWidth(true), window.parent.Ext.lib.Dom.getViewHeight(true) );
				}
				catch ( e )
				{
					Ext.Msg.alert( EditorMsg.errorTitle, EditorMsg.errAsocContent + ": " + e.message + " (" + e.name + ")" );
				}
			}
			else
			{
				Ext.Msg.alert( EditorMsg.errorTitle, EditorMsg.errLoadAsoc );
			}
		}, 
		scope: this,
		disableCaching: true 
	} );
}

function displayImage( divid, imgsrc )
{
	var imgtag = "<img src='" + imgsrc + "' alt=''/>";
	Ext.fly( window.parent.document.getElementById( divid ) ).insertHtml( 'afterbegin', imgtag );
}

function ocultaAsociado( )
{
	//window.parent.asocwindow.hide( );
	var parentdoc = ( window.parent != null ) ? window.parent.document : null;
	parentdoc.getElementById( 'extcontainer' ).className = 'hidden';
	Ext.fly( window.parent.mask ).remove( ); 
	clearChilds( parentdoc, 'asoclogo' );
	clearChilds( parentdoc, 'asocimage1' );
	clearChilds( parentdoc, 'asocimage2' );
	clearChilds( parentdoc, 'asocimage3' );
	clearChilds( parentdoc, 'asocimage4' );
	clearChilds( parentdoc, 'asoctext' );
	clearChilds( parentdoc, 'asocdenominacion' );
	clearChilds( parentdoc, 'asocdireccion' );
	clearChilds( parentdoc, 'asocemail' );
}

function clearChilds( doc, domid )
{
	var domEl = doc.getElementById( domid );
	if ( domEl != null )
	{
		var nchilds = domEl.childNodes.length;
		for ( var i = 0; i < nchilds; i++ ) domEl.removeChild( domEl.childNodes[ 0 ] ); 
	}
	else
	{
		alert( domid + " es nulo!" );
	}
}