// JavaScript Document

function strlen (string) {
    var str = string+'';
    var i = 0, chr = '', lgth = 0;
 
    var getWholeChar = function (str, i) {
        var code = str.charCodeAt(i);
        var next = '', prev = '';
        if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters)
            if (str.length <= (i+1))  {
                throw 'High surrogate without following low surrogate';
            }
            next = str.charCodeAt(i+1);
            if (0xDC00 > next || next > 0xDFFF) {
                throw 'High surrogate without following low surrogate';
            }
            return str.charAt(i)+str.charAt(i+1);
        } else if (0xDC00 <= code && code <= 0xDFFF) { // Low surrogate
            if (i === 0) {
                throw 'Low surrogate without preceding high surrogate';
            }
            prev = str.charCodeAt(i-1);
            if (0xD800 > prev || prev > 0xDBFF) { //(could change last hex to 0xDB7F to treat high private surrogates as single characters)
                throw 'Low surrogate without preceding high surrogate';
            }
            return false; // We can pass over low surrogates now as the second component in a pair which we have already processed
        }
        return str.charAt(i);
    };
 
    for (i=0, lgth=0; i < str.length; i++) {
        if ((chr = getWholeChar(str, i)) === false) {
            continue;
        } // Adapt this line at the top of any loop, passing in the whole string and the current iteration and returning a variable to represent the individual character; purpose is to treat the first part of a surrogate pair as the whole character and then ignore the second part
        lgth++;
    }
    return lgth;
}


///////////////////////////////////////////// Agrandara el tamaņo del texarea sin dejar mostrar el barra 

// http://jroller.com/rmcmahon/entry/resizingtextarea_with_prototype
// Usage: <% apply_behaviour "textarea", "new ResizingTextArea(this);" %>
 
var ResizingTextArea = Class.create();
 
ResizingTextArea.prototype = {
    defaultRows: 1,
    initialize: function(field)
    {
        this.defaultRows = Math.max(field.rows, 1);
        this.resizeNeeded = this.resizeNeeded.bindAsEventListener(this);
        Event.observe(field, "click", this.resizeNeeded);
        Event.observe(field, "keyup", this.resizeNeeded);
    },
 
    resizeNeeded: function(event)
    {
        var t = Event.element(event);
        var lines = t.value.split('\n');
        var newRows = lines.length + 1;
        var oldRows = t.rows;
        for (var i = 0; i < lines.length; i++)
        {
            var line = lines[i];
            if (line.length >= t.cols) newRows += Math.floor(line.length / t.cols);
        }
        if (newRows > t.rows) t.rows = newRows;
        if (newRows < t.rows) t.rows = Math.max(this.defaultRows, newRows);
    }
}


function activarCampo(id){
	get(id).disabled="";
	}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function showMensajes(id_web,id_cosa,tipohilo,cache_general,tituloContent){
	var con='control=tablon/textmensaje&id_web='+id_web+'&id_cosa='+id_cosa+'&tipohilo='+tipohilo+'&cache_general='+cache_general+'&tituloContent='+tituloContent;
	var adm='control=tablon/administrar&id_web='+id_web+'&id_cosa='+id_cosa+'&tipohilo='+tipohilo+'&cache_general='+cache_general+'&tituloContent='+tituloContent;
	goAJAX('mensaje','ajax.php',con,'','');
	goAJAX('adminis','ajax.php',adm,'','');
}
	
function showRespuesta(id,id_web,id_cosa,tipohilo){
	var con='control=tablon/textrespuesta&id_web='+id_web+'&id_cosa='+id_cosa+'&tipohilo='+tipohilo+'&idmensaje='+id;
	Effect.BlindUp('linkresponder'+id, { duration: 0.5 });
	Effect.Appear('respuesta'+id, { duration: 1.5 }); 
	goAJAX('respuesta'+id,'ajax.php',con,'','');
	new Effect.ScrollTo('respuesta'+id, {duration: 0.9,offset: -90});
}
function showListaRespuesta(id){
	Effect.BlindDown('ListaRespuesta'+id, { duration: 0.5 });
	get('mostrar_respuestas'+id).style.display='none';
	}
function postComment(frm){
	var url=document.URL;
	var xP = akiSfrm(frm)+'&control=tablon/guardarmensaje&url='+url;
	goAJAX('ultimoMensaje','ajax.php',xP,'Effect.BlindUp(\'areadeltexto\', { duration: 0.5 });Effect.BlindDown(\'ultimoMensaje\', { duration: 0.9 });');
	return false;
	}
function postRespuesta(frm,id){
	var url=document.URL;
	var xP = akiSfrm(frm)+'&control=tablon/guardarRespuesta&url='+url;
	goAJAX('respuesta'+id,'ajax.php',xP,'Effect.BlindUp(\'areadeltexto'+id+'\', { duration: 1.0 });Effect.BlindDown(\'ultimoMensaje\', { duration: 1.9 });');
	return false;
	}
function contarcaracteres(area){
	var str=document.getElementById(area).value;
	var cuantoshay=strlen(str);
	//alert(cuantos);
	var cuantos=800-cuantoshay;
	if(cuantoshay>10){
		get('button').disabled='';
		} else{get('button').disabled='disabled';}
	GetId('Rcarateres').innerHTML=cuantos;
	}
function contarcaracteresRespuesta(area,id){
	var str=document.getElementById(area).value;
	var cuantoshay=strlen(str);
	//alert(cuantos);
	var cuantos=800-cuantoshay;
	if(cuantoshay>10){
		get('button'+id).disabled='';
		} else{get('button'+id).disabled='disabled';}
	GetId('Rcarateres'+id).innerHTML=cuantos;
	}	
function administrar(id){
	var xP ='&control=tablon/AdministrarHilo&id='+id;
		goAJAX('tablon','ajax.php',xP,'');
	}

function Editarmensaje(id){
	document.getElementById('textoEditar'+id).readOnly=false;
	get('okt'+id).style.display="none";
	document.getElementById('textoEditar'+id).style.backgroundColor="#FFF";
}
function saveValtitulocolecc(obj){
	/* desactivamos el campo */
	get(obj.id).disabled="disabled";
	get(obj.id).style.bgcolor="#FFFFFF";
	var id = str_replace('textoEditar','',obj.id);
	/* construimos los parametros de la solicitud ajax */
	/* No se recomienda pasar la tabla como parametro en una web publica */
	var xP = 'name=' + obj.name;
	xP += '&value=' + obj.value;
	xP += '&id=' + id;
	xP += '&control=tablon/GuardartextoEditado';
	/* hacemos la solicitud ajax pero sin reemplazar ni al inicio ni al final,
	tambien llamamos a una funcion para reactivar el campo */
	var exec = 'activarCampo(\'' + obj.id + '\')';
	goAJAX('okt'+id,'ajax.php',xP,exec,'','0','0');
	get('okt'+id).style.display="";
	showSaved('okt'+id);
	document.getElementById('textoEditar'+id).readOnly=true;
	document.getElementById('textoEditar'+id).style.backgroundColor="#BBB";
}
function showSaved(val){
	$(val).style.display='';
	new Effect.Pulsate($(val),{direction: 'top-left'});
	setTimeout("new Effect.Fade($(val),{direction: 'top-left'});",2000);
	}

function borrarMensaje(id,idh){
	var confirmMsg  = ' Esta por Borrar Un Mensaje...\n Esta seguro? ';
	var	ID ='id='+id+'&control=tablon/Borrarmensaje&id_hilo='+idh;
	if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
        return true;
	    }
    var is_confirmed = confirm(confirmMsg + ' \n   ');
    if (is_confirmed){
		
		Effect.BlindUp('mensaje'+id, { duration: 0.7 });
		//get('mensaje'+id).style.display="none";	
		goAJAX('','ajax.php',ID);
	}
}
function BanearUser(user,id){
	var usr='control=tablon/banearUser&user='+user;
	goAJAX('','ajax.php',usr,'','');
	var xP ='&control=tablon/AdministrarHilo&id='+id;
	goAJAX('tablon','ajax.php',xP,'');
}

function suscribsion(id_cosa,tipo,idM){
	var usr='control=tablon/suscribsion&id_cosa='+id_cosa+'&tipo='+tipo;
	goAJAX('notificacion'+id_cosa+tipo+idM,'ajax.php',usr,'');
	}
function enviarmail(){
	var xP ='&control=tablon/enviarmail';
	goAJAX('tablon','ajax.php',xP,'');
	}
function mostrarOcularEfecto(id){
ob=get(id).style;
if(ob.display=='none'){
		Effect.Appear(id, { duration: 2.0 });
		}else{	
			new Effect.BlindUp(id, {duration: 1.0});		
			}
return false;
}
