mycount  = 0;
nowcount = 0;
usrcount = 0;
mcount   = 0;

date = new Date();
randp = date.getTime();


img01 = new Image();
img02 = new Image();
img01.src = 'img/u_pt.gif';
img02.src = 'img/t_act.gif';

function usrpt(usrid,bid) {
var httpObj1 = createXMLHttpRequest();
if (httpObj1) {
	httpObj1.open("GET", "_usr/" + usrid + "/" + bid + "pt.txt?p=" + randp, true);
	httpObj1.send(null);
	httpObj1.onreadystatechange = function() {
		if ( (httpObj1.readyState == 4) && (httpObj1.status == 200) ) {
			document.getElementById("usrpoint").innerHTML = httpObj1.responseText;
		}
	}
}
}

function artpt(bid,tid,kid) {
var httpObj2 = createXMLHttpRequest();
if (httpObj2) {
	if ( kid ) {
		httpObj2.open("GET", "_bbs/"+ bid + "/"+ tid +"/pt"+ kid + ".txt?p=" + randp, true);
		var tarid = kid;
	} else {
		httpObj2.open("GET", "_bbs/"+ bid + "/"+ tid +"/pt.txt?p=" + randp, true);
		var tarid = tid;
	}
	httpObj2.send(null);
	httpObj2.onreadystatechange = function() {
		if ( (httpObj2.readyState == 4) && (httpObj2.status == 200) ) {
			document.getElementById("pt"+ tarid).innerHTML = httpObj2.responseText;
		}
	}
}
}

function rank(fid,vid) {
	
	var date = new Date();
var randp = date.getTime();
	
var httpObj3 = createXMLHttpRequest();
if (httpObj3) {
	httpObj3.open("GET", "" + fid + ".txt?p=" + randp, true);
	httpObj3.send(null);
	httpObj3.onreadystatechange = function() {
		if ( (httpObj3.readyState == 4) && (httpObj3.status == 200) ) {
			document.getElementById(vid).innerHTML = httpObj3.responseText;
		}
	}
}
}

function add(tid, kid) {
	usrcount = document.getElementById("usrpoint").innerHTML;
	if ( usrcount > 0 ) {
		if ( kid ) {
			tarid = "pt" + kid;
		} else {
			tarid = "pt" + tid;
		}
		nowcount = document.getElementById(tarid).innerHTML;
		if ( !nowcount ) { nowcount = 0; parseInt(nowcount); }
		mycount ++;
		nowcount ++;
		usrcount --;
		/*
		if ( kid ) {
			mcount = document.getElementById("pt"+tid).innerHTML;
			if ( !mcount ) { mcount = 0; parseInt(mcount); }
			mcount ++;
			document.getElementById("pt"+tid).innerHTML = mcount;
		}
		*/
		document.getElementById(tarid).innerHTML = nowcount;
		document.getElementById("usrpoint").innerHTML = usrcount;
	}
}


function save(tid, kid) {
	if ( mycount ) {
		script = document.createElement("script");
		script.type = 'text/javascript';
		script.charset = 'UTF-8';
		script.src = "cnt.php?tid="+ tid +"&kid="+ kid +"&cnt="+ mycount;
		mycount = 0;
		document.getElementById('nn').appendChild(script);
	}
}

function aptf(tid, kid) {
	var adpoint = parseInt(document.getElementById("apt" + kid ).value);
	
	script = document.createElement("script");
	script.type = 'text/javascript';
	script.charset = 'UTF-8';
	script.src = "cnt.php?tid="+ tid +"&kid="+ kid +"&cnt="+ adpoint;
	document.getElementById('nn').appendChild(script);
	document.getElementById("apt" + kid ).value = "";
	
	var usrcount = parseInt(document.getElementById("usrpoint").innerHTML);
	if ( usrcount - adpoint < 0 ) { adpoint = usrcount; }
	usrcount = usrcount - adpoint;
	document.getElementById("usrpoint").innerHTML = usrcount;
	
	tarid = "pt" + kid;
	var mcount = parseInt(document.getElementById(tarid).innerHTML);
	mcount = mcount + adpoint;
	document.getElementById(tarid).innerHTML = mcount;
}

function do_trans_any(){
	var dir = document.any_form.lang.value;
	url = "http://translate.google.com/translate?u="+escape(location.href)+"&ie=UTF8&sl=auto&tl="+dir;
	window.open(url);
}

function createXMLHttpRequest() {
	var XMLhttpObject = null;
	try{
		XMLhttpObject = new XMLHttpRequest();
	}catch(e){
		try{
			XMLhttpObject = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				XMLhttpObject = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				return null;
			}
		}
	}
	return XMLhttpObject;
}

var randobet = function(n, b) {
	b = b || '';
	var a = 'abcdefghijklmnopqrstuvwxyz'
		+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		+ '0123456789'
		+ b;
	a = a.split('');
	var s = '';
	for (var i = 0; i < n; i++) {
    	s += a[Math.floor(Math.random() * a.length)];
	}
	return s;
};
