// 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($download)
{
	document.body.style.cursor='wait';
	ajaxPost = xmlhttpPost();
	if(!ajaxPost)
	{
		alert('Error setting up XMLHttpRequest');
	}

    ajaxPost.xmlHttpReq.open('POST', 'spc_release_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($download));
}


function getquerystring($download) 
{
    var artist = document.filter_releases.artist.value;
    var format = document.filter_releases.format.value;
    var order = document.filter_releases.order.value;

	if($download == "true")
	{	
	    qstr = 'artist=' + escape(artist) + '&format=download&' + 'order=' + escape(order);
	}
	else
	{
	    qstr = 'artist=' + escape(artist) + '&' + 'format=' + escape(format) + '&' + 'order=' + escape(order);
	}
	
    return qstr;
}

function updatedbquery(str)
{
    document.getElementById("filter_results").innerHTML = str;
	document.body.style.cursor='auto';
}
