/*
This script is copyright CouldBe Studios.
If you are interested in having this functionality added to your shopify website, 
please contact us at http://www.couldbestudios.com
*/

function buildReview(handle)
	{
	//build the review elements
	document.getElementById('comment_body').value = "(prod_id|"+handle+"|)";
	document.getElementById('comment_body').value += document.getElementById('rating').value;
	document.getElementById('comment_body').value += "\r\n(prod_comment|"+document.getElementById('the_comment_body').value+"|)";
	return true;
	}
function expandReviewForm()
	{
	document.getElementById('reviewform').style.height='640px';
	document.getElementById('addreview').style.display='none';
	}

function getTheReviews()
	{
		var theReviews = document.getElementById('reviewblock');
		var theSpans = theReviews.getElementsByTagName('span');
		var spanCount = theSpans.length;
		var starCount = 0;
		for(i=0; i<theSpans.length; i++)
		{
		if(theSpans[i].className == 'stars-1')
		  {
		  starCount = starCount+1;
		  }
		if(theSpans[i].className == 'stars-2')
		  {
		  starCount = starCount+2;
		  }
		if(theSpans[i].className == 'stars-3')
		  {
		  starCount = starCount+3;
		  }
		if(theSpans[i].className == 'stars-4')
		  {
		  starCount = starCount+4;
		  }
		var theAverage = starCount/spanCount;
		document.getElementById('average-rating').innerHTML = Math.round(theAverage) + " stars ("+ spanCount +" reviews)";
		document.getElementById('average-rating').className = "stars-"+Math.round(theAverage);
		}
	}