function toggle(x, y, disp) {
	if(!disp) var disp = 'block';
	if (x == 'login') {
		document.getElementById('loginform').style.display='block';
		return;
	}
	if (x == 'cancelLogin') {
		document.getElementById('loginform').style.display='none';
		return;
	}
	if(x) document.getElementById(x).style.display=disp;
	if(y) document.getElementById(y).style.display='none';
}

function toggle2(x, y, disp) {
	if(!disp) var disp = 'block';
	if (x == 'login') {
		document.getElementById('log-in').style.display='block';
		return;
	}
	if (x == 'exit') {
		document.getElementById('log-in').style.display='none';
		return;
	}
	if(x) document.getElementById(x).style.display=disp;
	if(y) document.getElementById(y).style.display='none';
}

var asyncRequest = function() {
	function handleReadyState(o, callback) {
	var poll = window.setInterval(function() {
	if(o && o.readyState == 4) {
	window.clearInterval(poll);
	if ( callback ){
	callback(o);
	}
	}
	},
	50);
	}
	var http;
	try {
	http = new XMLHttpRequest();
	}
	catch(e) {
	var msxml = [
	'MSXML2.XMLHTTP.3.0',
	'MSXML2.XMLHTTP',
	'Microsoft.XMLHTTP'
	];
	for ( var i=0, len = msxml.length; i < len; ++i ) {
	try {
	http = new ActiveXObject(msxml[i]);
	break;
	}
	catch(e) {}
	}
	}
	return function(method, uri, callback, postData) {
	http.open(method, uri, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	handleReadyState(http, callback);
	http.send(postData || null);
	return http;
	};
}();
function setCollection(what, albumid, usrid) {

if(!usrid) {
		toggle('login');
	} else {


	toggle('loading-'+what, 'check-'+what);
	
	if(document.getElementById('check-'+what).checked==true) var ch=1;
	else var ch=0;
	
	asyncRequest(
		"post",
		"http://squareanthology.com/library.php",
		function(response) {
			if(response.responseText) toggle('check-'+what, 'loading-'+what);
		},
		"what="+what+"&ch="+ch+"&gameid="+albumid+"&user="+usrid
	);
	
	}

}