// JavaScript Document

function fireArtistDetails($id) 
{
	myArtistPopupRelocate();

	document.getElementById("artist_results").style.display = "block";
	document.body.onscroll = myArtistPopupRelocate;
	window.onscroll = myArtistPopupRelocate;	

	artistQuery($id);
}


function myArtistPopupRelocate() 
{
 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 - 750) / 2;
 var topOffset = scrolledY + (centerY - 500) / 2;

 document.getElementById("artist_results").style.top = topOffset + "px";
 document.getElementById("artist_results").style.left = leftOffset + "px";
}


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 artistQuery($id)
{
	document.body.style.cursor='wait';
	ajaxPost = xmlhttpPost();
	if(!ajaxPost)
	{
		alert('Error setting up XMLHttpRequest');
	}

    ajaxPost.xmlHttpReq.open('POST', 'artist_details_query.php', true);
    ajaxPost.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    
	ajaxPost.xmlHttpReq.onreadystatechange = function() 
	{
        if (ajaxPost.xmlHttpReq.readyState == 4) 
		{
            updateArtistQuery(ajaxPost.xmlHttpReq.responseText);
        }
    }
    
	ajaxPost.xmlHttpReq.send('artist=' + $id);
	
}

function updateArtistQuery(str)
{
    document.getElementById("artist_results").innerHTML = str;
	document.getElementById("artist_results").style.display="block";
	
	document.body.style.cursor='auto';

}

function close_artist_popup()
{
	document.getElementById("artist_results").innerHTML = "";
	document.getElementById("artist_results").style.display="none";
}