
var ns_topshare;

if (!ns_topshare)
	ns_topshare = {};

ns_topshare.ns_rating;

if (!ns_topshare.ns_rating)
{
	ns_topshare.ns_rating = {};

	ns_topshare.ns_rating.Widget = function()
	{
		this.initialPosition = new Array();
		this.canVote = false;
	};

	ns_topshare.ns_rating.Widget.prototype.SubmitRating = function()
	{
		var form = document.getElementById('frm');
		var url = '/node/asp/modSaveFloatingForm.aspx'
		var str = this.makePostString(form);
		parent.postForm(str, url);
	};

	ns_topshare.ns_rating.Widget.prototype.ResetValues = function()
	{
		if(this.canVote)
		{
			for (var i = 1; i < this.initialPosition.length; i++)
				document.getElementById('ph' + i).style.backgroundPosition = 
					'0pt ' + this.initialPosition[i];
		}
	};

	ns_topshare.ns_rating.Widget.prototype.Opt = function(p_vote)
	{
		if(this.canVote)
		{
			// We need to change This image + all the images before this one;
			for (var i = 1; i <= p_vote; i++)
				document.getElementById('ph' + i).style.backgroundPosition = '0pt -28pt';
		}
	};

	ns_topshare.ns_rating.Widget.prototype.Vote = function(p_vote)
	{
		if(this.canVote)
		{
			document.getElementById('nbrRating').value = p_vote;
			this.SubmitRating();
			this.VoteAnimate(p_vote);
			var parentId = document.getElementById('parentId').value;
			var func = 'parent.syncToc(' + parentId +');';
			setTimeout(func, 500);
		}
	};

	ns_topshare.ns_rating.Widget.prototype.VoteAnimate = function(p_vote)
	{
		document.getElementById('ph' + p_vote).style.backgroundPosition = '0pt -25pt';
	};
	
	ns_topshare.ns_rating.Widget.prototype.AddInitialPosition = function(p_placeholder, p_value)
	{
		this.initialPosition[p_placeholder] = p_value;
	};

	ns_topshare.ns_rating.Widget.prototype.EnableVoting = function()
	{
		this.canVote = true;
	};

	ns_topshare.ns_rating.Widget.prototype.DisableVoting = function()
	{
		this.canVote = false;
	};
	ns_topshare.ns_rating.Widget.prototype.makePostString = function(form)
	{
		var str = '';
		var length = form.length;
		for (var i = 0; i < length; i++)
		{
			if(form.elements[i].name != '')
			{	
				
				var elem = form.elements[i];
				if((elem.type != 'radio' && elem.type != 'checkbox') || elem.checked == true)
				{
					if(str.length > 0) str = str + '&'; 
					str = str + elem.name + '=' + escape(elem.value);
				}
			}
		}
		return str;
	}
		
	
};

