if (top.location!= self.location)
{
	top.location = self.location.href
} 

function recaptcha()
{
	var srcs = document.getElementById('captcha').src;
	document.getElementById('captcha').src = srcs + "#";
}


function blinker(ele)
{

	$(ele).fadeTo("fast", 0.33);
	$(ele).fadeTo("fast", 1.0);
	$(ele).fadeTo("fast", 0.33);
	$(ele).fadeTo("fast", 1.0);
	$(ele).fadeTo("fast", 0.33);
	$(ele).fadeTo("fast", 1.0);
	$(ele).fadeTo("fast", 0.33);
	$(ele).fadeTo("fast", 1.0);

}


function openreport(main, sub)
{
	$.facebox({ ajax: '/callback/report.php?sub=' + sub + '&main=' + main });
}

function suggestTag(siteid)
{
	$.facebox({ ajax: '/callback/suggestTag.php?sidm=' + siteid});
}


function makereport(main, sub)
{
	$('#result2').html('');
	
	var reportType = $('input[name=report]:checked').val();
	var secret = $('#secure').val();

	if(!reportType)
	{
		$('#result2').html('<span style="color:red">No option selected</span>');
		return;
	}
	else
	{
		if(!secret)
		{
			$('#result2').html('<span style="color:red">Captcha field was empty</span>');
			return;
		}
		else
		{
			$.post("/callback/report.php", { 'main' : main, 'sub' : sub, 'secret' : secret, 'reportType' : reportType},
			function(data)
			{
				var response = data.split('::');
				if(response[0] == 'error')
				{
					$('#result2').html('<span style="color:red">'+response[1]+'</span>');
				}
				else
				{
					$('#maincontent').html('<h1 style="color:green">Report Saved, Thanks!</h1>');
				}
			});
		}
	}
}

function suggestTags(siteid)
{
	var textfield = $('#tagField').val();
	var secret = $('#secure').val();
	
	if(textfield == '' || secret == '')
	{
		$('#result2').html('<span style="color:red">Captcha/Tag field was empty</span>');
		return;
	}
	else
	{
		$.post("/callback/suggestTag.php", { 'sidm' : siteid, 'secret' : secret, 'tags' : textfield},
		function(data)
		{
			var response = data.split('::');
			if(response[0] == 'error')
			{
				$('#result2').html('<span style="color:red">'+response[1]+'</span>');
			}
			else
			{
				$('#maincontent').html('<h1 style="color:green">Tags have been received!</h1><br />Thank you for your contribution, your tags will be evaluated and added shortly.');
			}
		});
	}
}

function vote(direction, mainsite, subsite, checksum)
{

	$.post("/callback/vote.php", { 'direction' : direction, 'mainsite' : mainsite, 'subsite' : subsite, 'checksum' : checksum},
	function(data)
	{
		response = data.split('::');
		if(response[0] == 'error')
		{
			alert(response[1]);
		}
		if(response[0] == 'success')
		{
			
			if(direction == 'up')
			{
				blinker('#rate-' + response[1]);
				$('#rate-' + response[1]).html(response[2]);
			}
			else
			{
				blinker('#rate-' + response[1]);
				$('#rate-' + response[1]).html(response[2]);
			}
		}
		
	});
}
function addreference(refcode)
{
	$('.hide').remove();

	var site = $('#postlink').val();
	var captcha = $('#void').val();
	var tags = $('#tagsfield').val();
	

	if(site != '' && captcha != '')
	{
		var answer = confirm("READ THESE RULES!\n\n * Providing unrelated links will result in a permanent ban\n * In case of spam all links to the site in question will be removed (site wide)\n\n We are dedicated to keep the results clean and accurate. \nABUSE WILL NOT BE TOLERATED!\n");
		if(!answer)
		{
			return;
		}
		
		$.post("/add", { ajax:'1', 'ref':refcode, 'url':site, 'secret':captcha, 'tags':tags},
		function(data)
		{
			response = data.split('::');

			if(response[0] == 'exists')
			{
				$('#postlink').val('');
				$('#void').val('');
				recaptcha();
				$('.hide').remove();
				$.scrollTo('#thisid-' + response[1], 300);
				blinker('#thisid-' +response[1]);

			}
			else if(response[0] == 'error')
			{
				$('#result').html('<center style="color:red">'+response[1]+'</center>');
			}
			else
			{
				if(response[0] == 'success')
				{
					$.scrollTo('#newsite', 300);
					$('#postlink').val('');
					$('#void').val('');
					$('#tagsfield').val('');
					recaptcha();
					$('#result').html('<center style="color:green">Website was added (pending review), feel free ad add another one.</center>');
					$('#newsite').append(response[1]).slideDown();
					$.scrollTo('#newsite', 300);
					blinker('#newsite');
				}
			}
		});
	}
}

function bookmark(ele,link)
{

	var name = link;
	var title = 'Websites that are similar to ' + link;	
	link = 'http://www.siteslike.com/similar/'+ link;
	var mark = '<center>';

	mark += '<div class="BM_bookmarks cleartop">';
	mark += '<ul class="socials">';

	mark += '<li class="BM_delicious">';
	mark += '<a title="Share this on del.icio.us" rel="nofollow" target="_blank" href="http://del.icio.us/post?url='+link+'&amp;title='+title+'"> </a>';
	mark += '</li>';

	mark += '<li class="BM_digg">';
	mark += '<a title="Digg this!" rel="nofollow" target="_blank" href="http://digg.com/submit?phase=2&amp;url='+link+'&amp;title='+title+'"> </a>';
	mark += '</li>';

	mark += '<li class="BM_mixx">';
	mark += '<a title="Mixx it up!" rel="nofollow" target="_blank" href="http://www.mixx.com/submit?page_url='+link+'&amp;title='+title+'"> </a>';
	mark += '</li>';

	mark += '<li class="BM_reddit">';
	mark += '<a title="Share this on Reddit" rel="nofollow" target="_blank" href="http://reddit.com/submit?url='+link+'&amp;title='+title+'"> </a>';
	mark += '</li>';

	mark += '<li class="BM_twitter">';
	mark += '<a title="Tweet This!" rel="nofollow" target="_blank" href="http://twitter.com/home?status=Check this out: Websites that are similar to '+name+' - '+link+'"> </a>';
	mark += '</li>';

	mark += '<li class="BM_yahoo">';
	mark += '<a title="Buzz up!" rel="nofollow" target="_blank" href="http://buzz.yahoo.com/submit/?submitUrl='+link+'&amp;yahooBuzzArticleHeadline='+title+'"> </a>';
	mark += '</li>';

	mark += '<li class="BM_stumble">';
	mark += '<a title="Stumble upon something good? Share it on StumbleUpon" rel="nofollow" target="_blank" href="http://www.stumbleupon.com/submit?url='+link+'&amp;title='+title+'"> </a>';
	mark += '</li>';

	mark += '<li class="BM_technorati">';
	mark += '<a title="Share this on Technorati" rel="nofollow" target="_blank" href="http://technorati.com/faves?add='+link+'"> </a>';
	mark += '</li>';


	mark += '<li class="BM_facebook">';
	mark += '<a title="Share this on Facebook" rel="nofollow" target="_blank" href="http://www.facebook.com/sharer.php?src=bm&v=4&u='+link+'&t='+title+'"> </a>';
	mark += '</li>';

	mark += '<li class="BM_email">';
	mark += '<a title="Email this page to a friend" rel="nofollow" target="_blank" href="mailto:?subject='+title+'"> </a>';
	mark += '</li>';

	mark += '</ul>';
	mark += '</div>';

	mark += '</center>';
	
	$(ele).append(mark);
}

function setBookmark(siteid)
{
		$.post("/callback/bookmarking.php", { 'id':siteid, 'action':'bookmark'},
		function(data)
		{
			$('#bmDyn').html(data);
		});
}

function setBookmarkLite(siteid)
{
		$.post("/callback/bookmarking.php", { 'id':siteid, 'action':'bookmark'},
		function(data)
		{
			document.getElementById('bmLite-' + siteid).src = '/images/ok.gif';
		});
}

function unBookmark(siteid)
{
	$.post("/callback/bookmarking.php", { 'id':siteid, 'action':'unBookmark'},
	function(data)
	{
		$('#s-' + siteid).remove();
	});
}

function tracker(id)
{
	$.post("/callback/count.php", { 'id': id } );
}

function plusC(id,v)
{
	$('#vtnr-' + id).html(v);
}
