$(document).ready(function(){
    $("#nav-one li").hover(
        function(){ $("ul", this).fadeIn("fast"); }, 
        function() { } 
    );
    if (document.all) {
        $("#nav-one li").hoverClass ("sfHover");
    }
  $('#comment').one("focus", function() {
    $('#comment').parent().after('<div id="preview-box"><div class="comment-by">Previsualización de comentario</div><div id="live-preview"></div></div>');
  });
  var $comment = '';
  $('#comment').keyup(function() {
    $comment = $(this).val();
    $comment = $comment.replace(/\n/g, "<br />");
    $comment = $comment.replace(/\n\n+/g, '<br /><br />');
    $('#live-preview').html( $comment );
  });
  
	$("#datos").tabs({ remote:true });	
	$("#participacion").tabs({ remote:true });
	$("#comentarios-sidebar").tabs({ remote:true });
}); 

$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover( 
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
};    

function rateIt(commentID, rateType, baseURL) {
	$('#notrated-'+commentID).fadeOut("normal");
	var url = baseURL + "/wp-content/plugins/ratecomments/rate.php?ratetype="+rateType+"&commentid="+commentID;

	$.ajax({
		url: url,
		dataType: "html",
		success: function(html) {
			var respuesta = html.split("|");
			var i = parseInt(respuesta[0]);
	    	if (i > -1) {
				$("#rate-"+respuesta[1]).html('+'+respuesta[0]+' celestinos');
			} else {
				$("#rate-"+respuesta[1]).html(respuesta[0]+' celestinos');
			}
		}
	});

}

function mostrar_res(part) {
		$("#part-"+part).hide();	
		$("#votos-loading-"+part).show();
		$.post("http://celestes.org/elmejor/resultados3.php",{
  			partido: ""+part+"" },function(xml){
				$("#part-"+part).html(xml);
				$("#votos-loading-"+part).hide();
				$("#part-"+part).fadeIn("normal");
		});		
		$("#enlace-res-"+part).addClass("votos-no-act");
		$("#enlace-vot-"+part).removeClass("votos-no-act");
}

function mostrar_votos(part) {
		$("#part-"+part).hide();
		$("#votos-loading-"+part).show();
		$.post("http://celestes.org/elmejor/votos3.php",{
  			partido: ""+part+"", mostrar: "0" },function(xml){
				$("#part-"+part).html(xml);
				$("#votos-loading-"+part).hide();
				$("#part-"+part).fadeIn("normal");
		});
		$("#enlace-vot-"+part).addClass("votos-no-act");
		$("#enlace-res-"+part).removeClass("votos-no-act");		
}


function activar_desactivar(elemento) {
	var ele = document.getElementById(elemento);
	if((ele.style.display == 'none') || (ele.style.display == '')) {
		ele.style.display='block';
	}
	else {
		ele.style.display='none';
	}
}
function generar_codigos_compartir (numero, elemento) {
	//Genera una tabla con los codigos para compartir.
	var temporal="";
	temporal+='<strong>Enlace permanente:</strong> <a href="http://videos.celestes.org/?videoid='+numero+'">http://videos.celestes.org/?videoid='+numero+'</a>';
	temporal+='<table border=0 width="100%">';

	temporal+='<textarea class=form rows=3 style="width:100%;" onclick="this.focus(); this.select();">';
	temporal+='<embed src="http://videos.celestes.org/flvplayer.swf?videoid='+ numero + '" type="application/x-shockwave-flash" width="400" height="345"></embed>';
	temporal+="</textarea>";

	temporal+="</table>";

	document.getElementById(elemento).innerHTML=temporal;
	activar_desactivar(elemento);
}
function voto_portal(post_id){	
	$('#portal-'+post_id).html('<img src="http://celestes.org/elmejor/mozilla_blu.gif" alt="" />');
	$.post("http://celestes.org/blog/scripts/votos_portal.php",{
  			id: ""+post_id+"" },function(xml){
				$('#portal-'+post_id).html(xml);
				$('#portal-link-'+post_id).html('¡Gracias!');	});				
}


// audio
var ap_instances = new Array();

function ap_stopAll(playerID) {
	for(var i = 0;i<ap_instances.length;i++) {
		try {
			if(ap_instances[i] != playerID) document.getElementById("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 1);
			else document.getElementById("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 0);
		} catch( errorObject ) {
			// stop any errors
		}
	}
}

function ap_registerPlayers() {
	var objectID;
	var objectTags = document.getElementsByTagName("object");
	for(var i=0;i<objectTags.length;i++) {
		objectID = objectTags[i].id;
		if(objectID.indexOf("audioplayer") == 0) {
			ap_instances[i] = objectID.substring(11, objectID.length);
		}
	}
}

var ap_clearID = setInterval( ap_registerPlayers, 100 );
// audio

// livesearch
$(document).ready(function() {
    $(".txt").focus(function(){
    	this.style.backgroundColor='#FFE';}).blur(function(){
    		this.style.backgroundColor='#F7F5F0';});
    	$('form#searchform').jsearch(); });

$.fn.jsearch = function() {
   	if ($(this)) {
	var search_box = $('input#s');
	search_box.val(searchtext).blur(function(){
		$(this).val(($(this).val() == '') ? searchtext : $(this).val())}).click(function(){
			$(this).val('')
		});
	$(this).submit(function(e){
	    e.preventDefault();
	    buscar_ajax(1);
		});
   	}
}

function buscar_ajax(page) {
	var search_box = $('input#s');
	var search_button = $('input#search-submit');
	var results_div = $('div#search-results');
	
	if (page==1) results_div.html('<div style="text-align:center;"><img src="/elmejor/loading.gif" alt="Cargando" /></div>');
    if (search_box.val() == '' || search_box.val() == searchtext) return false;
	search_button.attr('disabled', 'disabled');    
	parametros = 'act=ajax&paged='+page;
	results_div.load(path+'/?'+parametros+'&s=' + escape(search_box.val()), function(){
		results_div.addClass('search-results-borders');
		if (page==1) results_div.slideDown('slow')
	});
}
// livesearch


// jsoc
JSOC = function(){
    var Cache = {};
    return {
        "get":function(n){
            var obj = {}, val = Cache[n];
            obj[n] = val;
            if(val) return obj;
        },
        "getMulti":function(l){
            var a = [];
            for (var k in l) a.push(this.get(l[k]));
            return a;
        },
        "getType":function(t){
            var a = [];
            for (var o in Cache) if(typeof(Cache[o])==t.toLowerCase()){a.push(this.get(o))}
            return a;
        },
        "set":function(n,v){
            if(Cache[n]) delete(Cache[n]);
            Cache[n]=v;
            if (arguments[2]){
                var ttl = arguments[2].ttl || null;
                if(ttl) var self = this, to = setTimeout(function(){self.remove(n)}, ttl);
            }
            return (Cache[n])?1:0;
        },
        "add":function(n,v){
            if(!Cache[n]){
                Cache[n]=v;
                if (arguments[2]){
                    var ttl = arguments[2].ttl || null;
                    if(ttl) var self = this, to = setTimeout(function(){self.remove(n)}, ttl);
                }
                return (Cache[n])?1:0;
            }
        },
        "replace":function(n,v){
            if(Cache[n]){
                delete(Cache[n]);
                Cache[n]=v;
                if (arguments[2]){
                    var ttl = arguments[2].ttl || null;
                    if(ttl) var self = this, to = setTimeout(function(){self.remove(n)}, ttl);
                }
                return (Cache[n])?1:0;
            }
        },
        "remove":function(n){
            delete(Cache[n]);
            return (!Cache[n])?1:0;
        },
        "flush_all":function(){
            for(k in Cache) delete(Cache[k]);
            return 1;
        }
    }
}
// jsoc


// tooltip
// 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 :  <div id="myHtmlElement" onmouseover="tooltip.show(this)"...></div>
*/

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 : <div id="myHtmlElement" ... onmouseout="tooltip.hide(this)"></div>
*/
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";
}

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...');
		this.timeout = setTimeout("tooltip.ajax_request('"+script+"', '"+id+"', "+maxcache+")", 200);
	}
}

tooltip.ajax_request = function(script, id, maxcache) {
	var url = '/blog/scripts/'+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);
		}
	});
}
// tooltip

// elmejor
function enviaVoto(voto,jug,par) {
	url = 'http://celestes.org/elmejor/bd.php';
	
	$('#resultado-'+par+'-'+jug).html('<img src="http://celestes.org/elmejor/mozilla_blu.gif" alt="" />');
	$('#link-'+par+'-'+jug).html('<img src="http://celestes.org/elmejor/c-bury-off.png" style="margin: 0 0 -2px;" />&nbsp;<img src="http://celestes.org/elmejor/nulo-off.png" style="margin: 0 0 -2px;" />&nbsp;<img src="http://celestes.org/elmejor/c-digg-off.png" style="margin: 0 0 -2px;" />');

	$.post("http://celestes.org/elmejor/bd.php",{
  			id: ""+par+"", voto: ""+voto+"", jug: ""+jug+"" },function(xml){
				$('#resultado-'+par+'-'+jug).html(xml);	});
}
// elmejor



// tw-sacks
/* Simple AJAX Code-Kit (SACK) */
function sack(file){
	this.AjaxFailedAlert = "Your browser does not support the enhanced functionality of this website, and therefore you will have an experience that differs from the intended one.\n";
	this.requestFile = file;
	this.method = "POST";
	this.URLString = "";
	this.encodeURIString = true;
	this.execute = false;

	this.onLoading = function() { };
	this.onLoaded = function() { };
	this.onInteractive = function() { };
	this.onCompletion = function() { };

	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (err) {
				this.xmlhttp = null;
			}
		}
		if(!this.xmlhttp && typeof XMLHttpRequest != "undefined")
			this.xmlhttp = new XMLHttpRequest();
		if (!this.xmlhttp){
			this.failed = true; 
		}
	};
	
	this.setVar = function(name, value){
		if (this.URLString.length < 3){
			this.URLString = name + "=" + value;
		} else {
			this.URLString += "&" + name + "=" + value;
		}
	}
	
	this.encVar = function(name, value){
		var varString = encodeURIComponent(name) + "=" + encodeURIComponent(value);
	return varString;
	}
	
	this.encodeURLString = function(string){
		varArray = string.split('&');
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split('=');
			if (urlVars[0].indexOf('amp;') != -1){
				urlVars[0] = urlVars[0].substring(4);
			}
			varArray[i] = this.encVar(urlVars[0],urlVars[1]);
		}
	return varArray.join('&');
	}
	
	this.runResponse = function(){
		eval(this.response);
	}
	
	this.runAJAX = function(urlstring){
		this.responseStatus = new Array(2);
		if(this.failed && this.AjaxFailedAlert){ 
			alert(this.AjaxFailedAlert); 
		} else {
			if (urlstring){ 
				if (this.URLString.length){
					this.URLString = this.URLString + "&" + urlstring; 
				} else {
					this.URLString = urlstring; 
				}
			}
			if (this.encodeURIString){
				var timeval = new Date().getTime(); 
				this.URLString = this.encodeURLString(this.URLString);
				this.setVar("rndval", timeval);
			}
			if (this.element) { this.elementObj = document.getElementById(this.element); }
			if (this.xmlhttp) {
				var self = this;
				if (this.method == "GET") {
					var totalurlstring = this.requestFile + "?" + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
				}
				if (this.method == "POST"){
  					try {
						this.xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded')  
					} catch (e) {}
				}

				this.xmlhttp.send(this.URLString);
				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState){
						case 1:
							self.onLoading();
						break;
						case 2:
							self.onLoaded();
						break;
						case 3:
							self.onInteractive();
						break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;
							self.onCompletion();
							if(self.execute){ self.runResponse(); }
							if (self.elementObj) {
								var elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea"){
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							self.URLString = "";
						break;
					}
				};
			}
		}
	};
this.createAJAX();
}
// tw-sacks



// polls
/*
+----------------------------------------------------------------+
|	WordPress 2.0 Plugin: WP-Polls 2.11
|	Copyright (c) 2006 Lester "GaMerZ" Chan	
+----------------------------------------------------------------+
*/
// Variables
var polls = new sack(site_url + '/index.php');
var poll_id = 0;
var poll_answer_id = 0;
var poll_fadein_opacity = 0;
var poll_fadeout_opacity = 100;
var is_ie = (document.all && document.getElementById);
var is_moz = (!document.all && document.getElementById);
var is_opera = (navigator.userAgent.indexOf("Opera") > -1);
var is_being_voted = false;


// When User Vote For Poll
function poll_vote(current_poll_id) {
	if(!is_being_voted) {
		is_being_voted = true;
		poll_id = current_poll_id;
		poll_form = document.getElementById('polls_form_' + poll_id);
		poll_answer = eval("poll_form.poll_" + poll_id);
		poll_answer_id = 0;
		for(i = 0; i < poll_answer.length; i++) {
			if (poll_answer[i].checked) {
				poll_answer_id = poll_answer[i].value;
			}
		}
		if(poll_answer_id > 0) {
			poll_loading_text();
			poll_process();
		} else {
			alert("Please choose a valid poll answer.");
		}
	} else {
		alert("Your last request is still being processed. Please wait a while ...");
	}
}


// When User View Poll's Result
function poll_result(current_poll_id) {
	if(!is_being_voted) {
		is_being_voted = true;
		poll_id = current_poll_id;
		poll_loading_text();
		poll_process_result();
	} else {
		alert("Your last request is still being processed. Please wait a while ...");
	}
}


// When User View Poll's Voting Booth
function poll_booth(current_poll_id) {
	if(!is_being_voted) {
		is_being_voted = true;
		poll_id = current_poll_id;
		poll_loading_text();
		poll_process_booth();
	} else {
		alert("Your last request is still being processed. Please wait a while ...");
	}
}


// Poll Fade In Text
function poll_fadein_text() {
	if(poll_fadein_opacity == 90) {
		poll_unloading_text();
	}
	if(poll_fadein_opacity < 100) {
		poll_fadein_opacity += 10;
		if(is_opera) {
			poll_fadein_opacity = 100;
			poll_unloading_text();
		} else if(is_ie) {
			document.getElementById('polls-' + poll_id + '-ans').filters.alpha.opacity = poll_fadein_opacity;
		} else	 if(is_moz) {
			document.getElementById('polls-' + poll_id + '-ans').style.MozOpacity = (poll_fadein_opacity/100);
		}
		setTimeout("poll_fadein_text()", 100); 
	} else {
		poll_fadein_opacity = 100;
		is_being_voted = false;
	}
}


// Poll Loading Text
function poll_loading_text() {
	document.getElementById('polls-' + poll_id + '-loading').style.display = 'block';
}


// Poll Finish Loading Text
function poll_unloading_text() {
	document.getElementById('polls-' + poll_id + '-loading').style.display = 'none';
}


// Process The Poll
function poll_process() {
	if(poll_fadeout_opacity > 0) {
		poll_fadeout_opacity -= 10;
		if(is_opera) {
			poll_fadeout_opacity = 0;
		} else if(is_ie) {
			document.getElementById('polls-' + poll_id + '-ans').filters.alpha.opacity = poll_fadeout_opacity;
		} else if(is_moz) {
			document.getElementById('polls-' + poll_id + '-ans').style.MozOpacity = (poll_fadeout_opacity/100);
		}
		setTimeout("poll_process()", 100); 
	} else {
		poll_fadeout_opacity = 0;		
		polls.setVar("vote", true);
		polls.setVar("poll_id", poll_id);
		polls.setVar("poll_" + poll_id, poll_answer_id);
		polls.method = 'POST';
		polls.element = 'polls-' + poll_id + '-ans';
		polls.onCompletion = poll_fadein_text;
		polls.runAJAX();
		poll_fadein_opacity = 0;
		poll_fadeout_opacity = 100;
	}
}


// Process Poll's Result
function poll_process_result() {
	if(poll_fadeout_opacity > 0) {
		poll_fadeout_opacity -= 10;
		if(is_opera) {
			poll_fadeout_opacity = 0;
		} else if(is_ie) {
			document.getElementById('polls-' + poll_id + '-ans').filters.alpha.opacity = poll_fadeout_opacity;
		} else if(is_moz) {
			document.getElementById('polls-' + poll_id + '-ans').style.MozOpacity = (poll_fadeout_opacity/100);
		}
		setTimeout("poll_process_result()", 100); 
	} else {
		poll_fadeout_opacity = 0;
		polls.setVar("pollresult", poll_id);
		polls.method = 'GET';
		polls.element = 'polls-' + poll_id + '-ans';
		polls.onCompletion = poll_fadein_text;
		polls.runAJAX();
		poll_fadein_opacity = 0;
		poll_fadeout_opacity = 100;
	}
}


// Process Poll's Voting Booth
function poll_process_booth() {
	if(poll_fadeout_opacity > 0) {
		poll_fadeout_opacity -= 10;
		if(is_opera) {
			poll_fadeout_opacity = 0;
		} else if(is_ie) {
			document.getElementById('polls-' + poll_id + '-ans').filters.alpha.opacity = poll_fadeout_opacity;
		} else if(is_moz) {
			document.getElementById('polls-' + poll_id + '-ans').style.MozOpacity = (poll_fadeout_opacity/100);
		}
		setTimeout("poll_process_booth()", 100); 
	} else {
		poll_fadeout_opacity = 0;
		polls.setVar("pollbooth", poll_id);
		polls.method = 'GET';
		polls.element = 'polls-' + poll_id + '-ans';
		polls.onCompletion = poll_fadein_text;
		polls.runAJAX();
		poll_fadein_opacity = 0;
		poll_fadeout_opacity = 100;
	}
}
// polls


// lmb-box
// Load Quicktags JavaScript
var edButtons = new Array();
var edOpenTags = new Array();

function edButton(id, display, tagStart, tagEnd, access, open) {
	this.id = id;				// used to name the toolbar button
	this.display = display;		// label on button
	this.tagStart = tagStart; 	// open tag
	this.tagEnd = tagEnd;		// close tag
	this.access = access;		// access key
	this.open = open;			// set to -1 if tag does not need to be closed
}

// Start code
function edShowButton(button, i) {
	if (button.id == 'ed_img') {
		document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="edInsertImage(edCanvas);" value="' + button.display + '" />');
	}
	else if (button.id == 'ed_link') {
		document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="edInsertLink(edCanvas, ' + i + ');" value="' + button.display + '" />');
	}
	else if (button.id == 'ed_block') {
		document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="edInsertQuote(edCanvas, ' + i + ');" value="' + button.display + '" />');
	}
	else {
		document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="edInsertTag(edCanvas, ' + i + ');" value="' + button.display + '"  />');
	}
}

function edAddTag(button) {
	if (edButtons[button].tagEnd != '') {
		edOpenTags[edOpenTags.length] = button;
		document.getElementById(edButtons[button].id).value = '/' + document.getElementById(edButtons[button].id).value;
	}
}

function edRemoveTag(button) {
	for (i = 0; i < edOpenTags.length; i++) {
		if (edOpenTags[i] == button) {
			edOpenTags.splice(i, 1);
			document.getElementById(edButtons[button].id).value = document.getElementById(edButtons[button].id).value.replace('/', '');
		}
	}
}

function edCheckOpenTags(button) {
	var tag = 0;
	for (i = 0; i < edOpenTags.length; i++) {
		if (edOpenTags[i] == button) {
			tag++;
		}
	}
	if (tag > 0) {
		return true; // tag found
	}
	else {
		return false; // tag not found
	}
}	

function edCloseAllTags() {
	var count = edOpenTags.length;
	for (o = 0; o < count; o++) {
		edInsertTag(edCanvas, edOpenTags[edOpenTags.length - 1]);
	}
}

function edToolbar() {
	document.write('<span id="ed_comment_toolbar">');
	for (i = 0; i < edButtons.length; i++) {
		edShowButton(edButtons[i], i);
	}
	document.write('<input type="button" id="ed_close" class="ed_button" onclick="edCloseAllTags();" title="Cerrar todas las etiquetas abiertas" value="Cerrar todo" />');
	document.write('</span>');
}

// insertion code

function edInsertTag(myField, i) {
	//IE support
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		if (sel.text.length > 0) {
			sel.text = edButtons[i].tagStart + sel.text + edButtons[i].tagEnd;
		}
		else {
			if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') {
				sel.text = edButtons[i].tagStart;
				edAddTag(i);
			}
			else {
				sel.text = edButtons[i].tagEnd;
				edRemoveTag(i);
			}
		}
		myField.focus();
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		var cursorPos = endPos;
		var scrollTop = myField.scrollTop;

		if (startPos != endPos) {
			myField.value = myField.value.substring(0, startPos)
						  + edButtons[i].tagStart
						  + myField.value.substring(startPos, endPos) 
						  + edButtons[i].tagEnd
						  + myField.value.substring(endPos, myField.value.length);
			cursorPos += edButtons[i].tagStart.length + edButtons[i].tagEnd.length;
		}
		else {
			if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') {
				myField.value = myField.value.substring(0, startPos) 
							  + edButtons[i].tagStart
							  + myField.value.substring(endPos, myField.value.length);
				edAddTag(i);
				cursorPos = startPos + edButtons[i].tagStart.length;
			}
			else {
				myField.value = myField.value.substring(0, startPos) 
							  + edButtons[i].tagEnd
							  + myField.value.substring(endPos, myField.value.length);
				edRemoveTag(i);
				cursorPos = startPos + edButtons[i].tagEnd.length;
			}
		}
		myField.focus();
		myField.selectionStart = cursorPos;
		myField.selectionEnd = cursorPos;
		myField.scrollTop = scrollTop;
	}
	else {
		if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') {
			myField.value += edButtons[i].tagStart;
			edAddTag(i);
		}
		else {
			myField.value += edButtons[i].tagEnd;
			edRemoveTag(i);
		}
		myField.focus();
	}
}

function edInsertContent(myField, myValue) {
	//IE support
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
		myField.focus();
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
					  + myValue 
					  + myField.value.substring(endPos, myField.value.length);
		myField.focus();
		myField.selectionStart = startPos + myValue.length;
		myField.selectionEnd = startPos + myValue.length;
	} else {
		myField.value += myValue;
		myField.focus();
	}
}



function edInsertLink(myField) {
	var myValue = prompt('Introduce la dirección', 'http://');
	var myValue2 = prompt('Introduce un título (opcional)', '');
	if (myValue) {
		if (myValue2)
			myValue = '<a href="'
					+ myValue + '"'
					+ ' title="' + myValue2 + '">' + myValue2 + '</a>';
		else
			myValue = '<a href="' + myValue + '" title="">' + myValue + '</a>';
		edInsertContent(myField, myValue);
	}
}

function edInsertQuote(myField, i, defaultValue) {
	var myValue = prompt('A quién citas', '');
	if (myValue) {
		myValue = '<blockquote><p><strong>' 
				+ myValue 
				+ '</strong> <em>dijo</em>:</p>'
				+ '<p>' + prompt('Texto a citar', '') 
				+ '</p></blockquote>';
		edInsertContent(myField, myValue);
	}
}

function edInsertImage(myField) {
	var myValue = prompt('Introduce la dirección de la imagen', 'http://');
	if (myValue) {
		myValue = '<img src="' 
				+ myValue 
				+ '" alt="' + prompt('Introduce una pequeña descripción', '') 
				+ '" />';
		edInsertContent(myField, myValue);
	}
}
// lmb-box
