/*
 * voting.js
 *
 * @description
 * @author       Razvan Nastase <contact@bonsoftware.com>
 * @version      1.0
 * @created      2008/05/01 09:00:00
 * @modified     2008/05/01 09:00:00
 * @copyright    Copyright (c) 2009, Bon Media Software - All Rights Reserved
 *
 * No part of this document may be reproduced and you may not modify or use this
 * document for any other purposes (including other projects) without written
 * consent from the author. Please see http://www.bonsoftware.com/license for
 * more information.
 */

var rating_max = 5;
function rating_display(type, id, rating) {
    rating = parseInt(rating);
    for (var i = 1; i <= rating_max; i++) {
        var imgEl = jQuery("#rimg_" + type + "_" + id + "_" + i);
        var picSrc = imgEl.attr('src');
        var ratingState = (i<=rating ? "on" : "off");
        imgEl.attr('src', picSrc.replace("on.gif", ratingState + ".gif")
                          .replace("off.gif", ratingState + ".gif"));
    }
}
	
function rating_submit(ot, oid, rt, captchaCode) {
    if (rt > rating_max || rt < 0) {
        return;
    }

    if (typeof captchaCode != undefined) {
        if (captchaCode == '') {
            document.getElementById('captcha').focus();
            return false;
        }
    }

    jQuery.ajax({
        url: votingURL,
        cache: false,
        dataType: "html",
        type: "post",
        data: 't=' + ot + '&i=' + oid + '&r=' +rt + (typeof captchaCode != undefined ? '&captcha=' + captchaCode : ''),
        success: function(html) {
            jQuery('#rdiv_' + ot + "_" + oid).html(html);
            
            /*if (jQuery("#rlabel_" + ot + "_" + oid)) {
                jQuery.ajax({
                    url: votingURL,
                    cache: false,
                    dataType: "html",
                    type: "post",
                    data: 't='+ot+'&i='+oid+'&info=1',
                    success: function(html2) {
                        jQuery("#rspan_" + ot + "_" + oid).html(html2);
                    }
                });
            }*/
        }
    })
}
