var seccion = "";

/* A- y A+ */

if (document.styleSheets) {
   var hoja = document.styleSheets[0];
   var plantilla = document.styleSheets[1];
   if (hoja.cssRules) hoja = hoja.cssRules;
   else if (hoja.rules) hoja = hoja.rules;
   else hoja = null;
   if (plantilla.cssRules) plantilla = plantilla.cssRules;
   else if (plantilla.rules) plantilla = plantilla.rules;
   else plantilla = null;
   if (hoja!=null) {
      hoja_ = new Array(hoja.length);
      for (i=0; estilo=hoja[i]; i++) {
         original = parseInt(estilo.style.fontSize);
         if (!isNaN(original)) hoja_[i] = original;
         else hoja_[i] = 0;
      }
   }
   if (plantilla!=null) {
      plantilla_ = new Array(plantilla.length);
      for (i=0; estilo=plantilla[i]; i++) {
         original = parseInt(estilo.style.fontSize);
         if (!isNaN(original)) plantilla_[i] = original;
         else plantilla_[i] = 0;
      }
   }
   var zoom_ = 0;
}

function zoom(accion) {
   if (!document.styleSheets || hoja==null || plantilla==null) return;
   if (accion=='-') {
      if (zoom_>-3) zoom_--;
      else return;
   } else if (accion=='+') {
      if (zoom_<3) zoom_++;
      else return;
   } else zoom_ = 0;
   for (i=0; estilo=hoja[i]; i++) {
      actual = parseInt(estilo.style.fontSize);
      if (!isNaN(actual)) {
         if (accion=='-') actual--;
         else if (accion=='+') actual++;
         else actual = hoja_[i];
         estilo.style.fontSize = actual + 'px';
      }
   }
   for (i=0; estilo=plantilla[i]; i++) {
      actual = parseInt(estilo.style.fontSize);
      if (!isNaN(actual)) {
         if (accion=='-') actual--;
         else if (accion=='+') actual++;
         else actual = plantilla_[i];
         nombre = estilo.selectorText.toLowerCase();
         if (!nombre.startsWith(".tab_enlaces") &&
            nombre.indexOf("tabs")==-1 &&
            nombre.indexOf("btn_buscar")==-1 &&
            nombre.indexOf("tab_enlaces")==-1) estilo.style.fontSize = actual + 'px';
      }
   }
}

/* Banners */

function doClick(id_banner, id_zona, codigo, referer, link_href, link_target) {
   var myScript = document.createElement("script");
   myScript.src = "http://www.yucatan.gob.mx/click.jsp?id_banner="+id_banner+"&id_zona="+id_zona+"&codigo="+codigo+"&referer="+referer+"&y="+Math.random();
   document.body.appendChild(myScript);
   document.body.removeChild(myScript);
   self.focus();
   window.open(link_href, link_target);
}

/*
Copyright (c) Copyright (c) 2007, Carl S. Yestrau All rights reserved.
Code licensed under the BSD License: http://www.featureblend.com/license.txt
Version: 1.0.3
*/
var FlashDetect=new function(){var self=this;self["installed"]=false;self["raw"]="";self["major"]=-1;self["minor"]=-1;self["revision"]=-1;self["revisionStr"]="";var activeXDetectRules=[{"name":"ShockwaveFlash.ShockwaveFlash.7","version":function(obj){return getActiveXVersion(obj);}},{"name":"ShockwaveFlash.ShockwaveFlash.6","version":function(obj){var version="6,0,21";try{obj["AllowScriptAccess"]="always";version=getActiveXVersion(obj);}catch(err){};return version;}},{"name":"ShockwaveFlash.ShockwaveFlash","version":function(obj){return getActiveXVersion(obj);}}];var getActiveXVersion=function(activeXObj){var version=-1;try{version=activeXObj.GetVariable("$version");}catch(err){};return version;};var getActiveXObject=function(name){var obj=-1;try{obj=new ActiveXObject(name);}catch(err){};return obj;};var parseActiveXVersion=function(str){var versionArray=str["split"](",");return {"raw":str,"major":parseInt(versionArray[0]["split"](" ")[1],10),"minor":parseInt(versionArray[1],10),"revision":parseInt(versionArray[2],10),"revisionStr":versionArray[2]};};var parseStandardVersion=function(str){var descParts=str["split"](/ +/);var majorMinor=descParts[2]["split"](/\./);var revisionStr=descParts[3];return {"raw":str,"major":parseInt(majorMinor[0],10),"minor":parseInt(majorMinor[1],10),"revisionStr":revisionStr,"revision":parseRevisionStrToInt(revisionStr)};};var parseRevisionStrToInt=function(str){return parseInt(str["replace"](/[a-zA-Z]/g,""),10)||self["revision"];};self["majorAtLeast"]=function(version){return self["major"]>=version;};self["FlashDetect"]=function(){if(navigator["plugins"]&&navigator["plugins"]["length"]>0){var type="application/x-shockwave-flash";var mimeTypes=navigator["mimeTypes"];if(mimeTypes&&mimeTypes[type]&&mimeTypes[type]["enabledPlugin"]&&mimeTypes[type]["enabledPlugin"]["description"]){var version=mimeTypes[type]["enabledPlugin"]["description"];var versionObj=parseStandardVersion(version);self["raw"]=versionObj["raw"];self["major"]=versionObj["major"];self["minor"]=versionObj["minor"];self["revisionStr"]=versionObj["revisionStr"];self["revision"]=versionObj["revision"];self["installed"]=true;};}else{if(navigator["appVersion"]["indexOf"]("Mac")==-1&&window["execScript"]){var version=-1;for(var i=0;i<activeXDetectRules["length"]&&version==-1;i++){var obj=getActiveXObject(activeXDetectRules[i]["name"]);if(typeof obj=="object"){self["installed"]=true;version=activeXDetectRules[i]["version"](obj);if(version!=-1){var versionObj=parseActiveXVersion(version);self["raw"]=versionObj["raw"];self["major"]=versionObj["major"];self["minor"]=versionObj["minor"];self["revision"]=versionObj["revision"];self["revisionStr"]=versionObj["revisionStr"];};};};};};}();};FlashDetect["release"]="1.0.3";
var showFlash = FlashDetect.installed;

function banner(swf,w,h,img,texto,liga) {
   var str = "";
   var _liga = "";
   if (liga!="") _liga = "</a>";
   var noFlash = "";
   if (img!="") noFlash = liga+"<img src='"+img+"' width="+w+" height="+h+" alt='"+texto+"' title='"+texto+"' border=0>"+_liga;
   else {
      noFlash = noFlash + "<div style='text-align:center;width:"+w+"px;background-color:#FFFFFF;padding:0px;border:1px solid #808080;'>";
      noFlash = noFlash + "<table cellpadding=5 cellspacing=0 style='width:"+w+"px;height:"+h+"px;'><tr><td align=center>";
      noFlash = noFlash + liga + texto + _liga;
      noFlash = noFlash + "<p><a href='http://www.macromedia.com/go/getflashplayer' target='_blank' class='blank'>Descargar Flash Viewer</a></p>";
      noFlash = noFlash + "</td></tr></table>";
      noFlash = noFlash + "</div>";
   }
   if (showFlash) {
      str = str + "<div style='position:relative;width:"+w+";height:"+h+";'>";
      str = str + "<div style='position:absolute;top:0px;left:0px;z-index:1;'>"+liga+"<img src='http://www.yucatan.gob.mx/images/1.gif' alt='"+texto+"' title='"+texto+"' width="+w+" height="+h+" border=0>"+_liga+"</div>";
      str = str + "<div><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width="+w+" height="+h+">";
      str = str + "<param name='movie' value='"+swf+"'>";
      str = str + "<param name='quality' value='high'>";
      str = str + "<param name='wmode' value='transparent'>";
      str = str + "<embed src='"+swf+"' width="+w+" height="+h+" quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' wmode='transparent'></embed></object></div>";
      str = str + "</div>";
   } else str = noFlash;
   return str;
}

function insertSWF(swf,w,h,html) {
   var str = "";
   var noFlash = "";
   noFlash = noFlash + "<div style='text-align:center;width:"+w+";background-color:#FFFFFF;padding:0px;border:1px solid #808080;'>";
   noFlash = noFlash + "<table cellpadding=5 cellspacing=0 style='width:"+w+"px;height:"+h+"px;'><tr><td align=center>";
   noFlash = noFlash + html;
   noFlash = noFlash + "<p><a href='http://www.macromedia.com/go/getflashplayer' target='_blank' class='blank'>Descargar Flash Viewer</a></p>";
   noFlash = noFlash + "</td></tr></table>";
   noFlash = noFlash + "</div>";
   if (showFlash) {
      str = str + "<div><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width="+w+" height="+h+">";
      str = str + "<param name='movie' value='"+swf+"'>";
      str = str + "<param name='quality' value='high'>";
      str = str + "<param name='wmode' value='transparent'>";
      str = str + "<param name='allowfullscreen' value='true'>";
      str = str + "<embed src='"+swf+"' width="+w+" height="+h+" quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' wmode='transparent' allowfullscreen='true'></embed></object></div>";
   } else str = noFlash;
   return str;
}

function popup(URL,winName,w,h,features) {
   var x = (screen.width-w)/2;
   var y = (screen.height-h)/2;
   features = "top="+y+",left="+x+",width="+w+",height="+h+","+features;
   pop = window.open(URL,winName,features);
   return pop;
}

/* Menús */

function ajax() {
   var xmlHttp = null;
   if (window.ActiveXObject) xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) xmlHttp = new XMLHttpRequest();
   return xmlHttp;
}

function getMenus() {
   var aj_menu = new ajax();
   aj_menu.onreadystatechange = function() {
      if (aj_menu.readyState==4) {
         var menus = aj_menu.responseText;
         var pos = menus.indexOf("<hr>");
         if (pos!=-1) {
            document.getElementById("tabnav").innerHTML = menus.substring(0,pos);
            document.getElementById("menu_principal").innerHTML = menus.substring(pos+4);
            if (seccion!="" && document.getElementById(seccion)) document.getElementById(seccion).className = "current";
         }
      }
   }
   aj_menu.open("POST","/util/getMenus.php?rnd=" + Math.random(), true);
   aj_menu.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   aj_menu.send("id=0");
}

function CambiaFlecha(flecha, estado) {
   document.getElementById(flecha).src = '/images/flecha_down' + estado + '.gif';
}

function CambiaMenu() {
   if (document.getElementById) {
      var m = document.getElementById("menu_principal");
      var t = document.getElementById("tab_menu");
      var l = document.getElementById("liga_menu");
      var f = document.getElementById("flecha_menu");
      if (m.style.display!="block") {
         l.onmouseover = function() {};
         l.onmouseout = function() {};
         m.style.display = "block";
         t.className = "current";
         f.src = "/images/flecha_up.gif";
      } else {
         l.onmouseover = function() {CambiaFlecha('flecha_menu', '_hover');};
         l.onmouseout = function () {CambiaFlecha('flecha_menu', '');};
         m.style.display = "none";
         t.className = "ppal";
         f.src = "/images/flecha_down_hover.gif";
         l.blur();
      }
   }
}

function CambiaTab() {
   if (document.getElementById) {
      var m = document.getElementById("menu_enlaces");
      var t = document.getElementById("tab_enlaces");
      var f = document.getElementById("flecha_enlaces");
      if (m.style.display!="block") {
         t.onmouseover = function() {};
         t.onmouseout = function() {};
         m.style.display = "block";
         t.className = "tab_enlaces_up";
         f.src = "/images/flecha_up.gif";
      } else {
         t.onmouseover = function() {CambiaFlecha('flecha_enlaces', '_hover');};
         t.onmouseout = function () {CambiaFlecha('flecha_enlaces', '');};
         m.style.display = "none";
         t.className = "tab_enlaces";
         f.src = "/images/flecha_down_hover.gif";
         t.blur();
      }
   }
}

/* Clima */

function obtenerClima() {
   var aj_clima = new ajax();
   aj_clima.onreadystatechange = function() {
      if (aj_clima.readyState==4) {
         var text = aj_clima.responseText;
			text = text.replaceAll("\n","");
         text = text.trim();
			if (text!="") document.getElementById("clima").innerHTML = text;
	      else document.getElementById("clima").innerHTML = "Anuncios oficiales";
      }
   }
   aj_clima.open("POST","/util/clima.php?rnd=" + Math.random(), true);
   aj_clima.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   aj_clima.send("id=0");
}

/* Versión para imprimir, exportar a PDF o enviar por mail */

function get2post(action, target, query) {
   if (query=="") {
      var pos = action.indexOf('?');
      if (pos>=0) {
         query = action.substring(pos+1);
         action = action.substring(0,pos);
      }
   }
   query = query.replaceAll('?','');
   if (target=="") target = "_self";
   var name_ = "";
   var value_ = "";
   var f = document.createElement('form');
   f.setAttribute('method','post');
   f.setAttribute('action',action);
   f.setAttribute('target',target);
   var params = query.split('&');
   for (var i=0;i<params.length;i++) {
      var pos = params[i].indexOf('=');
      if (pos>=0) {
         name_ = params[i].substring(0,pos);
         value_ = params[i].substring(pos+1);
      } else {
         name_ = params[i];
         value_ = "";
      }
      var v = document.createElement('input');
      v.setAttribute('type','hidden');
      v.setAttribute('name',name_);
      v.setAttribute('value',value_);
      f.appendChild(v);
	}
   document.body.appendChild(f);
   f.submit();
}

function imprimir(version) {
   var cuerpo_ = document.getElementById("cuerpo");
   if (cuerpo_) {
      //Obtener los <link> y <style>
      var h = "";
      var s = "";
      var ln = document.getElementsByTagName("link");
      for (var i=0; i<ln.length; i++) {
         if (ln[i].getAttribute("rel")=="stylesheet") {
            var href_ = ln[i].getAttribute("href");
            var media = ln[i].getAttribute("media");
            if (!href_.startsWith("http") && !href_.startsWith("//") && media!="screen") h = h + "<link type=\"text/css\" rel=\"stylesheet\" href=\"" + href_ + "\">";
         }
      }
      var st = document.getElementsByTagName("style");
      if (st.length>0) {
         for (var i=0; i<st.length; i++) {
            s = s + st[i].innerHTML;
         }
         while (s.indexOf("  ")!=-1) s = s.replaceAll("  ", " "); 
         s = s.replaceAll("\n ", "");
         s = s.replaceAll("\n", "");
         h = h + "<style type=\"text/css\">" + s + "</style>";
      }
      //Obtener el cuerpo de la página
      var html_ = cuerpo_.innerHTML;
      html_ = h + html_;
      html_ = encodeURIComponent(html_);
      var ref = location.href;
      var pos = ref.indexOf("?");
      if (pos!=-1) ref = ref.substring(0,pos);
      //Obtener los <iframe>
      var ifs = cuerpo_.getElementsByTagName("iframe");
      var qs = "";
      for (var i=0; i<ifs.length; i++) {
         try {
            var x = ifs[i].contentWindow ? ifs[i].contentWindow.document : ifs[i].contentDocument;
            var y = x.documentElement || x.body;
            var if_ = y.getElementsByTagName("body")[0].innerHTML;
            if_ = encodeURIComponent(if_);
            qs = qs + "&if_[]=" + if_;
         } catch(err) {
            qs = qs + "&if_[]=";
         }
      }
      //Enviar el código resultante
      qs = "version=" + version + "&ref=" + ref + "&html_=" + html_ + qs;
      if (version=="pdf") get2post('/imprimir.php', '_self', qs);
      else {
         var v = popup("",version,750,550,"scrollbars=yes");
         get2post("/imprimir.php", version, qs);
      }
   }
}

/* Validaciones */

function emailValido(email, multiple) {
   if (multiple===undefined) multiple = false;
   var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
   var arr_emails;
   if (!multiple) arr_emails = new Array(email);
   else arr_emails = email.split(",");
   for (var i=0; i<arr_emails.length; i++) {
      var email = arr_emails[i].trim();
      if(!email.match(emailExp)) return false;
   }
   return true;
}

function checkDate(myDayStr, myMonthStr, myYearStr) {
   if (myYearStr.length!=4) return false;
   else if (!esEntero(myDayStr) || !esEntero(myMonthStr) || !esEntero(myYearStr)) return false;
   else {
      myMonthStr = myMonthStr - 1;
      var myDate = new Date();
      myDate.setFullYear(myYearStr, myMonthStr, myDayStr);
      if (myDate.getMonth()!=myMonthStr) return false;
      else return true;
   }
}

function esEntero(s) {
   var i = 0;
   var ban = true;
   for (i=0; i<s.length; i++) if (s.charCodeAt(i)<48 || s.charCodeAt(i)>57) ban = false;
   return ban;
}

function error(campo, mensaje) {
   var c = document.getElementById(campo);
   c.innerHTML = mensaje;
   c.style.display = "block";
   return false;
}

function _reset(campo) {
   var c = document.getElementById(campo);
   c.style.display = "none";
   c.innerHTML = "";
}

/* Cadenas */

String.prototype.endsWith = function(s){
	var reg = new RegExp(s + "$");
	return reg.test(this);
}

String.prototype.startsWith = function(s){
	var reg = new RegExp("^" + s);
	return reg.test(this);
}

String.prototype.replaceAll = function(from, to)  {
   var str = this;
   while(str.indexOf(from)>=0) {
      str = str.replace(from, to);
   }
   return str;
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function fechaLarga() {
   var semana = new Array("Domingo","Lunes","Martes","Mi&eacute;rcoles","Jueves","Viernes","S&aacute;bado");
   var meses = new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
   var fecha = new Date();
   var diames = fecha.getDate();
   var diasemana = fecha.getDay();
   var mes = fecha.getMonth();
   var anio = fecha.getFullYear();
   document.write(semana[diasemana] + " " + diames + " de " + meses[mes] + " de " + anio);
}

function dec(liga) {
	liga = liga.replaceAll("%20", " ");
	liga = liga.replaceAll("%28", "(");
	liga = liga.replaceAll("%29", ")");
	liga = liga.replaceAll("%E1", "á");
	liga = liga.replaceAll("%E9", "é");
	liga = liga.replaceAll("%ED", "í");
	liga = liga.replaceAll("%F3", "ó");
	liga = liga.replaceAll("%FA", "ú");
	liga = liga.replaceAll("%C1", "Á");
	liga = liga.replaceAll("%C9", "É");
	liga = liga.replaceAll("%CD", "Í");
	liga = liga.replaceAll("%D3", "Ó");
	liga = liga.replaceAll("%DA", "Ú");
	liga = liga.replaceAll("%F1", "ñ");
	liga = liga.replaceAll("%D1", "Ñ");
	liga = liga.replaceAll("%3A", ":");
	liga = liga.replaceAll("%2F", "/");
	liga = liga.replaceAll("%3F", "?");
	liga = liga.replaceAll("%3D", "=");
	liga = liga.replaceAll("%26", "&");
	return liga;
}

function enc(liga) {
	liga = liga.replaceAll(" ", "%20");
	liga = liga.replaceAll("(", "%28");
	liga = liga.replaceAll(")", "%29");
	liga = liga.replaceAll("á", "%E1");
	liga = liga.replaceAll("é", "%E9");
	liga = liga.replaceAll("í", "%ED");
	liga = liga.replaceAll("ó", "%F3");
	liga = liga.replaceAll("ú", "%FA");
	liga = liga.replaceAll("Á", "%C1");
	liga = liga.replaceAll("É", "%C9");
	liga = liga.replaceAll("Í", "%CD");
	liga = liga.replaceAll("Ó", "%D3");
	liga = liga.replaceAll("Ú", "%DA");
	liga = liga.replaceAll("ñ", "%F1");
	liga = liga.replaceAll("Ñ", "%D1");
	liga = liga.replaceAll(":", "%3A");
	liga = liga.replaceAll("/", "%2F");
	liga = liga.replaceAll("?", "%3F");
	liga = liga.replaceAll("=", "%3D");
	liga = liga.replaceAll("&", "%26");
	return liga;
}

/* Varios */

function extension(archivo) {
   var i = archivo.lastIndexOf(".");
   var ext = "";
   if (i>-1) ext = archivo.substring(i+1);
   ext = ext.toLowerCase();
   return ext;
}

function descargar(a) {
   if (!a.startsWith("/")) a = "/" + a;
   document.location = "/util/descargar.jsp?a=" + a;
}

function pdf(a,t) {
	window.open(a, "_blank");
	/*
   var pie = "<div class='fila_impar'><a href=\"" + a + "\" target=\"_blank\">Abrir con programa asociado</a>";
   if (a.toLowerCase().endsWith('.pdf')) pie += " | <a href=\"http://www.adobe.com/products/acrobat/readstep2.html\" target=\"_blank\" class=\"blank\">Descargar Adobe Reader</a>";
   pie += "</div>";
   if (!a.startsWith("http")) {
      if (!a.startsWith("/")) a = "/" + a;
      t = t + " | <a href=\"" + a + "\" onClick=\"descargar(this.pathname);return false;\">Descargar</a>";
      a = "http://www.yucatan.gob.mx" + a;
   }
   a = dec(a);
	a = a + "?rnd=" + Math.random();
   a = enc(a);
	a = "http://docs.google.com/viewer?url=" + a + "&embedded=true";
   p._titulo(t);
   p._popup("<iframe name='iframe_p' id='iframe_p' src='" + a + "' width='750' height='500' frameborder='0' scrolling='auto'></iframe>" + pie);
   p.objFrame = document.getElementById("iframe_p");
   p.show();
	*/
}

function imagen(i,t,w,h) {
   p._titulo(t);
	p._popup(unescape('%3Cimg src="'+i+'" alt="'+t+'" width="'+w+'" height="'+h+'"%3E'));
	p.show();
}

function comentarios(h) {
   c._iframe(h,660,650);
   c.show();
}

function serv_CambiaLinkregresar(cLink) {
   var l = document.getElementById("link_regresar");
	if (l && cLink!="") l.href=cLink;
   else document.getElementById("td_regresar").innerHTML = "";
}

function serv_NoLinkcerrar() {
   document.getElementById("td_cerrar").innerHTML = "";
}

function abrirEnOpener(liga) {
   window.onerror = function() {
      window.open(liga, "_blank");
      this.close();
   }
   window.opener.location = liga;
   this.close();
}

