/*******************
VOTES FUNCTIONS
BASIC FUNCTIONS
************************************/
var update_voters = false;
var dn=new Array();
function menealo(user, id, htmlid, md5)
{
var url = base_url + "backend/menealo.php";
var content = "id=" + id + "&user=" + user + "&md5=" + md5;
url = url + "?" + content;
disable_vote_link(id, "...", '#FFC8AF');
$.get(url, {},
function(html) {
if (/^ERROR:/.test(html)) {
html = html.substring(6, html.length);
parseAnswer(htmlid, true, html);
updateVoters(id);
} else {
// Just a warning, do nothing
if (/^WARN:/.test(html)) {
alert(html);
} else {
parseAnswer (htmlid, false, html);
updateVoters(id);
}
}
reportAjaxStats('/vote');
}
);
}
function menealo_comment(user, id, value)
{
var url = base_url + "backend/menealo_comment.php";
var content = "id=" + id + "&user=" + user + "&value=" + value;
var myid = 'comment-'+id;
url = url + "?" + content;
$.get(url, {},
function(html) {
if (/^ERROR:/.test(html) || /^WARN:/.test(html)) {
html = html.substring(6, html.length);
alert(html);
} else {
vote_karma_image = html.split(",");
votes = parseInt(vote_karma_image[0]);
karma = parseInt(vote_karma_image[1]);
image = vote_karma_image[2];
$('#vc-'+id).html(votes);
$('#vk-'+id).html(karma);
if (image.length > 0) {
$('#c-votes-'+id).html('
');
}
}
reportAjaxStats('/comment_vote');
}
);
}
function disable_problem_form(id) {
$('#problem-' + id).hide();
}
function disable_vote_link(id, mess, background) {
//$('#a-va-' + id).hide();
$('#a-va-' + id).html(''+mess+'');
//$('#a-va-' + id).css('background', background);
//$('#a-va-' + id).show('fast');
}
function parseAnswer (id, error, server_answer)
{
answer = server_answer.split("~");
linkid = answer[0];
if (error || answer.length != 5 || id != linkid) {
alert(server_answer);
disable_vote_link(id, "grr...", '#FFCBAA');
disable_problem_form(id);
return false;
}
votes = answer[1];
negatives = answer[2];
karma = answer[3];
value = answer[4];
updateLinkValues(id, votes, negatives, karma, value);
return false;
}
function updateLinkValues (id, votes, negatives, karma, value) {
if ($('#a-votes-' + id).html() != votes) {
$('#a-votes-' + id).hide();
$('#a-votes-' + id).html(votes);
$('#a-votes-' + id).fadeIn('slow');
}
$('#a-neg-' + id).html(negatives);
$('#a-karma-' + id).html(karma);
if (value > 0) {
disable_vote_link(id, "chachi!", '#FFFFFF');
disable_problem_form(id);
} else if (value < 0) {
disable_vote_link(id, ":-(", '#FFFFFF');
disable_problem_form(id);
}
return false;
}
function enablebutton (button, button2, target)
{
var string = target.value;
if (button2 != null) {
button2.disabled = false;
}
if (string.length > 0) {
button.disabled = false;
} else {
button.disabled = true;
}
}
function checkfield (type, form, field)
{
var url = base_url + 'backend/checkfield.php?type='+type+'&name=' + field.value;
$.get(url, {},
function(html) {
if (html == 'OK') {
$('#'+type+'checkitvalue').html('"' + field.value + '": ' + html + '');
form.submit.disabled = '';
} else {
$('#'+type+'checkitvalue').html('"' + field.value + '": ' + html + '');
form.submit.disabled = 'disabled';
}
reportAjaxStats('/check_field');
}
);
return false;
}
function sel_img(a,b,c){
//alert(frm_img.src);
//alert(a+' \n'+b);
document.getElementById('frm_img').style.height=150;
frm_img.location='/backend/sub_img.php?a='+a+'&b='+b+'&c='+c;
}
function carga_css(css)
{
var noCache=Math.round(Math.random()*999999);
var url = base_url + 'backend/carga_css.php?css='+css;
$.get(url, {"css":css,"noCache":noCache},
function(html) {
$('#cont_css').html(html);
document.getElementById('Id_Cont_Css').value=css;
/*reportAjaxStats('/carga_css');*/
}
);
return false;
}
function carga_css_b(css,op)
{
var noCache=Math.round(Math.random()*999999);
var url = base_url + 'backend/carga_css_b.php?css='+css;
$.get(url, {"css":css,"op":op,"noCache":noCache},
function(html) {
$('#cont_css').html(html);
document.formCssD.action="/backend/cambiar_estilo.php?op=3";
document.getElementById('Id_Cont_Css').value=css;
/*reportAjaxStats('/carga_css');*/
}
);
return false;
}
function carga_interview(){
var noCache=Math.round(Math.random()*999999);
var url = base_url + 'backend/get_interview.php';
$.get(url, {"noCache":noCache},
function(html) {
$('#contenido_admin').html(html);
}
);
return false;
}
function C_CSS(css)
{
if(css=="block"){
var vt="";
vt+="
";
vt+="';
vt+='';
document.getElementById('contenido_admin').innerHTML=vt;
// carga_css(1);
}
/*
var url = base_url + 'backend/carga_css.php?css='+css;
$.get(url, {},
function(html) {
$('#cont_css').html(html);
reportAjaxStats('/carga_css');
}
);
*/
return false;
}
function S_CSS(css,uid)
{
if(css=="block"){
frm_css.location="backend/sub_css.php?uid="+uid;
} else if(css=="none"){
frm_css.location="about:blank";
}
return false;
}
function act_css(css_id,op){
var msj;
if(op==0){
msj="¿Activar?";
} else if(op==1){
msj="¿Borrar?";
}
if(confirm(msj)){
location.href="backend/cambiar_estilo.php?css_id="+css_id+"&op="+op;
}
}
function CambiarURL(crl,user){
if(crl.value.length>0){
var url = base_url + 'backend/crl.php?zz='+crl.value+"&usr="+user;
$.get(url, {},
function(html) {
//$('#mn_nom').html(html);
alert(html);
}
);
}
return false;
}
function carga_categorias(zz)
{
var noCache=Math.round(Math.random()*999999);
var url = base_url + 'backend/categoria.php?zz='+zz+'&noCache='+noCache;
$.get(url, {"zz":zz,"noCache":noCache},
function(html) {
$('#mn_cat').html(html);
reportAjaxStats('/carga_categoria');
}
);
return false;
}
function carga_categorias_cambia(zz)
{
var url = base_url + 'backend/categorias.php?ct='+zz;
$.get(url, {},
function(html) {
$('#contenido_admin').html(html);
reportAjaxStats('/carga_categoria_cambia');
}
);
return false;
}
function carga_imagenes(tema)
{
var noCache=Math.round(Math.random()*999999);
var url = base_url + 'backend/imagenes.php';
$.get(url, {"tema":tema,"noCache":noCache},
function(html) {
$('#contenido_admin').html(html);
reportAjaxStats('/carga_imagenes');
}
);
return false;
}
function carga_enlaces(){
var url = base_url + 'backend/set_links.php';
$.get(url, {},
function(html) {
$('#mn_enlaces').html(html);
reportAjaxStats('/mn_enlaces');
}
);
return false;
}
function borrarEnlace(id, enlace){
if(confirm("Estas seguro de borrar el enlace: ["+enlace+"] ?")){
var url = base_url + 'backend/set_links.php';
$.get(url, {"id":id},
function(html) {
$('#mn_enlaces').html(html);
}
);
return false;
}
}
function nuevoEnlace(form){
var titulo=form[0].value;
var enlace=form[1].value;
var descri=form[2].value;
var url = base_url + 'backend/set_links.php';
$.get(url, {"titulo":titulo, "enlace":enlace,"descripcion":descri},
function(html) {
$('#mn_enlaces').html(html);
reportAjaxStats('/mn_enlaces');
}
);
return false;
}
function CambiaCategoria(cat_id,link_id){
var dv=document.getElementById('noticia_'+link_id);
document.getElementById('noticia_'+link_id).parentNode.removeChild(dv);
var url = base_url + 'backend/ccategorias.php?ct='+cat_id+'&id_link='+link_id;
$.get(url, {},'');
return false;
}
function cambia_categorias(zz)
{
var sl=zz[0].value;
var tx=zz[1].value;
var ac=zz[2].value;
var noCache=Math.round(Math.random()*999999);
var url = base_url + 'backend/categoria.php?noCache='+noCache;
if(tx.length===0 && ac=="new"){
alert("Ponle nombre a la categoria");
return false;
} else if (ac=="del"){
if(confirm('Estas seguro que quieres eliminar la categoria '+tx+'?')==false){
return false;
}
}
$.get(url, {"sel":sl,"txt":tx,"acc":ac,"noCache":noCache},
function(html) {
$('#mn_cat').html(html);
}
);
return false;
}
var op=new Array();
function enviarNoticia(idOp,hg,md5){
if(op[idOp]==false){
op[idOp]='x';
$('#notic_'+idOp).html("cargando...");
var noCache=Math.round(Math.random()*999999*idOp);
var urlF="/backend/get_viral.php?noCache="+noCache;
$.get(urlF,{"link_id":idOp,"noCache":noCache},
function(html){
$('#noticia_'+idOp).fadeTo("slow",0.3);
$('#notic_'+idOp).animate({height:hg},"slow",
function(){
$('#notic_'+idOp).fadeIn();
$('#notic_'+idOp).html(html);
op[idOp]=true;
}
);
}
);
}else if(op[idOp]==true){
$('#notic_'+idOp).html(" ");
$('#notic_'+idOp).animate({height:20},"slow",
function(){
$('#noticia_'+idOp).fadeTo("slow",1);
op[idOp]=false;
}
);
}
}
function sendNoticia(form){
var link_id=form.link_id.value;
var link_title=form.link_titulo.value;
var nombre=form.nombre.value;
var email=form.email.value;
var comentario=form.comentario.value;
var noCache=Math.round(Math.random()*999999*link_id);
var urlF="/backend/get_viral.php?noCache="+noCache;
$.post(urlF,{"link_id":link_id,"link_title":link_title,"nombre":nombre,"email":email,"comentario":comentario,"noCache":noCache},
function(html){
$('#notic_'+link_id).html(html);
}
);
}
function denunciaN(idOp,uri){
if(op[idOp]==false){
op[idOp]='x';
$('#notic_'+idOp).html("cargando...");
var noCache=Math.round(Math.random()*999999*idOp);
var urlF="/backend/noUser.php?noCache="+noCache;
$.get(urlF,{"link_id":idOp,"uri":uri,"noCache":noCache},
function(html){
$('#noticia_'+idOp).fadeTo("slow",0.3);
$('#notic_'+idOp).animate({height:50},"slow",
function(){
$('#notic_'+idOp).fadeIn();
$('#notic_'+idOp).html(html);
}
);
op[idOp]=true;
}
);
}else if(op[idOp]==true){
$('#notic_'+idOp).html(" ");
$('#notic_'+idOp).animate({height:20},"slow");
//$('#noticia_'+idOp).fadeTo("slow",1);
$('#noticia_'+idOp).animate({height:250},"slow",
function(){
$('#noticia_'+idOp).fadeTo("slow",1);
op[idOp]=false;
}
);
//op[idOp]=false;
}
}
function denuncia(idOp){
if(op[idOp]==false){
op[idOp]='x';
$('#denuncia_noticia_'+idOp).html("cargando...");
//var noCache=Math.round(Math.random()*999999*idOp);
var noCache=new Date();
var urlF="/backend/get_denuncia.php?noCache="+noCache;
$.get(urlF,{"link_id":idOp,"noCache":noCache},
function(html){
$('#denuncia_noticia_'+idOp).html(" ");
$('#noticia_'+idOp).fadeTo("slow",0.1,
function(){
$('#noticia_'+idOp).animate({height:10},"slow");
$('#denuncia_noticia_'+idOp).animate({height:420},"slow",
function(){
$('#denuncia_noticia_'+idOp).fadeIn();
$('#noticia_'+idOp).hide("normal");
$('#denuncia_noticia_'+idOp).html(html);
op[idOp]=true;
}
);
}
);
}
);
}else if(op[idOp]==true){
$('#denuncia_noticia_'+idOp).html(" ");
$('#denuncia_noticia_'+idOp).animate({height:20},"slow");
$('#noticia_'+idOp).animate({height:250},"slow",
function(){
$('#noticia_'+idOp).fadeTo("slow",1);
op[idOp]=false;
}
);
}
}
function check_checkfield(fieldname, mess) {
field = document.getElementById(fieldname);
if (field && !field.checked) {
alert(mess);
// box is not checked
return false;
}
}
function report_problem(frm, user, id, md5 /*id, code*/) {
if (frm.ratings.value == 0)
return;
if (! confirm("¿Seguro que desea reportarlo?") ) {
frm.ratings.selectedIndex=0;
return false;
}
var content = "id=" + id + "&user=" + user + "&md5=" + md5 + '&value=' +frm.ratings.value;
var url=base_url + "backend/problem.php?" + content;
$.get(url, {},
function(html) {
if (/^ERROR:/.test(html)) {
html = html.substring(6, html.length);
parseAnswer(id, true, html);
} else {
parseAnswer(id, false, html);
updateVoters(id);
}
reportAjaxStats('/problem');
}
);
return false;
}
function updateVoters(id) {
if (update_voters) {
get_votes('meneos.php', 'voters', 'voters-container',1, id);
}
}
// Get voters by Beldar
// Generalized for other uses (gallir at gmail dot com)
function get_votes(program,type,container,page,id) {
var url = base_url + 'backend/'+program+'?id='+id+'&p='+page+'&type='+type;
$('#'+container).load(url);
reportAjaxStats('/get_html');
}
// See http://www.shiningstar.net/articles/articles/javascript/dynamictextareacounter.asp?ID=AW
function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit)
// if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}
/**************************************
Tooltips functions
***************************************/
/**
Stronglky modified, onky works with DOM2 compatible browsers.
Ricardo Galli
From http://ljouanneau.com/softs/javascript/tooltip.php
*
* Can show a tooltip over an element
* Content of tooltip is the title attribute value of the element
* copyright 2004 Laurent Jouanneau. http://ljouanneau.com/soft/javascript
* release under LGPL Licence
* works with dom2 compliance browser, and IE6. perhaps IE5 or IE4.. not Nestcape 4
*
* To use it :
* 1.include this script on your page
* 2.insert this element somewhere in your page
*
* 3. style it in your CSS stylesheet (set color, background etc..). You must set
* this two style too :
* div#tooltip { position:absolute; visibility:hidden; ... }
* 4.the end. test it ! :-)
*
*/
// create the tooltip object
function tooltip(){}
// setup properties of tooltip object
tooltip.id="tooltip";
tooltip.main=null;
tooltip.offsetx = 10;
tooltip.offsety = 10;
tooltip.shoffsetx = 8;
tooltip.shoffsety = 8;
tooltip.x = 0;
tooltip.y = 0;
tooltip.tooltipShadow=null;
tooltip.tooltipText=null;
tooltip.title_saved='';
tooltip.saveonmouseover=null;
tooltip.timeout = null;
tooltip.active = false;
tooltip.elementInitialWidth = 0;
tooltip.cache = new JSOC();
tooltip.ie = (document.all)? true:false; // check if ie
if(tooltip.ie) tooltip.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0);
else tooltip.ie5 = false;
tooltip.dom2 = ((document.getElementById) && !(tooltip.ie5))? true:false; // check the W3C DOM level2 compliance. ie4, ie5, ns4 are not dom level2 compliance !! grrrr >:-(
/**
* Open ToolTip. The title attribute of the htmlelement is the text of the tooltip
* Call this method on the mouseover event on your htmlelement
* ex :
*/
tooltip.show = function (event, text) {
// we save text of title attribute to avoid the showing of tooltip generated by browser
if (this.dom2 == false ) return false;
if (this.tooltipShadow == null) {
this.tooltipShadow = document.createElement("div");
this.tooltipShadow.setAttribute("id", "tooltip-shadow");
document.body.appendChild(tooltip.tooltipShadow);
this.tooltipText = document.createElement("div");
this.tooltipText.setAttribute("id", "tooltip-text");
document.body.appendChild(this.tooltipText);
}
this.saveonmouseover=document.onmousemove;
document.onmousemove = this.mouseMove;
this.elementInitialWidth = this.tooltipText.scrollWidth;
this.mouseMove(event); // This already moves the div to the right position
//this.moveTo(this.x + this.offsetx , this.y + this.offsety);
this.setText(text);
this.tooltipText.style.visibility ="visible";
this.tooltipShadow.style.visibility ="visible";
this.active = true;
return false;
}
tooltip.setText = function (text) {
tooltip.tooltipShadow.style.width = 0+"px";
tooltip.tooltipShadow.style.height = 0+"px";
this.tooltipText.innerHTML=text;
setTimeout('tooltip.setShadow()', 1);
return false;
}
tooltip.setShadow = function () {
tooltip.tooltipShadow.style.width = tooltip.tooltipText.clientWidth+"px";
tooltip.tooltipShadow.style.height = tooltip.tooltipText.clientHeight+"px";
}
/**
* hide tooltip
* call this method on the mouseout event of the html element
* ex :
*/
tooltip.hide = function (event) {
if (this.dom2 == false) return false;
document.onmousemove=this.saveonmouseover;
this.saveonmouseover=null;
if (this.tooltipShadow != null ) {
this.tooltipText.style.visibility = "hidden";
this.tooltipShadow.style.visibility = "hidden";
this.tooltipText.innerHTML='';
}
this.active = false;
}
// Moves the tooltip element
tooltip.mouseMove = function (e) {
// we don't use "this", but tooltip because this method is assign to an event of document
// and so is dreferenced
if (tooltip.ie) {
tooltip.x = event.clientX;
tooltip.y = event.clientY;
} else {
tooltip.x = e.pageX;
tooltip.y = e.pageY;
}
tooltip.moveTo( tooltip.x +tooltip.offsetx , tooltip.y + tooltip.offsety);
}
// Move the tooltip element
tooltip.moveTo = function (xL,yL) {
if (this.ie) {
xL += document.documentElement.scrollLeft;
yL += document.documentElement.scrollTop;
}
if (this.elementInitialWidth > 0 && document.documentElement.clientWidth > 0 && xL > document.documentElement.clientWidth * 0.6) {
xL = xL - this.elementInitialWidth - 2*this.offsetx;
}
this.tooltipText.style.left = xL +"px";
this.tooltipText.style.top = yL +"px";
xLS = xL + this.shoffsetx;
yLS = yL + this.shoffsety;
this.tooltipShadow.style.left = xLS +"px";
this.tooltipShadow.style.top = yLS +"px";
}
// Show the content of a given comment
tooltip.c_show = function (event, type, element, link) {
// we save text of title attribute to avoid the showing of tooltip generated by browser
if (this.dom2 == false ) return false;
if (type == 'id') {
target_text = 'comment-' + element;
target_author = 'cauthor-'+element;
target = document.getElementById(target_text);
author_target = document.getElementById(target_author);
if (! target || ! author_target) return false;
text = ''+author_target.innerHTML+'
'+target.innerHTML;
} else if (type == 'order') {
this.ajax_delayed(event,'get_comment_tooltip.php',element+"&link="+link);
return;
} else {
text = element;
}
return this.show(event, text);
}
tooltip.clear = function (event) {
if (this.timeout != null) {
clearTimeout(this.timeout);
this.timeout = null;
}
this.hide(event);
}
tooltip.ajax_delayed = function (event, script, id, maxcache) {
maxcache = maxcache || 600000; // 10 minutes in cache
if (this.active) return false;
if ((object = this.cache.get(script+id)) != undefined) {
tooltip.show(event, object[script+id]);
} else {
this.show(event, 'cargando...'); // Translate this to your language: it's "loading..." ;-)
this.timeout = setTimeout("tooltip.ajax_request('"+script+"', '"+id+"', "+maxcache+")", 200);
}
}
tooltip.ajax_request = function(script, id, maxcache) {
var url = base_url + 'backend/'+script+'?id='+id;
tooltip.timeout = null;
$.ajax({
url: url,
dataType: "html",
success: function(html) {
tooltip.cache.set(script+id, html, {'ttl':maxcache});
tooltip.setText(html);
reportAjaxStats('/tooltip');
}
});
}
/************************
Simple format functions
**********************************/
/*
Code from http://www.gamedev.net/community/forums/topic.asp?topic_id=400585
strongly improved by Juan Pedro López for http://meneame.net
2006/10/01, jotape @ http://jplopez.net
*/
function applyTag(id, tag) {
obj = document.getElementById(id);
if (obj) wrapText(obj, tag, tag);
}
function wrapText(obj, tag) {
if(typeof obj.selectionStart == 'number') {
// Mozilla, Opera and any other true browser
var start = obj.selectionStart;
var end = obj.selectionEnd;
if (start == end || end < start) return false;
obj.value = obj.value.substring(0, start) + replaceText(obj.value.substring(start, end), tag) + obj.value.substring(end, obj.value.length);
} else if(document.selection) {
// Damn Explorer
// Checking we are processing textarea value
obj.focus();
var range = document.selection.createRange();
if(range.parentElement() != obj) return false;
if (range.text == "") return false;
if(typeof range.text == 'string')
document.selection.createRange().text = replaceText(range.text, tag);
} else
obj.value += text;
}
function replaceText(text, tag) {
text = text.replace(/(^|\s)[\*_]([^\s]+)[\*_]/gm, '$1$2')
text = text.replace(/([^\s]+)/gm, tag+"$1"+tag)
return text;
}
// This function report the ajax request to stats trackers
// Only known how to do it with urchin/Google Analytics
// See http://www.google.com/support/analytics/bin/answer.py?answer=33985&topic=7292
function reportAjaxStats(page) {
if (window.urchinTracker) {
urchinTracker(page+'.ajax');
}
}