var prClientDomain = "http://myaccount.pureformulas.com/";
var prClientName = "PureFormulas.com";
var prClientSkin = "standard";
var prDebug = false;

/***************************************/
/******** UTILITY FUNCTIONS ************/
/***************************************/
function prIsBlank(item) {
	item = String(item).toLowerCase();
	if(item == "undefined" || item == "" || item == "null") return true;
	else return false;
}
/****************************************************/
/******** DISPLAY ITEM PAGE RATING STARS ************/
/****************************************************/
function prItemRatingDisplay(){
	if(prDebug){alert("ratingDisplay");}
	var prItemRating = document.getElementById('prItemRating');
	if(prItemRating){
		html = '';
		if(pdPrOverall.reviewCount > 0){
			if(pdPrOverall.reviewCount > 1){var prS = "s"}else{var prS = "";}
			html += '<table><tr>';
			html += '<td><a href="' + prClientDomain + 'mod_productReviews/reviewForm.php?productId=' + pdPrOverall.productId + '">';
			html += '<img src="' + prClientDomain + 'mod_productReviews/skins/' + prClientSkin + '/images/ratings/item/' + pdPrOverall.rating + '.gif" border="0">';
			html += '</a></td>';
			html += '<td>(<a href="#reviews" onclick="turnonreviewtab()">';
			html += pdPrOverall.reviewCount;
			html += ' review';
			if(pdPrOverall.reviewCount > 1){html += 's';}
			html += '</a> -  <a href="' + prClientDomain + 'mod_productReviews/reviewForm.php?productId=' + pdPrOverall.productId + '">Submit a Review)</a></td>';
			html += '</tr></table>';
			prItemRating.innerHTML = html;
		}else{
			prItemRating.innerHTML = html;
			html += 'Rate & Review this Item';
		}
	}
	if(prDebug){alert("ratingDisplay");}
}

function prProductReviewsDisplay(){
	if(prDebug){alert("prProductReviews");}
	
	var prProductReviews = document.getElementById('prProductReviewsDisplay');
	if(prProductReviews){
		
		var html = '';
		/*******************************************/
		/*********** FORMAT OVERALL INFO ***********/
		/*******************************************/
        html += '<div id="prOverallRatingTitle" class="prOverallRatingTitle">';
        html += '<h5>Overall Rating for ' + pdPrOverall.productName + '</h5>';
        html += '</div>';
		
		html += '<div id="prOverallRating" class="prOverallRating"><table><tr>';
		if(pdPrOverall.reviewCount > 0){
			html += '<td><a href="' + prClientDomain + 'mod_productReviews/reviewForm.php?productId=' + pdPrOverall.productId + '"><img src="' + prClientDomain + 'mod_productReviews/skins/' + prClientSkin + '/images/ratings/overall/' + pdPrOverall.rating + '.gif" border="0"></a></td>';
			html += '<td>(based on ';
			html += pdPrOverall.reviewCount;
			html += ' review';
			if(pdPrOverall.reviewCount > 1){html += 's';}
			html += ')</td>';
			html += '<td><a href="' + prClientDomain + 'mod_productReviews/reviewForm.php?productId=' + pdPrOverall.productId + '"><img src="' + prClientDomain + 'mod_productReviews/skins/' + prClientSkin + '/images/butItemReview.gif" class="prButItemReview" border="0"></a></td>';
		}
		else{
			html += '<td><a href="' + prClientDomain + 'mod_productReviews/reviewForm.php?productId=' + pdPrOverall.productId + '"><img src="' + prClientDomain + 'mod_productReviews/skins/' + prClientSkin + '/images/noRatings.gif" border="0"></a></td>';
			html += '<td>(no reviews)</td>';
			html += '<td><a href="' + prClientDomain + 'mod_productReviews/reviewForm.php?productId=' + pdPrOverall.productId + '"><img src="' + prClientDomain + 'mod_productReviews/skins/' + prClientSkin + '/images/butItemReview.gif" class="prButItemReview" border="0"></a></td>';
		}
		html += '</tr></table></div>';

		/*******************************************/
		/*********** FORMAT REVIEW HTML ************/
		/*******************************************/
		for(var i=0; i < pdPr.length; i++){
	
			html += '<div class="prListWrapper">';

			//******** REVIEW TITLE/RATING/LOCATION *******//
			html += '<div class="prListTitle">';
			//******** VERIFIED BUYER *******//
			if(pdPr[i].isVerifiedBuyer == 1){
				html += '<div class="prVerifiedBuyer"><img src="' + prClientDomain + 'mod_productReviews/skins/' + prClientSkin + '/images/iconVb.gif" border="0"></div>';
			}

			if(!prIsBlank(pdPr[i].reviewTitle)){html += '<h5>' + pdPr[i].reviewTitle + '</h5>';}
			
			html += '<h6>';
			if(pdPr[i].rating && pdPr[i].rating > 0){html += '<img src="' + prClientDomain + 'mod_productReviews/skins/' + prClientSkin + '/images/ratings/reviews/' + pdPr[i].rating + '.gif" border="0">';}
			if(!prIsBlank(pdPr[i].name)){html += 'By <span>' + pdPr[i].name + '</span>';}
			if(!prIsBlank(pdPr[i].location)){html += ' from <span>' + pdPr[i].location + '</span>';}
			if(!prIsBlank(pdPr[i].dateSubmitted)){html += ' on <span>' + pdPr[i].dateSubmitted + '</span>';}
			html += '</h6>';
			html += '<div class="clear">&nbsp;</div></div>';
			html += '<img src="' + prClientDomain + 'mod_productReviews/skins/' + prClientSkin + '/images/reviewBubbleArr.gif" border="0" class="prListBubbleArr">';
			
			//******** REVIEW BODY *******//
			if(!prIsBlank(pdPr[i].reviewBody)){html += pdPr[i].reviewBody + '<br clear="all">';}

			//******** REVIEW PROS & CONS *******//
			if(!prIsBlank(pdPr[i].reviewPros)){html += '<div class="prListPros"><h5>Pros:</h5>' + pdPr[i].reviewPros + '</div>';}
			if(!prIsBlank(pdPr[i].reviewCons)){html += '<div class="prListCons"><h5>Cons:</h5>' + pdPr[i].reviewCons + '</div>';}
			
			//******** REVIEW PHOTOS *******//
			if(!prIsBlank(pdPr[i].img1) || !prIsBlank(pdPr[i].img2) ||  !prIsBlank(pdPr[i].img3)){
				html += '<br clear="all"><div class="prReviewPhotos">';
				if(!prIsBlank(pdPr[i].img1) && pdPr[i].img1 != "error.jpg"){
					html += '<a href="';
					html += prClientDomain + 'mod_productReviews/userReviewImages/large-' + pdPr[i].img1;
					html += '" target="_blank">';
					html += '<img src="' + prClientDomain + 'mod_productReviews/userReviewImages/small-' + pdPr[i].img1 + '" border="0">';
					html += '</a>';
				}
				if(!prIsBlank(pdPr[i].img2) && pdPr[i].img2 != "error.jpg"){
					html += '<a href="';
					html += prClientDomain + 'mod_productReviews/userReviewImages/large-' + pdPr[i].img2;
					html += '" target="_blank">';
					html += '<img src="' + prClientDomain + 'mod_productReviews/userReviewImages/small-' + pdPr[i].img2 + '" border="0">';
					html += '</a>';
				}
				if(!prIsBlank(pdPr[i].img3) && pdPr[i].img3 != "error.jpg"){
					html += '<a href="';
					html += prClientDomain + 'mod_productReviews/userReviewImages/large-' + pdPr[i].img3;
					html += '" target="_blank">';
					html += '<img src="' + prClientDomain + 'mod_productReviews/userReviewImages/small-' + pdPr[i].img3 + '" border="0">';
					html += '</a>';
				}
				html += '</div>';
			}

			//******** MERCHANT RESPONSE *******//
			if(!prIsBlank(pdPr[i].response)){html += '<br clear="all"><div class="prMerchantResponse"><h5>Merchant Response:</h5>' + pdPr[i].response + '</div>';}
		
			//******** RECOMMENDED *******//
			if(pdPr[i].isRecommended){html += '<br clear="all"><div class="prListRecommend"><h5>I would recommend this item to a friend.</h5></div>';}

			html += '<br clear="all"></div><br clear="all">'; //**** CLOSE WRAPPING DIV
		}
	
	}
	prProductReviews.innerHTML = html;
}

