// JavaScript Document
var fileVoteClip="module/ajax_voteclip.php";
function $(id){return document.getElementById(id);};
function $name(name){return document.getElementsByName(name);};
function $value(node,name){try{return node.getElementsByTagName(name)[0].firstChild.nodeValue;}catch(e){return "";}}
function getDataNode(p,t){try{return p.getElementsByTagName(t)[0].firstChild.nodeValue;}catch(e){return "";}};
function setCenter(id){$(id).style.left=((getWindowSizeAll(true)[0]-$(id).offsetWidth)/2+getScrollXY()[0])+"px";$(id).style.top=((getWindowSizeAll(true)[1]-$(id).offsetHeight)/2+getScrollXY()[1])+"px";};
function spacialTag(txt){txt=txt.replace(/>/g,'&gt;');txt=txt.replace(/</g,'&lt;');return txt;}
function spacialChar(txt){
	txt = txt.replace(/\\u000a/g,"<br>");
	txt = txt.replace(/\\u003c/g,"<");
	txt = txt.replace(/\\u003e/g,">");
	txt = txt.replace(/\\u0026/g,"&");
	txt = txt.replace(/\\/g,"");
	return txt;
}
//////////////////////////Vote Clip////////////////////////
function voteOver(val,clipID,chkLogin){
	document.getElementById("score"+val).onclick=function(){voteClip(clipID,chkLogin,val);};
	for(var i=1;i<=val;i++){
		document.getElementById("score"+i).src="images/icon_star/iconStar-24.png";
		document.getElementById("score"+i).onmouseout=function(){voteOut(i);};
	}
}
function voteOut(val){
	for(var i=5;i>=val;i--){
		document.getElementById("score"+i).src="images/icon_star/iconStar-24G.png";
		document.getElementById("score"+i).onclick="";
		//document.getElementById("score"+i).onmouseover=function(){voteOver(i);};
	}
}
function voteClip(clipID,chkLogin,score){
//	if(chkLogin=="true"){
		cp.call(fileVoteClip,'voteClip',resVoteClip,clipID,score);
//	}else if(chkLogin=="false"){
//		thislogin(pathLogin);
//	}else{
//		alert("Error.");
//	}
}
function resVoteClip(result){
	var vote=result.getElementsByTagName('vote')[0];
	var clipID=vote.getAttribute('id');
	var over=vote.getElementsByTagName("over")[0].firstChild.nodeValue;
	var avgScore=vote.getElementsByTagName("avgScore")[0].firstChild.nodeValue;
//	var over=$value(vote,'over');
//	var avgScore=$value(vote,'avgScore');
	if(over!=1){
		var resultVoteHTML="";
		for(i=1;i<=5;i++){
			if(i<=avgScore){
				resultVoteHTML+="<img src=\"images/icon_star/iconStar-16.png\" />";
			}else if(i>avgScore){
				dif=i-avgScore;
				if(dif<0.75){
					resultVoteHTML+="<img src=\"images/icon_star/iconStar-16_5.png\" />";
				}else{
					resultVoteHTML+="<img src=\"images/icon_star/iconStar-16G.png\" />";
				}
			}
		}
		document.getElementById("boxBttVote").style.display="none";
		document.getElementById("boxResultScore").style.display="block";
		document.getElementById("boxResultScore").innerHTML=resultVoteHTML;
		document.getElementById("scoreThisClip").innerHTML=avgScore;
	}else{
		alert("คุณสามารถโหวตได้ 1 ครั้งต่อวัน");
	}
}
