function writeReview(nBookId) {
	document.location = '/users/WriteReview.asp?BookId=' + nBookId;
}

function seeAll(nBookId) {
	document.location = '/users/ViewReviews.asp?BookId=' + nBookId;
}

function rateOver(nBookId, val, nPageType) {
	if (nPageType == 2) {
		if (val == 0) {
			document.getElementById('rate' + nBookId + '-1').src = '/images/ratings/' +  document.getElementById('orginal' + nBookId).value;
		}
		else {
			document.getElementById('rate' + nBookId + '-1').src = '/images/ratings/choose-' + val + '.png';
		}
	}
	else {
		if (val == 0) {
			document.getElementById('rate' + nBookId + '-1').src = '/images/ratings/' +  document.getElementById('orginal' + nBookId).value;
			document.getElementById('rate' + nBookId + '-2').src = '/images/ratings/' +  document.getElementById('orginal' + nBookId).value;
		}
		else {
			document.getElementById('rate' + nBookId + '-1').src = '/images/ratings/choose-' + val + '.png';
			document.getElementById('rate' + nBookId + '-2').src = '/images/ratings/choose-' + val + '.png';
		}	
	}
}

function rateReaderOver(val) {
	if (val == 0) {
		document.getElementById('rate').src = '/images/ratings/' +  document.getElementById('orginal').value;
	}
	else {
		document.getElementById('rate').src = '/images/ratings/choose-reader-' + val + '.gif';
	}
}

function rateBook(nBookId, nUserId, val) {
	document.getElementById('orginal' + nBookId).value = 'choose-' + val + '.png';
	xmlhttpPost('/users/RateBook.asp', 'UserId=' + nUserId + '&BookId=' + nBookId + '&Rating=' + val + '&rnd=' + (Math.random() * 1000), 'updateRating');
}

function updateRating (str){
var strArray = str.split('|');
var nAvg = Math.round(strArray[1] * 10) /10;
var strAvg = String(nAvg);

	document.getElementById('infoFirst' + strArray[0]).innerHTML = 'Your Rating:&nbsp;';
	if (strArray[2] == 1) {
		document.getElementById('infoLast' + strArray[0]).innerHTML = '<span class="size13dim">Rated ' + nAvg + ' by 1 Reader</span>';
	}
	else {
		document.getElementById('infoLast' + strArray[0]).innerHTML = '<span class="size13dim">Rated ' + ((strAvg.length == 1) ? strAvg + '.0' : strAvg) + ' by ' + strArray[2] + ' Readers</span>';
	}	
}

function rateReader(nBookId, nUserId, val) {
	document.getElementById('orginal').value = 'choose-reader-' + val + '.gif';
	xmlhttpPost('/users/RateBook.asp', 'UserId=' + nUserId + '&BookId=' + nBookId + '&Rating=' + val + '&rnd=' + (Math.random() * 1000), 'updateReaderRating');
}

function updateReaderRating (str){
var strArray = str.split('|');
var nAvg = Math.round(strArray[1] * 10) /10;
var strAvg = String(nAvg);

	document.getElementById('infoFirst' + strArray[0]).innerHTML = 'Your Rating';
	if (strArray[2] == 1) {
		document.getElementById('infoLast' + strArray[0]).innerHTML = '<span class="size11white">Rated ' + ((strAvg.length == 1) ? strAvg + '.0' : strAvg) + ' by 1 Reader</span>';
	}
	else {
		document.getElementById('infoLast' + strArray[0]).innerHTML = '<span class="size11white">Rated ' + ((strAvg.length == 1) ? strAvg + '.0' : strAvg) + ' by ' + strArray[2] + ' Readers</span>';
	}	
}

function washelpful(RecId, nUserId, bHelp){
var nHelp = (bHelp == 1 ) ? 1 : 0;
	document.getElementById('helpfulTD-' + RecId).innerHTML = '<span class="size11">Thanks for your feedback!</span>';
	xmlhttpPost('/users/washelpful.asp', 'RecId=' + RecId + '&UserId=' + nUserId + '&nHelp=' + nHelp + '&rnd=' + (Math.random() * 1000), 'updatehelpful');
}

function updatehelpful (str) {
var strArray = str.split('|');
var strHelpful = '';

	if ((strArray[2]  * 1) == 1 ) {
		if ((strArray[1] * 1) == 0) {
			strHelpful = 'No readers found this helpful (1 rating)'
		}
		else {
			strHelpful = '1 reader found this helpful (1 rating)'
		}
	}
	else {
		strHelpful = strArray[1] + ' of ' + strArray[2] + ' readers found this review helpful'
	}

	document.getElementById('help-' + strArray[0]).innerHTML = strHelpful;
}

function addPhoto() {
	alert('add photo')
}

function deleteReview(val) {
	alert('delete review' + val)
}
