function display_friend_email_popup()
{
	if (document.getElementById('tell_a_friend_popup').style.display == 'none')
	{
		document.getElementById('TELL_A_FRIEND_SENDER_NAME').value = '';
		document.getElementById('TELL_A_FRIEND_EMAIL').value = '';
		
		var anchor_coords = getAnchorPosition('TELL_A_FRIEND_ANCHOR');
		
		document.getElementById('tell_a_friend_popup').style.display = '';
		document.getElementById('tell_a_friend_popup').style.left = anchor_coords.x + 'px';
		document.getElementById('tell_a_friend_popup').style.top = anchor_coords.y + 'px';
		
		document.getElementById('TELL_A_FRIEND_SENDER_NAME').focus();
	}
}

function edit_gift_message()
{
	if (document.getElementById('gift_message_popup').style.display == 'none')
	{
		if (document.getElementById('gift_message'))
		{
			document.getElementById('GIFT_MESSAGE').innerHTML = document.getElementById('GIFT_MESSAGE_LISTING_TEXT').innerHTML;
		}
		
		document.getElementById('gift_message_popup').style.visibility = 'hidden';
		document.getElementById('gift_message_popup').style.display = '';
		
		var popup_coords = get_screen_center('gift_message_popup');
		document.getElementById('gift_message_popup').style.left = popup_coords.x + 'px';
		document.getElementById('gift_message_popup').style.top = popup_coords.y + 'px';
		
		document.getElementById('gift_message_popup').style.visibility = 'visible';		
	}
}

function get_screen_center(div_name)
{
	var div_width, div_height;
	var coordinates=new Object();
	
	var frameWidth, frameHeight;
	
	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	
	width = document.getElementById(div_name).offsetWidth;
	height = document.getElementById(div_name).offsetHeight;
	
	coordinates.x = Math.round((frameWidth / 2) - (width / 2));
	coordinates.y = Math.round((frameHeight / 2) - (height / 2));
	
	return coordinates;
}

function display_edit_billing_popup()
{
	if (document.getElementById('edit_billing_popup').style.display == 'none')
	{
		if (document.getElementById('edit_shipping_popup').style.display != 'none')
		{
			document.getElementById('edit_shipping_popup').style.display = 'none';
		}
		
		// init fields
		document.getElementById('EDIT_BILLING_FIRST_NAME').value = document.getElementById('CURRENT_BILLING_FIRST_NAME').value;
		document.getElementById('EDIT_BILLING_LAST_NAME').value = document.getElementById('CURRENT_BILLING_LAST_NAME').value;
		document.getElementById('EDIT_BILLING_ADDRESS_1').value = document.getElementById('CURRENT_BILLING_ADDRESS_1').value;
		
		
		if (document.getElementById('CURRENT_BILLING_ADDRESS_2'))
		{
			document.getElementById('EDIT_BILLING_ADDRESS_2').value = document.getElementById('CURRENT_BILLING_ADDRESS_2').value;
		}
		
		document.getElementById('EDIT_BILLING_CITY').value = document.getElementById('CURRENT_BILLING_CITY').value;		
		document.getElementById('EDIT_BILLING_STATE').selectedIndex = (document.getElementById('CURRENT_BILLING_STATE_INDEX').value - 1);
		document.getElementById('EDIT_BILLING_ZIP').value = document.getElementById('CURRENT_BILLING_ZIP').value;	
		document.getElementById('EDIT_BILLING_PHONE').value = document.getElementById('CURRENT_BILLING_PHONE').value;	
		document.getElementById('EDIT_BILLING_EXTENSION').value = document.getElementById('CURRENT_BILLING_EXTENSION').value;	
		
		
		// center billing popup on screen
		document.getElementById('edit_billing_popup').style.visibility = 'hidden';
		document.getElementById('edit_billing_popup').style.display = '';
		
		var popup_coords = get_screen_center('edit_billing_popup');
		document.getElementById('edit_billing_popup').style.left = popup_coords.x + 'px';
		document.getElementById('edit_billing_popup').style.top = popup_coords.y + 'px';
		
		document.getElementById('edit_billing_popup').style.visibility = 'visible';		
	}
}

function display_edit_shipping_popup()
{
	if (document.getElementById('edit_shipping_popup').style.display == 'none')
	{
		if (document.getElementById('edit_billing_popup').style.display != 'none')
		{
			document.getElementById('edit_billing_popup').style.display = 'none';
		}
		
		// init fields
		document.getElementById('EDIT_SHIPPING_FIRST_NAME').value = document.getElementById('CURRENT_SHIPPING_FIRST_NAME').value;
		document.getElementById('EDIT_SHIPPING_LAST_NAME').value = document.getElementById('CURRENT_SHIPPING_LAST_NAME').value;
		document.getElementById('EDIT_SHIPPING_ADDRESS_1').value = document.getElementById('CURRENT_SHIPPING_ADDRESS_1').value;
		
		
		if (document.getElementById('CURRENT_SHIPPING_ADDRESS_2'))
		{
			document.getElementById('EDIT_SHIPPING_ADDRESS_2').value = document.getElementById('CURRENT_SHIPPING_ADDRESS_2').value;
		}
		
		document.getElementById('EDIT_SHIPPING_CITY').value = document.getElementById('CURRENT_SHIPPING_CITY').value;		
		document.getElementById('EDIT_SHIPPING_STATE').selectedIndex = (document.getElementById('CURRENT_SHIPPING_STATE_INDEX').value - 1);
		document.getElementById('EDIT_SHIPPING_ZIP').value = document.getElementById('CURRENT_SHIPPING_ZIP').value;	
		document.getElementById('EDIT_SHIPPING_PHONE').value = document.getElementById('CURRENT_SHIPPING_PHONE').value;	
		document.getElementById('EDIT_SHIPPING_EXTENSION').value = document.getElementById('CURRENT_SHIPPING_EXTENSION').value;	
		
		
		// center shipping popup on screen
		document.getElementById('edit_shipping_popup').style.visibility = 'hidden';
		document.getElementById('edit_shipping_popup').style.display = '';
		
		var popup_coords = get_screen_center('edit_shipping_popup');
		document.getElementById('edit_shipping_popup').style.left = popup_coords.x + 'px';
		document.getElementById('edit_shipping_popup').style.top = popup_coords.y + 'px';
		
		document.getElementById('edit_shipping_popup').style.visibility = 'visible';		
	}
}

function send_friend_email(product_id)
{
	var error_str = '';
	
	var sender_name = trim(document.getElementById('TELL_A_FRIEND_SENDER_NAME').value);
	var email = trim(document.getElementById('TELL_A_FRIEND_EMAIL').value);
	
	if (!check_email(email)) { error_str += 'Invalid Email Address\n'; }	
	if (sender_name.length < 1) { error_str += 'Your Name is blank'; }
	
	if (error_str.length) { alert('Please correct the following: \n\n' + error_str); }
	else
	{
		var url = "library/functions/send_friend_email.php";
		url = url + "?q=";
		url = url + "&ajax=1";
		url = url + "&sender_name=" + sender_name;
		url = url + "&email=" + email;
		url = url + "&product_id=" + product_id;
		url = url + "&sid=" + Math.random();		
		
		xmlreqGET(url);		
	}
}