// Log user in
	function checkLogin() {
		$.ajax({type: "POST",
						 url: "/ajax.php?rand="+Math.random(),
						data: "ajax=checkLogin&user_name="+escape($('#u_name').val())+"&user_pwd="+escape($('#u_pwd').val())+"&remember="+$('#rem').val(),
				 success: function(status) {
					 					if(status == 'success') {
											window.location.reload();
										}
										else if(status == 'not_verified') {
											alert('You have not verified your account. Please check your e-mail for your account activation link.  If you did not receive it, please click on find codes below.');
										}
										else if(status == 'deleted') {
											alert('This account no longer exists');
										}
										else {
											alert('The information you have entered is not valid.');
										}
					 				}});
	}

// Perform Search
	function performSearch() {
		window.location='/search/'+$('#search').val()+'&type='+$('#type').val()		
	}

// Rate a review
	function rateReview(id,r) {
		$.ajax({type: "POST",
						 url: "/ajax.php",
						data: "ajax=rateReview&id="+id+"&r="+r,
				 success: function(status) {
					 					$('#helpful_'+id).hide().html(status).fadeIn();
					 				}});
	}

// Rate something
	function rate(id,r,t,url,title) {
		$.ajax({type: "POST",
						 url: "/ajax.php",
						data: "ajax=rateItem&id="+id+"&r="+r+"&type="+t+"&url="+url+"&title="+title,
				 success: function(status) {
					 					window.location.reload(true);
					 				}});
	}

// Leave Comment
	function leaveComment(id,p,c,t,url,title) {
		$.ajax({type: "POST",
						 url: "/ajax.php",
						data: "ajax=leaveComment&id="+id+"&p="+p+"&c="+escape(c)+"&t="+t+"&url="+escape(url)+"&title="+escape(title),
				 success: function(status) {
					 					if(!status) {
											alert('There was a problem with your submission');
										}
										else {
					 						window.location.reload(true);
										}
					 				}});
	}

// Delete Comments
function deleteComment(comment_id,u) {
	if(confirm('Are you sure that you want to delete this comment?  This action cannot be undone!')) {
		$.ajax({
			type: "GET",
		 	url: "/ajax.php",
		 	data: "ajax=deleteComment&comment_id="+comment_id+"&u="+u,
		 	success: function(status) {$('#comment_'+comment_id).hide()}});
	}
}

function showDescription(d) {
	$('#description_'+d).slideToggle();
	$('#description_'+d+'_icon').toggleClass('toggle_expand');
	$('#description_'+d+'_icon').toggleClass('toggle_collapse');
}

// Toggle Section
function toggle(id){
	$("#toggle_"+id).slideToggle("slow");
	obj = document.getElementById('arrow_'+id);
	var src = $('#arrow_'+id).attr("src");
	if(src == '/images/collapse.gif') {
		obj.src = '/images/expand.gif';
	} else {
		obj.src = '/images/collapse.gif';
	}
}

	var l;
	var c;
	function startTimers() {
		l=setTimeout("logOut();",1200000);
		c=setTimeout("checkTimeOut();",900000);
	}
	function checkTimeOut() {
		extendTime();
		/*
		if(document.getElementById('keep_alive').value) {
				extendTime();
		}
		else {
			if(confirm("You have been inactive for 15 minutes.\n\nDo you wish to extend your time?")) {
				extendTime();
			}
			else {
				logOut();
			}
		}*/
	}
	
	function logOut() {
		window.location='/logout';
	}
	
	function extendTime() {
				$.ajax({
					type: "GET",
					url: "index.php",
					data: "ajax=true&a=check_time",
					success: function(){}});
				clearTimeout(l);
				startTimers();
	}
	
function openComicWindow(url,w,h,win) { // (url=page to open, w=width, h=height)
		if(!w)
			w=screen.availWidth;
		if(!h)
			h=screen.availHeight;
	   window.open(url, win, 'status=no,toolbar=no,resizable=yes,menubar=no,scrollbars=yes,directories=no,location=no,width='+ w +',height='+ h +'');
	}

function openCenterComicWindow(url,w,h,win) { // (url=page to open, w=width, h=height)
		var wl = (screen.width-w)/2;
		var wt = (screen.height-h)/2;
		window.open(url, win, 'status=no,toolbar=no,resizable=yes,menubar=no,scrollbars=yes,directories=no,location=no,top='+wt+',left='+wl+',width='+ w +',height='+ h +'');
	}
function textCounter(field,maxlimit) {
	obj = document.getElementById(field);
	if (obj.value.length > maxlimit) // if too long...trim it!
		obj.value = obj.value.substring(0, maxlimit);
	else 
		document.getElementById(field+'_remaining').innerHTML = maxlimit - obj.value.length;
}	

// Countdown Script
	function auctionEnds() {
		countdown('auction_ends', "September 7, 2009 20:00:00", 0, '');
	}


/* 	Realtime Countdown v1.1
 *	(C) 2006 Nathan Bolender
 *	www.nathanbolender.com
*/

/*	**********************************************************	*/
/*	**********************************************************	*/
/*	**************** DO NOT EDIT BELOW THIS LINE**************	*/
/*	**********************************************************	*/
/*	**********************************************************	*/

var version = '1.1';
		
function countdown(elementString, dateString, mode, name) { // date in format "December 25, 2005 00:00:00 GMT-500"
/////////////////////////////////////////
//	usage:
//	countdown(str element, str date [, int mode [, str name]])
//	element is the element that will contain the countdown
//	date is the countdown (or countup) date in this standard form:
//		December 25, 2005 00:00:00 GMT-500
/////
//	Modes:
//	0 (default): Time until My Birthday - 06:33:00 11/25/05: 6 hours, 28 minutes, and 36 seconds.
//	1: My Birthday - 06:33:00 11/25/05: 6 hours, 28 minutes, and 36 seconds.
//	2: 6 hours, 28 minutes, and 36 seconds.
//	3: 6 hours, 28 minutes, and 36 seconds
if (mode == null) mode = 0;
if (name == null) name = '0';
	var clock = document.getElementById(elementString);
	var eventdate = new Date(dateString); // in format "January 1, 2005 00:00:00 GMT"
	now = new Date();
	nowtime = now.getTime() + (now.getTimezoneOffset() * 60000);
	nowtime = new Date(nowtime+(3600000*-5));
	eventtime = eventdate.getTime(); // event in milliseconds
		
		var eventhour = eventdate.getHours();
		var eventminute = eventdate.getMinutes();
		var eventsecond = eventdate.getSeconds();
		var eventmonth = eventdate.getMonth()+1;
		var eventday = eventdate.getDate();
		var eventyear = eventdate.getFullYear();

	timeleft = Math.round((eventtime-nowtime) / 1000); // timeleft in seconds
	
	var passed = 0;
	if (timeleft < 0) { // if event has passed
		timeleft = Math.abs(timeleft);
		passed = 1;
	}
	
	if (timeleft != 0) {
		// Let's get a whole bunch of values
		years = Math.floor(timeleft/31556926);
		months = Math.floor((timeleft%31556926)/2629744);
		days = Math.floor(((timeleft%31556926)%2629744)/86400);
		hours = Math.floor((((timeleft%31556926)%2629744)%86400)/3600);
		minutes = Math.floor(((((timeleft%31556926)%2629744)%86400)%3600)/60);
		seconds = Math.floor(((((timeleft%31556926)%2629744)%86400)%3600)%60);
	}
	
	// Now lets build a response to print
	var togo = ''; // set up our variable
	
	if (mode == 0) {
		togo += 'Time ';
		if (passed != 1) {
			togo += 'until ';
		} else {
			togo += 'since ';
		}
	}
	
	if ((mode != 2) && (mode != 3)) {
		togo += '<strong>';
		if (name != '0') togo += name + ' - ';
		if ((eventhour + eventminute + eventsecond) != 0) {
			togo += eventhour + ':' + eventminute;
			if (eventsecond != 0) togo += ':' + eventsecond;
			togo += ' on ';
		}
		togo += eventmonth + '/' + eventday;
		if (eventyear != now.getFullYear()) togo += '/' + eventyear;
		togo += '</strong>: ';
	}
	togo = '';
	if (timeleft != 0) {
		if (years > 0) {
			togo += years + ' year';
			if (years > 1) togo += 's';
			if (months > 0) togo += ',';
			if ((minutes!=0)||(seconds!=0)||(hours!=0)||(days!=0)||(months!=0)) togo += ' ';
		}
		
		if (months > 0) {
			togo += months + ' month';
			if (months > 1) togo += 's';
			if (days > 0) togo += ',';
			if ((minutes!=0)||(seconds!=0)||(hours!=0)||(days!=0)) togo += ' ';
		}
		
		if (days > 0) {
			togo += days + ' day';
			if (days > 1) togo += 's';
			if (hours > 0) togo += ',';
			if ((minutes!=0)||(seconds!=0)||(hours!=0)) togo += ' ';
		}
		
		if (hours > 0) {
			togo += hours + ' hour';
			if (hours > 1) togo += 's';
			if (minutes > 0) togo += ',';
			if ((minutes!=0)||(seconds!=0)) togo += ' ';
		}
		
		if (minutes > 0) {
			togo += minutes + ' minute';
			if (minutes > 1) togo += 's';
			if (seconds > 0) togo += ',';
			if (seconds != 0) togo += ' ';
		}
		
		if (seconds > 0) {
			togo += seconds + ' second';
			if (seconds > 1) togo += 's';
		}
		
		var expld = togo.split(', ');
		// EXAMPLE:
		// 0 => 5 years
		// 1 => 5 months
		// 2 => 5 days
		// 3 => 5 hours
		// 4 => 5 minutes
		// 5 => 5 seconds
		
		var exlast = expld.length-1;
		var todo = '';
		var i;
		
		for (i=0 ; i<expld.length ; i++) {
			value = expld[i];
			todo += value;
			if ((i != exlast) && (expld.length!=2)) todo += ', ';
			if ((expld.length == 2) && (i != exlast)) todo += ' ';
			if (i == (exlast-1)) todo += 'and ';
			if ((i == exlast) && (passed == 1)) todo += ' ago';
			if ((i == exlast) && (mode != 3)) todo += '';
		}
	} else {
		var todo = togo + ' Now!';
	}
	
	// Now lets print it
	clock.innerHTML = todo;
	
	setTimeout('countdown(\'' + elementString + '\', \'' + dateString + '\', ' + mode + ', "' + name + '");', 1000); // re-execute the function in 1 second
}