// Funciones globales sitio

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function abrirVentana2(direccion,alto,ancho)
{
	MSGWindow = window.open(direccion,'newWin','scrollbars=yes ,status=no,width='+ancho+',height='+alto+',toolbar=no,menubar=no');
	MSGWindow.focus();
}


function abrirVentanaLanzadera(direccion)
{
	nombre = "new_" + aleatorio();
	MSGWindow = window.open(direccion,nombre);
	nombre.focus();
}

function aleatorio()
{ 
    numPosibilidades = 1000; 
    aleat = Math.random() * numPosibilidades; 
    aleat = Math.round(aleat); 
    return aleat; 
} 

function abrirVentanaLibre(direccion)
{
	MSGWindow = window.open(direccion,'newWin');
	newWin.focus();
}

function abrirVentanaNew(direccion)
{
	nombre = "new_" + aleatorio();
	MSGWindow = window.open(direccion,nombre);
	nombre.focus();
}

function abrirVentanaEnvio(direccion)
{
	MSGWindow = window.open(direccion,'newWin','scrollbars=yes ,status=no,width=500,height=450,toolbar=no,menubar=no');
	MSGWindow.focus();
}

function mostrar_contenido()
{
	valor = document.listado_menu.listado.value;
	
	aParametro = valor.split("::");

	//$iContenido::$sTipoCont::$sUrlCont::$sTarget::$iAlto::$iAncho
	
	if (aParametro[1] == 1) //pagina web
		atDesplegarContenido('tp_modulos/tpm_seccion/tpm_contenido.php', aParametro[0]);

	if (aParametro[1] == 2) //url
	{
		if (aParametro[3] == 1)
			document.location.href = aParametro[2];
		else
			window.open(aParametro[2]);
	}

	if (aParametro[1] == 3) //pagina flotante c/contenido
		javascript:abrirVentana('tp_modulos/tpm_seccion/contVentana.php?cc='+aParametro[0],aParametro[4],aParametro[5]);

	if (aParametro[1] == 4) //pagina flotante c/url
		abrirVentana(aParametro[0],aParametro[4],aParametro[5]);
}

function diccionario(OPC)
{
    var texto;
    var tema;
    switch(OPC)
    {
        case "ESP":
            texto="Diccionario de la Real Academia Española. Vigésima segunda edición. Teclee la palabra que desea consultar:"
            tema=window.prompt(texto,"")
            if (tema!=null)
            {
                window.open("http://buscon.rae.es/draeI/SrvltGUIBusUsual?TIPO_HTML=2&LEMA="  + tema,"win")
            }
            break;
        case "ENG":
            texto="Traducción de Inglés a Español. Ingrese la palabra o texto que desea traducir:"
            tema=window.prompt(texto,"")
            if (tema!=null)
            {
				//alert(document.form1.innerHTML);
				//document.form1.innerHTML = "<INPUT type=hidden name=lp><INPUT type=hidden name=trtext>"
                document.form1.action="http://babelfish.altavista.com/tr"
                document.form1.lp.value="en_es"
                document.form1.trtext.value=tema
                document.form1.target="_blank"
                document.form1.submit()
            }
            break;
    }
}

// Elimina espacios al principio y al final del texto
function EliminarEspacios(sTexto)
{
	var sResultado = "";

	sResultado = sTexto.replace(/^\s*/, "");
	sResultado = sResultado.replace(/\s*$/, "");
	
	return sResultado;
}

function gObtenerCookie(name)
{ 
	var cname=name + "="; 
	var dc=document.cookie;
	
	if(dc.length>0)
	{ 
		begin=dc.indexOf(cname); 
		if(begin!=-1)
		{ 
			begin+=cname.length; 
			end=dc.indexOf(";",begin); 
			if(end==-1) 
				end=dc.length;

			return(unescape(dc.substring(begin,end)).replace(/\+/g, " ")); 
		} 
	}
	return("");
}

function AbrirVentanaPopup(sURL, sNombreVtna, nAncho, nAlto)
{
        ventana = window.open(sURL, sNombreVtna,'resizable=yes,scrollbars=no,menubar=no,status=no,width=' + nAncho + ',height=' + nAlto);
		/*scrollbars=no,status=no,width=300,height=300,menubar=no*/
        ventana.focus();
}

// script para aumentar/disminuir tamaño de letra
	var max_size = 120;
	var min_size = 60;
	var tamagnoLetras = 80;
	
	function dzIncreaseFontSize(idElemento) {
		if (document.all || document.getElementById) {	
			var elemento = document.all ? document.all[idElemento] : document.getElementById(idElemento);

			if (elemento) 
				{	
				// el valor est&aacute; indicado en porcentaje:
				if(tamagnoLetras >= max_size){
					alert("No es posible aumentar mas el texto")
				}else{
					tamagnoLetras += 10;
					if (elemento.length) 
						for (i=0; i<elemento.length; i++) {
							elemento[i].style.fontSize = (tamagnoLetras+'%');
							}
					else
						elemento.style.fontSize = (tamagnoLetras+'%');				
				}
			}
		}
	}
	
	function dzDecreaseFontSize(idElemento) {
		if (document.all || document.getElementById) {	
			var elemento = document.all ? document.all[idElemento] : document.getElementById(idElemento);
			if (elemento) {	
				// el valor est&aacute; indicado en porcentaje:
				if(tamagnoLetras <= min_size){
					alert("No se puede disminuir mas el texto")
				}else{
					tamagnoLetras -= 10;
					if (elemento.length) 
						for (i=0; i<elemento.length; i++) {
							elemento[i].style.fontSize = (tamagnoLetras+'%');
						}
					else
						elemento.style.fontSize = (tamagnoLetras+'%');				
				}
			}
		}
	}
	

	function dzResetFontSize(idElemento) {
		var elemento = document.all[idElemento];
		elemento.body.style.fontSize = '100%';
	}

//valida solo numeros	
function validar2(e)
{ 
    tecla = (document.all) ? e.keyCode : e.which;

    if (tecla==8) 
		return true;

    patron = /\d/;
    te = String.fromCharCode(tecla);

    return patron.test(te);
} 

//valida letras y numeros
function validar1(e)
{ 
    tecla = (document.all) ? e.keyCode : e.which;

    if (tecla==8) 
		return true;

    patron =/[A-Za-zÑñ\d]/;
    te = String.fromCharCode(tecla);

    return patron.test(te);
}


/////////// movido a la plantilla del portal
// Inicialización google analytics
//var pageTracker = _gat._getTracker("UA-6616919-1");
//pageTracker._initData();
/////////////////////////////////////////////


function ShowHide(id) {
    if(document.getElementById(id).className != "oculta"){
        document.getElementById(id).className = "oculta";
    } else {
        document.getElementById(id).className = "muestra";
    }
}

function validarFormComen(form, tm)
{

	if (form.nombre_come.value == "" || form.email_come.value == "" || form.comentario_come.value == "")
	{
		alert("Debe ingresar todos los campos");
		return false;
	}
	else
	{
		if (tm == 2)
			form.action = "tp_modulos/tpm_seccion/envio_come.php";
		if (tm == 3)
			form.action = "tp_modulos/tpm_noticias/envio_come.php";

		form.submit();
	}
}

function validarFormEmail(email)
{
	var exprEmail = /^[\w\.-]{2,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]+$/;
			  
	if (!exprEmail.test(email))
	{
		alert("El Correo Electrónico es incorrecto");
		document.form_comentario.email_come.focus();
		return false;
	}
	else
		return true;
}


/* Inicio + y - letra */

ns4 = document.layers;
ie = document.all;
moz = document.getElementById && !document.all;
	 
function changeFontSize(id, isIncrease)
{

var obj;
var size; 

if (ns4) 
	return false;

if (ie) 
{ 
	if (document.all || document.getElementById) 	
	{
		var obj = document.all ? document.all[id] : document.getElementById(id);
		
		if (obj)
		{
			if (obj.length) 
			{
				if (isIncrease)
				{
					for (i=0; i<obj.length; i++) 
					{
						size = parseFloat(obj[i].currentStyle.fontSize) + 1;
						obj[i].style.fontSize = size + "px";
					}
				}
				else
				{
					for (i=0; i<obj.length; i++) 
					{
						if (obj[i].currentStyle.fontSize == '0px')
						{
							alert("No se puede disminuir mas el texto");
							return false; 
						}
						else
						{
							size = parseFloat(obj[i].currentStyle.fontSize) - 1;
							obj[i].style.fontSize = size + "px";
						}
					}
				}
			}
			else
			{
				if (isIncrease) 
				{
						size = parseFloat(obj.currentStyle.fontSize) + 1;
						obj.style.fontSize = size + "px";

				}
				else
				{
					if (obj.currentStyle.fontSize == '0px')
					{
						alert("No se puede disminuir mas el texto");
						return false; 
					}
					else
					{
						size = parseFloat(obj.currentStyle.fontSize) - 1;
						obj.style.fontSize = size + "px";
					}
				}
			}
		}
	}
}
else if (moz)
{
	obj = window.getComputedStyle(document.getElementById(id), ""); 
	size = obj.getPropertyValue('font-size');  // value only in px

	if (isIncrease)
	{
		size = parseFloat(size) + 1; // increase 
	} 
	else
	{
		size = parseFloat(size) - 1; // decrease
	}

	document.getElementById(id).style['fontSize'] = size + "px";
}
   
return true;

}

// Tags a las cuales se les va a aplicar el script: 
var tgs = new Array( 'div', 'span', 'a'); 

// Intervalos de las fuentes, en este caso de menor-mayor: 
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' ); 
var szs2 = new Array( '9','10','11','12','13','14','15' ); 
//var startSz = obtSize('contenido_noticia'); 

function ts( trgt,inc ) 
{ 
	var obj;
	var size; 
	var sVal;

	//var startSz = obtSize(trgt);

	var tamanoSize;

	if (ie) 
	{ 
		if (document.all || document.getElementById) 	
		{
			var obj = document.all ? document.all[trgt] : document.getElementById(trgt);
			tamanoSize = parseFloat(obj.currentStyle.fontSize);
		}
	}
	else if (moz)
	{
		obj = window.getComputedStyle(document.getElementById(trgt), ""); 
		tamanoSize = obj.getPropertyValue('font-size');  
		tamanoSize = tamanoSize.substring(0, tamanoSize.length-2);
	}

	if (tamanoSize <= 15)
	{
		if (inc)
		{
			tamanoSize++;
			size = parseFloat(tamanoSize);
		}
		else
		{
			tamanoSize--;
			size = parseFloat(tamanoSize);
		}

		sVal = posArray(tamanoSize);
				
		if (!document.getElementById) return 
		var d = document,cEl = null,sz = sVal,i,j,cTags; 

		if (sVal >= 0 || sVal <= 6)
		{
			if ( !( cEl = d.getElementById( trgt ) ) ) 
				cEl = d.getElementsByTagName( trgt )[ 0 ]; 

			cEl.style.fontSize = szs[ sVal ]; 

			for ( i = 0 ; i < tgs.length ; i++ ) 
			{ 
				cTags = cEl.getElementsByTagName( tgs[ i ] ); 
				
				for ( j = 0 ; j < cTags.length ; j++ ) 
				{
					cTags[ j ].style.fontSize = szs[ sVal ]; 
				}
			} 
			
			if (ie)
				obj.style.fontSize = size + "px";
			else if (moz)
				document.getElementById(trgt).style['fontSize'] = size + "px";
		}
	}
}  

function posArray(val)
{
	var sEncontrado;

	for ( i = 0 ; i < szs2.length ; i++ ) 
	{
		if (szs2[i] == val)
		{
			sEncontrado = i;
		}
	}
	
	return sEncontrado;
}



