/**
***************************************************************************
*       @developed by 	Mediafamily SRL,
* 						web: http://www.mediafamily.ro
* 						email: office@mediafamily.ro
* 						address:	str Tudor Vladimirescu nr. 63/14, 540014, Targu Mures, Romania
*
*		This script make uses of prototype and scriptaculous JS libraries.
***************************************************************************
*/

var ratings = new Array;
// cache the images used for rollover
if (document.images)
{
  pic1= new Image(7,14);
  pic1.src="/images/star_rating/star_e1.gif";
  pic2= new Image(7,14);
  pic2.src="/images/star_rating/star_e0.gif";
  pic3= new Image(7,14);
  pic3.src="/images/star_rating/star_f1.gif";
  pic4= new Image(7,14);
  pic4.src="/images/star_rating/star_f0.gif";
  pic5= new Image(14,15);
  pic5.src="/images/star_rating/hate1.gif";
  pic6= new Image(14,15);
  pic6.src="/images/star_rating/hate0.gif";
  pic7= new Image(14,15);
  pic7.src="/images/star_rating/love0.gif";
  pic8= new Image(14,15);
  pic8.src="/images/star_rating/love1.gif";
}


function showStarRateingResponse(response)
{
		var s = response.responseText;
		var res = s.split(",");
		var group = res[0];
		var id = res[1];
		var index = res[2];
		var message = res[3];

		ratings['star_'+group+'_'+id] = index;

		showOkWindow();

		for(z=1;z<=10;z++)
		{
			image_part = (z%2)?'0':'1';
			on_off = (z<=index)?'f':'e';
			if (index == 0) {
				// no vote yet
				on_off = 'n'+on_off;
			}
			on_off = on_off+image_part;
			usei = "/images/star_rating/star_"+on_off+".gif";
			i = $('star_'+ group + '_' + id + '_' + z);
			i.setAttribute("src", usei);

			/*
			i.setAttribute("onmouseover", null);
			i.setAttribute("onmouseout", null);
			i.setAttribute("onclick", null);
			i.style.cursor = 'default';
			*/
		}
		// clear events for the 0 and 1 vote too
		/*
		i = $('star_'+ group + '_' + id + '_' + 0);
		i.setAttribute("onmouseover", null);
		i.setAttribute("onmouseout", null);
		i.setAttribute("onclick", null);
		i.style.cursor = 'default';
		*/

}


function votio_vote(group, id, index, e)
{

	// save the event position;
	getMousePosition(e);

	// show the waiting message window
	showSpinnerWindow();

	var url = "/direct-star_rating-save_rating-" + group + "-" + id + "-" + index + ".php";
	var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				onComplete: showStarRateingResponse,
				onFailure: hideMsgWindow,
				onException: hideMsgWindow
			});
}

function votio_hatelove(group, id, option, e)
{

	// save the event position;
	getMousePosition(e);

	// show the waiting message window
	showSpinnerWindow();
	var url;
	i = $('star_'+group+'_'+id+'_hate');
	j = $('star_'+group+'_'+id+'_love');

	if (option=='hate') {
		if (i.src.indexOf('hate1.gif')>0) {
			useih = '/images/star_rating/hate0.gif';
		}else{
			useih = '/images/star_rating/hate1.gif';
		}
		useil = '/images/star_rating/love0.gif';
		url = "/direct-radiobutton_ajax-save_radiobutton-"+group+"Fav-" + id + "-hate.php";
	}else{
		if (j.src.indexOf('love1.gif')>0) {
			useil = '/images/star_rating/love0.gif';
		}else{
			useil = '/images/star_rating/love1.gif';
		}
		useih = '/images/star_rating/hate0.gif';
		url = "/direct-radiobutton_ajax-save_radiobutton-"+group+"Fav-" + id + "-fav.php";
	}


	i.setAttribute("src", useih);
	j.setAttribute("src", useil);

	var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				onComplete: showOkWindow,
				onFailure: hideMsgWindow,
				onException: hideMsgWindow
			});
}

function votio_hover(id, index, rating)
{

	var i;

	if (ratings[id] == null){
		ratings[id] = rating;
	}

	/*
	txt = $("ratings_text_" + id);
	var msg = ['Poor, I would not recommend','Below Average','Averange','Above Average','Excellent, I would recomment this'];
	txt.innerHTML = msg[index-1];
	txt.style.display = 'block';
	*/


	for (z=1; z<=10; z++) {
		i = $(id + "_" + z);

		image_part = (z%2)?'0':'1';
		on_off = (z<=index)?'f':'e';
		on_off = on_off+image_part;

		usei = "/images/star_rating/star_"+on_off+".gif";
		i.setAttribute("src", usei);
	}
}

function votio_unhover(id, index)
{
	var i;
	for (z=1; z<=10; z++) {
		i = $(id + "_" + z);

		image_part = (z%2)?'0':'1';
		on_off = (z<=ratings[id])?'f':'e';
		if (ratings[id] == 0) {
					// no vote yet
			on_off = 'n'+on_off;
		}
		on_off = on_off+image_part;

		usei = "/images/star_rating/star_"+on_off+".gif";

		i.setAttribute("src", usei);
	}
	// txt.style.display = 'none';
}


