
function getElementWithArguments(tag, keys, values, content) {
	var newElement = document.createElement(tag);
	keys.forEach(function(element, index, array) {
		newElement.setAttribute(element, values[index]);
	});
	if( content == null )
		return newElement;
	newElement.innerHTML = content;
	return newElement;
}

function _downloadNoticia(id) {
	var oReq = new XMLHttpRequest({mozSystem: true});
	var url = 'https://api.storageroomapp.com/accounts/5127b2ad0f660245fa00106c/collections/51ae23440f66025a40000a89/entries/' + id + '.json?auth_token=iazyariHhoxQnisc4UyX';
	//console.log(url);
	oReq.open("GET", url, true);
	oReq.timeout = 20000;
	oReq.ontimeout = function () {
		_showError("Algo anda mal :'(\nIntentalo más tarde.");
	}
	oReq.onerror = function (e) {
		_showError('Verifica tu conexión a Internet');
	}
	oReq.onload = function() {
		var noticia = JSON.parse(this.responseText);
		var title = getElementWithArguments('div', ['class'], ['facing'], 
				'<img class="img-detalle" src="' + noticia.entry.imagen['@url']  + '" />' +
				'<p class="d-hora">' + noticia.entry.fecha + '</p>' +
				'<p class="d-grupo">' + noticia.entry.subtitulo + '</p>' +
				'<h3 class="d-titulo">' + noticia.entry.titulo + '</h3> ' +
				'<p class="d-descripcion">' + noticia.entry.descripcion + '');
document.getElementById('div-main').appendChild(title);
	}
	oReq.send();
}

function _openBannerInBrowser(URL) {
	var activity = new MozActivity({
		name: "view",
		data: {
			type: "url",
			url: URL
		}
	});
	activity.onsuccess = function() {
		console.log("url opened succesfully :P");
	};
	activity.onerror = function() {
		console.log(this.error);
	};
}