if (document.images)
{
  pic1= new Image(16,16); 
  pic1.src="http://208.109.211.97/img/ajax-loader.gif"; 
}

function HideShow(id)
{
	var obj = document.getElementById(id);
	
	if(obj.style.display == "block")
	{
		obj.style.display = "none";
	}
	else
	{	
		obj.style.display = "block";
	}
	
}

var ajaxRequest;  // The variable that makes Ajax possible!

function setAjaxVariable()
{
	try{
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				return false;
			}
		}
	}
}

function ajaxAddComment(){

	var ajaxDisplay = document.getElementById('ajaxDiv');
	setAjaxVariable();
	
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
			fadeComment();
		}
	}
	var item = document.getElementById('item').value;
	var list = document.getElementById('list').value;
	var comments = document.getElementById('comments').value;
	comments = comments.replace(/ /g, "+");
	comments = comments.replace(/\n/g, "##");
	comments = comments.replace(/&/g, "^^");
	comments = comments.replace(/%/g, "~~");
	ajaxDisplay.innerHTML = '<img src="http://208.109.211.97/img/ajax-loader.gif">';
	var queryString = "item=" + item + "&list=" + list + "&comments=" + comments;
	ajaxRequest.open("POST", "/ajax/ajaxcomment.asp", true);
	ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	ajaxRequest.send(queryString); 
}

function fadeComment(){
	var colornum = document.getElementById('newcomment').style.color;
	colornum = colornum.substring(4,colornum.indexOf(","));
	colornum = colornum - 3;
	document.getElementById('newcomment').style.color = "rgb(" + colornum + "," + colornum + "," + colornum + ")";
	if (colornum > 51) { setTimeout("fadeComment()",1) }
}

function ajaxAddItem(list){
	var ajaxDisplay = document.getElementById('addnewitem');
	var ajaxRequestAddItem;
	
	try{
		ajaxRequestAddItem = new XMLHttpRequest();
	} catch (e){
		try{
			ajaxRequestAddItem = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequestAddItem = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequestAddItem.onreadystatechange = function(){
		if(ajaxRequestAddItem.readyState == 4){
			ajaxDisplay.innerHTML = ajaxRequestAddItem.responseText;
		}
	}
	var title = '';
	var content = '';
	if (document.getElementById('title')) {
		title = document.getElementById('title').value;
		title = title.replace(/ /g, "+");
		title = title.replace(/&/g, "^^");
		content = document.getElementById('comments').value;
		content = content.replace(/ /g, "+");
		content = content.replace(/\n/g, "##");
		content = content.replace(/&/g, "^^");
		document.getElementById('addnewitemform').innerHTML = '<img src="http://208.109.211.97/img/ajax-loader.gif">';
	}
	var queryString = "list=" + list + "&title=" + title + "&content=" + content;
	ajaxRequestAddItem.open("POST", "/ajax/ajaxitem.asp", true);
	ajaxRequestAddItem.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	ajaxRequestAddItem.send(queryString); 
}

function ajaxLogin(task,list,member){
	
	var ajaxRequestLogin;
	
	try{
		ajaxRequestLogin = new XMLHttpRequest();
	} catch (e){
		try{
			ajaxRequestLogin = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequestLogin = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				return false;
			}
		}
	}
	
	ajaxRequestLogin.onreadystatechange = function(){
		if(ajaxRequestLogin.readyState == 4){
			document.getElementById('loginform').innerHTML = ajaxRequestLogin.responseText.substr(0,ajaxRequestLogin.responseText.indexOf("<!--social-->"));


			if (document.getElementById('soc')) {
				document.getElementById('soc').innerHTML = ajaxRequestLogin.responseText.substr(ajaxRequestLogin.responseText.indexOf("<!--social-->"));
				if (ajaxRequestLogin.responseText.match("fbshare")) {
					var GM_Script = document.createElement('script');
					GM_Script.src = 'http://connect.facebook.net/en_US/all.js#xfbml=1';
					GM_Script.type = 'text/javascript';
					document.getElementsByTagName('body')[0].appendChild(GM_Script);
					var GM_Script2 = document.createElement('script');
					GM_Script2.src = 'http://platform.twitter.com/widgets.js';
					GM_Script2.type = 'text/javascript';
					document.getElementsByTagName('body')[0].appendChild(GM_Script2);
				}
			}
			if (ajaxRequestLogin.responseText.match("logged in") && document.getElementById('addnewitem')){
				ajaxAddItem(list);
			}
			else if (document.getElementById('addnewitem')){
				document.getElementById('addnewitem').innerHTML = '';
			}
			if (ajaxRequestLogin.responseText.match("logged in") && document.getElementById('messagelink') && ajaxRequestLogin.responseText.match("ajaxFriend")){
				document.getElementById('messagelink').style.display = 'block';
			}
			else if (document.getElementById('messagelink')){
				document.getElementById('messagelink').style.display = 'none';
			}
			if (document.getElementById('isfriend') && document.getElementById('messagefriend'))
			{
				document.getElementById('messagefriend').style.display = 'block';
			}
		}
	}
	user = '';
	pass = '';
	if (document.getElementById('username')) {
		user = document.getElementById('username').value;
		pass = document.getElementById('password').value;
	}
	if (task == 'login') {
		document.getElementById('loginform').innerHTML = '<img src="http://208.109.211.97/img/ajax-loader.gif">';
	}
	var queryString = "task=" + task + "&user=" + user + "&pass=" + pass + "&list=" + list + "&member=" + member + "&script=" + window.location.href;
	ajaxRequestLogin.open("POST", "/ajax/ajaxlogin.asp", true);
	ajaxRequestLogin.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	ajaxRequestLogin.send(queryString); 
}

function showVotes(listID){

	setAjaxVariable();
	
	var span = document.getElementsByTagName("span");

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplayVotes = document.getElementById('ajaxSwapSpace');
			ajaxDisplayVotes.innerHTML = ajaxRequest.responseText;
			
			for(i=0; i<span.length; i++)if(span[i].id.match("i"))
				{
				if ( document.getElementById('v' + span[i].id.slice(1)) ){
					document.getElementById(span[i].id).innerHTML = document.getElementById('v' + span[i].id.slice(1)).value;
				}
				document.getElementById(span[i].id).style.display = "block";
				}
			ajaxDisplayVotes.innerHTML = "";
			if (Math.random() < .99) saveTerm(listID);
		}
	}
	
	var queryString = "id=" + listID + "&r=" + Math.floor(Math.random()*1001);
	ajaxRequest.open("POST", "/vote.asp", true);
	ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	ajaxRequest.send(queryString); 
}

function saveTerm(listID){
	setAjaxVariable();
	
	var category = "";
	if (document.getElementById('crumbs').childNodes[1])
	{
		category = document.getElementById('crumbs').childNodes[1].href;
		category = category.replace("http://www.mymusiclists.com/","");
		category = category.replace("/","");
	}
	
	term = document.referrer;
	var regexS = "[\\?&]q=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( term );
	if( results != null && category != "")
	{
		var queryString = "list=" + listID + "&category=" + category + "&term=" + results[1];
		ajaxRequest.open("POST", "/ajaxsearch.asp", true);
		ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		ajaxRequest.send(queryString); 
	}
}

function recordvote(itemID,userID){
	var span = document.getElementsByTagName("span");
	for(i=0; i<span.length; i++)if(span[i].id.match("i"))
		{
		document.getElementById(span[i].id).innerHTML = '<img src="http://208.109.211.97/img/ajax-loader.gif" style="width:16px">';
		}

	var ajaxRequestVote;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequestVote = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequestVote = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequestVote = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				//alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequestVote.onreadystatechange = function(){
		if(ajaxRequestVote.readyState == 4){
			var ajaxDisplay = document.getElementById('ajaxSwapSpace');
			ajaxDisplay.innerHTML = ajaxRequestVote.responseText;
			
			for(i=0; i<span.length; i++)if(span[i].id.match("i") && document.getElementById('v' + span[i].id.slice(1)))
			{
				document.getElementById(span[i].id).innerHTML = document.getElementById('v' + span[i].id.slice(1)).value;
			}
			
			if (document.getElementById('c' + itemID) && document.getElementById('commentform'))	
			{
				document.getElementById('c' + itemID).innerHTML = document.getElementById('commentform').innerHTML + document.getElementById('c' + itemID).innerHTML;
			}
			ajaxDisplay.innerHTML = "";
		}
	}
	
	var queryString = "id=" + itemID + "&user=" + userID;
	ajaxRequestVote.open("POST", "/recordvote.asp", true);
	ajaxRequestVote.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	ajaxRequestVote.send(queryString); 
	pageTracker._trackEvent(itemID, 'Vote');
}

function ajaxMemberData(user,username,type,start,sortby){
	var ajaxDisplay = document.getElementById('memberajax');
	document.getElementById('memberlist').className='';
	document.getElementById('membercomment').className='';
	document.getElementById('memberblogpost').className='';
	document.getElementById('memberblogcomment').className='';
	document.getElementById('memberfriends').className='';
	document.getElementById('memberfollowers').className='';
	document.getElementById('memberfavorites').className='';
	document.getElementById('member' + type).className='membernavover';
	ajaxDisplay.innerHTML = '<br><br><img src="http://208.109.211.97/img/ajax-loader.gif"><br><br>';
	
	setAjaxVariable();
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	var queryString = "user=" + user + "&username=" + username + "&type=" + type + "&start=" + start + "&sortby=" + sortby;
	ajaxRequest.open("POST", "/ajaxmember.asp", true);
	ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	ajaxRequest.send(queryString); 
}

function addfriend(task,friendID){

	setAjaxVariable();
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajaxFriend');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	var queryString = "task=" + task + "&friend=" + friendID;
	ajaxRequest.open("POST", "/ajax/ajaxfriend.asp", true);
	ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	ajaxRequest.send(queryString); 
}

function addFavorite(task,userID,listID){

	setAjaxVariable();
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajaxFavorite');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	var queryString = "task=" + task + "&id=" + userID + "&list=" + listID;
	ajaxRequest.open("POST", "/ajax/ajaxfavorite.asp", true);
	ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	ajaxRequest.send(queryString); 
}

function getDuplicateItems(){

	var title = document.getElementById('title').value;

	setAjaxVariable();
	
	var ajaxDisplay = document.getElementById('itemsearch');
	ajaxDisplay.innerHTML = '<img src="http://www.the-top-tens.com/img/ajax-loader.gif" style="margin-top:15px">'
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			if (ajaxRequest.responseText != ""){
				ajaxDisplay.innerHTML = '<div class="loginform"><strong>Is your addition already listed?</strong><br><br>' + ajaxRequest.responseText + '</div>';
			}
			else{
				ajaxDisplay.innerHTML = '';
			}
		}
	}
	
	title = title.replace(/ /g, "+");
	title = title.replace(/&/g, "^^");
	var queryString = "task=item&title=" + title + "&list=" + document.getElementById('list').value;
	if (title.length > 2 && title == document.getElementById('title').value) 
	{
		ajaxRequest.open("POST", "/ajaxduplicate.asp", true);
		ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		ajaxRequest.send(queryString); 
	}
	else
	{
		ajaxDisplay.innerHTML = '';
	}
}

function trackConv(listID,itemID){

}

var stopWords = ',,a,able,about,across,after,all,almost,also,am,among,an,and,any,are,as,at,awesome,band,be,because,been,best,but,by,can,cannot,could,dear,did,do,does,either,else,ever,every,for,from,get,good,got,great,greatest,had,has,have,he,her,hers,him,his,how,however,i,if,in,into,is,it,its,just,least,let,like,likely,lol,may,me,might,most,must,my,neither,no,nor,not,of,off,often,on,only,or,other,our,own,rather,said,say,says,she,should,since,so,song,songs,some,than,that,the,their,them,then,there,these,they,this,tis,to,too,twas,us,vote,wants,was,we,were,what,when,where,which,while,who,whom,why,will,with,would,wtf,yet,you,your,';

function commentScore(){
	if (document.getElementById('listTitle'))
	{
		stopWords = stopWords + document.getElementById('listTitle').innerHTML.toLowerCase().replace(/ /g,",") + "," + document.getElementById('itemTitle').innerHTML.toLowerCase().replace(/ /g,",") + ",";
	}
	if (document.getElementsByTagName("h1")[0])
	{
		stopWords = stopWords + document.getElementsByTagName("h1")[0].innerHTML.toLowerCase().replace(/ /g,",") + ",";
	}
	var negScore = 2;
	var commentArray = document.getElementById('comments').value;
	for (i=0;i<=9;i++)
	{
		if (commentArray.toLowerCase().match(i + ". ")) {negScore = negScore + 2}
		commentArray = commentArray.replace(i,"");
	}
	commentArray = commentArray.replace(/\./g,"");
	commentArray = commentArray.replace(/\?/g,"");
	commentArray = commentArray.replace(/,/g,"");
	commentArray = commentArray.replace(/!/g,"");
	commentArray = commentArray.replace(/\(/g,"");
	commentArray = commentArray.replace(/\)/g,"");
	commentArray = commentArray.replace(/\n/g," ");
	commentArray = commentArray.replace(/  /g," ");
	commentArray = commentArray.split(" ");
	for (x=0;x<commentArray.length;x++)
	{
		if (commentArray[x].length > 20) {negScore = negScore + 3}
		if (commentArray[x].length == 1) {negScore = negScore + 1}
		if (commentArray[x].toLowerCase().match("http:")) {negScore = negScore + 5}
		if (stopWords.match(","+commentArray[x].toLowerCase()+",")) {commentArray.splice(x,1);x--;}
	}
	
	var ratingCode = '<div style="float:left;margin:-2px 10px 0 10px;font-weight:bold;font-size:10px">Comment Quality</div><div style="float:left;margin:-2px 3px 0 0;color:#7B7A7F;font-size:10px">poor</div>';
	var ratingColors = ["7B7A7F","CC0033","CC0033","FF9900","FF9900","FFCC00","FFCC00","006699","006699","339900"]
	var rating = commentArray.length - negScore;
	if (rating < 0) {rating = 0}
	for (i=0;i<10;i++)
	{
		ratingCode = ratingCode + '<div style="height:10px;width:20px;float:left;margin:2px 1px 0 0;background:#'
		if (rating >= i) 
			{ratingCode = ratingCode + ratingColors[i]}
		else
			{ratingCode = ratingCode + 'F8FCFF'}
		ratingCode = ratingCode + '"></div>';
	}
	ratingCode = ratingCode + '<div style="float:left;margin:-2px 0 0 3px;color:#7B7A7F;font-size:10px">good</div><br clear="all">';
	//document.getElementById('commentscore').innerHTML = stopWords + "<br><br>" + commentArray + "<br><br>" + ratingCode + "<br><br>" + negScore;
	document.getElementById('commentscore').innerHTML = ratingCode;
}
