// JavaScript Document


function xmlhttpPost() 
{
    var xmlHttpReq = false;
    var self = this;
    
	// Mozilla/Safari
    if (window.XMLHttpRequest) 
	{
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)     // IE
	{
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
	else
	{
		return false;
	}
	
	return self;
}

function dbQuery()
{
	document.body.style.cursor='wait';
	fireWaitPopup();
	
	ajaxPost = xmlhttpPost();
	if(!ajaxPost)
	{
		alert('Error setting up XMLHttpRequest');
	}

    ajaxPost.xmlHttpReq.open('POST', 'used_filter_query.php', true);
    ajaxPost.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	ajaxPost.xmlHttpReq.onreadystatechange = function() 
	{
        if (ajaxPost.xmlHttpReq.readyState == 4) 
		{
            updatedbquery(ajaxPost.xmlHttpReq.responseText);
        }
    }
    
	ajaxPost.xmlHttpReq.send(getquerystring());
	
}


function getquerystring() 
{
    var artist = document.filter_releases.artist.value;
    var format = document.filter_releases.format.value;
    var order = document.filter_releases.order.value;
    var mode = document.filter_releases.mode.value;	
	
	qstr = 'artist=' + escape(artist) + '&' + 'format=' + escape(format) + '&' + 'mode=' + escape(mode)+ '&' + 'order=' + escape(order);

    return qstr;
}

function updatedbquery(str)
{
	document.getElementById("please_wait").style.display = "none";
    document.getElementById("filter_results").innerHTML = str;
	document.body.style.cursor='auto';
}


function fireWaitPopup() 
{
	myWaitPopupRelocate();

	document.getElementById("please_wait").style.display = "block";
	document.body.onscroll = myWaitPopupRelocate;
	window.onscroll = myWaitPopupRelocate;	

}


function myWaitPopupRelocate() 
{
 var scrolledX, scrolledY;
 if( self.pageYOffset ) {
   scrolledX = self.pageXOffset;
   scrolledY = self.pageYOffset;
 } else if( document.documentElement && document.documentElement.scrollTop ) {
   scrolledX = document.documentElement.scrollLeft;
   scrolledY = document.documentElement.scrollTop;
 } else if( document.body ) {
   scrolledX = document.body.scrollLeft;
   scrolledY = document.body.scrollTop;
 }

 var centerX, centerY;
 if( self.innerHeight ) {
   centerX = self.innerWidth;
   centerY = self.innerHeight;
 } else if( document.documentElement && document.documentElement.clientHeight ) {
   centerX = document.documentElement.clientWidth;
   centerY = document.documentElement.clientHeight;
 } else if( document.body ) {
   centerX = document.body.clientWidth;
   centerY = document.body.clientHeight;
 }

 var leftOffset = scrolledX + (centerX - 200) / 2;
 var topOffset = scrolledY + (centerY) / 2;

 document.getElementById("please_wait").style.top = topOffset + "px";
 document.getElementById("please_wait").style.left = leftOffset + "px";
}
