/* $Id: UC_clientscript.js - 28/02/2008 */
  
/* ----- save vote ----- */

var net = new Object();

net.READY_STATE_UNINITIALIZED = 0;
net.READY_STATE_LOADING = 1;
net.READY_STATE_LOADED = 2;
net.READY_STATE_INTERACTIVE = 3;
net.READY_STATE_COMPLETE = 4;
net.quitCounter;

function saveVote(id, points, boxId)
{
	var id = new net.Vote(id, points, boxId);
	return false;
}

net.Vote = function(id, points, boxId)
{
	this.songId = id;
	this.points = points;
	this.boxId = boxId;
	this.req = null;
	this.voteBox = document.getElementById('vote_box_' + boxId);
	this.prevHTML = this.voteBox.innerHTML;
	this.prevHTML = this.prevHTML.replace(/\'/g, "\\'");
	this.sendRequest(script_url, "UC_view=client_vote&UC_id=" + this.songId + "&points=" + this.points);
}


net.Vote.prototype =
{
	sendRequest : function(url,params,HttpMethod)
	{
		if (!HttpMethod)
			HttpMethod = "POST";
		if (window.XMLHttpRequest)
			this.req = new XMLHttpRequest();
		else if (window.ActiveXObject)
			this.req = new ActiveXObject("Microsoft.XMLHTTP");
		
		if (this.req)
		{
      		var loader = this;
			this.req.onreadystatechange = function()
			{
        		loader.onReadyState.call(loader);
      		}
			this.req.open(HttpMethod,url,true);
			this.req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			this.req.send(params);
		}
	},
	onReadyState : function()
	{
		var req = this.req;
		var ready = req.readyState;
		var xmlDoc;
		var entry;
		var status = false;
		var data = new Array();
		if (ready == net.READY_STATE_COMPLETE)
		{
			xmlDoc = this.req.responseXML.documentElement;
			entry = xmlDoc.getElementsByTagName('entry');
			data[0] = entry[0].childNodes[0].firstChild.nodeValue;
			data[1] = entry[0].childNodes[1].firstChild.nodeValue;
			status = true;
		}
		else
			status = false;
		this.message(status, data);
	},
	
	message : function(status, data)
	{
		if (this.voteBox != null)
		{
			if (status == true)
			{
				if (data[0] == 1)
				{
					this.voteBox.style.color = "#006600";
					this.voteBox.style.backgroundImage = "none";
					this.voteBox.style.backgroundColor = "#FFFFFF";
					this.voteBox.style.padding = "5px 0px 5px 0px";
					this.voteBox.style.border = "1px solid #CCCCCC";
				}
				else
				{
					this.voteBox.style.color = "#FF0000";
					this.voteBox.style.backgroundImage = "none";
					this.voteBox.style.backgroundColor = "#FFFFFF";
					this.voteBox.style.padding = "5px 0px 5px 0px";
					this.voteBox.style.border = "1px solid #CCCCCC";
				}
				this.voteBox.innerHTML = unescape(data[1]);
				this.startHideMessage();
			}
			else
			{
				this.voteBox.style.backgroundColor = "#FFFFFF";
				this.voteBox.style.backgroundImage = "none";
				this.voteBox.style.padding = "2px 0px 2px 0px";
				this.voteBox.style.border = "1px solid #CCCCCC";
				this.voteBox.innerHTML = "<img src=\"templates/images/loading.gif\" alt=\"\" />";
			}
		}
	},
	
	startHideMessage : function()
	{
		this.quitCounter = setTimeout('hideMessage(\'' + this.boxId + '\',\'' + this.prevHTML + '\')',1200);
	}
}

function hideMessage(boxId,prevHTML)
{
	voteBox = document.getElementById('vote_box_' + boxId);
	this.voteBox.style.border = "0px";
	this.voteBox.style.backgroundColor = "";
	this.voteBox.style.backgroundImage = "url(templates/images/legend.gif)";
	this.voteBox.style.color = "#000000";
	this.voteBox.style.padding = "0px 0px 6px 0px";
	voteBox.innerHTML = prevHTML;
}

/* // ----- save vote ----- */

function changeDataRow(style,rowStyle,count,row)
{
	for (var i = 1; i <= count; i++)
	{
		if (style == 'hover')
			className = "hover";
		if (style == 'out')
		{
			if (rowStyle == 1)
				className = "row1";
			else
				className = "row2";
		}
		element = $('row_' + row + '_' + i);
		if (element != null)
			element.className = className;
	}
}

function changeEntryRow(style,rowStyle,count,row)
{
	for (var i = 1; i <= count; i++)
	{
		if (style == 'hover')	
			className = "hover";
		if (style == 'out')
		{
			if (rowStyle == 1)
				className = "row1";
			else
				className = "row2";
		}
		element = $('row_' + row + '_' + i);
		if (element != null)
			element.className = className;
	}
}

function jumpMenu(targ,selObj,restore)
{
  	eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
  	if (restore)
		selObj.selectedIndex = 0;
}
