function go_to_member_page_from_popup(url)
{
	window.opener.location.href = url;
	window.opener.focus();
}

var Toggle =
{
	display: function(id)
	{
		var el = document.getElementById(id)
		if (el.style.display == "none") {
			el.style.display = "";
		} else {
			el.style.display = "none";
		}
	}
}
var sentItems =
{
	success: function(o)
	{
		try {
			if (o.responseText != 'timeout') {
				var sent = document.getElementById(sentItems.id).innerHTML = "<span style='font-weight:bold;'>Sent!</span>";
				if (sentItems.hide_id != "") {
					document.getElementById(sentItems.hide_id).style.display = "none";
				}
			} else {
				alert('Your session has expired. Please log in again and mark your items as sent. Sorry.')
				document.location.href = "http://www.swap-bot.com/account/login.php";
			}
		} catch (e) {}
	},
	failure: function(o)
	{
		alert(o.statusText);
	},
	click: function(url,id,hide_id)
	{
		if (confirm("Click OK to confirm that you sent your item(s).")) {
			sentItems.id = id;
			sentItems.hide_id = hide_id;
			var cObj = YAHOO.util.Connect.asyncRequest('GET',url,this,null);
		}
	}
	
}


// delete comments
function delete_comments(id)
{
	if (confirm("Are you sure you want to delete this comment forever?")) {
		var dc = new deleteComments(id);
		dc.connect();
	}
}

function deleteComments(id)
{
	this.id = id;
}

deleteComments.prototype.success = function()
{
	Toggle.display("comment-" + this.id);
}

deleteComments.prototype.failure = function()
{
	
}

deleteComments.prototype.connect = function()
{
	var url = swap_bot.global.base_url + "/swap/admin_delete_comment.php";
	var post = "id=" + this.id;
	var cObj = YAHOO.util.Connect.asyncRequest('POST',url,this,post);
}

function messagesSelectAll()
{
	var allEls = document.getElementsByTagName("input");
    for (var i = 0; i < allEls.length; i++) {
        if (allEls.item(i).className == 'delete_message') {
			allEls.item(i).checked = true;
        }
    }
}

function choose_category()
{
	var choice = document.getElementById('category').value;
	document.location.href = swap_bot.global.base_url + "/swap/search.php?action=search&category=" + choice
}

// image loader
function showImage(url)
{
	$('photo-holder').show();
	$('photo-holder').update("<img src='" + url + "' />");
}

function setBirthday() {}

setBirthday.prototype.connect = function()
{
	YAHOO.util.Connect.setForm(document.getElementById('birthday-form')); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', swap_bot.global.base_url + "/account/save_birthday.php?ajax", this);
}

setBirthday.prototype.success = function(o)
{
	var response = eval("(" + o.responseText + ")");
	if (response.success) {
		switch (response.type) {
			case "swap":
				document.getElementById('enter-birthday').innerHTML = '<p>You birthday has been saved. Thank you! <h1><a href="' + swap_bot.global.base_url + '/swap/signup/' + response.swap_id + '">Signup for this swap</a></h1></p>';
				break;
			default:
				document.getElementById('enter-birthday').innerHTML = '<p>You birthday has been saved. Thank you! <a href="#" onclick="Toggle.display(\'enter-birthday\'); return false;">[Hide message]</a></p>';
		}
	} else {
		document.getElementById('enter-birthday').innerHTML = '<p>Error saving birthday. Please try again later.</p>';
	}
}

function showOther(type, num, value)
{
	if (type == 'urls') {
		document.getElementById(type + '-defined-' + num).style.display = 'none';
	}

	document.getElementById(type + '-other-' + num).style.display = 'none';
	if (value == 'other') {
		document.getElementById(type + '-other-' + num).style.display = '';
	} else if (type == 'urls') {
		document.getElementById(type + '-defined-' + num).style.display = '';
	}
}

function addAnother(type)
{
	var found = false;
	var max = (type == 'urls' ? 5 : 10)
	var i = 0;
	while (!found) {
		if (document.getElementById(type + '-' + i).style.display == 'none') {
			document.getElementById(type + '-' + i).style.display = '';
			found = true;
		}
		i++;
	}
	if (i == max) {
		document.getElementById('add-another-' + type).style.display = 'none';
	}
}

function viewSent(value)
{
	var to = '';
	if (value) {
		to = "&to=" + value;
	}
	document.location.href = swap_bot.global.base_url + "/account/messages.php?view=sent" + to;
}

function archiveSwap(type, swap_id)
{
	this.type = type;
	this.swap_id = swap_id;
}

archiveSwap.prototype.success = function(o)
{
	if (o.responseText == 1) {
		var archive_link = YAHOO.util.Dom.get('archive-'+this.swap_id);
		archive_link.innerHTML = 'Archived!';
		
		var list_swaps = YAHOO.util.Dom.getElementsByClassName('list-swap-'+this.swap_id);
		for (var i = 0; i < list_swaps.length; i++) {
		    list_swaps[i].style.display = "none";
		}
	} else {
		// do nothing :(
	}
}

archiveSwap.prototype.connect = function()
{
	var post = "swap_id=" + this.swap_id + "&type=" + this.type;
	var cObj = YAHOO.util.Connect.asyncRequest('POST', swap_bot.global.base_url + "/account/archive_swap.php?ajax", this, post);
}

// Swap description page js

function new_win(url, height, width)
{
	window.open(url, 'new_win', 'width='+width+'px, height='+height+'px, scrollbars=yes, resize=yes');
}
function launch_gallery(url)
{
	new_win(url, 600, 760);
}

function toggle_image_upload()
{
	var up_el = document.getElementById('upload_swap_image');
	if (up_el.style.height == '0px') {
		var div_height = document.getElementById('upload_swap_image_wrapper').offsetHeight;
		var myAnim = new YAHOO.util.Anim('upload_swap_image', { height: {to: div_height} });
	} else {
		var myAnim = new YAHOO.util.Anim('upload_swap_image', { height: {to: 0} });
	}
	myAnim.animate();
}