var CONTEXT_PATH='/ajax'
//var CONTEXT_PATH='http://localhost:8085'
var skey="";
function vote(artId, value){
	cockieRec=getCookie(artId+"vt");	
	skey="voted";
	if(cockieRec==null){		
		setCookieDays(artId+"vt",value,30);		
		dataObject={articleId:artId,key:skey,value:value};
		evalServerCall('/do/statistics/save',dataObject);
		actualizarVote(value);
	}
	else{
		skey="";
		value=cockieRec;
		if (articleLanguage=='ES')
			alert("Tu voto ya fue contabilizado para el artículo. Gracias por participar!");
		else
			alert("Thanks for voting!");
		dataObject={articleId:artId};
		evalServerCall('/do/statistics/get',dataObject);
	}
	
}

function actualizarVote(value){
	for(i=1;i<value+1;i++){
		document.getElementById("starR"+i).src="/images/aniversario/99/starActive.gif";
		document.getElementById("star"+i).src="/images/aniversario/99/starActive.gif";		
	}
	

	for(j=value+1;j<6;j++){
			document.getElementById("starR"+j).src="/images/aniversario/99/starOff.gif";
			document.getElementById("star"+j).src="/images/aniversario/99/starOff.gif";		
	}

}

function countVisit(artId){
	try{
		cockieRec=getCookie(artId+"v");	
		if(cockieRec==null){		
			setCookieSession(artId+"v",1);
			skey="visited";
			dataObject={articleId:artId,key:skey,value:1};
			evalServerCall('/do/statistics/save',dataObject);		
		}
	}catch(e){
	}
}

function showVote(artId){
	try{
		cockieRec=getCookie(artId+"vt");	
		if(cockieRec!=null){
			skey="voted";		
			actualizarVote(cockieRec);
			dataObject={articleId:artId};
			evalServerCall('/do/statistics/get',dataObject);
		}
		
	}
    catch(e){
    }
}

function showErrorStatistics(msg){
	alert(msg);
}

function showStatistics(articleStatistics){
	if (articleStatistics.voted>0){		
		if (articleLanguage=='ES')
			votos = articleStatistics.voted==1?" voto":" votos";
		else
			votos = articleStatistics.voted==1?" vote":" votes";		
		if(skey=='voted'){
			document.getElementById("divASVotado").innerHTML= articleStatistics.voted + votos;
			var resultados = articleStatistics.votedValue/articleStatistics.voted
			document.getElementById("divASValVotado").innerHTML= "("+Decimales(resultados, 2)+")";
			
			document.getElementById("starVote").style.display='none';
			document.getElementById("starResult").style.display='';
		}
		
	}

}

function Decimales(Numero, Decimales) { 
pot = Math.pow(10,Decimales); 
return parseInt(Numero * pot) / pot; 
} 

function GetThisMySpace(titleURL,URL,sumaryNews){
	try{
		dataObject={title:encodeURIComponent(titleURL),url:URL,type:'myspace',summary:encodeURIComponent(sumaryNews)};
		evalServerCall('/do/articulos/share',dataObject);
	}catch(e){}
}

function GetThisTwitter(titleURL,URL){
	try{
		dataObject={title:encodeURIComponent(titleURL),url:URL,type:'twitter'};
		evalServerCall('/do/articulos/share',dataObject);
	}catch(e){}
}

function GetThisFacebook(titleURL,URL){
	try{
		dataObject={title:encodeURIComponent(titleURL),url:URL,type:'facebook'};
		evalServerCall('/do/articulos/share',dataObject);
	}catch(e){}
}

function showNewPage(url,title,summary,type){
	var theURL ='';
	if (type=='twitter'){
		theURL = 'http://twitter.com/home?status=@ELUniversal - ' + title+' '+url;
	} else if (type=='myspace'){
		theURL = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=ElUniversal - ' + encodeURIComponent(title) + '&c=' +
			encodeURIComponent(summary) + '&u=' + encodeURIComponent(url) + '&l=1';
	} else if (type=='facebook'){
		u=location.href;
        t=document.title;
		theURL = "http://www.facebook.com/sharer.php?u='"+encodeURIComponent(u)+'&t='+ encodeURIComponent('ElUniversal - '+t);
	}
    window.open(theURL,'sharer','toolbar=0,status=0,width=800,height=600');
    return false;
}