var	nstars = 5;
var ratings = new Array(3);
for (var i=0; i < 3; i++) {
	ratings[i] = -1;
}

function updateCnt() {
	st=document.getElementById('reviewTxt').value;
	if (st == defText) {
		document.getElementById('reviewTxt').value="";
	}
	cnt=document.getElementById('reviewTxt').value.length;
	document.getElementById('reviewCnt').innerHTML=cnt;
	if (cnt < 50 || cnt > 250) {
		document.getElementById('reviewCnt').style.color="#ff0000";
	}
	else {
		document.getElementById('reviewCnt').style.color="#333333";
	}
}


function rateSend(g,r) {
	updateRate(g,r);
	//alert(g+r);
	ratings[g] = r;
}

function rateSave(page) {
	obj = document.getElementById("reviewTxt");
	txt = obj.value;
	if (txt == null) txt = "";
	len = txt.length;

	// validation
	if (len < 50 || len > 250) {
		alert('Your review should at least contain 50 characters but no more than 250.');
		return;
	}
	if (ratings[0] == -1 && ratings[1] == -1 && ratings[2] == -1) {
		var ok = confirm("You did not rate Battery Life, Amount of Vapor and Overall? Click OK to submit 0 ratings. Click Cancel to provide ratings.");
		if (!ok) return;

	}

	obj = document.getElementById("model");
	mdl = obj.value;
	obj = document.getElementById("rname");
	rn = obj.value;
	if (rn == null) rn = "";

	len = rn.length;
	if (len < 3 ) {
		alert('Please enter your name.');
		return;
	}

	

	rateInsert(txt, mdl, rn, page, ratings[0], ratings[1], ratings[2]);

}

function rate(g,r) {

	if (r == 0 && ratings[g] > 0) return; // mouse out and already rated
	if (r > 0 && ratings[g] > -1) return; // mouse over and rated
	updateRate(g,r);

}

function updateRate(g,r) {
	val = "On";
	for (var i=1; i <= nstars; i++) {
		if (i > r) val = "Off"; 

		obj = document.getElementById("rate_"+g+i);
		//alert(obj.src);
		obj.src="/images/rate"+val+".gif";
	}
}

//alert("x");