﻿//<![CDATA[

var rating_set=false;
var current_photo=0;
var photoid=[];
var current_rating=[];
var current_votes=[];

function loadStars()
{
star1 = new Image();
star1.src = "icons/star_gray.png";
star2 = new Image();
star2.src= "icons/star_yellow.png";
star1.title="test";
star2.title="test";
}

function highlight(x)
{
if (rating_set==false)
	{
	for (var i=1;i<=x;i++)
		document.getElementById(i).src= star2.src;
	for (var i=x+1;i<=5;i++)
		document.getElementById(i).src= star1.src;

	switch(x)
		{
		case "1": 
		document.getElementById('vote').innerHTML="Poor";
		break;
		case "2":
		document.getElementById('vote').innerHTML="Moderate";
		break;
		case "3":
		document.getElementById('vote').innerHTML="Good";
		break;
		case "4":
		document.getElementById('vote').innerHTML="Very Good";
		break;
		case "5":
		document.getElementById('vote').innerHTML="Excellent";
		break;
		}
	}
}

function losehighlight(x)
{
if (rating_set==false)
	{
	for (i=1;i<6;i++)
		{
		document.getElementById(i).src=star1.src;
		document.getElementById('vote').innerHTML="&nbsp;"
		}
	}
}

function setStar(x)
{
if (rating_set==false)
    {
	for (var i=1;i<=x;i++)	
		document.getElementById(i).src= star2.src;
	rating_set=true;
    SendPhotoRating(photoid[current_photo],x);
	document.getElementById('vote').innerHTML="Thank you for your vote!"
    }
}


function initialrate(x)
{
    if(x==0)
        return;
    document.getElementById("vote").innerHTML="Current Rating: "+current_rating[current_photo] + " (" + current_votes[current_photo] + " votes)";
    if(x>5)
        x=5;
	for (var i=1;i<=x;i++)	
		document.getElementById(i).src= star2.src;
	for (var i=x+1;i<=5;i++)	
		document.getElementById(i).src= star1.src;
}

function suggestion(x)
{
    SendPhotoRating(photoid[current_photo],x);
	document.getElementById('vote').innerHTML="Thank you for your suggestion!"
}

// send star ratings and suggestions function
var xmlhttp;
function SendPhotoRating(photo_id,rating)
{
xmlhttp=null;
if (window.XMLHttpRequest)
  {// code for all new browsers
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE5 and IE6
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.open("GET","photorating.aspx?photo_id="+photo_id+"&rating="+rating,true);
  xmlhttp.send(null);
  }
else
  {
  //alert("Your browser does not support XMLHTTP.");
  }
}

//]]>

