 document.domain = "sherwin-williams.com";  
   
 function ratingsDisplayed(totalReviewsCount, avgRating, ratingsOnlyReviewCount, recommendPercentage, productID)  
 {  
     if (totalReviewsCount > 0) {  
         var bvRevCntr = document.getElementById("BVReviewsContainer");  
         if (bvRevCntr) { bvRevCntr.style.display = "block"; }  
     }  
     // Other custom items leveraging these values.  
     // TODO: insert Web Analytics tracking here  

	var bazaarVoice = {
		config : {
			loggedIn : $('#logged-in'), 
			loggedOut : $('#logged-out'), 
			bvActionLinks : $('#BVRRRatingSummaryLinkWriteID a, #BVRRRatingSummaryLinkWriteFirstID a, .BVRRReviewFeedbackLink a'),
 			bazaarWidget : $("a[href='#BVRRWidgetID']"),
			feedback : $('.BVRRReviewFeedbackLink a'),
			ratingStars : $('#BVRRSubmissionLink'),
			ratingsAndReviews : $('#BVRRRatingSummaryLinkWriteID a'),
			noratingsAndReviews : $('#BVRRRatingSummaryLinkWriteFirstID a'),
			numberOfRatings : $('#BVRRRatingSummaryLinkReadID a'),
			windowLocation : escape(window.location.href)
		},
		helpers : {
			getEnvr : function(){
				var full = window.location.host;
				var parts = full.split('.');
				var sub = parts[0];
				return sub;
			},
			createCookie: function(cookieName, cookieValue, daysTillExpire){
				if(!daysTillExpire){ 
					document.cookie=cookieName+"="+cookieValue+"; expires=''; path=/";
				}else{
					var date = new Date();
					date.setTime(date.getTime()+(daysTillExpire*24*60*60*1000));
					var expires = "expires="+date.toGMTString();
					document.cookie=cookieName+"="+cookieValue+";"+expires+"; path=/";
				}			
			},
			getCookie: function(cookieName, cookieValue){
				(cookieValue === undefined) ? cookieValue = '.*' : cookieValue = cookieValue;
				var re = new RegExp(cookieName+'=('+cookieValue+')', 'g');
				var cookies = document.cookie.split(';');
				var cookieFound = 0;
				for(i=0; i<cookies.length; i++){
					if(cookies[i].match(re)){
						cookieFound = 1;
						var cookieVal=cookies[i].split(cookieName + '=');
						return cookieVal[1];
					}
				}
				if(cookieFound === 0 ){
					return null;
				}
			},
			deleteCookie : function(cookieName){
				bazaarVoice.helpers.createCookie(cookieName,"",-1);
			}
		},
		init : {
			logInState : function(){
				if(bazaarVoice.config.loggedOut.length > 0){
					bazaarVoice.config.bvActionLinks.each(function(){
						var url= $(this).attr('href');
						if($(this).length > 0){
							$(this)
							.removeAttr('target')
							.removeAttr('name')
							//Change the .attr to the appropriate url when this is ready for stage
							.attr('href', 'https://'+bazaarVoice.helpers.getEnvr()+'.sherwin-williams.com/account/login/?persisted=productPage&productPage=true&postAuthUrl='+bazaarVoice.config.windowLocation)
							.click(function(){
								bazaarVoice.helpers.createCookie('bvoverlay', url);
							});
						}
					});
				}else if(bazaarVoice.config.loggedIn.length > 0){
					if(bazaarVoice.helpers.getCookie('bvoverlay') != null){
						//Shows the overlay if the user succussfully logs in and is redirected from the login page.
		       				ol_show('', bazaarVoice.helpers.getCookie('bvoverlay'), '');
							bazaarVoice.helpers.deleteCookie('bvoverlay');
					}	
			
					//Initializes the overlay for the 'Rate and Review' this product links and the 'yes', 'no', and 'report as inappropriate' links.
					bazaarVoice.config.bvActionLinks.each(
						function(){
		 					var url= $(this).attr('href');
							$(this)
								.removeAttr('target')
								.removeAttr('name')
						});
					if(bazaarVoice.config.ratingsAndReviews.length > 0){
						ol_init(bazaarVoice.config.ratingsAndReviews.selector);
					}
					if(bazaarVoice.config.feedback.length > 0){
						ol_init(bazaarVoice.config.feedback.selector);
					}
					if(bazaarVoice.config.noratingsAndReviews.length > 0){
						ol_init(bazaarVoice.config.noratingsAndReviews.selector);
					}
				}
			},
			cleanupBVCode : function(){
   				bazaarVoice.config.bazaarWidget.removeAttr('href');
				bazaarVoice.config.ratingStars.removeAttr('href');
				bazaarVoice.config.numberOfRatings.removeAttr('href');
			},
			turnAutoCompleteOff : function(){
				window.onload=function(){
					$('#BVRRFieldTextReviewTitleID').attr('autocomplete', 'off');
				}
			}
		}
	};
	for(var prop in bazaarVoice.init){ 
		bazaarVoice.init[prop]();
	}
}



 


