//
//Js ML by Marioly Garza
//
var yaEnviar = false;
function get_xmlhttp() {
try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}
return xmlhttp
}

function recibir(xmlhttp, status1, status2, text) {
  if(status2 != false)
  {
    document.getElementById(status2).innerHTML=text;
  }
 
  document.getElementById(status1).innerHTML=xmlhttp.responseText
}

function Env(xmlhttp, url, string, status1, status2, text)
{
 xmlhttp.open('POST', url, true);
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
   recibir(xmlhttp, status1, status2, text)
  }
 }
  xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  xmlhttp.send(string) 
}

function comprobar(mode, registro) {
    var xmlhttpC=get_xmlhttp();
    var nick = document.getElementById('nickR').value;
    var email = document.getElementById('email').value;
    var check = mode;
    var contrasena = document.getElementById('contrasenaR').value;
	var recontrasena = document.getElementById('recontrasena').value;
    var website = document.getElementById('website').value;
	var sexo  = document.getElementById('sexo').value;
    var descripcion = document.getElementById('descripcion').value;
    var firma = document.getElementById('firma').value;
	var template = document.getElementById('template').value;
    var email_publico = document.getElementById('email_publico').value;	var masurl = '';
	
	var masurl = '';
	
	if(registro != true)
	{
       var pascontrasena = document.getElementById('pascontrasena').value;

	   masurl = "&pascontrasena="+encodeURIComponent(pascontrasena);
	}
	else
	{
	   var code = document.getElementById('code').value;
	   
	   masurl = "&code="+encodeURIComponent(code);
	}
	
	var mode_url = (registro != true) ? 'editar' : 'registrar';

    mode = (mode == 1) ? 'status' : 'statusr';
    Env(xmlhttpC, "modulos.php?ml=perfil&mode="+mode_url, "nick="+encodeURIComponent(nick)+"&email="+encodeURIComponent(email)+"&check="+check+"&contrasena="+encodeURIComponent(contrasena)+"&recontrasena="+encodeURIComponent(recontrasena)+"&website="+encodeURIComponent(website)+"&descripcion="+encodeURIComponent(descripcion)+"&firma="+encodeURIComponent(firma)+"&sexo="+sexo+"&template="+template+"&email_publico="+email_publico+masurl, mode, false, false)
    Fat.fade_element(mode, null, null, '#FFFF33')
}

function login() {
    var xmlhttpL = get_xmlhttp();
    var nick = document.getElementById('nick').value;
    var contrasena = document.getElementById('contrasena').value;
    var login = 'Login';
    Env(xmlhttpL, 'login.php', "nick="+encodeURIComponent(nick)+"&contrasena="+encodeURIComponent(contrasena)+"&login="+login, 'login', false, false)
}

function com() {
    var xmlhttpCom=get_xmlhttp();
    var n = document.getElementById('n').value;
	var nick = document.getElementById('nick_com').value;
    var comentario = document.getElementById('comentario').value;
	document.getElementById("statuscom").innerHTML='Status: Enviando...';
    Env(xmlhttpCom, "modulos.php?ml=Noticias", "n="+n+"&nick="+encodeURIComponent(nick)+"&comentario="+encodeURIComponent(comentario), 'coment', 'statuscom', 'Status: Comentario Enviado')
    document.getElementById('comentario').value='';
	Fat.fade_element('statuscom', null, null, '#FFFF33')
}

function modulo(url) {
 yaEnviar = false;
 var xmlhttpM=get_xmlhttp();
 xmlhttpM.open('GET', "modulos.php?ml="+url, true);
 xmlhttpM.onreadystatechange=function() {
  if (xmlhttpM.readyState==4) {
   recibir(xmlhttpM, 'modulos', false, false)
  }
 }
   xmlhttpM.send(null)
}

function Mens(preview) {
    var xmlhttpNot = get_xmlhttp();
    var titulo = document.getElementById('titulo').value;
    var mensaje = document.getElementById('mensaje').value;
    var categoria = document.getElementById('categoria').value;
    var validacion = document.getElementById('validacion').value;
    var editar = document.getElementById('editar').value;
    Env(xmlhttpNot, "modulos.php?ml=EnviarMensajes", "titulo="+encodeURIComponent(titulo)+"&mensaje="+encodeURIComponent(mensaje)+"&categoria="+categoria+"&validacion="+validacion+"&editar="+editar+"&preview="+preview, 'mens', false, false)
    Fat.fade_element('status_post', null, null, '#FFFF33')

}

function seguridad() { 
   var  filteralp=/[a-zA-Z]+/;
   var  filternum=/\d+/;
   var  filtercar=/\W+/;
   var  contrasena = document.getElementById('contrasenaR').value;
   var  baja = document.getElementById("baja");
   var  media = document.getElementById("media");
   var  alta = document.getElementById("alta");
      
   longitud = contrasena.length;
   if(longitud > 5 && filteralp.test(contrasena) && filternum.test(contrasena) && filtercar.test(contrasena))
   {
      baja.className = "alta";
	  media.className = "alta";
	  alta.className = "alta";
   }
   else if(longitud > 5 && filteralp.test(contrasena) && filternum.test(contrasena) || longitud > 6 && filteralp.test(contrasena) && filtercar.test(contrasena) || longitud > 6 && filternum.test(contrasena) && filtercar.test(contrasena))
   {
      baja.className = "media"
	  media.className = "media"
	  alta.className = "des"
   }
   else if(longitud > 5)
   {
      baja.className = "baja";
	  media.className = "des";
	  alta.className = "des";
   }
   else
   {
      baja.className = "des";
	  media.className = "des";
	  alta.className = "des";
   }
   
}


function desc(capa) {
    var targetElement = document.getElementById(capa);
    var element_img = document.getElementById(capa+"_img");
    var element_img2 = document.getElementById(capa+"_img2");
	
     if (targetElement.style.display == "none") 
     {
	   targetElement.style.display = "";
	  
	   if(element_img)
	     element_img.src = './images/ba-up.gif';
       else if(element_img2)
         element_img2.src = './images/f1.gif';
	  }
     else
	 {
       targetElement.style.display = "none";

	   if(element_img)
	      element_img.src = './images/ra-down.gif';
	   else if(element_img2)
		  element_img2.src = './images/f2.gif';
	 }
}

function check() {
    var nick = document.getElementById('nickR').value;
    var email = document.getElementById('email').value;
	var contrasena = document.getElementById('contrasenaR').value;
	var recontrasena = document.getElementById('recontrasena').value;

     if(nick.length > 2 && email.length > 5 && contrasena != '' && contrasena == recontrasena)
	 {
      document.getElementById('reg').disabled = '';
	 }
	 else
	 {
	  document.getElementById('reg').disabled = 'disabled';
	 }
	   if(contrasena != '' && contrasena == recontrasena)
       document.getElementById("coinciden").innerHTML='Correcto Coinciden ';
       else
	   document.getElementById("coinciden").innerHTML='Reescriba la contrasena:';
}

function checkc() {
    var comentario = document.getElementById('comentario').value;
	
     if(comentario.length > 5)
	 {
      document.getElementById('env').disabled = '';
	 }
	 else
	 {
	  document.getElementById('env').disabled = 'disabled';
	 }
}
	
	var EstaEditando = false;
	
function EditarCampo(texto) {
		if(EstaEditando)return false;
		EstaEditando = true;
		var texto = document.getElementById("texto");
		document.getElementById("statusabout").innerHTML='Editando.';
		texto.innerHTML = "<textarea cols=\"100\" rows=\"10\" onblur=\"return Guardar(this)\" />" + texto.innerHTML + "</textarea>";
		texto.firstChild.focus();
}
		
function Guardar(subcampo) {
		var ajax = get_xmlhttp();
		if(!ajax){
			alert("Imposible Editar el Campo");
			return false;
		}
		document.getElementById("statusabout").innerHTML='Guardando...';

		ajax.open("POST","modulos.php?ml=About",true);
		ajax.onreadystatechange = function() {
				if (ajax.readyState == 4) {
					campo = document.getElementById("texto");
					campo.innerHTML = subcampo.value;
					EstaEditando = false;
				}
			}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("texto="+encodeURIComponent(subcampo.value));
		document.getElementById("statusabout").innerHTML='Editado con exito!.';
        Fat.fade_element('statusabout', null, null, '#FFFF33')
}
		
function contacto() {
    var xmlhttpCon = get_xmlhttp();
    var nombre = document.getElementById('nombre').value;
    var email = document.getElementById('email').value;
    var mensaje = document.getElementById('mensaje').value;
	
  document.getElementById("contactstatus2").innerHTML='Status: Enviando...';

  Env(xmlhttpCon, "modulos.php?ml=Contacto", "nombre="+nombre+"&email="+email+"&mensaje="+encodeURIComponent(mensaje), 'contactstatus', 'contactstatus2', 'Status: Mensaje Enviado.')
  Fat.fade_element('contactstatus2', null, null, '#FFFF33')
}

function checkcontacto() {
    var nombre = document.getElementById('nombre').value;
    var email = document.getElementById('email').value;
    var mensaje = document.getElementById('mensaje').value;
	
     if(nombre.length > 2 && email.length > 5 && mensaje.length > 5)
	 {
      document.getElementById('env').disabled = '';
	 }
	 else
	 {
	  document.getElementById('env').disabled = 'disabled';
	 }
}

function users_online() {
  var xmlhttpU = get_xmlhttp();
  xmlhttpU.open('GET', "modulos.php?users_online=true", true);
  xmlhttpU.onreadystatechange=function() {
  if(xmlhttpU.readyState==4) {
   try {  
    recibir(xmlhttpU, "users_online", false, false)
   }
   catch ( e )
   {}
  }
 }
   xmlhttpU.send(null)
}

function preparPost() {
		if(yaEnviar == true)
		{
           var nombre = document.getElementById('nombre').value;
           var mensaje = document.getElementById('mensaje').value;
           xmlhttpLib=get_xmlhttp();
		   Env(xmlhttpLib, "modulos.php?ml=Libro", "nombre="+encodeURIComponent(nombre)+"&mensaje="+encodeURIComponent(mensaje), 'libro', false, false);
		}
		else
		{
		yaEnviar = true;
		var formLibro = document.getElementById("formLibro");
		formLibro.innerHTML = "Firma aki: <br /><input type=\"text\" id=\"nombre\" value=\"Nombre\" onclick=\"limpiar('nombre');\" class=\"libro_post\"> <br /><textarea  id=\"mensaje\" onclick=\"limpiar('mensaje');\" class=\"libro_post\" cols=\"100\" rows=\"5\" />Mensaje (para guardar tambien)</textarea>";
		}
}


// Begin js Poll


		
function poll() {
    var xmlhttpCon = get_xmlhttp();
    var cms_name = document.getElementById('cms_name').value;
	var cms_plugins = document.getElementById('cms_plugins').value;
    var cms_modules = document.getElementById('cms_modules').value;
    var cms_sug = document.getElementById('cms_sug').value;
    var cms_yourname = document.getElementById('cms_yourname').value;
    var cms_youremail = document.getElementById('cms_youremail').value;

    Env(xmlhttpCon, "modulos.php?ml=Poll", "cms_name="+encodeURIComponent(cms_name)+
										   "&cms_plugins="+encodeURIComponent(cms_plugins)+
										   "&cms_modules="+encodeURIComponent(cms_modules)+
										   "&cms_sug="+encodeURIComponent(cms_sug)+
										   "&cms_yourname="+encodeURIComponent(cms_yourname)+
										   "&cms_youremail="+encodeURIComponent(cms_youremail), 'modulos', false, false)
}


/*Nicolas Zulawski
Creación : 14/10/2005
Funciones necesarias para realizar el efecto de desaparicion de los nuevos mensajes*/

var animationIsRunning = 0;

function divAnimation(origen, destino, rate, endfunc){

// Si no existe messengerOut la creo 
if (!document.getElementById('messengerOut')){
var messengerOut = document.createElement('div');
messengerOut.id = 'messengerOut';
document.body.appendChild(messengerOut);
}
else{
// Sino la muevo y la uso 
if(animationIsRunning == 1){
document.getElementById(origen).style.display = 'none';
eval(endfunc);
return;
}
else{
document.getElementById('messengerOut').style.display = 'block';
}
}
animationIsRunning = 1;
posOrigen = getPos(origen);
posDestino = getPos(destino);
variacion = getVar(posOrigen,posDestino,rate);

posAux = posOrigen;

setPos('messengerOut',posAux);

moveDiv ('messengerOut',posAux,variacion,rate,origen,endfunc);

poll();

}

function findPosX(obj)
{
var curleft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
}
else if (obj.x)
curleft += obj.x;
return curleft;
}

function findPosY(obj)
{
var curtop = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curtop += obj.offsetTop
obj = obj.offsetParent;
}
}
else if (obj.y)
curtop += obj.y;
return curtop;
}

function moveDiv(messengerOut,posAux,variacion,rate,origen,endfunc){
setPos (messengerOut,posAux);
for (i=0 ; i<4 ; i ++)
posAux[i] = posAux[i] + variacion[i];
rate --;
if (rate >= 0){
 window.setTimeout("moveDiv('messengerOut',posAux,variacion,"+ rate +",'"+origen+"','"+ endfunc+"');", 1);
}
else{
document.getElementById('messengerOut').style.display = 'none';
document.getElementById(origen).style.display = 'none';
animationIsRunning = 0;
eval(endfunc);
}
}

function getVar(posOrigen,posDestino,rate){

ret = new Array;
for (i=0 ; i<4 ; i ++){
ret[i] = (posDestino[i] - posOrigen[i])/rate;
// if (navigator.appName=="Microsoft Internet Explorer" && i == 1)
// ret[i] = (posDestino[i] - posOrigen[i] - ((posOrigen[3] - posDestino[3])/2))/rate;
}
return ret;
}

function setPos(div,pos){
/*
Array de posicion 
0 = top
1 = left
2 = height
3 = width
*/
ret = new Array;

document.getElementById(div).style.height = parseInt(pos[2]) + 'px'; 
document.getElementById(div).style.width = parseInt(pos[3]) + 'px'; 
document.getElementById(div).style.top = parseInt(pos[0]) + 'px' ; 
document.getElementById(div).style.left = parseInt(pos[1]) + 'px'; 

return ret;
}

function getPos(div){
/*
Array de posicion 
0 = top
1 = left
2 = height
3 = width
*/
ret = new Array;
ret[0] = findPosY(document.getElementById(div));
ret[1] = findPosX(document.getElementById(div));
ret[2] = document.getElementById(div).offsetHeight;
ret[3] = document.getElementById(div).offsetWidth;

return ret;
}

// End Poll


function footer(element, value) {
      element.src = "templates/ml/images/" + (value ? "h_" : "") + element.id + ".gif";
}
												
function borrarCom(not, com) {
	     var  name=confirm('Estas seguro de borrar el comentario numero '+com+'?')
		  if(name != true)
		  {
			  return;
		  }
	
  xmlhttpBc=get_xmlhttp()
  Env(xmlhttpBc, "modulos.php?ml=Noticias&n="+not, "borrarcom="+com, 'modulos', false, false)
}
						
function borrarN(not) {
	     var  name=confirm('Estas seguro de borrar el mensaje numero '+not+' y sus comentarios?')
		  if(name != true)
		  {
			  return;
		  }
  xmlhttpBn=get_xmlhttp()
  Env(xmlhttpBn, "modulos.php?ml=Noticias", "borrarn="+not, 'modulos', false, false)
}

function limpiar(campo) {
	      var campov = document.getElementById(campo).value;
		  if(campov == 'Nombre' || campov == 'Mensaje (para guardar tambien)')
		  {
			   document.getElementById(campo).value = '';
			   document.getElementById(campo).focus();
		  }
}

function Mps(preview) {
    var xmlhttpMp = get_xmlhttp();
    var titulo = document.getElementById('titulo').value;
    var mensaje = document.getElementById('mensaje').value;
    var destinatario = document.getElementById('destinatario').value;
    var editar = document.getElementById('editar').value;
    var status_mp = document.getElementById('status_mp');

    Env(xmlhttpMp, "modulos.php?ml=mps&mode=escribir", "destinatario="+destinatario+"&titulo="+encodeURIComponent(titulo)+"&mensaje="+encodeURIComponent(mensaje)+"&editar="+editar+"&preview="+preview, 'mps', false, false)

    Fat.fade_element('status_mp', null, null, '#FFFF33')
	
}

var checkeds = false;
function select_switch() {
	    checkeds = !checkeds;
		for (i = 0; i < document.privf.length; i++)
		{
			document.privf.elements[i].checked = checkeds;
		}
}

function carita(text, id) {
        document.getElementById(id).value+=" "+ text;
        document.getElementById(id).focus();
}

function buscar_entrada() {
    var xmlhttpBue = get_xmlhttp();
    var buscar_entrada = document.getElementById('buscar_entrada').value;
	if(buscar_entrada != '')
    Env(xmlhttpBue, "modulos.php?ml=mensajes&buscar="+buscar_entrada, "", 'modulos', false, false)
}

function categorias_main() {
    var xmlhttpCM = get_xmlhttp();
    var categorias_main = document.getElementById('categorias_main').value;
	if(categorias_main != '')
      Env(xmlhttpCM, "modulos.php?ml=mensajes&cAt="+categorias_main, "", 'modulos', false, false)
}

// bbCode control by
// subBlue design
// www.subBlue.com

// Startup variables
var imageTag = false;
var theSelection = false;

// Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version

var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
                && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;

var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);

// Helpline messages
b_help = "Negrita: [b]texto[/b]  (alt+b)";
i_help = "Cursiva: [i]texto[/i]  (alt+i)";
u_help = "Subrayado: [u]texto[/u]  (alt+u)";
q_help = "Cita: [quote]texto[/quote]  (alt+q)";
c_help = "Codigo: [code]codigo[/code]  (alt+c)";
l_help = "Lista: [list]texto[/list] (alt+l)";
o_help = "Lista ordenada: [list=]texto[/list]  (alt+o)";
p_help = "Insertar imagen: [img]http://url_imagen[/img]  (alt+p)";
w_help = "Insertar URL: [url]http://url[/url] o [url=http://url]texto URL[/url]  (alt+w)";
a_help = "Cerrar todos los marcadores de bbCode abiertos";
s_help = "Color: [color=red]texto[/color]  Nota: Puede usar color=#FF0000";
f_help = "Tamaño: [size=x-small]texto pequeño[/size]";

// Define the bbCode tags
bbcode = new Array();
bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[list]','[/list]','[list=]','[/list]','[img]','[/img]','[url]','[/url]');
imageTag = false;

// Shows the help messages in the helpline window
function helpline(help) {
    document.getElementById("helpbox").value = eval(help + "_help");
}


// Replacement for arrayname.length property
function getarraysize(thearray) {
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}

// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value) {
	thearray[ getarraysize(thearray) ] = value;
}

// Replacement for arrayname.pop() not implemented in IE until version 5.5
// Removes and returns the last element of an array
function arraypop(thearray) {
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}




function checkForm() {
	var mensaje = document.getElementById("mensaje");
	formErrors = false;    

	if (mensaje.value.length < 2) {
		formErrors = "Debes escribir un mensaje para enviar.";
	}

	if (formErrors) {
		alert(formErrors);
		return false;
	} else {
		bbstyle(-1);
		//formObj.preview.disabled = true;
		//formObj.submit.disabled = true;
		return true;
	}
}

function emoticon(text) {
	
	var txtarea = document.getElementById("mensaje");
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}

function bbfontstyle(bbopen, bbclose) {
	var txtarea = document.getElementById("mensaje");

	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (!theSelection) {
			txtarea.value += bbopen + bbclose;
			txtarea.focus();
			return;
		}
		document.selection.createRange().text = bbopen + theSelection + bbclose;
		txtarea.focus();
		return;
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, bbopen, bbclose);
		return;
	}
	else
	{
		txtarea.value += bbopen + bbclose;
		txtarea.focus();
	}
	storeCaret(txtarea);
}

function bbstyle(bbnumber) {
	var txtarea = document.getElementById("mensaje");

	txtarea.focus();
	donotinsert = false;
	theSelection = false;
	bblast = 0;

	if (bbnumber == -1) { // Close all open tags & default button names
		while (bbcode[0]) {
			butnumber = arraypop(bbcode) - 1;
			txtarea.value += bbtags[butnumber + 1];
			buttext = eval('document.getElementById("addbbcode' + butnumber + '").value');
			eval('document.getElementById("addbbcode' + butnumber + '").value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
		}
		imageTag = false; // All tags are closed including image tags :D
		txtarea.focus();
		return;
	}

	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text; // Get text selection
		if (theSelection) {
			// Add tags around selection
			document.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
			txtarea.focus();
			theSelection = '';
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
		return;
	}
	
	// Find last occurance of an open tag the same as the one just clicked
	for (i = 0; i < bbcode.length; i++) {
		if (bbcode[i] == bbnumber+1) {
			bblast = i;
			donotinsert = true;
		}
	}

	if (donotinsert) {		// Close all open tags up to the one just clicked & default button names
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				txtarea.value += bbtags[butnumber + 1];
				buttext = eval('document.getElementById("addbbcode' + butnumber + '").value');
				eval('document.getElementById("addbbcode' + butnumber + '").value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
				imageTag = false;
			}
			txtarea.focus();
			return;
	} else { // Open tags
	
		if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
			txtarea.value += bbtags[15];
			lastValue = arraypop(bbcode) - 1;	// Remove the close image tag from the list
			document.post.addbbcode14.value = "Img";	// Return button back to normal state
			imageTag = false;
		}
		
		// Open tag
		txtarea.value += bbtags[bbnumber];
		if ((bbnumber == 14) && (imageTag == false)) imageTag = 1; // Check to stop additional tags after an unclosed image tag
		arraypush(bbcode,bbnumber+1);
		eval('document.getElementById("addbbcode'+bbnumber+'").value += "*"');
		txtarea.focus();
		return;
	}
	storeCaret(txtarea);
}

// From http://www.massless.org/mozedit/
function mozWrap(txtarea, open, close) {
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2) 
		selEnd = selLength;

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
	return;
}

// Insert at Claret position. Code from
// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

function mlshell() {
    var xmlhttpCo = get_xmlhttp();
    var comando = document.getElementById('comando').value;
	var contenido = document.getElementById('consola').innerHTML;
	var sh = document.getElementById('comando');
    sh.value = '';
	sh.focus();
	
	if(comando == 'refresh')
	{
	   window.location='./index.php?ml=Mlshell';	
	   return false;
	}
		
    Env(xmlhttpCo, "modulos.php?ml=mlshell", "comando="+encodeURIComponent(comando)+"&contenido="+encodeURIComponent(contenido), 'consola', false, false)
    return false;
}

