function aleatorio(inferior,superior){
    numPosibilidades = superior - inferior
    aleat = Math.random() * numPosibilidades
    aleat = Math.floor(aleat)
    return parseInt(inferior) + aleat
} 

function dame_color_aleatorio(){
	hexadecimal = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F")
	color_aleatorio = "#";
	for (i=0;i<6;i++){
		pos = aleatorio(0,hexadecimal.length)
		color_aleatorio += hexadecimal[pos]
	}
	if(color_aleatorio == "FFFFFF") {
		dame_color_aleatorio();
	}
	return color_aleatorio
}
		
function keywords(str, object) {
	var keys = str.split(" ");
	var color;
	var words = "";
	keys.sort();
	keys.reverse();
	
	for(a=0; a<keys.length; ++a) {
		color = dame_color_aleatorio();
		words += ' <strong id="key_' + a +'"class="found" style="background:' + color + ';">' + keys[a] + '</strong>';
	}
	$("#"+object).html(words);
}
		
function obtencolor(num) {
	color = document.getElementById("key_"+num).style.background;
	return color;
}
		
function search(str, word, original, id) {
	texto = new String(str);
	var tofound = word.split(" ");			
	var toreplace = original.split(" ");
	tofound.sort();
	tofound.reverse();
	toreplace.sort();
	toreplace.reverse();
	
	for(i=0; i<tofound.length; ++i) {
		var re = new RegExp((tofound[i]), 'gi');				
		//alert(re);
		color = obtencolor(i);
		texto = texto.replace(re, '<strong class="found" style="background:' + color + ';">' + toreplace[i] + '</strong>');			
		$("#text_"+id).html(texto);
	}			
}