var xmlHttp;
var flag = 'N';
var No = '';
var OldNo = '';

function createXHR(){
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}	

	if(!xmlHttp){
		alert("XMLHttpRequest ¿¡·¯!!");
	}
}

function AddCnt(no){
	if(OldNo == no){		
		return;
	}
	OldNo = no;
	
	createXHR();

	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {	
				var tmpStr = xmlHttp.responseText;
				if(tmpStr.indexOf('\n')==0) tmpStr = tmpStr.replace('\n', '');

				if(tmpStr == 'Y'){
					ViewCnt(no);
					alert("¾ËÂù ÄÁÆÛ·±½º°¡ µÇµµ·Ï ³ë·ÂÇÏ°Ú½À´Ï´Ù!");
				}else{
					alert("Error!!");
				}
			}
		}
	}

	xmlHttp.open("POST", "./ajax/poll.php", true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send("no="+no+"&act=add");	
}

function ViewCnt(no){
	if(OldNo != no) OldNo = '';

	createXHR();

	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {	
				var tmpStr = xmlHttp.responseText;
				if(tmpStr.indexOf('\n')==0) tmpStr = tmpStr.replace('\n', '');				
				
				var Html = '<table width="'+tmpStr+'%" border="0" cellspacing="1" cellpadding="0"><tr><td height="8" bgcolor="#424242"></td></tr></table>';												
				document.getElementById("bar").innerHTML = Html;
				document.getElementById("rate").innerHTML = tmpStr;
				
				No = no;
			}
		}
	}

	xmlHttp.open("POST", "./ajax/poll.php", true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send("no="+no+"&act=view");	
}
