var activityId , taxonomyType,divcontentId,openForm,gmyId ;
function showVoteBox(contentId,targetId, id , type, myId )
{
	if(lg == true) {
		pos = findPos(targetId);
		executegetPatListDiv(contentId,type);
		activityId = id;
		divcontentId = targetId;
		taxonomyType = type;
		openForm = contentId;
		gmyId = myId;
		
	} else {
		if(confirm('You need to be logged in to Vote')) 
			window.location = '/utilities/utility/trackback';
	}
}
function executegetPatListDiv(contentId,type)
{
		 
		if(type == 'Winloose') type = 'Winner/Loser';
		if(type == 'WinloosePoll' || type == 'ResponsePoll' ) type = 'Poll';
	    type = type.toUpperCase()
		$("#"+contentId).html($("#"+contentId).html().replace(/article/gi,type));
		$("#"+contentId).css({top:pos[1]-260, left:pos[0]-40 }).show('slow');
}
function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
	}
	return [curleft,curtop];
}
function hideVoteBox(val)
{
	$("#"+val).hide('slow');
}
function vote(value) { 
	var queryString = 'vote='+value+'&id='+activityId+'&type='+taxonomyType+'&myId='+gmyId;
	/*$.getJSON('/utilities/voting/index',queryString, function (data){ alert(data);
															alert('Your Vote has been added');
															hideVoteBox(); 
															  });*/
	$.ajax({
					type: "POST",
				   	dataType: "json",
				   	url: "/utilities/voting/index",
				   	data: queryString,
				   	success: function(data){
				   		//alert(data.value);
				   		
						if(data.error == 'VoteExist') 
							alert("You have already voted for this "+taxonomyType);
						else if(data.error == 'Owner') {
							if(taxonomyType == 'Winloose') taxonomyType = 'Winner/Loser';
							if(taxonomyType == 'WinloosePoll' || taxonomyType == 'ResponsePoll' ) taxonomyType = 'Poll';
							alert("You are the Owner of this "+taxonomyType+". Your vote is not added");
						}
						if(data.value != 0) {
							//divcontentId.innerHTML = data.value;
							$("#"+taxonomyType+"_"+activityId).html(data.value)
							alert('Your Vote has been added');
						} 
						hideVoteBox(openForm); 
			   	    }
				});
}
