/*
Author: Taeko
*/

var sMax;	// Isthe maximum number of stars
var holder; // Is the holding pattern for clicked state
var preSet; // Is the PreSet value onces a selection has been made
var prefix = "rate";

// Rollover for image Stars //
function rating(num, meigenid){
	sMax = 0;	// Isthe maximum number of stars
	for(n=0; n<num.parentNode.childNodes.length; n++){
		if(num.parentNode.childNodes[n].nodeName == "A"){
			sMax++;	
		}
	}
	var str = prefix+meigenid+"_";
	var s = num.id.replace(str, ''); // Get the selected star
	var a = 0;
	for(i=1; i<=sMax; i++){		
		if(i<=s){
			document.getElementById(prefix+meigenid+"_"+i).className = "on";
			holder = a+1;
			a++;
		}else{
			document.getElementById(prefix+meigenid+"_"+i).className = "";
		}
	}
}

// For when you roll out of the the whole thing //
function off(me, meigenid){
	if(preSet){	
		rating(preSet, meigenid);
	}
}// When you actually rate something //
function rateIt(me, meigenid){

	if(!navigator.cookieEnabled){ 
		alert("Cookieの設定をONにしてください。");
		return;
	}
	scookie = document.cookie;
	keyword = prefix + meigenid;
	start = scookie.indexOf(keyword);
	if (start != -1){
		alert('すでに投票済みです。\nご協力ありがとうございます。');
		return;
	}
		
	rate = me.id.replace(keyword+"_", '');
	script = document.createElement( 'script' );
	p_script_url = 'rating.php?id=' + meigenid + '&rate=' + rate;
	script.src = p_script_url;
	document.getElementsByTagName( 'head' )[0].appendChild( script );

	document.cookie = keyword + "=" + escape(keyword);
}

// Send the rating information somewhere using Ajax or something like that.


