// Funciones para los archivos index de los links que no sean General

document.write("<script type='text/javascript' src='../../Library/Others/jquery/jquery-1.3.1.js'></script>");
document.write("<script type='text/javascript' src='../../Library/IngeomapsIniJS.js'></script>");


var preloadFlag = false;

function preloadImages() {
	if (document.images) {
		preloadFlag = true;
	}
}


var VartxtCity; //Variable que contiene el texto que muestra el sistema en el txt 
				//de serach si el usuario no escribio nada para buscar pero si en el txt de ciudad

//Funcion que limpia el txt de la bsqueda
function CleanSearchTxt()
{
	var txtName = $('#txtName').attr("value");

	if((txtName == "¿Qué desea buscar?")||(txtName == VartxtCity))
	{
		//Limpio el txt
		$('#txtName').attr("value", "");
		//Asigno la clase del estilo al txt
		$("#txtName").attr("className", "texto10gris2");
	}
}

//Realiza la busqueda en los links
function Search(){
	
	//NO SE CAMBIA A JQUERY PORQUE SI NO; NO SIRVE EL REPLACE Y ES IMPORTANTE
	var txtName = document.getElementById("txtName").value;
	var txtCity = document.getElementById("txtCity").value;

	//tomo el valor del item seleccionado en el combo de tipo de busqueda
	var Option = $('#cmbSearchType').attr("value");

	txtNameDeseaBuscar = decodeURIComponent(txtName); //Se usa para solamente validar que no sea "Qu desea buscar" y se usa otra 

	txtName = txtName.replace(/(^\s*)|(\s*$)/g,""); 
	txtCity = txtCity.replace(/(^\s*)|(\s*$)/g,""); 
	
	//Extraeré solamente el "Que desea buscar"
	//Posicion del caracter "r"
	var txtNameDecodePositionEnd = txtNameDeseaBuscar.indexOf("r");
	txtNameDecodePositionEnd =  txtNameDecodePositionEnd + 1;

	//Extraigo el string "Que desea buscar"
	txtNameDeseaBuscar = txtNameDeseaBuscar.slice(0, txtNameDecodePositionEnd);

	if (txtName != "" && txtNameDeseaBuscar !="¿Qué desea buscar" && txtName != null && txtName.length >= 3)
	{
		
		txtName = encodeURIComponent(txtName);//Se codifican a utf8 debido a que ajax manda los datos en este formato
		txtCity = encodeURIComponent(txtCity);
			
		var sParams="?txtName="+txtName+"&rbtnSearch="+Option+"&CityName="+txtCity+"&LayerId="+Option+"&sfop=1";
		
		//Redirecciono a home pasando las variables que contiene los datos para poder realizar la busqueda:
		Redirect('../../Map/index.php'+sParams);
							  
	}else
	{
		if(txtName.length < 3 && txtName != "" && txtName != null)
		{
			alert("Lo que desea buscar tiene que ser mayor a 2 letras");
		}else
		{
			//Quiere decir que txtName es vacio o null, osea el usuario no ha escrito nada para buscar.
			if(txtCity != "")//True: quiere decir que el usuario ha escrito algo en ciudad pero no en lo que desea buscar.
			{	
				$('#txtName').attr("className", "txt10rojo2");
				
				var text = "¿Qué desea buscar en la ciudad " + 	txtCity + "?" ;
			
				$('#txtName').attr("value", text);
				
				VartxtCity = text ;
				
			}else
			{	
				//El usuario no ha escrito nada para buscar
				$('#txtName').attr("className", "txt10rojo2");
				
				<!-- var text = decodeURIComponent("¿Qué desea buscar?");-->	
				var text ="¿Qué desea buscar?";
				//var text = encodeURIComponent(text);
		
				$('#txtName').attr("value", text);		
			}		
		}		
	}	
}


function OnlyLetterSearch(evt, string){
	//Mayusculas 65-90
	//Minusculas 97-122
	// 209,  241
	//Enter 13
	// # (key == 35 && string.indexOf(char)==-1) || 
	var key; 
	var value= true;
	var char; 
	
	if(window.event) // IE
	{
		key = evt.keyCode;
	}
	else if(evt.which) // Netscape/Firefox/Opera
	{
		key = evt.which;
	}
	char = String.fromCharCode(key);
	
	
	if (key == 13){
		Search(1);
		value= false;
	}	
	else if (!(key <= 32  || (key >= 48 && key <= 57) || (key >= 65 && key <= 90) || (key >= 97 && key <= 122)|| (key == 241 || key == 209) || 
				 (key == 45 && string.indexOf(char)==-1) || (key == 35 && string.indexOf(char)==-1) )){
		 value= false;
	}
	return value;

}

//Cambia los ejemplos al cambiar el combobox
function ChangeExample(Value){

	var Div = $("#ExampleDiv");
	
	//TODOS
	if (Value == LAYER_ALL){
		Div.html("<label><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><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><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><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><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><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><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("<label><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><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><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><strong>Ej:</strong> \'Diego Bautista Urbaneja\'</label>");
		var txtCity = $('#txtCity');
		txtCity.attr("disabled", false);
		txtCity.attr("value", "");
		$('#TxtBuscarEnMapa').html("Municipio");
	}
}
	
function CloseSession(){
	
	var dataSource= "../mymaps/CloseSession.php";
		
	$.ajax({
		type: "GET",
		url: dataSource,
		dataType: "html",
		cache: false,
		success: function(XMLhtml){
			Redirect('../../Map/index.php');
		}
	})
}

function Redirect(Page){
	window.location=Page;
}

function GoToME(){
	window.open("http://www.mapaelectoral.com");
}

/******************************** FUNCIONES DE IMAGENES DE SECCIONES ******************************/
/* -- Adobe GoLive JavaScript Library */


function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

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);
}

function GoToFacebook(){
	var url = "http://www.facebook.com/group.php?gid=20008645052"; 
	var PopUp = window.open(url);
	PopUp.focus();
}

function SectionGoToHome(){
	window.location='../../index.php';	
	
}
function SectionGoToSiteMap(){
	window.location='../../SiteMap/index.php';	
	
}
function SectionGoToFAQ(){
	window.location='../help/index.php';	
	
}