/**
 * Function: will take the span from the template files and replace the
 * text or images for the PRODUCT PAGE.
 */
function update_by_reviewer_status(reviewerType, whichSelect)
{
	// <span> specific to the sizing grey bar on the product page
	var span_size_count = document.getElementById('productSize');
	var span_size_total_count = document.getElementById('productSizeTotalCount');
	var span_size_text = document.getElementById('productSizeText');

	// <span> specific to the width grey bar on the product page
	var span_width_percent = document.getElementById('productWidth');
	var span_width_count = document.getElementById('productWidthTotalCount');
	var span_width_text = document.getElementById('productWidthText');

	// <span> specific to the 5 star images on the product page
	var span_star_rating = document.getElementById('starRating');
	var span_star_text = document.getElementById('starText');

	// <span> to see what pull-down was selected
	var sizeSelect = document.getElementById('sizeStatus');
	var widthSelect = document.getElementById('widthStatus');

	if (whichSelect == "SizeStatus") {
		if (widthSelect) {
			var choice = sizeSelect.selectedIndex;
			widthSelect.selectedIndex = choice;
		}
	} else if (whichSelect == "WidthStatus") {
		var choice = widthSelect.selectedIndex;
		sizeSelect.selectedIndex = choice;
	}

	// If no reviewerType was sent over (ie Player, Parent, Coach, Fan, Referee) then do nothing
	if(reviewerType)
	{
		// Accessing pre-defined variables from ProductReviewsAttributes.tem that contain
		// values that were coming over from the java bridge
		var sCount = reviewerTypeArray[reviewerType]['HighestSizeCount'];
		var sText = reviewerTypeArray[reviewerType]['HighestSizePercentText'];

		var wCount = reviewerTypeArray[reviewerType]['HighestWidthCount'];
		var wText = reviewerTypeArray[reviewerType]['HighestWidthPercentText'];

		var totalCount = reviewerTypeArray[reviewerType]['Count'];
		var rating = new String(reviewerTypeArray[reviewerType]['Rating']);

		var fsCount = fullReviewerTypeArray[reviewerType]['CountFullSizeSmall'];

		var hsCount = fullReviewerTypeArray[reviewerType]['CountHalfSizeSmall'];

		var tsCount = fullReviewerTypeArray[reviewerType]['CountTrueSize'];

		var hlCount = fullReviewerTypeArray[reviewerType]['CountHalfSizeLarge'];

		var flCount = fullReviewerTypeArray[reviewerType]['CountFullSizeLarge'];

		var nwCount = fullReviewerTypeArray[reviewerType]['CountNarrow'];

		var twCount = fullReviewerTypeArray[reviewerType]['CountTrue'];

		var wwCount = fullReviewerTypeArray[reviewerType]['CountWide'];

		var totalSizeReviews = fsCount + hsCount + tsCount + hlCount + flCount;
		var totalWidthReviews = nwCount + twCount + wwCount;

		// If this product's rating is -1 then that means there are no reviews for this reviewerType
		if (rating != "-1") {

			// Do condition checking to make sure the span exists before we try to replace it
			if (rating && span_star_rating) {
				// Need to format the product rating correctly to access the right 5 star image
				var formattedRating = (rating.match(".5")) ? rating.replace(".","-") : rating + "-0";
				var srcString = "";

				if (company == '01') {
					srcString = "http://www.soccer.com/review/images/stars-" + formattedRating + "-lg.png";
				}
				if (company == '03') {
					srcString = "http://www.lacrosse.com/review/images/stars_lax/stars-" + formattedRating + "-lg.png";
				}
				var altString = rating + " out of 5.0";

				// Creating the image tag to replace the exiting one contained in the <span>
				var starRating = document.createElement('img');
				starRating.setAttribute('src', srcString);
				starRating.setAttribute('alt', altString);
				starRating.setAttribute('class', '\"pngFix\"');
				starRating.setAttribute('width', '\"90\"');
				starRating.setAttribute('height', '\"20\"');
				span_star_rating.replaceChild(starRating,span_star_rating.firstChild);
			}
			if (span_star_text) {
				var cType = ( reviewerType == "All" ) ? ' ' : reviewerType + ':';
				var cText = document.createTextNode(cType);
				span_star_text.replaceChild(cText,span_star_text.firstChild);
			}
			if (sCount && span_size_count) {
				var textSizePercent = document.createTextNode(sCount);
				span_size_count.replaceChild(textSizePercent,span_size_count.firstChild);
			}
			if (totalSizeReviews && span_size_total_count) {
				var textSizeCount = document.createTextNode(totalSizeReviews);
				span_size_total_count.replaceChild(textSizeCount,span_size_total_count.firstChild);
			}
			if (sText && span_size_text) {
				var textSizePhrase = document.createTextNode(sText);
				span_size_text.replaceChild(textSizePhrase,span_size_text.firstChild);
			}
			if (wCount && span_width_percent) {
				var textWidthPercent = document.createTextNode(wCount);
				span_width_percent.replaceChild(textWidthPercent,span_width_percent.firstChild);
			}
			if (totalWidthReviews && span_width_count) {
				var textWidthCount = document.createTextNode(totalWidthReviews);
				span_width_count.replaceChild(textWidthCount,span_width_count.firstChild);
			}
			if (wText && span_width_text) {
				var textWidthPhrase = document.createTextNode(wText);
				span_width_text.replaceChild(textWidthPhrase,span_width_text.firstChild);
			}
		}
		// There are no reviews for this reviewerType - default to zeros and N/A
		else {
			if (rating && span_star_rating) {
				var formattedRating = rating.replace(".","-");
				var srcString = "";
				if (company == '01') {
					srcString = "http://www.soccer.com/review/images/stars-0-0-lg.png";
				}
				if (company == '03') {
					srcString = "http://www.lacrosse.com/review/images/stars_lax/stars-0-0-lg.png";
				}
				var altString = "0 out of 5.0";

				var starRating = document.createElement('img');
				starRating.setAttribute('src', srcString);
				starRating.setAttribute('alt', altString);
				starRating.setAttribute('class', '\"pngFix\"');
				starRating.setAttribute('width', '\"90\"');
				starRating.setAttribute('height', '\"20\"');

				span_star_rating.replaceChild(starRating,span_star_rating.firstChild);
			}
			if (span_star_text) {
				var cType = ( reviewerType == "All" ) ? ' ' : reviewerType + ':';
				var sText = document.createTextNode(cType);
				span_star_text.replaceChild(sText,span_star_text.firstChild);
			}
			if (span_size_count) {
				var textSizePercent = document.createTextNode("0");
				span_size_count.replaceChild(textSizePercent,span_size_count.firstChild);
			}

			if (span_size_total_count) {
				var textSizeCount = document.createTextNode("0");
				span_size_total_count.replaceChild(textSizeCount,span_size_total_count.firstChild);
			}

			if (span_size_text) {
				var textSizePhrase = document.createTextNode("N/A");
				span_size_text.replaceChild(textSizePhrase,span_size_text.firstChild);
			}

			if (span_width_percent) {
				var textWidthPercent = document.createTextNode("0");
				span_width_percent.replaceChild(textWidthPercent,span_width_percent.firstChild);
			}

			if (span_width_count) {
				var textWidthCount = document.createTextNode("0");
				span_width_count.replaceChild(textWidthCount,span_width_count.firstChild);
			}

			if (span_width_text) {
				var textWidthPhrase = document.createTextNode("N/A");
				span_width_text.replaceChild(textWidthPhrase,span_width_text.firstChild);
			}
		}
	}

}


/**
 * Function: will take the span from the template files and replace the
 * text or images for the sizing detail POP-UP WINDOW.
 */
function update_details_by_reviewer_status(typeOfReviewer)
{

	// <span> specific to the sizing count
	var div_full_small = document.getElementById('wrapFullSmall');
	var div_half_small = document.getElementById('wrapHalfSmall');
	var div_true_size = document.getElementById('wrapTrue');
	var div_half_large = document.getElementById('wrapHalfLarge');
	var div_full_large = document.getElementById('wrapFullLarge');
	var div_narrow = document.getElementById('wrapNarrow');
	var div_true_width = document.getElementById('wrapTrueWidth');
	var div_wide = document.getElementById('wrapWide');

	var div_empty = document.getElementById('empty');

	// If no reviewerType was sent over (ie Player, Parent, Coach, Fan, Referee) then do nothing
	if(typeOfReviewer)
	{
		// Accessing pre-defined variables from ProductReviewsAttributes.tem that contain
		// values that were coming over from the java bridge
		var fsCount = fullReviewerTypeArray[typeOfReviewer]['CountFullSizeSmall'];
		var fsPercent = fullReviewerTypeArray[typeOfReviewer]['PercentFullSizeSmall'];
		var fsAllCount = fullReviewerTypeArray[typeOfReviewer]['NumReviews'];

		var hsCount = fullReviewerTypeArray[typeOfReviewer]['CountHalfSizeSmall'];
		var hsPercent = fullReviewerTypeArray[typeOfReviewer]['PercentHalfSizeSmall'];
		var hsAllCount = fullReviewerTypeArray[typeOfReviewer]['NumReviews'];

		var tsCount = fullReviewerTypeArray[typeOfReviewer]['CountTrueSize'];
		var tsPercent = fullReviewerTypeArray[typeOfReviewer]['PercentTrueSize'];
		var tsAllCount = fullReviewerTypeArray[typeOfReviewer]['NumReviews'];

		var hlCount = fullReviewerTypeArray[typeOfReviewer]['CountHalfSizeLarge'];
		var hlPercent = fullReviewerTypeArray[typeOfReviewer]['PercentHalfSizeLarge'];
		var hlAllCount = fullReviewerTypeArray[typeOfReviewer]['NumReviews'];

		var flCount = fullReviewerTypeArray[typeOfReviewer]['CountFullSizeLarge'];
		var flPercent = fullReviewerTypeArray[typeOfReviewer]['PercentFullSizeLarge'];
		var flAllCount = fullReviewerTypeArray[typeOfReviewer]['NumReviews'];

		var nwCount = fullReviewerTypeArray[typeOfReviewer]['CountNarrow'];
		var nwPercent = fullReviewerTypeArray[typeOfReviewer]['PercentNarrow'];
		var nwAllCount = fullReviewerTypeArray[typeOfReviewer]['NumReviews'];

		var twCount = fullReviewerTypeArray[typeOfReviewer]['CountTrue'];
		var twPercent = fullReviewerTypeArray[typeOfReviewer]['PercentTrueWidth'];
		var twAllCount = fullReviewerTypeArray[typeOfReviewer]['NumReviews'];

		var wwCount = fullReviewerTypeArray[typeOfReviewer]['CountWide'];
		var wwPercent = fullReviewerTypeArray[typeOfReviewer]['PercentWide'];
		var wwAllCount = fullReviewerTypeArray[typeOfReviewer]['NumReviews'];

		var rating = new String(fullReviewerTypeArray[typeOfReviewer]['AveProdRating']);

		var totalSizeReviews = fsCount + hsCount + tsCount + hlCount + flCount;
		var totalWidthReviews = nwCount + twCount + wwCount;

		// If this product's rating is -1 then that means there are no reviews for this reviewerType
		if (rating != 'undefined' && rating != '-1') {

			if (div_empty) {
				div_empty.style.display="none";
			}

			if (fsCount != 'undefined' && fsCount != '0' && div_full_small) {
				var lineText = fsCount + ' of ' + totalSizeReviews + ' (' + fsPercent + '%) say this product runs a full size small.';
				var fsTxt = document.createTextNode(lineText);
				div_full_small.style.display="none";
				div_full_small.replaceChild(fsTxt,div_full_small.firstChild);
				div_full_small.style.display="block";
			} else {
				div_full_small.style.display="none";
			}
			if (hsCount != 'undefined' && hsCount != '0' && div_half_small) {
				var lineText = hsCount + ' of ' + totalSizeReviews + ' (' + hsPercent + '%) say this product runs a half size small.';
				var hsTxt = document.createTextNode(lineText);
				div_half_small.style.display="none";
				div_half_small.replaceChild(hsTxt,div_half_small.firstChild);
				div_half_small.style.display="block";
			} else {
				div_half_small.style.display="none";
			}
			if (tsCount != 'undefined' && tsCount != '0' && div_true_size) {
				var lineText = tsCount + ' of ' + totalSizeReviews + ' (' + tsPercent + '%) say this product runs true to size.';
				var tsTxt = document.createTextNode(lineText);
				div_true_size.style.display="none";
				div_true_size.replaceChild(tsTxt,div_true_size.firstChild);
				div_true_size.style.display="block";
			} else {
				div_true_size.style.display="none";
			}
			if (hlCount != 'undefined' && hlCount != '0' && div_half_large) {
				var lineText = hlCount + ' of ' + totalSizeReviews + ' (' + hlPercent + '%) say this product runs a half size large.';
				var hlTxt = document.createTextNode(lineText);
				div_half_large.style.display="none";
				div_half_large.replaceChild(hlTxt,div_half_large.firstChild);
				div_half_large.style.display="block";
			} else {
				div_half_large.style.display="none";
			}
			if (flCount != 'undefined' && flCount != '0' && div_full_large) {
				var lineText = flCount + ' of ' + totalSizeReviews + ' (' + flPercent + '%) say this product runs a full size large.';
				var flTxt = document.createTextNode(lineText);
				div_full_large.style.display="none";
				div_full_large.replaceChild(flTxt,div_full_large.firstChild);
				div_full_large.style.display="block";
			} else {
				div_full_large.style.display="none";
			}
			if (nwCount != 'undefined' && nwCount != '0' && div_narrow) {
				var lineText = nwCount + ' of ' + totalWidthReviews + ' (' + nwPercent + '%) say this product runs narrow.';
				var nwTxt = document.createTextNode(lineText);
				div_narrow.style.display="none";
				div_narrow.replaceChild(nwTxt,div_narrow.firstChild);
				div_narrow.style.display="block";
			} else {
				div_narrow.style.display="none";
			}
			if (twCount != 'undefined' && twCount != '0' && div_true_width) {
				var lineText = twCount + ' of ' + totalWidthReviews + ' (' + twPercent + '%) say this product runs true to width.';
				var twTxt = document.createTextNode(lineText);
				div_true_width.style.display="none";
				div_true_width.replaceChild(twTxt,div_true_width.firstChild);
				div_true_width.style.display="block";
			} else {
				div_true_width.style.display="none";
			}
			if (wwCount != 'undefined' && wwCount != '0' && div_wide) {
				var lineText = wwCount + ' of ' + totalWidthReviews + ' (' + wwPercent + '%) say this product runs wide.';
				var wwTxt = document.createTextNode(lineText);
				div_wide.style.display="none";
				div_wide.replaceChild(wwTxt,div_wide.firstChild);
				div_wide.style.display="block";
			} else {
				div_wide.style.display="none";
			}

		} else {
			/*var label=document.getElementById('wrapAll');
			while( label.hasChildNodes() ) {
				label.removeChild( label.lastChild );
			}*/

			if (div_empty) {
				div_empty.style.display="block";
			}

			if (div_full_small) {
				div_full_small.style.display="none";
			}
			if (div_half_small) {
				div_half_small.style.display="none";
			}
			if (div_true_size) {
				div_true_size.style.display="none";
			}
			if (div_half_large) {
				div_half_large.style.display="none";
			}
			if (div_full_large) {
				div_full_large.style.display="none";
			}
			if (div_narrow) {
				div_narrow.style.display="none";
			}
			if (div_true_width) {
				div_true_width.style.display="none";
			}
			if (div_wide) {
				div_wide.style.display="none";
			}
		}
	}
}