function make_http() {

	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}

	return xmlhttp;

}

function get_view_feed(fid,gwords) {

	document.getElementById('feed_close').innerHTML = '<img src=/gfx/i_transmit.gif border=0> fetching feed...';

	xmlhttp = make_http();

	xmlhttp.open("GET", "/ajax_get_feed.php?feed="+fid+"&google="+gwords+"",true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {

	        if (xmlhttp.status == 200) {

				resultcheck = xmlhttp.responseText;

				document.getElementById('feed_display').innerHTML = xmlhttp.responseText;
				/*document.getElementById('feed_display').style.display = 'block';*/
				Effect.BlindDown('feed_display');
				document.getElementById('feed_close').innerHTML = '<a href="javascript:close_feed()"><img src=/gfx/i_rss_delete.gif border=0></a> <a href="javascript:close_feed()">Close this feed</a>';
	        } else {
				// error stuff
				//alert('problem with the page :(');	
			}
		}

	}
	xmlhttp.send(null);


}

function get_category_images(what) {

	xmlhttp = make_http();

	xmlhttp.open("GET", "/ajax_category_images.php?w="+what+"",true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {

	        if (xmlhttp.status == 200) {

				resultcheck = xmlhttp.responseText;

				document.getElementById('images_'+what).innerHTML = xmlhttp.responseText;
	        } else {
				// error stuff
				//alert('problem with the page :(');	
			}
		}

	}
	xmlhttp.send(null);

}

function get_image_rips(where) {

	xmlhttp = make_http();

	xmlhttp.open("GET", "/ajax_image_ripper.php?u="+where+"",true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {

	        if (xmlhttp.status == 200) {

				resultcheck = xmlhttp.responseText;

				if (resultcheck == 'error') {
					parent.document.getElementById('cant_find_imgs').style.display = 'block';
					parent.document.getElementById('loading_img').style.display = 'none';
				} else {
					document.getElementById('loadingrips').innerHTML = xmlhttp.responseText;
				}
	        } else {
				// error stuff
				//alert('problem with the page :(');	
			}
		}

	}
	xmlhttp.send(null);

}

function growl_read_pm(what) {

	xmlhttp = make_http();

	xmlhttp.open("GET", "/ajax_read_pm.php?pmid="+what+"",true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {

	        if (xmlhttp.status == 200) {

				resultcheck = xmlhttp.responseText;

				pgrowl("Message Marked as Read","The above PM has been marked as read","pg_notifyonly");

	        } else {
				// error stuff
				//alert('problem with the page :(');	
			}
		}

	}
	xmlhttp.send(null);

}

function read_pm(what) {

	xmlhttp = make_http();

	xmlhttp.open("GET", "/ajax_read_pm.php?pmid="+what+"",true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {

	        if (xmlhttp.status == 200) {

				resultcheck = xmlhttp.responseText;

				if (resultcheck == 'ERROR') {
					alert('access problem with the page :(');	
				} else {
					get_pm(what);
				}
	        } else {
				// error stuff
				//alert('problem with the page :(');	
			}
		}

	}
	xmlhttp.send(null);

}

function check_new_pms() {

	new Ajax.Request(
		'/ajax_get_newpm.php', 
		{
			onSuccess: function(transport) 
				{
					if (transport.responseText != '') {

						pgrowl('New Private Message','<div class="pg_newpm">'+transport.responseText+'</div>','pg_innerclose pg_notifyonly');

					}
				}
		}
	); 

	get_pm_info();

	setTimeout("check_new_pms()",5000);

}

function get_pm_info() {

	xmlhttp = make_http();

	xmlhttp.open("GET", "/ajax_pm_info.php",true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {

	        if (xmlhttp.status == 200) {

				resultcheck = xmlhttp.responseText;

				if (resultcheck == 'ERROR') {
					alert('access problem with the page :(');	
				} else {
					if (resultcheck != '0') {
						document.getElementById('mymail').innerHTML = '<span style="font-weight:normal"><img src=/gfx/gotmail.gif border=0 title="You have '+resultcheck+' new privates message(s)" style="margin-top:3px"> '+resultcheck+'</span>';
					} else {
						document.getElementById('mymail').innerHTML = '';
					}

				}
	        } else {
				// error stuff
				//alert('problem with the page :(');	
			}
		}

	}
	xmlhttp.send(null);

}

function get_pm(what) {

	xmlhttp = make_http();

	xmlhttp.open("GET", "/ajax_get_pm.php?pmid="+what+"",true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {

	        if (xmlhttp.status == 200) {

				resultcheck = xmlhttp.responseText;

				if (resultcheck == 'ERROR') {
					alert('access problem with the page :(');	
				} else {
					document.getElementById('pm_'+what).innerHTML = resultcheck;
				}
				get_pm_info();
	        } else {
				// error stuff
				//alert('problem with the page :(');	
			}
		}

	}
	xmlhttp.send(null);

}

function show_pms(what,thisnum) {

	xmlhttp = make_http();

	document.getElementById('open_'+thisnum).innerHTML = 'getting messages...';

	xmlhttp.open("GET", "/ajax_show_pms.php?pmid="+what+"",true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {

	        if (xmlhttp.status == 200) {

				resultcheck = xmlhttp.responseText;

				if (resultcheck == 'ERROR') {
					//alert('access problem with the page :(');	
				} else {
					thispm = 'pms_'+thisnum;
					document.getElementById('open_'+thisnum).style.display = 'none';
					document.getElementById(thispm).style.display = 'block';
					document.getElementById(thispm).innerHTML = resultcheck;
					nextnum = thisnum + 1;
					document.getElementById('open_'+nextnum).style.display = 'block';
				}
	        } else {
				// error stuff
				//alert('problem with the page :(');	
			}
		}

	}
	xmlhttp.send(null);

}

function delete_pm(what) {

	xmlhttp = make_http();

	xmlhttp.open("GET", "/ajax_delete_pm.php?pmid="+what+"",true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {

	        if (xmlhttp.status == 200) {

				resultcheck = xmlhttp.responseText;

				if (resultcheck == 'ERROR') {
					//alert('access problem with the page :(');	
				} else {
					new Effect.DropOut('pm_'+what);	
					get_pm_info();
				}
	        } else {
				// error stuff
				//alert('problem with the page :(');	
			}
		}

	}
	xmlhttp.send(null);

}

function show_stat() {

	document.getElementById('show_stat').style.display = 'none';
	document.getElementById('hide_stat').style.display = 'block';

}
function hide_stat() {

	document.getElementById('show_stat').style.display = 'block';
	document.getElementById('hide_stat').style.display = 'none';
	document.getElementById('stat_up').innerHTML = '';
}
function confirm_logout() {

	document.getElementById('confirmlogout').style.display = 'block';
	document.getElementById('logout').style.display = 'none';

}

function cancel_logout() {

	document.getElementById('confirmlogout').style.display = 'none';
	document.getElementById('logout').style.display = 'block';

}

function stat_updated() {

	document.getElementById('stat_up').innerHTML = '...updated!';

}

function show_membernav() {

//	var navstate = document.getElementById('mynav').style.display;
//	if (navstate == 'none') {
//		document.getElementById('mynav').style.display = 'block';
//		fetch_member_memberbox();
//	} else {
//		document.getElementById('mynav').style.display = 'none';
//	}

	load_pop('ajax','/memberbox.php');


}

function fetch_member_memberbox() {

	xmlhttp = make_http();

	xmlhttp.open("GET", "/ajax_fetch_memberbox.php",true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {

	        if (xmlhttp.status == 200) {

				resultcheck = xmlhttp.responseText;

				if (resultcheck == 'ERROR') {
					//alert('access problem with the page :(');	
				} else {
					document.getElementById('mynav_content').innerHTML = resultcheck;
					document.getElementById('mem_pic').className = 'glossy';
				}
	        } else {
				// error stuff
				//alert('problem with the page :(');	
			}
		}

	}
	xmlhttp.send(null);

}

function update_wurl() {

	wurl = document.sf.wurl.value;
	oldwurl = document.sf.oldwurl.value;

	if (wurl != oldwurl) {

		document.sf.oldwurl.value = wurl;
		cancel_ripimg();
		document.getElementById('loading_img').style.display = 'none';
		load_image_rip();

	}

}

function update_wtitle() {

	var thisurl = document.getElementById('wurl').value;


	new Ajax.Request(
		'/ajax_get_title.php?u='+escape(thisurl)+'', 
		{
			onSuccess: function(transport) 
				{
					if (transport.responseText != '') {
						thetitle = transport.responseText;
						document.getElementById('wtitle').value = thetitle;
						var wtleft = 65 - (thetitle.length);
						document.getElementById('wtleft').innerHTML = '<b>'+wtleft+'</b> characters left';
					}
				}
		}
	); 

}

function retry_thumb() {

	document.getElementById('tsrc').innerHTML = '<IMG SRC=/gfx/al.gif>';
	setTimeout("do_retry_thumb()",2000);

}

function do_retry_thumb() {

	var theimg = document.getElementById('ripimg').value;

	document.getElementById('thethumbsrc').src = ''+theimg+'';
	document.getElementById('tsrc').innerHTML = '';

}

function generate_thumb() {

	document.getElementById('thethumb').innerHTML = '<IMG SRC=/gfx/al.gif>';
	document.getElementById('thumbtxt').style.display = 'none';

	var thisurl = document.getElementById('wurl').value;

	new Ajax.Request(
		'/zt.php?a=new&url='+escape(thisurl)+'', 
		{
			onSuccess: function(transport) 
				{
					theinfo = transport.responseText;
					if (theinfo.indexOf("ERROR") != -1) {
						document.getElementById('thethumb').innerHTML = 'Internet monkeys say no - cannot generate a thumb for this URL...';
					} else {
						var thebits = theinfo.split("::");
						var thumbimg = thebits[1];
						document.getElementById('thethumb').innerHTML = '<div id="tsrc"></div><img src="'+thumbimg+'" width=80 style="float:left;margin-right:10px;margin-bottom:10px;" id="thethumbsrc"/> This image will be used for this story. If the image is showing the DeadAlfs logo, it\'s still being generated - hold on, and <a href="javascript:retry_thumb()">click here</a> to check if the internet monkeys are done yet';
						document.getElementById('ripimg').value = thumbimg;
					}
				}
		}
	); 

}

function load_image_rip() {

	var thisurl = document.sf.wurl.value;

	parent.document.getElementById('cant_find_imgs').style.display = 'none';

	if (document.getElementById('loading_img').style.display == 'none') {

		document.getElementById('loading_img').style.display = 'block';
	
		if (thisurl != '') {
			document.getElementById('image_ripper').innerHTML = '<iframe src="/ajax_image_ripper_loader.php?u='+thisurl+'" width=90 height=90 scrolling=no frameborder=0></iframe>';
			document.getElementById('url_link').innerHTML = 'Need to add an image? <a href="'+thisurl+'" target=_blank>Open this URL in a new window</a>';
			document.getElementById('url_link').style.display = 'block';
		} else {
			document.getElementById('url_link').innerHTML = '';
			document.getElementById('url_link').style.display = 'none';
		}

	}

}

function img_library() {

	var isopen = document.getElementById('img_lib_off').style.display;
	
	if (isopen == 'block') {
		/* show the library */
		document.getElementById('img_lib_off').style.display = 'none';
		document.getElementById('img_lib_on').style.display = 'block';
		document.getElementById('show_img_lib').innerHTML = '<iframe src="/ajax_library_image.php" width=412 height=136 scrolling=no frameborder=0></iframe>';
	} else {
		/* close the library */
		document.getElementById('img_lib_off').style.display = 'block';
		document.getElementById('img_lib_on').style.display = 'none';

	}
		

}

	function choose_libimg(thisimg) {

		document.getElementById('loading_img').style.display = 'block';
		document.getElementById('img_lib_off').style.display = 'block';
		document.getElementById('img_lib_on').style.display = 'none';
		document.getElementById('show_selected').style.display = 'block';
		document.sf.ripimg.value = thisimg;
		document.getElementById('theripimg').src = thisimg;
	
	}

function cancel_ripimg() {

	document.sf.ripimg.value = '';
	document.getElementById('theripimg').src = '/images/spacer.gif';
	document.getElementById('show_selected').style.display = 'none';

}

function ajax_rate_story(sid) {

	var thisform = 'ratestory_'+sid;

	var sbox = document.all[thisform].score;

	var score;

	for(var i = 0; i < sbox.length; i++) {

		if(sbox[i].checked) {
			score = sbox[i].value;
		}

	}

	var rating = document.all[thisform].rating.options[document.all[thisform].rating.selectedIndex].value;

	document.getElementById('ajaxstorylinks_'+sid).innerHTML = '<center>Updating... please wait...</center>';
	pause(2000);

	xmlhttp = make_http();

	xmlhttp.open("GET", "/ajax_rate_story.php?sid="+sid+"&score="+score+"&rating="+rating+"",true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			//alert(xmlhttp.responseText)
			ajax_get_story_rating(sid);
		} else {
			document.getElementById('ajaxstorylinks_'+sid).innerHTML = '<center>Updating... please wait...</center>';
		}
	}
	xmlhttp.send(null)

}

function ajax_get_story_rating(sid) {

	xmlhttp = make_http();

	xmlhttp.open("GET", "/ajax_get_story_rating.php?sid="+sid+"",true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			//alert(xmlhttp.responseText)
			document.getElementById('ajaxstorylinks_'+sid).innerHTML = xmlhttp.responseText;
		} else {
			document.getElementById('ajaxstorylinks_'+sid).innerHTML = '<center>Updating... please wait...</center>';
		}
	}
	xmlhttp.send(null)

}

function ajax_rate_blog(sid) {

	var thisform = 'ratestory_'+sid;

	var sbox = document.all[thisform].score;

	var score;

	for(var i = 0; i < sbox.length; i++) {

		if(sbox[i].checked) {
			score = sbox[i].value;
		}

	}

	var rating = document.all[thisform].rating.options[document.all[thisform].rating.selectedIndex].value;

	document.getElementById('ajaxstorylinks_'+sid).innerHTML = '<center>Updating... please wait...</center>';
	pause(2000);

	xmlhttp = make_http();

	xmlhttp.open("GET", "/ajax_rate_blog.php?sid="+sid+"&score="+score+"&rating="+rating+"",true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			//alert(xmlhttp.responseText)
			ajax_get_story_rating(sid);
		} else {
			document.getElementById('ajaxstorylinks_'+sid).innerHTML = '<center>Updating... please wait...</center>';
		}
	}
	xmlhttp.send(null)

}

function ajax_get_blog_rating(sid) {

	xmlhttp = make_http();

	xmlhttp.open("GET", "/ajax_get_blog_rating.php?sid="+sid+"",true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			//alert(xmlhttp.responseText)
			document.getElementById('ajaxstorylinks_'+sid).innerHTML = xmlhttp.responseText;
		} else {
			document.getElementById('ajaxstorylinks_'+sid).innerHTML = '<center>Updating... please wait...</center>';
		}
	}
	xmlhttp.send(null)

}

function ajax_session(seshname,sesh) {

	xmlhttp = make_http();

	xmlhttp.open("GET", "/ajax_session.php?sesh="+sesh+"&seshname="+seshname+"",true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			//alert(xmlhttp.responseText)
			//document.getElementById('ajaxstorylinks_'+sid).innerHTML = xmlhttp.responseText;
		} else {
			//document.getElementById('ajaxstorylinks_'+sid).innerHTML = '<center>Updating... please wait...</center>';
		}
	}
	xmlhttp.send(null)

}

function ajax_status() {

	xmlhttp = make_http();

	var nstat = document.sf.nstat.value;

	xmlhttp.open("GET", "/updatestat.php?nstat="+nstat+"",true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			hide_stat();
			document.getElementById('da_status_on').innerHTML = ''+nstat+'';
			if (nstat != '') {
				stat_updated();
			}
		}
	}
	xmlhttp.send(null)

}

function ajax_clear_status() {

	xmlhttp = make_http();

	var oldnstat = document.sf.nstat.value;

	document.sf.nstat.value = '';

	xmlhttp.open("GET", "/updatestat.php?nstat=",true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			hide_stat();
			document.getElementById('da_status_on').innerHTML = '';
			document.getElementById('da_status_off').innerHTML = '';
			if (oldnstat != '') {
				stat_updated();
			}
		}
	}
	xmlhttp.send(null)

}



function pause(numberMillis)
{
        var now = new Date();
        var exitTime = now.getTime() + numberMillis;
        while (true)
        {
                now = new Date();
                if (now.getTime() > exitTime)
                return;
        }
}


