RutaCompleta = "http://www.noroeste.com/dwd";
ruta_web = "www.noroeste.com";

RutaCompleta = "http://208.43.0.58/dwd";
ruta_web = "208.43.0.58";

function MuestraMenu(nombre) {
  if (nombre == "DivCiudades") {
    document.getElementById('DivCiudades').style.display = 'block';
	
	if (FF() == true) {
	  document.getElementById('DivCiudades').style.top = "349px";
	  
	  navegador = navigator.userAgent;
	  if (navegador.indexOf("Safari") > 1) {
		document.getElementById('DivCiudades').style.top = "339px";
	  }
	} else {
	  document.getElementById('DivCiudades').style.top = "344px";
	}
	
	document.getElementById('DivCiudades').style.height = parseInt(25 * parseInt(document.getElementById("CuantasCiudades").innerHTML)) + "px";
	//document.getElementById('DivCiudades').style.width = parseInt(9 * parseInt(document.getElementById("CiudadMayor").innerHTML)) + "px";
	document.getElementById('DivCiudades').style.width = "100px";
	
	left1 = document.frmBusquedaImpresa.left1.value;
		
	if (FF() == true) {
	  document.getElementById('DivCiudades').style.left = parseInt((AnchoVentana() / 2) - left1 - 9) + "px";
	} else { 
	  document.getElementById('DivCiudades').style.left = parseInt((AnchoVentana() / 2) - left1) + "px";
	}
	
    document.getElementById('ComboCiudad1').className = 'texto_normal_blanco';
    document.getElementById('ComboCiudad2').className = 'texto_normal_blanco';
	
	document.getElementById('TablaFecha1').className = 'texto_normal_negro';
    document.getElementById('TablaFecha2').className = 'texto_normal_negro';
	document.getElementById('ComboSeccion1').className = 'texto_normal_negro';
    document.getElementById('ComboSeccion2').className = 'texto_normal_negro';
	document.getElementById('DivSecciones').style.display = 'none';
	
	OcultaCalendario();
	
	menu_visible = 1;
  }
  
  if (nombre == "DivSecciones") {
    document.getElementById('DivSecciones').style.display = 'block';
	
	if (FF() == true) {
	  document.getElementById('DivSecciones').style.top = "349px";
	  
	  navegador = navigator.userAgent;
	  if (navegador.indexOf("Safari") > 1) {
		document.getElementById('DivSecciones').style.top = "339px";
	  }
	} else { 
	  document.getElementById('DivSecciones').style.top = "344px";
	}
	
	document.getElementById('DivSecciones').style.height = parseInt(25 * parseInt(document.getElementById("CuantasSecciones").innerHTML)) + "px";
	//document.getElementById('DivSecciones').style.width = parseInt(9 * parseInt(document.getElementById("SeccionMayor").innerHTML)) + "px";
	document.getElementById('DivSecciones').style.width = "100px";
	
	left2 = document.frmBusquedaImpresa.left2.value;
	
	if (FF() == true) {
	  document.getElementById('DivSecciones').style.left = parseInt((AnchoVentana() / 2) - left2 - 9) + "px";
	} else { 
	  document.getElementById('DivSecciones').style.left = parseInt((AnchoVentana() / 2) - left2) + "px";
	}
    
	document.getElementById('ComboSeccion1').className = 'texto_normal_blanco';
    document.getElementById('ComboSeccion2').className = 'texto_normal_blanco';
	
	document.getElementById('TablaFecha1').className = 'texto_normal_negro';
    document.getElementById('TablaFecha2').className = 'texto_normal_negro';
	document.getElementById('ComboCiudad1').className = 'texto_normal_negro';
    document.getElementById('ComboCiudad2').className = 'texto_normal_negro';
	document.getElementById('DivCiudades').style.display = 'none';
	
	OcultaCalendario();
	
	menu_visible = 3;
  }
  
  if (nombre == "TablaFecha1") {
    document.getElementById('ComboCiudad1').className = 'texto_normal_negro';
    document.getElementById('ComboCiudad2').className = 'texto_normal_negro';
	document.getElementById('DivCiudades').style.display = 'none';
	
    document.getElementById('TablaFecha1').className = 'texto_normal_blanco';
    document.getElementById('TablaFecha2').className = 'texto_normal_blanco';
	document.getElementById('ComboSeccion1').className = 'texto_normal_negro';
    document.getElementById('ComboSeccion2').className = 'texto_normal_negro';
	document.getElementById('DivSecciones').style.display = 'none';
	
	menu_visible = 2;
  }
}

var idtimer;

function TerminaTimer() {
  clearInterval(idtimer);
}

function SubOcultaMenu() {
  clearInterval(idtimer);
  idtimer = setTimeout("Inicio('si'); OcultaMenu()", 1000);
}

function OcultaMenu() {

  if (menu_visible == 1 && iniciar == "si") {
    el_div = document.getElementById("DivCiudades");
		
	// calcula las dimensiones del menu
	x1 = parseInt(el_div.style.left);
	x2 = parseInt(el_div.style.width) + x1;

	y1 = parseInt(el_div.style.top);
	y2 = parseInt(el_div.style.height) + y1;
	
	//document.getElementById("tres").innerHTML = x1 + ">" + px + "<br>" + x2 + "<" + px + "<br>" + y1 + ">" + py + "<br>" + y2 + "<" + py;
	
	// si el cursor no esta sobre el menu lo oculta
	if ( x1 > px || x2 < px || y1 > py || y2 < py ) {
	  document.getElementById('DivCiudades').style.display = 'none';
      document.getElementById('ComboCiudad1').className = 'texto_normal_negro'; 
      document.getElementById('ComboCiudad2').className = 'texto_normal_negro';
	  iniciar = "no";
	}
  }
  
  // ----------------------------------------------------------------
  
  if (menu_visible == 2 && iniciar == "si") {
    encontrado = "no";
	
    oItems = document.getElementsByTagName("div");
    for (i = 0; i < oItems.length; i++) {
      if (oItems[i].className == "calendar") {
	    el_div = oItems[i];
		encontrado = "si";
	  }
    }
	
	if (encontrado == "si") {
	  x1 = parseInt(el_div.style.left);
	  
	  x2 = parseInt(el_div.style.width) + x1;
	  if (!el_div.style.width) { x2 = parseInt(x1 + 200); }
	  
	  y1 = parseInt(el_div.style.top);
	  
	  y2 = parseInt(el_div.style.height) + y1;	  
	  if (!el_div.style.height) { y2 = parseInt(y1 + 177); }
	  
	  // si el cursor no esta sobre el menu lo oculta
	  if ( x1 > px || x2 < px || y1 > py || y2 < py ) {
	    document.getElementById('TablaFecha1').className = 'texto_normal_negro'; 
        document.getElementById('TablaFecha2').className = 'texto_normal_negro';
	    OcultaCalendario();
	  }	  
	} else {
	  document.getElementById('TablaFecha1').className = 'texto_normal_negro'; 
      document.getElementById('TablaFecha2').className = 'texto_normal_negro';
	}
	
  }
  
  // ----------------------------------------------------------------
  
  if (menu_visible == 3 && iniciar == "si") {
    el_div = document.getElementById("DivSecciones");
		
	// calcula las dimensiones del menu
	x1 = parseInt(el_div.style.left);
	x2 = parseInt(el_div.style.width) + x1;
	y1 = parseInt(el_div.style.top);
	y2 = parseInt(el_div.style.height) + y1;
	
	//document.getElementById("tres").innerHTML = x1 + ">" + px + "<br>" + x2 + "<" + px + "<br>" + y1 + ">" + py + "<br>" + y2 + "<" + py;
	
	// si el cursor no esta sobre el menu lo oculta
	if ( x1 > px || x2 < px || y1 > py || y2 < py ) {
	  document.getElementById('DivSecciones').style.display = 'none';
      document.getElementById('ComboSeccion1').className = 'texto_normal_negro'; 
      document.getElementById('ComboSeccion2').className = 'texto_normal_negro';
	  iniciar = "no";
	}
  }
  
}

var menu_visible;
var iniciar;

function Inicio(valor) {
  iniciar = valor;
}

var px, py;

function RevisaMenu(ev) {
  // calcula la posicion del raton
  if (!document.all) {
	event = ev;
	py = ev.pageY; 
	px = ev.pageX;
  } else {
	py = event.clientY + ScrollY(); 
	px = event.clientX + ScrollX();
  }
	
  // si hay un menu visible
  if (menu_visible == 1 && iniciar == 'si') {
    el_div = document.getElementById("DivCiudades");
		
	// calcula las dimensiones del menu
	x1 = parseInt(el_div.style.left);
	x2 = parseInt(el_div.style.width) + x1;
	y1 = parseInt(el_div.style.top);
	y2 = parseInt(el_div.style.height) + y1;
	
	//document.getElementById("tres").innerHTML = x1 + ">" + px + "<br>" + x2 + "<" + px + "<br>" + y1 + ">" + py + "<br>" + y2 + "<" + py;
	
	// si el cursor no esta sobre el menu lo oculta
	if ( x1 > px || x2 < px || y1 > py || y2 < py ) {
	  setTimeout("OcultaMenu()", 1000);
	}	
  }
  
  // si hay un menu visible
  if (menu_visible == 2 && iniciar == 'si') {
    encontrado = "no";
	
    oItems = document.getElementsByTagName("div");
    for (i = 0; i < oItems.length; i++) {
      if (oItems[i].className == "calendar") {
	    el_div = oItems[i];
		encontrado = "si";
	  }
    }
	
	if (encontrado == "si") {
	  x1 = parseInt(el_div.style.left);
	  
	  x2 = parseInt(el_div.style.width) + x1;
	  if (!el_div.style.width) { x2 = parseInt(x1 + 200); }
	  
	  y1 = parseInt(el_div.style.top);
	  
	  y2 = parseInt(el_div.style.height) + y1;	  
	  if (!el_div.style.height) { y2 = parseInt(y1 + 177); }
	    
	  // si el cursor no esta sobre el menu lo oculta
	  if ( x1 > px || x2 < px || y1 > py || y2 < py ) {
	    setTimeout("OcultaMenu()", 1000);
	  }
	}
  }
  
  // si hay un menu visible
  if (menu_visible == 3 && iniciar == 'si') {
    el_div = document.getElementById("DivSecciones");
		
	// calcula las dimensiones del menu
	x1 = parseInt(el_div.style.left);
	x2 = parseInt(el_div.style.width) + x1;
	y1 = parseInt(el_div.style.top);
	y2 = parseInt(el_div.style.height) + y1;
	
	//document.getElementById("tres").innerHTML = x1 + ">" + px + "<br>" + x2 + "<" + px + "<br>" + y1 + ">" + py + "<br>" + y2 + "<" + py;
	
	// si el cursor no esta sobre el menu lo oculta
	if ( x1 > px || x2 < px || y1 > py || y2 < py ) {
	  setTimeout("OcultaMenu()", 1000);
	}	
  }
  
}

var cal;

function LeeFechaEdicionImpresa() {
	dia = document.getElementById("DiaEdicionImpresa").value;
	if (dia.length == 1) { dia = "0" + dia; }
	
	mes = document.getElementById("MesEdicionImpresa").value;
	if (mes.length == 1) { mes = "0" + mes; }
	
	anio = document.getElementById("AnioEdicionImpresa").value;
	
	document.frmBusquedaImpresa.fecha.value = anio + "-" + mes + "-" + dia;
	LeeCiudades("'" + anio + "-" + mes + "-" + dia + "'");
}

function DesEI() {
  // deshabilitar ciudad y seccion
  document.getElementById("comboCiudades").disabled = true;
  document.getElementById("comboSecciones").disabled = true;
}

function OcultaCalendario() {
  oItems = document.getElementsByTagName("div");
  for (i = 0; i < oItems.length; i++) {
    if (oItems[i].className == "calendar") {
	  oItems[i].style.visibility = "hidden";
	  oItems[i].className = "";
	  document.getElementById('TablaFecha1').className = 'texto_normal_negro';
      document.getElementById('TablaFecha2').className = 'texto_normal_negro';
	}
  }
  
  oItems = document.getElementsByTagName("iframe");
  for (i = 0; i < oItems.length; i++) {
	oItems[i].style.visibility = "hidden";
  }
  
  menu_visible = 0;
}

var objetoImpresa = false;

function crearObjetoImpresa() {
  try { objetoImpresa = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) {
    try { objetoImpresa = new ActiveXObject("Microsoft.XMLHTTP"); }
    catch (E) { objetoImpresa = false; }
  }

  if (!objetoImpresa && typeof XMLHttpRequest!='undefined') {
    objetoImpresa = new XMLHttpRequest();
  }
} 

var PonerEn;
var cadena;

function LeeImagen(url, numero) { 
  cuantos = parseInt(document.getElementById("NumImagenesEI").innerHTML);
  for (i = 0; i <= cuantos; i ++) {
	try {
     document.getElementById("ImagenEI_" + i).filters.alpha.opacity = 100;
	} catch(e) { }
	
	try {
	  document.getElementById("ImagenEI_" + i).style.MozOpacity = 100/100;
	} catch(e) { }
  }  
  
  try {
    document.getElementById("ImagenEI_" + numero).filters.alpha.opacity = 40;
  } catch(e) { }
  
  try {
    document.getElementById("ImagenEI_" + numero).style.MozOpacity = 40/100;
  } catch(e) { }
  
  PonerEn = "EspacioImagenPrincipal";
  cadena = "accion=LeeImagen&url=" + url;
  
  LeeDatosImpresa();
}

function VerPdf(archivo) {
  if (archivo == "LINK") {
    archivo = document.getElementById("LinkPdf").innerHTML;
  }

  if (archivo == "X" || archivo == "http://www.noroeste.com/dwd/X") {
    alert('El archivo solicitado no existe');
  } else {
    if (archivo == "Y") {
	  if (document.getElementById("ArchivoPdf").innerHTML == "X") {
	    alert('El archivo solicitado no existe');
	  } else {
	    window.open(document.getElementById("ArchivoPdf").innerHTML,"Pdf");
	  }
	} else {
      window.open(archivo,"Pdf");
	}
  }
}

function VerImagenEI(url) {
  window.open('muestra_imagen.php?url=' + url,'mostrar_imagen','width=760, height=640, status=no, toolbar=no ,menubar=no, resizable=no, scrollbars=yes, left=' + CentrarAncho(760) + ', top=' + CentrarAlto(640));
}

function BuscarImpresa() {
  PonerEn = "DivBody";
  cadena = "accion=LeeBody&fecha=" + document.frmBusquedaImpresa.fecha.value + "&ciu=" + document.frmBusquedaImpresa.ciudad.value + "&sec=" + document.frmBusquedaImpresa.seccion.value;
  
  LeeDatosImpresa();
}

function LeeCiudades(valor) {
  PonerEn = "PonCiudades";
  cadena = "accion=LeeCiudades&id=" + valor + "&fecha=" + document.frmBusquedaImpresa.fecha.value;
  
  LeeDatosImpresa();
}

function LeeSecciones(valor) {
  PonerEn = "PonSecciones";
  cadena = "accion=LeeSecciones&id=" + valor  + "&fecha=" + document.frmBusquedaImpresa.fecha.value;
  
  LeeDatosImpresa();
}

function ValorBusqueda(tipo,dato) {
  
  separa = dato.split("|");
  
  valor = separa[0];
  largo = separa[1];
    
  if (tipo == 2) {
    anterior = document.frmBusquedaImpresa.ciudad.value;
	
    document.frmBusquedaImpresa.ciudad.value = valor;
	
	if (anterior != valor) {
	  // actualizar el combo de secciones
	  LeeSecciones(valor);
	}
  }
  
  if (tipo == 3) {
    document.frmBusquedaImpresa.seccion.value = valor;
	
	BuscarImpresa();
  }
}

function Contacto(valor) {
  window.open('contactanos.php?para=' + valor + '&archivo=contacto.gif','mail','width=640, height=480, status=no, toolbar=no ,menubar=no, resizable=no, left=' + CentrarAncho(640) + ', top=' + CentrarAlto(480));
}

function LeeDatosImpresa() {
  try {
    mostrar_espera();
  } catch(e) { }

  crearObjetoImpresa();
  
  if (objetoImpresa.readyState != 0) {
	try {
      ocultar_espera();
	} catch(e) { }
	
    alert('Error al crear el objeto XML. El Navegador no soporta AJAX');
  } else {
    objetoImpresa.onreadystatechange = procesaResultadoImpresa;	
	
    objetoImpresa.open("GET", "curl.php?link=http://" + ruta_web + "/dwd/edicion_impresa.php&" + cadena + "&random=" + Math.random(), true);

	//alert("curl.php?link=http://" + ruta_web + "/dwd/edicion_impresa.php&" + cadena);

    objetoImpresa.send(null);
  }
}

function procesaResultadoImpresa() { 
  if (objetoImpresa.readyState == 4) {
	try {
      ocultar_espera();
	} catch(e) { }
	
    datoImpresa = objetoImpresa.responseText;
	
	try {
	document.getElementById(PonerEn).innerHTML = datoImpresa;
	} catch(e) { }
	
	if (PonerEn == "PonCiudades") { 
	  document.frmBusquedaImpresa.ciudad.value = document.getElementById("PrimeraCiudad").innerHTML;
	  LeeSecciones(document.frmBusquedaImpresa.ciudad.value);
	  return;
	}
	if (PonerEn == "PonSecciones") { document.frmBusquedaImpresa.seccion.value = document.getElementById("PrimeraSeccion").innerHTML; BuscarImpresa(); }
	
	if (pasos == 1) {  
	  PonerEn = "DivHeader";
      cadena = "accion=LeeHeader";
  
      LeeDatosImpresa();
	  
	  pasos = 2;
	} else { 
	
	  if (pasos == 2) {
		try {
		  //activaCalendario();
		} catch(e) { }
		
	    PonerEn = "DivBody";
						
		try {
          cadena = "accion=LeeBody&ciu=" + document.getElementById("ClavePrimeraCiudad").value + "&sec=" + document.getElementById("ClavePrimeraSeccion").value;
		} catch(e) {
		  try {
		    cadena = "accion=LeeBody&ciu=cul&sec=" + document.getElementById("ClavePrimeraSeccion").value;
		  } catch(e) {
			cadena = "accion=LeeBody&ciu=cul&sec=cul";
		  }		  
		}
		  
        LeeDatosImpresa();
		
	    pasos = 3;
	  }
	  
	}
	
  } 
}

coordx = parseInt((AnchoVentana() / 2) - 491);
coordy = 344;

if (FF() == true) {
  coordy = 349;
}

navegador = navigator.userAgent;
if (navegador.indexOf("Safari") > 1) {
  coordy = 339;
}

var pasos;

pasos = 1;


function inicioEI() {
  PonerEn = "EdicionImpresa";
  cadena = "accion=LeeInicio";
  LeeDatosImpresa();
}
