/*=====================================*\
|| ################################### ||
|| # Post welcome you Hack version 6.1 # ||
|| ################################### ||
\*=====================================*/

function post_welcomes_give(postid, integrate)
{
	fetch_object('post_welcomes_button_' + postid).style.display = 'none';

	if (integrate == true)
	{
		fetch_object('post_groan_button_' + postid).style.display = 'none';
	}
	
	do_welcomes_add = new vB_AJAX_Handler(true);
	do_welcomes_add.postid = postid;
	do_welcomes_add.onreadystatechange(welcomes_add_Done);
	do_welcomes_add.send('post_welcomes.php?do=post_welcomes_add&using_ajax=1&p=' + postid);
}
function welcomes_add_Done()
{
	if (do_welcomes_add.handler.readyState == 4 && do_welcomes_add.handler.status == 200)
	{
		fetch_object('post_welcomes_box_' + do_welcomes_add.postid).innerHTML = do_welcomes_add.handler.responseText;
	}
}
function post_welcomes_remove_all(postid, integrate)
{
	do_welcomes_remove_all = new vB_AJAX_Handler(true)
	do_welcomes_remove_all.postid = postid
	do_welcomes_remove_all.onreadystatechange(welcomes_remove_all_Done)
	do_welcomes_remove_all.send('post_welcomes.php?do=post_welcomes_remove_all&using_ajax=1&p=' + postid)

	fetch_object('post_welcomes_button_' + postid).style.display = ''

	if (integrate == true)
	{
		fetch_object('post_groan_button_' + postid).style.display = '';
	}
}
function welcomes_remove_all_Done()
{
	if (do_welcomes_remove_all.handler.readyState == 4 && do_welcomes_remove_all.handler.status == 200)
	{
		fetch_object('post_welcomes_box_' + do_welcomes_remove_all.postid).innerHTML = do_welcomes_remove_all.handler.responseText
	}
}
function post_welcomes_remove_user(postid, integrate)
{
	do_welcomes_remove_user = new vB_AJAX_Handler(true)
	do_welcomes_remove_user.postid = postid
	do_welcomes_remove_user.onreadystatechange(welcomes_remove_user_Done)
	do_welcomes_remove_user.send('post_welcomes.php?do=post_welcomes_remove_user&using_ajax=1&p=' + postid)

	fetch_object('post_welcomes_button_' + postid).style.display = ''

	if (integrate == true)
	{
		fetch_object('post_groan_button_' + postid).style.display = '';
	}	
}
function welcomes_remove_user_Done()
{
	if (do_welcomes_remove_user.handler.readyState == 4 && do_welcomes_remove_user.handler.status == 200)
	{
		fetch_object('post_welcomes_box_' + do_welcomes_remove_user.postid).innerHTML = do_welcomes_remove_user.handler.responseText
	}
}

var _psd_welcomed = true;

jQuery(document).ready(function() {
	if (jQuery("a[id^=post_welcomes_button_]:visible").length > 0) { _psd_welcomed = false; }
	else return false;	

	jQuery("a[id^=post_welcomes_button]").click(function() {
		_psd_welcomed = true;
		
		window.onbeforeunload = function() { };
	});
	
	
	window.onbeforeunload = function() { 
	
		if (_psd_welcomed) return null; 
		
		var username = jQuery("a[id^=post_welcomes_button_]").parents("table[id^=post]").find("a.bigusername:first").html(); 
		var cnfrm = confirm("You didn\'t welcome "+username+" to the forum yet. Would you like to say \"Welcome to AquariumForum.com!\" to "+username+"? Click OK to enter your name in the list of people who have said welcome to "+username+".");
		if (cnfrm) { 
			//clicked ok 
			
			
			var btn = jQuery("a[id^=post_welcomes_button]");
			if (btn.length > 0) {
				var r = btn.attr("id").match(/^post_welcomes_button_([0-9]+)/);
				if (r) {
					var id = parseInt(r[1]);
					post_welcomes_give(id, false);
					_psd_welcomed = true;
	
					return "";
				}
			}
		} 
		return null; 
	};
	
	
	
});


