function on(val) {

   // get specific div item, identified by node index
   var itm = document.getElementById(val);
   var txt = document.getElementById(val+"text");
  
   // turn on menu tip display
   txt.style.display="block";

   // set style properties
   //itm.style.backgroundColor="green";
   //itm.style.color="yellow"
   //itm.style.fontWeight = 700;
      
}

// turn off menu highlighting
function off(val) {

   // get specific div item, identified by node index
   var itm = document.getElementById(val);
   var txt = document.getElementById(val+"text");

   // turn off menu tip display
   txt.style.display="none";

   // set style properties
   itm.style.backgroundColor="white";
   itm.style.color="black"
   itm.style.fontWeight = 400;
   txt.style.display="none";
}


var rating_img = '/images/star.gif';
var rating_img_bg = '/images/star_bg.gif';

function myRating(maxStars, objectName, formName, ratingMessageId, componentSuffix, tid, noOfRatingsTag)
{
	this.maxStars = maxStars;
	this.objectName = objectName;
	this.formName = formName;
	this.ratingMessageId = ratingMessageId;
	this.componentSuffix = componentSuffix;

	this.starTimer = null;
	this.starCount = 0;
	
	this.noOfRatingsTag = noOfRatingsTag;
	

	this.tid = tid;
	
	this.delay = 250;	
	// pre-fetch image
	(new Image()).src = rating_img;


	function showStars(starNum, skipMessageUpdate) {
		

			this.clearStarTimer();
			this.greyStars();
			this.colorStars(starNum);
			if(!skipMessageUpdate)
				this.setMessage(starNum);
	}

	function setMessage(starNum) {
		messages = new Array("Rate this picture", "Poor shot", "Below Average", "Average", "Good shot", "Excellent!");
		document.getElementById(this.ratingMessageId).innerHTML = messages[starNum];
	}

	function colorStars(starNum) {
		for (var i=0; i < starNum; i++)
			document.getElementById(this.objectName + 'star_'  + this.componentSuffix + "_" + (i+1)).src = rating_img;
	}

	function greyStars() {
		for (var i=0; i < this.maxStars; i++) {
			if (i <= this.starCount)
				document.getElementById(this.objectName + 'star_' + this.componentSuffix + "_"  + (i+1)).src = rating_img_bg;
			else
				document.getElementById(this.objectName + 'star_' + this.componentSuffix + "_"  + (i+1)).src = rating_img_bg;
		}
	}

	function setStars(starNum) {
		this.starCount = starNum;
		this.drawStars(starNum);
		document.forms[this.formName]['rating'].value = this.starCount;

		
  	var url = "/servlet/TravelExpRatingsServlet?tid=" + escape(this.tid) + "&rating=" + escape(document.forms[this.formName]['rating'].value);
		
		getUrl(url, true, function (req) { updatePage(req, ratingMessageId, noOfRatingsTag, objectName); });

	}

function updatePage(xmlHttpRequest, dstDivId, noOfRatingsTag, objectName)
{
	if (xmlHttpRequest.readyState == 4) {
       if (xmlHttpRequest.status == 200) {

  		 		var dstDiv = document.getElementById(dstDivId);
  		 		dstDiv.innerHTML = "Thanks!";
					//dstDiv.innerHTML = xmlHttpRequest.responseText;
				}
				
				if (xmlHttpRequest.responseText == 1) {
  					var dstDiv2 = document.getElementById(noOfRatingsTag);
  					dstDiv2.innerHTML = xmlHttpRequest.responseText + " rating";
				} else {					
			 			var dstDiv3 = document.getElementById(noOfRatingsTag);
  		 			dstDiv3.innerHTML = xmlHttpRequest.responseText + " ratings";
				}
		
						for (var i=0; i < 5; i++) {
							var starId = objectName +  "star__" + (i+1);
					 		document.getElementById(starId).onmouseover = null;        	
					 		document.getElementById(starId).onmouseout= null;        	
					 		document.getElementById(starId).onclick = null;        	
					 	}

		}		
}


	function drawStars(starNum, skipMessageUpdate) {
		this.starCount=starNum;
		this.showStars(starNum, skipMessageUpdate);
	}

	function clearStars() {
		this.starTimer = setTimeout(this.objectName + ".resetStars()", this.delay);
	}

	function resetStars() {
		this.clearStarTimer();
		if (this.starCount)
			this.drawStars(this.starCount);
		else
			this.greyStars();
		this.setMessage(0);
	}

	function clearStarTimer() {
		if (this.starTimer) {
			clearTimeout(this.starTimer);
			this.starTimer = null;
		}
	}

	this.clearStars = clearStars;
	this.clearStarTimer = clearStarTimer;
	this.greyStars = greyStars;
	this.colorStars = colorStars;
	this.resetStars = resetStars;
	this.setStars = setStars;
	this.drawStars = drawStars;
	this.showStars = showStars;
	this.setMessage = setMessage;

}


