//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 = "http://www.featuring.com/";
	
	var img_url = "http://www.featuring.com/images/rating_images/";
	
	var UT_RATING_IMG = img_url + '/full' + imgExt;
	
	var UT_RATING_IMG_HOVER =  img_url + '/ic_star.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 "profile"   : messages = new Array("Rate this profile", "Poor", "Fair", "Average", "Good", "Excellent!"); break;			
			case "ad"   : messages = new Array("Rate this classified", "Poor", "Fair", "Average", "Good", "Excellent!"); 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 = "Rate this profile";*/
		}
	}

	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(starNum,formName) 
	{
		
		if(checkLogin()==false)
		{
			return false;
		}
		
		starCount = starNum;
		
		drawStars(starNum);
		
		//document.forms[formName]['rating'].value = starCount;
		document.getElementById("rating").value = starCount;
		var targetDiv = '';
		
		var url = "../store_rating.php";
		
		var actionName = "post_rating";
		
		//var frmObj = browserObject(formName);
		
		var param = "content_id=" + encodeURI(document.getElementById("hid_content_id").value) + 
		
				  "&content_type=" + encodeURI(document.getElementById("hid_content_type").value) + 
				  
				  "&to_user_id=" + encodeURI(document.getElementById("hid_to_user_id").value) + 
				  
				  "&rating=" + encodeURI(document.getElementById("rating").value)+
				  
				  "&tot_votes=" + encodeURI(document.getElementById("tot_votes").value) + 
				  
				  "&tot_rating=" + encodeURI(document.getElementById("tot_rating").value);
		  
				  
		load_ajax_request(url,targetDiv,actionName,param);
		
	}

	function refreshPage()
	{
		if(ajax_request_completed == 1)
		{
			location.href = location.href;
		}
		else
		{
			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;
		}
	}
