// v0.1
// Communi frontal services
// 
// Requirements: Spry framework v1.6
//
// Copyright 2007 Communi.TV.  All rights reserved.
function formatDate(datetime, row) {
	if (datetime == '{creationDate}') return;
	
	var m_names = new Array("", "ene", "feb", "mar", "abr", "may", "jun", "jul", "ago", "sep", "oct", "nov", "dic");
	
	var todo = datetime.split(" ");
	var fechaArray = todo[0].split("-");
	var horaArray = todo[1].split(":");
	
	var dateRearranged = fechaArray[2] + " " + m_names[parseInt(fechaArray[1])] + ". " + fechaArray[0] + " a las " + horaArray[0] + ":" + horaArray[1];
	var elTab = document.getElementById('creationDate_' + row);
	elTab.innerHTML = dateRearranged;
}

function getUrl(data, imgId) {
	var uri = data;
	
	if(typeof(uri)=="undefined") {
		uri = "";
	}
	
	if (uri.indexOf('string') < 0) {
		if (uri == "") {
			uri = "/assets/default-videos.jpg";
		} else {
			uri = uri.substring("/deliverty/demo".length);
		}
		document.getElementById(imgId).src = uri;
	}
}

/************* cookies *************/

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


/************** player *******************/

function getAdvertisement() {
	return urlvideomitele;
}

/************* getAuthor ****************/
function autorObserver(notificationType, ds, data) {
	if (notificationType == "onPostLoad") {
		var row = ds.getCurrentRow();
		if (row) {
			var nickAutor = row["user/significatives/entry/string"];
			setAutorToSpan("autor_" + row["item/id"], nickAutor);
			setAutorToSpan("autor_player_" + row["item/id"], nickAutor);
		}
	}
}

function setAutorToSpan(spanid, autorname) {
	if (Spry.$(spanid)) {
		Spry.Utils.setInnerHTML(spanid, autorname);
	}
}

function getAuthor(id) {
	var dsAutor = new Spry.Data.XMLDataSet("/su/services/getParticipationsByContentId?CONTENT_TYPE=UGC&CONTENT_ID=" + id, "/list/com.ctv.web.vo.FavoriteVO", {subPaths: ["user/significatives/entry[string='NICK']/string[2]", "item/id"]});
	dsAutor.addObserver(autorObserver);
	dsAutor.loadData();
}

/************ volver () *****************/
function volver() {
	history.back(-2);
}
 
/**
 * timestamp
 */
function timestamp() {
	return new Date().getTime();
}
 