if (document.images)
{
  pic1= new Image(16,16); 
  pic1.src="http://www.the-top-tens.com/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(){

	setAjaxVariable();
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajaxDiv');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
			fadeComment();
		}
	}
	var item = document.getElementById('item').value;
	var comments = document.getElementById('comments').value;
	comments = comments.replace(/ /g, "+");
	comments = comments.replace(/\n/g, "##");
	comments = comments.replace(/&/g, "^^");
	var userid = document.getElementById('userid').value;
	var catchpa = document.getElementById('catchpa').value;
	var signature = "no";
	//alert(document.getElementById('catchpa').checked);
	if (document.getElementById('signature').checked == true)
		{
		var signature = "yes";
		}
	var queryString = "item=" + item + "&comments=" + comments + "&userid=" + userid + "&signature=" + signature + "&catchpa=" + catchpa;
	ajaxRequest.open("POST", "/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(){
	
	setAjaxVariable();
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('addnewitem');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	var list = document.getElementById('listid').value;
	var title = document.getElementById('title').value;
	title = title.replace(/ /g, "+");
	title = title.replace(/&/g, "^^");
	var content = document.getElementById('comments').value;
	content = content.replace(/ /g, "+");
	content = content.replace(/\n/g, "##");
	content = content.replace(/&/g, "^^");
	var userid = document.getElementById('userid').value;
	var signature = "no";
	if (document.getElementById('signature').checked==true)
		{
		var signature = "yes";
		}
	var catchpa = document.getElementById('catchpa').value;
	var queryString = "list=" + list + "&title=" + title + "&content=" + content + "&userid=" + userid + "&signature=" + signature + "&catchpa=" + catchpa;
	ajaxRequest.open("POST", "/ajaxitem.asp", true);
	ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	ajaxRequest.send(queryString); 
}

function ajaxLogin(task){
	
	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;
		}
	}
	user = '';
	pass = '';
	if (document.getElementById('username')) {
		user = document.getElementById('username').value;
		pass = document.getElementById('password').value;
	}
	var queryString = "task=" + task + "&user=" + user + "&pass=" + pass;
	ajaxRequestLogin.open("POST", "/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 ajaxDisplay = document.getElementById('ajaxSwapSpace');
			ajaxDisplay.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";
				}
			ajaxDisplay.innerHTML = "";
		}
	}
	
	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 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://www.the-top-tens.com/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(span[i].id).innerHTML = document.getElementById('v' + span[i].id.slice(1)).value;
				}
			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://www.the-top-tens.com/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,userID,friendID,friendName){

	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 + "&id=" + userID + "&friend=" + friendID + "&name=" + friendName;
	ajaxRequest.open("POST", "/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", "/ajaxfavorite.asp", true);
	ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	ajaxRequest.send(queryString); 
}

function trackConv(listID){
	if (listID == 195)
	{
		document.getElementById('ajaxSwapSpace').innerHTML = '<img height="1" width="1" border="0" src="http://www.googleadservices.com/pagead/conversion/1060307750/?value=5.0&amp;label=xlAHCKy2YBCmhsz5Aw&amp;script=0"/><IMG width=1 height=1 SRC="http://101574.r.msn.com/?type=1&cp=1"/>';
		pageTracker._trackEvent('Credit Repair', 'Click');
	}
	if (listID == 4183)
	{
		pageTracker._trackEvent('Vacation Planning', 'Click');
	}
}