var firstprocess = true;
function gethttpreq () {if (window.XMLHttpRequest && !(window.ActiveXObject)) {try{q = new XMLHttpRequest(); }catch(e){q=null;}}else if(window.ActiveXObject){try{q=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{q=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){q=null;}}}return q;}
function sendhttp (url) {
	q = gethttpreq();
    if (q.readyState != 0) q.abort();
	q.onreadystatechange = function (){if (q.readyState != 4) return;if (q.status != 200) return;};
	q.open("GET", url, true);
	q.send("");
}

function motdhide() {
	document.getElementById('motdspace').style.display = 'none';
	sendhttp('/dmmotd');
}

var ratingaboxcount = new Array;
var ratingcboxcount = new Array;
var ratingaboxstates = new Array;
var ratingcboxstates = new Array;
var ratingaboxmiddlecounts = new Array;
var ratingcboxmiddlecounts = new Array;
function addratingabox (id,type) {if(!ratingaboxcount[id])ratingaboxcount[id]=0;
var m = document.getElementById('aar' + id + 'x' + ratingaboxcount[id]); m.innerHTML = '<a href="#" onclick="doratea(' + id + ',1,0,' + type + ');return false"><img src="/img/upa.png" alt="Up" border="0" id="aar' + id + 'bu' + type + '" /></a><div><span id="aar' + id + 't' + type + '" style="font-size: 11px; font-weight: bold;">0</span></div><a href="#" onclick="doratea(' + id + ',-1,0,' + type + ');return false"><img src="/img/downa.png" alt="Down" border="0" id="aar' + id + 'bd' + type + '" /></a>';
m.style.display = 'block';
ratingaboxmiddlecounts[id + ':' + type] = 0;
ratingaboxcount[id]++;
}
function addratingcbox (nid,id,type) {if(!ratingcboxcount[id])ratingcboxcount[id]=0;
var m = document.getElementById('r' + id + 'x' + ratingcboxcount[id]); m.innerHTML = '<a href="#" onclick="doratec(' + nid + ',' + id + ',1,0,' + type + ');return false"><img src="/img/upa2.png" alt="Up" border="0" id="r' + id + 'bu' + type + '" ></a><b><span id="r' + id + 't' + type + '">0</span></b><a href="#" onclick="doratec(' + nid + ',' + id + ',-1,0,' + type + ');return false"><img src="/img/downa2.png" alt="Down" border="0" id="r' + id + 'bd' + type + '" ></a>';
m.style.display = 'inline';
ratingcboxmiddlecounts[id + ':' + type] = 0;
ratingcboxcount[id]++;
}
function ratingasetcount(id,num) {
	ratingaboxcount[id] = num;
}
function ratingcsetcount(id,num) {
	ratingcboxcount[id] = num;
}
function tempstuff (id) {
	if (!ratingaboxcount[id]) 
		a = 1; 
	else 
		a = ratingaboxcount[id]+1;
	addratingabox(id,a);
}
function tempstuffc (nid,id) {
	if (!ratingcboxcount[id]) 
		a = 1; 
	else 
		a = ratingcboxcount[id]+1;
	addratingcbox(nid,id,a);
}
function refreshratingboxstates () {
	var mkey;
	for (mkey in ratingaboxstates) {
	//	document.getElementById('aar' + id + 'bu' + t).src = '/img/upb.png';
	}
	for (mkey in ratingcboxstates) {
		
	}
}
function doratea(id,d,c,t) {
	var cancel;
	if ((ratingaboxstates[id + ',' + t]) && (d == ratingaboxstates[id + ',' + t])) { cancel = true; }
	if (ratingaboxstates[id + ',' + t]) {
		document.getElementById('aar' + id + 't' + t).innerHTML = ratingaboxmiddlecounts[id + ':' + t];
		if (cancel) sendhttp('/en/ratelink?id=' + id + '&r1=0&t=' + t);
		if (ratingaboxstates[id + ',' + t] == 1) {
			document.getElementById('aar' + id + 'bu' + t).src = '/img/upa.png';
		} else if (ratingaboxstates[id + ',' + t] == -1) {
			document.getElementById('aar' + id + 'bd' + t).src = '/img/downa.png';
		}
		delete ratingaboxstates[id + ',' + t];
	}
	if (!cancel) {
		document.getElementById('aar' + id + 't' + t).innerHTML = ratingaboxmiddlecounts[id + ':' + t] + d;
		sendhttp('/en/ratelink?id=' + id + '&r1=' + d + '&t=' + t);
		ratingaboxstates[id + ',' + t] = d;
		if (d == 1) {
			document.getElementById('aar' + id + 'bu' + t).src = '/img/upb.png';
		} else if (d == -1) {
			document.getElementById('aar' + id + 'bd' + t).src = '/img/downb.png';
		}
	}
//	refreshratingboxstates();
}
function doratec(nid,id,d,c,t) {
	var cancel;
	if ((ratingcboxstates[id + ',' + t]) && (d == ratingcboxstates[id + ',' + t])) cancel = true;
	if (ratingcboxstates[id + ',' + t]) {
		document.getElementById('r' + id + 't' + t).innerHTML = ratingcboxmiddlecounts[id + ':' + t];
		if (cancel) sendhttp('/en/ratecomment?rid=' + nid + '&cid=' + id + '&r=0&t=' + t);
		if (ratingcboxstates[id + ',' + t] == 1) {
			document.getElementById('r' + id + 'bu' + t).src = '/img/upa2.png';
		} else if (ratingcboxstates[id + ',' + t] == -1) {
			document.getElementById('r' + id + 'bd' + t).src = '/img/downa2.png';
		}
		delete ratingcboxstates[id + ',' + t];
	}
	if (!cancel) {
		document.getElementById('r' + id + 't' + t).innerHTML = ratingcboxmiddlecounts[id + ':' + t] + d;
		sendhttp('/en/ratecomment?rid=' + nid + '&cid=' + id + '&r='+ d + '&t=' + t);
		ratingcboxstates[id + ',' + t] = d;
		if (d == 1) {
			document.getElementById('r' + id + 'bu' + t).src = '/img/upb2.png';
		} else if (d == -1) {
			document.getElementById('r' + id + 'bd' + t).src = '/img/downb2.png';
		}
	}
//	refreshratingboxstates();
}
function setratingadata (id,t,c) {
	ratingaboxmiddlecounts[id + ':' + t] = c;
}
function setratingcdata (id,t,c) {
	ratingcboxmiddlecounts[id + ':' + t] = c;
}
function getratingboxdata () {  } // TODO: AJAX stuff
function getratingboxcdata (id) {  } // TODO: AJAX stuff
