﻿	
    
	//页面加载时星的默认显示状态
	window.onload = function()
	{ 
	    mouseOutStar();
	    setDisplayInfo( "strong_displayMessage" , "" , 1 , voteCount );
    }
	
	
	/* 星评级效果显示开始 */
	
	//星的默认状态以及改变被点击时的星的状态
	//levelCount        默认或者点击的级别
	//starStyle         星的显示样式
	function changeStar( levelCount , starStyle )
	{
		for( var i = 0 ; i < 5 ; i++ )
		{
			if( i < levelCount )
			{
				if( (levelCount - i) > 0.7 )
				{
					starBox[i].style.backgroundImage = "url("+ starStyle +")";
					continue;
				}
				if( (levelCount - i) < 0.7 && (levelCount - i) > 0.3 )
				{
					starBox[i].style.backgroundImage = "url("+ mouseouthalfStarFilePath +")";
					continue;
				}
			}
			starBox[i].style.backgroundImage = "url("+ defaultStarFilePath +")";
		}
	}
	
	//鼠标滑上时的效果
	function mouseOverStar( levelCount )
	{
	    changeStar( levelCount , mouseoverStarFilePath );
	}
	
	//鼠标移开时的效果
	function mouseOutStar()
	{
	    //alert(totalLevelCount / voteCount);
	    if( voteCount == 0 )
	        changeStar(0 , defaultStarFilePath);
	    else
	        changeStar( (totalLevelCount / voteCount) , mouseoutStarFilePath );
	}
	
	/* 星评级效果显示结束 */
	
	
	/* 星评级数据的提交开始 */
	
	var xmlHttp;
	var clickLevelCount;
	
	//发送请求
	function main(url)
	{
		createXMLHttpRequest();
		xmlHttp.onreadystatechange = handleStateChange;
		xmlHttp.open("GET",url,"true");
		xmlHttp.send(null);
	}   

	//创建对象
	function createXMLHttpRequest()
	{
		 if (window.ActiveXObject)
			 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		 else if (window.XMLHttpRequest)
			 xmlHttp = new XMLHttpRequest("Msxml2.XMLHTTP.3.0");
	}
	
	//处理响应
	function handleStateChange()
	{
		if (xmlHttp.readyState == 4)
		{
//			if (xmlHttp.status == 200)
//			{
			    parseResults();
//			}
		}
	}
	
	//读取数据处理后的返回值
	function parseResults()
	{
	    //alert(xmlHttp.responseText.toLowerCase());
		if( xmlHttp.responseText.toLowerCase() == 'true' )
		{
		    setCookie( cookieNameForMembershipID + cookieNameForContentID , membershipID + contentID  , cookieExpireHours);
	        voteCount = voteCount + 1;
	        totalLevelCount = totalLevelCount + clickLevelCount;
		    mouseOutStar();
		    setDisplayInfo("strong_displayMessage" , voteSuccessful , 3 , voteCount);
		}
		else
		{
		    setDisplayInfo( "strong_displayMessage" , voteUnsuccessful , 3 , voteCount);
		}
	}
	
	
	function clickStar( levelCount )
	{	
	    if( isLogin.toLowerCase() == 'true' )
	    {
	        if( getCookieValue( cookieNameForMembershipID + cookieNameForContentID ) == (membershipID + contentID))
	        {
	            setDisplayInfo("strong_displayMessage" , voteBefor , 3 , voteCount);
	        }
	        else
	        {
	            clickLevelCount = levelCount;
		        main( getUrl(dataHelperUrl) + parameterName +"=" + levelCount );
		     }
	     }
	     else
	     {
	         setDisplayInfo( "strong_displayMessage" , notLogin , 3 , voteCount);
	     }
	     mouseOutStar();
	}
	
	/* 星评级数据的提交结束 */
	
