var checkboxImages = new Array(
					"http://www.unimall.it/images/person/ratings/check-off._V47060180_.gif",
                    "http://www.unimall.it/images/person/ratings/check-on._V47060003_.gif",
					"http://www.unimall.it/images/person/ratings/check-hover._V47060180_.gif"
		 			  );

var starImages = new Array(
			"http://www.unimall.com/images/person/ratings/unrated.gif",
			"http://www.unimall.com/images/person/ratings/1-star.gif",
			"http://www.unimall.com/images/person/ratings/2-star.gif",
			"http://www.unimall.com/images/person/ratings/3-star.gif",
			"http://www.unimall.com/images/person/ratings/4-star.gif",
			"http://www.unimall.com/images/person/ratings/5-star.gif"
	);

var starMap = new Array(
		'0,0,12,20',
		'13,0,24,20',
		'25,0,36,20',
		'37,0,48,20',
		'49,0,60,20',
		'61,0,72,20');

var savedRatings = new Array();
var changedRatings = new Array();
var isSaved = new Array();
var starTwinkler = new Array();
var msgTwinkler = new Array();

var starMessages = new Array(
		"Non valutato",
		"Non mi piace per niente",
		"Non mi piace",
		"Non male",
		"Mi piace",
		"Mi piace molto",
		"",
		"<span style="+'"'+"font-size:10px; color: #990000"+'"'+">Salvato</span>",
            "&nbsp;");


var allImages = new Array();

var delayTime = 500;

function unml_js_preloadImages(imgArray){
  for (i=1; i < imgArray.length ;i++){
    if (imgArray[i] != undefined) {
      allImages[i] = new Image();
      allImages[i].src = imgArray[i];
    }
  }
}

unml_js_preloadImages(starImages);
unml_js_preloadImages(checkboxImages);

/**
 * Eric tabot
 * @param asin
 * @param rating
 * @return
 */
function maintainStars(asin, rating){

    document.write('<img src="' + starImages[rating] + '"');
    document.write(' valign="bottom" border="0" ');
    document.write(' /> ('+ rating +')');

}


function unml_js_showStarsProductsInfo(asin, rating){
	
    var starID = "stars." + asin;

    starTwinkler[asin] = 0;
    msgTwinkler[asin] = 0;

    document.write('<map style="cursor: pointer;cursor: hand;" name="starmap' + asin + '">');

    var i = 1;
    for (i = 1; i < 6; i++) {
        document.write('<area shape="rect" coords="' + starMap[i] + '" ' +
            'onmouseover="unml_js_starMouseOver(' + "'" + asin + "'," + i + ');" ' +
            'onfocus="unml_js_starMouseOver(' + "'" + asin + "'," + i + ');" ' +
            'onmouseout="unml_js_starMouseOut(' + "'" + asin + "'" + ');" ' +
            'onblur="unml_js_starMouseOut(' + "'" + asin + "'" + ');" ' +
            'onclick="unml_js_sendStars(' + "'" + asin + "'," + i + '); return false;" ' + 
            'alt="'+starMessages[i]+'" '+
            'href="#" />');
    }
    document.write("</map>");

    document.write('<img src="' + starImages[0] + '"');
    document.write(' valign="bottom" border="0" usemap="#starmap' + asin + '"');
    document.write(' id="' + starID + '" />');

}


function unml_js_showStars(asin, rating){
	
    var starID = "stars." + asin;

    starTwinkler[asin] = 0;
    msgTwinkler[asin] = 0;

    document.write('<map style="cursor: pointer;cursor: hand;" name="starmap' + asin + '">');

    var i = 0;
    for (i = 0; i < 6; i++) {
        document.write('<area shape="rect" coords="' + starMap[i] + '" ' +
            'onmouseover="unml_js_starMouseOver(' + "'" + asin + "'," + i + ');" ' +
            'onfocus="unml_js_starMouseOver(' + "'" + asin + "'," + i + ');" ' +
            'onmouseout="unml_js_starMouseOut(' + "'" + asin + "'" + ');" ' +
            'onblur="unml_js_starMouseOut(' + "'" + asin + "'" + ');" ' +
            'onclick="unml_js_sendStars(' + "'" + asin + "'," + i + '); return false;" ' + 
            'alt="'+starMessages[i]+'" '+
            'href="#" />');
    }
    document.write("</map>");

    document.write('<img src="' + starImages[rating] + '"');
    document.write(' valign="bottom" border="0" usemap="#starmap' + asin + '"');
    document.write(' id="' + starID + '" />');

}



function unml_js_starMouseOver(asin, rating){

   if (starTwinkler[asin] != 0){
    window.clearTimeout(starTwinkler[asin]);
    starTwinkler[asin] = 0;
  }
  if (msgTwinkler[asin] != 0){
    window.clearTimeout(msgTwinkler[asin]);
    msgTwinkler[asin] = 0;
  }  
  unml_js_swapStars(asin, rating);
  unml_js_swapStarMsgs(asin, rating);
  			 
}

function unml_js_starMouseOut(asin){
  starTwinkler[asin] = window.setTimeout("unml_js_swapStars('"+asin+"')", delayTime);
  msgTwinkler[asin] = window.setTimeout("unml_js_swapStarMsgs('"+asin+"')", delayTime);
}

function unml_js_swapStars(asin, rating) {
    if (document.images["stars." + asin] != undefined) {
        if (rating == undefined) rating = savedRatings[asin];
        if (rating == undefined) rating = 0;
        document.images["stars." + asin].src = starImages[rating];
    }  
}

function unml_js_swapStarMsgs(asin, rating) {
    if (!isSaved[asin] && document.getElementById("messages." + asin)) {
        if (rating == undefined) {
            document.getElementById("messages." + asin).innerHTML = starMessages[6];
        } else {
            document.getElementById("messages." + asin).innerHTML = starMessages[rating];
            if (rating == 7) isSaved[asin]= 1;
        }
    }
}

function unml_js_sendStars(asin, rating) {
	
    savedRatings[asin] = rating;
    changedRatings[asin] = 1;
	
    try {
        if (shvl) {
            shvl.rating[asin] = savedRatings[asin];
            shvl.notInterested[asin] = 0;
        }    
    } catch(e) {}   
	
    unml_js_swapStarMsgs(asin, 7);
	
    if (savedRatings[asin]) {
      //  unml_js_swapNotInterested(asin, 0);
    }

    window.setTimeout("unml_js_sendRating('"+asin+"', 'onetofive', '"+rating+"')", delayTime);
    
}

function unml_js_sendRating(asin, ratingType, ratingValue){
  


  var submitURL = '/ratings.php?'
      + '&rating_asin=' + asin
      + '&' + asin + '.rating.' + ratingType + '=' + ratingValue 
	  + '&rating_value=' 
      + ratingValue;


   /* if ( ( ( ratingType == 'onetofive' ) || ( ratingType == 'owned'  ) )
            && ( savedNotInterested[asin] == 1 ) ) {
        submitURL = submitURL + '&' + asin + '.rating.not-interested=NONE';
        savedNotInterested[asin] = 0;
    }
    else if ( ratingType == 'not-interested' ) {
        if ( savedRatings[asin] > 0 ) {
            submitURL = submitURL + '&' + asin + '.rating.onetofive=0';
            savedRatings[asin] = 0;
        }
        if ( savedIsOwned[asin] == 1 ) {
            submitURL = submitURL + '&' + asin + '.rating.owned=NONE';
            savedIsOwned[asin] = 0;
        }
    }
*/
    try {
        if (shvl != undefined) {
            invalidateAsin(asin);
        }
    }
    catch(e) { }


    isRatingsBarChanged = true;
    window.location.href = submitURL + "&return.response=204";
}

function unml_js_showMessages(asin, defaultMsg){
	
    if (defaultMsg) {
        starMessages[6] = starMessages[defaultMsg];
    }
    document.write("<span id="+'"'+"messages." + asin + ""+'"'+" style="+'"'+"font-size:10px;"+'"'+">" + starMessages[6]  + "</span>");
}

function unml_js_swapStarMsgs(asin, rating) {
	
    if (!isSaved[asin] && document.getElementById("messages." + asin)) {
		
        if (rating == undefined) {
            document.getElementById("messages." + asin).innerHTML = starMessages[6];
        } else {
			
            document.getElementById("messages." + asin).innerHTML = starMessages[rating];
            if (rating == 7) isSaved[asin]= 1;
        }
    }
}
