/*
 * This JavaScrip uses Ext JS Library 2.2.1, Copyright(c) 2006-2009, Ext JS, LLC., licensing@extjs.com, http://extjs.com/license
 */

/** globaly visible */
var currentlySelectedTabTitle = "";

function adjustDataIndex()
{
	var dataIndex33 = Ext.get('dataIndex33');
	//dataIndex33.applyStyles("background-color: #007000;");
	if(isIe7())
	{
		dataIndex33.applyStyles("margin-left:-27px;");
		dataIndex33.applyStyles("margin-top:20px;");
	}
	if(isIe8())
	{
		dataIndex33.applyStyles("margin-top:20px;");
	}
}

function isIe7()
{
	if(navigator.appVersion.indexOf("MSIE 7.0")!=-1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function isIe8()
{
	if(navigator.appVersion.indexOf("MSIE 8.0")!=-1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

Ext.onReady
(
	function()
	{
		//  so our extjs windows can be over the Java Applet
		Ext.useShims = true;
		var browser = navigator.appName;
					
		var p;
		var V = new Ext.ux.plugin.VisibilityMode({bubble:false});
		var firstOptionSelectedStr = "";
		if(kvpIne==null)
		{
			firstOptionSelectedStr = "selected";
		}
		var html = "<option value='-1' "+firstOptionSelectedStr+">  Todos los municipios</option><!--<option value='-2'>Callejero</option>--><option value='41001'>Aguadulce</option><option value='41002'>Alan&iacute;s</option><option  value='41003'>Albaida del Aljarafe</option><option value='41005'>Alcal&aacute; del R&iacute;o</option><option value='41006'>Alcolea del R&iacute;o</option><option value='41008'>Alg&aacute;mitas</option><option value='41009'>Almad&eacute;n de la Plata</option><option value='41010'>Almensilla</option><option value='41011'>Arahal</option><option value='41012'>Aznalc&aacute;zar</option><option value='41013'>Aznalcollar</option><option value='41014'>Badolatosa</option><option value='41015'>Benacaz&oacute;n</option><option value='41016'>Bollullos de la Mitaci&oacute;n</option><option value='41017'>Bormujos</option><option value='41018'>Brenes</option><option value='41019'>Burguillos</option><option value='41021'>Camas</option><option value='41901'>Ca&ntilde;ada Rosal</option><option value='41023'>Cantillana</option><option value='41024'>Carmona</option><option value='41025'>Carri&oacute;n de los C&eacute;spedes</option><option value='41026'>Casariche</option><option value='41027'>Castilblanco de los Arroyos</option><option value='41028'>Castilleja de Guzm&aacute;n</option><option value='41029'>Castilleja de la Cuesta</option><option value='41030'>Castilleja del Campo</option><option value='41032'>Cazalla de la Sierra</option><option value='41033'>Constantina</option><option value='41034'>Coria del R&iacute;o</option><option value='41035'>Coripe</option><option value='41039'>&Eacute;cija</option><option value='41031'>El Castillo de las Guardas</option><option value='41036'>El Coronil</option><option value='41903'>El Cuervo de Sevilla</option><option value='41043'>El Garrobo</option><option value='41057'>El Madro&ntilde;o</option><option value='41073'>El Pedroso</option><option value='41080'>El Real de la Jara</option><option value='41083'>El Ronquillo</option><option value='41084'>El Rubio</option><option value='41090'>El Saucejo</option><option value='41102'>El Viso del Alcor</option><option value='41040'>Espartinas</option><option value='41041'>Estepa</option><option value='41042'>Fuentes de Andaluc&iacute;a</option><option value='41044'>Gelves</option><option value='41045'>Gerena</option><option value='41046'>Gilena</option><option value='41047'>Gines</option><option value='41048'>Guadalcanal</option><option value='41049'>Guillena</option><option value='41050'>Herrera</option><option value='41051'>Hu&eacute;var del Aljarafe</option><option value='41902'>Isla Mayor</option><option value='41007'>La Algaba</option><option value='41022'>La Campana</option><option value='41052'>Lantejuela</option><option value='41056'>La Luisiana</option><option value='41077'>La Puebla de Cazalla</option><option value='41078'>La Puebla de los Infantes</option><option value='41079'>La Puebla del R&iacute;o</option><option value='41081'>La Rinconada</option><option value='41082'>La Roda de Andaluc&iacute;a</option><option value='41020'>Las Cabezas de San Juan</option><option value='41066'>Las Navas de la Concepci&oacute;n</option><option value='41053'>Lebrija</option><option value='41054'>Lora de Estepa</option><option value='41055'>Lora del R&iacute;o</option><option value='41037'>Los Corrales</option><option value='41063'>Los Molares</option><option value='41069'>Los Palacios y Villafranca</option><option value='41058'>Mairena del Alcor</option><option value='41059'>Mairena del Aljarafe</option><option value='41060'>Marchena</option><option value='41061'>Marinaleda</option><option value='41062'>Mart&iacute;n de la Jara</option><option value='41064'>Montellano</option><option value='41065'>Mor&oacute;n de la Frontera</option><option value='41067'>Olivares</option><option value='41068'>Osuna</option><option value='41070'>Palomares del R&iacute;o</option><option value='41071'>Paradas</option><option value='41072'>Pedrera</option><option value='41074'>Pe&ntilde;aflor</option><option value='41075'>Pilas</option><option value='41076'>Pruna</option><option value='41085'>Salteras</option><option value='41086'>San Juan de Aznalfarache</option><option value='41087'>Sanl&uacute;car la Mayor</option><option value='41088'>San Nicol&aacute;s del Puerto</option><option value='41089'>Santiponce</option><option value='41092'>Tocina</option><option value='41093'>Tomares</option><option value='41094'>Umbrete</option><option value='41095'>Utrera</option><option value='41096'>Valencina de la Concepci&oacute;n</option><option value='41097'>Villamanrique de la Condesa</option><option value='41098'>Villanueva del Ariscal</option><option value='41099'>Villanueva del R&iacute;o y Minas</option><option value='41100'>Villanueva de San Juan</option><option value='41101'>Villaverde del R&iacute;o</option>";

		if(kvpIne!=null)
		{
			// seleccionar el municipio en los 2 search filter
			kvpIneStr = ""+kvpIne;
			ineNdx = html.indexOf(kvpIneStr);
			if(ineNdx>0)
			{
				ineNdx += 6;
				leftHtml = html.substring(0,ineNdx);
				rightHtml = html.substring(ineNdx);
				html = leftHtml+" selected "+rightHtml;
			}
		}

		

		var search_html_map_tab =
			"	<div class='tabTopBandElements' id='tabTopBandElements' style='display:inline-block;'>"+//<font class='comboBoxLetter'>Buscar: </font>"+
			"		<div id='selectionSearch'> "+
			"			<input  name='searchText' class='comboBoxLetter'  type='text' size='25' style='width:160px;' tabindex=1 id='searchText' onclick='/*fullScreenMap();*/select_all()' onkeypress='validateKeyPressed(event);' value='Buscar...' >"+
			//"		<font class='comboBoxLetter'>&nbsp;&nbsp;Filtro de B&uacute;squeda:</font>"+
			"			<span class='comboBoxLetter'>en</span>"+
			"			<select class='comboBoxLetter' name='searchFilter' tabindex=1 id='searchFilter' style='width:160px;'>"+
							html+
			"			</select>&nbsp;&nbsp;"+								
			" 		</div>"+
			"		<div id='buttonSearch'>"+
			"			<input type='image' src='img/b-buscar_on.png' id='show-btn' value='Buscar'  tabindex=2 onclick=\"checkTextToFilter(document.getElementById('searchText').value,document.getElementById('searchFilter').value);\"/>"+
			"		</div>"+
			"	</div>";

		var search_html_data_tab =
			"	<div class='tabTopBandElements' id='tabTopBandElements'>"+//<font class='comboBoxLetter'>Buscar: </font>"+
			"		<div id='selectionSearch'> "+
			"			<input  name='searchText2' class='comboBoxLetter'  type='text' size='25' style='width:160px;' tabindex=1 id='searchText2' onclick='select_all2()' onkeypress='validateKeyPressed2(event);' value='Buscar...' >"+
			"			<span class='comboBoxLetter'>en</span>"+
			"			<select class='comboBoxLetter' name='searchFilter2' tabindex=1 id='searchFilter2'  style='width:160px;'>"+
							html+
			"			</select>&nbsp;&nbsp;"+								
			" 		</div>"+
			"		<div id='buttonSearch'>"+
			"			<input type='image' src='img/b-buscar_on.png' id='show-btn' value='Buscar' tabindex=2 onclick=\"checkTextToFilter2(document.getElementById('searchText2').value,document.getElementById('searchFilter2').value);\"/>"+
			"		</div>"+
			"	</div>";

		var search_html_photo_tab =
			"	<div class='tabTopBandElements'id='tabTopBandElements'>"+//<font class='comboBoxLetter'>Buscar: </font>"+
			"		<div id='selectionSearch'> "+
			"			<input  name='searchText3' class='comboBoxLetter'  type='text' size='25' style='width:160px;' tabindex=1 id='searchText3' onclick='/*fullScreenMap();*/select_all3()' onkeypress='validateKeyPressed3(event);' value='Buscar...' >"+
			//"		<font class='comboBoxLetter'>&nbsp;&nbsp;Filtro de B&uacute;squeda:</font>"+
			"			<span class='comboBoxLetter'>en</span>"+
			"			<select class='comboBoxLetter' name='searchFilter3'  tabindex=1 id='searchFilter3' style='width:160px;'>"+
							html+
			"			</select>&nbsp;&nbsp;"+								
			" 		</div>"+
			"		<div id='buttonSearch'>"+
			"			<input type='image' src='img/b-buscar_on.png' id='show-btn' value='Buscar'  tabindex=2 onclick=\"checkTextToFilter3(document.getElementById('searchText3').value,document.getElementById('searchFilter3').value);\"/>"+
			"		</div>"+
			"	</div>";

	   /****************************************************************************************************************
		*	This is the Tab Panel definition				     																					 
		****************************************************************************************************************/
		
		if(browser!= "Microsoft Internet Explorer")
		{	
			// not ie
			tabs2 = new Ext.TabPanel
			(
				{
					renderTo: 'mainTabsDiv',
					activeTab: 2,
					deferredRender: false,
					layoutOnTabChange:true,
					width:'100%',
					height: currentTabHeight,
					autoTabs: true,
					plain:true,
					resizeTabs:true,
					tabWidth:75,

				  	defaults:
					{
						hideMode:!Ext.isIE?'visibility':'nosize',
						style:{position:!Ext.isIE?'absolute':'absolute'}
					},

					listeners: {tabchange:handleTabChange,beforetabchange:handleBeforeTabActivation},
				  	items:
					[
						{
							// this is the pics tab						
							title: 'Fotos',
							html:
								"	<div class='fotosTabTopBand' id='fotosTabTopBand'>"+
								search_html_photo_tab+
								"	<div id='fotosTabTopBandSpecific' style='margin-left:auto;'>vacia</div>"+
								"	</div>"+
								"	<div class='fotosTabContent' id='fotosTabContent' align='center'>"+
								"		<div id='show' class='slideshow' style='position:absolute: width:100;height:150'>"+
								"		</div>"+
								"	</div>",
							id:'fotos'
						},
						{
							// this is the data tab						
							title: 'Datos',
							html:
								"<div class='datosTabTopBand'>"+
								search_html_data_tab+
								//------------
								"	<div class='searchButtonDiv'>"+
								"		<img id='searchImgButtonDatos' src='img/b-enviar-incidencia_on.png' onmouseover=\"changeButton('searchImgButtonDatos','img/b-enviar-incidencia_hover.png');\" onmouseout=\"changeButton('searchImgButtonDatos','img/b-enviar-incidencia_on.png');\" onclick=\"showIssueVGI('Incidencia no contextualizada',-1)\">"+
								"	</div>"+
								//------------								
								"</div>"+
								"<div class='datosTabContent' id='datosTabContent' style='height:"+(altura+1)+"px;'>"+
								"</div>",
							id:'datos'
				      },
							
						{
							// this is the map tab						
							title: 'Mapas',
							html:
								"<div class='mapasTabTopBand'>"+
								search_html_map_tab+
								// search facilities ------------ 
								//------------
								"	<div class='searchButtonDiv' style='display:inline-block;float:right;'>"+
								"		<img id='searchImgButtonMapas' src='img/b-enviar-incidencia_on.png' onmouseover=\"changeButton('searchImgButtonMapas','img/b-enviar-incidencia_hover.png');\" onmouseout=\"changeButton('searchImgButtonMapas','img/b-enviar-incidencia_on.png');\" onclick=\"showIssueVGI('Incidencia no contextualizada',-1)\">"+
								"	</div>"+							
								"</div>"+
								"<div class='mapasTabContent' id='mapasTabContent' align='center' >"+
								"		<div id='map_wrapper' style='width: "+ (anchura + 2) +"px; height:"+ (altura+1) +"px; ' >"+
								"			<div id='map_tool_bar'>" +
								"				<div class='co_ini_viewport'>"+
								"					<a href='javascript:MiradorMashup.initial_viewport()'>" +
								"						<img src='img/MIR_bot_vista_inicial.png' />"+
								"					</a>"+
								"				</div>"+
								//"				<div style='float:left' id='zoom_not'></div>" +
								"				<div class='co_button'>"+
								"					<div class='button_group' id='co_but_map'></div>" +
								"					<div class='button_group' id='but_sat'></div>" +
								"					<div class='button_group_separator'></div>" +
								"					<div class='button_group'>"+
								"						<div class='label_buttom'>Capas</div>"+
								"						<img class='jsLink' onclick='MiradorMashup.toogleTreeInterface()' src='img/MIR_bot_capas.png' /></div>" +
								"					<div id='layer_tree' style='display:none;height:"+ (altura+1-40) +"px;'></div>" +
								"				</div>"+
								"			</div>" +
								"			<div id='map_canvas' style='width: "+ (anchura + 2) +"px; height:"+ (altura+1-40) +"px; '></div>"+
								"		</div>" +
								"</div>",
							id:'mapas'
				      }
					]
				}
			);
		}
		else
		{	
			// ie
			if(navigator.appVersion.indexOf("MSIE 8.0")==-1 && navigator.appVersion.indexOf("MSIE 9.0")==-1)
			{
				// it's not explorer 8
				notExplorer8 = true;
			}
			tabs2 = new Ext.TabPanel
			(
				{
					renderTo: 'mainTabsDiv',
					activeTab: 0,// doesn't matter
					deferredRender: false,
					layoutOnTabChange:true,
					width:'100%',
					height: currentTabHeight ,
					autoTabs: true,
					plain:true,
					resizeTabs:true,
					tabWidth:75,
			
					defaults:
					{
						plugins:V,
						style:{position:!Ext.isIE?'absolute':'absolute'},
						//hideMode:'nosize',
						hideMode: isIe7() ? 'visibility' : 'nosize',
						closable:false
					},

					listeners: {tabchange:handleTabChange,beforetabchange:handleBeforeTabActivation},
				items:
					[
						{
							// this is the pics tab						
							title: 'Fotos',
							html:
								"	<div class='fotosTabTopBand' id='fotosTabTopBand'>"+
								search_html_photo_tab+
								"	<div id='fotosTabTopBandSpecific' style='margin-left:auto;'>vacia</div>"+
								"	</div>"+
								"	<div class='fotosTabContent' id='fotosTabContent' align='center'>"+
								"		esta es la otra zona" +
								"		<div id='show' class='slideshow' style='position:absolute: width:100;height:150'>"+
								"		</div>"+
								"	</div>",
							id:'fotos'
						},
						{
							// this is the data tab						
							title: 'Datos',
							html:
								"<div class='datosTabTopBand'>"+
								search_html_data_tab+
								//------------
								"<div class='searchButtonDiv'>"+
								"	<img id='searchImgButtonDatos' src='img/b-enviar-incidencia_on.png' onmouseover=\"changeButton('searchImgButtonDatos','img/b-enviar-incidencia_hover.png');\" onmouseout=\"changeButton('searchImgButtonDatos','img/b-enviar-incidencia_on.png');\" onclick=\"showIssueVGI('Incidencia no contextualizada',-1)\">"+
								"</div>"+
								//------------								
								"</div>"+
								"<div class='datosTabContent' id='datosTabContent' style='height:"+(altura+1)+"px;'>"+
								"</div>"
								,
							id:'datos'
				      },
							
					{
							// this is the map tab
							title: 'Mapas',
							html:
								"<div class='mapasTabTopBand'>"+
								search_html_map_tab+
								// search facilities ------------
								//------------
								"	<div class='searchButtonDiv' style='display:inline-block;float:right;'>"+
								"		<img id='searchImgButtonMapas' src='img/b-enviar-incidencia_on.png' onmouseover=\"changeButton('searchImgButtonMapas','img/b-enviar-incidencia_hover.png');\" onmouseout=\"changeButton('searchImgButtonMapas','img/b-enviar-incidencia_on.png');\" onclick=\"showIssueVGI('Incidencia no contextualizada',-1)\">"+
								"	</div>"+
								"</div>"+
								"<div class='mapasTabContent' id='mapasTabContent' align='center' >"+
								"		<div id='map_wrapper' style='width: "+ (anchura + 2) +"px; height:"+ (altura+1) +"px; ' >"+
								"			<div id='map_tool_bar' align='right'>" +
								"				<div class='co_ini_viewport'>"+
								"					<a href='javascript:MiradorMashup.initial_viewport()'>" +
								"						<img src='img/MIR_bot_vista_inicial.png' />"+
								"					</a>"+
								"				</div>"+
								"				<div class='co_button'>"+
								"					<div class='button_group' id='co_but_map'></div>" +
								"					<div class='button_group' id='but_sat'></div>" +
								"					<div class='button_group_separator'></div>" +
								"					<div class='button_group'>"+
								"						<div class='label_buttom'>Capas</div>"+
								"						<img class='jsLink' onclick='MiradorMashup.toogleTreeInterface()' src='img/MIR_bot_capas.png' /></div>" +
								"					<div id='layer_tree' style='display:none;height:"+ (altura+1-40) +"px;'></div>" +
								"				</div>"+
								"			</div>" +
								"			<div id='map_canvas' style='width: "+ (anchura + 2) +"px; height:"+ (altura+1-40) +"px; '></div>"+
								"		</div>" +
								"</div>",
							id:'mapas'
				      }
					]
				}
			);
		}

		var ini_lat = 37.4538;
		var ini_lng = -5.6815;
		var ini_zoom = 9;
		var ini_sw_lat = 36.8017;
		var ini_sw_lng = -6.8147;
		var ini_ne_lat = 38.1424;
		var ini_ne_lng = -4.4577;

		if (centerBox)
		{
			ini_lat = centerBox.y;
			ini_lng = centerBox.x;
			ini_sw_lat = centerBox.y0;
			ini_sw_lng = centerBox.x0;
			ini_ne_lat = centerBox.y1;
			ini_ne_lng = centerBox.x1;
			ini_zoom = 14;
		}

		//initialize map
		MiradorMashup.init({
			/*Bounding box*/
			ini_sw_lat: ini_sw_lat,
			ini_sw_lng: ini_sw_lng,
			ini_ne_lat : ini_ne_lat,
			ini_ne_lng : ini_ne_lng,
			ini_lat: ini_lat,
			ini_lng: ini_lng,
			ini_zoom: ini_zoom,
			canvas : "map_canvas",
			userClick : true
		});


		jQuery('img.hover_image').imghover();
		/****************************************************************************************************************************************
		*	This is an Ajax called to a php content for the pics initial state ( php/getListTown) and the town combo box
		*****************************************************************************************************************************************/
			
		// we use this Ext object that allows us to get an Ajax connection 	
		var connection = new Ext.data.Connection();		
		
		// the page should be 1 at first
		var page = 1;

		// the url where the php file is
		var fullUrl = 'php/getTownList_shadowbox.php?pag='+page;

		var width = screenWidthGlobal;
		var height = screenHeightGlobal;		

		connection.request 
		(
			{
				url: fullUrl,
				method: 'POST',
 				params: {'pag': page, 'width': width, 'height': height},
 					
				success:
					function (responseObject) 
					{
		  				showFirstStatePics (responseObject.responseText);
	 				},

  				failure:
					function () 
					{
						Ext.Msg.alert ('estado','Incapaz de listar los municipios. Intente por favor otra vez.');
	  				}
			}
		);

		// the handle function for the ext ajax connection request 
		function showFirstStatePics(t)
		{
			var connection2 = new Ext.data.Connection();
			var urlComboBox = 'php/getTownComboBox_shadowbox.php?isIe7='+(isIe7() ? '1' : '0');

			Ext.get('fotosTabContent').update("");
			Ext.get('fotosTabContent').update(t.toString());
			connection2.request
			(
				{
					url: urlComboBox,
					method: 'POST',
    					
    				success:
						function (responseObject) 
						{
		     				showTownComboBox (responseObject.responseText);
		 				},
     				failure:
						function () 
						{
		      			Ext.Msg.alert ('estado', 'Incapaz de listar los municipios. Intente por favor otra vez.');
		  				}
				}
			);			
		}

		function showTownComboBox(t)
		{
			Ext.get('fotosTabTopBandSpecific').update(t.toString());
		}

		/****************************************************************************************************************************************
		*****************************************************************************************************************************************/

		/****************************************************************************************************************************************
		*	This is an embed ajax called to a html file for the data initial state ( html/dataIndex.html) and the town combo box (next 2do)	*
		*****************************************************************************************************************************************/
		
		this.firstTimeChangeToDataTabPanel=true;
		
		/****************************************************************************************************************************************
		*****************************************************************************************************************************************/		

		/****************************************************************************************************************************************
		*	These are the Handle functions 				     																													 *
		*****************************************************************************************************************************************/

		// this is the photo slide show
		var myShow = null;

		// this is the data tree
		var treeDatos = null;		

		// main tabs change
		function handleTabChange(tabpanel,newTab)
		{
			currentlySelectedTabTitle = newTab.title;
			var url_ = 'html/dataIndex.php';
			var connection = new Ext.data.Connection();
	
			if(newTab.title=="Mapas")
			{
				Ext.useShims = true;
				if(vgiFlag)
				{				
					win.hide();
					win.show();
				}
				if(vgiFlagIssue)
				{				
					winIssue.hide();
					winIssue.show();
				}
				if(vgiFlagSearch)
				{				
					winSearch.hide();
					winSearch.show();
				}
				if(notExplorer8)
				{
					var el = Ext.get('mapasTabContent');
					el.applyStyles("width: "+(anchura+2)+"px");
					el.applyStyles("height: "+(altura+2)+ "px;");
					var  widthIE7 = (Ext.get('mainTabsDiv').getComputedWidth()-anchura-2)/2;
					el.applyStyles("margin-left: "+widthIE7+"px;");		
					// if dont check this many times exceptions are launched
					if(currentTabHeight!= mapasTabHeight)
					{
						currentTabHeight = mapasTabHeight;
						tabs2.setHeight(currentTabHeight);
					}
				}
				if(isIe7())
				{
					var el = Ext.get('mapasTabContent');
					el.applyStyles('display:inline;');
				}
			}
			if(newTab.title=="Fotos")
			{
				if(((kvpSuinfo!=null && kvpSuinfo=="true") || kvpIne!=null) && photoTabHasShownConcreteTown<=2)
				{
					photoTabHasShownConcreteTown++;
					if(isIe7())
					{
						var el = Ext.get('mapasTabContent');
						el.applyStyles('width:0px;height:0px;display:none;');
//						el.applyStyles('height:0px;');
					}
					if(photoTabHasShownConcreteTown==2 || !Ext.isIE /*|| isIe7()*/)
					{
						// suinfo mode goes directly to a municipio
						photoTabHasShownConcreteTown = 23;
						showFirstStatePics("");
						combobox = document.getElementById('searchFilter');
						nombreMunicipio = combobox.options[combobox.selectedIndex].text;
//alert("mostrando foto tab");
						goToTheTownPicsShow_shadowbox(kvpIne,nombreMunicipio);
					}
				}
				if(isIe7() || !Ext.isIE)
				{
					// this shouldn't be necesary, but extjs doesn't behave well
					var el = Ext.get('fotosTabContent');
					el.applyStyles('visibility:visible;');
					el.applyStyles('display:inline;');
					el.applyStyles("height: "+(altura+2)+"px;");
				}
				else
				if(notExplorer8)
				{
					var el = Ext.get('fotosTabContent');
					el.applyStyles("width: "+(anchura+2)+"px");	
					el.applyStyles("height: 400 px;");
					var widthIE7 = (Ext.get('mainTabsDiv').getComputedWidth()-anchura)/2;
					el.applyStyles("margin-left: "+widthIE7+"px;");
					el.applyStyles("height: "+(altura+2)+"px;");
					currentTabHeight = fotosTabHeight;
					tabs2.setHeight(currentTabHeight);
				}
			}
			else
			if(newTab.title=="Datos")
			{	
				if(!Ext.isIE)
				{
					// this shouldn't be necesary, but extjs doesn't behave well
					var el = Ext.get('datosTabContent');
					el.applyStyles('visibility:visible;');
					el.applyStyles('display:inline;');
					el.applyStyles("height: "+(altura+2)+"px;");
				}
				else
				if (notExplorer8)
				{
					var el = Ext.get('datosTabContent');
					el.applyStyles("width: "+ (anchura + 2) +"px");
					el.applyStyles("height: " + (altura + 2)+ "px;");
					var  widthIE7 = (Ext.get('mainTabsDiv').getComputedWidth() -anchura -2 )/ 2;
					el.applyStyles("margin-left: "+widthIE7+"px;");			
					currentTabHeight = datosTabHeight;
					tabs2.setHeight(currentTabHeight);
				}
				
				if(firstTimeChangeToDataTabPanel)
				{
					firstTimeChangeToDataTabPanel=false;
	
					if(((kvpSuinfo!=null && kvpSuinfo=='true') || kvpIne!=null))
					{
						// customize mirador for suinfo
						goToADataTown(kvpIne);
					}
					else
					{
						var connection = new Ext.data.Connection();		
						connection.request
						(	
							{
								url: url_,
								method: 'POST',
			 					success: function (responseObject) 
								{
				  					showGoToTheDataIndex(responseObject.responseText);
			 					},
			  					failure: function () 
								{
			 						Ext.Msg.alert('estado','Incapaz de listar los municipios. Intente por favor otra vez.');
			  					}
							}
						);					
						setCurrentScroll();
					}
				}
			}
			return true;
		}

		// main tabs change
		function handleBeforeTabActivation(tabpanel, newTab, oldTab)
		{
			if (oldTab!=null && newTab!=null && newTab.title==oldTab.title)
			{
				// click over the same tab 
				return true;
			}
			
			if(oldTab!=null)
			{
				// sync search controls over all tabs
				if(oldTab.title=="Mapas")
				{
					var searchText = document.getElementById('searchText').value;
					document.getElementById('searchText2').value = searchText;
					document.getElementById('searchText3').value = searchText;
					var searchFilter = document.getElementById('searchFilter').value;
					document.getElementById('searchFilter2').value = searchFilter;
					document.getElementById('searchFilter3').value = searchFilter;
				}
				else
				if(oldTab.title=="Datos")
				{
					var searchText = document.getElementById('searchText2').value;
					document.getElementById('searchText').value = searchText;
					document.getElementById('searchText3').value = searchText;
					var searchFilter = document.getElementById('searchFilter2').value;
					document.getElementById('searchFilter').value = searchFilter;
					document.getElementById('searchFilter3').value = searchFilter;
				}
				else
				if(oldTab.title=="Fotos")
				{
					var searchText = document.getElementById('searchText3').value;
					document.getElementById('searchText2').value = searchText;
					document.getElementById('searchText').value = searchText;
					var searchFilter = document.getElementById('searchFilter3').value;
					document.getElementById('searchFilter2').value = searchFilter;
					document.getElementById('searchFilter').value = searchFilter;
				}

				if(oldTab.title=="Fotos" && !Ext.isIE)
				{
					// this shouldn't be necesary, but extjs doesn't behave well
					var el = Ext.get('fotosTabContent');
					el.applyStyles('visibility:hidden;');
					el.applyStyles('display:none;');
				}
				else
				if(oldTab.title=="Fotos" && notExplorer8)
				{
					var el = Ext.get('fotosTabContent');
					el.applyStyles('width:0;');
					el.applyStyles('height:0;');
					
				}
				else
				if(oldTab.title=="Datos" && !Ext.isIE)
				{
					// save the current scroll position
					var panelScroll =  document.getElementById('panelIdOverflow2');
					if (panelScroll != null)
					{

						currentScrollTop = panelScroll.scrollTop;
						currentScrollLeft = panelScroll.scrollLeft;	
					}
					// town index scroll
					var panelScrollId =  document.getElementById('panelId');
					if (panelScrollId != null)
					{
						currentScrollIndexTownTop = panelScrollId.scrollTop;
						currentScrollIndexTownLeft = panelScrollId.scrollLeft;	
					}
					// this shouldn't be necesary, but extjs doesn't behave well
					var el = Ext.get('datosTabContent');
					el.applyStyles('visibility:hidden;');
					el.applyStyles('display:none;');
				}
				else
				if(oldTab.title=="Datos" && notExplorer8)
				{
					// save the current scroll position
					var panelScroll =  document.getElementById('panelIdOverflow2');
					if (panelScroll != null)
					{
						currentScrollTop = panelScroll.scrollTop;
						currentScrollLeft = panelScroll.scrollLeft;
					}	
					// town index scroll
					var panelScrollId =  document.getElementById('panelId');
					if (panelScrollId != null)
					{
						currentScrollIndexTownTop = panelScrollId.scrollTop;
						currentScrollIndexTownLeft = panelScrollId.scrollLeft;	
					}
					// this shouldn't be necesary, but extjs doesn't behave well
					var el = Ext.get('datosTabContent');
					el.applyStyles('width:0;');
					el.applyStyles('height:0;');
				}
				else
				if (oldTab.title=="Mapas" && notExplorer8)
				{				
					var el = Ext.get('mapasTabContent');
					el.applyStyles('width:0;');
					el.applyStyles('height:0;');
				}					
			}
			if (newTab != null && !notExplorer8)
			{
				if (newTab.title == "Mapas")
				{
					// if dont check this many times exceptions are launched
					if (currentTabHeight != mapasTabHeight)
					{
						currentTabHeight = mapasTabHeight;
						tabs2.setHeight(currentTabHeight);
					}
				}
				if (newTab.title == "Datos")
				{
					// if dont check this many times exceptions are launched
					if (currentTabHeight != datosTabHeight)
					{
						currentTabHeight = datosTabHeight;
						tabs2.setHeight(currentTabHeight);
					}
				}
				if (newTab.title == "Fotos")
				{
					// if dont check this many times exceptions are launched
					if(currentTabHeight!=fotosTabHeight)
					{
						currentTabHeight = fotosTabHeight;
						if(tabs2!=null)
						{
							tabs2.setHeight(currentTabHeight);
						}
					}
				}
			}			
			return true;
		}

		function show(t)
		{
			Ext.get('datosTabContent').update("");
			Ext.get('datosTabContent').update(t.toString());
		}

		function showGoToTheDataIndex(t)
		{
			Ext.get('datosTabContent').update("");
			Ext.get('datosTabContent').update("<div id='panelId' style='overflow:auto; width:100%; height:"+ altura +"px; background:#FFFFFF;'></div>");
			Ext.get('panelId').update(t.toString());
			adjustDataIndex();
		}		

		if(kvpShowTab!=null || (kvpSuinfo!=null && kvpSuinfo=='true'))
		{
			tabNdx = 2;
			if(kvpSuinfo!=null && kvpSuinfo=='true')
			{
				tabNdx = 1;
			}
			if(kvpShowTab=="mapas")
			{
				tabNdx = 2;
			}
			else
			if(kvpShowTab=="datos")
			{
				tabNdx = 1;
			}
			else
			if(kvpShowTab=="fotos")
			{
				tabNdx = 0;
			}
			tabs2.setActiveTab(tabNdx);
		}
		else
		{
			tabs2.setActiveTab(2);
		}
	}
);





