//javascript document
/*
#############################################################################
# eLuminous Technologies - Copyright (C)  http://eluminoustechnologies.com 
# This code is written by eLuminous Technologies, Its a sole property of 
eLuminous Technologies and cant be used / modified without license.  
Any changes/ alterations, illegal uses, unlawful distribution, copying is strictly
prohibhited #
#############################################################################
# Name: functions_rating.php
# Usage: included ( WRITE USAGE DETAILS ) 
  {
   -- It is called from index file.
  } 
# Update: created on 5-mar-2007 by swati patel
# Status: production
# Purpose: All the required functions for rating are present here.
 
#############################################################################
ALSO STRICTLY MAINTAINING THE LOGS OF CHANGES AND PERSON NAME 
#############################################################################
*/
	var imgExt = '.gif';

	if ((navigator.appVersion.indexOf('MSIE') > -1) && (typeof window.XMLHttpRequest == 'undefined')) 
	{
		imgExt = '.gif';
	}
	else
	{
		imgExt = '.png';
	}
		imgExt = '.gif';
		
		
	var site_url = "../images";
	
	var img_url = "../images";
	
	var UT_RATING_IMG = img_url + '/full' + imgExt;
	
	var UT_RATING_IMG_HOVER =  img_url + '/star_hover.gif';
	
	var UT_RATING_IMG_HALF =  img_url + '/half' + imgExt;
	
	var UT_RATING_IMG_BG =  img_url + '/blank' + imgExt;
	
	var UT_RATING_IMG_REMOVED =  img_url + '/star_removed.gif';
	
	// pre-fetch image
	
	(new Image()).src = UT_RATING_IMG;
	
	(new Image()).src = UT_RATING_IMG_HALF;
	
	var ratingElementId, maxStars, objectName, formName, ratingMessageId, componentSuffix, size, starCount, starTimer, skipMessageUpdate;

	var halfImgNo = -1;
	
	maxStars = 5;
	
	starTimer = null;
	
	var messages = Array();
	
	var contentType = "";
	
	var ex_star_id = "";
	
	function setSkipMessageUpdate(msgStatus)
	{
		skipMessageUpdate = msgStatus;
	}
	
	function setMessagesArray(message_type)
	{
		contentType = message_type;
		
		switch(message_type)
		{
			case "lesson"   : messages = new Array("Rate this product", "Poor", "Nothing special", "Worth watching", "Pretty cool", "Awesome!"); break;			
			
		}
	}
	
	function setStarCount(starCount1,msgType)
	{
		starCount = starCount1;
		
		setMessagesArray(msgType);
	}
	
	function showStars(starNum, skipMessageUpdate, half_img_no1, ex_offer_id) 
	{
		/*alert(starNum);	
		alert(skipMessageUpdate);	
		alert(half_img_no1);	
		alert(ex_offer_id);	*/
		
		halfImgNo = half_img_no1;
		
		if(ex_offer_id)
		{
			ex_star_id = ex_offer_id;
		}
		
		clearStarTimer();
		
		greyStars();
		
		colorStars(starNum);		
		
		if(contentType == 'exchange' || skipMessageUpdate == 'false')
		{	
			
			skipMessageUpdate = false;
		}
		
		if(!skipMessageUpdate)
		{			
			setMessage(starNum);
		}
	}

	function setMessage(starNum) 
	{
		
		var ratingMessageIdObj1 = browserObject("ratingMessage" + ex_star_id);
		if(ex_star_id !='')
		{
			ratingMessageIdObj1.innerHTML = messages[starNum];
		}
		else
		{
			ratingMessageIdObj1.innerHTML = "Rating of product";	
		}
	}

	function colorStars(starNum) 
	{	
		for (var i=0; i < starNum; i++) 
		{
			if((i+1) == halfImgNo)
			{
				document.getElementById('star' + ex_star_id + '_'  + "_" + (i+1)).src = UT_RATING_IMG_HALF;
			}
			else
			{
				document.getElementById('star' + ex_star_id + '_'  + "_" + (i+1)).src = UT_RATING_IMG;
			}
		}
	}

	function greyStars() 
	{
		for (var i=0; i < maxStars; i++)
		{
			if (i <= starCount) 
			{
				document.getElementById('star' + ex_star_id + '_'  + "_"  + (i+1)).src = UT_RATING_IMG_BG;
			}
			else
			{
				document.getElementById('star' + ex_star_id + '_'  + "_"  + (i+1)).src = UT_RATING_IMG_BG;
			}
		}
	}

	function setStars(storefile,starNum,formName) 
	{
		starCount = starNum;
		drawStars(starNum);
		document.forms[formName]['rating'].value = starCount;
		var targetDiv = '';
		var url = storefile;
		var actionName = "post_rating";
		var frmObj = document.forms[formName];
		//var frmObj = browserObject(formName);
		var param = "rating_date=" + encodeURI(frmObj.rating_date.value) + 
				  "&user_ip=" + encodeURI(frmObj.user_ip.value) + 
				  "&starNum=" + starNum + 
				  "&prod_id=" + encodeURI(frmObj.prod_id.value);
		  
		load_ajax_request(url,targetDiv,actionName,param);
		alert("Thanks for rating");
		refreshPage();		
	}

	function refreshPage()
	{
		if(ajax_request_completed == 1)
		{
			location.href = location.href;
		}
		else
		{
			location.href = location.href;
			//setTimeout("refreshPage()",2000);
		}
	}
	
	
	function drawStars(starNum, skipMessageUpdate) 
	{
		starCount=starNum;
		showStars(starNum,skipMessageUpdate,halfImgNo);
	}

	function clearStars(star_count,half_img_no1) 
	{
		//alert(star_count);
		//alert(half_img_no1);
		starCount = star_count;
		halfImgNo = half_img_no1;
		starTimer = setTimeout("resetStars()", 300);
	}

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

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