function RevisarMapa() {
	if (!loaded) return;
	
	if (map == null) {
		AjustarMapa();
	}
}

function CrearMapa() {
	map = new Microsoft.Maps.Map(document.getElementById('myMap'), 
		{
		credentials: 'Av_F6h7rfsUUouj5Jg83cCBvI9qK7rdxKS5gSx5L0yTSbNXCVf0sw796mSQVCYj7', 
		disableBirdseye: true,
		disableKeyboardInput: true,
		enableClickableLogo: false,
		enableSearchLogo: false,
		showCopyright: false,
		showDashboard: false,
		showMapTypeSelector: false,
		showScalebar: false,
		mapTypeId:Microsoft.Maps.MapTypeId.road
		}
	);
}

function AjustarMapa(north, west, south, east) {
	if (!loaded) return;
	
	if (map == null) {
		CrearMapa();
	}
	
	if (north == undefined) {
		north=12.511111; west=-79.023056; south=-4.225, east=-66.848333;
	}
	
	var boundingBox = Microsoft.Maps.LocationRect.fromEdges(north, west, south, east); 
	map.setView({bounds: boundingBox});
	
	EsconderMunicipio();	
}

var lastMouseOverPushPin;
function MunicipioOver(Latitud,Longitud) {
	if (!loaded || map == null) return;

	MunicipioOut();
	lastMouseOverPushPin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(Latitud, Longitud), null);
	map.entities.push(lastMouseOverPushPin);
}

function MunicipioOut() {
	if (!loaded || map == null) return;

	if (lastMouseOverPushPin != null) {
		map.entities.remove(lastMouseOverPushPin);
		lastMouseOverPushPin = null;
	}
}

var lastMouseClickPushPin;
function MunicipioClick() {
	RemoveMunicipioClick();
	lastMouseClickPushPin = lastMouseOverPushPin;
	lastMouseOverPushPin = null;
}

function RemoveMunicipioClick() {
	if (lastMouseClickPushPin != null) {
		map.entities.remove(lastMouseClickPushPin);
		lastMouseClickPushPin = null;
	}	
}

var lastMun = null;
function VerMunicipio(IDMunicipio) {
	EsconderMunicipio();
	var divMun = document.getElementById("div" + IDMunicipio);
	if (divMun != null) {
		divMun.style.display = "";
		document.getElementById('TopEnlaces').scrollIntoView(true);
	}
	lastMun = divMun;
	MunicipioClick();
}

function EsconderMunicipio() {
	if (lastMun != null) {
		lastMun.style.display = "none";
	}	
	RemoveMunicipioClick();
}

	
// TO OPEN A POPUP WINDOW
function OpenPopup(popupName, myURL, popupWidth, popupHeight, popupScroll) {
	var popupX = (screen.availWidth)? ((screen.availWidth - popupWidth) / 2): 20;
	var popupY = (screen.availHeight)? ((screen.availHeight - popupHeight) / 3):20;
	var details = 'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=' + (typeof(popupScroll)=="undefined" ? 0 : popupScroll) + ',resizable=0,width='+popupWidth+',height='+popupHeight+',top='+popupY+',left='+popupX;
	var mypopup = window.open(myURL, popupName, details);
	if (mypopup != null) {
	    mypopup.focus();
	}
}

function AjustarEnlacesET() {
	var anchors=document.getElementsByTagName('a');
	var a, title, normaID;
	for (var i = 0; i < anchors.length; i++) {    
		a=anchors[i];
		title = a.getAttribute("title");    
		if (title!=null && title.indexOf("NormaSIT")==0) {
			normaID = title.substring(9);
			a.rel = "clases/ArtET.asp?Norma=" + normaID;
			a.setAttribute("title","Estatuto Tributario CETA");
			a.href="vista_de_un_articulo.asp?Norma=" + normaID;
			$(a).cluetip({
					arrows:true,
					clickThrough:true,
					width:350
			});
		}
	}

}

function AjustarConcordanciasET() {
	var anchors=document.getElementsByTagName('a');
	var a, clase, destino, normaID;
	for (var i = 0; i < anchors.length; i++) {    
		a=anchors[i];
		clase = a.className;
		destino = a.href;
		if (clase!=null && destino!=null && clase.indexOf("EnlConc")==0) {
			// Enlace con ET
			if (destino.indexOf("Norma=")>0) {
				normaID = destino.substring(destino.indexOf("=")+1);
				a.rel = "clases/ArtET.asp?Norma=" + normaID;
				a.setAttribute("title","Estatuto Tributario CETA");
				$(a).cluetip({
						arrows:true,
						clickThrough:true,
						width:350
				});				
			}
			// Enlace con Documento
			else if (destino.indexOf("DocumentoID=")>0) {
				normaID = destino.substring(destino.indexOf("=")+1);
				a.rel = "clases/RelDoc.asp?DocumentoID=" + normaID;
				a.setAttribute("title", "Relator&iacute;a CETA: " + a.getAttribute("title"));
				$(a).cluetip({
						arrows:true,
						clickThrough:true,
						width:350
				});
			}
		}
	}
}


function GetDefaultTab() {
	var metas = document.getElementsByTagName('META'), content;
	for (var i=0; i<metas.length; i++) {
		content = metas[i].getAttribute('CONTENT');
		if (metas[i].getAttribute('NAME') == "Generator" && content.indexOf("Tab") == 0) {
			return parseInt(content.replace("Tab", ""));
		}
	}
	return 1;
}

function TabClick(tabClicked, totalTabs) {
	var tmpClass, tmpDisplay;
	tabClicked--;
	for (var i=0; i<totalTabs; i++) {
		tmpClass = (tabClicked==i) ? 'TabA' : 'TabB';
		tmpDisplay = (tabClicked==i) ? '' : 'none';
		objTabs[i].className = tmpClass;
		objPnls[i].style.display = tmpDisplay;
		objImgs[i].src = objImgs[i].src.replace('TabA','TabX').replace('TabB','TabX').replace('TabX',((tabClicked==i) ? 'TabA' : 'TabB'));
	}
}

// Variables for the tab behavior
var objPnls, objTabs, objImgs;

function LoadTabsAndPanels(maxTabs) {
	// Prepare the container
	var objSubmenu=document.getElementById('pnlSubmenu');
	//objSubmenu.childNodes[0].style.display='none';

	// Fill the arrays and prepare the submenus
	objPnls = new Array(maxTabs); objTabs = new Array(maxTabs); objImgs = new Array(maxTabs);
	for (var i=0; i<maxTabs; i++) {
		objTabs[i] = document.getElementById('tab' + (i+1));
		objPnls[i] = document.getElementById('pnl' + (i+1));
		objImgs[i] = document.getElementById('imgTab' + (i+1));
		objPnls[i].width = '';
		objSubmenu.appendChild(objPnls[i]);
	}
		
	TabClick(GetDefaultTab(), maxTabs);
}

function ResizeFrame(f) {
	f.style.height = f.contentWindow.document.body.scrollHeight + "px";
	f.style.visibility = "visible";
}


function mClick(classSelected, classUnselected, parentsPrefix, childrenPrefix, maxElements, selectedElement) {
	var tmpChild, tmpParent, selected;
	for (var i=1; i<=maxElements; i++) {
		selected = (selectedElement == i);
		tmpParent = document.getElementById(parentsPrefix + i);
		tmpParent.setAttribute("childSelected",(selected ? "1" : "0"));
		tmpParent.className = (selected ? classSelected : classUnselected);
		
		tmpChild = document.getElementById(childrenPrefix + i);
		tmpChild.style.display = (selected ? '' : 'none');
	}
}

function mOver(src, classHover) {
	src.className = classHover;
}

function mOut(src, classUnselected) {
	if (src.getAttribute("childSelected") != "1") {
		src.className = classUnselected;
	}
}

function getParameterByName(name) {
    var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
    return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}


// Funciones usadas en la pagina 2001-2010
/*
function mClick(src) {
	var enl;
	if (src.tagName == "TR") {
		enl = src.getElementsByTagName("A");
		if (enl.length > 0) {
			enl[0].click();
		}
	}
}

function mOver(src,clrOver) {
	src.style.cursor = 'hand';
	src.bgColor = clrOver;
}

function mOut(src,clrIn) {
	src.style.cursor = 'default';
	src.bgColor = clrIn;
}
*/
