// JavaScript Document
var v_artistid = "";
var xmlHttp = "";
var v_followers = "";
function getTweets(v_path)
{
	document.getElementById("tweets").className = "subactive";
	document.getElementById("retweets").className = "inactive";
	document.getElementById("discussion").className = "inactive";
	document.getElementById("tweetsbar").innerHTML = "<img src='"+v_path+"images/working.gif' style='padding-top:100px;padding-left:180px;' >";
	
	var url=v_path+"list_twitter_feeds.php";
	var content = "artist_id=" + v_artistid;
	xmlHTTPRequest(url, "POST", content, feedsReceived);
}
function getRetweets(v_path)
{
	document.getElementById("retweets").className = "subactive";
	document.getElementById("tweets").className = "inactive";
	document.getElementById("discussion").className = "inactive";
	document.getElementById("tweetsbar").innerHTML = "<img src='"+v_path+"images/working.gif' style='padding-top:100px;padding-left:180px;' >";
	var url=v_path+"list_twitter_retweets.php";
	var content = "artist_id=" + v_artistid;
	xmlHTTPRequest(url, "POST", content, feedsReceived);
}


function getDiscussions(v_path)
{
	document.getElementById("discussion").className = "subactive";
	document.getElementById("tweets").className = "inactive";
	document.getElementById("retweets").className = "inactive";
	document.getElementById("tweetsbar").innerHTML = "<img src='"+v_path+"images/working.gif' style='padding-top:100px;padding-left:180px;' >";
	var url=v_path+"list_twitter_search.php";
	var content = "artist_id=" + v_artistid+"&product_id="+v_productid;
	xmlHTTPRequest(url, "POST", content, feedsReceived);
}

function setArtistId(v_artist_id, v_product_id)
{
	v_artistid = v_artist_id;
	v_productid = v_product_id;
}
/*
function followMe(id,v_path)
{
	v_followers = document.getElementById("followers").innerHTML;
	var url=v_path+"../list_twitter_followers.php";
	var content = "twitter_user_name=" + v_tusername + "&twitter_password=" + v_tpassword+"&id="+id;
	xmlHTTPRequest(url, "POST", content, followersReceived);
}

function followersReceived(v_data) 
{ 
	if(v_data!="1")
		document.getElementById("followers").innerHTML = v_data;
}
*/
function feedsReceived(v_data) 
{ 
	v_data = v_data.split("<#@#>");
	var v_content = v_data[0];
	var v_times = v_data[1];
	var v_sp = v_times.split("#$#");
	var k = 0;
	while(k<v_sp.length)
	{
		if(!parseInt(v_sp[k]))
		{
			v_sp[k] = new Date(v_sp[k]);
			v_sp[k] = v_sp[k].getTime()/1000;
		}
		v_content = v_content.replace("<{time_"+(k+1)+"}>", relative_time(v_sp[k]));
		k++;
	}
	document.getElementById("tweetsbar").innerHTML = v_content;
}



function xmlHTTPRequest(url, method, data, callback){
    var xmlHttp;
    try{
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }catch (e){
        // Internet Explorer
        try{
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e){
            try{
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e){
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
    xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState==4)
        {
            callback(xmlHttp.responseText);
        }
    }

	//url = url+"&hash="+Math.random();

    xmlHttp.open(method,url,true);
    if (method == "POST") {
        var header='Content-Type:application/x-www-form-urlencoded';
        xmlHttp.setRequestHeader(header.split(':')[0], header.split(':')[1]);
    }
    xmlHttp.send(data);
}

