﻿var ajaxRequest = null;
var ratings = '';
var numberOfRatings = 0;
var ratingPhrase = Array('Not rated', 'Poor', 'OK', 'Good', 'Very Good', 'Excellent');

function showRating(goodForTypeID, newRating) {
	newRating = parseInt(newRating);
	for (var i = 1; i <= newRating; i++) {
		document.getElementById('rating' + goodForTypeID + '_' + i).src = '/assets/skiresorts/images/starfull.gif';
		document.getElementById('rating' + goodForTypeID + '_' + i).alt = ratingPhrase[newRating];
	}
	for (var i = newRating + 1; i <= 5; i++) {
		document.getElementById('rating' + goodForTypeID + '_' + i).src = '/assets/skiresorts/images/staroutline.gif';
		document.getElementById('rating' + goodForTypeID + '_' + i).alt = ratingPhrase[newRating];
	}
}

function hideRating(goodForTypeID, hideSaving) {
	for (i in ratings) {
		if (ratings[i].id == goodForTypeID) {
			oldRating = ratings[i].rating;
		}
	}
	if (oldRating == 0) {
		for (var i = 1; i <= 5; i++) {
			document.getElementById('rating' + goodForTypeID + '_' + i).src = '/assets/skiresorts/images/stargrey.gif';
			document.getElementById('rating' + goodForTypeID + '_' + i).alt = ratingPhrase[oldRating];
		}
	} else {
		for (var i = 1; i <= oldRating; i++) {
			document.getElementById('rating' + goodForTypeID + '_' + i).src = '/assets/skiresorts/images/starfull.gif';
			document.getElementById('rating' + goodForTypeID + '_' + i).alt = ratingPhrase[oldRating];
		}
		for (var i = oldRating + 1; i <= 5; i++) {
			document.getElementById('rating' + goodForTypeID + '_' + i).src = '/assets/skiresorts/images/staroutline.gif';
			document.getElementById('rating' + goodForTypeID + '_' + i).alt = ratingPhrase[oldRating];
		}
	}
	if (hideSaving) {
		document.getElementById('saving' + goodForTypeID).style.display = 'none';
		document.getElementById('stars' + goodForTypeID).style.display = '';
	}
}

function saveRating(contactID, goodForTypeID, newRating) {
	ajaxRequest = jSki.ajax.createAjaxRequest();
	if (ajaxRequest) {
		for (i in ratings) {
			if (ratings[i].id == goodForTypeID) {
				ratings[i].rating = newRating;
			}
		}
		document.getElementById('stars' + goodForTypeID).style.display = 'none';
		document.getElementById('saving' + goodForTypeID).style.display = '';
		setTimeout('hideRating(' + goodForTypeID + ', true)', 500);
		var timestamp = new Date();
		jSki.ajax.sendAjaxRequest(ajaxRequest, '/skiclub/skiresorts/saverating.aspx?intContactID=' + contactID + '&intGoodForTypeID=' + goodForTypeID + '&intRating=' + newRating + '&timestamp=' + encodeURI(timestamp.toString()), null, null);
	}
}

function toggleReviewForm(showReviewConfirmation) {
	var formStyle = document.getElementById('rrReviewResort').style;
	if (formStyle.display == 'none') {
		if (showReviewConfirmation) {
			document.getElementById('rrReviewConfirmation').style.display = 'none';
		}
		formStyle.display = '';
	} else {
		formStyle.display = 'none';
	}
	return false;
}


