var conexion;

function crearXMLHttpRequest() {
   var xmlHttp = null;
   if (window.ActiveXObject) xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) xmlHttp = new XMLHttpRequest();
   return xmlHttp;
}

if (document.styleSheets) {
   var hoja = document.styleSheets[0];
   var plantilla = document.styleSheets[1];
   var original = 11;
   var titulo = 4;
   var titulo_adicional = 4;
   var subtitulo = 1;
   var pie = -2;
   var actual = original;
   var actual_ = original;
   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;
}

function zoom(accion) {
   if (!document.styleSheets || hoja==null || plantilla==null) return;
   if (accion=="") {
      actual = original;
      actual_ = original;
   } else if (accion=="+") {
      if (actual_<original+2 && actual_==actual) actual_++;
      actual++;
   } else if (accion=="-") {
      if (actual_>original-2 && actual_==actual) actual_--;
      actual--;
   }
   for (i=0; estilo=hoja[i]; i++) {
      var nombre = estilo.selectorText.toLowerCase();
      if (nombre==".titulo") estilo.style.fontSize = (actual+titulo) + "px";
      else if (nombre==".titulo_adicional") estilo.style.fontSize = (actual+titulo_adicional) + "px";
      else if (nombre==".subtitulo") estilo.style.fontSize = (actual+subtitulo) + "px";
      else estilo.style.fontSize = actual + "px";
   }
   for (i=0; estilo=plantilla[i]; i++) {
      var nombre = estilo.selectorText.toLowerCase();
      if (nombre==".title"
       || nombre==".parent"
       || nombre==".numero") estilo.style.fontSize = actual + "px";
      else if (nombre.startsWith(".pie")) estilo.style.fontSize = (actual_+pie) + "px";
      else if (nombre==".encabezado_negro"
            || nombre.startsWith(".texto_plantilla")
            || nombre.startsWith(".menu_sup")
            || nombre.indexOf("navmenu")!=-1) estilo.style.fontSize = actual_ + "px";
   }

}

function getMenus() {
   conexion = crearXMLHttpRequest();
   conexion.onreadystatechange = doMenus;
   conexion.open("POST","/getMenus.php", true);
   conexion.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   conexion.send("id=0");
}

function doMenus() {
   if (conexion.readyState==4) {
      document.getElementById("menu_principal").innerHTML = conexion.responseText;
   }
}

function MM_openBrWindow(theURL,winName,features) {
   window.open(theURL,winName,features);
}

function promptCtrl(ctrl, str) {
   alert(str);
   ctrl.focus();
   return false;
}

function formatear_cadena(texto) {
	while (texto.indexOf("\"")!=-1) texto = texto.replaceAll("\"", "");
	while (texto.indexOf("'")!=-1) texto = texto.replaceAll("'", "");
	while (texto.indexOf("“")!=-1) texto = texto.replaceAll("“", "");
	while (texto.indexOf("”")!=-1) texto = texto.replaceAll("”", "");
	while (texto.indexOf("`")!=-1) texto = texto.replaceAll("`", "");
	while (texto.indexOf("´")!=-1) texto = texto.replaceAll("´", "");
	while (texto.indexOf("‘")!=-1) texto = texto.replaceAll("‘", "");
	while (texto.indexOf("’")!=-1) texto = texto.replaceAll("’", "");
	return texto;
}

function comentarios(mailto) {
   //var url = document.location;
   //var titulo = document.title;
   mailto = mailto.toLowerCase();
   if (mailto.indexOf("@")==-1) mailto = mailto + "@yucatan.gob.mx";
   if (mailto.endsWith("@yucatan.gob.mx")) {
      //...?mailto=" + mailto + "&titulo=" + titulo + "&url=" + url + "\" onClick...
      document.write("<a href=\"/independientes/comentarios.jsp?mailto=" + mailto + "\" onClick=\"popup(this.href, 'comentarios', 630, 460, 'statusbar=yes,status=yes,scrollbars=yes'); return false;\" onMouseover=\"window.status='" + mailto + "';return true;\" onMouseout=\"window.status='';\" class=\"texto_plantilla\">" + mailto + "</a>");
   }
}

function Launch(page) { 
   OpenWin = this.open(page, "centered", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,status=yes,width=660,height=560"); 
}

function serv_CambiaLinkregresar(cLink)
{
	if (cLink!="") {
		document.getElementById("link_regresar").innerHTML="&nbsp;REGRESAR&nbsp;";
		document.getElementById("link_regresar").href=cLink;
		document.getElementById("link_regresar").className="menu_sup_popup";
	} else {
		document.getElementById("link_regresar").innerHTML="";
		document.getElementById("link_regresar").href="javascript:void(0);";
		document.getElementById("link_regresar").className="menu_sup";
	}
}

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 getParameter(key) {
	var value = null;
	for (var i=0;i<getParameter.keys.length;i++)
	{
		if (getParameter.keys[i]==key)
		{
			value = getParameter.values[i];
			if (value==null) value = "";
			break;
		}
	}
	return value;
}
getParameter.keys = new Array();
getParameter.values = new Array();

function QueryString_Parse() {
	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos>=0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			getParameter.keys[getParameter.keys.length] = argname;
			getParameter.values[getParameter.values.length] = value;
		}
	}
}
QueryString_Parse();

function decode(param) {
   param = unescape(param);
   param = param.replaceAll("+", " ");
   if (param=="null" || param==null) param = "";
   return param;
}
