﻿// JScript File
function calculaterate(id,votes,nameid,showid,isPayed, cPrice) {
    /*
    if(isPayed == "False" || isPayed == "false")
    {
        showAlert();
        return false;
    }
    */
    
    var name = document.getElementById(nameid);
    
    if(name.value <= 1)
        name.value = 1;
    else
    {
        alert("You can only rate once.");
        return false;
    }
    
    showPop('popAjax');
    var rid=id.substring(0,id.length-5);    
    var url = "/ajaxHandle/calculateRating.ashx?v=" + votes + "&rid=" + rid;
    
	g = false;
	if (window.XMLHttpRequest) {
		g = new XMLHttpRequest();
		if (g.overrideMimeType) {
			g.overrideMimeType("text/xml");
		}
	} else {
		if (window.ActiveXObject) {
			try {
				g = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					g = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
				}
			}
		}
	}
	if (!g) {
		alert("Can not create XMLHTTP-instance");
		return false;
	}
	g.onreadystatechange = function () {
		showStar(id,votes,nameid,showid);
	};
	g.open("GET", url, true);
	g.send(null);
}

function showStar(id,votes,nameid,showid) {
	if (g.readyState == 4) {
		if (g.status == 200) {
			c = document.getElementById(id);
			if (c != null) {
				c.style.width = 23*votes + "px";
				document.getElementById(showid).src="/images/s" + g.responseText + ".gif";
				d = document.getElementById(showid+"1");
				if(d != null)
				    d.src="/images/s" + g.responseText + ".gif";
				document.getElementById(nameid).value=2;
				hidePop('popAjax');
			}
		} else {
		    hidePop('popAjax');
			alert("An error has occurred during request");
			
		}
	}
}
