(function(){function navigateToUrl(evt){evt.preventDefault();var target=$(evt.target);var href=target.attr("href")||"";href+="&appAction="+AdblGlobal.getPageAction()+"&appActionToken="+AdblGlobal.getPageActionToken();document.location=href;return false}$(function(){$(".adbl-add").click(navigateToUrl);$(".adbl-questions").click(AdblGlobal.popupFormats);if($(".adbl-page-index a.adbl-link").length>0){AdblGlobal.enableAjaxPagination($(".adbl-reviews").parent())}var xpressPayLink=$("#adbl_pd_xpress_link");if(xpressPayLink.length>0){xpressPayLink.click(xpressPay)}function xpressPay(evt){evt.preventDefault();$('form[id="adbl_pd_xpress_form"]').submit()}})})();

(function(){var maxCharLen=2000;var minCharLen=25;function reviewEditCallback(evt){var target=$(evt.target);updateReviewTextCount(target)}function updateReviewTextCount(target){var reviewText=target.val();var charLen=reviewText.length;if(charLen>maxCharLen){$(".adbl-error").html("Maximum review length reached. Your message has been shortened to "+maxCharLen+" characters.");$(".adbl-error").attr("style","display:block");target.val(reviewText.substr(0,maxCharLen));charLen=maxCharLen}$("#adbl_char_count").val(charLen)}function submitFormForPreview(evt){evt.preventDefault();var noRating=$("#adbl_write_review ul label")[0];var noTitle=$("#adbl_write_review ul label")[1];var noReview=$("#adbl_write_review ul label")[2];var showError=false;var errorMsg="Please enter all the required details below.<br/>You need to rate the item and enter a title and some review text before you can preview.";var curRating=$(".adbl-rating-act-cont").attr("rating");if(curRating<1){showError=true;noRating.style.color="red"}if($("#adbl_review_title").val().length==0){showError=true;noTitle.style.color="red"}if($("#adbl_review_text").val().length==0){showError=true;noReview.style.color="red"}if($("#adbl_review_text").val().length<minCharLen||$("#adbl_review_text").val().split(" ").length<15){showError=true;noReview.style.color="red"}var text=$("#adbl_review_text").val();text=text.replace(/(<([^>]+)>)/ig,"");$("#adbl_review_text").val(text);if(showError){$(".adbl-write-review-error").show();$(".adbl-error").html(errorMsg);$(".adbl-error").attr("style","display:block")}else{$("#adbl_review_rating").val(curRating);$('form[name="adbl_write_review"]').submit()}}function editReview(evt){$('input[name="appAction"]').val("createReview");$('form[name="adbl_save_review"]').submit()}function saveReview(evt){$('form[name="adbl_save_review"]').submit()}function showFlyout(evt){evt.preventDefault();evt.stopPropagation();var target=$(evt.target);var qualityElm=target.parent();var reviewId=qualityElm.attr("rid");var authorId=qualityElm.attr("aid");var asin=qualityElm.attr("asin");var left=target.position().left;var top=target.position().top;$(".adbl-review-flyout").removeData("voteParams");$(".adbl-review-flyout").data("voteParams",{reviewId:reviewId,authorId:authorId,asin:asin,voteValue:2});$(".adbl-review-flyout").data("qualityElm",qualityElm);$(".adbl-review-flyout").css("left",left+65);$(".adbl-review-flyout").css("top",top-108);$(".adbl-review-flyout").css("display","inline");$(".adbl-review-flyout").css("position","absolute")}function showGuideLineFlyout(evt){evt.preventDefault();evt.stopPropagation();var target=$(evt.target);var left=target.offset().left;var top=target.offset().top;$(".adbl-reviewguideline-flyout").css("left",left-20);$(".adbl-reviewguideline-flyout").css("top",top-120);$(".adbl-reviewguideline-flyout").css("display","inline");$(".adbl-reviewguideline-flyout").css("position","absolute")}function hideFlyout(evt){evt.preventDefault();$(".adbl-review-flyout").css("display","none");$(".adbl-review-report").css("display","inline");$(".adbl-review-report-finish").css("display","none");var target=$(evt.target);if(target.hasClass("adbl-review-flyout-close")){var qualityelm=$(".adbl-review-flyout").data("qualityElm");$(qualityelm).html("You have voted on this review.")}}function sendReport(evt){evt.preventDefault();var reviewId=$(".adbl-review-flyout").data("voteParams").reviewId;var authorId=$(".adbl-review-flyout").data("voteParams").authorId;var asin=$(".adbl-review-flyout").data("voteParams").asin;var voteValue=$(".adbl-review-flyout").data("voteParams").voteValue;postVoteOnReview(reviewId,authorId,asin,voteValue);$(".adbl-review-report-finish").css("display","inline");$(".adbl-review-report").css("display","none")}function postVoteOnReview(reviewId,authorId,asin,voteValue){var appAction=$("input:[name='appAction']").attr("value");var appActionToken=$("input:[name='appActionToken']").attr("value");var dest="/vote-review";var postData={rid:reviewId,aid:authorId,appAction:appAction,appActionToken:appActionToken,vote:voteValue,asin:asin};$.post(dest,postData,function dataLoaded(data,textStatus){})}function voteHelpfulness(evt){evt.preventDefault();evt.stopPropagation();var target=$(evt.target);target=target.parent();if(target.hasClass("adbl-yes")||target.hasClass("adbl-no")){var qualityElm=target.parent();var reviewId=qualityElm.attr("rid");var authorId=qualityElm.attr("aid");var asin=qualityElm.attr("asin");var voteValue=-1;if(target.hasClass("adbl-yes")){voteValue=1}var appAction=$("input:[name='appAction']").attr("value");var appActionToken=$("input:[name='appActionToken']").attr("value");var dest="/vote-review";var postData={rid:reviewId,aid:authorId,appAction:appAction,appActionToken:appActionToken,voteValue:voteValue,asin:asin};$.post(dest,postData,function dataLoaded(data,textStatus){var parentElm=$(target).parents(".adbl-review");parentElm.find(".adbl-review-helpfulness").html(data);parentElm.find(".adbl-review-quality").html("You have voted on this review.")})}}function authorReviewDropDownChange(evt){var sortby=$(".adbl-authreview-sortby").val();var pagesize=$(".adbl-authreview-pagesize").val();var pagenum;pagenum=1;var asin=$(".adbl-authreview-parent").data("asin");var url=window.location+"&sortby="+sortby+"&pagesize="+pagesize+"&page="+pagenum;url=url.toString().replace("review-by-author","get-author-review");fetchReviewsAjax(url,"adbl-authreview-parent")}function authorReviewPagination(evt){evt.preventDefault();var target=$(evt.target);var sortby=$(".adbl-authreview-sortby").val();var pagesize=$(".adbl-authreview-pagesize").val();var asin=$(".adbl-authreview-parent").data("asin");var url=target.attr("href")+"&sortby="+sortby+"&pagesize="+pagesize+"&asin="+asin;fetchReviewsAjax(url,"adbl-authreview-parent")}function fetchReviewsAjax(url,destContainer){$.get(url,function dataLoaded(data,textStatus){if(textStatus!=="success"){alert("Error fetching reviews")}else{$("."+destContainer).html(data);setupAuthReviewAjax();if($("#center_8").size()>0){window.scrollTo(0,$("#center_8").offset().top)}}})}function setupAuthReviewAjax(){$(".adbl-page-index").find(".adbl-page-link").each(function(index){$(this).bind("click",authorReviewPagination)});$(".adbl-page-index").find(".adbl-page-prev").each(function(index){$(this).bind("click",authorReviewPagination)});$(".adbl-page-index").find(".adbl-page-next").each(function(index){$(this).bind("click",authorReviewPagination)})}function registerProdIdForAuthReviewPage(){if($(".adbl-authreview-parent").length>0){var url=$(".adbl-prod-image-sample-cont a:first").attr("href");var asin=(url.split("="))[1];$(".adbl-authreview-parent").data("asin",asin)}}function showWriteReviewLinks(evt){evt.preventDefault();evt.stopPropagation();var target=$(evt.target);if(target.html().match("guidelines")){showGuideLineFlyout(evt)}else{if(target.html().match("sample reviews")){AdblGlobal.popupWindow("http://"+document.location.host+"/review-sample","","reviewsamples","resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no,scrollbars=yes,status=no,width=800,height=520","0","0")}else{var url="http://"+document.location.host;url+=target.attr("href");window.location.href=url}}}var clearWriteReviewError=function(evt){$("#adbl_write_review ul label").attr("style","color:#000;");$(".adbl-write-review-error").hide()};function enableAjaxPaginationPDPage(destContainer){$(".adbl-page-index a.adbl-link").bind("click",fetchReviewsAjax);$(".adbl-review-quality .adbl-link").each(function(){$(this).bind("click",showFlyout)});$(".adbl-review-quality").bind("click",voteHelpfulness);$(".adbl-review-flyout-cancel").bind("click",hideFlyout);$(".adbl-review-flyout-report").bind("click",sendReport);$(".adbl-review-flyout-close").bind("click",hideFlyout);function fetchReviewsAjax(evt){evt.preventDefault();var dest=$(this).attr("href");$.get(dest,function dataLoaded(data,textStatus){if(textStatus!=="success"){alert("Error fetching reviews")}else{$(".adbl-page-index a.adbl-link").unbind("click",fetchReviewsAjax);$(destContainer).html(data);enableAjaxPaginationPDPage(destContainer)}})}}$(function(){$(".adbl-authreview-sortby").bind("change",authorReviewDropDownChange);$(".adbl-authreview-pagesize").bind("change",authorReviewDropDownChange);$("#adbl_review_text").keyup(reviewEditCallback);$("#adbl_review_text").blur(reviewEditCallback);$("#adbl_preview").click(submitFormForPreview);$("#adbl_edit_review").click(editReview);$("#adbl_save_review").click(saveReview);$("#adbl_review_title").bind("focus",clearWriteReviewError);$("#adbl_review_text").bind("focus",clearWriteReviewError);$(".adbl-write-review-intro .adbl-link").each(function(){$(this).bind("click",showWriteReviewLinks)});$(".adbl-reviewguideline-close").click(function(){$(".adbl-reviewguideline-flyout").hide()});setupAuthReviewAjax();registerProdIdForAuthReviewPage();$(".adbl-page-index a.adbl-link").unbind("click",fetchReviewsAjax);enableAjaxPaginationPDPage($(".adbl-reviews").parent())})})();


