/*  ### GENERALES ###  */

///	 Para colocar la hoja de estilos dependiendo del navegador.

if ((navigator.appName).indexOf("Microsoft")!=-1) 
	document.write('<link href="../css/globalIE.css" rel="stylesheet" type="text/css">');
else
	document.write('<link href="../css/global.css" rel="stylesheet" type="text/css">');

///	 Para evitar copiar y pegar texto.

function Seg()
{
	document.onselectstart = function() {return false;} // ie
	document.onmousedown = function() {return false;} // mozilla
}

/// Funciones para aumentar y disminuir el tamaño del texto.

var vOriginal= .80;
vIncremento = 0;
vTamano = 0;

function Aumentar() {
	vIncremento += .25;
	vTamano = vOriginal + vIncremento;
	document.getElementById("TEXTOBLOG").style.fontSize = vTamano + "em";
}
function Reducir() {
	vIncremento -= .25;
	vTamano = vOriginal + vIncremento;
	document.getElementById("TEXTOBLOG").style.fontSize = vTamano + "em";
}
function Restaurar() {
	document.getElementById("TEXTOBLOG").style.fontSize = vOriginal + "em";
	vTamano = 0;
	vIncremento = 0;
}

///	 Funciones para controlar el botón de vover.

var vNumPaginas = -1;

function retroceder() {  vNumPaginas --; }
function volver() { history.go(vNumPaginas); }

///	 Función para imprimir.

function AbreVentana(pDestino)
{
	var vCaracteristicas='scrollbars=2, resizable=no, width=400, height=400, top=50, left=50';
	var ventana = window.open("", "", vCaracteristicas);
	ventana.location = pDestino;
}

function AmpliarFoto(pFoto)
{
	var vCaracteristicas='scrollbars=0, width=400, height=400, top=50, left=50';
	var ventana = window.open("", "", vCaracteristicas);
		ventana.location = '../blogs/amp_foto.php?foto=' + pFoto;	
}

/*  ### FORMULARIOS ###  */

/// Función que sólo permite introducir números en un formulario.

function SoloNum()
{
	if ( event.keyCode >= 58 || event.keyCode <= 47)
		event.keyCode=0;
}

///	 Funciones de insercción de texto en los formularios.

function DepuraBuscador()
{
	if (document.formulario.pregunta.value.length == 0)
		return false;
	else
		return true;
}

function DepuraAcceso()
{
	if (document.acceso.fUsuario.value.length == 0)
	{
		document.acceso.fUsuario.style.backgroundColor = "#EFCBCB";
		return false;
	}
	if (document.acceso.fClave.value.length == 0)
	{
		document.acceso.fClave.style.backgroundColor = "#EFCBCB";
		return false;
	}

	return true;
}

///	 Funciones para controlar el número de caracteres de un textarea.

function ContarTexto(pCampo, pBarraContador, pLimiteCar, pLineas)
{
	//	Ancho del texto
	var vAnchoCampo =  parseInt(pCampo.style.width);
	var vContCar = pCampo.value.length;        
	//	Quitar el texto sobrante
	if (vContCar > pLimiteCar)
	{ 
		pCampo.value = pCampo.value.substring(0, pLimiteCar);
	}
	else
	{ 
		// progress bar percentage
		var vPorcentaje = parseInt(100 - ((pLimiteCar - vContCar) * 100)/pLimiteCar) ;
		document.getElementById(pBarraContador).style.width =  parseInt((vAnchoCampo*vPorcentaje)/100)+"px";
		// color correction on style from CCFFF -> CC0000
		PonerColor(document.getElementById(pBarraContador), vPorcentaje, "background-color");
	}
}

function PonerColor(obj, percentage, prop)
{
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}

/*  ### MISCELANOUS ###  */

///	 Función que muestra u oculta capas.

function Activar(pCapa)
{
	var vCapa = document.getElementById(pCapa);

	if (!vCapa) return true;

	if (vCapa.style.display == 'block')
		vCapa.style.display="none";
	else
		vCapa.style.display="block";

	return true;
}

///	 Función para escribir una dirección de correo sin SPAM

function PonerCorreo(pNombre, pDominio, pSufijo)
{
	document.write('<a href="' + 'mailto:' + pNombre + '@' + pDominio + '.' + pSufijo + '">' + pNombre + '@' + pDominio + '.' + pSufijo + '</a>');
}

///	 Scroll de la barra de estado

var data = "AVCRKIFLST";
var done = 1;

function statusIn(text)
{
	decrypt(text, 2, 20);
}

function decrypt(text, max, delay)
{
	if (done)
	{
		done = 0;
		decrypt_helper(text, max, delay,  0, max);
   }
}

function decrypt_helper(text, runs_left, delay, charvar, max)
{
	if (!done)
	{
		runs_left = runs_left - 1;
		var status = text.substring(0, charvar);
		for (var current_char = charvar; current_char < text.length; current_char++)
		{
			status += data.charAt(Math.round(Math.random()*data.length));
		}
		
		window.status = status;
		var rerun = "decrypt_helper('" + text + "'," + runs_left + "," + delay + "," + charvar + "," + max + ");"
		var new_char = charvar + 1;
		var next_char = "decrypt_helper('" + text + "'," + max + "," + delay + "," + new_char + "," + max + ");"
		if(runs_left > 0)
		{
			setTimeout(rerun, delay);
		}
		else
		{
			if (charvar < text.length)
			{
				setTimeout(next_char, Math.round(delay*(charvar+3)/(charvar+1)));
			}
			else
			{
				done = 1;
	         }
		}
	}
}
