function friendList(form_name)
{
	// Pass the form name
	friendlist = openNewWindow('/mart/friendlist.php?form_name='+form_name, 'fl', 300, 400, 'yes');
	friendlist.focus();
}
function show_annual_gift() {
	var annual_gift = document.getElementById("annual_gift");
	var checkbox	= document.getElementById("show_annual_gift_checkbox");
	var returnVal	= document.getElementById("annual_return");
	if(annual_gift.style.display == "block") {
		var mode = "none";
		var returnVal = "/vip/payment-confirm.php";
		var value = false;
	} else {
		var mode = "block";
		var returnVal = "/vip/gift-thanks.php";
		var value = true;
	}
	annual_gift.style.display = mode;
	checkbox.checked = value;
}
function show_monthly_gift() {
	var monthly_gift = document.getElementById("monthly_gift");
	var checkbox	= document.getElementById("show_monthly_gift_checkbox");
	var returnVal	= document.getElementById("monthly_return");
	if(monthly_gift.style.display == "block") {
		var mode = "none";
		var returnVal = "/vip/payment-confirm.php";
		var value = false;
	} else {
		var mode = "block";
		var returnVal = "/vip/gift-thanks.php";
		var value = true;
	}
	monthly_gift.style.display = mode;
	checkbox.checked = value;
}
var form_vip;
function validate_vip(o)
{
	// Need to check if the user name exists before hand via AJAX
	if(o.gift.checked && o.user_option.value == 'username')
	{
		var url = "/common/ajax/user_exists.php";
		var params = { user: o.text_gift_for.value };
		$.getJSON(url, params, function(data)
		{
		   validate_vip_handler(o, data);
		});
	}
	else
	{
		validate_vip_handler(o, true); // True, because we know it's not the non-existant user name that failed.
	}
	// Because of poopie IE we're going to return false and submit the form with JS in validate_vip_handler
	return false;
}
function validate_vip_handler(o, data)
{
	var div = $('#popup');
	// Check for an existing div
	if(!div.length)
	{
		// Create a hidden div to give content to
		div = $('<div id="popup" style="display: none;"></div>');
		// Add it to the body
		$('body').append(div);
	}
	var height = 120;
	var width = 300;

	// If the user isn't logged in, ask them to

	var msg = '';
	if(!o.agree_terms.checked)
	   msg += "You need to accept our terms of use before becoming a VIP member.<br /><br />";

	// If there's a gift checked, check the gift form as well
	if(o.gift.checked)
	{
	   // They are putting in an email
	   if(o.user_option.value == 'email')
	   {
	      // Is it a valid email
			if(!/^[a-z0-9_\-\.]+@[a-z0-9_\-\.]+\.[a-z]{2,4}$/i.test(o.text_gift_for.value))
			   msg += "Please enter a valid email address.<br /><br />";
	   }
	   // Or it's a user.  We have to check for an existing.
	   else
	   {
	      if(!data)
			   msg += "That username doesn't exist in our database.<br /><br />";
	   }
	}
	
	// oops, there's a problem
	if(msg)
	{
	   div.html(
			'<div style="font-size: 14px; font-weight: bold; text-align: center; margin-top: 10px;">'+
			msg+
			'<div onclick="tb_remove();" class="button_small_orange" style="margin: 0 auto;">Okay</div>'+
			'</div>'+
		'');
		tb_inline('popup', width, height);
		return false;
	}
	
	// If the user isn't logged in we need to store the information.  So let's redirect the form to store it
	if(!logged_in)
	{
	   // We'll need it in save_vip function and I don't feel like regetting it.
	   form_vip = o;
	   div.html(
			'<div style="font-size: 14px; font-weight: bold; text-align: center; margin-top: 10px;">'+
			'Please <span onclick="save_vip(\'login\');" style="text-decoration: underline; cursor: pointer">sign-in</span> or <span onclick="save_vip(\'signup\');" style="text-decoration: underline; cursor: pointer">register</span> to become a grab VIP.<br />'+
			'<br />'+
			'<span onclick="save_vip(\'login\');" style="text-decoration: underline; cursor: pointer">Click here to sign-in</span><br />'+
			'<span onclick="save_vip(\'signup\');" style="text-decoration: underline; cursor: pointer">Click here to register</span><br /><br />'+
			'</div>'+
		'');
		tb_inline('popup', width, height);
		return false;
	}


	// Wow, everything is good, submit the form.
	o.submit();
	return true;
}

function save_vip(type)
{
	form_vip.action = 'buy-now_save.php?type='+type;
	form_vip.submit();
}








