function addComment() {
	if ( Get_Cookie( 'lpc' ) ) {
		alert("You must wait one minute between comments!");
	} else {
		var comment = document.getElementById("fullcomment").value;
		var name = document.getElementById("commentname").value;
		
		if (comment.length < 1) {
			alert("Please enter SOMETHING for a comment.");
			return false;
		}
		
		if (name.length < 1) {
			alert("You didn't put in a name...");
			return false;
		}
		
		var itemid = document.getElementById("itemid").value;
		var commentfile = document.getElementById("commentfile").value;
		var d = new Date();
		var time = d.getTime();
		
		$.post("http://www.leakingpen.com/addcomment.php", { postid: itemid, name: name, comment: comment });
		pausecomp(1000)
		
		alert("Your comment has been added.");
		
		$("#comments").load("http://www.leakingpen.com/showcomments.php?id="+itemid+"&rd="+time+"");
		// simple spam protection
		Set_Cookie( 'lpc', 'justdid', 1, '/', '', '' );
	}
	return true;
}

function loadHot(what) {
	var hotarea = document.getElementById("hot4area");
	var d = new Date();
	var time = d.getTime();
	
	var file = what+".inc";
	var button = "hot"+what;
	
	// change button styles
	
	$("a#hottoday").removeClass("selected");
	$("a#hotweek").removeClass("selected");
	$("a#hotmonth").removeClass("selected");
	$("a#hotyear").removeClass("selected");
	
	$("a#"+button+"").addClass("selected");
	
	$(hotarea).load("http://www.leakingpen.com/hotitems/"+file+"?dummy="+time+"");
}

function loadItem(what) {
	window.location = what;
}

function loadHotItem(what) {
	window.location = "http://www.leakingpen.com/item/"+what;
}

function showLoadingSubmit() {
	var what = document.getElementById("submitindicator");
	what.style.visibility = "visible";
}

function pausecomp(millis)
{
date = new Date();
var curDate = null;

do { var curDate = new Date(); }
while(curDate-date < millis);
} 

function checkFormCookie() { 
	if ( Get_Cookie( 'lpf' ) ) {
		alert("You must wait two minutes between submissions/contact messages!");
		return false;
	};
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}	
