/*****************************************************************************/
/*                                                                           */
/* SCRIPT                                                                    */
/*   view_detail.js                                                          */
/*                                                                           */
/* TYPE                                                                      */
/*   javascript library                                                      */
/*                                                                           */
/* DESCRIPTION                                                               */
/*   photo detail rating and comment form validation                         */
/*                                                                           */
/*****************************************************************************/

/*                                                                           */
/* translate the mouse position over the rating div to the rating value and  */
/* update the information on the page                                        */
/*                                                                           */
function mouseOverRating(e) {
	var sourceElement;
	var fullWidth
	var mousePosition;
	if (e) {	/* firefox */
		sourceElement = e.target;
		fullWidth = sourceElement.clientWidth;
		mousePosition = e.clientX - sourceElement.offsetLeft;
	} else {	/* ie */
		sourceElement = event.srcElement;
		fullWidth = sourceElement.clientWidth;
		mousePosition = event.offsetX;
	}
	setRating(Math.ceil((mousePosition / fullWidth) * 5))
}
/*                                                                           */
/* reset the rating to 0 (not rated) if the mouse leaves the rating div      */
/*                                                                           */
function mouseOutRating(e) {
	setRating(0);
}
/*                                                                           */
/* show the current rating in the images and hidden field                    */
/*                                                                           */
function setRating(ratingValue) {
	var className = 'rating' + ratingValue;
	document.getElementById('rating').value = ratingValue;
	if (document.getElementById('ratingimagetop'))
	{
		if (document.getElementById('ratingimagetop').className != className) {
			document.getElementById('ratingimagetop').className = className;
			document.getElementById('ratingimagetop').style.cursor = 'hand';
			document.getElementById('ratingimagetop').title = ratingLabels[ratingValue];
			document.getElementById('ratingtexttop').innerHTML = '[' + ratingLabels[ratingValue] + ']';
		}
	}
	if (document.getElementById('ratingimagebottom'))
	{
		if (document.getElementById('ratingimagebottom').className != className) {
			document.getElementById('ratingimagebottom').className = className;
			document.getElementById('ratingimagebottom').style.cursor = 'hand';
			document.getElementById('ratingimagebottom').title = ratingLabels[ratingValue];
			document.getElementById('ratingtextbottom').innerHTML = '[' + ratingLabels[ratingValue] + ']';
		}
	}
}

/*                                                                           */
/* submit the rating form if a rating was set by the mouseOverRating()       */
/* function                                                                  */
/*                                                                           */
function clickRating() {
	if (document.getElementById('rating').value > 0) {
		document.getElementById('ratingform').submit();
	}
}
/*                                                                           */
/* check all the fields                                                      */
/*                                                                           */
function validateForm() {
	formHasErrors = false;
	var value = document.getElementById('comment').value;
	var ruleExpression = new RegExp('\\S+');
	error('comment', 'commentInvalid', ! ruleExpression.test(value));
	return ! formHasErrors;
}
/*                                                                           */
/* move focus to the sign in form's username                                 */
/*                                                                           */
function focusSignin() {
	if (document.getElementById('username')) {
		document.getElementById('username').focus();
		window.scrollTo(0, 0);
	}
}
/*                                                                           */
/* show or hide extra comments                                               */
/*                                                                           */
function showExtraComments(showMore) {
	document.getElementById('showMore').style.display = (showMore ? 'none' : 'block');
	document.getElementById('commentsExtra').style.display = (showMore ? 'block' : 'none');
}

/*                                                                           */
/* submit the category form                                                  */
/*                                                                           */
function submitCategoryForm() {
	var categoryOption = document.getElementById('categoryid').selectedIndex;
	var categoryId = document.getElementById('categoryid').options[categoryOption].value;
	var categoryTitle = textForUrl(document.getElementById('categoryid').options[categoryOption].text);

	var newUrl = '';
	if (categoryOption > 0) {
		newUrl += '/' + seoFolderCategory + '/' + categoryId + '/' + categoryTitle + '.html';
	} else {
		newUrl += '/' + seoFolderCategory + '/' + categoryTitle + '.html';
	}
	location = newUrl;
}
