function createXMLHttpRequest() 
{

   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   try { return new XMLHttpRequest(); } catch(e) {}
   alert("XMLHttpRequest not supported");
   return null;
   
 }
 
 function GetElementContents( name )
 {
	Target = document.getElementById( name );	
	if (!Target) return '';
	
	return Target.innerHTML;
 }

 function SetElement( name, text )
 {
 	Target = document.getElementById( name );	
	if (!Target) return;
	
	Target.innerHTML = text;
 }
 
 function AddElement( name, text )
 {
 	Target = document.getElementById( name );	
	if (!Target) return;
	
	Target.innerHTML = Target.innerHTML + text;
 }
 
 function ShowElement( name, show )
 {
	Target = document.getElementById( name );	
	if (!Target) return;
	
	if ( !show )
	{
		Target.style.display = "none";
	}
	else
	{
		Target.style.display = "";
	}
 }
 
 function OpenScrollWindow(theURL,winName,theWidth,theHeight) {
	var x=Math.min(screen.width,theWidth);
	var y=Math.min(screen.height-25,theHeight);
	window.open(theURL,winName,'width='+x+',height='+y+',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,top='+((screen.height/2)-(y/2))+',left='+((screen.width/2)-(x/2))+'');
}

var xmlSearch = false;
	var LastSearch = '';
	
function SearchMoreRespond()
	{
		if ( xmlSearch.readyState != 4 ) return;
		
		//SetElement( 'SearchMore', '' );	
	
		AddElement( 'content', xmlSearch.responseText );
		delete xmlSearch;
		xmlSearch = false;
	}
	
	function SearchMore( offs, searchsr )
	{
		xmlSearch = createXMLHttpRequest();
		xmlSearch.open( "GET", "http://"+document.location.hostname+"/includes/search.php?q="+searchsr, true );
		xmlSearch.onreadystatechange = SearchMoreRespond;
		xmlSearch.send( null );
		
		SetElement( 'SearchMore'+offs, '' );		
		return false;
	}
	
	function SearchRespond()
	{
		if ( xmlSearch.readyState != 4 ) return;
		
		SetElement( 'results', xmlSearch.responseText );
		ShowElement( 'SearchStatus', false );
		
		delete xmlSearch;
		xmlSearch = false;
		
	}
	
	function StartSearch( name )
	{
		if ( LastSearch == name ) return;
		LastSearch = name;
		
		SetElement( 'SearchStatus', '<img src="http://www.saurdo.com/includes/images/loading.gif">' );
		ShowElement( 'SearchStatus', true );
		
		xmlSearch = createXMLHttpRequest();
		xmlSearch.open( "GET", "http://"+document.location.hostname+"/includes/search.php?q="+name, true );
		xmlSearch.onreadystatechange = SearchRespond;
		xmlSearch.send( null );
	}
	
	function QuickSearch( Input, e )
	{
		e = e ? e : window.event;
 
		if (!e)
		{
			alert("Couldn't Get Event..");
		}
		
		if ( e.keyCode != 13 && e.which != 13 ) return;
		if ( Input.value.length < 3 )
		{
			alert( 'Enter 3 or more characters!' );
			return;
		}
		
		StartSearch( Input.value );
 
	}
	
	function SearchTag( name )
	{
		StartSearch( name );
		
		var SearchBox = document.getElementById( 'searchinput' );
		if ( SearchBox )
		{
			SearchBox.value = name;
		}
		
		return false;
	}
	
		function postsRespond()
	{
		if ( xmlSearch.readyState != 4 ) return;
		
		SetElement( 'results', xmlSearch.responseText );
		ShowElement( 'SearchStatus', false );
		
		delete xmlSearch;
		xmlSearch = false;
		
	}
	
	function Startposts( name )
	{		
		SetElement( 'SearchStatus', '<img src="http://www.saurdo.com/includes/images/loading.gif">' );
		ShowElement( 'SearchStatus', true );
		
		xmlSearch = createXMLHttpRequest();
		xmlSearch.open( "GET", "http://"+document.location.hostname+"/includes/postlist.php"+name, true );
		xmlSearch.onreadystatechange = postsRespond;
		xmlSearch.send( null );
	}
	
			function catsRespond()
	{
		if ( xmlSearch.readyState != 4 ) return;
		
		SetElement( 'dostuff', xmlSearch.responseText );
		ShowElement( 'SearchStatus', false );
		
		delete xmlSearch;
		xmlSearch = false;
		
	}
	
	function startcats( name )
	{		
		SetElement( 'SearchStatus', '<img src="http://www.saurdo.com/includes/images/loading.gif">' );
		ShowElement( 'SearchStatus', true );
		
		xmlSearch = createXMLHttpRequest();
		xmlSearch.open( "GET", "http://"+document.location.hostname+"/includes/categories.php?q="+name, true );
		xmlSearch.onreadystatechange = catsRespond;
		xmlSearch.send( null );
	}
	
	function catsrRespond()
	{
		if ( xmlSearch.readyState != 4 ) return;
		
		SetElement( 'results', xmlSearch.responseText );
		ShowElement( 'SearchStatus', false );
		
		delete xmlSearch;
		xmlSearch = false;
		
	}
	
	function startcatsr( name )
	{		
		SetElement( 'SearchStatus', '<img src="http://www.saurdo.com/includes/images/loading.gif">' );
		ShowElement( 'SearchStatus', true );
		
		xmlSearch = createXMLHttpRequest();
		xmlSearch.open( "GET", "http://"+document.location.hostname+"/includes/categories.php?q="+name, true );
		xmlSearch.onreadystatechange = catsrRespond;
		xmlSearch.send( null );
	}
	
	
	function setstuff(type){
	if(type == 'search'){
	SetElement('dostuff', '<p>Search: <input type="text" id="searchinput" onKeyPress="QuickSearch( this, event );">');
	SetElement('results', '');}
	else if(type == 'category'){
		startcats('cats');
		SetElement('results', '');
		}
	else if(type == 'posts'){
		SetElement('dostuff', '<p>All posts in entire posting history!');
		SetElement('results', '');
		Startposts('');}
	else{
	SetElement('doatuff', type);
	SetElement('results', '');}
	}
 
onload=function() {
	blocked = 0;
	if (document.getElementById('ads').offsetHeight == 0){
		blocked = 1;
		showads();
	}
		recordBlock(blocked);
}
 
function showads(){
	SetElement('ads', 'It has been detected that you are blocking advertisements on this website. You are free to do so and I will not try to stop you. Just know that, although you are clearly not interested in clicking any of the advertisements on this website, effortlessly viewing them has a large impact on the amount of revenue that is gained from them;  revenue that goes towards keeping this website online. The advertisements are as harmless and unobtrusive as the text you are reading right now. Simply putting this website on your white list would make all the difference. If you choose, you may also support the website by donating. <p><center><form action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_s-xclick"><input type="hidden" name="hosted_button_id" value="2279868"><input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit" alt=""><img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"></form></center>');
}
function recordBlock(b)
{
	b = typeof(b) != 'undefined' ? b : 0;
 
	xmlPost = createXMLHttpRequest();
	xmlPost.open( "GET", "http://"+document.location.hostname+"/recordblock.php?b="+b, true );
	xmlPost.send( null );
}
