// JavaScript Document


/***************************************************************************
 * Printer
 * Procedimiento que muestra una página de impresion previa del mapa
 ****************************************************************************/
function Printer(){
	
	// Asigno a la bandera 0 para que deje de dibujar la linea continuamente y pueda volver a realizar ruler
	document.op_map.OneLine.value = 0;
		
	var url = 'PrintPreview.php?width='+width+'&height='+height;	
	window.open(url,'Imprimir','resizable=1,left=20,top=20,width='+width+',height='+height+',toolbar=0, scrollbars=1');

}



//***************************************************
//	MUESTRA LA LEYENDA
function GoToHelp()
{
	var url = "Help/Ayuda.htm";
	var PopUp = window.open(url,'Leyenda','resizable=1,left=120,top=90,width=960,height=650,toolbar=0, scrollbars=1, status=yes ');
	PopUp.focus();
}




function GoToSendFriend()
{
	var url = "MailFriend/MailFriend.php";
	
	var PopUp = window.open(url,'Amigo','left=120,top=70,width=540,height=500,toolbar=0, scrollbars=1, status=yes, resizable=yes ');
	
	PopUp.focus();
}

//Cambia los ejemplos al cambiar el combobox
function ChangeExample(Value){

	var Div = $("#ExampleDiv");
	
	//TODOS
	if (Value == LAYER_ALL){
		Div.html("<label style=\"width:100%\"><strong>Ej:</strong> \'Hospital\', \'Avenida Bolivar\', \'Quinta Rosa\'</label>");
		var txtCity = $('#txtCity');
		txtCity.attr("disabled", false);
		$('#TxtBuscarEnMapa').html("");
		
	}
	//VIALIDAD
	else if (Value == LAYER_VIALITY){
		Div.html("<label style=\"width:100%\"><strong>Ej:</strong> \'Calle 25 con Carrera 22\', \'Avenida Santiago Mari&ntilde;o\'</label>");
		var txtCity = $('#txtCity');
		txtCity.attr("disabled", false);
		$('#TxtBuscarEnMapa').html("Vialidad");
	}
	//PTOS DE REFERENCIA
	else if (Value == LAYER_REFERENCE){
		Div.html("<label style=\"width:100%\"><strong>Ej:</strong> \'CC Propatria\', \'Hotel del Mar\', \'Ateneo\'</label>");
		var txtCity = $('#txtCity');
		txtCity.attr("disabled", false);
		$('#TxtBuscarEnMapa').html("Pto de referencia");
	}
	//SECTOR
	else if (Value == LAYER_SECTOR){
		Div.html("<label style=\"width:100%\"><strong>Ej:</strong> \'Los Palos Grandes\', \'Barrio Nuevo\'</label>");
		var txtCity = $('#txtCity');
		txtCity.attr("disabled", false);
		$('#TxtBuscarEnMapa').html("Sector");
	}
	//POBLACION
	else if (Value == LAYER_POPULATION){
		Div.html("<label style=\"width:100%\"><strong>Ej:</strong> \'El Pao de Z&aacute;rate\'</label>");
		var txtCity = $('#txtCity');
		txtCity.attr("disabled", false);
		$('#TxtBuscarEnMapa').html("Poblaci&oacute;n");
	}
	//INMUEBLES
	else if (Value == LAYER_BUILDING){
		Div.html("<label style=\"width:100%\"><strong>Ej:</strong> \'Quinta Rosa\'</label>");
		var txtCity = $('#txtCity');
		txtCity.attr("disabled", false);
		txtCity.attr("value", "");
		$('#TxtBuscarEnMapa').html("Inmueble");
	}
	//RESTAURANTES
	else if (Value == LAYER_RESTAURANT){
		Div.html("&nbsp;");
		var txtCity = $('#txtCity');
		txtCity.attr("disabled", false);
		$('#TxtBuscarEnMapa').html("Restaurante");
	}
	//CENTROS ELECTORALES
	else if (Value == LAYER_ELECTORAL){
		Div.html("<label style=\"width:100%\"><strong>Ej:</strong> \'Escuela Unitaria 27\'</label>");
		var txtCity = $('#txtCity');
		txtCity.attr("disabled", false);
		$('#TxtBuscarEnMapa').html("Centro electoral");
	}
	//METRO Y TROLEBUSES
	else if (Value == LAYER_TRANSP){
		Div.html("<labe style=\"width:100%\"l><strong>Ej:</strong> \'Las Adjuntas\'</label>");
		var txtCity = $('#txtCity');
		txtCity.attr("disabled", false);
		$('#TxtBuscarEnMapa').html("Metro o troleb&uacute;s");
	}
	//POSADAS Y HOTELES
	else if (Value == LAYER_HOTEL){
		Div.html("<label style=\"width:100%\"><strong>Ej:</strong> \'Posada La LLovizna\'</label>");
		var txtCity = $('#txtCity');
		txtCity.attr("disabled", false);
		$('#TxtBuscarEnMapa').html("Hotel o posada");
	}
	//BANCOS
	else if (Value == LAYER_BANK){
		Div.html("&nbsp;");
		var txtCity = $('#txtCity');
		txtCity.attr("disabled", false);
		$('#TxtBuscarEnMapa').html("Banco");
	}
	//PTOS TURISTICOS
	else if (Value == LAYER_TURISTIC){
		Div.html("<label style=\"width:100%\"><strong>Ej:</strong> \'Salto Aponwao\'</label>");
		var txtCity = $('#txtCity');
		txtCity.attr("disabled", false);
		$('#TxtBuscarEnMapa').html("Pto Tur&iacute;stico");
	}
	//MUNICIPIOS
	else if (Value == LAYER_MUNICIPALITY){
		Div.html("<label style=\"width:100%\"><strong>Ej:</strong> \'Diego Bautista Urbaneja\'</label>");
		var txtCity = $('#txtCity');
		txtCity.attr("disabled", false);
		txtCity.attr("value", "");
		$('#TxtBuscarEnMapa').html("Municipio");
	}
}




function ShowOrHide(op)
{

	if(op == 1)//Tabla search Estado Municipio y parroquia
	{
		if(SorHEMP == "Show")
		{	
			SorHEMP = "hide";
			contraer(2); 
			$('#ExpandOrHide').attr("src", "../Images/SectionMap/map_r9_c4.gif");
		}	
		else
		{
			SorHEMP = "Show";
			extender(2);
			$('#ExpandOrHide').attr("src", "../Images/SectionMap/map_r9_c18.gif");
		}	
	}else
	{
		if(op==2)//Tool
		{
			if(SorHTool == "Show")// quiere decir que por defecto la tabla esta visible y si el usuario pulso el objeto, se cambiar? este valor por h
			{	
				
				contraer_geotools();
				SorHTool = "hide";
				$('#ExpandOrHide2').attr("src", "../Images/SectionMap/map_r9_c18.gif");
				
			}	
			else
			{
				extender_geotools() ;
				SorHTool = "Show";
				$('#ExpandOrHide2').attr("src", "../Images/SectionMap/map_r9_c4.gif");
			}	
		 }else
		 {
		 
			if(op==3)//true: Reference div se mostrar? o se esconder? dependiendo del caso.
			{
				if(SorHR == "Show")
				{	
					SorHR = "hide";
					contraer(1); 
					$('#ExpandOrHide3').attr("src", "../Images/SectionMap/flecha_arriba.gif");
					
				}	
				else
				{
					SorHR = "Show";
					extender(1);
					$('#ExpandOrHide3').attr("src", "../Images/SectionMap/map_r11_c16.gif");
					
				}	
			}
		} 
	}			
}

function extender(op)
{
	
	if(op == 1)//Referencia efecto: FadeOut
	{
			var objeto = $('#ReferenceDiv');

			//$('#ExpandOrHide3').attr("src", "../Images/SectionMap/map_r11_c16.gif");
			
			objeto.css("visibility", 'visible');
			altura += velocidad;
			
			if (!(altura >= 95)) 
			{
				objeto.css("height", altura);
				window.setTimeout ("extender("+op+");", 20);
			}
	}else
	{
		if(op == 2)//Tabla estado municipio parroquia Id objeto = ParamsDiv. Efecto: Esconder hacia arriba
		{
			var objeto = $('#ParamsDiv');

			objeto.css("visibility", 'visible');
			altura += velocidad;
			
			if (!(altura >= 95)) 
			{
				objeto.css("height", altura);
				window.setTimeout ("extender("+op+");", 20);
			}
		}	
	}	
}


function contraer(op) 
{
	if(op == 1)//Referencia
	{
		var objeto = $('#ReferenceDiv');
		
		//$('#ExpandOrHide3').attr("src", "../Images/SectionMap/flecha_arriba.gif");
		altura -= velocidad;
		
		if (!(altura <= 0)) 
		{
			objeto.css("height", altura);
			window.setTimeout ("contraer("+op+");", 20);
		} 
		else{
			objeto.css("visibility", 'hidden');
			objeto.css("height", '0px');
		}
	}else
	{
		if(op == 2)//Tabla estado municipio parroquia Id objeto = ParamsDiv
		{
			var objeto = $('#ParamsDiv');
		
			altura -= velocidad;
			
			if (!(altura <= 0))
			{
				objeto.css("height", altura);
				window.setTimeout ("contraer("+op+");", 20);
			} 
			else {
				objeto.css("visibility", 'hidden');
				objeto.css("height", '0px');
			}
		}
	}
}



function extender_geotools() {
	
	var objeto = $('#Tool');
	
	objeto.css("visibility", 'visible');
	ancho += velocidad;
	
	if (!(ancho >= 50)) {

		objeto.css("width", ancho);
		
		window.setTimeout ("extender_geotools();", 20);
	}
	
}

function contraer_geotools() {

	var objeto =$('#Tool');
	ancho -= velocidad;

	if (!(ancho <= 0)) {

		objeto.css("width", ancho);
		window.setTimeout ("contraer_geotools();", 20);
	} else {
	
		objeto.css("visibility", "hidden");
		objeto.css("width", "0px");
	}
	
}

function GoToME(){
	
	window.open("http://www.mapaelectoral.com");
}

function RelocateObject(div, varLeft, varTop ){
	
	var offsetLeft = document.getElementById("AnclaRulerReferenceInfo").offsetLeft;
	var offsetTop = document.getElementById("AnclaRulerReferenceInfo").offsetTop;
	var left = offsetLeft + varLeft;
	var top = offsetTop + varTop;
	$("#"+div).css("left", left);
	$("#"+div).css("top", top);	
}



function RelocatedTools()
{

	//Reubicacion de referencia
	RelocateObject("ReferenceDiv", REF_LEFT, REF_TOP);	
	
	RelocateObject("RulerInfo", RULER_LEFT, RULER_TOP);

	RelocateObject("ParamsDiv", EMP_LEFT, EMP_TOP);
	
	/*
	//Reubicacion de EMP y de su boton
	var ObjParamsDiv = $("#ParamsDiv");
	var ObjButtonTableEMP = $("#ButtonTableEMP");;
	
	ObjParamsDiv.css("left", offsetLeft + 825);//495 
	ObjParamsDiv.css ("top", offsetTop -550);
	ObjButtonTableEMP.css ("left", offsetLeft + 677) ;
	ObjButtonTableEMP.css ("top", offsetTop -554);*/

}		


function CloseSession(){
	
	var dataSource= "../Sections/mymaps/CloseSession.php";
		
	$.ajax({
		type: "GET",
		url: dataSource,
		dataType: "html",
		cache: false,
		success: function(XMLhtml){
					parent.$('#loguer2').css('visibility', 'hidden');
					parent.$('#loguer2').css('display', 'none');
					parent.$('#loguer1').css('visibility', 'visible');
					parent.$('#loguer1').css('display', 'block');
		}
	})
}

function Redirect(Page){
	window.location=Page;
}

//////////////////////FUNCIONES DEL HEADER EN INDEX////////////////////////
/******************************** FUNCIONES DE IMAGENES DE SECCIONES ******************************/
/* -- Adobe GoLive JavaScript Library */


function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

var preloadFlag= true;

userAgent = window.navigator.userAgent;
browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/")+1),10);
mustInitImg = true;
function initImgID() {var di = document.images; if (mustInitImg && di) { for (var i=0; i<di.length; i++) { if (!di[i].id) di[i].id=di[i].name; } mustInitImg = false;}}

function findElement(n,ly) {
	var d = document;
	if (browserVers < 4)		return d[n];
	if ((browserVers >= 6) && (d.getElementById)) {initImgID; return(d.getElementById(n))}; 
	var cd = ly ? ly.document : d;
	var elem = cd[n];
	if (!elem) {
		for (var i=0;i<cd.layers.length;i++) {
			elem = findElement(n,cd.layers[i]);
			if (elem) return elem;
		}
	}
	return elem;
}

function changeImagesArray(array) {
	if (preloadFlag == true) {
		var d = document; var img;
		for (i=0;i<array.length;i+=2) {
			img = null; var n = array[i];
			if (d.images) {
				if (d.layers) {img = findElement(n,0);}
				else {img = d.images[n];}
			}
			if (!img && d.getElementById) {img = d.getElementById(n);}
			if (!img && d.getElementsByName) {
				var elms = d.getElementsByName(n);
				if (elms) {
					for (j=0;j<elms.length;j++) {
						if (elms[j].src) {img = elms[j]; break;}
					}
				}
			}
			if (img) {img.src = array[i+1];}
		}
	}
}

function changeImages() {
	changeImagesArray(changeImages.arguments);
}