PriceRatingKey = new Array();
PriceRatingKey[1] = "Inexpensive";
PriceRatingKey[2] = "Affordable";
PriceRatingKey[3] = "Expensive";

NumberOf = new Array();
NumberOf["Star"] = 5;
NumberOf["Dollar"] = 3

function Rate(ListingID,Stars,Type) {
	RateImage = new Image;
	if (Type == "Star") {
		RateImage.src = "/rate/" + ListingID + "/" + Stars + ".jpg?SID=" + SID;
		ratingsArray[ListingID] = Stars;
	} else if (Type == "Dollar") {
		RateImage.src = "/pricerate/" + ListingID + "/" + Stars + ".jpg?SID=" + SID;
		priceratingsArray[ListingID] = Stars;
		PriceRating = document.getElementById(ListingID + "PriceRating");
		PriceRating.innerHTML = PriceRatingKey[Stars];
		priceratingsArray[ListingID] = Stars;
	}
	
}

function Roll(ListingID,Stars,Type) {
	//alert(ListingID + " " + Stars );
	if (Type == "Dollar") {
		PriceRating = document.getElementById(ListingID + "PriceRating");
		PriceRating.innerHTML = PriceRatingKey[Stars];
	}

	eval("document." + Type + ListingID + "_" + Stars + ".src = " + Type + "Red.src;");
	for (i=1;i<=Stars;i++) {	
		eval("document." + Type + ListingID + "_" + i + ".src = " + Type + "Red.src;");
	}
	
	Stars = parseInt(Stars);
	
	StarsPlus = Stars + 1;
	//alert(StarsPlus);
	for (i=StarsPlus;i<=NumberOf[Type];i++) {	
		//alert("Gray out " + i);
		eval("document." + Type + ListingID + "_" + i + ".src = " + Type + "Gray.src;");
	}
	
	
}

function Out(ListingID,Type) {
	ListingID = parseInt(ListingID);

	if (Type == "Dollar") {
		PriceRating = document.getElementById(ListingID + "PriceRating");
		if (priceratingsArray[ListingID] != undefined) {
			UserRated = priceratingsArray[ListingID];
		} else {
			UserRated = userdollarsArray[ListingID];
		}
	} else {
		if (ratingsArray[ListingID] != undefined) {
			UserRated = ratingsArray[ListingID];
		} else {
			UserRated = userstarsArray[ListingID];
		}
	}
	
	if (UserRated != undefined) {
		Rated = UserRated;
		for (i=1;i<=Rated;i++) {	
			eval("document." + Type + ListingID + "_" + i + ".src = " + Type + "Red.src;");
		}
	} else {
		if (Type == "Dollar") { 
			Rated = dollarsArray[ListingID];
		} else {
			Rated = starsArray[ListingID];
		}
		if (Rated == undefined) {  //still is null, no user rating or average
			Rated = 0;
		}
		//alert(ListingID + " is already rated " + Rated);
		for (i=1;i<=Rated;i++) {	
			eval("document." + Type + ListingID + "_" + i + ".src = " + Type + "Yellow.src;");
		}
	}	
	
	if (Type == "Dollar") { //reset the PriceRating text
		if (Rated > 0) {
			PriceRating.innerHTML = PriceRatingKey[Rated];
		} else {
			PriceRating.innerHTML = "";
		}
	}
	
	if (Rated === undefined) {
		RatedPlus = 1;
	} else {
		RatedPlus = Rated + 1;
	}	

	//alert(Type + " " + NumberOf[Type]);
	
	for (i=RatedPlus;i<=NumberOf[Type];i++) {	
		//alert("Gray out " + i);
		eval("document." + Type + ListingID + "_" + i + ".src = " + Type + "Gray.src;");
	}
	
}