
	function debug(elemento) {
		var r = '{';
		if (elemento) {
			for (i in elemento) {
				r += i + ', ';
			}
			r.substring(0, r.length - 2);
		}
		alert(r + '}');
	}

	function populate_select(select, items, default_on) {
		select = $(select);
		select_reset(select);
		items.each(function(item) {
			var option = document.createElement('option');
			option.setAttribute('value', item.value);
			if (default_on && default_on == item.value) option.setAttribute('selected', 'selected');
			option.appendChild(document.createTextNode(item.text));
			select.appendChild(option);
		});
	}

	function remove_all_childs(element) {
		while ($(element).firstChild) {
			$(element).removeChild($(element).firstChild);
		}
	}

	function select_reset(select) {
		remove_all_childs(select);
	}

	function get_option_selected(select) {
		if (-1 == $(select).selectedIndex) return {};
		var option = $(select).options[$(select).selectedIndex];
		return {value: option.value, text: option.firstChild.nodeValue};
	}

	function pd() {
		return parent.document;
	}

	function pd$$(selector) {
		return parent.document.getElementsBySelector(selector).first();
	}

	function wo() {
		return window.opener;
	}

	function wo$$(selector) {
		return window.opener.document.getElementsBySelector(selector).first();
	}

	function d$$(selector) {
		return document.getElementsBySelector(selector).first();
	}

	function popup(url2pop, popW, popH) {

		var popW = (popW == null) ? 780 : popW;
		var popH = (popH == null) ? 550 : popH;

		var winleft = (screen.width - popW) / 2;
		var winUp = (screen.height - popH) / 2;
		winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+'toolbar=0,location=0,directories=0,menubar=0,resizable=1,scrollbars=yes';
		Win = window.open(url2pop, '', winProp);
		Win.window.focus();
	}

	function terminate_event(e) {
		if (e.stopPropagation != undefined)
			e.stopPropagation();
		else if (e.cancelBubble != undefined)
			e.cancelBubble = true;

		if (e.preventDefault != undefined)
			e.preventDefault();
		else
			e.returnValue = false;
	}

	function clear_number(num) {
		if (undefined == num) return;
		return parseFloat((num.toString().gsub('[^0-9\.]', '') || 0));
	}
	
	function currency_format(num) {
		if (undefined == num) return;
		num = clear_number(num);
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num)) num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
		if (cents<10) cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
		return (((sign)?'':'-') + '$ ' + num + '.' + cents);
	}
	
	function format_currency(element) {
		$(element).value = currency_format($F(element));
	}
	
	function is_email(text) {
		return /^([a-zA-Z0-9\_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(text);
	}

	var myrules = {
		'a.warning' : function(element) {
			element.onclick = function(){
				var text_confirm = '¿Seguro?';
				if (this.firstChild.nodeValue != text_confirm) {
					this.firstChild.nodeValue = text_confirm;
					return false;
				}
			}
		}, 
		'input.warning' : function(element) {
			element.onclick = function(){
				var text_confirm = '¿Seguro?';
				if (this.value != text_confirm) {
					this.value = text_confirm;
					return false;
				}
			}
		}
	};

	Behaviour.register(myrules);
	
	function refresh_alternate_colors_rows(table) {
		var table_id = $(table).getAttribute('id');
		var rows = $$('#' + table_id + ' .row');
		var i = 0;
		rows.each(function(row) {
			if (i++ % 2) {
				row.addClassName('row_alt');
			} else {
				row.removeClassName('row_alt');
			}
		});
	}
	
	// Player	
	function show_player(track_id) {
		var player_path = _relpath + 'static/_mediaplayer/?track_id=' + track_id;
		var popW = 306;
		var popH = 170;
		var winleft = (screen.width - popW) / 2;
		var winUp = (screen.height - popH) / 2;
		winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+'toolbar=0,location=0,directories=0,menubar=0,resizable=0,scrollbars=no';
		Win = window.open(player_path, 'MediaPlayer', winProp);
		Win.window.focus();
	}
	
	Behaviour.register({
		'a.play' : function(element) {
			element.onclick = function(){
				track_id = element.hash.gsub('^\#', '');
				show_player(track_id);
				return false;
			}
		}
	});
	
	// Vota videorola
	function popup_vota() {
		var url = 'http://www.videorola.com/backup/voto_gruperrona.htm';
		var popW = 200;
		var popH = 180;
		var winleft = (screen.width - popW) / 2;
		var winUp = (screen.height - popH) / 2;
		winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+'toolbar=0,location=0,directories=0,menubar=0,resizable=0,scrollbars=no';
		WinVota = window.open(url, 'vota', winProp);
		WinVota.window.focus();
	}
	