var rb_widgetBase = 'http://www.ratingbug.com/rating/widget/ratingwidget1'; var alphaPNGHack = 0; if (navigator.appVersion.indexOf("MSIE")!=-1){ var temp = navigator.appVersion.split("MSIE") var version=parseFloat(temp[1]); if (version < 7) { alphaPNGHack = 1; } } var rb_default_icon_set = 'http://www.ratingbug.com/iconset/24x24/plain'; var rb_widgets = new Array(); var rb_load_count = 0; var rb_uiBox = document.createElement('DIV'); var cssFile = document.createElement('link'); cssFile.rel = 'stylesheet'; cssFile.href = rb_widgetBase + '/widget.css' cssFile.type = 'text/css'; var headTags = document.getElementsByTagName("head"); if (headTags.length == 0) { document.documentElement.appendChild(document.createElement('head')); } document.getElementsByTagName("head")[0].appendChild(cssFile); function rb_findWidgets () { var w = document.getElementsByTagName('DIV'); for (var i = 0; i < w.length; i++) { var curWidget = w[i] if (! curWidget.is_parsed) { curWidget.is_parsed = 1; var _name = curWidget.getAttribute('name'); var _contentID = curWidget.getAttribute('contentID'); var _type = curWidget.getAttribute('widgetType'); var _iconSet = curWidget.getAttribute('iconSet'); var _commentLink = curWidget.getAttribute('commentLink'); var _moreLink = curWidget.getAttribute('moreLink'); if (_name == 'ratingWidget') { var _inner = curWidget.innerHTML; if (_contentID != null) { curWidget.content_id = _contentID; } else if (_inner) { curWidget.content_id = _inner; } else { curWidget.content_id = document.location.href; } curWidget.iconSet = _iconSet ? _iconSet : rb_default_icon_set; curWidget.commentLink = _commentLink ? _commentLink : 'off'; curWidget.moreLink = _moreLink ? _moreLink : 0; if (_type != null) { curWidget.widget_type = _type; } if (curWidget.widget_type == null) { curWidget.widget_type = 'rating'; } rb_widgets.push(curWidget); } } } rb_loadWidgets(); if (rb_load_count < 4) { rb_load_count += 1; setTimeout("rb_findWidgets()",1000); } else if (rb_load_count < 8) { rb_load_count += 1; setTimeout("rb_findWidgets()",10000); } } setTimeout("rb_findWidgets()",100); function rb_loadWidgets() { var content_ids = new Array(); for (var i = 0; i < rb_widgets.length; i++) { var curWidget = rb_widgets[i]; if (! curWidget.data_loaded) { curWidget.data_loaded = 1; content_ids.push(curWidget.content_id); } } if (content_ids.length > 0) { rb_dispatchJSON('getData',{ content_ids: content_ids }); } } function rb_setUser( data ) { rb_user = data; } function rb_setData( data ) { for (var i = 0 ; i < rb_widgets.length; i++) { var curWidget = rb_widgets[i]; if (curWidget.content_id == data.content_id) { curWidget.data = data; var allow_update = curWidget.allowUpdate ? curWidget.allowUpdate : 1; var HTML = '
'; curWidget.innerHTML = HTML; curWidget.starBox = curWidget.getElementsByTagName('td')[0]; rb_draw_stars(curWidget, -1); curWidget.style.display = ''; } } } function rb_findContainer (el) { var widgetBox = el; while ((widgetBox = widgetBox.parentNode) != null && !widgetBox.content_id) {} return widgetBox; } function rb_star_click (el,newRating) { var container = rb_findContainer(el); rb_dispatchJSON('setRating',{ content_id: container.content_id, rating: newRating }); container.data.userRating = newRating; rb_draw_stars(container, -1); return false; } function rb_star_over (el,num) { var container = rb_findContainer(el); rb_draw_stars(container, num); } function rb_star_out (el) { var container = rb_findContainer(el); rb_draw_stars(container, -1); } function rb_draw_stars(curWidget, userRating) { if (userRating == -1) { userRating = curWidget.data.userRating; } if (alphaPNGHack) { return rb_draw_stars_IE(curWidget, userRating); } var average_rating = curWidget.data.averageRating; var stars = curWidget.starBox.getElementsByTagName('IMG'); if (userRating > -1) { for (var i = 0; i < stars.length; i++) { if (i < userRating) { stars[i].src=curWidget.iconSet + "/star_yellow.png"; } else { stars[i].src=curWidget.iconSet + "/star_grey.png"; } } } else { for (var i = 0; i < stars.length; i++) { if (i < average_rating) { stars[i].src=curWidget.iconSet + "/star_red.png"; } else { stars[i].src=curWidget.iconSet + "/star_grey.png"; } } } } function rb_draw_stars_IE(curWidget, userRating) { var average_rating = curWidget.data.average_rating; var stars = curWidget.starBox.getElementsByTagName('SPAN'); if (userRating > -1) { for (var i = 0; i < stars.length; i++) { if (i < userRating) { stars[i].style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + curWidget.iconSet + "/star_yellow.png', sizingMethod='crop')"; } else { stars[i].style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + curWidget.iconSet + "/star_grey.png', sizingMethod='crop')"; } } } else { for (var i = 0; i < stars.length; i++) { if (i < average_rating) { stars[i].style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + curWidget.iconSet + "/star_red.png', sizingMethod='crop')"; } else { stars[i].style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + curWidget.iconSet + "/star_grey.png', sizingMethod='crop')"; } } } } function rb_moreLinkClick(link) { return rb_loadUIBox(link,'loadMoreBox'); } function rb_commentReadClick(link) { return rb_loadUIBox(link,'loadCommentReadBox'); } function rb_commentPostClick(link) { return rb_loadUIBox(link,'loadCommentPostBox'); } function rb_uiBoxCallBack(HTML,JS) { rb_uiBox.innerHTML = HTML; } function rb_loadUIBox(link, component) { var widgetBox = rb_findContainer(link); rb_uiBox.appendChild(rb_createLoadingBox()); if (rb_uiBox.parentNode) { rb_uiBox.parentNode.removeChild(rb_uiBox); } widgetBox.lastChild.appendChild(rb_uiBox); rb_dispatchJSON(component,{ content_id: widgetBox.content_id, Output: 'jscallback', Callback: 'rb_uiBoxCallBack' }); return false; } function rb_createLoadingBox () { var el = document.createElement('DIV'); //One day we can add a fancy loading box here el.innerHTML = ''; return el; } function rb_dispatchJSONForm (component,container) { var params = new Array(); var inputs = container.getElementsByTagName('INPUT'); for (var i = 0; i < inputs.length; i++) { params[inputs[i].name] = inputs[i].value; } var texts = container.getElementsByTagName('TEXTAREA'); for (var i = 0; i < texts.length; i++) { params[texts[i].name] = texts[i].value; } rb_dispatchJSON(component,params); } function rb_dispatchJSON (component,params) { var url = rb_widgetBase + '/' + component + '.html?'; params['user_id'] = rb_get_userID(); for (var key in params) { url += escape(key); url += '='; if (params[key] instanceof Array) { var vals = params[key]; for (var j in vals) { url += escape(vals[j]); url += ' '; } } else { url += escape(params[key]); } url += '&'; } url += 'random='; url += Math.random(); var headTag = document.getElementsByTagName("head").item(0); var scriptTag = document.createElement("script"); scriptTag.src = url; headTag.appendChild( scriptTag ); return false; } function rb_get_userID () { var uid = rb_getUserCookie(); if (uid == null) { uid = Math.random() * Math.random(); rb_setUserCookie(uid); } return uid; } function rb_getUserCookie() { var name = 'rb_user'; var start = document.cookie.indexOf( name + "=" ); var len = start + name.length + 1; if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) { return null; } if ( start == -1 ) return null; var end = document.cookie.indexOf( ";", len ); if ( end == -1 ) end = document.cookie.length; return unescape( document.cookie.substring( len, end ) ); } function rb_setUserCookie( uid ) { document.cookie = "rb_user="+uid+";expires=Fri, 01-Apr-2016 00:00:01 GMT;path=/"; }