function externalLinks() {   
 if (!document.getElementsByTagName) return;   
 var anchors = document.getElementsByTagName("a");   
 for (var i=0; i<anchors.length; i++) {   
   var anchor = anchors[i];   
   if (anchor.getAttribute("href") &&   
       	anchor.getAttribute("rel") == "external")   
     	anchor.target = "_blank";   
 }   
}   
window.onload = externalLinks;

function AbreRevista(){
	var TamanioX = 1014;
	var TamanioY = 700;
	var screenX = window.screen.availWidth;
	var screenY = window.screen.availHeight;
	var Izquierda = ((screenX-TamanioX) / 2)-5;
	var Top = ((screenY-TamanioY) / 2)-15;
	var Atributos = "";
	Atributos += "top=" + Top + ", ";
	Atributos += "left=" + Izquierda + ", ";
	Atributos += "width=" + TamanioX + ", ";//1014
	Atributos += "height=" + TamanioY + ", ";//700
	Atributos += "status=0, ";
	Atributos += "menubar=no, ";
	Atributos += "resizable=no, ";
	Atributos += "scrollbars=no, ";
	Atributos += "toolbar=no, ";
	Atributos += "location=no, ";
	Atributos += "directories=no,fullscreen=0";
	w = window.open("http://emi.expomayoristas.com.mx/index2.html", "Revista", Atributos);
	w.focus();
 }
 
 
function Numerico(e) 	{
	key=(document.all) ? e.keyCode : e.which;
	if ((key==33||key==34||key==35||key==36||key==37||key==38||key==39||key==40||key==41||key==42||key==43||key==44||key==45||key==46||key==47||key>57)) {
		return false;
	}
	return true;
}

 
 //############################
//####### MENU
//############################
var NoMenus = 1;
var tiempoabierto=0;
var navegador = navigator.appName;
var UsarTimeouts = true;
var version	= parseFloat(navigator.appVersion.indexOf("MSIE")>0?navigator.appVersion.split(";")[1].substr(6):navigator.appVersion);
if ((navegador != "Microsoft Internet Explorer")||(version < 5)) {  UsarTimeouts = false; }

function ShowMenu(Menu) {
	if (UsarTimeouts == false) {  return; }
	var MenuId = "m" + Menu;
	if (typeof(document.getElementById(MenuId))=="undefined") {  return;  }
	if (tiempoabierto != 0) { clearTimeout(tiempoabierto); }
	document.getElementById(MenuId).style.display = "inline";
	//document.getElementById("top" + Menu).style.backgroundColor="#f9f8f8";
	CerrarMenus(Menu);
}

function CerrarMenus(Menu) {
	for (var i=1; i<=NoMenus; i++) {
		if (i != Menu)  { 
			document.getElementById('m' + i).style.display = "none"; 
			//document.getElementById("top" + i).style.backgroundColor="transparent"; 
		}
		//else { document.getElementById("top" + i).style.backgroundColor="#f9f8f8";  }
	}
}

function CerrarMenu() {
	if (UsarTimeouts == false) {  return; }
	tiempoabierto = setInterval(CerrarMenus, 500);
}

function mantenerMenu() { 
		if (UsarTimeouts == false) {  return; }
		if (tiempoabierto != 0) { clearTimeout(tiempoabierto); }
}

function AbreClick(Menu) {
	var MenuId = "m" + Menu;
	if (document.getElementById(MenuId).style.display == "none" || document.getElementById(MenuId).style.display == "") { 
		document.getElementById(MenuId).style.display = "block"; 
		//document.getElementById("top" + Menu).style.backgroundColor="#f9f8f8";
	}
	else { 
		document.getElementById(MenuId).style.display = "none"; 
		//document.getElementById("top" + Menu).style.backgroundColor="transparent";
	}
	
	CerrarMenus(Menu);
}

// #### FIN MENU

// MODAL


function QuitarModal(did) {
	var Body = document.body;
	var olddiv = document.getElementById(did);
	Body.removeChild(olddiv);
}

function getWindowData(){ 
	/*
	widthViewport: el ancho del viewport.
	heightViewport: el alto del viewport.
	xScroll: la medida del desplazamiento horizontal del scroll.
	yScroll: la medida del desplazamiento vertical del scroll.
	widthTotal: el ancho total de la página (porción visible más porción oculta por el scroll).
	heightTotal: el alto total de la página (porción visible más porción oculta por el scroll).
	*/

    var widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal; 
    if (typeof window.innerWidth != 'undefined'){ 
        widthViewport= window.innerWidth-17; 
        heightViewport= window.innerHeight-17; 
    }else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0){ 
        widthViewport=document.documentElement.clientWidth; 
        heightViewport=document.documentElement.clientHeight; 
    }else{ 
        widthViewport= document.getElementsByTagName('body')[0].clientWidth; 
        heightViewport=document.getElementsByTagName('body')[0].clientHeight; 
    } 
    xScroll=self.pageXOffset || (document.documentElement.scrollLeft+document.body.scrollLeft); 
    yScroll=self.pageYOffset || (document.documentElement.scrollTop+document.body.scrollTop); 
    widthTotal=Math.max(document.documentElement.scrollWidth,document.body.scrollWidth,widthViewport); 
    heightTotal=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,heightViewport); 
    return [widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal]; 
} 



function VerModal(url,width,titulo,id) {

	if (typeof(id)=="undefined" || id=="") { 
		var numero = parseInt(Math.random()*10000000);
		id="modal" + numero;
	}
	
	var ven = getWindowData();
	var widthViewport = ven[0];
	var heightViewport = ven[1];
	var xScroll = ven[2];
	var yScroll = ven[3];
	var widthTotal = ven[4];
	var heightTotal = ven[5];
	ven.length=0;
	var Body = document.body;
	
	var pantalla = document.createElement("div");
	pantalla.setAttribute("class","pantalla_modal");
	pantalla.id = id;
	pantalla.style.height=heightTotal + "px";
	pantalla.style.width=widthTotal + "px";
	
	var msg = document.createElement("div");
	msg.setAttribute("class","pantalla_modal_msg");
	msg.style.width=width + "px";
	
	var encabezado = document.createElement("div");
	encabezado.setAttribute("class","pantalla_modal_encabezado");
	encabezado.style.width= width + "px";
	
	var titulod = document.createElement("div");
	titulod.setAttribute("class","pantalla_modal_titulo");
	titulod.innerHTML = titulo;
	encabezado.appendChild(titulod);
	
	var cerrar = document.createElement("div");
	cerrar.setAttribute("class","pantalla_modal_close");
	cerrar.setAttribute("onclick","QuitarModal('"+ pantalla.id + "')");
	
	encabezado.appendChild(cerrar);
	msg.appendChild(encabezado);
	
	var contenido = document.createElement("div");
	contenido.setAttribute("class","pantalla_modal_contenido");
	contenido.style.width= (width-30) + "px";
	
	msg.appendChild(contenido);
	
	msg.style.height = 240 +"px";
	msg.style.top = ((heightViewport /2) + yScroll) + "px";
	msg.style.marginTop= "-120px";	
		
	msg.style.width= width +"px";
	
	var left = ((widthViewport /2) + xScroll);
	var marginLeft = (width/2);
	if (widthViewport <width) { marginLeft=10; left=20;}
	msg.style.marginLeft= "-" + marginLeft + "px";
	msg.style.left = left + "px";
	
	
	pantalla.appendChild(msg);
	Body.appendChild(pantalla);	
	
	var req = false;
	if (window.XMLHttpRequest) {  
		req = new XMLHttpRequest();
		if (req.overrideMimeType) {
			req.overrideMimeType('text/xml');
		}
	} 
	else if (window.ActiveXObject) { 
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) { QuitarModal(); }
		}
	}
	
	req.onreadystatechange  = function() {
	
	if (req.readyState  == 4) 
         {
            if(req.status  == 200) { 
				var flagScroll=0;
				contenido.innerHTML = req.responseText;

				var alturaTotal = contenido.offsetHeight + encabezado.offsetHeight;
				msg.style.height = alturaTotal +"px";
				if ((alturaTotal+10)> heightTotal) {  pantalla.style.height=(alturaTotal+20) + "px"; flagScroll+=1;}
				var top = ((heightViewport /2) + yScroll);
				var marginTop = (alturaTotal/2);
				if (heightViewport <alturaTotal) { marginTop=10; top=20;}
				msg.style.top = top + "px";
				msg.style.marginTop= "-" + marginTop + "px";	
				
				if (width>widthTotal) { pantalla.style.width=(width+20) + "px";}
				else {
					if (flagScroll==1) { pantalla.style.width= (widthTotal-17) + "px";}
				}
				msg.style.width= width +"px";
				
				var left = ((widthViewport /2) + xScroll);
				var marginLeft = (width/2);
				if (widthViewport <width) { marginLeft=10; left=20;}
				msg.style.marginLeft= "-" + marginLeft + "px";
				msg.style.left = left + "px";
				contenido.style.backgroundImage="none";
				contenido.appendChild(document.createElement("div")); //esto se puso para que el video se acomode
			}
            else { 
			  	QuitarModal(id);
			}
         }

	
	}
	
	req.open('GET', url,  true); 
   	req.send(null); 

}
