function AumentarTextArticulo(){
	if(document.getElementById("contenido_articulo").className=="text_contenido_3"){
		document.getElementById("contenido_articulo").className = "text_contenido_4";		
	}else if(document.getElementById("contenido_articulo").className=="text_contenido_2"){
		document.getElementById("contenido_articulo").className = "text_contenido_3";		
	}else if(document.getElementById("contenido_articulo").className=="text_contenido_1"){
		document.getElementById("contenido_articulo").className = "text_contenido_2";		
	}else if(document.getElementById("contenido_articulo").className=="text_contenido_0"){
		document.getElementById("contenido_articulo").className = "text_contenido_1";		
	}
} <!-- Funcion para aumentar el texto del articulo -->

function RestablecerTextArticulo(){
	document.getElementById("contenido_articulo").className = "text_contenido_2";		
} <!-- Funcion para restablecer el texto del articulo -->

function DisminuirTextArticulo(){
	if(document.getElementById("contenido_articulo").className=="text_contenido_4"){
		document.getElementById("contenido_articulo").className = "text_contenido_3";		
	}else if(document.getElementById("contenido_articulo").className=="text_contenido_3"){
		document.getElementById("contenido_articulo").className = "text_contenido_2";		
	}else if(document.getElementById("contenido_articulo").className=="text_contenido_2"){
		document.getElementById("contenido_articulo").className = "text_contenido_1";		
	}else if(document.getElementById("contenido_articulo").className=="text_contenido_1"){
		document.getElementById("contenido_articulo").className = "text_contenido_0";		
	}
} <!-- Funcion para disminuir el texto del articulo -->

function SelectionObject(Window) {
this.window=(Window?Window:window);
this.document=this.window.document;
}
SelectionObject.prototype={
"clear":function() {
try {
var sel = this.window.getSelection();
sel.collapse(true);
sel.dettach();
} catch (ex) {}
},
"createRange":function() {
if (this.type=="none") {
return "no selection";
}
var txt = this.window.getSelection()
var sel = {};
try { sel=this.window.getSelection().getRangeAt(0); } catch (ex) {}
var html = getHTMLOfSelection(this.window, this.document);
var range = null;

range = new ControlRangeObject();
range._text=(""+txt+"");
range._htmlText=html;
range._range=sel;
range.base=sel.commonAncestorContainer?sel.commonAncestorContainer:this.document.body
range.items=new Array();
range.addElement=range.add;

try {
while (range.base.nodeName.substr(0,1)=="#") {
range.base=range.base.parentNode;
}
var index = 0; var started;
var current = range.base.childNodes[0];
while (current) {
if (started || current==sel.startContainer || current==sel.commonAncestorContainer) {
started = true;
range.items.push(current);
}
if (current == sel.endContainer || current==sel.commonAncestorContainer) {
break;
}
index++;
current = range.base.childNodes[index];
}
range.length=range.items.length;
} catch (ex) {}

return range;
}
}

SelectionObject.prototype.empty=SelectionObject.prototype.clear;
SelectionObject.prototype.createRangeControl=SelectionObject.prototype.createRange;
SelectionObject.prototype.__defineGetter__("type", function() {
try {
var sel = window.getSelection().getRangeAt(0);
if (sel.commonAncestorContainer.nodeName.substr(0,1)=="#") {
return "text";
} else {
return "control";
}
} catch (ex) {}
return "none";
})
SelectionObject.prototype.__defineSetter__("type", function() {
// Do nothing
})

// ControlRangeObject
function ControlRangeObject() {}
ControlRangeObject.prototype={
"_text":"",
"_htmlText":"",
"_range":null,
"parentElement":function() {
return this.base;
},
"item":function(i) {
return this.items[i];
},
"add":function(node) {
try {
this._range.insertNode(node);
} catch (ex) {}
},
"execCommand":function(a1,a2,a3,a4) {
var mode = document.designMode;
document.designMode="on";
document.execCommand(a1,a2,a3,a4);
document.designMode=mode;
}
}
// Properties
ControlRangeObject.prototype.__defineGetter__("text",function() {
return this._text;
});
ControlRangeObject.prototype.__defineSetter__("text",function(value) {
var range = this._range;
var p=document.createTextNode(value);
range.deleteContents();
range.insertNode(p)
});

ControlRangeObject.prototype.__defineGetter__("htmlText",function() {
return this._htmlText
});
ControlRangeObject.prototype.__defineSetter__("htmlText",function(value) {
var range = this._range;
var p=document.createElement("htmlSection");
p.innerHTML=value;
range.deleteContents();
range.insertNode(p)
});

document.selection=new SelectionObject();

function getHTMLOfSelection (window, document) {
var range;
if (window.ActiveXObject && document.selection && document.selection.createRange) {
range = document.selection.createRange();
return range.htmlText;
}
else if (window.getSelection) {
var selection = window.getSelection();
if (selection.rangeCount > 0) {
range = selection.getRangeAt(0);
var clonedSelection = range.cloneContents();
var div = document.createElement('div');
div.appendChild(clonedSelection);
return div.innerHTML;
}
else {
return '';
}
}
else {
return '';
}
} 

var Texto_original=new String();
var Texto_plano=new String();

function cargar_variables(ElementType){
	if(!ElementType){ElementType = 'contenido_articulo';}
	//alert(ElementType);
	Texto_original=document.getElementById(ElementType).innerHTML;
	Texto_original=Texto_original.replace(/\n/g," ");
	//Texto_original=Texto_original.replace(/\r/g," ");
	//Texto_original=Texto_original.replace(/class="text_contenido_2"/, "");
	while(Texto_original.indexOf('  ')!=-1)   Texto_original=Texto_original.replace(/  /g," ");
	document.getElementById(ElementType).innerHTML = Texto_original;
	eval('patron=/<([la|link|h|c|e|s|d|a|\/s|\/d|\/a|\/e|\/c|\/h|\/link|\/la|LA|LINK|H|C|E|S|D|A|\/S|\/D|\/A|\/E|\/C|\/H|\/LINK|\/LA])([a-zA-Z0-9\(\)"=\/:.?\\_; ]+)>/g;');// falta -
	resaltar_primera_vez=true;
	Texto_plano=Texto_original.replace(patron,"");
	//Texto_plano=Texto_plano.replace(/<([u|\/u|i|\/i|b|\/b|I|\/I|B|\/B|U|\/U])>/g,"");
} <!-- Funcion de Seleccion de document.selected.range -->

function resaltar(){
	if(resaltar_primera_vez){
		texto_original=texto=Texto_plano;
		resaltar_primera_vez=false;
		texto=texto.replace(/&nbsp;/g," ");
		//alert(texto);
		texto=texto.replace(/<p>([ |\n]+)<p>/g,"<p>&nbsp;<p>");
		texto=texto.replace(/<P>([ |\n]+)<P>/g,"<P>&nbsp;<P>");
		//alert(texto);
	}else{
		texto_original=texto=document.getElementById('contenido_articulo').innerHTML;
	}
	  
	//alert(texto);
	q=(document.length?'':document.selection.createRange().text);
	var originalString = new String(texto);
	if(q=="" || q==null || q==" ") return;
	  
	var bloques=q.split("\n");
	for(i=0;i<bloques.length;i++){
		//originalString = new String(texto);
		q = bloques[i];
		//q=q.replace(/<\/p>/g,"");
		//q=q.replace(/<\/p>/g,"");
		while(q.indexOf('\r')!=-1 || q.indexOf('\n')!=-1)  q=q.substring(0,q.length-1); 
		if(q=="" || q==null || q==" " || q=="&nbsp;") continue;
		//q=q.substring(0,q.length-1); 
		//alert("x"+q+"xx");
		cadena='<span class=amarillo>';
		if(cadena.indexOf(q)>-1 && bloques.length==1) {alert('No se pudo sombrear su cadena');return;}
		cadena='</span>';
		if(cadena.indexOf(q)>-1  && bloques.length==1) {alert('No se pudo sombrear su cadena');return;}
		// alert("texto=originalString.replace(/"+escape(q)+"/g,'<span style=\"background-color:#FFFF00\">"+escape(q)+"</span>');");
		q=q.replace(/\(/g,"\\\(");
		q=q.replace(/\?/g,"\\\?");
		q=q.replace(/\)/g,"\\\)");
		q=q.replace(/"/g,"\\\"");
		q=q.replace(/\//g,"\\\/");
		q=q.replace(/^ /,"");
		q=q.replace(/ $/,"");
		q=q.replace(/\+/g,"\\\+");
		q=q.replace(/\*/g,"\\\*");
		q=q.replace(/\{/g,"\\\{");
		q=q.replace(/\}/g,"\\\}");		 
		q=q.replace(/&/g,"&amp;");		 
		q=q.replace(/</g,"&lt;");		 
		q=q.replace(/>/g,"&gt;");
		q=q.replace(/\./g,"\\.");
		//alert(q);
		eval("texto=texto.replace(/"+q+"/g,\"<span class='amarillo'>"+q+"</span>\");");
		//alert("texto=texto.replace(/"+q+"/g,\"<span class='amarillo'>"+q+"</span>\");"); 
	}
	document.getElementById('contenido_articulo').innerHTML = texto;
	if(texto_original==texto) {alert('No se pudo sombrear su cadena');return;}
} <!-- Funcion para Resaltar el texto del articulo seleccionado -->

function Restaurar(){
	resaltar_primera_vez=true;
	document.getElementById('contenido_articulo').innerHTML = Texto_original; 
} <!-- Funcion para Restaurar el texto del articulo -->

function ImprimirArticulo(){
	document.detalle_articulo.target = "_blank";
	document.detalle_articulo.method = "POST";
	document.detalle_articulo.action = "imprimir_articulo.php";
	document.detalle_articulo.submit();
} <!-- Funcion para Imprimir el articulo -->

function GenerarPDF(){
	document.detalle_articulo.target = "_blank";
	document.detalle_articulo.method = "POST";
	document.detalle_articulo.action = "imprimir_pdf.php";
	document.detalle_articulo.submit();
} <!-- Funcion para Generar el PDF del articulo -->



function Bold(ElementType){
	texto_original=texto=Texto_plano;
	resaltar_primera_vez=false;
	texto=texto.replace(/&nbsp;/g," ");
	texto=texto.replace(/<p>([ |\n]+)<p>/g,"<p>&nbsp;<p>");
	texto=texto.replace(/<P>([ |\n]+)<P>/g,"<P>&nbsp;<P>");
	texto_original=texto=document.getElementById(ElementType).innerHTML;
	q=(document.length?'':document.selection.createRange().text);
	var originalString = new String(texto);
	if(q=="" || q==null || q==" ") return;
	var bloques=q.split("\n");
	for(i=0;i<bloques.length;i++){
		q = bloques[i];
		while(q.indexOf('\r')!=-1 || q.indexOf('\n')!=-1)  q=q.substring(0,q.length-1); 
		if(q=="" || q==null || q==" " || q=="&nbsp;") continue;
		cadena='<span class=bold>';
		if(cadena.indexOf(q)>-1 && bloques.length==1) {alert('No se pudo colocar bold en su cadena');return;}
		cadena='</span>';
		if(cadena.indexOf(q)>-1  && bloques.length==1) {alert('No se pudo colocar bold en su cadena');return;}
		q=q.replace(/\(/g,"\\\(");
		q=q.replace(/\?/g,"\\\?");
		q=q.replace(/\)/g,"\\\)");
		q=q.replace(/"/g,"\\\"");
		q=q.replace(/\//g,"\\\/");
		q=q.replace(/^ /,"");
		q=q.replace(/ $/,"");
		q=q.replace(/\+/g,"\\\+");
		q=q.replace(/\*/g,"\\\*");
		q=q.replace(/\{/g,"\\\{");
		q=q.replace(/\}/g,"\\\}");		 
		q=q.replace(/&/g,"&amp;");		 
		q=q.replace(/</g,"&lt;");		 
		q=q.replace(/>/g,"&gt;");
		q=q.replace(/\./g,"\\.");
		eval("texto=texto.replace(/"+q+"/g,\"<span class='bold'>"+q+"</span>\");");
	}
	document.getElementById(ElementType).innerHTML = texto;
	if(texto_original==texto) {alert('No se pudo colocar bold en su cadena');return;}
	
} <!-- Funcion para Agregar Negrita al Texto de Contenido de un Articulo -->

function Italic(ElementType){
	texto_original=texto=Texto_plano;
	resaltar_primera_vez=false;
	texto=texto.replace(/&nbsp;/g," ");
	texto=texto.replace(/<p>([ |\n]+)<p>/g,"<p>&nbsp;<p>");
	texto=texto.replace(/<P>([ |\n]+)<P>/g,"<P>&nbsp;<P>");
	texto_original=texto=document.getElementById(ElementType).innerHTML;
	q=(document.length?'':document.selection.createRange().text);
	var originalString = new String(texto);
	if(q=="" || q==null || q==" ") return;
	var bloques=q.split("\n");
	for(i=0;i<bloques.length;i++){
		q = bloques[i];
		while(q.indexOf('\r')!=-1 || q.indexOf('\n')!=-1)  q=q.substring(0,q.length-1); 
		if(q=="" || q==null || q==" " || q=="&nbsp;") continue;
		cadena='<span class=italic>';
		if(cadena.indexOf(q)>-1 && bloques.length==1) {alert('No se pudo colocar italic en su cadena');return;}
		cadena='</span>';
		if(cadena.indexOf(q)>-1  && bloques.length==1) {alert('No se pudo colocar italic en su cadena');return;}
		q=q.replace(/\(/g,"\\\(");
		q=q.replace(/\?/g,"\\\?");
		q=q.replace(/\)/g,"\\\)");
		q=q.replace(/"/g,"\\\"");
		q=q.replace(/\//g,"\\\/");
		q=q.replace(/^ /,"");
		q=q.replace(/ $/,"");
		q=q.replace(/\+/g,"\\\+");
		q=q.replace(/\*/g,"\\\*");
		q=q.replace(/\{/g,"\\\{");
		q=q.replace(/\}/g,"\\\}");		 
		q=q.replace(/&/g,"&amp;");		 
		q=q.replace(/</g,"&lt;");		 
		q=q.replace(/>/g,"&gt;");
		q=q.replace(/\./g,"\\.");
		eval("texto=texto.replace(/"+q+"/g,\"<span class='italic'>"+q+"</span>\");");
	}
	document.getElementById(ElementType).innerHTML = texto;
	if(texto_original==texto) {alert('No se pudo colocar italic en su cadena');return;}
	
} <!-- Funcion para Agregar Cursiva al Texto de Contenido de un Articulo -->

function Underline(ElementType){
	texto_original=texto=Texto_plano;
	resaltar_primera_vez=false;
	texto=texto.replace(/&nbsp;/g," ");
	texto=texto.replace(/<p>([ |\n]+)<p>/g,"<p>&nbsp;<p>");
	texto=texto.replace(/<P>([ |\n]+)<P>/g,"<P>&nbsp;<P>");
	texto_original=texto=document.getElementById(ElementType).innerHTML;
	q=(document.length?'':document.selection.createRange().text);
	var originalString = new String(texto);
	if(q=="" || q==null || q==" ") return;
	var bloques=q.split("\n");
	for(i=0;i<bloques.length;i++){
		q = bloques[i];
		while(q.indexOf('\r')!=-1 || q.indexOf('\n')!=-1)  q=q.substring(0,q.length-1); 
		if(q=="" || q==null || q==" " || q=="&nbsp;") continue;
		cadena='<span class=underline>';
		if(cadena.indexOf(q)>-1 && bloques.length==1) {alert('No se pudo colocar underline en su cadena');return;}
		cadena='</span>';
		if(cadena.indexOf(q)>-1  && bloques.length==1) {alert('No se pudo colocar underline en su cadena');return;}
		q=q.replace(/\(/g,"\\\(");
		q=q.replace(/\?/g,"\\\?");
		q=q.replace(/\)/g,"\\\)");
		q=q.replace(/"/g,"\\\"");
		q=q.replace(/\//g,"\\\/");
		q=q.replace(/^ /,"");
		q=q.replace(/ $/,"");
		q=q.replace(/\+/g,"\\\+");
		q=q.replace(/\*/g,"\\\*");
		q=q.replace(/\{/g,"\\\{");
		q=q.replace(/\}/g,"\\\}");		 
		q=q.replace(/&/g,"&amp;");		 
		q=q.replace(/</g,"&lt;");		 
		q=q.replace(/>/g,"&gt;");
		q=q.replace(/\./g,"\\.");
		eval("texto=texto.replace(/"+q+"/g,\"<span class='underline'>"+q+"</span>\");");
	}
	document.getElementById(ElementType).innerHTML = texto;
	if(texto_original==texto) {alert('No se pudo colocar underline en su cadena');return;}
	
} <!-- Funcion para Agregar Subrayado al Texto de Contenido de un Articulo -->

function Remove_Format(ElementType){
	document.getElementById(ElementType).innerHTML = document.getElementById('texto').value;
}

function Create_Link(ElementType,direccion_url){
	texto_original=texto=Texto_plano;
	resaltar_primera_vez=false;
	texto=texto.replace(/&nbsp;/g," ");
	texto=texto.replace(/<p>([ |\n]+)<p>/g,"<p>&nbsp;<p>");
	texto=texto.replace(/<P>([ |\n]+)<P>/g,"<P>&nbsp;<P>");
	texto_original=texto=document.getElementById(ElementType).innerHTML;
	q=(document.length?'':document.selection.createRange().text);
	var originalString = new String(texto);
	if(q=="" || q==null || q==" ") return;
	var bloques=q.split("\n");
	for(i=0;i<bloques.length;i++){
		q = bloques[i];
		while(q.indexOf('\r')!=-1 || q.indexOf('\n')!=-1)  q=q.substring(0,q.length-1); 
		if(q=="" || q==null || q==" " || q=="&nbsp;") continue;
		cadena='<a href='+direccion_url+'>';
		if(cadena.indexOf(q)>-1 && bloques.length==1) {alert('No se pudo colocar link en su cadena');return;}
		cadena='</a>';
		if(cadena.indexOf(q)>-1  && bloques.length==1) {alert('No se pudo colocar link en su cadena');return;}
		q=q.replace(/\(/g,"\\\(");
		q=q.replace(/\?/g,"\\\?");
		q=q.replace(/\)/g,"\\\)");
		q=q.replace(/"/g,"\\\"");
		q=q.replace(/\//g,"\\\/");
		q=q.replace(/^ /,"");
		q=q.replace(/ $/,"");
		q=q.replace(/\+/g,"\\\+");
		q=q.replace(/\*/g,"\\\*");
		q=q.replace(/\{/g,"\\\{");
		q=q.replace(/\}/g,"\\\}");		 
		q=q.replace(/&/g,"&amp;");		 
		q=q.replace(/</g,"&lt;");		 
		q=q.replace(/>/g,"&gt;");
		q=q.replace(/\./g,"\\.");
		eval("texto=texto.replace(/"+q+"/g,\"<a href='"+direccion_url+"' target='_blank'>"+q+"</a>\");");
	}
	document.getElementById(ElementType).innerHTML = texto;
	if(texto_original==texto) {alert('No se pudo colocar link en su cadena');return;}
}






function descripcion(div,votos,precios,fotos){
	var promediovotos = votos;
	var conjuntovotos = "";
	for(var i=1;i<=5;i++){ 
		if(promediovotos>=i){
			conjuntovotos =  conjuntovotos + "<img src='images/estrella.gif' width='11' height='11'>"; 
		}else{
			conjuntovotos = conjuntovotos + "<img src='images/estrella_no.gif' width='11' height='11'>";
		}
	}
	var promedioprecios = precios;
	var conjuntoprecios = "";
	for(var i=1;i<=5;i++){ 
		if(promedioprecios>=i){
			conjuntoprecios =  conjuntoprecios + "<img src='images/icono_precio.gif' width='11' height='11'>"; 
		}else{
			conjuntoprecios = conjuntoprecios + "<img src='images/icono_precio_no.gif' width='11' height='11'>";
		}
	}
	document.getElementById(div).innerHTML = "<table width='100%' height='20' border='0' cellpadding='0' cellspacing='0'><tr><td width='25%'><div align='left' class='style2'>"+document.getElementById(div).innerHTML+" "+conjuntovotos+" <span class='style70'>"+promediovotos+"</span><span class='style70'> / 5</span> <span class='style72 '>("+votos+" votos) </span></div></td><td width='25%'><div align='left' class='style2'>"+conjuntoprecios+" <span class='style72 '>(...) </span></div></td></tr></table>";
}


function votos(div,nro){
	var promedio = nro;
	var conjunto = "";
	for(var i=1;i<=5;i++){ 
		if(promedio>=i){
			conjunto =  conjunto + "<img src='images/estrella.gif' width='11' height='11'>"; 
		}else{
			conjunto = conjunto + "<img src='images/estrella_no.gif' width='11' height='11'>";
		}
	}
	document.getElementById(div).innerHTML = "<table width='100%' height='20' border='0' cellpadding='0' cellspacing='0'><tr><td><div align='left' class='style2'>"+document.getElementById(div).innerHTML+" "+conjunto+" <span class='style70'>"+promedio+"</span><span class='style70'> / 5</span> <span class='style72 '>("+nro+" votos) </span></div></td></tr></table>";
} 

function precios(div,nro){
	var promedio = nro;
	var conjunto = "";
	for(var i=1;i<=5;i++){ 
		if(promedio>=i){
			conjunto =  conjunto + "<img src='images/icono_precio.gif' width='11' height='11'>"; 
		}else{
			conjunto = conjunto + "<img src='images/icono_precio_no.gif' width='11' height='11'>";
		}
	}
	document.getElementById(div).innerHTML = document.getElementById(div).innerHTML + conjunto + " <span class='style42'>(---)</span>";
} 

function recetas(div,nro){
	document.getElementById(div).innerHTML = "<table width='106' height='20' border='0' cellpadding='0' cellspacing='0'><tr><td width='15' class='style60'><div align='center'><img src='images/icono_recetas.gif' width='11' height='12' /></div></td><td width='91' class='style70'>"+nro+" <span class='style72'>recetas </span></td></tr></table>";
} 

function fotos(div,nro){
	document.getElementById(div).innerHTML = "<table width='106' height='20' border='0' cellpadding='0' cellspacing='0'><tr><td width='15' class='style60'><div align='center'><img src='images/icono_foto.gif' width='11' height='12' /></div></td><td width='91' class='style70'>"+nro+" <span class='style72'>fotos </span></td></tr></table>";
} 

function comentarios(div,nro){
	document.getElementById(div).innerHTML = "<table width='106' height='20' border='0' cellpadding='0' cellspacing='0'><tr><td width='15' class='style60'><div align='center'><img src='images/nube_comentario.gif' width='11' height='12' /></div></td><td width='91' class='style70'>"+nro+" <span class='style72'>comentarios </span></td></tr></table>";
} 
